@navios/react-query 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/README.md +405 -273
- package/dist/src/client/declare-client.d.mts +13 -4
- 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 +3 -3
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/src/mutation/types.d.mts +13 -5
- package/dist/src/mutation/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/_tsup-dts-rollup.d.mts +117 -10
- package/lib/_tsup-dts-rollup.d.ts +117 -10
- package/lib/index.d.mts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +57 -33
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +58 -34
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/declare-client.spec.mts +24 -5
- package/src/__tests__/make-mutation.spec.mts +214 -5
- package/src/client/__type-tests__/client-instance.spec-d.mts +151 -1
- package/src/client/declare-client.mts +45 -16
- package/src/client/types.mts +323 -0
- package/src/mutation/make-hook.mts +100 -43
- package/src/mutation/types.mts +29 -7
|
@@ -1,11 +1,13 @@
|
|
|
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';
|
|
7
8
|
import type { HttpMethod } from '@navios/builder';
|
|
8
9
|
import type { InfiniteData } from '@tanstack/react-query';
|
|
10
|
+
import type { MutationFunctionContext } from '@tanstack/react-query';
|
|
9
11
|
import type { NaviosZodRequest } from '@navios/builder';
|
|
10
12
|
import { NoInfer as NoInfer_2 } from '@tanstack/react-query';
|
|
11
13
|
import { ProcessResponseFunction as ProcessResponseFunction_2 } from '../index.mjs';
|
|
@@ -345,6 +347,82 @@ declare interface ClientInstance {
|
|
|
345
347
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
346
348
|
urlParams: UrlParams<Url>;
|
|
347
349
|
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
350
|
+
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: {
|
|
351
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
352
|
+
}, mutationOptions: {
|
|
353
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
354
|
+
useKey: UseKey;
|
|
355
|
+
useContext?: () => Context;
|
|
356
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
357
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
358
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
359
|
+
urlParams: UrlParams<Url>;
|
|
360
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
361
|
+
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: {
|
|
362
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
363
|
+
}, mutationOptions?: {
|
|
364
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
365
|
+
useContext?: () => Context;
|
|
366
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
367
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
368
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
369
|
+
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: {
|
|
370
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
371
|
+
}, mutationOptions: {
|
|
372
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
373
|
+
useKey: UseKey;
|
|
374
|
+
useContext?: () => Context;
|
|
375
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
376
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
377
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
378
|
+
urlParams: UrlParams<Url>;
|
|
379
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
380
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown>(endpoint: {
|
|
381
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
382
|
+
}, mutationOptions?: {
|
|
383
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
384
|
+
useContext?: () => Context;
|
|
385
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
386
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
387
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
388
|
+
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: {
|
|
389
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
390
|
+
}, mutationOptions: {
|
|
391
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
392
|
+
useKey: UseKey;
|
|
393
|
+
useContext?: () => Context;
|
|
394
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
395
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
396
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
397
|
+
urlParams: UrlParams<Url>;
|
|
398
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
399
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
400
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
401
|
+
}, mutationOptions?: {
|
|
402
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
403
|
+
useContext?: () => Context;
|
|
404
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
405
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
406
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
407
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
408
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
409
|
+
}, mutationOptions: {
|
|
410
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
411
|
+
useKey: UseKey;
|
|
412
|
+
useContext?: () => Context;
|
|
413
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
414
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
415
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
416
|
+
urlParams: UrlParams<Url>;
|
|
417
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, undefined>;
|
|
418
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown>(endpoint: {
|
|
419
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
420
|
+
}, mutationOptions?: {
|
|
421
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
422
|
+
useContext?: () => Context;
|
|
423
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
424
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
425
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & StreamHelper<Method, Url, undefined, undefined>;
|
|
348
426
|
}
|
|
349
427
|
export { ClientInstance }
|
|
350
428
|
export { ClientInstance as ClientInstance_alias_1 }
|
|
@@ -538,12 +616,12 @@ export { makeInfiniteQueryOptions as makeInfiniteQueryOptions_alias_2 }
|
|
|
538
616
|
* @param options - Mutation configuration including processResponse and callbacks
|
|
539
617
|
* @returns A hook function that returns mutation result with attached helpers
|
|
540
618
|
*/
|
|
541
|
-
declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown, TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false>(endpoint: AbstractEndpoint<Config>, options: MutationParams<Config, TData, TVariables, TResponse, TContext, UseKey>): {
|
|
542
|
-
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, NaviosZodRequest<Config
|
|
619
|
+
declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown, TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false>(endpoint: AbstractEndpoint<Config>, options: MutationParams<Config, TData, TVariables, TResponse, TOnMutateResult, TContext, UseKey>): {
|
|
620
|
+
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, NaviosZodRequest<Config>, TOnMutateResult>;
|
|
543
621
|
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
544
622
|
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
545
623
|
urlParams: UrlParams<Config["url"]>;
|
|
546
|
-
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
624
|
+
} : {} : 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
625
|
[dataTagSymbol]: Result;
|
|
548
626
|
[dataTagErrorSymbol]: Error;
|
|
549
627
|
} : never;
|
|
@@ -592,7 +670,7 @@ export { MutationArgs as MutationArgs_alias_2 }
|
|
|
592
670
|
/**
|
|
593
671
|
* Configuration for declaring a mutation endpoint.
|
|
594
672
|
*/
|
|
595
|
-
declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : ZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends boolean = false> {
|
|
673
|
+
declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : ZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, TOnMutateResult = unknown, Context = unknown, UseKey extends boolean = false> {
|
|
596
674
|
method: Method;
|
|
597
675
|
url: Url;
|
|
598
676
|
querySchema?: QuerySchema;
|
|
@@ -600,9 +678,18 @@ declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELE
|
|
|
600
678
|
requestSchema?: RequestSchema;
|
|
601
679
|
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
602
680
|
useContext?: () => Context;
|
|
603
|
-
onSuccess?: (
|
|
604
|
-
|
|
681
|
+
onSuccess?: (data: Result, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
682
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
683
|
+
}) => void | Promise<void>;
|
|
684
|
+
onError?: (err: unknown, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
685
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
686
|
+
}) => void | Promise<void>;
|
|
687
|
+
onMutate?: (variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
688
|
+
onSettled?: (data: Result | undefined, error: Error | null, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
689
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
690
|
+
}) => void | Promise<void>;
|
|
605
691
|
useKey?: UseKey;
|
|
692
|
+
meta?: Record<string, unknown>;
|
|
606
693
|
}
|
|
607
694
|
export { MutationConfig }
|
|
608
695
|
export { MutationConfig as MutationConfig_alias_1 }
|
|
@@ -631,15 +718,23 @@ export { mutationKeyCreator as mutationKeyCreator_alias_2 }
|
|
|
631
718
|
/**
|
|
632
719
|
* Base parameters for mutation configuration.
|
|
633
720
|
*/
|
|
634
|
-
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
|
|
721
|
+
declare interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false> extends Omit<UseMutationOptions<TData, Error, TVariables>, 'mutationKey' | 'mutationFn' | 'onMutate' | 'onSuccess' | 'onError' | 'onSettled' | 'scope'> {
|
|
722
|
+
processResponse?: ProcessResponseFunction<TData, TResponse>;
|
|
636
723
|
/**
|
|
637
724
|
* React hooks that will prepare the context for the mutation onSuccess and onError
|
|
638
725
|
* callbacks. This is useful for when you want to use the context in the callbacks
|
|
639
726
|
*/
|
|
640
727
|
useContext?: () => TContext;
|
|
641
|
-
onSuccess?: (
|
|
642
|
-
|
|
728
|
+
onSuccess?: (data: TData, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
729
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
730
|
+
}) => void | Promise<void>;
|
|
731
|
+
onError?: (err: unknown, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
732
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
733
|
+
}) => void | Promise<void>;
|
|
734
|
+
onMutate?: (variables: TVariables, context: TContext & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
735
|
+
onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
736
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
737
|
+
}) => void | Promise<void>;
|
|
643
738
|
/**
|
|
644
739
|
* If true, we will create a mutation key that can be shared across the project.
|
|
645
740
|
*/
|
|
@@ -763,4 +858,16 @@ export { Split }
|
|
|
763
858
|
export { Split as Split_alias_1 }
|
|
764
859
|
export { Split as Split_alias_2 }
|
|
765
860
|
|
|
861
|
+
/**
|
|
862
|
+
* Helper type that attaches a stream endpoint to mutation results.
|
|
863
|
+
*/
|
|
864
|
+
declare type StreamHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, QuerySchema = unknown> = {
|
|
865
|
+
endpoint: ((params: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, RequestSchema>>) => Promise<Blob>) & {
|
|
866
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
export { StreamHelper }
|
|
870
|
+
export { StreamHelper as StreamHelper_alias_1 }
|
|
871
|
+
export { StreamHelper as StreamHelper_alias_2 }
|
|
872
|
+
|
|
766
873
|
export { }
|
|
@@ -1,11 +1,13 @@
|
|
|
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';
|
|
7
8
|
import type { HttpMethod } from '@navios/builder';
|
|
8
9
|
import type { InfiniteData } from '@tanstack/react-query';
|
|
10
|
+
import type { MutationFunctionContext } from '@tanstack/react-query';
|
|
9
11
|
import type { NaviosZodRequest } from '@navios/builder';
|
|
10
12
|
import { NoInfer as NoInfer_2 } from '@tanstack/react-query';
|
|
11
13
|
import { ProcessResponseFunction as ProcessResponseFunction_2 } from '../index.mjs';
|
|
@@ -345,6 +347,82 @@ declare interface ClientInstance {
|
|
|
345
347
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
346
348
|
urlParams: UrlParams<Url>;
|
|
347
349
|
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
350
|
+
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: {
|
|
351
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
352
|
+
}, mutationOptions: {
|
|
353
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
354
|
+
useKey: UseKey;
|
|
355
|
+
useContext?: () => Context;
|
|
356
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
357
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
358
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
359
|
+
urlParams: UrlParams<Url>;
|
|
360
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
361
|
+
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: {
|
|
362
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
363
|
+
}, mutationOptions?: {
|
|
364
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
365
|
+
useContext?: () => Context;
|
|
366
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
367
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
368
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, QuerySchema>>) & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
369
|
+
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: {
|
|
370
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
371
|
+
}, mutationOptions: {
|
|
372
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
373
|
+
useKey: UseKey;
|
|
374
|
+
useContext?: () => Context;
|
|
375
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
376
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
377
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
378
|
+
urlParams: UrlParams<Url>;
|
|
379
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
380
|
+
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result = Blob, Context = unknown>(endpoint: {
|
|
381
|
+
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
382
|
+
}, mutationOptions?: {
|
|
383
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
384
|
+
useContext?: () => Context;
|
|
385
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
386
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
387
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, RequestSchema, undefined>>) & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
388
|
+
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: {
|
|
389
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
390
|
+
}, mutationOptions: {
|
|
391
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
392
|
+
useKey: UseKey;
|
|
393
|
+
useContext?: () => Context;
|
|
394
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
395
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
396
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
397
|
+
urlParams: UrlParams<Url>;
|
|
398
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
399
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result = Blob, Context = unknown>(endpoint: {
|
|
400
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
401
|
+
}, mutationOptions?: {
|
|
402
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
403
|
+
useContext?: () => Context;
|
|
404
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
405
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
406
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, QuerySchema>>) & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
407
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
408
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
409
|
+
}, mutationOptions: {
|
|
410
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
411
|
+
useKey: UseKey;
|
|
412
|
+
useContext?: () => Context;
|
|
413
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
414
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
415
|
+
}): ((params: UrlHasParams<Url> extends true ? {
|
|
416
|
+
urlParams: UrlParams<Url>;
|
|
417
|
+
} : {}) => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & MutationHelpers<Url, Result> & StreamHelper<Method, Url, undefined, undefined>;
|
|
418
|
+
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result = Blob, Context = unknown>(endpoint: {
|
|
419
|
+
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
420
|
+
}, mutationOptions?: {
|
|
421
|
+
processResponse?: ProcessResponseFunction<Result, Blob>;
|
|
422
|
+
useContext?: () => Context;
|
|
423
|
+
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
424
|
+
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
425
|
+
}): (() => UseMutationResult<Result, Error, MutationArgs<Url, undefined, undefined>>) & StreamHelper<Method, Url, undefined, undefined>;
|
|
348
426
|
}
|
|
349
427
|
export { ClientInstance }
|
|
350
428
|
export { ClientInstance as ClientInstance_alias_1 }
|
|
@@ -538,12 +616,12 @@ export { makeInfiniteQueryOptions as makeInfiniteQueryOptions_alias_2 }
|
|
|
538
616
|
* @param options - Mutation configuration including processResponse and callbacks
|
|
539
617
|
* @returns A hook function that returns mutation result with attached helpers
|
|
540
618
|
*/
|
|
541
|
-
declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown, TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false>(endpoint: AbstractEndpoint<Config>, options: MutationParams<Config, TData, TVariables, TResponse, TContext, UseKey>): {
|
|
542
|
-
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, NaviosZodRequest<Config
|
|
619
|
+
declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown, TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false>(endpoint: AbstractEndpoint<Config>, options: MutationParams<Config, TData, TVariables, TResponse, TOnMutateResult, TContext, UseKey>): {
|
|
620
|
+
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, NaviosZodRequest<Config>, TOnMutateResult>;
|
|
543
621
|
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
544
622
|
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
545
623
|
urlParams: UrlParams<Config["url"]>;
|
|
546
|
-
} : {} : never : never) => ProcessResponseFunction_2<TData, TResponse> extends (...args: unknown[]) => infer Result ? [Config["url"]] & {
|
|
624
|
+
} : {} : 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
625
|
[dataTagSymbol]: Result;
|
|
548
626
|
[dataTagErrorSymbol]: Error;
|
|
549
627
|
} : never;
|
|
@@ -592,7 +670,7 @@ export { MutationArgs as MutationArgs_alias_2 }
|
|
|
592
670
|
/**
|
|
593
671
|
* Configuration for declaring a mutation endpoint.
|
|
594
672
|
*/
|
|
595
|
-
declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : ZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends boolean = false> {
|
|
673
|
+
declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : ZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, TOnMutateResult = unknown, Context = unknown, UseKey extends boolean = false> {
|
|
596
674
|
method: Method;
|
|
597
675
|
url: Url;
|
|
598
676
|
querySchema?: QuerySchema;
|
|
@@ -600,9 +678,18 @@ declare interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELE
|
|
|
600
678
|
requestSchema?: RequestSchema;
|
|
601
679
|
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
602
680
|
useContext?: () => Context;
|
|
603
|
-
onSuccess?: (
|
|
604
|
-
|
|
681
|
+
onSuccess?: (data: Result, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
682
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
683
|
+
}) => void | Promise<void>;
|
|
684
|
+
onError?: (err: unknown, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
685
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
686
|
+
}) => void | Promise<void>;
|
|
687
|
+
onMutate?: (variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
688
|
+
onSettled?: (data: Result | undefined, error: Error | null, variables: MutationArgs<Url, RequestSchema, QuerySchema>, context: Context & MutationFunctionContext & {
|
|
689
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
690
|
+
}) => void | Promise<void>;
|
|
605
691
|
useKey?: UseKey;
|
|
692
|
+
meta?: Record<string, unknown>;
|
|
606
693
|
}
|
|
607
694
|
export { MutationConfig }
|
|
608
695
|
export { MutationConfig as MutationConfig_alias_1 }
|
|
@@ -631,15 +718,23 @@ export { mutationKeyCreator as mutationKeyCreator_alias_2 }
|
|
|
631
718
|
/**
|
|
632
719
|
* Base parameters for mutation configuration.
|
|
633
720
|
*/
|
|
634
|
-
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
|
|
721
|
+
declare interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables = NaviosZodRequest<Config>, TResponse = z.output<Config['responseSchema']>, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false> extends Omit<UseMutationOptions<TData, Error, TVariables>, 'mutationKey' | 'mutationFn' | 'onMutate' | 'onSuccess' | 'onError' | 'onSettled' | 'scope'> {
|
|
722
|
+
processResponse?: ProcessResponseFunction<TData, TResponse>;
|
|
636
723
|
/**
|
|
637
724
|
* React hooks that will prepare the context for the mutation onSuccess and onError
|
|
638
725
|
* callbacks. This is useful for when you want to use the context in the callbacks
|
|
639
726
|
*/
|
|
640
727
|
useContext?: () => TContext;
|
|
641
|
-
onSuccess?: (
|
|
642
|
-
|
|
728
|
+
onSuccess?: (data: TData, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
729
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
730
|
+
}) => void | Promise<void>;
|
|
731
|
+
onError?: (err: unknown, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
732
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
733
|
+
}) => void | Promise<void>;
|
|
734
|
+
onMutate?: (variables: TVariables, context: TContext & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
735
|
+
onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
736
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
737
|
+
}) => void | Promise<void>;
|
|
643
738
|
/**
|
|
644
739
|
* If true, we will create a mutation key that can be shared across the project.
|
|
645
740
|
*/
|
|
@@ -763,4 +858,16 @@ export { Split }
|
|
|
763
858
|
export { Split as Split_alias_1 }
|
|
764
859
|
export { Split as Split_alias_2 }
|
|
765
860
|
|
|
861
|
+
/**
|
|
862
|
+
* Helper type that attaches a stream endpoint to mutation results.
|
|
863
|
+
*/
|
|
864
|
+
declare type StreamHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, QuerySchema = unknown> = {
|
|
865
|
+
endpoint: ((params: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, RequestSchema>>) => Promise<Blob>) & {
|
|
866
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
export { StreamHelper }
|
|
870
|
+
export { StreamHelper as StreamHelper_alias_1 }
|
|
871
|
+
export { StreamHelper as StreamHelper_alias_2 }
|
|
872
|
+
|
|
766
873
|
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,46 +154,66 @@ 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
|
-
const queryClient = reactQuery.useQueryClient();
|
|
160
160
|
const {
|
|
161
161
|
useKey,
|
|
162
162
|
useContext,
|
|
163
|
+
onMutate,
|
|
163
164
|
onError,
|
|
164
165
|
onSuccess,
|
|
166
|
+
onSettled,
|
|
165
167
|
keyPrefix: _keyPrefix,
|
|
166
168
|
keySuffix: _keySuffix,
|
|
167
169
|
processResponse,
|
|
168
170
|
...rest
|
|
169
171
|
} = options;
|
|
170
|
-
const
|
|
171
|
-
return reactQuery.useMutation(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return processResponse(response);
|
|
187
|
-
},
|
|
188
|
-
onSuccess: onSuccess ? (data, variables) => {
|
|
189
|
-
return onSuccess?.(queryClient, data, variables, context);
|
|
190
|
-
} : void 0,
|
|
191
|
-
onError: onError ? (err, variables) => {
|
|
192
|
-
return onError?.(queryClient, err, variables, context);
|
|
193
|
-
} : void 0
|
|
172
|
+
const ownContext = useContext?.() ?? {};
|
|
173
|
+
return reactQuery.useMutation({
|
|
174
|
+
...rest,
|
|
175
|
+
mutationKey: useKey ? mutationKey({
|
|
176
|
+
urlParams: keyParams
|
|
177
|
+
}) : void 0,
|
|
178
|
+
scope: useKey ? {
|
|
179
|
+
id: JSON.stringify(
|
|
180
|
+
mutationKey({
|
|
181
|
+
urlParams: keyParams
|
|
182
|
+
})
|
|
183
|
+
)
|
|
184
|
+
} : void 0,
|
|
185
|
+
async mutationFn(params) {
|
|
186
|
+
const response = await endpoint(params);
|
|
187
|
+
return processResponse ? processResponse(response) : response;
|
|
194
188
|
},
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
onSuccess: onSuccess ? (data, variables, onMutateResult, context) => {
|
|
190
|
+
return onSuccess?.(data, variables, {
|
|
191
|
+
...ownContext,
|
|
192
|
+
...context,
|
|
193
|
+
onMutateResult
|
|
194
|
+
});
|
|
195
|
+
} : void 0,
|
|
196
|
+
onError: onError ? (err, variables, onMutateResult, context) => {
|
|
197
|
+
return onError?.(err, variables, {
|
|
198
|
+
onMutateResult,
|
|
199
|
+
...ownContext,
|
|
200
|
+
...context
|
|
201
|
+
});
|
|
202
|
+
} : void 0,
|
|
203
|
+
onMutate: onMutate ? (variables, context) => {
|
|
204
|
+
return onMutate(variables, {
|
|
205
|
+
...ownContext,
|
|
206
|
+
...context
|
|
207
|
+
});
|
|
208
|
+
} : void 0,
|
|
209
|
+
onSettled: onSettled ? (data, error, variables, onMutateResult, context) => {
|
|
210
|
+
return onSettled(data, error, variables, {
|
|
211
|
+
...ownContext,
|
|
212
|
+
...context,
|
|
213
|
+
onMutateResult
|
|
214
|
+
});
|
|
215
|
+
} : void 0
|
|
216
|
+
});
|
|
197
217
|
};
|
|
198
218
|
result.useIsMutating = (keyParams) => {
|
|
199
219
|
if (!options.useKey) {
|
|
@@ -284,6 +304,7 @@ function declareClient({
|
|
|
284
304
|
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
285
305
|
onError: config.onError,
|
|
286
306
|
useKey: config.useKey,
|
|
307
|
+
meta: config.meta,
|
|
287
308
|
...defaults
|
|
288
309
|
});
|
|
289
310
|
useMutation2.endpoint = endpoint;
|
|
@@ -291,11 +312,10 @@ function declareClient({
|
|
|
291
312
|
}
|
|
292
313
|
function mutationFromEndpoint(endpoint, options) {
|
|
293
314
|
return makeMutation(endpoint, {
|
|
294
|
-
processResponse: options
|
|
295
|
-
useContext: options
|
|
296
|
-
onSuccess: options
|
|
297
|
-
|
|
298
|
-
onError: options.onError,
|
|
315
|
+
processResponse: options?.processResponse,
|
|
316
|
+
useContext: options?.useContext,
|
|
317
|
+
onSuccess: options?.onSuccess,
|
|
318
|
+
onError: options?.onError,
|
|
299
319
|
...defaults
|
|
300
320
|
});
|
|
301
321
|
}
|
|
@@ -315,6 +335,10 @@ function declareClient({
|
|
|
315
335
|
onSuccess: config.onSuccess,
|
|
316
336
|
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
317
337
|
onError: config.onError,
|
|
338
|
+
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
339
|
+
onMutate: config.onMutate,
|
|
340
|
+
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
341
|
+
onSettled: config.onSettled,
|
|
318
342
|
useKey: config.useKey,
|
|
319
343
|
...defaults
|
|
320
344
|
});
|