@wisemen/vue-core-api-utils 1.0.0-beta.1 → 1.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 +386 -322
- package/dist/index.mjs +329 -248
- package/package.json +11 -5
- package/LICENSE +0 -21
- package/README.md +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
|
-
import { QueryClient } from "@tanstack/vue-query";
|
|
3
|
-
import
|
|
4
|
-
import { ComputedRef, MaybeRef, Ref, UnwrapRef } from "vue";
|
|
2
|
+
import { QueryClient as QueryClient$1, QueryClient as TanstackQueryClient, QueryClientConfig } from "@tanstack/vue-query";
|
|
3
|
+
import { App, ComputedRef, MaybeRef, Ref } from "vue";
|
|
5
4
|
|
|
6
5
|
//#region src/async-result/asyncResult.d.ts
|
|
7
6
|
/**
|
|
@@ -112,10 +111,8 @@ declare const AsyncResult: {
|
|
|
112
111
|
};
|
|
113
112
|
//#endregion
|
|
114
113
|
//#region src/types/apiError.type.d.ts
|
|
115
|
-
interface
|
|
116
|
-
|
|
117
|
-
interface ApiKnownErrorObject {
|
|
118
|
-
code: ApiErrorCode;
|
|
114
|
+
interface ApiKnownErrorObject<TCode extends string = string> {
|
|
115
|
+
code: TCode;
|
|
119
116
|
detail: string;
|
|
120
117
|
source?: {
|
|
121
118
|
pointer: string;
|
|
@@ -130,82 +127,17 @@ interface ApiUnknownErrorObject {
|
|
|
130
127
|
};
|
|
131
128
|
status: string;
|
|
132
129
|
}
|
|
133
|
-
type ApiErrorObject = ApiKnownErrorObject | ApiUnknownErrorObject;
|
|
134
|
-
interface ApiExpectedError {
|
|
135
|
-
errors: ApiErrorObject[];
|
|
130
|
+
type ApiErrorObject<TCode extends string = string> = ApiKnownErrorObject<TCode> | ApiUnknownErrorObject;
|
|
131
|
+
interface ApiExpectedError<TCode extends string = string> {
|
|
132
|
+
errors: ApiErrorObject<TCode>[];
|
|
136
133
|
}
|
|
137
134
|
type ApiUnexpectedError = Error;
|
|
138
|
-
type ApiError = ApiExpectedError | ApiUnexpectedError;
|
|
139
|
-
type ApiResult<T> = Result<T, ApiError
|
|
140
|
-
|
|
141
|
-
//#region src/types/queryKeys.type.d.ts
|
|
142
|
-
/**
|
|
143
|
-
* Base interface for defining query keys with their associated entities
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* declare module '@wisemen/vue-core-api-utils' {
|
|
148
|
-
* interface QueryKeys {
|
|
149
|
-
* userDetail: {
|
|
150
|
-
* params: { userUuid: ComputedRef<UserUuid> }
|
|
151
|
-
* entity: User
|
|
152
|
-
* }
|
|
153
|
-
* productList: {
|
|
154
|
-
* params: { category: ComputedRef<string> }
|
|
155
|
-
* entity: Product[]
|
|
156
|
-
* }
|
|
157
|
-
* }
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
interface QueryKeys {}
|
|
162
|
-
/**
|
|
163
|
-
* Generic helper types for libraries/factories that want to infer query key typing
|
|
164
|
-
* from a user-provided config object (instead of relying on module augmentation).
|
|
165
|
-
*/
|
|
166
|
-
/**
|
|
167
|
-
* Extract the entity type from a query-keys config for a specific key.
|
|
168
|
-
*/
|
|
169
|
-
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey extends PropertyKey> = TKey extends keyof TQueryKeys ? TQueryKeys[TKey] extends {
|
|
170
|
-
entity: infer E;
|
|
171
|
-
} ? E : never : never;
|
|
172
|
-
/**
|
|
173
|
-
* Extract the params type from a query-keys config for a specific key.
|
|
174
|
-
*/
|
|
175
|
-
type QueryKeyParamsFromConfig<TQueryKeys extends object, TKey extends PropertyKey> = TKey extends keyof TQueryKeys ? TQueryKeys[TKey] extends {
|
|
176
|
-
params: infer P;
|
|
177
|
-
} ? P : Record<string, never> : never;
|
|
178
|
-
/**
|
|
179
|
-
* Get all keys that have an associated entity in a query-keys config.
|
|
180
|
-
*/
|
|
181
|
-
type QueryKeysWithEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
|
|
182
|
-
entity: any;
|
|
183
|
-
} ? K : never }[keyof TQueryKeys]) & string;
|
|
184
|
-
/**
|
|
185
|
-
* Extract the parameters object from a query key definition
|
|
186
|
-
*/
|
|
187
|
-
type QueryKeyParams<TKey extends keyof QueryKeys> = QueryKeys[TKey] extends {
|
|
188
|
-
params: infer P;
|
|
189
|
-
} ? P : QueryKeys[TKey];
|
|
190
|
-
/**
|
|
191
|
-
* Extract the entity type from a query key definition
|
|
192
|
-
*/
|
|
193
|
-
type QueryKeyEntity<TKey extends keyof QueryKeys> = QueryKeys[TKey] extends {
|
|
194
|
-
entity: infer E;
|
|
195
|
-
} ? E : never;
|
|
196
|
-
/**
|
|
197
|
-
* Check if a query key has an associated entity
|
|
198
|
-
*/
|
|
199
|
-
type HasEntity<TKey extends keyof QueryKeys> = QueryKeys[TKey] extends {
|
|
200
|
-
entity: any;
|
|
201
|
-
} ? TKey : never;
|
|
202
|
-
/**
|
|
203
|
-
* Get all query keys that have an associated entity
|
|
204
|
-
*/
|
|
205
|
-
type QueryKeysWithEntity = { [K in keyof QueryKeys]: HasEntity<K> }[keyof QueryKeys];
|
|
135
|
+
type ApiError<TCode extends string = string> = ApiExpectedError<TCode> | ApiUnexpectedError;
|
|
136
|
+
type ApiResult<T, TCode extends string = string> = Result<T, ApiError<TCode>>;
|
|
137
|
+
type AsyncApiResult<T, TCode extends string = string> = AsyncResult<T, ApiError<TCode>>;
|
|
206
138
|
//#endregion
|
|
207
139
|
//#region src/composables/mutation/mutation.composable.d.ts
|
|
208
|
-
type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
140
|
+
type RequestParams$1<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
209
141
|
params: TParams;
|
|
210
142
|
} : TParams extends void ? {
|
|
211
143
|
body: TReqData;
|
|
@@ -213,25 +145,10 @@ type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends
|
|
|
213
145
|
body: TReqData;
|
|
214
146
|
params: TParams;
|
|
215
147
|
};
|
|
216
|
-
interface
|
|
217
|
-
/**
|
|
218
|
-
* Whether to enable debug mode
|
|
219
|
-
*/
|
|
220
|
-
isDebug?: boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Function that will be called to perform the mutation
|
|
223
|
-
* @param options - Parameters and body for the mutation
|
|
224
|
-
* @returns Promise with ApiResult containing either the response data or an error
|
|
225
|
-
*/
|
|
226
|
-
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData>>;
|
|
227
|
-
/**
|
|
228
|
-
* Array of query keys which should be invalidated after mutation is successful
|
|
229
|
-
*/
|
|
230
|
-
queryKeysToInvalidate: { [TQueryKey in keyof QueryKeys]?: { [TQueryKeyParam in keyof QueryKeys[TQueryKey]]: (params: TParams, data: TResData) => UnwrapRef<QueryKeys[TQueryKey][TQueryKeyParam]> } };
|
|
231
|
-
}
|
|
232
|
-
interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
148
|
+
interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode extends string = string> {
|
|
233
149
|
/**
|
|
234
150
|
* Whether mutation is loading
|
|
151
|
+
* @deprecated - use `result.value.isLoading()` instead
|
|
235
152
|
*/
|
|
236
153
|
isLoading: ComputedRef<boolean>;
|
|
237
154
|
/**
|
|
@@ -244,7 +161,7 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
|
244
161
|
* @param data - Parameters and body for the mutation
|
|
245
162
|
* @returns Promise with ApiResult containing either the response data or an error
|
|
246
163
|
*/
|
|
247
|
-
execute: (data: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData>>;
|
|
164
|
+
execute: (data: RequestParams$1<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
248
165
|
/**
|
|
249
166
|
* Computed result of the mutation
|
|
250
167
|
* Returns an AsyncResult with three states:
|
|
@@ -252,31 +169,36 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
|
252
169
|
* - ok: use `result.value.isOk()` and `result.value.getValue()`
|
|
253
170
|
* - err: use `result.value.isErr()` and `result.value.getError()`
|
|
254
171
|
*/
|
|
255
|
-
result: ComputedRef<AsyncResult<TResData, ApiError
|
|
172
|
+
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
256
173
|
}
|
|
257
|
-
declare function useMutation<TReqData = void, TResData = void, TParams = void>(options: UseMutationOptions<TReqData, TResData, TParams>): UseMutationReturnType<TReqData, TResData, TParams>;
|
|
258
174
|
//#endregion
|
|
259
175
|
//#region src/types/sort.type.d.ts
|
|
260
|
-
|
|
261
|
-
|
|
176
|
+
declare enum SortDirection {
|
|
177
|
+
ASC = "asc",
|
|
178
|
+
DESC = "desc",
|
|
179
|
+
}
|
|
180
|
+
interface Sort<TKey$1 extends string = string> {
|
|
262
181
|
direction: SortDirection;
|
|
263
|
-
key: TKey;
|
|
182
|
+
key: TKey$1;
|
|
264
183
|
}
|
|
265
184
|
//#endregion
|
|
266
|
-
//#region src/types/
|
|
185
|
+
//#region src/types/queryOptions.d.ts
|
|
267
186
|
interface QueryParams {
|
|
268
187
|
filters?: Record<string, any>;
|
|
269
188
|
search?: string;
|
|
270
189
|
sort?: Sort[];
|
|
271
190
|
}
|
|
272
191
|
interface WithSearchQuery {
|
|
273
|
-
search
|
|
192
|
+
search?: string | undefined;
|
|
274
193
|
}
|
|
275
194
|
interface WithSortQuery<TKeys extends string> {
|
|
276
195
|
sort: Sort<TKeys>[];
|
|
277
196
|
}
|
|
278
197
|
interface WithFilterQuery<TFilters extends Record<string, any>> {
|
|
279
|
-
filters
|
|
198
|
+
filters?: TFilters;
|
|
199
|
+
}
|
|
200
|
+
interface WithStaticFilterQuery<TFilters extends Record<string, any>> {
|
|
201
|
+
staticFilters: TFilters;
|
|
280
202
|
}
|
|
281
203
|
interface InfiniteQueryOptions<TParams> {
|
|
282
204
|
params: { [K in keyof TParams]: Ref<TParams[K]> };
|
|
@@ -311,8 +233,8 @@ interface KeysetPaginationResponse<TData> {
|
|
|
311
233
|
next: unknown;
|
|
312
234
|
};
|
|
313
235
|
}
|
|
314
|
-
type OffsetPaginationResult<TData> = ApiResult<OffsetPaginationResponse<TData
|
|
315
|
-
type KeysetPaginationResult<TData> = ApiResult<KeysetPaginationResponse<TData
|
|
236
|
+
type OffsetPaginationResult<TData, TErrorCode extends string = string> = ApiResult<OffsetPaginationResponse<TData>, TErrorCode>;
|
|
237
|
+
type KeysetPaginationResult<TData, TErrorCode extends string = string> = ApiResult<KeysetPaginationResponse<TData>, TErrorCode>;
|
|
316
238
|
interface PaginatedDataDto<TSchema> {
|
|
317
239
|
items: TSchema[];
|
|
318
240
|
meta: {
|
|
@@ -323,11 +245,7 @@ interface PaginatedDataDto<TSchema> {
|
|
|
323
245
|
}
|
|
324
246
|
//#endregion
|
|
325
247
|
//#region src/composables/query/keysetInfiniteQuery.composable.d.ts
|
|
326
|
-
|
|
327
|
-
type ExtractParams$2<T> = T extends {
|
|
328
|
-
params: infer P;
|
|
329
|
-
} ? P : T;
|
|
330
|
-
interface KeysetInfiniteQueryOptions<TData> {
|
|
248
|
+
interface KeysetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
|
|
331
249
|
/**
|
|
332
250
|
* The time in milliseconds after which the query will be considered stale
|
|
333
251
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -349,30 +267,63 @@ interface KeysetInfiniteQueryOptions<TData> {
|
|
|
349
267
|
* Function that will be called when query is executed
|
|
350
268
|
* @returns Promise with response data
|
|
351
269
|
*/
|
|
352
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData>>;
|
|
270
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData, TErrorCode>>;
|
|
353
271
|
/**
|
|
354
272
|
* Query key associated with the query
|
|
355
273
|
*/
|
|
356
|
-
queryKey:
|
|
274
|
+
queryKey: Record<string, unknown>;
|
|
357
275
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
276
|
+
interface UseKeysetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
|
|
277
|
+
/**
|
|
278
|
+
* Whether there is a next page available to fetch
|
|
279
|
+
*/
|
|
280
|
+
hasNextPage: ComputedRef<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* Whether query has errored at least once
|
|
283
|
+
* @deprecated - use `result.value.isErr()` instead
|
|
284
|
+
*/
|
|
285
|
+
isError: ComputedRef<boolean>;
|
|
286
|
+
/**
|
|
287
|
+
* Whether query is currently fetching data, regardless of cache status
|
|
288
|
+
*/
|
|
289
|
+
isFetching: ComputedRef<boolean>;
|
|
290
|
+
/**
|
|
291
|
+
* Whether query is currently fetching the next page
|
|
292
|
+
*/
|
|
293
|
+
isFetchingNextPage: ComputedRef<boolean>;
|
|
294
|
+
/**
|
|
295
|
+
* Whether query is initially loading
|
|
296
|
+
* @deprecated - use `result.value.isLoading()` instead
|
|
297
|
+
*/
|
|
298
|
+
isLoading: ComputedRef<boolean>;
|
|
299
|
+
/**
|
|
300
|
+
* Whether query has been executed successfully
|
|
301
|
+
* @deprecated - use `result.value.isOk()` instead
|
|
302
|
+
*/
|
|
303
|
+
isSuccess: ComputedRef<boolean>;
|
|
304
|
+
/**
|
|
305
|
+
* Fetch the next page of results using the keyset cursor
|
|
306
|
+
*/
|
|
365
307
|
fetchNextPage: () => Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Refetch the query
|
|
310
|
+
*/
|
|
366
311
|
refetch: () => Promise<void>;
|
|
367
|
-
|
|
368
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Computed result of the query containing all accumulated pages
|
|
314
|
+
* Returns an AsyncResult with three states:
|
|
315
|
+
* - loading: use `result.value.isLoading()`
|
|
316
|
+
* - ok: use `result.value.isOk()` and `result.value.getValue()`
|
|
317
|
+
* - err: use `result.value.isErr()` and `result.value.getError()`
|
|
318
|
+
*
|
|
319
|
+
* Use `result.value.match({ loading, ok, err })` for exhaustive handling
|
|
320
|
+
*/
|
|
321
|
+
result: ComputedRef<AsyncResult<KeysetPaginationResponse<TData>, ApiError<TErrorCode>>>;
|
|
322
|
+
}
|
|
323
|
+
declare function useKeysetInfiniteQuery<TData, TErrorCode extends string = string>(options: KeysetInfiniteQueryOptions<TData, TErrorCode>): UseKeysetInfiniteQueryReturnType<TData, TErrorCode>;
|
|
369
324
|
//#endregion
|
|
370
325
|
//#region src/composables/query/offsetInfiniteQuery.composable.d.ts
|
|
371
|
-
|
|
372
|
-
type ExtractParams$1<T> = T extends {
|
|
373
|
-
params: infer P;
|
|
374
|
-
} ? P : T;
|
|
375
|
-
interface OffsetInfiniteQueryOptions<TData> {
|
|
326
|
+
interface OffsetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
|
|
376
327
|
/**
|
|
377
328
|
* The time in milliseconds after which the query will be considered stale
|
|
378
329
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -394,30 +345,63 @@ interface OffsetInfiniteQueryOptions<TData> {
|
|
|
394
345
|
* Function that will be called when query is executed
|
|
395
346
|
* @returns Promise with response data
|
|
396
347
|
*/
|
|
397
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData>>;
|
|
348
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData, TErrorCode>>;
|
|
398
349
|
/**
|
|
399
350
|
* Query key associated with the query
|
|
400
351
|
*/
|
|
401
|
-
queryKey:
|
|
352
|
+
queryKey: Record<string, unknown>;
|
|
402
353
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
354
|
+
interface UseOffsetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
|
|
355
|
+
/**
|
|
356
|
+
* Whether there is a next page available to fetch
|
|
357
|
+
*/
|
|
358
|
+
hasNextPage: ComputedRef<boolean>;
|
|
359
|
+
/**
|
|
360
|
+
* Whether query has errored at least once
|
|
361
|
+
* @deprecated - use `result.value.isErr()` instead
|
|
362
|
+
*/
|
|
363
|
+
isError: ComputedRef<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* Whether query is currently fetching data, regardless of cache status
|
|
366
|
+
*/
|
|
367
|
+
isFetching: ComputedRef<boolean>;
|
|
368
|
+
/**
|
|
369
|
+
* Whether query is currently fetching the next page
|
|
370
|
+
*/
|
|
371
|
+
isFetchingNextPage: ComputedRef<boolean>;
|
|
372
|
+
/**
|
|
373
|
+
* Whether query is initially loading
|
|
374
|
+
* @deprecated - use `result.value.isLoading()` instead
|
|
375
|
+
*/
|
|
376
|
+
isLoading: ComputedRef<boolean>;
|
|
377
|
+
/**
|
|
378
|
+
* Whether query has been executed successfully
|
|
379
|
+
* @deprecated - use `result.value.isOk()` instead
|
|
380
|
+
*/
|
|
381
|
+
isSuccess: ComputedRef<boolean>;
|
|
382
|
+
/**
|
|
383
|
+
* Fetch the next page of results using offset-based pagination
|
|
384
|
+
*/
|
|
410
385
|
fetchNextPage: () => Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Refetch the query
|
|
388
|
+
*/
|
|
411
389
|
refetch: () => Promise<void>;
|
|
412
|
-
|
|
413
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Computed result of the query containing all accumulated pages
|
|
392
|
+
* Returns an AsyncResult with three states:
|
|
393
|
+
* - loading: use `result.value.isLoading()`
|
|
394
|
+
* - ok: use `result.value.isOk()` and `result.value.getValue()`
|
|
395
|
+
* - err: use `result.value.isErr()` and `result.value.getError()`
|
|
396
|
+
*
|
|
397
|
+
* Use `result.value.match({ loading, ok, err })` for exhaustive handling
|
|
398
|
+
*/
|
|
399
|
+
result: ComputedRef<AsyncResult<OffsetPaginationResponse<TData>, ApiError<TErrorCode>>>;
|
|
400
|
+
}
|
|
401
|
+
declare function useOffsetInfiniteQuery<TData, TErrorCode extends string = string>(options: OffsetInfiniteQueryOptions<TData, TErrorCode>): UseOffsetInfiniteQueryReturnType<TData, TErrorCode>;
|
|
414
402
|
//#endregion
|
|
415
403
|
//#region src/composables/query/query.composable.d.ts
|
|
416
|
-
|
|
417
|
-
type ExtractParams<T> = T extends {
|
|
418
|
-
params: infer P;
|
|
419
|
-
} ? P : T;
|
|
420
|
-
interface UseQueryOptions<TResData> {
|
|
404
|
+
interface UseQueryOptions<TResData, TErrorCode extends string = string> {
|
|
421
405
|
/**
|
|
422
406
|
* The time in milliseconds after which the query will be considered stale
|
|
423
407
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -440,13 +424,13 @@ interface UseQueryOptions<TResData> {
|
|
|
440
424
|
* Function that will be called when query is executed
|
|
441
425
|
* @returns Promise with response data
|
|
442
426
|
*/
|
|
443
|
-
queryFn: () => Promise<ApiResult<TResData>>;
|
|
427
|
+
queryFn: () => Promise<ApiResult<TResData, TErrorCode>>;
|
|
444
428
|
/**
|
|
445
429
|
* Query key associated with the query
|
|
446
430
|
*/
|
|
447
|
-
queryKey:
|
|
431
|
+
queryKey: Record<string, unknown>;
|
|
448
432
|
}
|
|
449
|
-
interface UseQueryReturnType<TResData> {
|
|
433
|
+
interface UseQueryReturnType<TResData, TErrorCode extends string = string> {
|
|
450
434
|
/**
|
|
451
435
|
* Whether query has errored at least once
|
|
452
436
|
* @deprecated - use `result.value.isErr()` instead
|
|
@@ -479,153 +463,232 @@ interface UseQueryReturnType<TResData> {
|
|
|
479
463
|
*
|
|
480
464
|
* Use `result.value.match({ loading, ok, err })` for exhaustive handling
|
|
481
465
|
*/
|
|
482
|
-
result: ComputedRef<AsyncResult<TResData, ApiError
|
|
466
|
+
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
483
467
|
}
|
|
484
|
-
declare function useQuery<TResData>(options: UseQueryOptions<TResData>): UseQueryReturnType<TResData>;
|
|
485
|
-
//#endregion
|
|
486
|
-
//#region src/composables/query/prefetchQuery.composable.d.ts
|
|
487
|
-
declare function usePrefetchQuery<TResData>(query: UseQueryOptions<TResData>): {
|
|
488
|
-
execute: () => Promise<void>;
|
|
489
|
-
};
|
|
490
468
|
//#endregion
|
|
491
469
|
//#region src/config/config.d.ts
|
|
470
|
+
/**
|
|
471
|
+
* Initialize the API utilities with a QueryClient.
|
|
472
|
+
* Call this once during app setup (e.g. in a plugin or main.ts).
|
|
473
|
+
*
|
|
474
|
+
* After calling this, `createApiUtils()` can be called without options.
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* import { initializeApiUtils } from '@wisemen/vue-core-api-utils'
|
|
479
|
+
*
|
|
480
|
+
* const queryClient = new QueryClient()
|
|
481
|
+
* initializeApiUtils(queryClient)
|
|
482
|
+
*
|
|
483
|
+
* // Then in your api lib:
|
|
484
|
+
* export const { useQuery, useMutation, ... } = createApiUtils<MyQueryKeys>()
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
declare function initializeApiUtils(queryClient: QueryClient$1): void;
|
|
488
|
+
/**
|
|
489
|
+
* @internal
|
|
490
|
+
*/
|
|
491
|
+
declare function getQueryClient(): QueryClient$1;
|
|
492
492
|
interface QueryConfig {
|
|
493
493
|
prefetchStaleTime: number;
|
|
494
494
|
limit: number;
|
|
495
495
|
}
|
|
496
496
|
declare function setQueryConfig(config: Partial<QueryConfig>): void;
|
|
497
497
|
//#endregion
|
|
498
|
+
//#region src/types/queryKeys.type.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* Generic helper types for libraries/factories that want to infer query key typing
|
|
501
|
+
* from a user-provided config object (instead of relying on module augmentation).
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* Extract the entity type from a query-keys config for a specific key.
|
|
505
|
+
*/
|
|
506
|
+
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
507
|
+
entity: infer E;
|
|
508
|
+
} ? E : never : never;
|
|
509
|
+
/**
|
|
510
|
+
* Extract the params type from a query-keys config for a specific key.
|
|
511
|
+
* Automatically wraps each param in Ref for reactivity.
|
|
512
|
+
*/
|
|
513
|
+
type QueryKeyParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
514
|
+
params: infer P;
|
|
515
|
+
} ? { [K in keyof P]: Ref<P[K]> } : void : never;
|
|
516
|
+
/**
|
|
517
|
+
* Extract the raw params type from a query-keys config for a specific key (unwrapped from Computed).
|
|
518
|
+
* Used for optimistic updates which accept plain values.
|
|
519
|
+
*/
|
|
520
|
+
type QueryKeyRawParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
521
|
+
params: infer P;
|
|
522
|
+
} ? P : void : never;
|
|
523
|
+
/**
|
|
524
|
+
* Get all keys that have an associated entity in a query-keys config.
|
|
525
|
+
*/
|
|
526
|
+
type QueryKeysWithEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
|
|
527
|
+
entity: any;
|
|
528
|
+
} ? K : never }[keyof TQueryKeys]) & string;
|
|
529
|
+
//#endregion
|
|
498
530
|
//#region src/factory/createApiUtils.types.d.ts
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Helper type to build the invalidation config for a specific query key
|
|
533
|
+
* Maps the query key's params to optional parameter extractors
|
|
534
|
+
*/
|
|
535
|
+
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] } : {};
|
|
502
536
|
type QueryKeysWithArrayEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
|
|
503
537
|
entity: any[];
|
|
504
538
|
} ? K : never }[keyof TQueryKeys]) & string;
|
|
505
|
-
type QueryKeyArrayItemFromConfig<TQueryKeys extends object, TKey extends PropertyKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey> extends (infer TItem)[] ? TItem : never;
|
|
506
|
-
type ApiUseQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithEntityFromConfig<TQueryKeys
|
|
539
|
+
type QueryKeyArrayItemFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1> extends (infer TItem)[] ? TItem : never;
|
|
540
|
+
type ApiUseQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
507
541
|
staleTime?: number;
|
|
508
542
|
isDebug?: boolean;
|
|
509
543
|
isEnabled?: MaybeRef<boolean>;
|
|
510
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey
|
|
511
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
512
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
544
|
+
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
545
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
546
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
513
547
|
} : {
|
|
514
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
548
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
515
549
|
});
|
|
516
|
-
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithEntityFromConfig<TQueryKeys
|
|
550
|
+
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
517
551
|
staleTime?: number;
|
|
518
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey
|
|
519
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
520
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
552
|
+
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
553
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
554
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
521
555
|
} : {
|
|
522
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
556
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
523
557
|
});
|
|
524
|
-
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
558
|
+
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
525
559
|
staleTime?: number;
|
|
526
560
|
isEnabled?: MaybeRef<boolean>;
|
|
527
561
|
limit?: number;
|
|
528
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey
|
|
529
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
530
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
562
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
563
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
564
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
531
565
|
} : {
|
|
532
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
566
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
533
567
|
});
|
|
534
|
-
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
568
|
+
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
535
569
|
staleTime?: number;
|
|
536
570
|
limit?: number;
|
|
537
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey
|
|
538
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
539
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
571
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
572
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
573
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
540
574
|
} : {
|
|
541
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
575
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
542
576
|
});
|
|
543
|
-
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
577
|
+
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
544
578
|
staleTime?: number;
|
|
545
579
|
isEnabled?: MaybeRef<boolean>;
|
|
546
580
|
limit?: number;
|
|
547
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey
|
|
548
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
549
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
581
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
582
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
583
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
550
584
|
} : {
|
|
551
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
585
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
552
586
|
});
|
|
553
|
-
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
587
|
+
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
554
588
|
staleTime?: number;
|
|
555
589
|
limit?: number;
|
|
556
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey
|
|
557
|
-
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends
|
|
558
|
-
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
590
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
591
|
+
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
592
|
+
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
559
593
|
} : {
|
|
560
|
-
params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
|
|
594
|
+
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
561
595
|
});
|
|
596
|
+
type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
597
|
+
params: TParams;
|
|
598
|
+
} : TParams extends void ? {
|
|
599
|
+
body: TReqData;
|
|
600
|
+
} : {
|
|
601
|
+
body: TReqData;
|
|
602
|
+
params: TParams;
|
|
603
|
+
};
|
|
604
|
+
interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, TParams = void, TErrorCode extends string = string> {
|
|
605
|
+
/**
|
|
606
|
+
* Whether to enable debug mode
|
|
607
|
+
*/
|
|
608
|
+
isDebug?: boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Function that will be called to perform the mutation
|
|
611
|
+
* @param options - Parameters and body for the mutation
|
|
612
|
+
* @returns Promise with ApiResult containing either the response data or an error
|
|
613
|
+
*/
|
|
614
|
+
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
615
|
+
/**
|
|
616
|
+
* Query keys which should be invalidated after mutation is successful
|
|
617
|
+
* Each key is optional and maps to the query key's specific parameters
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* queryKeysToInvalidate: {
|
|
621
|
+
* userDetail: {
|
|
622
|
+
* userUuid: (params, result) => params.userUuid,
|
|
623
|
+
* },
|
|
624
|
+
* userList: {},
|
|
625
|
+
* }
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
queryKeysToInvalidate?: { [TKey in keyof TQueryKeys]?: QueryKeyInvalidationConfig<TQueryKeys, TKey, TParams, TResData> };
|
|
629
|
+
}
|
|
630
|
+
interface CreateApiMutationUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
631
|
+
useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams>;
|
|
632
|
+
}
|
|
562
633
|
//#endregion
|
|
563
634
|
//#region src/factory/createApiInfiniteQueryUtils.d.ts
|
|
564
|
-
|
|
565
|
-
useKeysetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey>) =>
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
635
|
+
interface CreateApiInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
636
|
+
useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => ReturnType<typeof useKeysetInfiniteQuery<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
637
|
+
useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => ReturnType<typeof useOffsetInfiniteQuery<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
638
|
+
}
|
|
639
|
+
declare function createApiInfiniteQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiInfiniteQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/factory/createApiMutationUtils.d.ts
|
|
642
|
+
declare function createApiMutationUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiMutationUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region src/factory/createApiPrefetchInfiniteQueryUtils.d.ts
|
|
645
|
+
interface CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
646
|
+
usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
647
|
+
execute: () => Promise<void>;
|
|
575
648
|
};
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
isError: vue0.ComputedRef<boolean>;
|
|
579
|
-
isFetching: vue0.ComputedRef<boolean>;
|
|
580
|
-
isFetchingNextPage: vue0.ComputedRef<boolean>;
|
|
581
|
-
isLoading: vue0.ComputedRef<boolean>;
|
|
582
|
-
isSuccess: vue0.ComputedRef<boolean>;
|
|
583
|
-
fetchNextPage: () => Promise<void>;
|
|
584
|
-
refetch: () => Promise<void>;
|
|
585
|
-
result: vue0.ComputedRef<AsyncResult<OffsetPaginationResponse<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>, ApiError>>;
|
|
649
|
+
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
650
|
+
execute: () => Promise<void>;
|
|
586
651
|
};
|
|
587
|
-
}
|
|
652
|
+
}
|
|
653
|
+
declare function createApiPrefetchInfiniteQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
588
654
|
//#endregion
|
|
589
|
-
//#region src/
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
655
|
+
//#region src/factory/createApiPrefetchQueryUtils.d.ts
|
|
656
|
+
interface CreateApiPrefetchQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
657
|
+
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
658
|
+
execute: () => Promise<void>;
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
declare function createApiPrefetchQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiPrefetchQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/utils/query-client/queryClient.d.ts
|
|
594
664
|
/**
|
|
595
|
-
*
|
|
665
|
+
* Helper type to extract the item type from an entity (array item or entity itself)
|
|
596
666
|
*/
|
|
597
667
|
type EntityItem<TEntity> = TEntity extends any[] ? TEntity[number] : TEntity;
|
|
598
|
-
type MatchByKeyValue<TEntity> = Partial<{ [K in keyof EntityItem<TEntity>]: MaybeRef<UnwrapRef<EntityItem<TEntity>[K]>> }>;
|
|
599
668
|
/**
|
|
600
|
-
* Options for
|
|
669
|
+
* Options for type-safe query client update
|
|
601
670
|
*/
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Options for optimistic update
|
|
605
|
-
*/
|
|
606
|
-
interface OptimisticUpdateOptions<TEntity> {
|
|
671
|
+
interface QueryClientUpdateOptions<TEntity> {
|
|
607
672
|
/**
|
|
608
|
-
*
|
|
609
|
-
* - function: a predicate that returns true for the entity to update
|
|
610
|
-
* - object: key-value pairs to match (e.g., { id: '123' } or { uuid: 'abc' })
|
|
611
|
-
* - undefined: defaults to matching by 'id' from the value
|
|
673
|
+
* Predicate function that receives the current item and returns true if it should be updated
|
|
612
674
|
*/
|
|
613
|
-
by
|
|
675
|
+
by: (item: EntityItem<TEntity>) => boolean;
|
|
614
676
|
/**
|
|
615
|
-
*
|
|
677
|
+
* Function that receives the current item and returns the updated item
|
|
616
678
|
*/
|
|
617
|
-
value:
|
|
679
|
+
value: (item: EntityItem<TEntity>) => EntityItem<TEntity>;
|
|
618
680
|
}
|
|
619
681
|
/**
|
|
620
|
-
*
|
|
682
|
+
* QueryClient utility class for type-safe query operations
|
|
621
683
|
*/
|
|
622
|
-
declare class
|
|
684
|
+
declare class QueryClient<TQueryKeys extends object> {
|
|
623
685
|
private readonly queryClient;
|
|
624
|
-
constructor(queryClient: QueryClient);
|
|
686
|
+
constructor(queryClient: QueryClient$1);
|
|
625
687
|
/**
|
|
626
688
|
* Extract the raw entity from AsyncResult data
|
|
627
689
|
*/
|
|
628
690
|
private extractEntityFromAsyncResult;
|
|
691
|
+
private hasDataArray;
|
|
629
692
|
private isInfiniteDataLike;
|
|
630
693
|
/**
|
|
631
694
|
* Determine if an item should be updated
|
|
@@ -635,6 +698,7 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
635
698
|
* Internal method to update entity based on the "by" option
|
|
636
699
|
*/
|
|
637
700
|
private updateEntity;
|
|
701
|
+
private updateInfinitePageValue;
|
|
638
702
|
/**
|
|
639
703
|
* Wrap a raw entity in an AsyncResult (preserving ok state)
|
|
640
704
|
*/
|
|
@@ -650,22 +714,22 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
650
714
|
* @example
|
|
651
715
|
* ```typescript
|
|
652
716
|
* // Get all userDetail queries (returns array)
|
|
653
|
-
* const allUsers =
|
|
717
|
+
* const allUsers = queryClient.get('userDetail')
|
|
654
718
|
*
|
|
655
719
|
* // Get exact query stored as ['userDetail']
|
|
656
|
-
* const exactUser =
|
|
720
|
+
* const exactUser = queryClient.get('userDetail', { isExact: true })
|
|
657
721
|
*
|
|
658
722
|
* // Get specific userDetail query with params
|
|
659
|
-
* const user =
|
|
723
|
+
* const user = queryClient.get(['userDetail', { userUuid: '123' }] as const)
|
|
660
724
|
* ```
|
|
661
725
|
*/
|
|
662
|
-
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options?: {
|
|
726
|
+
get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, options?: {
|
|
663
727
|
isExact?: false;
|
|
664
|
-
}): QueryKeyEntityFromConfig<TQueryKeys, TKey>[];
|
|
665
|
-
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options: {
|
|
728
|
+
}): QueryKeyEntityFromConfig<TQueryKeys, TKey$1>[];
|
|
729
|
+
get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, options: {
|
|
666
730
|
isExact: true;
|
|
667
|
-
}): QueryKeyEntityFromConfig<TQueryKeys, TKey> | null;
|
|
668
|
-
get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<
|
|
731
|
+
}): QueryKeyEntityFromConfig<TQueryKeys, TKey$1> | null;
|
|
732
|
+
get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>]): QueryKeyEntityFromConfig<TQueryKeys, TKey$1> | null;
|
|
669
733
|
/**
|
|
670
734
|
* Invalidate queries to trigger a refetch
|
|
671
735
|
*
|
|
@@ -675,14 +739,14 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
675
739
|
* @example
|
|
676
740
|
* ```typescript
|
|
677
741
|
* // Invalidate all userDetail queries
|
|
678
|
-
* await
|
|
742
|
+
* await queryClient.invalidate('userDetail')
|
|
679
743
|
*
|
|
680
744
|
* // Invalidate specific query
|
|
681
|
-
* await
|
|
745
|
+
* await queryClient.invalidate(['userDetail', { userUuid: '123' }] as const)
|
|
682
746
|
* ```
|
|
683
747
|
*/
|
|
684
|
-
invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey): Promise<void>;
|
|
685
|
-
invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(keyTuple: readonly [TKey, Partial<
|
|
748
|
+
invalidate<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1): Promise<void>;
|
|
749
|
+
invalidate<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(keyTuple: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>]): Promise<void>;
|
|
686
750
|
/**
|
|
687
751
|
* Set raw entity data in the query cache for a specific query
|
|
688
752
|
* Automatically wraps the entity in AsyncResult
|
|
@@ -694,113 +758,113 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
694
758
|
* @example
|
|
695
759
|
* ```typescript
|
|
696
760
|
* // Set query with just the key
|
|
697
|
-
*
|
|
761
|
+
* queryClient.set('userDetail', userData)
|
|
698
762
|
*
|
|
699
763
|
* // Set query with key + params
|
|
700
|
-
*
|
|
764
|
+
* queryClient.set(['userDetail', { userUuid: '123' }] as const, userData)
|
|
701
765
|
* ```
|
|
702
766
|
*/
|
|
703
|
-
set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey>): void;
|
|
704
|
-
set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<
|
|
767
|
+
set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
|
|
768
|
+
set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>], entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
|
|
705
769
|
/**
|
|
706
|
-
* Update entity data in the query cache
|
|
770
|
+
* Update entity data in the query cache
|
|
707
771
|
*
|
|
708
772
|
* When using just the key, updates ALL queries with that key
|
|
709
773
|
* When using key + params tuple, updates SPECIFIC query
|
|
710
774
|
*
|
|
711
775
|
* @example
|
|
712
776
|
* ```typescript
|
|
713
|
-
* // Update
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
* })
|
|
717
|
-
*
|
|
718
|
-
* // Update specific query by key + params
|
|
719
|
-
* optimisticUpdates.update(['userDetail', { userUuid: '123' }] as const, {
|
|
720
|
-
* value: { name: 'John Doe' }
|
|
777
|
+
* // Update a specific user by id
|
|
778
|
+
* queryClient.update('userDetail', {
|
|
779
|
+
* by: (user) => user.id === '123',
|
|
780
|
+
* value: (user) => ({ ...user, name: 'John Doe' })
|
|
721
781
|
* })
|
|
722
782
|
*
|
|
723
|
-
* // Update
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
783
|
+
* // Update all electronics products to out of stock
|
|
784
|
+
* queryClient.update('productList', {
|
|
785
|
+
* by: (product) => product.category === 'electronics',
|
|
786
|
+
* value: (product) => ({ ...product, inStock: false })
|
|
727
787
|
* })
|
|
728
788
|
* ```
|
|
729
789
|
*/
|
|
730
|
-
update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(key: TKey, options:
|
|
731
|
-
update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(keyTuple: readonly [TKey, Partial<
|
|
790
|
+
update<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey$1> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>(key: TKey$1, options: QueryClientUpdateOptions<TEntity>): void;
|
|
791
|
+
update<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey$1> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>(keyTuple: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>], options: QueryClientUpdateOptions<TEntity>): void;
|
|
732
792
|
}
|
|
733
|
-
/**
|
|
734
|
-
* Create an OptimisticUpdates instance
|
|
735
|
-
*/
|
|
736
|
-
declare function createOptimisticUpdates(queryClient: QueryClient): OptimisticUpdates;
|
|
737
|
-
//#endregion
|
|
738
|
-
//#region src/factory/createApiOptimisticUpdatesUtils.d.ts
|
|
739
|
-
declare function createApiOptimisticUpdatesUtils<TQueryKeys extends object>(options: CreateApiUtilsOptions): {
|
|
740
|
-
useOptimisticUpdates: () => OptimisticUpdates<TQueryKeys>;
|
|
741
|
-
};
|
|
742
793
|
//#endregion
|
|
743
|
-
//#region src/factory/
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
usePrefetchOffsetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey>) => {
|
|
749
|
-
execute: () => Promise<void>;
|
|
750
|
-
};
|
|
751
|
-
};
|
|
752
|
-
//#endregion
|
|
753
|
-
//#region src/factory/createApiPrefetchQueryUtils.d.ts
|
|
754
|
-
declare function createApiPrefetchQueryUtils<TQueryKeys extends object>(options: CreateApiUtilsOptions): {
|
|
755
|
-
usePrefetchQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey>) => {
|
|
756
|
-
execute: () => Promise<void>;
|
|
757
|
-
};
|
|
758
|
-
};
|
|
794
|
+
//#region src/factory/createApiQueryClientUtils.d.ts
|
|
795
|
+
interface CreateApiQueryClientUtilsReturnType<TQueryKeys extends object> {
|
|
796
|
+
useQueryClient: () => QueryClient<TQueryKeys>;
|
|
797
|
+
}
|
|
798
|
+
declare function createApiQueryClientUtils<TQueryKeys extends object>(): CreateApiQueryClientUtilsReturnType<TQueryKeys>;
|
|
759
799
|
//#endregion
|
|
760
800
|
//#region src/factory/createApiQueryUtils.d.ts
|
|
761
|
-
|
|
762
|
-
useQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey>>;
|
|
763
|
-
}
|
|
801
|
+
interface CreateApiQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
|
|
802
|
+
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>;
|
|
803
|
+
}
|
|
804
|
+
declare function createApiQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
764
805
|
//#endregion
|
|
765
806
|
//#region src/factory/createApiUtils.d.ts
|
|
766
807
|
/**
|
|
767
808
|
* Factory that creates typed composables based on a user-provided query-keys config.
|
|
768
|
-
*
|
|
809
|
+
*
|
|
810
|
+
* Requires `initializeApiUtils(queryClient)` to be called first.
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* // In app setup (plugin or main.ts):
|
|
815
|
+
* initializeApiUtils(queryClient)
|
|
816
|
+
*
|
|
817
|
+
* // In your api lib:
|
|
818
|
+
* export const { useQuery, useMutation, useQueryClient } = createApiUtils<MyQueryKeys>()
|
|
819
|
+
* ```
|
|
769
820
|
*/
|
|
770
|
-
declare function createApiUtils<TQueryKeys extends object>(
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
isFetchingNextPage: vue0.ComputedRef<boolean>;
|
|
777
|
-
isLoading: vue0.ComputedRef<boolean>;
|
|
778
|
-
isSuccess: vue0.ComputedRef<boolean>;
|
|
779
|
-
fetchNextPage: () => Promise<void>;
|
|
780
|
-
refetch: () => Promise<void>;
|
|
781
|
-
result: vue0.ComputedRef<AsyncResult<KeysetPaginationResponse<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>, ApiError>>;
|
|
782
|
-
};
|
|
783
|
-
useOffsetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey>) => {
|
|
784
|
-
hasNextPage: vue0.ComputedRef<boolean>;
|
|
785
|
-
isError: vue0.ComputedRef<boolean>;
|
|
786
|
-
isFetching: vue0.ComputedRef<boolean>;
|
|
787
|
-
isFetchingNextPage: vue0.ComputedRef<boolean>;
|
|
788
|
-
isLoading: vue0.ComputedRef<boolean>;
|
|
789
|
-
isSuccess: vue0.ComputedRef<boolean>;
|
|
790
|
-
fetchNextPage: () => Promise<void>;
|
|
791
|
-
refetch: () => Promise<void>;
|
|
792
|
-
result: vue0.ComputedRef<AsyncResult<OffsetPaginationResponse<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>, ApiError>>;
|
|
793
|
-
};
|
|
794
|
-
usePrefetchKeysetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey>) => {
|
|
821
|
+
declare function createApiUtils<TQueryKeys extends object, TErrorCode extends string = string>(): {
|
|
822
|
+
useQueryClient: () => QueryClient<TQueryKeys>;
|
|
823
|
+
useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams, string>;
|
|
824
|
+
useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
825
|
+
useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
|
|
826
|
+
usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
795
827
|
execute: () => Promise<void>;
|
|
796
828
|
};
|
|
797
|
-
usePrefetchOffsetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey>) => {
|
|
829
|
+
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
798
830
|
execute: () => Promise<void>;
|
|
799
831
|
};
|
|
800
|
-
usePrefetchQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey>) => {
|
|
832
|
+
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
801
833
|
execute: () => Promise<void>;
|
|
802
834
|
};
|
|
803
|
-
useQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey
|
|
835
|
+
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, string>;
|
|
804
836
|
};
|
|
805
837
|
//#endregion
|
|
806
|
-
|
|
838
|
+
//#region src/plugin/apiUtilsPlugin.d.ts
|
|
839
|
+
/**
|
|
840
|
+
* Create a Vue plugin that sets up TanStack Query and initializes API utilities.
|
|
841
|
+
*
|
|
842
|
+
* This plugin handles:
|
|
843
|
+
* - Creating a QueryClient with the provided config
|
|
844
|
+
* - Installing VueQueryPlugin on the app
|
|
845
|
+
* - Initializing the global QueryClient for api-utils
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```typescript
|
|
849
|
+
* import { apiUtilsPlugin } from '@wisemen/vue-core-api-utils'
|
|
850
|
+
* import { vueQueryClientConfig } from '@wisemen/vue-core-configs'
|
|
851
|
+
*
|
|
852
|
+
* app.use(apiUtilsPlugin(vueQueryClientConfig()))
|
|
853
|
+
* ```
|
|
854
|
+
*
|
|
855
|
+
* @param config - QueryClient configuration
|
|
856
|
+
* @returns A Vue plugin that can be used with app.use()
|
|
857
|
+
*/
|
|
858
|
+
declare function apiUtilsPlugin(config: QueryClientConfig): {
|
|
859
|
+
install: (app: App<any>) => void;
|
|
860
|
+
};
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/utils/sort/sort.utils.d.ts
|
|
863
|
+
declare class SortUtil {
|
|
864
|
+
static toDto<SortKey extends string, QueryKey>(sort: Sort<SortKey>[], sortKeyMap: Record<SortKey, QueryKey>): {
|
|
865
|
+
key: QueryKey;
|
|
866
|
+
order: SortDirection;
|
|
867
|
+
}[];
|
|
868
|
+
}
|
|
869
|
+
//#endregion
|
|
870
|
+
export { ApiError, ApiErrorObject, ApiExpectedError, ApiKnownErrorObject, ApiResult, ApiUnexpectedError, ApiUnknownErrorObject, ApiUseKeysetInfinitePrefetchQueryOptions, ApiUseKeysetInfiniteQueryOptions, ApiUseMutationOptions, ApiUseOffsetInfinitePrefetchQueryOptions, ApiUseOffsetInfiniteQueryOptions, ApiUsePrefetchQueryOptions, ApiUseQueryOptions, AsyncApiResult, AsyncResult, AsyncResultErr, AsyncResultLoading, AsyncResultOk, type CreateApiInfiniteQueryUtilsReturnType, type CreateApiMutationUtilsReturnType, type CreateApiPrefetchInfiniteQueryUtilsReturnType, type CreateApiPrefetchQueryUtilsReturnType, type CreateApiQueryClientUtilsReturnType, type CreateApiQueryUtilsReturnType, type InfiniteQueryOptions, type KeysetInfiniteQueryOptions, KeysetPagination, KeysetPaginationParams, KeysetPaginationResponse, KeysetPaginationResult, type OffsetInfiniteQueryOptions, OffsetPagination, OffsetPaginationParams, OffsetPaginationResponse, OffsetPaginationResult, PaginatedDataDto, QueryClient, QueryClientUpdateOptions, type QueryConfig, QueryKeyArrayItemFromConfig, QueryKeysWithArrayEntityFromConfig, type QueryParams, Sort, SortDirection, SortUtil, type TanstackQueryClient, type UseMutationReturnType, type UseQueryOptions, type UseQueryReturnType, type WithFilterQuery, type WithSearchQuery, type WithSortQuery, type WithStaticFilterQuery, apiUtilsPlugin, createApiInfiniteQueryUtils, createApiMutationUtils, createApiPrefetchInfiniteQueryUtils, createApiPrefetchQueryUtils, createApiQueryClientUtils, createApiQueryUtils, createApiUtils, getQueryClient as getTanstackQueryClient, initializeApiUtils, setQueryConfig };
|