@navios/react-query 0.5.1 → 0.5.2
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/CHANGELOG.md +34 -0
- package/dist/src/client/declare-client.d.mts.map +1 -1
- package/dist/src/client/types.d.mts +85 -1
- package/dist/src/client/types.d.mts.map +1 -1
- package/dist/src/mutation/make-hook.d.mts +1 -1
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/src/mutation/types.d.mts +1 -1
- package/dist/src/mutation/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/_tsup-dts-rollup.d.mts +91 -2
- package/lib/_tsup-dts-rollup.d.ts +91 -2
- package/lib/index.d.mts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -7
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +7 -7
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/make-mutation.spec.mts +67 -0
- package/src/client/__type-tests__/client-instance.spec-d.mts +151 -1
- package/src/client/declare-client.mts +12 -8
- package/src/client/types.mts +323 -0
- package/src/mutation/make-hook.mts +5 -2
- package/src/mutation/types.mts +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbstractEndpoint } from '@navios/builder';
|
|
2
2
|
import type { AnyEndpointConfig } from '@navios/builder';
|
|
3
3
|
import type { BaseEndpointConfig } from '@navios/builder';
|
|
4
|
+
import type { BaseStreamConfig } from '@navios/builder';
|
|
4
5
|
import type { BuilderInstance } from '@navios/builder';
|
|
5
6
|
import type { DataTag } from '@tanstack/react-query';
|
|
6
7
|
import type { EndpointFunctionArgs } from '@navios/builder';
|
|
@@ -345,6 +346,82 @@ declare interface ClientInstance {
|
|
|
345
346
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
346
347
|
urlParams: UrlParams<Url>;
|
|
347
348
|
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
349
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
350
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
351
|
+
}, mutationOptions: {
|
|
352
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
353
|
+
useKey: UseKey;
|
|
354
|
+
useContext?: () => Context;
|
|
355
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
356
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
357
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
358
|
+
urlParams: UrlParams<Url>;
|
|
359
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
360
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
361
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
362
|
+
}, mutationOptions?: {
|
|
363
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
364
|
+
useContext?: () => Context;
|
|
365
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
366
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
367
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
368
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
369
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
370
|
+
}, mutationOptions: {
|
|
371
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
372
|
+
useKey: UseKey;
|
|
373
|
+
useContext?: () => Context;
|
|
374
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
375
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
376
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
377
|
+
urlParams: UrlParams<Url>;
|
|
378
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
379
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown>(endpoint: {
|
|
380
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
381
|
+
}, mutationOptions?: {
|
|
382
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
383
|
+
useContext?: () => Context;
|
|
384
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
385
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
386
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
387
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
388
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
389
|
+
}, mutationOptions: {
|
|
390
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
391
|
+
useKey: UseKey;
|
|
392
|
+
useContext?: () => Context;
|
|
393
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
394
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
395
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
396
|
+
urlParams: UrlParams<Url>;
|
|
397
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
398
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
399
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
400
|
+
}, mutationOptions?: {
|
|
401
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
402
|
+
useContext?: () => Context;
|
|
403
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
404
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
405
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
406
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
407
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
408
|
+
}, mutationOptions: {
|
|
409
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
410
|
+
useKey: UseKey;
|
|
411
|
+
useContext?: () => Context;
|
|
412
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
413
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
414
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
415
|
+
urlParams: UrlParams<Url>;
|
|
416
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, undefined>;
|
|
417
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown>(endpoint: {
|
|
418
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
419
|
+
}, mutationOptions?: {
|
|
420
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
421
|
+
useContext?: () => Context;
|
|
422
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
423
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
424
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & StreamHelper<Method, Url, undefined, undefined>;
|
|
348
425
|
}
|
|
349
426
|
export { ClientInstance }
|
|
350
427
|
export { ClientInstance as ClientInstance_alias_1 }
|
|
@@ -543,7 +620,7 @@ declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown,
|
|
|
543
620
|
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
544
621
|
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
545
622
|
urlParams: UrlParams<Config["url"]>;
|
|
546
|
-
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
623
|
+
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> | ((data: z.core.output<Config["responseSchema"]>) => z.core.output<Config["responseSchema"]>) extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
547
624
|
[dataTagSymbol]: Result;
|
|
548
625
|
[dataTagErrorSymbol]: Error;
|
|
549
626
|
} : never;
|
|
@@ -632,7 +709,7 @@ export { mutationKeyCreator as mutationKeyCreator_alias_2 }
|
|
|
632
709
|
* Base parameters for mutation configuration.
|
|
633
710
|
*/
|
|
634
711
|
declare interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false> extends Omit<UseMutationOptions<TData, Error, TVariables>, 'mutationKey' | 'mutationFn' | 'onSuccess' | 'onError' | 'scope'> {
|
|
635
|
-
processResponse
|
|
712
|
+
processResponse?: ProcessResponseFunction<TData, TResponse>;
|
|
636
713
|
/**
|
|
637
714
|
* React hooks that will prepare the context for the mutation onSuccess and onError
|
|
638
715
|
* callbacks. This is useful for when you want to use the context in the callbacks
|
|
@@ -763,4 +840,16 @@ export { Split }
|
|
|
763
840
|
export { Split as Split_alias_1 }
|
|
764
841
|
export { Split as Split_alias_2 }
|
|
765
842
|
|
|
843
|
+
/**
|
|
844
|
+
* Helper type that attaches a stream endpoint to mutation results.
|
|
845
|
+
*/
|
|
846
|
+
declare type StreamHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, QuerySchema = unknown> = {
|
|
847
|
+
endpoint: ((params: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, RequestSchema>>) => Promise<Blob>) & {
|
|
848
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
export { StreamHelper }
|
|
852
|
+
export { StreamHelper as StreamHelper_alias_1 }
|
|
853
|
+
export { StreamHelper as StreamHelper_alias_2 }
|
|
854
|
+
|
|
766
855
|
export { }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbstractEndpoint } from '@navios/builder';
|
|
2
2
|
import type { AnyEndpointConfig } from '@navios/builder';
|
|
3
3
|
import type { BaseEndpointConfig } from '@navios/builder';
|
|
4
|
+
import type { BaseStreamConfig } from '@navios/builder';
|
|
4
5
|
import type { BuilderInstance } from '@navios/builder';
|
|
5
6
|
import type { DataTag } from '@tanstack/react-query';
|
|
6
7
|
import type { EndpointFunctionArgs } from '@navios/builder';
|
|
@@ -345,6 +346,82 @@ declare interface ClientInstance {
|
|
|
345
346
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
346
347
|
urlParams: UrlParams<Url>;
|
|
347
348
|
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
349
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
350
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
351
|
+
}, mutationOptions: {
|
|
352
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
353
|
+
useKey: UseKey;
|
|
354
|
+
useContext?: () => Context;
|
|
355
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
356
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
357
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
358
|
+
urlParams: UrlParams<Url>;
|
|
359
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
360
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
361
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
362
|
+
}, mutationOptions?: {
|
|
363
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
364
|
+
useContext?: () => Context;
|
|
365
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
366
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
367
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
368
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
369
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
370
|
+
}, mutationOptions: {
|
|
371
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
372
|
+
useKey: UseKey;
|
|
373
|
+
useContext?: () => Context;
|
|
374
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
375
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
376
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
377
|
+
urlParams: UrlParams<Url>;
|
|
378
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
379
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown>(endpoint: {
|
|
380
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
381
|
+
}, mutationOptions?: {
|
|
382
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
383
|
+
useContext?: () => Context;
|
|
384
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
385
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
386
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
387
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
388
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
389
|
+
}, mutationOptions: {
|
|
390
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
391
|
+
useKey: UseKey;
|
|
392
|
+
useContext?: () => Context;
|
|
393
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
394
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
395
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
396
|
+
urlParams: UrlParams<Url>;
|
|
397
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
398
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
399
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
400
|
+
}, mutationOptions?: {
|
|
401
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
402
|
+
useContext?: () => Context;
|
|
403
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
404
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
405
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
406
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
407
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
408
|
+
}, mutationOptions: {
|
|
409
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
410
|
+
useKey: UseKey;
|
|
411
|
+
useContext?: () => Context;
|
|
412
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
413
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
414
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
415
|
+
urlParams: UrlParams<Url>;
|
|
416
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, undefined>;
|
|
417
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown>(endpoint: {
|
|
418
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
419
|
+
}, mutationOptions?: {
|
|
420
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
421
|
+
useContext?: () => Context;
|
|
422
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
423
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
424
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & StreamHelper<Method, Url, undefined, undefined>;
|
|
348
425
|
}
|
|
349
426
|
export { ClientInstance }
|
|
350
427
|
export { ClientInstance as ClientInstance_alias_1 }
|
|
@@ -543,7 +620,7 @@ declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown,
|
|
|
543
620
|
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
544
621
|
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
545
622
|
urlParams: UrlParams<Config["url"]>;
|
|
546
|
-
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
623
|
+
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> | ((data: z.core.output<Config["responseSchema"]>) => z.core.output<Config["responseSchema"]>) extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
547
624
|
[dataTagSymbol]: Result;
|
|
548
625
|
[dataTagErrorSymbol]: Error;
|
|
549
626
|
} : never;
|
|
@@ -632,7 +709,7 @@ export { mutationKeyCreator as mutationKeyCreator_alias_2 }
|
|
|
632
709
|
* Base parameters for mutation configuration.
|
|
633
710
|
*/
|
|
634
711
|
declare interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false> extends Omit<UseMutationOptions<TData, Error, TVariables>, 'mutationKey' | 'mutationFn' | 'onSuccess' | 'onError' | 'scope'> {
|
|
635
|
-
processResponse
|
|
712
|
+
processResponse?: ProcessResponseFunction<TData, TResponse>;
|
|
636
713
|
/**
|
|
637
714
|
* React hooks that will prepare the context for the mutation onSuccess and onError
|
|
638
715
|
* callbacks. This is useful for when you want to use the context in the callbacks
|
|
@@ -763,4 +840,16 @@ export { Split }
|
|
|
763
840
|
export { Split as Split_alias_1 }
|
|
764
841
|
export { Split as Split_alias_2 }
|
|
765
842
|
|
|
843
|
+
/**
|
|
844
|
+
* Helper type that attaches a stream endpoint to mutation results.
|
|
845
|
+
*/
|
|
846
|
+
declare type StreamHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, QuerySchema = unknown> = {
|
|
847
|
+
endpoint: ((params: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, RequestSchema>>) => Promise<Blob>) & {
|
|
848
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
export { StreamHelper }
|
|
852
|
+
export { StreamHelper as StreamHelper_alias_1 }
|
|
853
|
+
export { StreamHelper as StreamHelper_alias_2 }
|
|
854
|
+
|
|
766
855
|
export { }
|
package/lib/index.d.mts
CHANGED
|
@@ -26,6 +26,7 @@ export { BaseMutationParams } from './_tsup-dts-rollup.mjs';
|
|
|
26
26
|
export { BaseMutationArgs } from './_tsup-dts-rollup.mjs';
|
|
27
27
|
export { EndpointHelper } from './_tsup-dts-rollup.mjs';
|
|
28
28
|
export { ClientEndpointHelper } from './_tsup-dts-rollup.mjs';
|
|
29
|
+
export { StreamHelper } from './_tsup-dts-rollup.mjs';
|
|
29
30
|
export { ClientInstance } from './_tsup-dts-rollup.mjs';
|
|
30
31
|
export { declareClient } from './_tsup-dts-rollup.mjs';
|
|
31
32
|
export { QueryConfig } from './_tsup-dts-rollup.mjs';
|
package/lib/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { BaseMutationParams } from './_tsup-dts-rollup.js';
|
|
|
26
26
|
export { BaseMutationArgs } from './_tsup-dts-rollup.js';
|
|
27
27
|
export { EndpointHelper } from './_tsup-dts-rollup.js';
|
|
28
28
|
export { ClientEndpointHelper } from './_tsup-dts-rollup.js';
|
|
29
|
+
export { StreamHelper } from './_tsup-dts-rollup.js';
|
|
29
30
|
export { ClientInstance } from './_tsup-dts-rollup.js';
|
|
30
31
|
export { declareClient } from './_tsup-dts-rollup.js';
|
|
31
32
|
export { QueryConfig } from './_tsup-dts-rollup.js';
|
package/lib/index.js
CHANGED
|
@@ -154,7 +154,8 @@ function createMutationKey(config, options = {
|
|
|
154
154
|
var mutationKeyCreator = createMutationKey;
|
|
155
155
|
function makeMutation(endpoint, options) {
|
|
156
156
|
const config = endpoint.config;
|
|
157
|
-
const mutationKey = createMutationKey(config,
|
|
157
|
+
const mutationKey = createMutationKey(config, {
|
|
158
|
+
...options});
|
|
158
159
|
const result = (keyParams) => {
|
|
159
160
|
const queryClient = reactQuery.useQueryClient();
|
|
160
161
|
const {
|
|
@@ -183,7 +184,7 @@ function makeMutation(endpoint, options) {
|
|
|
183
184
|
} : void 0,
|
|
184
185
|
async mutationFn(params) {
|
|
185
186
|
const response = await endpoint(params);
|
|
186
|
-
return processResponse(response);
|
|
187
|
+
return processResponse ? processResponse(response) : response;
|
|
187
188
|
},
|
|
188
189
|
onSuccess: onSuccess ? (data, variables) => {
|
|
189
190
|
return onSuccess?.(queryClient, data, variables, context);
|
|
@@ -291,11 +292,10 @@ function declareClient({
|
|
|
291
292
|
}
|
|
292
293
|
function mutationFromEndpoint(endpoint, options) {
|
|
293
294
|
return makeMutation(endpoint, {
|
|
294
|
-
processResponse: options
|
|
295
|
-
useContext: options
|
|
296
|
-
onSuccess: options
|
|
297
|
-
|
|
298
|
-
onError: options.onError,
|
|
295
|
+
processResponse: options?.processResponse,
|
|
296
|
+
useContext: options?.useContext,
|
|
297
|
+
onSuccess: options?.onSuccess,
|
|
298
|
+
onError: options?.onError,
|
|
299
299
|
...defaults
|
|
300
300
|
});
|
|
301
301
|
}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/query/key-creator.mts","../src/query/make-options.mts","../src/query/make-infinite-options.mts","../src/mutation/key-creator.mts","../src/mutation/make-hook.mts","../src/client/declare-client.mts"],"names":["bindUrlParams","queryOptions","result","useQuery","useSuspenseQuery","infiniteQueryOptions","useInfiniteQuery","useSuspenseInfiniteQuery","useQueryClient","useMutation","useIsMutating"],"mappings":";;;;;;AAmBO,SAAS,cAAA,CAOd,MAAA,EACA,OAAA,EACA,WAAA,EASA;AACA,EAAA,MAAM,MAAM,MAAA,CAAO,GAAA;AACnB,EAAA,MAAM,WAAW,GAAA,CAAI,KAAA,CAAM,GAAG,CAAA,CAAE,OAAO,OAAO,CAAA;AAC9C,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,QAAA;AAAA;AAAA,IAEV,OAAA,EAAS,CAAC,MAAA,KAAW;AACnB,MAAA,MAAM,WAAA,GACJ,MAAA,IAAU,aAAA,IAAiB,MAAA,IAAU,QAAA,IAAY,MAAA,GAC7C,MAAA,CAAO,WAAA,EAAa,KAAA,CAAM,MAAA,CAAO,MAAM,CAAA,GACvC,EAAC;AACP,MAAA,OAAO;AAAA,QACL,GAAI,OAAA,CAAQ,SAAA,IAAa,EAAC;AAAA,QAC1B,GAAG,QAAA,CAAS,GAAA;AAAA,UAAI,CAAC,IAAA,KACf,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA;AAAA;AAAA,YAEf,OAAO,SAAA,CAAU,IAAA,CAAK,MAAM,CAAC,CAAC,EAAE,QAAA;AAAS,cACzC;AAAA,SACN;AAAA,QACA,GAAI,OAAA,CAAQ,SAAA,IAAa,EAAC;AAAA,QAC1B,eAAe;AAAC,OAClB;AAAA,IASF,CAAA;AAAA;AAAA,IAEA,SAAA,EAAW,CAAC,MAAA,KAAW;AACrB,MAAA,OAAO;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from '@navios/builder'\nimport type { DataTag, InfiniteData } from '@tanstack/react-query'\n\nimport { bindUrlParams } from '@navios/builder'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryKeyCreatorResult, QueryParams } from './types.mjs'\n\n/**\n * Creates a query key generator for a given endpoint configuration.\n *\n * The returned object provides methods to generate query keys that can be used\n * with TanStack Query for caching, invalidation, and data tagging.\n *\n * @param config - The endpoint configuration\n * @param options - Query parameters including processResponse and key prefix/suffix\n * @param isInfinite - Whether this is for an infinite query\n * @returns An object with methods to generate query keys\n */\nexport function createQueryKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n IsInfinite extends boolean,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options,\n _isInfinite: IsInfinite,\n): QueryKeyCreatorResult<\n Config['querySchema'],\n Url,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? Result\n : never,\n IsInfinite,\n HasParams\n> {\n const url = config.url as Url\n const urlParts = url.split('/').filter(Boolean) as Split<Url, '/'>\n return {\n template: urlParts,\n // @ts-expect-error We have correct types in return type\n dataTag: (params) => {\n const queryParams =\n params && 'querySchema' in config && 'params' in params\n ? config.querySchema?.parse(params.params)\n : []\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n queryParams ?? [],\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n // @ts-expect-error We have correct types in return type\n filterKey: (params) => {\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n\n bindToUrl: (params) => {\n return bindUrlParams<Url>(url, params ?? ({} as never))\n },\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createQueryKey instead */\nexport const queryKeyCreator = createQueryKey\n","import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder'\nimport type {\n DataTag,\n QueryClient,\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from '@tanstack/react-query'\n\nimport { queryOptions, useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryArgs, QueryParams } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create query options for\n * @param options - Query configuration including processResponse\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates query options with attached helpers\n */\nexport function makeQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n BaseQuery extends Omit<\n UseQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'enabled'\n | 'throwOnError'\n | 'placeholderData'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, false)\n const processResponse = options.processResponse\n\n const result = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T ? T : Result,\n DataTag<Split<Config['url'], '/'>, Result, Error>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return queryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n ...params,\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n ...baseQuery,\n })\n }\n result.queryKey = queryKey\n result.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useQuery(result(params))\n }\n\n result.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseQuery(result(params))\n }\n\n result.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.dataTag(params),\n })\n }\n\n result.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n UrlParams,\n} from '@navios/builder'\nimport type {\n InfiniteData,\n QueryClient,\n UseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryOptions,\n} from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n infiniteQueryOptions,\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport type { InfiniteQueryOptions, QueryArgs } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates infinite query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query infinite options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create infinite query options for\n * @param options - Infinite query configuration including processResponse and pagination params\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates infinite query options with attached helpers\n */\nexport function makeInfiniteQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends InfiniteQueryOptions<Config>,\n BaseQuery extends Omit<\n UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'placeholderData'\n | 'throwOnError'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, true)\n\n const processResponse = options.processResponse\n const res = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseInfiniteQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T\n ? T\n : InfiniteData<Result>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return infiniteQueryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal, pageParam }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n // @ts-expect-error TS2345 We bind the url params only if the url has params\n urlParams: params.urlParams as z.infer<UrlParams<Config['url']>>,\n params: {\n ...('params' in params ? params.params : {}),\n ...(pageParam as z.infer<Config['querySchema']>),\n },\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options.getPreviousPageParam,\n initialPageParam:\n options.initialPageParam ??\n config.querySchema.parse('params' in params ? params.params : {}),\n ...baseQuery,\n })\n }\n res.queryKey = queryKey\n\n res.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useInfiniteQuery(res(params))\n }\n\n res.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseInfiniteQuery(res(params))\n }\n\n res.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.dataTag(params),\n })\n }\n\n res.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return res\n}\n","import type {\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { DataTag } from '@tanstack/react-query'\n\nimport type { QueryParams } from '../query/types.mjs'\n\nimport { createQueryKey } from '../query/key-creator.mjs'\n\n/**\n * Creates a mutation key generator for a given endpoint configuration.\n *\n * @param config - The endpoint configuration\n * @param options - Optional query parameters with a default `processResponse` function\n * @returns A function that generates mutation keys\n *\n * @example Basic usage:\n * ```typescript\n * const createMutationKey = createMutationKey(endpoint.config);\n * const mutationKey = createMutationKey({ urlParams: { id: 123 } });\n * ```\n *\n * @example Advanced usage with processResponse:\n * ```ts\n * const createMutationKey = createMutationKey(endpoint.config, {\n * processResponse: (data) => {\n * if (!data.success) {\n * throw new Error(data.message);\n * }\n * return data.data;\n * },\n * });\n * // We create a mutation that will be shared across the project for all passed userId\n * const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });\n * ```\n */\nexport function createMutationKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options = {\n processResponse: (data) => data,\n } as Options,\n): (\n params: HasParams extends true ? { urlParams: UrlParams<Url> } : {},\n) => Options['processResponse'] extends (...args: unknown[]) => infer Result\n ? DataTag<[Config['url']], Result, Error>\n : never {\n const queryKey = createQueryKey(config, options, false)\n\n // @ts-expect-error We have correct types in return type\n return (params) => {\n return queryKey.filterKey(params)\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createMutationKey instead */\nexport const mutationKeyCreator = createMutationKey\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n NaviosZodRequest,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { UseMutationResult } from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n useIsMutating,\n useMutation,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { MutationParams } from './types.mjs'\n\nimport { createMutationKey } from './key-creator.mjs'\n\n/**\n * Creates a mutation hook for a given endpoint.\n *\n * Returns a function that when called returns a TanStack Query mutation result.\n * The returned function also has helper methods attached (mutationKey, useIsMutating).\n *\n * @param endpoint - The navios endpoint to create a mutation hook for\n * @param options - Mutation configuration including processResponse and callbacks\n * @returns A hook function that returns mutation result with attached helpers\n */\nexport function makeMutation<\n Config extends AnyEndpointConfig,\n TData = unknown,\n TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>,\n TResponse = z.output<Config['responseSchema']>,\n TContext = unknown,\n UseKey extends boolean = false,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: MutationParams<\n Config,\n TData,\n TVariables,\n TResponse,\n TContext,\n UseKey\n >,\n) {\n const config = endpoint.config\n\n const mutationKey = createMutationKey(config, options)\n const result = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): UseMutationResult<TData, Error, NaviosZodRequest<Config>> => {\n const queryClient = useQueryClient()\n const {\n useKey,\n useContext,\n onError,\n onSuccess,\n keyPrefix: _keyPrefix,\n keySuffix: _keySuffix,\n processResponse,\n ...rest\n } = options\n\n const context = useContext?.() as TContext\n\n // @ts-expect-error The types match\n return useMutation(\n {\n ...rest,\n mutationKey: useKey\n ? mutationKey({\n urlParams: keyParams,\n })\n : undefined,\n scope: useKey\n ? {\n id: JSON.stringify(\n mutationKey({\n urlParams: keyParams,\n }),\n ),\n }\n : undefined,\n async mutationFn(params: TVariables) {\n const response = await endpoint(params)\n\n return processResponse(response) as TData\n },\n onSuccess: onSuccess\n ? (data: TData, variables: TVariables) => {\n return onSuccess?.(queryClient, data, variables, context)\n }\n : undefined,\n onError: onError\n ? (err: Error, variables: TVariables) => {\n return onError?.(queryClient, err, variables, context)\n }\n : undefined,\n },\n queryClient,\n )\n }\n result.useIsMutating = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): boolean => {\n if (!options.useKey) {\n throw new Error(\n 'useIsMutating can only be used when useKey is set to true',\n )\n }\n const isMutating = useIsMutating({\n mutationKey: mutationKey({\n urlParams: keyParams,\n }),\n })\n return isMutating > 0\n }\n result.mutationKey = mutationKey\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n HttpMethod,\n} from '@navios/builder'\nimport type { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport type { ClientOptions, ProcessResponseFunction } from '../common/types.mjs'\nimport type { MutationArgs } from '../mutation/types.mjs'\nimport type { ClientInstance } from './types.mjs'\n\nimport { makeMutation } from '../mutation/make-hook.mjs'\nimport { makeInfiniteQueryOptions } from '../query/make-infinite-options.mjs'\nimport { makeQueryOptions } from '../query/make-options.mjs'\n\n/**\n * Configuration for declaring a query endpoint.\n */\nexport interface QueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema = ZodObject,\n Response extends ZodType = ZodType,\n Result = z.output<Response>,\n RequestSchema = unknown,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => Result\n}\n\n/**\n * Configuration for declaring an infinite query endpoint.\n */\nexport type InfiniteQueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema extends ZodObject = ZodObject,\n Response extends ZodType = ZodType,\n PageResult = z.output<Response>,\n Result = InfiniteData<PageResult>,\n RequestSchema = unknown,\n> = {\n method: Method\n url: Url\n querySchema: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => PageResult\n select?: (data: InfiniteData<PageResult>) => Result\n getNextPageParam: (\n lastPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema> | undefined\n getPreviousPageParam?: (\n firstPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema>\n initialPageParam?: z.input<QuerySchema>\n}\n\n/**\n * Configuration for declaring a mutation endpoint.\n */\nexport interface MutationConfig<\n Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' =\n | 'POST'\n | 'PUT'\n | 'PATCH'\n | 'DELETE',\n Url extends string = string,\n RequestSchema = Method extends 'DELETE' ? never : ZodObject,\n QuerySchema = unknown,\n Response extends ZodType = ZodType,\n ReqResult = z.output<Response>,\n Result = unknown,\n Context = unknown,\n UseKey extends boolean = false,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse: ProcessResponseFunction<Result, ReqResult>\n useContext?: () => Context\n onSuccess?: (\n queryClient: QueryClient,\n data: NoInfer<Result>,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n useKey?: UseKey\n}\n\n/**\n * Creates a client instance for making type-safe queries and mutations.\n *\n * @param options - Client configuration including the API builder and defaults\n * @returns A client instance with query, infiniteQuery, and mutation methods\n *\n * @example\n * ```typescript\n * const api = createBuilder({ baseUrl: '/api' });\n * const client = declareClient({ api });\n *\n * const getUser = client.query({\n * method: 'GET',\n * url: '/users/$id',\n * responseSchema: UserSchema,\n * });\n *\n * // In a component\n * const { data } = useSuspenseQuery(getUser({ urlParams: { id: '123' } }));\n * ```\n */\nexport function declareClient<Options extends ClientOptions>({\n api,\n defaults = {},\n}: Options): ClientInstance {\n function query(config: QueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const queryOptions = makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n })\n // @ts-expect-error We attach the endpoint to the queryOptions\n queryOptions.endpoint = endpoint\n return queryOptions\n }\n\n function queryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options?: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n },\n ) {\n return makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n })\n }\n\n function infiniteQuery(config: InfiniteQueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n const infiniteQueryOptions = makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n getNextPageParam: config.getNextPageParam,\n getPreviousPageParam: config.getPreviousPageParam,\n initialPageParam: config.initialPageParam,\n })\n\n // @ts-expect-error We attach the endpoint to the infiniteQueryOptions\n infiniteQueryOptions.endpoint = endpoint\n return infiniteQueryOptions\n }\n\n function infiniteQueryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n getNextPageParam: (\n lastPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']> | undefined\n getPreviousPageParam?: (\n firstPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']>\n initialPageParam?: z.input<AnyEndpointConfig['querySchema']>\n },\n ) {\n return makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options?.getPreviousPageParam,\n initialPageParam: options?.initialPageParam,\n })\n }\n\n function mutation(config: MutationConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n function mutationFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse: ProcessResponseFunction\n useContext?: () => unknown\n onSuccess?: (\n queryClient: QueryClient,\n data: unknown,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n },\n ) {\n return makeMutation(endpoint, {\n processResponse: options.processResponse,\n useContext: options.useContext,\n onSuccess: options.onSuccess,\n // @ts-expect-error simplify types here\n onError: options.onError,\n ...defaults,\n })\n }\n\n function multipartMutation(config: MutationConfig) {\n const endpoint = api.declareMultipart({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n return {\n // @ts-expect-error We simplified types here\n query,\n // @ts-expect-error We simplified types here\n queryFromEndpoint,\n // @ts-expect-error We simplified types here\n infiniteQuery,\n // @ts-expect-error We simplified types here\n infiniteQueryFromEndpoint,\n // @ts-expect-error We simplified types here\n mutation,\n // @ts-expect-error We simplified types here\n mutationFromEndpoint,\n // @ts-expect-error We simplified types here\n multipartMutation,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/query/key-creator.mts","../src/query/make-options.mts","../src/query/make-infinite-options.mts","../src/mutation/key-creator.mts","../src/mutation/make-hook.mts","../src/client/declare-client.mts"],"names":["bindUrlParams","queryOptions","result","useQuery","useSuspenseQuery","infiniteQueryOptions","useInfiniteQuery","useSuspenseInfiniteQuery","useQueryClient","useMutation","useIsMutating"],"mappings":";;;;;;AAmBO,SAAS,cAAA,CAOd,MAAA,EACA,OAAA,EACA,WAAA,EASA;AACA,EAAA,MAAM,MAAM,MAAA,CAAO,GAAA;AACnB,EAAA,MAAM,WAAW,GAAA,CAAI,KAAA,CAAM,GAAG,CAAA,CAAE,OAAO,OAAO,CAAA;AAC9C,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,QAAA;AAAA;AAAA,IAEV,OAAA,EAAS,CAAC,MAAA,KAAW;AACnB,MAAA,MAAM,WAAA,GACJ,M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QAAA,EAAU;AAAA,MACzC,eAAA,EAAiB,MAAA,CAAO,eAAA,KAAoB,CAAC,IAAA,KAAS,IAAA,CAAA;AAAA,MACtD,YAAY,MAAA,CAAO,UAAA;AAAA;AAAA,MAEnB,WAAW,MAAA,CAAO,SAAA;AAAA;AAAA,MAElB,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,GAAG;AAAA,KACJ,CAAA;AAGD,IAAAA,aAAY,QAAA,GAAW,QAAA;AACvB,IAAA,OAAOA,YAAAA;AAAA,EACT;AAEA,EAAA,OAAO;AAAA;AAAA,IAEL,KAAA;AAAA;AAAA,IAEA,iBAAA;AAAA;AAAA,IAEA,aAAA;AAAA;AAAA,IAEA,yBAAA;AAAA;AAAA,IAEA,QAAA;AAAA;AAAA,IAEA,oBAAA;AAAA;AAAA,IAEA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { AnyEndpointConfig, UrlHasParams } from '@navios/builder'\nimport type { DataTag, InfiniteData } from '@tanstack/react-query'\n\nimport { bindUrlParams } from '@navios/builder'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryKeyCreatorResult, QueryParams } from './types.mjs'\n\n/**\n * Creates a query key generator for a given endpoint configuration.\n *\n * The returned object provides methods to generate query keys that can be used\n * with TanStack Query for caching, invalidation, and data tagging.\n *\n * @param config - The endpoint configuration\n * @param options - Query parameters including processResponse and key prefix/suffix\n * @param isInfinite - Whether this is for an infinite query\n * @returns An object with methods to generate query keys\n */\nexport function createQueryKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n IsInfinite extends boolean,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options,\n _isInfinite: IsInfinite,\n): QueryKeyCreatorResult<\n Config['querySchema'],\n Url,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? Result\n : never,\n IsInfinite,\n HasParams\n> {\n const url = config.url as Url\n const urlParts = url.split('/').filter(Boolean) as Split<Url, '/'>\n return {\n template: urlParts,\n // @ts-expect-error We have correct types in return type\n dataTag: (params) => {\n const queryParams =\n params && 'querySchema' in config && 'params' in params\n ? config.querySchema?.parse(params.params)\n : []\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n queryParams ?? [],\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n // @ts-expect-error We have correct types in return type\n filterKey: (params) => {\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n\n bindToUrl: (params) => {\n return bindUrlParams<Url>(url, params ?? ({} as never))\n },\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createQueryKey instead */\nexport const queryKeyCreator = createQueryKey\n","import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder'\nimport type {\n DataTag,\n QueryClient,\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from '@tanstack/react-query'\n\nimport { queryOptions, useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryArgs, QueryParams } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create query options for\n * @param options - Query configuration including processResponse\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates query options with attached helpers\n */\nexport function makeQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n BaseQuery extends Omit<\n UseQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'enabled'\n | 'throwOnError'\n | 'placeholderData'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, false)\n const processResponse = options.processResponse\n\n const result = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T ? T : Result,\n DataTag<Split<Config['url'], '/'>, Result, Error>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return queryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n ...params,\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n ...baseQuery,\n })\n }\n result.queryKey = queryKey\n result.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useQuery(result(params))\n }\n\n result.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseQuery(result(params))\n }\n\n result.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.dataTag(params),\n })\n }\n\n result.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n UrlParams,\n} from '@navios/builder'\nimport type {\n InfiniteData,\n QueryClient,\n UseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryOptions,\n} from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n infiniteQueryOptions,\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport type { InfiniteQueryOptions, QueryArgs } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates infinite query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query infinite options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create infinite query options for\n * @param options - Infinite query configuration including processResponse and pagination params\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates infinite query options with attached helpers\n */\nexport function makeInfiniteQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends InfiniteQueryOptions<Config>,\n BaseQuery extends Omit<\n UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'placeholderData'\n | 'throwOnError'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, true)\n\n const processResponse = options.processResponse\n const res = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseInfiniteQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T\n ? T\n : InfiniteData<Result>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return infiniteQueryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal, pageParam }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n // @ts-expect-error TS2345 We bind the url params only if the url has params\n urlParams: params.urlParams as z.infer<UrlParams<Config['url']>>,\n params: {\n ...('params' in params ? params.params : {}),\n ...(pageParam as z.infer<Config['querySchema']>),\n },\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options.getPreviousPageParam,\n initialPageParam:\n options.initialPageParam ??\n config.querySchema.parse('params' in params ? params.params : {}),\n ...baseQuery,\n })\n }\n res.queryKey = queryKey\n\n res.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useInfiniteQuery(res(params))\n }\n\n res.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseInfiniteQuery(res(params))\n }\n\n res.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.dataTag(params),\n })\n }\n\n res.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return res\n}\n","import type {\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { DataTag } from '@tanstack/react-query'\n\nimport type { QueryParams } from '../query/types.mjs'\n\nimport { createQueryKey } from '../query/key-creator.mjs'\n\n/**\n * Creates a mutation key generator for a given endpoint configuration.\n *\n * @param config - The endpoint configuration\n * @param options - Optional query parameters with a default `processResponse` function\n * @returns A function that generates mutation keys\n *\n * @example Basic usage:\n * ```typescript\n * const createMutationKey = createMutationKey(endpoint.config);\n * const mutationKey = createMutationKey({ urlParams: { id: 123 } });\n * ```\n *\n * @example Advanced usage with processResponse:\n * ```ts\n * const createMutationKey = createMutationKey(endpoint.config, {\n * processResponse: (data) => {\n * if (!data.success) {\n * throw new Error(data.message);\n * }\n * return data.data;\n * },\n * });\n * // We create a mutation that will be shared across the project for all passed userId\n * const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });\n * ```\n */\nexport function createMutationKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options = {\n processResponse: (data) => data,\n } as Options,\n): (\n params: HasParams extends true ? { urlParams: UrlParams<Url> } : {},\n) => Options['processResponse'] extends (...args: unknown[]) => infer Result\n ? DataTag<[Config['url']], Result, Error>\n : never {\n const queryKey = createQueryKey(config, options, false)\n\n // @ts-expect-error We have correct types in return type\n return (params) => {\n return queryKey.filterKey(params)\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createMutationKey instead */\nexport const mutationKeyCreator = createMutationKey\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n NaviosZodRequest,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { UseMutationResult } from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n useIsMutating,\n useMutation,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { MutationParams } from './types.mjs'\n\nimport { createMutationKey } from './key-creator.mjs'\n\n/**\n * Creates a mutation hook for a given endpoint.\n *\n * Returns a function that when called returns a TanStack Query mutation result.\n * The returned function also has helper methods attached (mutationKey, useIsMutating).\n *\n * @param endpoint - The navios endpoint to create a mutation hook for\n * @param options - Mutation configuration including processResponse and callbacks\n * @returns A hook function that returns mutation result with attached helpers\n */\nexport function makeMutation<\n Config extends AnyEndpointConfig,\n TData = unknown,\n TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>,\n TResponse = z.output<Config['responseSchema']>,\n TContext = unknown,\n UseKey extends boolean = false,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: MutationParams<\n Config,\n TData,\n TVariables,\n TResponse,\n TContext,\n UseKey\n >,\n) {\n const config = endpoint.config\n\n const mutationKey = createMutationKey(config, {\n ...options,\n processResponse: options.processResponse ?? ((data) => data),\n })\n const result = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): UseMutationResult<TData, Error, NaviosZodRequest<Config>> => {\n const queryClient = useQueryClient()\n const {\n useKey,\n useContext,\n onError,\n onSuccess,\n keyPrefix: _keyPrefix,\n keySuffix: _keySuffix,\n processResponse,\n ...rest\n } = options\n\n const context = useContext?.() as TContext\n\n // @ts-expect-error The types match\n return useMutation(\n {\n ...rest,\n mutationKey: useKey\n ? mutationKey({\n urlParams: keyParams,\n })\n : undefined,\n scope: useKey\n ? {\n id: JSON.stringify(\n mutationKey({\n urlParams: keyParams,\n }),\n ),\n }\n : undefined,\n async mutationFn(params: TVariables) {\n const response = await endpoint(params)\n\n return (processResponse ? processResponse(response) : response) as TData\n },\n onSuccess: onSuccess\n ? (data: TData, variables: TVariables) => {\n return onSuccess?.(queryClient, data, variables, context)\n }\n : undefined,\n onError: onError\n ? (err: Error, variables: TVariables) => {\n return onError?.(queryClient, err, variables, context)\n }\n : undefined,\n },\n queryClient,\n )\n }\n result.useIsMutating = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): boolean => {\n if (!options.useKey) {\n throw new Error(\n 'useIsMutating can only be used when useKey is set to true',\n )\n }\n const isMutating = useIsMutating({\n mutationKey: mutationKey({\n urlParams: keyParams,\n }),\n })\n return isMutating > 0\n }\n result.mutationKey = mutationKey\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AbstractStream,\n AnyEndpointConfig,\n AnyStreamConfig,\n HttpMethod,\n} from '@navios/builder'\nimport type { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport type { ClientOptions, ProcessResponseFunction } from '../common/types.mjs'\nimport type { MutationArgs } from '../mutation/types.mjs'\nimport type { ClientInstance } from './types.mjs'\n\nimport { makeMutation } from '../mutation/make-hook.mjs'\nimport { makeInfiniteQueryOptions } from '../query/make-infinite-options.mjs'\nimport { makeQueryOptions } from '../query/make-options.mjs'\n\n/**\n * Configuration for declaring a query endpoint.\n */\nexport interface QueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema = ZodObject,\n Response extends ZodType = ZodType,\n Result = z.output<Response>,\n RequestSchema = unknown,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => Result\n}\n\n/**\n * Configuration for declaring an infinite query endpoint.\n */\nexport type InfiniteQueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema extends ZodObject = ZodObject,\n Response extends ZodType = ZodType,\n PageResult = z.output<Response>,\n Result = InfiniteData<PageResult>,\n RequestSchema = unknown,\n> = {\n method: Method\n url: Url\n querySchema: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => PageResult\n select?: (data: InfiniteData<PageResult>) => Result\n getNextPageParam: (\n lastPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema> | undefined\n getPreviousPageParam?: (\n firstPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema>\n initialPageParam?: z.input<QuerySchema>\n}\n\n/**\n * Configuration for declaring a mutation endpoint.\n */\nexport interface MutationConfig<\n Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' =\n | 'POST'\n | 'PUT'\n | 'PATCH'\n | 'DELETE',\n Url extends string = string,\n RequestSchema = Method extends 'DELETE' ? never : ZodObject,\n QuerySchema = unknown,\n Response extends ZodType = ZodType,\n ReqResult = z.output<Response>,\n Result = unknown,\n Context = unknown,\n UseKey extends boolean = false,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse: ProcessResponseFunction<Result, ReqResult>\n useContext?: () => Context\n onSuccess?: (\n queryClient: QueryClient,\n data: NoInfer<Result>,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n useKey?: UseKey\n}\n\n/**\n * Creates a client instance for making type-safe queries and mutations.\n *\n * @param options - Client configuration including the API builder and defaults\n * @returns A client instance with query, infiniteQuery, and mutation methods\n *\n * @example\n * ```typescript\n * const api = createBuilder({ baseUrl: '/api' });\n * const client = declareClient({ api });\n *\n * const getUser = client.query({\n * method: 'GET',\n * url: '/users/$id',\n * responseSchema: UserSchema,\n * });\n *\n * // In a component\n * const { data } = useSuspenseQuery(getUser({ urlParams: { id: '123' } }));\n * ```\n */\nexport function declareClient<Options extends ClientOptions>({\n api,\n defaults = {},\n}: Options): ClientInstance {\n function query(config: QueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const queryOptions = makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n })\n // @ts-expect-error We attach the endpoint to the queryOptions\n queryOptions.endpoint = endpoint\n return queryOptions\n }\n\n function queryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options?: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n },\n ) {\n return makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n })\n }\n\n function infiniteQuery(config: InfiniteQueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n const infiniteQueryOptions = makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n getNextPageParam: config.getNextPageParam,\n getPreviousPageParam: config.getPreviousPageParam,\n initialPageParam: config.initialPageParam,\n })\n\n // @ts-expect-error We attach the endpoint to the infiniteQueryOptions\n infiniteQueryOptions.endpoint = endpoint\n return infiniteQueryOptions\n }\n\n function infiniteQueryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n getNextPageParam: (\n lastPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']> | undefined\n getPreviousPageParam?: (\n firstPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']>\n initialPageParam?: z.input<AnyEndpointConfig['querySchema']>\n },\n ) {\n return makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options?.getPreviousPageParam,\n initialPageParam: options?.initialPageParam,\n })\n }\n\n function mutation(config: MutationConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n function mutationFromEndpoint(\n endpoint:\n | AbstractEndpoint<AnyEndpointConfig>\n | AbstractStream<AnyStreamConfig>,\n options?: {\n processResponse?: ProcessResponseFunction\n useContext?: () => unknown\n onSuccess?: (\n queryClient: QueryClient,\n data: unknown,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n },\n ) {\n // @ts-expect-error endpoint types are compatible at runtime\n return makeMutation(endpoint, {\n processResponse: options?.processResponse,\n useContext: options?.useContext,\n onSuccess: options?.onSuccess,\n onError: options?.onError,\n ...defaults,\n })\n }\n\n function multipartMutation(config: MutationConfig) {\n const endpoint = api.declareMultipart({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n return {\n // @ts-expect-error We simplified types here\n query,\n // @ts-expect-error We simplified types here\n queryFromEndpoint,\n // @ts-expect-error We simplified types here\n infiniteQuery,\n // @ts-expect-error We simplified types here\n infiniteQueryFromEndpoint,\n // @ts-expect-error We simplified types here\n mutation,\n // @ts-expect-error We simplified types here\n mutationFromEndpoint,\n // @ts-expect-error We simplified types here\n multipartMutation,\n }\n}\n"]}
|
package/lib/index.mjs
CHANGED
|
@@ -152,7 +152,8 @@ function createMutationKey(config, options = {
|
|
|
152
152
|
var mutationKeyCreator = createMutationKey;
|
|
153
153
|
function makeMutation(endpoint, options) {
|
|
154
154
|
const config = endpoint.config;
|
|
155
|
-
const mutationKey = createMutationKey(config,
|
|
155
|
+
const mutationKey = createMutationKey(config, {
|
|
156
|
+
...options});
|
|
156
157
|
const result = (keyParams) => {
|
|
157
158
|
const queryClient = useQueryClient();
|
|
158
159
|
const {
|
|
@@ -181,7 +182,7 @@ function makeMutation(endpoint, options) {
|
|
|
181
182
|
} : void 0,
|
|
182
183
|
async mutationFn(params) {
|
|
183
184
|
const response = await endpoint(params);
|
|
184
|
-
return processResponse(response);
|
|
185
|
+
return processResponse ? processResponse(response) : response;
|
|
185
186
|
},
|
|
186
187
|
onSuccess: onSuccess ? (data, variables) => {
|
|
187
188
|
return onSuccess?.(queryClient, data, variables, context);
|
|
@@ -289,11 +290,10 @@ function declareClient({
|
|
|
289
290
|
}
|
|
290
291
|
function mutationFromEndpoint(endpoint, options) {
|
|
291
292
|
return makeMutation(endpoint, {
|
|
292
|
-
processResponse: options
|
|
293
|
-
useContext: options
|
|
294
|
-
onSuccess: options
|
|
295
|
-
|
|
296
|
-
onError: options.onError,
|
|
293
|
+
processResponse: options?.processResponse,
|
|
294
|
+
useContext: options?.useContext,
|
|
295
|
+
onSuccess: options?.onSuccess,
|
|
296
|
+
onError: options?.onError,
|
|
297
297
|
...defaults
|
|
298
298
|
});
|
|
299
299
|
}
|