@wisemen/vue-core-api-utils 1.0.0-beta.2 → 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 +319 -270
- package/dist/index.mjs +316 -261
- 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,13 +127,14 @@ 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
|
|
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>>;
|
|
140
138
|
//#endregion
|
|
141
139
|
//#region src/composables/mutation/mutation.composable.d.ts
|
|
142
140
|
type RequestParams$1<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
|
|
@@ -147,35 +145,10 @@ type RequestParams$1<TReqData, TParams> = TReqData extends void ? TParams extend
|
|
|
147
145
|
body: TReqData;
|
|
148
146
|
params: TParams;
|
|
149
147
|
};
|
|
150
|
-
interface
|
|
151
|
-
/**
|
|
152
|
-
* Whether to enable debug mode
|
|
153
|
-
*/
|
|
154
|
-
isDebug?: boolean;
|
|
155
|
-
/**
|
|
156
|
-
* Function that will be called to perform the mutation
|
|
157
|
-
* @param options - Parameters and body for the mutation
|
|
158
|
-
* @returns Promise with ApiResult containing either the response data or an error
|
|
159
|
-
*/
|
|
160
|
-
queryFn: (options: RequestParams$1<TReqData, TParams>) => Promise<ApiResult<TResData>>;
|
|
161
|
-
/**
|
|
162
|
-
* Object where each key is a query key to invalidate after mutation succeeds.
|
|
163
|
-
* Each query key can optionally have nested parameter extractors.
|
|
164
|
-
* @example
|
|
165
|
-
* ```typescript
|
|
166
|
-
* queryKeysToInvalidate: {
|
|
167
|
-
* contactDetail: {
|
|
168
|
-
* contactUuid: (params, result) => params.contactUuid,
|
|
169
|
-
* },
|
|
170
|
-
* contactIndex: {},
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
queryKeysToInvalidate?: Record<string, Record<string, (params: TParams, data: TResData) => any> | undefined>;
|
|
175
|
-
}
|
|
176
|
-
interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
148
|
+
interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode extends string = string> {
|
|
177
149
|
/**
|
|
178
150
|
* Whether mutation is loading
|
|
151
|
+
* @deprecated - use `result.value.isLoading()` instead
|
|
179
152
|
*/
|
|
180
153
|
isLoading: ComputedRef<boolean>;
|
|
181
154
|
/**
|
|
@@ -188,7 +161,7 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
|
188
161
|
* @param data - Parameters and body for the mutation
|
|
189
162
|
* @returns Promise with ApiResult containing either the response data or an error
|
|
190
163
|
*/
|
|
191
|
-
execute: (data: RequestParams$1<TReqData, TParams>) => Promise<ApiResult<TResData>>;
|
|
164
|
+
execute: (data: RequestParams$1<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
192
165
|
/**
|
|
193
166
|
* Computed result of the mutation
|
|
194
167
|
* Returns an AsyncResult with three states:
|
|
@@ -196,31 +169,36 @@ interface UseMutationReturnType<TReqData, TResData, TParams = void> {
|
|
|
196
169
|
* - ok: use `result.value.isOk()` and `result.value.getValue()`
|
|
197
170
|
* - err: use `result.value.isErr()` and `result.value.getError()`
|
|
198
171
|
*/
|
|
199
|
-
result: ComputedRef<AsyncResult<TResData, ApiError
|
|
172
|
+
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
200
173
|
}
|
|
201
|
-
declare function useMutation<TReqData = void, TResData = void, TParams = void>(options: UseMutationOptions<TReqData, TResData, TParams>): UseMutationReturnType<TReqData, TResData, TParams>;
|
|
202
174
|
//#endregion
|
|
203
175
|
//#region src/types/sort.type.d.ts
|
|
204
|
-
|
|
176
|
+
declare enum SortDirection {
|
|
177
|
+
ASC = "asc",
|
|
178
|
+
DESC = "desc",
|
|
179
|
+
}
|
|
205
180
|
interface Sort<TKey$1 extends string = string> {
|
|
206
181
|
direction: SortDirection;
|
|
207
182
|
key: TKey$1;
|
|
208
183
|
}
|
|
209
184
|
//#endregion
|
|
210
|
-
//#region src/types/
|
|
185
|
+
//#region src/types/queryOptions.d.ts
|
|
211
186
|
interface QueryParams {
|
|
212
187
|
filters?: Record<string, any>;
|
|
213
188
|
search?: string;
|
|
214
189
|
sort?: Sort[];
|
|
215
190
|
}
|
|
216
191
|
interface WithSearchQuery {
|
|
217
|
-
search
|
|
192
|
+
search?: string | undefined;
|
|
218
193
|
}
|
|
219
194
|
interface WithSortQuery<TKeys extends string> {
|
|
220
195
|
sort: Sort<TKeys>[];
|
|
221
196
|
}
|
|
222
197
|
interface WithFilterQuery<TFilters extends Record<string, any>> {
|
|
223
|
-
filters
|
|
198
|
+
filters?: TFilters;
|
|
199
|
+
}
|
|
200
|
+
interface WithStaticFilterQuery<TFilters extends Record<string, any>> {
|
|
201
|
+
staticFilters: TFilters;
|
|
224
202
|
}
|
|
225
203
|
interface InfiniteQueryOptions<TParams> {
|
|
226
204
|
params: { [K in keyof TParams]: Ref<TParams[K]> };
|
|
@@ -255,8 +233,8 @@ interface KeysetPaginationResponse<TData> {
|
|
|
255
233
|
next: unknown;
|
|
256
234
|
};
|
|
257
235
|
}
|
|
258
|
-
type OffsetPaginationResult<TData> = ApiResult<OffsetPaginationResponse<TData
|
|
259
|
-
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>;
|
|
260
238
|
interface PaginatedDataDto<TSchema> {
|
|
261
239
|
items: TSchema[];
|
|
262
240
|
meta: {
|
|
@@ -266,86 +244,8 @@ interface PaginatedDataDto<TSchema> {
|
|
|
266
244
|
};
|
|
267
245
|
}
|
|
268
246
|
//#endregion
|
|
269
|
-
//#region src/types/queryKeys.type.d.ts
|
|
270
|
-
/**
|
|
271
|
-
* Base interface for defining query keys with their associated entities
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```typescript
|
|
275
|
-
* declare module '@wisemen/vue-core-api-utils' {
|
|
276
|
-
* interface QueryKeys {
|
|
277
|
-
* userDetail: {
|
|
278
|
-
* params: { userUuid: ComputedRef<UserUuid> }
|
|
279
|
-
* entity: User
|
|
280
|
-
* }
|
|
281
|
-
* productList: {
|
|
282
|
-
* params: { category: ComputedRef<string> }
|
|
283
|
-
* entity: Product[]
|
|
284
|
-
* }
|
|
285
|
-
* }
|
|
286
|
-
* }
|
|
287
|
-
* ```
|
|
288
|
-
*/
|
|
289
|
-
interface QueryKeys {}
|
|
290
|
-
/**
|
|
291
|
-
* Generic helper types for libraries/factories that want to infer query key typing
|
|
292
|
-
* from a user-provided config object (instead of relying on module augmentation).
|
|
293
|
-
*/
|
|
294
|
-
/**
|
|
295
|
-
* Extract the entity type from a query-keys config for a specific key.
|
|
296
|
-
*/
|
|
297
|
-
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
298
|
-
entity: infer E;
|
|
299
|
-
} ? E : never : never;
|
|
300
|
-
/**
|
|
301
|
-
* Extract the params type from a query-keys config for a specific key.
|
|
302
|
-
* Automatically wraps each param in Ref for reactivity.
|
|
303
|
-
*/
|
|
304
|
-
type QueryKeyParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
305
|
-
params: infer P;
|
|
306
|
-
} ? { [K in keyof P]: Ref<P[K]> } : void : never;
|
|
307
|
-
/**
|
|
308
|
-
* Extract the raw params type from a query-keys config for a specific key (unwrapped from Computed).
|
|
309
|
-
* Used for optimistic updates which accept plain values.
|
|
310
|
-
*/
|
|
311
|
-
type QueryKeyRawParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
|
|
312
|
-
params: infer P;
|
|
313
|
-
} ? P : void : never;
|
|
314
|
-
/**
|
|
315
|
-
* Get all keys that have an associated entity in a query-keys config.
|
|
316
|
-
*/
|
|
317
|
-
type QueryKeysWithEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
|
|
318
|
-
entity: any;
|
|
319
|
-
} ? K : never }[keyof TQueryKeys]) & string;
|
|
320
|
-
/**
|
|
321
|
-
* Extract the parameters object from a query key definition
|
|
322
|
-
*/
|
|
323
|
-
type QueryKeyParams<TKey$1 extends keyof QueryKeys> = QueryKeys[TKey$1] extends {
|
|
324
|
-
params: infer P;
|
|
325
|
-
} ? Ref<P> : QueryKeys[TKey$1];
|
|
326
|
-
/**
|
|
327
|
-
* Extract the entity type from a query key definition
|
|
328
|
-
*/
|
|
329
|
-
type QueryKeyEntity<TKey$1 extends keyof QueryKeys> = QueryKeys[TKey$1] extends {
|
|
330
|
-
entity: infer E;
|
|
331
|
-
} ? E : never;
|
|
332
|
-
/**
|
|
333
|
-
* Check if a query key has an associated entity
|
|
334
|
-
*/
|
|
335
|
-
type HasEntity<TKey$1 extends keyof QueryKeys> = QueryKeys[TKey$1] extends {
|
|
336
|
-
entity: any;
|
|
337
|
-
} ? TKey$1 : never;
|
|
338
|
-
/**
|
|
339
|
-
* Get all query keys that have an associated entity
|
|
340
|
-
*/
|
|
341
|
-
type QueryKeysWithEntity = { [K in keyof QueryKeys]: HasEntity<K> }[keyof QueryKeys];
|
|
342
|
-
//#endregion
|
|
343
247
|
//#region src/composables/query/keysetInfiniteQuery.composable.d.ts
|
|
344
|
-
|
|
345
|
-
type ExtractParams$2<T> = T extends {
|
|
346
|
-
params: infer P;
|
|
347
|
-
} ? P : T;
|
|
348
|
-
interface KeysetInfiniteQueryOptions<TData> {
|
|
248
|
+
interface KeysetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
|
|
349
249
|
/**
|
|
350
250
|
* The time in milliseconds after which the query will be considered stale
|
|
351
251
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -367,30 +267,63 @@ interface KeysetInfiniteQueryOptions<TData> {
|
|
|
367
267
|
* Function that will be called when query is executed
|
|
368
268
|
* @returns Promise with response data
|
|
369
269
|
*/
|
|
370
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData>>;
|
|
270
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData, TErrorCode>>;
|
|
371
271
|
/**
|
|
372
272
|
* Query key associated with the query
|
|
373
273
|
*/
|
|
374
|
-
queryKey:
|
|
274
|
+
queryKey: Record<string, unknown>;
|
|
375
275
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
+
*/
|
|
383
307
|
fetchNextPage: () => Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Refetch the query
|
|
310
|
+
*/
|
|
384
311
|
refetch: () => Promise<void>;
|
|
385
|
-
|
|
386
|
-
|
|
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>;
|
|
387
324
|
//#endregion
|
|
388
325
|
//#region src/composables/query/offsetInfiniteQuery.composable.d.ts
|
|
389
|
-
|
|
390
|
-
type ExtractParams$1<T> = T extends {
|
|
391
|
-
params: infer P;
|
|
392
|
-
} ? P : T;
|
|
393
|
-
interface OffsetInfiniteQueryOptions<TData> {
|
|
326
|
+
interface OffsetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
|
|
394
327
|
/**
|
|
395
328
|
* The time in milliseconds after which the query will be considered stale
|
|
396
329
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -412,30 +345,63 @@ interface OffsetInfiniteQueryOptions<TData> {
|
|
|
412
345
|
* Function that will be called when query is executed
|
|
413
346
|
* @returns Promise with response data
|
|
414
347
|
*/
|
|
415
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData>>;
|
|
348
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData, TErrorCode>>;
|
|
416
349
|
/**
|
|
417
350
|
* Query key associated with the query
|
|
418
351
|
*/
|
|
419
|
-
queryKey:
|
|
352
|
+
queryKey: Record<string, unknown>;
|
|
420
353
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
+
*/
|
|
428
385
|
fetchNextPage: () => Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Refetch the query
|
|
388
|
+
*/
|
|
429
389
|
refetch: () => Promise<void>;
|
|
430
|
-
|
|
431
|
-
|
|
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>;
|
|
432
402
|
//#endregion
|
|
433
403
|
//#region src/composables/query/query.composable.d.ts
|
|
434
|
-
|
|
435
|
-
type ExtractParams<T> = T extends {
|
|
436
|
-
params: infer P;
|
|
437
|
-
} ? P : T;
|
|
438
|
-
interface UseQueryOptions<TResData> {
|
|
404
|
+
interface UseQueryOptions<TResData, TErrorCode extends string = string> {
|
|
439
405
|
/**
|
|
440
406
|
* The time in milliseconds after which the query will be considered stale
|
|
441
407
|
* After this time, the query will be refetched automatically in the background when it is rendered or accessed
|
|
@@ -458,13 +424,13 @@ interface UseQueryOptions<TResData> {
|
|
|
458
424
|
* Function that will be called when query is executed
|
|
459
425
|
* @returns Promise with response data
|
|
460
426
|
*/
|
|
461
|
-
queryFn: () => Promise<ApiResult<TResData>>;
|
|
427
|
+
queryFn: () => Promise<ApiResult<TResData, TErrorCode>>;
|
|
462
428
|
/**
|
|
463
429
|
* Query key associated with the query
|
|
464
430
|
*/
|
|
465
|
-
queryKey:
|
|
431
|
+
queryKey: Record<string, unknown>;
|
|
466
432
|
}
|
|
467
|
-
interface UseQueryReturnType<TResData> {
|
|
433
|
+
interface UseQueryReturnType<TResData, TErrorCode extends string = string> {
|
|
468
434
|
/**
|
|
469
435
|
* Whether query has errored at least once
|
|
470
436
|
* @deprecated - use `result.value.isErr()` instead
|
|
@@ -497,26 +463,71 @@ interface UseQueryReturnType<TResData> {
|
|
|
497
463
|
*
|
|
498
464
|
* Use `result.value.match({ loading, ok, err })` for exhaustive handling
|
|
499
465
|
*/
|
|
500
|
-
result: ComputedRef<AsyncResult<TResData, ApiError
|
|
466
|
+
result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
|
|
501
467
|
}
|
|
502
|
-
declare function useQuery<TResData>(options: UseQueryOptions<TResData>): UseQueryReturnType<TResData>;
|
|
503
|
-
//#endregion
|
|
504
|
-
//#region src/composables/query/prefetchQuery.composable.d.ts
|
|
505
|
-
declare function usePrefetchQuery<TResData>(query: UseQueryOptions<TResData>): {
|
|
506
|
-
execute: () => Promise<void>;
|
|
507
|
-
};
|
|
508
468
|
//#endregion
|
|
509
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;
|
|
510
492
|
interface QueryConfig {
|
|
511
493
|
prefetchStaleTime: number;
|
|
512
494
|
limit: number;
|
|
513
495
|
}
|
|
514
496
|
declare function setQueryConfig(config: Partial<QueryConfig>): void;
|
|
515
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
|
|
516
530
|
//#region src/factory/createApiUtils.types.d.ts
|
|
517
|
-
interface CreateApiUtilsOptions {
|
|
518
|
-
queryClient: QueryClient;
|
|
519
|
-
}
|
|
520
531
|
/**
|
|
521
532
|
* Helper type to build the invalidation config for a specific query key
|
|
522
533
|
* Maps the query key's params to optional parameter extractors
|
|
@@ -526,57 +537,57 @@ type QueryKeysWithArrayEntityFromConfig<TQueryKeys extends object> = ({ [K in ke
|
|
|
526
537
|
entity: any[];
|
|
527
538
|
} ? K : never }[keyof TQueryKeys]) & string;
|
|
528
539
|
type QueryKeyArrayItemFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1> extends (infer TItem)[] ? TItem : never;
|
|
529
|
-
type ApiUseQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys
|
|
540
|
+
type ApiUseQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
530
541
|
staleTime?: number;
|
|
531
542
|
isDebug?: boolean;
|
|
532
543
|
isEnabled?: MaybeRef<boolean>;
|
|
533
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1
|
|
544
|
+
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
534
545
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
535
546
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
536
547
|
} : {
|
|
537
548
|
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
538
549
|
});
|
|
539
|
-
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys
|
|
550
|
+
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
540
551
|
staleTime?: number;
|
|
541
|
-
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1
|
|
552
|
+
queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
542
553
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
543
554
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
544
555
|
} : {
|
|
545
556
|
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
546
557
|
});
|
|
547
|
-
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
558
|
+
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
548
559
|
staleTime?: number;
|
|
549
560
|
isEnabled?: MaybeRef<boolean>;
|
|
550
561
|
limit?: number;
|
|
551
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
562
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
552
563
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
553
564
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
554
565
|
} : {
|
|
555
566
|
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
556
567
|
});
|
|
557
|
-
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
568
|
+
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
558
569
|
staleTime?: number;
|
|
559
570
|
limit?: number;
|
|
560
|
-
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
571
|
+
queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
561
572
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
562
573
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
563
574
|
} : {
|
|
564
575
|
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
565
576
|
});
|
|
566
|
-
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
577
|
+
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
567
578
|
staleTime?: number;
|
|
568
579
|
isEnabled?: MaybeRef<boolean>;
|
|
569
580
|
limit?: number;
|
|
570
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
581
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
571
582
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
572
583
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
573
584
|
} : {
|
|
574
585
|
params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
575
586
|
});
|
|
576
|
-
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys
|
|
587
|
+
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
|
|
577
588
|
staleTime?: number;
|
|
578
589
|
limit?: number;
|
|
579
|
-
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
590
|
+
queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
|
|
580
591
|
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
|
|
581
592
|
params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
|
|
582
593
|
} : {
|
|
@@ -590,7 +601,7 @@ type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends
|
|
|
590
601
|
body: TReqData;
|
|
591
602
|
params: TParams;
|
|
592
603
|
};
|
|
593
|
-
interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, TParams = void> {
|
|
604
|
+
interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, TParams = void, TErrorCode extends string = string> {
|
|
594
605
|
/**
|
|
595
606
|
* Whether to enable debug mode
|
|
596
607
|
*/
|
|
@@ -600,7 +611,7 @@ interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, T
|
|
|
600
611
|
* @param options - Parameters and body for the mutation
|
|
601
612
|
* @returns Promise with ApiResult containing either the response data or an error
|
|
602
613
|
*/
|
|
603
|
-
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData>>;
|
|
614
|
+
queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
|
|
604
615
|
/**
|
|
605
616
|
* Query keys which should be invalidated after mutation is successful
|
|
606
617
|
* Each key is optional and maps to the query key's specific parameters
|
|
@@ -616,60 +627,68 @@ interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, T
|
|
|
616
627
|
*/
|
|
617
628
|
queryKeysToInvalidate?: { [TKey in keyof TQueryKeys]?: QueryKeyInvalidationConfig<TQueryKeys, TKey, TParams, TResData> };
|
|
618
629
|
}
|
|
619
|
-
interface CreateApiMutationUtilsReturnType<TQueryKeys extends object> {
|
|
620
|
-
useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams>) => UseMutationReturnType<TReqData, TResData, TParams>;
|
|
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>;
|
|
621
632
|
}
|
|
622
633
|
//#endregion
|
|
623
634
|
//#region src/factory/createApiInfiniteQueryUtils.d.ts
|
|
624
|
-
interface CreateApiInfiniteQueryUtilsReturnType<TQueryKeys extends object> {
|
|
625
|
-
useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1>) => ReturnType<typeof useKeysetInfiniteQuery<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
626
|
-
useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1>) => ReturnType<typeof useOffsetInfiniteQuery<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1
|
|
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>>;
|
|
627
638
|
}
|
|
628
|
-
declare function createApiInfiniteQueryUtils<TQueryKeys extends object>(): CreateApiInfiniteQueryUtilsReturnType<TQueryKeys>;
|
|
639
|
+
declare function createApiInfiniteQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiInfiniteQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
629
640
|
//#endregion
|
|
630
641
|
//#region src/factory/createApiMutationUtils.d.ts
|
|
631
|
-
declare function createApiMutationUtils<TQueryKeys extends object>(): CreateApiMutationUtilsReturnType<TQueryKeys>;
|
|
642
|
+
declare function createApiMutationUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiMutationUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
632
643
|
//#endregion
|
|
633
|
-
//#region src/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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>;
|
|
648
|
+
};
|
|
649
|
+
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
650
|
+
execute: () => Promise<void>;
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
declare function createApiPrefetchInfiniteQueryUtils<TQueryKeys extends object, TErrorCode extends string = string>(): CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys, TErrorCode>;
|
|
654
|
+
//#endregion
|
|
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
|
|
638
664
|
/**
|
|
639
|
-
*
|
|
665
|
+
* Helper type to extract the item type from an entity (array item or entity itself)
|
|
640
666
|
*/
|
|
641
667
|
type EntityItem<TEntity> = TEntity extends any[] ? TEntity[number] : TEntity;
|
|
642
|
-
type MatchByKeyValue<TEntity> = Partial<{ [K in keyof EntityItem<TEntity>]: MaybeRef<UnwrapRef<EntityItem<TEntity>[K]>> }>;
|
|
643
|
-
/**
|
|
644
|
-
* Options for the "by" parameter - can be a predicate function or key-value object
|
|
645
|
-
*/
|
|
646
|
-
type ByOption<TEntity> = MatchByKeyValue<TEntity> | PredicateFn<TEntity> | null | undefined;
|
|
647
668
|
/**
|
|
648
|
-
* Options for
|
|
669
|
+
* Options for type-safe query client update
|
|
649
670
|
*/
|
|
650
|
-
interface
|
|
671
|
+
interface QueryClientUpdateOptions<TEntity> {
|
|
651
672
|
/**
|
|
652
|
-
*
|
|
653
|
-
* - function: a predicate that returns true for the entity to update
|
|
654
|
-
* - object: key-value pairs to match (e.g., { id: '123' } or { uuid: 'abc' })
|
|
655
|
-
* - 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
|
|
656
674
|
*/
|
|
657
|
-
by
|
|
675
|
+
by: (item: EntityItem<TEntity>) => boolean;
|
|
658
676
|
/**
|
|
659
|
-
*
|
|
677
|
+
* Function that receives the current item and returns the updated item
|
|
660
678
|
*/
|
|
661
|
-
value:
|
|
679
|
+
value: (item: EntityItem<TEntity>) => EntityItem<TEntity>;
|
|
662
680
|
}
|
|
663
681
|
/**
|
|
664
|
-
*
|
|
682
|
+
* QueryClient utility class for type-safe query operations
|
|
665
683
|
*/
|
|
666
|
-
declare class
|
|
684
|
+
declare class QueryClient<TQueryKeys extends object> {
|
|
667
685
|
private readonly queryClient;
|
|
668
|
-
constructor(queryClient: QueryClient);
|
|
686
|
+
constructor(queryClient: QueryClient$1);
|
|
669
687
|
/**
|
|
670
688
|
* Extract the raw entity from AsyncResult data
|
|
671
689
|
*/
|
|
672
690
|
private extractEntityFromAsyncResult;
|
|
691
|
+
private hasDataArray;
|
|
673
692
|
private isInfiniteDataLike;
|
|
674
693
|
/**
|
|
675
694
|
* Determine if an item should be updated
|
|
@@ -679,6 +698,7 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
679
698
|
* Internal method to update entity based on the "by" option
|
|
680
699
|
*/
|
|
681
700
|
private updateEntity;
|
|
701
|
+
private updateInfinitePageValue;
|
|
682
702
|
/**
|
|
683
703
|
* Wrap a raw entity in an AsyncResult (preserving ok state)
|
|
684
704
|
*/
|
|
@@ -694,13 +714,13 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
694
714
|
* @example
|
|
695
715
|
* ```typescript
|
|
696
716
|
* // Get all userDetail queries (returns array)
|
|
697
|
-
* const allUsers =
|
|
717
|
+
* const allUsers = queryClient.get('userDetail')
|
|
698
718
|
*
|
|
699
719
|
* // Get exact query stored as ['userDetail']
|
|
700
|
-
* const exactUser =
|
|
720
|
+
* const exactUser = queryClient.get('userDetail', { isExact: true })
|
|
701
721
|
*
|
|
702
722
|
* // Get specific userDetail query with params
|
|
703
|
-
* const user =
|
|
723
|
+
* const user = queryClient.get(['userDetail', { userUuid: '123' }] as const)
|
|
704
724
|
* ```
|
|
705
725
|
*/
|
|
706
726
|
get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, options?: {
|
|
@@ -719,10 +739,10 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
719
739
|
* @example
|
|
720
740
|
* ```typescript
|
|
721
741
|
* // Invalidate all userDetail queries
|
|
722
|
-
* await
|
|
742
|
+
* await queryClient.invalidate('userDetail')
|
|
723
743
|
*
|
|
724
744
|
* // Invalidate specific query
|
|
725
|
-
* await
|
|
745
|
+
* await queryClient.invalidate(['userDetail', { userUuid: '123' }] as const)
|
|
726
746
|
* ```
|
|
727
747
|
*/
|
|
728
748
|
invalidate<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1): Promise<void>;
|
|
@@ -738,84 +758,113 @@ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
|
|
|
738
758
|
* @example
|
|
739
759
|
* ```typescript
|
|
740
760
|
* // Set query with just the key
|
|
741
|
-
*
|
|
761
|
+
* queryClient.set('userDetail', userData)
|
|
742
762
|
*
|
|
743
763
|
* // Set query with key + params
|
|
744
|
-
*
|
|
764
|
+
* queryClient.set(['userDetail', { userUuid: '123' }] as const, userData)
|
|
745
765
|
* ```
|
|
746
766
|
*/
|
|
747
767
|
set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
|
|
748
768
|
set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>], entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
|
|
749
769
|
/**
|
|
750
|
-
* Update entity data in the query cache
|
|
770
|
+
* Update entity data in the query cache
|
|
751
771
|
*
|
|
752
772
|
* When using just the key, updates ALL queries with that key
|
|
753
773
|
* When using key + params tuple, updates SPECIFIC query
|
|
754
774
|
*
|
|
755
775
|
* @example
|
|
756
776
|
* ```typescript
|
|
757
|
-
* // Update
|
|
758
|
-
*
|
|
759
|
-
*
|
|
777
|
+
* // Update a specific user by id
|
|
778
|
+
* queryClient.update('userDetail', {
|
|
779
|
+
* by: (user) => user.id === '123',
|
|
780
|
+
* value: (user) => ({ ...user, name: 'John Doe' })
|
|
760
781
|
* })
|
|
761
782
|
*
|
|
762
|
-
* // Update
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
* })
|
|
766
|
-
*
|
|
767
|
-
* // Update using predicates
|
|
768
|
-
* optimisticUpdates.update('userList', {
|
|
769
|
-
* value: { isActive: false },
|
|
770
|
-
* by: (user) => user.email === 'john@example.com'
|
|
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 })
|
|
771
787
|
* })
|
|
772
788
|
* ```
|
|
773
789
|
*/
|
|
774
|
-
update<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey$1> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>(key: TKey$1, options:
|
|
775
|
-
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:
|
|
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;
|
|
776
792
|
}
|
|
777
|
-
/**
|
|
778
|
-
* Create an OptimisticUpdates instance
|
|
779
|
-
*/
|
|
780
|
-
declare function createOptimisticUpdates(queryClient: QueryClient): OptimisticUpdates;
|
|
781
793
|
//#endregion
|
|
782
|
-
//#region src/factory/
|
|
783
|
-
interface
|
|
784
|
-
|
|
794
|
+
//#region src/factory/createApiQueryClientUtils.d.ts
|
|
795
|
+
interface CreateApiQueryClientUtilsReturnType<TQueryKeys extends object> {
|
|
796
|
+
useQueryClient: () => QueryClient<TQueryKeys>;
|
|
785
797
|
}
|
|
786
|
-
declare function
|
|
798
|
+
declare function createApiQueryClientUtils<TQueryKeys extends object>(): CreateApiQueryClientUtilsReturnType<TQueryKeys>;
|
|
787
799
|
//#endregion
|
|
788
|
-
//#region src/factory/
|
|
789
|
-
interface
|
|
790
|
-
|
|
800
|
+
//#region src/factory/createApiQueryUtils.d.ts
|
|
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>;
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region src/factory/createApiUtils.d.ts
|
|
807
|
+
/**
|
|
808
|
+
* Factory that creates typed composables based on a user-provided query-keys config.
|
|
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
|
+
* ```
|
|
820
|
+
*/
|
|
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>) => {
|
|
791
827
|
execute: () => Promise<void>;
|
|
792
828
|
};
|
|
793
|
-
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1>) => {
|
|
829
|
+
usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
794
830
|
execute: () => Promise<void>;
|
|
795
831
|
};
|
|
796
|
-
|
|
797
|
-
declare function createApiPrefetchInfiniteQueryUtils<TQueryKeys extends object>(options: CreateApiUtilsOptions): CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys>;
|
|
798
|
-
//#endregion
|
|
799
|
-
//#region src/factory/createApiPrefetchQueryUtils.d.ts
|
|
800
|
-
interface CreateApiPrefetchQueryUtilsReturnType<TQueryKeys extends object> {
|
|
801
|
-
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1>) => {
|
|
832
|
+
usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
|
|
802
833
|
execute: () => Promise<void>;
|
|
803
834
|
};
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
//#endregion
|
|
807
|
-
//#region src/factory/createApiQueryUtils.d.ts
|
|
808
|
-
interface CreateApiQueryUtilsReturnType<TQueryKeys extends object> {
|
|
809
|
-
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>;
|
|
810
|
-
}
|
|
811
|
-
declare function createApiQueryUtils<TQueryKeys extends object>(): CreateApiQueryUtilsReturnType<TQueryKeys>;
|
|
835
|
+
useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, string>;
|
|
836
|
+
};
|
|
812
837
|
//#endregion
|
|
813
|
-
//#region src/
|
|
814
|
-
type CreateApiUtilsReturnType<TQueryKeys extends object> = ReturnType<typeof createApiQueryUtils<TQueryKeys>> & ReturnType<typeof createApiPrefetchQueryUtils<TQueryKeys>> & ReturnType<typeof createApiInfiniteQueryUtils<TQueryKeys>> & ReturnType<typeof createApiPrefetchInfiniteQueryUtils<TQueryKeys>> & ReturnType<typeof createApiMutationUtils<TQueryKeys>> & ReturnType<typeof createApiOptimisticUpdatesUtils<TQueryKeys>>;
|
|
838
|
+
//#region src/plugin/apiUtilsPlugin.d.ts
|
|
815
839
|
/**
|
|
816
|
-
*
|
|
817
|
-
*
|
|
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()
|
|
818
857
|
*/
|
|
819
|
-
declare function
|
|
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
|
+
}
|
|
820
869
|
//#endregion
|
|
821
|
-
export { ApiError,
|
|
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 };
|