@wisemen/vue-core-api-utils 0.0.1-beta.5 → 1.0.0-beta.1

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.
@@ -0,0 +1,806 @@
1
+ import { Result } from "neverthrow";
2
+ import { QueryClient } from "@tanstack/vue-query";
3
+ import * as vue0 from "vue";
4
+ import { ComputedRef, MaybeRef, Ref, UnwrapRef } from "vue";
5
+
6
+ //#region src/async-result/asyncResult.d.ts
7
+ /**
8
+ * Base class for AsyncResult - internal use only.
9
+ * Use AsyncResult<T, E> as the public type.
10
+ */
11
+ declare abstract class AsyncResultBase<T, E> {
12
+ protected readonly _error: E | undefined;
13
+ protected readonly _status: 'err' | 'loading' | 'ok';
14
+ protected readonly _value: T | undefined;
15
+ protected constructor(status: 'err' | 'loading' | 'ok', value?: T, error?: E);
16
+ /**
17
+ * Check if the result is an error (type predicate for narrowing)
18
+ */
19
+ isErr(): this is AsyncResultErr<T, E>;
20
+ /**
21
+ * Check if the result is in loading state (type predicate for narrowing)
22
+ */
23
+ isLoading(): this is AsyncResultLoading<T, E>;
24
+ /**
25
+ * Check if the result is a success (type predicate for narrowing)
26
+ */
27
+ isOk(): this is AsyncResultOk<T, E>;
28
+ /**
29
+ * Map the success value to a new value
30
+ */
31
+ map<U>(fn: (value: T) => U): AsyncResult<U, E>;
32
+ /**
33
+ * Map the error to a new error
34
+ */
35
+ mapErr<F>(fn: (error: E) => F): AsyncResult<T, F>;
36
+ /**
37
+ * Pattern match on all three states
38
+ */
39
+ match<U>(handlers: {
40
+ err: (error: E) => U;
41
+ loading: () => U;
42
+ ok: (value: T) => U;
43
+ }): U;
44
+ /**
45
+ * Get the success value, or return null if loading or error.
46
+ * Returns T | null when null is passed as the default value.
47
+ */
48
+ unwrapOr(defaultValue: null): T | null;
49
+ /**
50
+ * Get the success value, or return the default value of type T if loading or error.
51
+ * Returns T when a value of type T is passed as the default value.
52
+ */
53
+ unwrapOr(defaultValue: T): T;
54
+ }
55
+ /**
56
+ * AsyncResult representing an error state
57
+ */
58
+ declare class AsyncResultErr<T, E> extends AsyncResultBase<T, E> {
59
+ private constructor();
60
+ /** @internal */
61
+ static _create<T, E>(error: E): AsyncResultErr<T, E>;
62
+ /** Get the error value - only available after isErr() check */
63
+ getError(): E;
64
+ getResult(): Result<T, E>;
65
+ }
66
+ /**
67
+ * AsyncResult representing a loading state
68
+ */
69
+ declare class AsyncResultLoading<T, E> extends AsyncResultBase<T, E> {
70
+ private constructor();
71
+ /** @internal */
72
+ static _create<T, E>(): AsyncResultLoading<T, E>;
73
+ getResult(): null;
74
+ }
75
+ /**
76
+ * AsyncResult representing a success state
77
+ */
78
+ declare class AsyncResultOk<T, E> extends AsyncResultBase<T, E> {
79
+ private constructor();
80
+ /** @internal */
81
+ static _create<T, E>(value: T): AsyncResultOk<T, E>;
82
+ getResult(): Result<T, E>;
83
+ /** Get the success value - only available after isOk() check */
84
+ getValue(): T;
85
+ }
86
+ /**
87
+ * Union type of all AsyncResult states.
88
+ * Use isOk(), isErr(), or isLoading() to narrow to specific state.
89
+ */
90
+ type AsyncResult<T, E> = AsyncResultErr<T, E> | AsyncResultLoading<T, E> | AsyncResultOk<T, E>;
91
+ /**
92
+ * Static factory methods for creating AsyncResult instances.
93
+ * This pattern (same name for type and value) is intentional for ergonomic API.
94
+ */
95
+ declare const AsyncResult: {
96
+ /**
97
+ * Create a failed AsyncResult with error
98
+ */
99
+ readonly err: <T, E>(error: E) => AsyncResultErr<T, E>;
100
+ /**
101
+ * Create an AsyncResult from an existing neverthrow Result
102
+ */
103
+ readonly fromResult: <T, E>(result: Result<T, E>) => AsyncResult<T, E>;
104
+ /**
105
+ * Create a loading AsyncResult
106
+ */
107
+ readonly loading: <T, E>() => AsyncResultLoading<T, E>;
108
+ /**
109
+ * Create a successful AsyncResult with data
110
+ */
111
+ readonly ok: <T, E>(value: T) => AsyncResultOk<T, E>;
112
+ };
113
+ //#endregion
114
+ //#region src/types/apiError.type.d.ts
115
+ interface ApiErrorCodes {}
116
+ type ApiErrorCode = ApiErrorCodes[keyof ApiErrorCodes];
117
+ interface ApiKnownErrorObject {
118
+ code: ApiErrorCode;
119
+ detail: string;
120
+ source?: {
121
+ pointer: string;
122
+ };
123
+ status: string;
124
+ }
125
+ interface ApiUnknownErrorObject {
126
+ code: string;
127
+ detail: string;
128
+ source?: {
129
+ pointer: string;
130
+ };
131
+ status: string;
132
+ }
133
+ type ApiErrorObject = ApiKnownErrorObject | ApiUnknownErrorObject;
134
+ interface ApiExpectedError {
135
+ errors: ApiErrorObject[];
136
+ }
137
+ type ApiUnexpectedError = Error;
138
+ type ApiError = ApiExpectedError | ApiUnexpectedError;
139
+ type ApiResult<T> = Result<T, ApiError>;
140
+ //#endregion
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];
206
+ //#endregion
207
+ //#region src/composables/mutation/mutation.composable.d.ts
208
+ type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
209
+ params: TParams;
210
+ } : TParams extends void ? {
211
+ body: TReqData;
212
+ } : {
213
+ body: TReqData;
214
+ params: TParams;
215
+ };
216
+ interface UseMutationOptions<TReqData, TResData, TParams = void> {
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> {
233
+ /**
234
+ * Whether mutation is loading
235
+ */
236
+ isLoading: ComputedRef<boolean>;
237
+ /**
238
+ * Response data from the mutation
239
+ * @deprecated - use `result.value.getValue()` instead
240
+ */
241
+ data: ComputedRef<TResData | null>;
242
+ /**
243
+ * Function to execute the mutation
244
+ * @param data - Parameters and body for the mutation
245
+ * @returns Promise with ApiResult containing either the response data or an error
246
+ */
247
+ execute: (data: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData>>;
248
+ /**
249
+ * Computed result of the mutation
250
+ * Returns an AsyncResult with three states:
251
+ * - loading: use `result.value.isLoading()`
252
+ * - ok: use `result.value.isOk()` and `result.value.getValue()`
253
+ * - err: use `result.value.isErr()` and `result.value.getError()`
254
+ */
255
+ result: ComputedRef<AsyncResult<TResData, ApiError>>;
256
+ }
257
+ declare function useMutation<TReqData = void, TResData = void, TParams = void>(options: UseMutationOptions<TReqData, TResData, TParams>): UseMutationReturnType<TReqData, TResData, TParams>;
258
+ //#endregion
259
+ //#region src/types/sort.type.d.ts
260
+ type SortDirection = 'asc' | 'desc';
261
+ interface Sort<TKey extends string = string> {
262
+ direction: SortDirection;
263
+ key: TKey;
264
+ }
265
+ //#endregion
266
+ //#region src/types/query.type.d.ts
267
+ interface QueryParams {
268
+ filters?: Record<string, any>;
269
+ search?: string;
270
+ sort?: Sort[];
271
+ }
272
+ interface WithSearchQuery {
273
+ search: string;
274
+ }
275
+ interface WithSortQuery<TKeys extends string> {
276
+ sort: Sort<TKeys>[];
277
+ }
278
+ interface WithFilterQuery<TFilters extends Record<string, any>> {
279
+ filters: TFilters;
280
+ }
281
+ interface InfiniteQueryOptions<TParams> {
282
+ params: { [K in keyof TParams]: Ref<TParams[K]> };
283
+ }
284
+ //#endregion
285
+ //#region src/types/pagination.type.d.ts
286
+ interface OffsetPaginationParams {
287
+ limit: number;
288
+ offset: number;
289
+ }
290
+ type OffsetPagination<T extends QueryParams = Record<string, never>> = {
291
+ pagination: OffsetPaginationParams;
292
+ } & T;
293
+ interface KeysetPaginationParams {
294
+ key?: any;
295
+ limit: number;
296
+ }
297
+ type KeysetPagination<T extends QueryParams> = {
298
+ pagination: KeysetPaginationParams;
299
+ } & T;
300
+ interface OffsetPaginationResponse<TData> {
301
+ data: TData[];
302
+ meta: {
303
+ limit: number;
304
+ offset: number;
305
+ total: number;
306
+ };
307
+ }
308
+ interface KeysetPaginationResponse<TData> {
309
+ data: TData[];
310
+ meta: {
311
+ next: unknown;
312
+ };
313
+ }
314
+ type OffsetPaginationResult<TData> = ApiResult<OffsetPaginationResponse<TData>>;
315
+ type KeysetPaginationResult<TData> = ApiResult<KeysetPaginationResponse<TData>>;
316
+ interface PaginatedDataDto<TSchema> {
317
+ items: TSchema[];
318
+ meta: {
319
+ limit: number;
320
+ offset: number;
321
+ total: number;
322
+ };
323
+ }
324
+ //#endregion
325
+ //#region src/composables/query/keysetInfiniteQuery.composable.d.ts
326
+ type NonOptionalKeys$2<T> = { [K in keyof T]-?: T[K] };
327
+ type ExtractParams$2<T> = T extends {
328
+ params: infer P;
329
+ } ? P : T;
330
+ interface KeysetInfiniteQueryOptions<TData> {
331
+ /**
332
+ * The time in milliseconds after which the query will be considered stale
333
+ * After this time, the query will be refetched automatically in the background when it is rendered or accessed
334
+ * @default 0
335
+ */
336
+ staleTime?: number;
337
+ /**
338
+ * Whether the query is enabled
339
+ * If false, the query will not be executed
340
+ * @default true
341
+ */
342
+ isEnabled?: MaybeRef<boolean>;
343
+ /**
344
+ * Maximum number of items to fetch per page, default can be set in config
345
+ * @default 20
346
+ */
347
+ limit?: number;
348
+ /**
349
+ * Function that will be called when query is executed
350
+ * @returns Promise with response data
351
+ */
352
+ queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData>>;
353
+ /**
354
+ * Query key associated with the query
355
+ */
356
+ queryKey: { [TQueryKey in keyof QueryKeys]?: { [TQueryKeyParam in keyof NonOptionalKeys$2<ExtractParams$2<QueryKeys[TQueryKey]>>]: MaybeRef<ExtractParams$2<QueryKeys[TQueryKey]>[TQueryKeyParam]> } };
357
+ }
358
+ declare function useKeysetInfiniteQuery<TData>(options: KeysetInfiniteQueryOptions<TData>): {
359
+ hasNextPage: vue0.ComputedRef<boolean>;
360
+ isError: vue0.ComputedRef<boolean>;
361
+ isFetching: vue0.ComputedRef<boolean>;
362
+ isFetchingNextPage: vue0.ComputedRef<boolean>;
363
+ isLoading: vue0.ComputedRef<boolean>;
364
+ isSuccess: vue0.ComputedRef<boolean>;
365
+ fetchNextPage: () => Promise<void>;
366
+ refetch: () => Promise<void>;
367
+ result: vue0.ComputedRef<AsyncResult<KeysetPaginationResponse<TData>, ApiError>>;
368
+ };
369
+ //#endregion
370
+ //#region src/composables/query/offsetInfiniteQuery.composable.d.ts
371
+ type NonOptionalKeys$1<T> = { [K in keyof T]-?: T[K] };
372
+ type ExtractParams$1<T> = T extends {
373
+ params: infer P;
374
+ } ? P : T;
375
+ interface OffsetInfiniteQueryOptions<TData> {
376
+ /**
377
+ * The time in milliseconds after which the query will be considered stale
378
+ * After this time, the query will be refetched automatically in the background when it is rendered or accessed
379
+ * @default 0
380
+ */
381
+ staleTime?: number;
382
+ /**
383
+ * Whether the query is enabled
384
+ * If false, the query will not be executed
385
+ * @default true
386
+ */
387
+ isEnabled?: MaybeRef<boolean>;
388
+ /**
389
+ * Maximum number of items to fetch per page, default can be set in config
390
+ * @default 20
391
+ */
392
+ limit?: number;
393
+ /**
394
+ * Function that will be called when query is executed
395
+ * @returns Promise with response data
396
+ */
397
+ queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData>>;
398
+ /**
399
+ * Query key associated with the query
400
+ */
401
+ queryKey: { [TQueryKey in keyof QueryKeys]?: { [TQueryKeyParam in keyof NonOptionalKeys$1<ExtractParams$1<QueryKeys[TQueryKey]>>]: MaybeRef<ExtractParams$1<QueryKeys[TQueryKey]>[TQueryKeyParam]> } };
402
+ }
403
+ declare function useOffsetInfiniteQuery<TData>(options: OffsetInfiniteQueryOptions<TData>): {
404
+ hasNextPage: vue0.ComputedRef<boolean>;
405
+ isError: vue0.ComputedRef<boolean>;
406
+ isFetching: vue0.ComputedRef<boolean>;
407
+ isFetchingNextPage: vue0.ComputedRef<boolean>;
408
+ isLoading: vue0.ComputedRef<boolean>;
409
+ isSuccess: vue0.ComputedRef<boolean>;
410
+ fetchNextPage: () => Promise<void>;
411
+ refetch: () => Promise<void>;
412
+ result: vue0.ComputedRef<AsyncResult<OffsetPaginationResponse<TData>, ApiError>>;
413
+ };
414
+ //#endregion
415
+ //#region src/composables/query/query.composable.d.ts
416
+ type NonOptionalKeys<T> = { [K in keyof T]-?: T[K] };
417
+ type ExtractParams<T> = T extends {
418
+ params: infer P;
419
+ } ? P : T;
420
+ interface UseQueryOptions<TResData> {
421
+ /**
422
+ * The time in milliseconds after which the query will be considered stale
423
+ * After this time, the query will be refetched automatically in the background when it is rendered or accessed
424
+ * @default 0
425
+ */
426
+ staleTime?: number;
427
+ /**
428
+ * Whether to enable debug mode
429
+ * When enabled, the query key and parameters will be logged to the console
430
+ * @default false
431
+ */
432
+ isDebug?: boolean;
433
+ /**
434
+ * Whether the query is enabled
435
+ * If false, the query will not be executed
436
+ * @default true
437
+ */
438
+ isEnabled?: MaybeRef<boolean>;
439
+ /**
440
+ * Function that will be called when query is executed
441
+ * @returns Promise with response data
442
+ */
443
+ queryFn: () => Promise<ApiResult<TResData>>;
444
+ /**
445
+ * Query key associated with the query
446
+ */
447
+ queryKey: { [TQueryKey in keyof QueryKeys]?: { [TQueryKeyParam in keyof NonOptionalKeys<ExtractParams<QueryKeys[TQueryKey]>>]: MaybeRef<ExtractParams<QueryKeys[TQueryKey]>[TQueryKeyParam]> } };
448
+ }
449
+ interface UseQueryReturnType<TResData> {
450
+ /**
451
+ * Whether query has errored at least once
452
+ * @deprecated - use `result.value.isErr()` instead
453
+ */
454
+ isError: ComputedRef<boolean>;
455
+ /**
456
+ * Whether query is currently fetching data, regardless of cache status
457
+ */
458
+ isFetching: ComputedRef<boolean>;
459
+ /**
460
+ * Whether query is initially loading
461
+ * @deprecated - use `result.value.isLoading()` instead
462
+ */
463
+ isLoading: ComputedRef<boolean>;
464
+ /**
465
+ * Whether query has been executed successfully
466
+ * @deprecated - use `result.value.isOk()` instead
467
+ */
468
+ isSuccess: ComputedRef<boolean>;
469
+ /**
470
+ * Refetch the query
471
+ */
472
+ refetch: () => Promise<void>;
473
+ /**
474
+ * Computed result of the query
475
+ * Returns an AsyncResult with three states:
476
+ * - loading: use `result.value.isLoading()`
477
+ * - ok: use `result.value.isOk()` and `result.value.getValue()`
478
+ * - err: use `result.value.isErr()` and `result.value.getError()`
479
+ *
480
+ * Use `result.value.match({ loading, ok, err })` for exhaustive handling
481
+ */
482
+ result: ComputedRef<AsyncResult<TResData, ApiError>>;
483
+ }
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
+ //#endregion
491
+ //#region src/config/config.d.ts
492
+ interface QueryConfig {
493
+ prefetchStaleTime: number;
494
+ limit: number;
495
+ }
496
+ declare function setQueryConfig(config: Partial<QueryConfig>): void;
497
+ //#endregion
498
+ //#region src/factory/createApiUtils.types.d.ts
499
+ interface CreateApiUtilsOptions {
500
+ queryClient: QueryClient;
501
+ }
502
+ type QueryKeysWithArrayEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
503
+ entity: any[];
504
+ } ? 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>> = {
507
+ staleTime?: number;
508
+ isDebug?: boolean;
509
+ isEnabled?: MaybeRef<boolean>;
510
+ queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey>>>;
511
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
512
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
513
+ } : {
514
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
515
+ });
516
+ type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>> = {
517
+ staleTime?: number;
518
+ queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey>>>;
519
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
520
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
521
+ } : {
522
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
523
+ });
524
+ type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>> = {
525
+ staleTime?: number;
526
+ isEnabled?: MaybeRef<boolean>;
527
+ limit?: number;
528
+ queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>>;
529
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
530
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
531
+ } : {
532
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
533
+ });
534
+ type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>> = {
535
+ staleTime?: number;
536
+ limit?: number;
537
+ queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>>;
538
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
539
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
540
+ } : {
541
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
542
+ });
543
+ type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>> = {
544
+ staleTime?: number;
545
+ isEnabled?: MaybeRef<boolean>;
546
+ limit?: number;
547
+ queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>>;
548
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
549
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
550
+ } : {
551
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
552
+ });
553
+ type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>> = {
554
+ staleTime?: number;
555
+ limit?: number;
556
+ queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>>;
557
+ } & (QueryKeyParamsFromConfig<TQueryKeys, TKey> extends Record<string, never> ? {
558
+ params?: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
559
+ } : {
560
+ params: QueryKeyParamsFromConfig<TQueryKeys, TKey>;
561
+ });
562
+ //#endregion
563
+ //#region src/factory/createApiInfiniteQueryUtils.d.ts
564
+ declare function createApiInfiniteQueryUtils<TQueryKeys extends object>(): {
565
+ useKeysetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey>) => {
566
+ hasNextPage: vue0.ComputedRef<boolean>;
567
+ isError: vue0.ComputedRef<boolean>;
568
+ isFetching: vue0.ComputedRef<boolean>;
569
+ isFetchingNextPage: vue0.ComputedRef<boolean>;
570
+ isLoading: vue0.ComputedRef<boolean>;
571
+ isSuccess: vue0.ComputedRef<boolean>;
572
+ fetchNextPage: () => Promise<void>;
573
+ refetch: () => Promise<void>;
574
+ result: vue0.ComputedRef<AsyncResult<KeysetPaginationResponse<QueryKeyArrayItemFromConfig<TQueryKeys, TKey>>, ApiError>>;
575
+ };
576
+ useOffsetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey>) => {
577
+ hasNextPage: vue0.ComputedRef<boolean>;
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>>;
586
+ };
587
+ };
588
+ //#endregion
589
+ //#region src/utils/optimisticUpdates.d.ts
590
+ /**
591
+ * Predicate function type that takes an entity and returns boolean
592
+ */
593
+ type PredicateFn<TEntity> = TEntity extends any[] ? (item: TEntity[number]) => boolean : (item: TEntity) => boolean;
594
+ /**
595
+ * Type for matching by key-value pair
596
+ */
597
+ 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
+ /**
600
+ * Options for the "by" parameter - can be a predicate function or key-value object
601
+ */
602
+ type ByOption<TEntity> = MatchByKeyValue<TEntity> | PredicateFn<TEntity> | null | undefined;
603
+ /**
604
+ * Options for optimistic update
605
+ */
606
+ interface OptimisticUpdateOptions<TEntity> {
607
+ /**
608
+ * How to match the entity to update:
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
612
+ */
613
+ by?: ByOption<TEntity>;
614
+ /**
615
+ * The new value to set (for single entities) or merge (for arrays)
616
+ */
617
+ value: TEntity extends any[] ? Partial<TEntity[number]> : Partial<TEntity>;
618
+ }
619
+ /**
620
+ * OptimisticUpdates utility class for type-safe optimistic updates
621
+ */
622
+ declare class OptimisticUpdates<TQueryKeys extends object = QueryKeys> {
623
+ private readonly queryClient;
624
+ constructor(queryClient: QueryClient);
625
+ /**
626
+ * Extract the raw entity from AsyncResult data
627
+ */
628
+ private extractEntityFromAsyncResult;
629
+ private isInfiniteDataLike;
630
+ /**
631
+ * Determine if an item should be updated
632
+ */
633
+ private shouldUpdateItem;
634
+ /**
635
+ * Internal method to update entity based on the "by" option
636
+ */
637
+ private updateEntity;
638
+ /**
639
+ * Wrap a raw entity in an AsyncResult (preserving ok state)
640
+ */
641
+ private wrapEntityInAsyncResult;
642
+ /**
643
+ * Get raw entity data from the query cache
644
+ * Automatically extracts the entity from AsyncResult wrapper
645
+ *
646
+ * When using just a key string:
647
+ * - By default (isExact=false), returns ALL queries with that key as first element
648
+ * - With isExact=true, returns only the query stored as [key]
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * // Get all userDetail queries (returns array)
653
+ * const allUsers = optimisticUpdates.get('userDetail')
654
+ *
655
+ * // Get exact query stored as ['userDetail']
656
+ * const exactUser = optimisticUpdates.get('userDetail', { isExact: true })
657
+ *
658
+ * // Get specific userDetail query with params
659
+ * const user = optimisticUpdates.get(['userDetail', { userUuid: '123' }] as const)
660
+ * ```
661
+ */
662
+ get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options?: {
663
+ isExact?: false;
664
+ }): QueryKeyEntityFromConfig<TQueryKeys, TKey>[];
665
+ get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, options: {
666
+ isExact: true;
667
+ }): QueryKeyEntityFromConfig<TQueryKeys, TKey> | null;
668
+ get<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<QueryKeyParamsFromConfig<TQueryKeys, TKey>>]): QueryKeyEntityFromConfig<TQueryKeys, TKey> | null;
669
+ /**
670
+ * Invalidate queries to trigger a refetch
671
+ *
672
+ * When using just the key, invalidates ALL queries with that key
673
+ * When using key + params tuple, invalidates SPECIFIC query
674
+ *
675
+ * @example
676
+ * ```typescript
677
+ * // Invalidate all userDetail queries
678
+ * await optimisticUpdates.invalidate('userDetail')
679
+ *
680
+ * // Invalidate specific query
681
+ * await optimisticUpdates.invalidate(['userDetail', { userUuid: '123' }] as const)
682
+ * ```
683
+ */
684
+ invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey): Promise<void>;
685
+ invalidate<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(keyTuple: readonly [TKey, Partial<QueryKeyParamsFromConfig<TQueryKeys, TKey>>]): Promise<void>;
686
+ /**
687
+ * Set raw entity data in the query cache for a specific query
688
+ * Automatically wraps the entity in AsyncResult
689
+ *
690
+ * Both formats set a single query - just with different key representations:
691
+ * - 'userDetail' sets the query with key ['userDetail']
692
+ * - ['userDetail', { userUuid: '123' }] sets the query with that exact key
693
+ *
694
+ * @example
695
+ * ```typescript
696
+ * // Set query with just the key
697
+ * optimisticUpdates.set('userDetail', userData)
698
+ *
699
+ * // Set query with key + params
700
+ * optimisticUpdates.set(['userDetail', { userUuid: '123' }] as const, userData)
701
+ * ```
702
+ */
703
+ set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey>): void;
704
+ set<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey, Partial<QueryKeyParamsFromConfig<TQueryKeys, TKey>>], entity: QueryKeyEntityFromConfig<TQueryKeys, TKey>): void;
705
+ /**
706
+ * Update entity data in the query cache optimistically
707
+ *
708
+ * When using just the key, updates ALL queries with that key
709
+ * When using key + params tuple, updates SPECIFIC query
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * // Update all userDetail queries by id
714
+ * optimisticUpdates.update('userDetail', {
715
+ * value: { id: '123', name: 'John Doe' }
716
+ * })
717
+ *
718
+ * // Update specific query by key + params
719
+ * optimisticUpdates.update(['userDetail', { userUuid: '123' }] as const, {
720
+ * value: { name: 'John Doe' }
721
+ * })
722
+ *
723
+ * // Update using predicates
724
+ * optimisticUpdates.update('userList', {
725
+ * value: { isActive: false },
726
+ * by: (user) => user.email === 'john@example.com'
727
+ * })
728
+ * ```
729
+ */
730
+ update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(key: TKey, options: OptimisticUpdateOptions<TEntity>): void;
731
+ update<TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey>>(keyTuple: readonly [TKey, Partial<QueryKeyParamsFromConfig<TQueryKeys, TKey>>], options: OptimisticUpdateOptions<TEntity>): void;
732
+ }
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
+ //#endregion
743
+ //#region src/factory/createApiPrefetchInfiniteQueryUtils.d.ts
744
+ declare function createApiPrefetchInfiniteQueryUtils<TQueryKeys extends object>(options: CreateApiUtilsOptions): {
745
+ usePrefetchKeysetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey>) => {
746
+ execute: () => Promise<void>;
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
+ };
759
+ //#endregion
760
+ //#region src/factory/createApiQueryUtils.d.ts
761
+ declare function createApiQueryUtils<TQueryKeys extends object>(): {
762
+ useQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey>>;
763
+ };
764
+ //#endregion
765
+ //#region src/factory/createApiUtils.d.ts
766
+ /**
767
+ * Factory that creates typed composables based on a user-provided query-keys config.
768
+ * This is an alternative to module augmentation of `QueryKeys`.
769
+ */
770
+ declare function createApiUtils<TQueryKeys extends object>(options: CreateApiUtilsOptions): {
771
+ useOptimisticUpdates: () => OptimisticUpdates<TQueryKeys>;
772
+ useKeysetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey>) => {
773
+ hasNextPage: vue0.ComputedRef<boolean>;
774
+ isError: vue0.ComputedRef<boolean>;
775
+ isFetching: vue0.ComputedRef<boolean>;
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>) => {
795
+ execute: () => Promise<void>;
796
+ };
797
+ usePrefetchOffsetInfiniteQuery: <TKey extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey>) => {
798
+ execute: () => Promise<void>;
799
+ };
800
+ usePrefetchQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey>) => {
801
+ execute: () => Promise<void>;
802
+ };
803
+ useQuery: <TKey extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey>>;
804
+ };
805
+ //#endregion
806
+ export { ApiError, ApiErrorCode, ApiErrorCodes, ApiErrorObject, ApiExpectedError, ApiKnownErrorObject, ApiResult, ApiUnexpectedError, ApiUnknownErrorObject, AsyncResult, AsyncResultErr, AsyncResultLoading, AsyncResultOk, type CreateApiUtilsOptions, HasEntity, InfiniteQueryOptions, KeysetInfiniteQueryOptions, KeysetPagination, KeysetPaginationParams, KeysetPaginationResponse, KeysetPaginationResult, OffsetInfiniteQueryOptions, OffsetPagination, OffsetPaginationParams, OffsetPaginationResponse, OffsetPaginationResult, OptimisticUpdateOptions, OptimisticUpdates, PaginatedDataDto, type QueryConfig, QueryKeyEntity, QueryKeyEntityFromConfig, QueryKeyParams, QueryKeyParamsFromConfig, QueryKeys, QueryKeysWithEntity, QueryKeysWithEntityFromConfig, QueryParams, Sort, SortDirection, UseMutationReturnType, UseQueryOptions, UseQueryReturnType, WithFilterQuery, WithSearchQuery, WithSortQuery, createApiInfiniteQueryUtils, createApiOptimisticUpdatesUtils, createApiPrefetchInfiniteQueryUtils, createApiPrefetchQueryUtils, createApiQueryUtils, createApiUtils, createOptimisticUpdates, setQueryConfig, useKeysetInfiniteQuery, useMutation, useOffsetInfiniteQuery, usePrefetchQuery, useQuery };