Skip to content

Commit a73797b

Browse files
committed
Fix linter errors
1 parent 26732f2 commit a73797b

2 files changed

Lines changed: 35 additions & 36 deletions

File tree

eslint.config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@ import xo from "eslint-config-xo";
22
import typescriptEslintParser from "@typescript-eslint/parser";
33
import eslint from '@eslint/js';
44
import tseslint from 'typescript-eslint';
5-
import unicornPlugin from 'eslint-plugin-unicorn';
65

76
export default tseslint.config(
87
eslint.configs.recommended,
98
eslint.configs.recommended,
109
...tseslint.configs.recommendedTypeChecked,
1110
...tseslint.configs.stylisticTypeChecked,
12-
unicornPlugin.configs.recommended,
13-
...xo,
11+
...xo(),
1412
{
1513
languageOptions: {
1614
parser: typescriptEslintParser,
17-
parserOptions: {
18-
project: "./tsconfig.json",
19-
},
2015
},
2116
rules: {
2217
"@stylistic/function-paren-newline": ["off"],
@@ -73,6 +68,7 @@ export default tseslint.config(
7368
"@stylistic/object-curly-newline": ["error", {
7469
"ImportDeclaration": "never"
7570
}],
71+
"import-x/extensions": "off",
7672
"n/file-extension-in-import": "off",
7773
"promise-function-async": "off",
7874
"camelcase": "off",

src/vue-shv.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import {computed, ComputedRef, Ref, ref, watchEffect} from 'vue';
2-
import {CallRpcMethodOptions, type WsClient, type WsClientOptionsLogin} from 'libshv-js/ws-client';
1+
import {computed, type ComputedRef, type Ref, ref, watchEffect} from 'vue';
2+
import {type CallRpcMethodOptions, type WsClient, type WsClientOptionsLogin} from 'libshv-js/ws-client';
33
import {useLocalStorage, useSessionStorage} from '@vueuse/core';
44
import PKCE from 'js-pkce';
55
import * as z from 'libshv-js-zod/zod';
66
// @ts-expect-error - shvMapType is indirectly used by Zod, it's needed for exporting
77
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8-
import {type shvMapType} from 'libshv-js/rpcvalue';
9-
import {RpcValue} from 'libshv-js/rpcvalue';
10-
import {resolveString, StringGetter} from 'libshv-js/utils';
11-
import {createZodWsClient, ZodMethodHandler} from 'libshv-js-zod';
8+
import {type shvMapType, type RpcValue} from 'libshv-js/rpcvalue';
9+
import {resolveString, type StringGetter} from 'libshv-js/utils';
10+
import {createZodWsClient, type ZodMethodHandler} from 'libshv-js-zod';
1211
import {ShvRI} from 'libshv-js';
1312

1413
type GlobalResourceOptions<ResourceType> = {
@@ -17,7 +16,7 @@ type GlobalResourceOptions<ResourceType> = {
1716
validator: z.ZodType<ResourceType>;
1817
signalName: string;
1918
signalHandler: (param: RpcValue, resource: Ref<ResourceType | undefined>, reinit: () => void) => void;
20-
callRpcMethodOptions?: CallRpcMethodOptions,
19+
callRpcMethodOptions?: CallRpcMethodOptions;
2120
};
2221

2322
type VueShvOptions = {
@@ -60,7 +59,7 @@ type LoginFailure = {
6059
message?: string;
6160
};
6261

63-
const makePkce = (oauthOptions: {azureCodeRedirect: string, clientId: string; authorizeUrl: string; tokenUrl: string; scopes: string | string[]}) => {
62+
const makePkce = (oauthOptions: {azureCodeRedirect: string; clientId: string; authorizeUrl: string; tokenUrl: string; scopes: string | string[]}) => {
6463
const pkce = new PKCE({
6564
client_id: oauthOptions.clientId,
6665
redirect_uri: (() => {
@@ -206,13 +205,13 @@ export function useShv(options: VueShvOptions) {
206205
shvSessionStorage.value.shvLoginPassword = password;
207206
};
208207

209-
const rpcCall = async (shvPath: StringGetter, method: string, params?: RpcValue, options?: CallRpcMethodOptions) => {
208+
const rpcCall = async (shvPath: StringGetter, method: string, params?: RpcValue, rpcCallOptions?: CallRpcMethodOptions) => {
210209
const shv = await getConnection();
211-
return shv.callRpcMethod(await resolveString(shvPath), method, params, options);
210+
return shv.callRpcMethod(await resolveString(shvPath), method, params, rpcCallOptions);
212211
};
213212

214-
const makeRpcCall = <ResultType>(shvPath: StringGetter, method: string, validator: z.ZodType<ResultType>, options?: CallRpcMethodOptions) => async () => {
215-
const resultOrError = await rpcCall(await resolveString(shvPath), method, undefined, options);
213+
const makeRpcCall = <ResultType>(shvPath: StringGetter, method: string, validator: z.ZodType<ResultType>, rpcCallOptions?: CallRpcMethodOptions) => async () => {
214+
const resultOrError = await rpcCall(await resolveString(shvPath), method, undefined, rpcCallOptions);
216215
if (resultOrError instanceof Error) {
217216
return resultOrError;
218217
}
@@ -226,8 +225,8 @@ export function useShv(options: VueShvOptions) {
226225
};
227226

228227
// eslint-disable-next-line max-params -- five is fine, this function does not get called a lot and I don't want to change everything to a config object
229-
const makeRpcCallParam = <ResultType, ParamType extends RpcValue>(shvPath: StringGetter, method: string, _paramType: z.ZodType<ParamType>, validator: z.ZodType<ResultType>, options?: CallRpcMethodOptions) => async (param: ParamType) => {
230-
const resultOrError = await rpcCall(await resolveString(shvPath), method, param, options);
228+
const makeRpcCallParam = <ResultType, ParamType extends RpcValue>(shvPath: StringGetter, method: string, _paramType: z.ZodType<ParamType>, validator: z.ZodType<ResultType>, rpcCallOptions?: CallRpcMethodOptions) => async (param: ParamType) => {
229+
const resultOrError = await rpcCall(await resolveString(shvPath), method, param, rpcCallOptions);
231230
if (resultOrError instanceof Error) {
232231
return resultOrError;
233232
}
@@ -253,6 +252,7 @@ export function useShv(options: VueShvOptions) {
253252

254253
for (const [globalResourceKey, globalResource] of Object.entries(globalResources)) {
255254
globalResource.reset();
255+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
256256
delete globalResources[globalResourceKey];
257257
}
258258

@@ -386,19 +386,19 @@ export function useShv(options: VueShvOptions) {
386386
loading: ComputedRef<boolean>;
387387
};
388388

389-
function makeGlobalResource<ResourceType>(options: GlobalResourceOptions<ResourceType>): () => {res: ComputedRef<ResourceType | undefined>} & Loading;
390-
function makeGlobalResource<ResourceType>(options: GlobalResourceOptions<ResourceType> & {default: ResourceType}): () => {res: ComputedRef<ResourceType>} & Loading;
391-
function makeGlobalResource<ResourceType>(options: GlobalResourceOptions<ResourceType> & {default?: ResourceType}): () => {res: ComputedRef<ResourceType> | ComputedRef<ResourceType | undefined>} & Loading {
389+
function makeGlobalResource<ResourceType>(resourceOptions: GlobalResourceOptions<ResourceType>): () => {res: ComputedRef<ResourceType | undefined>} & Loading;
390+
function makeGlobalResource<ResourceType>(resourceOptions: GlobalResourceOptions<ResourceType> & {default: ResourceType}): () => {res: ComputedRef<ResourceType>} & Loading;
391+
function makeGlobalResource<ResourceType>(resourceOptions: GlobalResourceOptions<ResourceType> & {default?: ResourceType}): () => {res: ComputedRef<ResourceType> | ComputedRef<ResourceType | undefined>} & Loading {
392392
const resource = ref<ResourceType>();
393393

394-
const resourceCall = makeRpcCall<ResourceType>(options.shvPath, options.method, options.validator, options.callRpcMethodOptions);
394+
const resourceCall = makeRpcCall<ResourceType>(resourceOptions.shvPath, resourceOptions.method, resourceOptions.validator, resourceOptions.callRpcMethodOptions);
395395

396396
const loading = ref(false);
397397
const refreshValue = async () => {
398398
const newResource = await resourceCall();
399399
if (newResource instanceof Error) {
400-
const shvPath = await resolveString(options.shvPath);
401-
const resIdentifier = `${shvPath}:${options.method}`;
400+
const shvPath = await resolveString(resourceOptions.shvPath);
401+
const resIdentifier = `${shvPath}:${resourceOptions.method}`;
402402
console.error(`Failed to parse new data for resource: ${resIdentifier}:`, newResource);
403403
return;
404404
}
@@ -407,8 +407,8 @@ export function useShv(options: VueShvOptions) {
407407
};
408408

409409
const initialize = async () => {
410-
const shvPath = await resolveString(options.shvPath);
411-
const resIdentifier = `${shvPath}:${options.method}`;
410+
const shvPath = await resolveString(resourceOptions.shvPath);
411+
const resIdentifier = `${shvPath}:${resourceOptions.method}`;
412412
try {
413413
await refreshValue();
414414
globalResources[resIdentifier] = {
@@ -420,10 +420,12 @@ export function useShv(options: VueShvOptions) {
420420
};
421421

422422
const connection = await getConnection();
423-
await connection.subscribe(`Global-${resIdentifier}:`, ShvRI.fromPathMethodSignal(shvPath, '*', options.signalName), (_path: string, _method: string, param: RpcValue) => {
424-
options.signalHandler(param, resource, async () => refreshValue().catch((error: unknown) => {
425-
console.error(`Failed to initialize ${resIdentifier}`, error);
426-
}));
423+
await connection.subscribe(`Global-${resIdentifier}:`, ShvRI.fromPathMethodSignal(shvPath, '*', resourceOptions.signalName), (_path: string, _method: string, param: RpcValue) => {
424+
resourceOptions.signalHandler(param, resource, () => {
425+
refreshValue().catch((error: unknown) => {
426+
console.error(`Failed to initialize ${resIdentifier}`, error);
427+
});
428+
});
427429
});
428430
} catch (error) {
429431
console.error(`Failed to initialize ${resIdentifier}`, error);
@@ -436,13 +438,14 @@ export function useShv(options: VueShvOptions) {
436438
if (!initialized) {
437439
initialized = true;
438440
loading.value = true;
441+
// eslint-disable-next-line @typescript-eslint/strict-void-return
439442
watchEffect(async () => {
440443
if (connected.value !== 'connected') {
441444
return;
442445
}
443446

444-
const shvPath = await resolveString(options.shvPath);
445-
const resIdentifier = `${shvPath}:${options.method}`;
447+
const shvPath = await resolveString(resourceOptions.shvPath);
448+
const resIdentifier = `${shvPath}:${resourceOptions.method}`;
446449
await initialize().catch((error: unknown) => {
447450
console.error(`Failed to initialize ${resIdentifier}`, error);
448451
});
@@ -451,8 +454,8 @@ export function useShv(options: VueShvOptions) {
451454
}
452455

453456
let res;
454-
if ('default' in options) {
455-
const defaultValue = options.default;
457+
if ('default' in resourceOptions) {
458+
const defaultValue = resourceOptions.default;
456459
const withDefault = computed(() => {
457460
if (resource.value === undefined) {
458461
return defaultValue;

0 commit comments

Comments
 (0)