@wisemen/vue-core-api-utils 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +254 -281
- package/dist/index.mjs +13162 -353
- package/package.json +2 -2
- package/skills/asyncresult-handling/SKILL.md +6 -8
- package/skills/cache-management/SKILL.md +113 -76
- package/skills/foundations/SKILL.md +1 -2
- package/skills/getting-started/SKILL.md +55 -19
- package/skills/optimistic-uis/SKILL.md +107 -164
- package/skills/writing-infinitequeries/SKILL.md +108 -42
- package/skills/writing-mutations/SKILL.md +59 -34
- package/skills/writing-queries/SKILL.md +26 -14
package/dist/index.d.mts
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
2
|
import { QueryClient as QueryClient$1, QueryClient as TanstackQueryClient, QueryClientConfig } from "@tanstack/vue-query";
|
|
3
|
-
import { App, ComputedRef, MaybeRef, Ref } from "vue";
|
|
3
|
+
import { App, ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from "vue";
|
|
4
|
+
import z from "zod";
|
|
4
5
|
|
|
5
6
|
//#region src/async-result/asyncResult.d.ts
|
|
6
7
|
/**
|
|
7
8
|
* Base class for AsyncResult - internal use only.
|
|
8
9
|
* Use AsyncResult<T, E> as the public type.
|
|
9
10
|
*/
|
|
10
|
-
declare abstract class AsyncResultBase<T, E> {
|
|
11
|
-
protected readonly _error: E | undefined;
|
|
11
|
+
declare abstract class AsyncResultBase<T, E$1> {
|
|
12
|
+
protected readonly _error: E$1 | undefined;
|
|
12
13
|
protected readonly _status: 'err' | 'loading' | 'ok';
|
|
13
14
|
protected readonly _value: T | undefined;
|
|
14
|
-
protected constructor(status: 'err' | 'loading' | 'ok', value?: T, error?: E);
|
|
15
|
+
protected constructor(status: 'err' | 'loading' | 'ok', value?: T, error?: E$1);
|
|
15
16
|
/**
|
|
16
17
|
* Check if the result is an error (type predicate for narrowing)
|
|
17
18
|
*/
|
|
18
|
-
isErr(): this is AsyncResultErr<T, E>;
|
|
19
|
+
isErr(): this is AsyncResultErr<T, E$1>;
|
|
19
20
|
/**
|
|
20
21
|
* Check if the result is in loading state (type predicate for narrowing)
|
|
21
22
|
*/
|
|
22
|
-
isLoading(): this is AsyncResultLoading<T, E>;
|
|
23
|
+
isLoading(): this is AsyncResultLoading<T, E$1>;
|
|
23
24
|
/**
|
|
24
25
|
* Check if the result is a success (type predicate for narrowing)
|
|
25
26
|
*/
|
|
26
|
-
isOk(): this is AsyncResultOk<T, E>;
|
|
27
|
+
isOk(): this is AsyncResultOk<T, E$1>;
|
|
27
28
|
/**
|
|
28
29
|
* Map the success value to a new value
|
|
29
30
|
*/
|
|
30
|
-
map<U>(fn: (value: T) => U): AsyncResult<U, E>;
|
|
31
|
+
map<U>(fn: (value: T) => U): AsyncResult<U, E$1>;
|
|
31
32
|
/**
|
|
32
33
|
* Map the error to a new error
|
|
33
34
|
*/
|
|
34
|
-
mapErr<F>(fn: (error: E) => F): AsyncResult<T, F>;
|
|
35
|
+
mapErr<F>(fn: (error: E$1) => F): AsyncResult<T, F>;
|
|
35
36
|
/**
|
|
36
37
|
* Pattern match on all three states
|
|
37
38
|
*/
|
|
38
39
|
match<U>(handlers: {
|
|
39
|
-
err: (error: E) => U;
|
|
40
|
+
err: (error: E$1) => U;
|
|
40
41
|
loading: () => U;
|
|
41
42
|
ok: (value: T) => U;
|
|
42
43
|
}): U;
|
|
@@ -54,31 +55,31 @@ declare abstract class AsyncResultBase<T, E> {
|
|
|
54
55
|
/**
|
|
55
56
|
* AsyncResult representing an error state
|
|
56
57
|
*/
|
|
57
|
-
declare class AsyncResultErr<T, E> extends AsyncResultBase<T, E> {
|
|
58
|
+
declare class AsyncResultErr<T, E$1> extends AsyncResultBase<T, E$1> {
|
|
58
59
|
private constructor();
|
|
59
60
|
/** @internal */
|
|
60
|
-
static _create<T, E>(error: E): AsyncResultErr<T, E>;
|
|
61
|
+
static _create<T, E$1>(error: E$1): AsyncResultErr<T, E$1>;
|
|
61
62
|
/** Get the error value - only available after isErr() check */
|
|
62
|
-
getError(): E;
|
|
63
|
-
getResult(): Result<T, E>;
|
|
63
|
+
getError(): E$1;
|
|
64
|
+
getResult(): Result<T, E$1>;
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* AsyncResult representing a loading state
|
|
67
68
|
*/
|
|
68
|
-
declare class AsyncResultLoading<T, E> extends AsyncResultBase<T, E> {
|
|
69
|
+
declare class AsyncResultLoading<T, E$1> extends AsyncResultBase<T, E$1> {
|
|
69
70
|
private constructor();
|
|
70
71
|
/** @internal */
|
|
71
|
-
static _create<T, E>(): AsyncResultLoading<T, E>;
|
|
72
|
+
static _create<T, E$1>(): AsyncResultLoading<T, E$1>;
|
|
72
73
|
getResult(): null;
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* AsyncResult representing a success state
|
|
76
77
|
*/
|
|
77
|
-
declare class AsyncResultOk<T, E> extends AsyncResultBase<T, E> {
|
|
78
|
+
declare class AsyncResultOk<T, E$1> extends AsyncResultBase<T, E$1> {
|
|
78
79
|
private constructor();
|
|
79
80
|
/** @internal */
|
|
80
|
-
static _create<T, E>(value: T): AsyncResultOk<T, E>;
|
|
81
|
-
getResult(): Result<T, E>;
|
|
81
|
+
static _create<T, E$1>(value: T): AsyncResultOk<T, E$1>;
|
|
82
|
+
getResult(): Result<T, E$1>;
|
|
82
83
|
/** Get the success value - only available after isOk() check */
|
|
83
84
|
getValue(): T;
|
|
84
85
|
}
|
|
@@ -86,7 +87,7 @@ declare class AsyncResultOk<T, E> extends AsyncResultBase<T, E> {
|
|
|
86
87
|
* Union type of all AsyncResult states.
|
|
87
88
|
* Use isOk(), isErr(), or isLoading() to narrow to specific state.
|
|
88
89
|
*/
|
|
89
|
-
type AsyncResult<T, E> = AsyncResultErr<T, E> | AsyncResultLoading<T, E> | AsyncResultOk<T, E>;
|
|
90
|
+
type AsyncResult<T, E$1> = AsyncResultErr<T, E$1> | AsyncResultLoading<T, E$1> | AsyncResultOk<T, E$1>;
|
|
90
91
|
/**
|
|
91
92
|
* Static factory methods for creating AsyncResult instances.
|
|
92
93
|
* This pattern (same name for type and value) is intentional for ergonomic API.
|
|
@@ -95,21 +96,41 @@ declare const AsyncResult: {
|
|
|
95
96
|
/**
|
|
96
97
|
* Create a failed AsyncResult with error
|
|
97
98
|
*/
|
|
98
|
-
readonly err: <T, E>(error: E) => AsyncResultErr<T, E>;
|
|
99
|
+
readonly err: <T, E$1>(error: E$1) => AsyncResultErr<T, E$1>;
|
|
99
100
|
/**
|
|
100
101
|
* Create an AsyncResult from an existing neverthrow Result
|
|
101
102
|
*/
|
|
102
|
-
readonly fromResult: <T, E>(result: Result<T, E>) => AsyncResult<T, E>;
|
|
103
|
+
readonly fromResult: <T, E$1>(result: Result<T, E$1>) => AsyncResult<T, E$1>;
|
|
103
104
|
/**
|
|
104
105
|
* Create a loading AsyncResult
|
|
105
106
|
*/
|
|
106
|
-
readonly loading: <T, E>() => AsyncResultLoading<T, E>;
|
|
107
|
+
readonly loading: <T, E$1>() => AsyncResultLoading<T, E$1>;
|
|
107
108
|
/**
|
|
108
109
|
* Create a successful AsyncResult with data
|
|
109
110
|
*/
|
|
110
|
-
readonly ok: <T, E>(value: T) => AsyncResultOk<T, E>;
|
|
111
|
+
readonly ok: <T, E$1>(value: T) => AsyncResultOk<T, E$1>;
|
|
111
112
|
};
|
|
112
113
|
//#endregion
|
|
114
|
+
//#region src/register.d.ts
|
|
115
|
+
interface Register {}
|
|
116
|
+
type RegisteredQueryKeys = Register extends {
|
|
117
|
+
queryKeys: infer T;
|
|
118
|
+
} ? T extends object ? T : object : object;
|
|
119
|
+
type RegisteredErrorCodes = Register extends {
|
|
120
|
+
errorCodes: infer T;
|
|
121
|
+
} ? T extends string ? T : string : string;
|
|
122
|
+
type RegisteredApiUseMutationOptions<TReqData, TResData, TParams = void> = UseMutationOptions<TReqData, TResData, TParams, RegisteredErrorCodes>;
|
|
123
|
+
type RegisteredQueryKeyInput = { [K in keyof RegisteredQueryKeys]?: RegisteredQueryKeys[K] extends {
|
|
124
|
+
params: infer P;
|
|
125
|
+
} ? P : unknown };
|
|
126
|
+
type RegisteredQueryKeyConfig<TKey extends PropertyKey> = RegisteredQueryKeys extends Record<TKey, infer V> ? V : unknown;
|
|
127
|
+
type RegisteredQueryKeyEntity<TKey extends PropertyKey> = RegisteredQueryKeyConfig<TKey> extends {
|
|
128
|
+
entity: infer E;
|
|
129
|
+
} ? E : unknown;
|
|
130
|
+
type RegisteredQueryKeyParams<TKey extends PropertyKey> = RegisteredQueryKeyConfig<TKey> extends {
|
|
131
|
+
params: infer P;
|
|
132
|
+
} ? P : undefined;
|
|
133
|
+
//#endregion
|
|
113
134
|
//#region src/types/apiError.type.d.ts
|
|
114
135
|
interface ApiKnownErrorObject<TCode extends string = string> {
|
|
115
136
|
code: TCode;
|
|
@@ -137,7 +158,7 @@ type ApiResult<T, TCode extends string = string> = Result<T, ApiError<TCode>>;
|
|
|
137
158
|
type AsyncApiResult<T, TCode extends string = string> = AsyncResult<T, ApiError<TCode>>;
|
|
138
159
|
//#endregion
|
|
139
160
|
//#region src/composables/mutation/mutation.composable.d.ts
|
|
140
|
-
type RequestParams
|
|
161
|
+
type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
141
162
|
params: TParams;
|
|
142
163
|
} : TParams extends void ? {
|
|
143
164
|
body: TReqData;
|
|
@@ -145,7 +166,33 @@ type RequestParams$1<TReqData, TParams> = TReqData extends void ? TParams extend
|
|
|
145
166
|
body: TReqData;
|
|
146
167
|
params: TParams;
|
|
147
168
|
};
|
|
148
|
-
interface
|
|
169
|
+
interface UseMutationOptions<TReqData, TResData, TParams = void, TErrorCode extends string = RegisteredErrorCodes> {
|
|
170
|
+
/**
|
|
171
|
+
* Whether to enable debug mode
|
|
172
|
+
*/
|
|
173
|
+
isDebug?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Function that will be called to perform the mutation
|
|
176
|
+
* @param options - Parameters and body for the mutation
|
|
177
|
+
* @returns Promise with ApiResult containing either the response data or an error
|
|
178
|
+
*/
|
|
179
|
+
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
180
|
+
/**
|
|
181
|
+
* Object where each key is a query key to invalidate after mutation succeeds.
|
|
182
|
+
* Each query key can optionally have nested parameter extractors.
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* queryKeysToInvalidate: {
|
|
186
|
+
* contactDetail: {
|
|
187
|
+
* contactUuid: (params, result) => params.contactUuid,
|
|
188
|
+
* },
|
|
189
|
+
* contactIndex: {},
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
queryKeysToInvalidate?: { [K in keyof RegisteredQueryKeyInput]?: Record<string, (params: TParams, data: TResData) => any> };
|
|
194
|
+
}
|
|
195
|
+
interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode extends string = RegisteredErrorCodes> {
|
|
149
196
|
/**
|
|
150
197
|
* Whether mutation is loading
|
|
151
198
|
* @deprecated - use `result.value.isLoading()` instead
|
|
@@ -161,7 +208,7 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode e
|
|
|
161
208
|
* @param data - Parameters and body for the mutation
|
|
162
209
|
* @returns Promise with ApiResult containing either the response data or an error
|
|
163
210
|
*/
|
|
164
|
-
execute: (data: RequestParams
|
|
211
|
+
execute: (data: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
165
212
|
/**
|
|
166
213
|
* Computed result of the mutation
|
|
167
214
|
* Returns an AsyncResult with three states:
|
|
@@ -171,15 +218,16 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode e
|
|
|
171
218
|
*/
|
|
172
219
|
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
173
220
|
}
|
|
221
|
+
declare function useMutation<TReqData = void, TResData = void, TParams = void, TErrorCode extends string = RegisteredErrorCodes>(options: UseMutationOptions<TReqData, TResData, TParams, TErrorCode>): UseMutationReturnType<TReqData, TResData, TParams, TErrorCode>;
|
|
174
222
|
//#endregion
|
|
175
223
|
//#region src/types/sort.type.d.ts
|
|
176
224
|
declare enum SortDirection {
|
|
177
225
|
ASC = "asc",
|
|
178
226
|
DESC = "desc",
|
|
179
227
|
}
|
|
180
|
-
interface Sort<TKey
|
|
228
|
+
interface Sort<TKey extends string = string> {
|
|
181
229
|
direction: SortDirection;
|
|
182
|
-
key: TKey
|
|
230
|
+
key: TKey;
|
|
183
231
|
}
|
|
184
232
|
//#endregion
|
|
185
233
|
//#region src/types/queryOptions.d.ts
|
|
@@ -245,35 +293,38 @@ interface PaginatedDataDto<TSchema> {
|
|
|
245
293
|
}
|
|
246
294
|
//#endregion
|
|
247
295
|
//#region src/composables/query/keysetInfiniteQuery.composable.d.ts
|
|
248
|
-
|
|
296
|
+
type NestedMaybeRefOrGetter$2<T> = { [K in keyof T]: MaybeRefOrGetter<T[K]> };
|
|
297
|
+
type ArrayItemOf$1<E$1> = E$1 extends (infer I)[] ? I : E$1;
|
|
298
|
+
type EntityItemOf$1<TKey extends PropertyKey> = RegisteredQueryKeyConfig<TKey> extends {
|
|
299
|
+
entity: infer E;
|
|
300
|
+
} ? ArrayItemOf$1<E> : unknown;
|
|
301
|
+
type WithParams$5<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
302
|
+
params?: undefined;
|
|
303
|
+
} : {
|
|
304
|
+
params: NestedMaybeRefOrGetter$2<RegisteredQueryKeyParams<TKey>>;
|
|
305
|
+
};
|
|
306
|
+
type KeysetInfiniteQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
249
307
|
/**
|
|
250
308
|
* The time in milliseconds after which the query will be considered stale
|
|
251
|
-
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
252
309
|
* @default 0
|
|
253
310
|
*/
|
|
254
311
|
staleTime?: number;
|
|
255
312
|
/**
|
|
256
313
|
* Whether the query is enabled
|
|
257
|
-
* If false, the query will not be executed
|
|
258
314
|
* @default true
|
|
259
315
|
*/
|
|
260
316
|
isEnabled?: MaybeRef<boolean>;
|
|
261
317
|
/**
|
|
262
|
-
* Maximum number of items to fetch per page
|
|
318
|
+
* Maximum number of items to fetch per page
|
|
263
319
|
* @default 20
|
|
264
320
|
*/
|
|
265
321
|
limit?: number;
|
|
266
322
|
/**
|
|
267
323
|
* Function that will be called when query is executed
|
|
268
|
-
* @returns Promise with response data
|
|
269
324
|
*/
|
|
270
325
|
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData, TErrorCode>>;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
*/
|
|
274
|
-
queryKey: Record<string, unknown>;
|
|
275
|
-
}
|
|
276
|
-
interface UseKeysetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
|
|
326
|
+
} & WithParams$5<TKey>;
|
|
327
|
+
interface UseKeysetInfiniteQueryReturnType<TData, TErrorCode extends string = RegisteredErrorCodes> {
|
|
277
328
|
/**
|
|
278
329
|
* Whether there is a next page available to fetch
|
|
279
330
|
*/
|
|
@@ -320,37 +371,41 @@ interface UseKeysetInfiniteQueryReturnType<TData, TErrorCode extends string = st
|
|
|
320
371
|
*/
|
|
321
372
|
result: ComputedRef<AsyncResult<KeysetPaginationResponse<TData>, ApiError<TErrorCode>>>;
|
|
322
373
|
}
|
|
374
|
+
declare function useKeysetInfiniteQuery<TKey extends keyof RegisteredQueryKeys, TData = EntityItemOf$1<TKey>, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: KeysetInfiniteQueryOptions<TKey, TData, TErrorCode>): UseKeysetInfiniteQueryReturnType<TData, TErrorCode>;
|
|
323
375
|
//#endregion
|
|
324
376
|
//#region src/composables/query/offsetInfiniteQuery.composable.d.ts
|
|
325
|
-
|
|
377
|
+
type NestedMaybeRefOrGetter$1<T> = { [K in keyof T]: MaybeRefOrGetter<T[K]> };
|
|
378
|
+
type ArrayItemOf<E$1> = E$1 extends (infer I)[] ? I : E$1;
|
|
379
|
+
type EntityItemOf<TKey extends PropertyKey> = RegisteredQueryKeyConfig<TKey> extends {
|
|
380
|
+
entity: infer E;
|
|
381
|
+
} ? ArrayItemOf<E> : unknown;
|
|
382
|
+
type WithParams$4<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
383
|
+
params?: undefined;
|
|
384
|
+
} : {
|
|
385
|
+
params: NestedMaybeRefOrGetter$1<RegisteredQueryKeyParams<TKey>>;
|
|
386
|
+
};
|
|
387
|
+
type OffsetInfiniteQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
326
388
|
/**
|
|
327
389
|
* The time in milliseconds after which the query will be considered stale
|
|
328
|
-
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
329
390
|
* @default 0
|
|
330
391
|
*/
|
|
331
392
|
staleTime?: number;
|
|
332
393
|
/**
|
|
333
394
|
* Whether the query is enabled
|
|
334
|
-
* If false, the query will not be executed
|
|
335
395
|
* @default true
|
|
336
396
|
*/
|
|
337
397
|
isEnabled?: MaybeRef<boolean>;
|
|
338
398
|
/**
|
|
339
|
-
* Maximum number of items to fetch per page
|
|
399
|
+
* Maximum number of items to fetch per page
|
|
340
400
|
* @default 20
|
|
341
401
|
*/
|
|
342
402
|
limit?: number;
|
|
343
403
|
/**
|
|
344
404
|
* Function that will be called when query is executed
|
|
345
|
-
* @returns Promise with response data
|
|
346
405
|
*/
|
|
347
406
|
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData, TErrorCode>>;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
*/
|
|
351
|
-
queryKey: Record<string, unknown>;
|
|
352
|
-
}
|
|
353
|
-
interface UseOffsetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
|
|
407
|
+
} & WithParams$4<TKey>;
|
|
408
|
+
interface UseOffsetInfiniteQueryReturnType<TData, TErrorCode extends string = RegisteredErrorCodes> {
|
|
354
409
|
/**
|
|
355
410
|
* Whether there is a next page available to fetch
|
|
356
411
|
*/
|
|
@@ -397,38 +452,110 @@ interface UseOffsetInfiniteQueryReturnType<TData, TErrorCode extends string = st
|
|
|
397
452
|
*/
|
|
398
453
|
result: ComputedRef<AsyncResult<OffsetPaginationResponse<TData>, ApiError<TErrorCode>>>;
|
|
399
454
|
}
|
|
455
|
+
declare function useOffsetInfiniteQuery<TKey extends keyof RegisteredQueryKeys, TData = EntityItemOf<TKey>, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: OffsetInfiniteQueryOptions<TKey, TData, TErrorCode>): UseOffsetInfiniteQueryReturnType<TData, TErrorCode>;
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/composables/query/prefetchKeysetInfiniteQuery.composable.d.ts
|
|
458
|
+
type WithParams$3<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
459
|
+
params?: undefined;
|
|
460
|
+
} : {
|
|
461
|
+
params: RegisteredQueryKeyParams<TKey>;
|
|
462
|
+
};
|
|
463
|
+
type PrefetchKeysetInfiniteQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
464
|
+
/**
|
|
465
|
+
* The time in milliseconds after which the prefetched query will be considered stale
|
|
466
|
+
* @default config.prefetchStaleTime
|
|
467
|
+
*/
|
|
468
|
+
staleTime?: number;
|
|
469
|
+
/**
|
|
470
|
+
* Maximum number of items to fetch per page
|
|
471
|
+
* @default 20
|
|
472
|
+
*/
|
|
473
|
+
limit?: number;
|
|
474
|
+
/**
|
|
475
|
+
* Function that will be called when query is executed
|
|
476
|
+
*/
|
|
477
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData, TErrorCode>>;
|
|
478
|
+
} & WithParams$3<TKey>;
|
|
479
|
+
declare function usePrefetchKeysetInfiniteQuery<TKey extends keyof RegisteredQueryKeys, TData = unknown, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: PrefetchKeysetInfiniteQueryOptions<TKey, TData, TErrorCode>): {
|
|
480
|
+
execute: () => Promise<void>;
|
|
481
|
+
};
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/composables/query/prefetchOffsetInfiniteQuery.composable.d.ts
|
|
484
|
+
type WithParams$2<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
485
|
+
params?: undefined;
|
|
486
|
+
} : {
|
|
487
|
+
params: RegisteredQueryKeyParams<TKey>;
|
|
488
|
+
};
|
|
489
|
+
type PrefetchOffsetInfiniteQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
490
|
+
/**
|
|
491
|
+
* The time in milliseconds after which the prefetched query will be considered stale
|
|
492
|
+
* @default config.prefetchStaleTime
|
|
493
|
+
*/
|
|
494
|
+
staleTime?: number;
|
|
495
|
+
/**
|
|
496
|
+
* Maximum number of items to fetch per page
|
|
497
|
+
* @default 20
|
|
498
|
+
*/
|
|
499
|
+
limit?: number;
|
|
500
|
+
/**
|
|
501
|
+
* Function that will be called when query is executed
|
|
502
|
+
*/
|
|
503
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData, TErrorCode>>;
|
|
504
|
+
} & WithParams$2<TKey>;
|
|
505
|
+
declare function usePrefetchOffsetInfiniteQuery<TKey extends keyof RegisteredQueryKeys, TData = unknown, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: PrefetchOffsetInfiniteQueryOptions<TKey, TData, TErrorCode>): {
|
|
506
|
+
execute: () => Promise<void>;
|
|
507
|
+
};
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/composables/query/prefetchQuery.composable.d.ts
|
|
510
|
+
type WithParams$1<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
511
|
+
params?: undefined;
|
|
512
|
+
} : {
|
|
513
|
+
params: RegisteredQueryKeyParams<TKey>;
|
|
514
|
+
};
|
|
515
|
+
type UsePrefetchQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
516
|
+
/**
|
|
517
|
+
* The time in milliseconds after which the prefetched query will be considered stale
|
|
518
|
+
* @default config.prefetchStaleTime
|
|
519
|
+
*/
|
|
520
|
+
staleTime?: number;
|
|
521
|
+
/**
|
|
522
|
+
* Function that will be called when query is executed
|
|
523
|
+
*/
|
|
524
|
+
queryFn: () => Promise<ApiResult<TData, TErrorCode>>;
|
|
525
|
+
} & WithParams$1<TKey>;
|
|
526
|
+
declare function usePrefetchQuery<TKey extends keyof RegisteredQueryKeys, TData = unknown, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: UsePrefetchQueryOptions<TKey, TData, TErrorCode>): {
|
|
527
|
+
execute: () => Promise<void>;
|
|
528
|
+
};
|
|
400
529
|
//#endregion
|
|
401
530
|
//#region src/composables/query/query.composable.d.ts
|
|
402
|
-
|
|
531
|
+
type NestedMaybeRefOrGetter<T> = { [K in keyof T]: MaybeRefOrGetter<T[K]> };
|
|
532
|
+
type WithParams<TKey extends PropertyKey> = RegisteredQueryKeyParams<TKey> extends undefined ? {
|
|
533
|
+
params?: undefined;
|
|
534
|
+
} : {
|
|
535
|
+
params: NestedMaybeRefOrGetter<RegisteredQueryKeyParams<TKey>>;
|
|
536
|
+
};
|
|
537
|
+
type UseQueryOptions<TKey extends keyof RegisteredQueryKeys, TData, TErrorCode extends string = RegisteredErrorCodes> = {
|
|
403
538
|
/**
|
|
404
539
|
* The time in milliseconds after which the query will be considered stale
|
|
405
|
-
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
406
540
|
* @default 0
|
|
407
541
|
*/
|
|
408
542
|
staleTime?: number;
|
|
409
543
|
/**
|
|
410
544
|
* Whether to enable debug mode
|
|
411
|
-
* When enabled, the query key and parameters will be logged to the console
|
|
412
545
|
* @default false
|
|
413
546
|
*/
|
|
414
547
|
isDebug?: boolean;
|
|
415
548
|
/**
|
|
416
549
|
* Whether the query is enabled
|
|
417
|
-
* If false, the query will not be executed
|
|
418
550
|
* @default true
|
|
419
551
|
*/
|
|
420
552
|
isEnabled?: MaybeRef<boolean>;
|
|
421
553
|
/**
|
|
422
554
|
* Function that will be called when query is executed
|
|
423
|
-
* @returns Promise with response data
|
|
424
555
|
*/
|
|
425
|
-
queryFn: () => Promise<ApiResult<
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
*/
|
|
429
|
-
queryKey: Record<string, unknown>;
|
|
430
|
-
}
|
|
431
|
-
interface UseQueryReturnType<TResData, TErrorCode extends string = string> {
|
|
556
|
+
queryFn: () => Promise<ApiResult<TData, TErrorCode>>;
|
|
557
|
+
} & WithParams<TKey>;
|
|
558
|
+
interface UseQueryReturnType<TResData, TErrorCode extends string = RegisteredErrorCodes> {
|
|
432
559
|
/**
|
|
433
560
|
* Whether query has errored at least once
|
|
434
561
|
* @deprecated - use `result.value.isErr()` instead
|
|
@@ -463,6 +590,7 @@ interface UseQueryReturnType<TResData, TErrorCode extends string = string> {
|
|
|
463
590
|
*/
|
|
464
591
|
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
465
592
|
}
|
|
593
|
+
declare function useQuery<TKey extends keyof RegisteredQueryKeys, TData = RegisteredQueryKeyEntity<TKey>, TErrorCode extends string = RegisteredErrorCodes>(key: TKey, options: UseQueryOptions<TKey, TData, TErrorCode>): UseQueryReturnType<TData, TErrorCode>;
|
|
466
594
|
//#endregion
|
|
467
595
|
//#region src/config/config.d.ts
|
|
468
596
|
/**
|
|
@@ -493,6 +621,55 @@ interface QueryConfig {
|
|
|
493
621
|
}
|
|
494
622
|
declare function setQueryConfig(config: Partial<QueryConfig>): void;
|
|
495
623
|
//#endregion
|
|
624
|
+
//#region src/plugin/apiUtilsPlugin.d.ts
|
|
625
|
+
/**
|
|
626
|
+
* Create a Vue plugin that sets up TanStack Query and initializes API utilities.
|
|
627
|
+
*
|
|
628
|
+
* This plugin handles:
|
|
629
|
+
* - Creating a QueryClient with the provided config
|
|
630
|
+
* - Installing VueQueryPlugin on the app
|
|
631
|
+
* - Initializing the global QueryClient for api-utils
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
* ```typescript
|
|
635
|
+
* import { apiUtilsPlugin } from '@wisemen/vue-core-api-utils'
|
|
636
|
+
* import { vueQueryClientConfig } from '@wisemen/vue-core-configs'
|
|
637
|
+
*
|
|
638
|
+
* app.use(apiUtilsPlugin(vueQueryClientConfig()))
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @param config - QueryClient configuration
|
|
642
|
+
* @returns A Vue plugin that can be used with app.use()
|
|
643
|
+
*/
|
|
644
|
+
declare function apiUtilsPlugin(config: QueryClientConfig): {
|
|
645
|
+
install: (app: App<any>) => void;
|
|
646
|
+
};
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/utils/api/api.util.d.ts
|
|
649
|
+
declare class ApiUtil {
|
|
650
|
+
static fromPromise<T>(promise: PromiseLike<T>, message?: string): Promise<ApiResult<T, RegisteredErrorCodes>>;
|
|
651
|
+
static getKeysetPaginationNextOffset(keysetPaginationMeta: KeysetPaginationResponse<any>['meta']): number | null;
|
|
652
|
+
static getResultError(result: AsyncResult<unknown, ApiError> | Result<unknown, ApiError> | null): ApiError<RegisteredErrorCodes> | null;
|
|
653
|
+
private static isAsyncResult;
|
|
654
|
+
static void<T, TApiResult extends ApiResult<void>>(result: ApiResult<T>): TApiResult;
|
|
655
|
+
}
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/utils/api-error/apiError.util.d.ts
|
|
658
|
+
declare class ApiErrorUtil {
|
|
659
|
+
static getApiErrorCode(error: ApiExpectedError): string | null;
|
|
660
|
+
static getApiErrorMessage(error: ApiExpectedError): string | null;
|
|
661
|
+
static getMessage(error: ApiExpectedError): string | null;
|
|
662
|
+
static handleApiError({
|
|
663
|
+
error,
|
|
664
|
+
message
|
|
665
|
+
}: {
|
|
666
|
+
error: unknown;
|
|
667
|
+
message?: string;
|
|
668
|
+
}): ApiError<RegisteredErrorCodes>;
|
|
669
|
+
static isExpectedApiError(error: unknown): error is ApiExpectedError<RegisteredErrorCodes>;
|
|
670
|
+
static isZodError(error: unknown): error is z.ZodError;
|
|
671
|
+
}
|
|
672
|
+
//#endregion
|
|
496
673
|
//#region src/types/queryKeys.type.d.ts
|
|
497
674
|
/**
|
|
498
675
|
* Generic helper types for libraries/factories that want to infer query key typing
|
|
@@ -501,21 +678,14 @@ declare function setQueryConfig(config: Partial<QueryConfig>): void;
|
|
|
501
678
|
/**
|
|
502
679
|
* Extract the entity type from a query-keys config for a specific key.
|
|
503
680
|
*/
|
|
504
|
-
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey
|
|
681
|
+
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey extends PropertyKey> = TKey extends keyof TQueryKeys ? TQueryKeys[TKey] extends {
|
|
505
682
|
entity: infer E;
|
|
506
683
|
} ? E : never : never;
|
|
507
|
-
/**
|
|
508
|
-
* Extract the params type from a query-keys config for a specific key.
|
|
509
|
-
* Automatically wraps each param in Ref for reactivity.
|
|
510
|
-
*/
|
|
511
|
-
type QueryKeyParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
512
|
-
params: infer P;
|
|
513
|
-
} ? { [K in keyof P]: Ref<P[K]> } : void : never;
|
|
514
684
|
/**
|
|
515
685
|
* Extract the raw params type from a query-keys config for a specific key (unwrapped from Computed).
|
|
516
686
|
* Used for optimistic updates which accept plain values.
|
|
517
687
|
*/
|
|
518
|
-
type QueryKeyRawParamsFromConfig<TQueryKeys extends object, TKey
|
|
688
|
+
type QueryKeyRawParamsFromConfig<TQueryKeys extends object, TKey extends PropertyKey> = TKey extends keyof TQueryKeys ? TQueryKeys[TKey] extends {
|
|
519
689
|
params: infer P;
|
|
520
690
|
} ? P : void : never;
|
|
521
691
|
/**
|
|
@@ -525,137 +695,6 @@ type QueryKeysWithEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof T
|
|
|
525
695
|
entity: any;
|
|
526
696
|
} ? K : never }[keyof TQueryKeys]) & string;
|
|
527
697
|
//#endregion
|
|
528
|
-
//#region src/factory/createApiUtils.types.d.ts
|
|
529
|
-
/**
|
|
530
|
-
* Helper type to build the invalidation config for a specific query key
|
|
531
|
-
* Maps the query key's params to optional parameter extractors
|
|
532
|
-
*/
|
|
533
|
-
type QueryKeyInvalidationConfig<TQueryKeys extends object, TKey$1 extends keyof TQueryKeys, TParams, TResData> = QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string> extends void ? {} : QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string> extends object ? { [ParamKey in keyof QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string>]?: (params: TParams, data: TResData) => QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string>[ParamKey] } : {};
|
|
534
|
-
type QueryKeysWithArrayEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
|
|
535
|
-
entity: any[];
|
|
536
|
-
} ? K : never }[keyof TQueryKeys]) & string;
|
|
537
|
-
type QueryKeyArrayItemFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1> extends (infer TItem)[] ? TItem : never;
|
|
538
|
-
type ApiUseQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
539
|
-
staleTime?: number;
|
|
540
|
-
isDebug?: boolean;
|
|
541
|
-
isEnabled?: MaybeRef<boolean>;
|
|
542
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
543
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
544
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
545
|
-
} : {
|
|
546
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
547
|
-
});
|
|
548
|
-
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
549
|
-
staleTime?: number;
|
|
550
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
551
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
552
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
553
|
-
} : {
|
|
554
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
555
|
-
});
|
|
556
|
-
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
557
|
-
staleTime?: number;
|
|
558
|
-
isEnabled?: MaybeRef<boolean>;
|
|
559
|
-
limit?: number;
|
|
560
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
561
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
562
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
563
|
-
} : {
|
|
564
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
565
|
-
});
|
|
566
|
-
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
567
|
-
staleTime?: number;
|
|
568
|
-
limit?: number;
|
|
569
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
570
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
571
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
572
|
-
} : {
|
|
573
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
574
|
-
});
|
|
575
|
-
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
576
|
-
staleTime?: number;
|
|
577
|
-
isEnabled?: MaybeRef<boolean>;
|
|
578
|
-
limit?: number;
|
|
579
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
580
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
581
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
582
|
-
} : {
|
|
583
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
584
|
-
});
|
|
585
|
-
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
586
|
-
staleTime?: number;
|
|
587
|
-
limit?: number;
|
|
588
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
589
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
590
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
591
|
-
} : {
|
|
592
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
593
|
-
});
|
|
594
|
-
type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
595
|
-
params: TParams;
|
|
596
|
-
} : TParams extends void ? {
|
|
597
|
-
body: TReqData;
|
|
598
|
-
} : {
|
|
599
|
-
body: TReqData;
|
|
600
|
-
params: TParams;
|
|
601
|
-
};
|
|
602
|
-
interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, TParams = void, TErrorCode extends string = string> {
|
|
603
|
-
/**
|
|
604
|
-
* Whether to enable debug mode
|
|
605
|
-
*/
|
|
606
|
-
isDebug?: boolean;
|
|
607
|
-
/**
|
|
608
|
-
* Function that will be called to perform the mutation
|
|
609
|
-
* @param options - Parameters and body for the mutation
|
|
610
|
-
* @returns Promise with ApiResult containing either the response data or an error
|
|
611
|
-
*/
|
|
612
|
-
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
613
|
-
/**
|
|
614
|
-
* Query keys which should be invalidated after mutation is successful
|
|
615
|
-
* Each key is optional and maps to the query key's specific parameters
|
|
616
|
-
* @example
|
|
617
|
-
* ```typescript
|
|
618
|
-
* queryKeysToInvalidate: {
|
|
619
|
-
* userDetail: {
|
|
620
|
-
* userUuid: (params, result) => params.userUuid,
|
|
621
|
-
* },
|
|
622
|
-
* userList: {},
|
|
623
|
-
* }
|
|
624
|
-
* ```
|
|
625
|
-
*/
|
|
626
|
-
queryKeysToInvalidate?: { [TKey in keyof TQueryKeys]?: QueryKeyInvalidationConfig<TQueryKeys, TKey, TParams, TResData> };
|
|
627
|
-
}
|
|
628
|
-
//#endregion
|
|
629
|
-
//#region src/factory/createApiInfiniteQueryUtils.d.ts
|
|
630
|
-
interface CreateApiInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
631
|
-
useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
632
|
-
useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
633
|
-
}
|
|
634
|
-
type ApiUseKeysetInfiniteQueryReturnType<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
635
|
-
type ApiUseOffsetInfiniteQueryReturnType<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
636
|
-
//#endregion
|
|
637
|
-
//#region src/factory/createApiMutationUtils.d.ts
|
|
638
|
-
interface CreateApiMutationUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
639
|
-
useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams, TErrorCode>;
|
|
640
|
-
}
|
|
641
|
-
//#endregion
|
|
642
|
-
//#region src/factory/createApiPrefetchInfiniteQueryUtils.d.ts
|
|
643
|
-
interface CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
644
|
-
usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
645
|
-
execute: () => Promise<void>;
|
|
646
|
-
};
|
|
647
|
-
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
648
|
-
execute: () => Promise<void>;
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
//#endregion
|
|
652
|
-
//#region src/factory/createApiPrefetchQueryUtils.d.ts
|
|
653
|
-
interface CreateApiPrefetchQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
654
|
-
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
655
|
-
execute: () => Promise<void>;
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
//#endregion
|
|
659
698
|
//#region src/utils/query-client/queryClient.d.ts
|
|
660
699
|
/**
|
|
661
700
|
* Helper type to extract the item type from an entity (array item or entity itself)
|
|
@@ -729,13 +768,13 @@ declare class QueryClient<TQueryKeys extends object> {
|
|
|
729
768
|
* const user = queryClient.get(['userDetail', { userUuid: '123' }] as const)
|
|
730
769
|
* ```
|
|
731
770
|
*/
|
|
732
|
-
get<TKey
|
|
771
|
+
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options?: {
|
|
733
772
|
isExact?: false;
|
|
734
|
-
}): QueryKeyEntityFromConfig<TQueryKeys, TKey
|
|
735
|
-
get<TKey
|
|
773
|
+
}): QueryKeyEntityFromConfig<TQueryKeys, TKey>[];
|
|
774
|
+
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options: {
|
|
736
775
|
isExact: true;
|
|
737
|
-
}): QueryKeyEntityFromConfig<TQueryKeys, TKey
|
|
738
|
-
get<TKey
|
|
776
|
+
}): QueryKeyEntityFromConfig<TQueryKeys, TKey> | null;
|
|
777
|
+
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey>>]): QueryKeyEntityFromConfig<TQueryKeys, TKey> | null;
|
|
739
778
|
/**
|
|
740
779
|
* Invalidate queries to trigger a refetch
|
|
741
780
|
*
|
|
@@ -751,8 +790,8 @@ declare class QueryClient<TQueryKeys extends object> {
|
|
|
751
790
|
* await queryClient.invalidate(['userDetail', { userUuid: '123' }] as const)
|
|
752
791
|
* ```
|
|
753
792
|
*/
|
|
754
|
-
invalidate<TKey
|
|
755
|
-
invalidate<TKey
|
|
793
|
+
invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey): Promise<void>;
|
|
794
|
+
invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(keyTuple: readonly [TKey, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey>>]): Promise<void>;
|
|
756
795
|
/**
|
|
757
796
|
* Set raw entity data in the query cache for a specific query
|
|
758
797
|
* Automatically wraps the entity in AsyncResult
|
|
@@ -770,8 +809,8 @@ declare class QueryClient<TQueryKeys extends object> {
|
|
|
770
809
|
* queryClient.set(['userDetail', { userUuid: '123' }] as const, userData)
|
|
771
810
|
* ```
|
|
772
811
|
*/
|
|
773
|
-
set<TKey
|
|
774
|
-
set<TKey
|
|
812
|
+
set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey>): void;
|
|
813
|
+
set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey>>], entity: QueryKeyEntityFromConfig<TQueryKeys, TKey>): void;
|
|
775
814
|
/**
|
|
776
815
|
* Update entity data in the query cache
|
|
777
816
|
*
|
|
@@ -796,76 +835,10 @@ declare class QueryClient<TQueryKeys extends object> {
|
|
|
796
835
|
* })
|
|
797
836
|
* ```
|
|
798
837
|
*/
|
|
799
|
-
update<TKey
|
|
800
|
-
update<TKey
|
|
801
|
-
}
|
|
802
|
-
//#endregion
|
|
803
|
-
//#region src/factory/createApiQueryClientUtils.d.ts
|
|
804
|
-
interface CreateApiQueryClientUtilsReturnType<TQueryKeys extends object> {
|
|
805
|
-
useQueryClient: () => QueryClient<TQueryKeys>;
|
|
838
|
+
update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(key: TKey, options: QueryClientUpdateOptions<TEntity>): QueryClientUpdateResult;
|
|
839
|
+
update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(keyTuple: readonly [TKey, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey>>], options: QueryClientUpdateOptions<TEntity>): QueryClientUpdateResult;
|
|
806
840
|
}
|
|
807
841
|
//#endregion
|
|
808
|
-
//#region src/factory/createApiQueryUtils.d.ts
|
|
809
|
-
interface CreateApiQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
810
|
-
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>;
|
|
811
|
-
}
|
|
812
|
-
//#endregion
|
|
813
|
-
//#region src/factory/createApiUtils.d.ts
|
|
814
|
-
/**
|
|
815
|
-
* Factory that creates typed composables based on a user-provided query-keys config.
|
|
816
|
-
*
|
|
817
|
-
* Requires `initializeApiUtils(queryClient)` to be called first.
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* ```typescript
|
|
821
|
-
* // In app setup (plugin or main.ts):
|
|
822
|
-
* initializeApiUtils(queryClient)
|
|
823
|
-
*
|
|
824
|
-
* // In your api lib:
|
|
825
|
-
* export const { useQuery, useMutation, useQueryClient } = createApiUtils<MyQueryKeys>()
|
|
826
|
-
* ```
|
|
827
|
-
*/
|
|
828
|
-
declare function createApiUtils<TQueryKeys extends object, TErrorCode extends string = string>(): {
|
|
829
|
-
useQueryClient: () => QueryClient<TQueryKeys>;
|
|
830
|
-
useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams, TErrorCode>;
|
|
831
|
-
useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
832
|
-
useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
833
|
-
usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
834
|
-
execute: () => Promise<void>;
|
|
835
|
-
};
|
|
836
|
-
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
837
|
-
execute: () => Promise<void>;
|
|
838
|
-
};
|
|
839
|
-
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
840
|
-
execute: () => Promise<void>;
|
|
841
|
-
};
|
|
842
|
-
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, string>;
|
|
843
|
-
};
|
|
844
|
-
//#endregion
|
|
845
|
-
//#region src/plugin/apiUtilsPlugin.d.ts
|
|
846
|
-
/**
|
|
847
|
-
* Create a Vue plugin that sets up TanStack Query and initializes API utilities.
|
|
848
|
-
*
|
|
849
|
-
* This plugin handles:
|
|
850
|
-
* - Creating a QueryClient with the provided config
|
|
851
|
-
* - Installing VueQueryPlugin on the app
|
|
852
|
-
* - Initializing the global QueryClient for api-utils
|
|
853
|
-
*
|
|
854
|
-
* @example
|
|
855
|
-
* ```typescript
|
|
856
|
-
* import { apiUtilsPlugin } from '@wisemen/vue-core-api-utils'
|
|
857
|
-
* import { vueQueryClientConfig } from '@wisemen/vue-core-configs'
|
|
858
|
-
*
|
|
859
|
-
* app.use(apiUtilsPlugin(vueQueryClientConfig()))
|
|
860
|
-
* ```
|
|
861
|
-
*
|
|
862
|
-
* @param config - QueryClient configuration
|
|
863
|
-
* @returns A Vue plugin that can be used with app.use()
|
|
864
|
-
*/
|
|
865
|
-
declare function apiUtilsPlugin(config: QueryClientConfig): {
|
|
866
|
-
install: (app: App<any>) => void;
|
|
867
|
-
};
|
|
868
|
-
//#endregion
|
|
869
842
|
//#region src/utils/sort/sort.utils.d.ts
|
|
870
843
|
declare class SortUtil {
|
|
871
844
|
static toDto<SortKey extends string, QueryKey>(sort: Sort<SortKey>[], sortKeyMap: Record<SortKey, QueryKey>): {
|
|
@@ -874,4 +847,4 @@ declare class SortUtil {
|
|
|
874
847
|
}[];
|
|
875
848
|
}
|
|
876
849
|
//#endregion
|
|
877
|
-
export { type
|
|
850
|
+
export { type ApiError, type ApiErrorObject, ApiErrorUtil, type ApiExpectedError, type ApiKnownErrorObject, type ApiResult, type ApiUnexpectedError, type ApiUnknownErrorObject, ApiUtil, type AsyncApiResult, AsyncResult, AsyncResultErr, AsyncResultLoading, AsyncResultOk, type InfiniteQueryOptions, type KeysetInfiniteQueryOptions, type KeysetPagination, type KeysetPaginationParams, type KeysetPaginationResponse, type KeysetPaginationResult, type OffsetInfiniteQueryOptions, type OffsetPagination, type OffsetPaginationParams, type OffsetPaginationResponse, type OffsetPaginationResult, type PaginatedDataDto, type PrefetchKeysetInfiniteQueryOptions, type PrefetchOffsetInfiniteQueryOptions, QueryClient, type QueryClientUpdateOptions, type QueryClientUpdateResult, type QueryConfig, type QueryParams, type Register, type RegisteredApiUseMutationOptions, type RegisteredErrorCodes, type RegisteredQueryKeyInput, type RegisteredQueryKeys, type Sort, SortDirection, SortUtil, type TanstackQueryClient, type UseKeysetInfiniteQueryReturnType, type UseMutationOptions, type UseMutationReturnType, type UseOffsetInfiniteQueryReturnType, type UseQueryOptions, type UseQueryReturnType, type WithFilterQuery, type WithSearchQuery, type WithSortQuery, type WithStaticFilterQuery, apiUtilsPlugin, getQueryClient as getTanstackQueryClient, initializeApiUtils, setQueryConfig, useKeysetInfiniteQuery, useMutation, useOffsetInfiniteQuery, usePrefetchKeysetInfiniteQuery, usePrefetchOffsetInfiniteQuery, usePrefetchQuery, useQuery };
|