@kubb/plugin-react-query 4.5.15 → 4.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/dist/{components-0G5mZf1J.cjs → components-C0HQi0Tg.cjs} +319 -25
- package/dist/components-C0HQi0Tg.cjs.map +1 -0
- package/dist/{components-BWrDXrTl.js → components-K4qy3AIg.js} +307 -25
- package/dist/components-K4qy3AIg.js.map +1 -0
- package/dist/components.cjs +3 -1
- package/dist/components.d.cts +121 -30
- package/dist/components.d.ts +121 -30
- package/dist/components.js +2 -2
- package/dist/{generators-DTCyUuOe.cjs → generators-CKLkXi1h.cjs} +225 -2
- package/dist/generators-CKLkXi1h.cjs.map +1 -0
- package/dist/{generators-BAjiYTwQ.js → generators-Df7UUFaq.js} +220 -3
- package/dist/generators-Df7UUFaq.js.map +1 -0
- package/dist/generators.cjs +3 -2
- package/dist/generators.d.cts +4 -1
- package/dist/generators.d.ts +4 -1
- package/dist/generators.js +3 -3
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/SuspenseInfiniteQuery.tsx +212 -0
- package/src/components/SuspenseInfiniteQueryOptions.tsx +230 -0
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/findSuspenseInfiniteByTags.ts +100 -0
- package/src/generators/__snapshots__/findSuspenseInfiniteByTagsCursor.ts +100 -0
- package/src/generators/index.ts +1 -0
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +191 -0
- package/src/plugin.ts +2 -2
- package/dist/components-0G5mZf1J.cjs.map +0 -1
- package/dist/components-BWrDXrTl.js.map +0 -1
- package/dist/generators-BAjiYTwQ.js.map +0 -1
- package/dist/generators-DTCyUuOe.cjs.map +0 -1
|
@@ -6,7 +6,7 @@ import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
|
6
6
|
import { Client } from "@kubb/plugin-client/components";
|
|
7
7
|
|
|
8
8
|
//#region src/components/QueryKey.tsx
|
|
9
|
-
function getParams$
|
|
9
|
+
function getParams$10({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
10
10
|
return FunctionParams.factory({
|
|
11
11
|
pathParams: {
|
|
12
12
|
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
@@ -36,7 +36,7 @@ const getTransformer$1 = ({ operation, schemas, casing }) => {
|
|
|
36
36
|
].filter(Boolean);
|
|
37
37
|
};
|
|
38
38
|
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
|
|
39
|
-
const params = getParams$
|
|
39
|
+
const params = getParams$10({
|
|
40
40
|
pathParamsType,
|
|
41
41
|
typeSchemas,
|
|
42
42
|
paramsCasing
|
|
@@ -69,12 +69,12 @@ function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation,
|
|
|
69
69
|
})
|
|
70
70
|
})] });
|
|
71
71
|
}
|
|
72
|
-
QueryKey.getParams = getParams$
|
|
72
|
+
QueryKey.getParams = getParams$10;
|
|
73
73
|
QueryKey.getTransformer = getTransformer$1;
|
|
74
74
|
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region src/components/QueryOptions.tsx
|
|
77
|
-
function getParams$
|
|
77
|
+
function getParams$9({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
78
78
|
if (paramsType === "object") return FunctionParams.factory({
|
|
79
79
|
data: {
|
|
80
80
|
mode: "object",
|
|
@@ -130,7 +130,7 @@ function getParams$7({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
133
|
-
const params = getParams$
|
|
133
|
+
const params = getParams$9({
|
|
134
134
|
paramsType,
|
|
135
135
|
paramsCasing,
|
|
136
136
|
pathParamsType,
|
|
@@ -174,11 +174,11 @@ function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCas
|
|
|
174
174
|
})
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
|
-
QueryOptions.getParams = getParams$
|
|
177
|
+
QueryOptions.getParams = getParams$9;
|
|
178
178
|
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/components/InfiniteQuery.tsx
|
|
181
|
-
function getParams$
|
|
181
|
+
function getParams$8({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
|
|
182
182
|
if (paramsType === "object") return FunctionParams.factory({
|
|
183
183
|
data: {
|
|
184
184
|
mode: "object",
|
|
@@ -272,7 +272,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
272
272
|
typeSchemas,
|
|
273
273
|
paramsCasing
|
|
274
274
|
});
|
|
275
|
-
const params = getParams$
|
|
275
|
+
const params = getParams$8({
|
|
276
276
|
paramsCasing,
|
|
277
277
|
paramsType,
|
|
278
278
|
pathParamsType,
|
|
@@ -308,11 +308,11 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
308
308
|
})
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
|
-
InfiniteQuery.getParams = getParams$
|
|
311
|
+
InfiniteQuery.getParams = getParams$8;
|
|
312
312
|
|
|
313
313
|
//#endregion
|
|
314
314
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
315
|
-
function getParams$
|
|
315
|
+
function getParams$7({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
316
316
|
if (paramsType === "object") return FunctionParams.factory({
|
|
317
317
|
data: {
|
|
318
318
|
mode: "object",
|
|
@@ -377,7 +377,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
377
377
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
378
378
|
const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
|
|
379
379
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
380
|
-
const params = getParams$
|
|
380
|
+
const params = getParams$7({
|
|
381
381
|
paramsType,
|
|
382
382
|
paramsCasing,
|
|
383
383
|
pathParamsType,
|
|
@@ -456,18 +456,18 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
456
456
|
})
|
|
457
457
|
});
|
|
458
458
|
}
|
|
459
|
-
InfiniteQueryOptions.getParams = getParams$
|
|
459
|
+
InfiniteQueryOptions.getParams = getParams$7;
|
|
460
460
|
|
|
461
461
|
//#endregion
|
|
462
462
|
//#region src/components/MutationKey.tsx
|
|
463
|
-
function getParams$
|
|
463
|
+
function getParams$6({}) {
|
|
464
464
|
return FunctionParams.factory({});
|
|
465
465
|
}
|
|
466
466
|
const getTransformer = ({ operation, casing }) => {
|
|
467
467
|
return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
468
468
|
};
|
|
469
469
|
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
|
|
470
|
-
const params = getParams$
|
|
470
|
+
const params = getParams$6({
|
|
471
471
|
pathParamsType,
|
|
472
472
|
typeSchemas
|
|
473
473
|
});
|
|
@@ -499,19 +499,19 @@ function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operatio
|
|
|
499
499
|
})
|
|
500
500
|
})] });
|
|
501
501
|
}
|
|
502
|
-
MutationKey.getParams = getParams$
|
|
502
|
+
MutationKey.getParams = getParams$6;
|
|
503
503
|
MutationKey.getTransformer = getTransformer;
|
|
504
504
|
|
|
505
505
|
//#endregion
|
|
506
506
|
//#region src/components/MutationOptions.tsx
|
|
507
|
-
function getParams$
|
|
507
|
+
function getParams$5({ typeSchemas }) {
|
|
508
508
|
return FunctionParams.factory({ config: {
|
|
509
509
|
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
510
510
|
default: "{}"
|
|
511
511
|
} });
|
|
512
512
|
}
|
|
513
513
|
function MutationOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
514
|
-
const params = getParams$
|
|
514
|
+
const params = getParams$5({ typeSchemas });
|
|
515
515
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
516
516
|
const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
|
|
517
517
|
const clientParams = Client.getParams({
|
|
@@ -574,11 +574,11 @@ function MutationOptions({ name, clientName, dataReturnType, typeSchemas, params
|
|
|
574
574
|
})
|
|
575
575
|
});
|
|
576
576
|
}
|
|
577
|
-
MutationOptions.getParams = getParams$
|
|
577
|
+
MutationOptions.getParams = getParams$5;
|
|
578
578
|
|
|
579
579
|
//#endregion
|
|
580
580
|
//#region src/components/Mutation.tsx
|
|
581
|
-
function getParams$
|
|
581
|
+
function getParams$4({ paramsCasing, dataReturnType, typeSchemas }) {
|
|
582
582
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
583
583
|
const TRequest = FunctionParams.factory({
|
|
584
584
|
...getPathParams(typeSchemas.pathParams, {
|
|
@@ -619,7 +619,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, pathParamsType, dat
|
|
|
619
619
|
pathParamsType,
|
|
620
620
|
typeSchemas
|
|
621
621
|
});
|
|
622
|
-
const params = getParams$
|
|
622
|
+
const params = getParams$4({
|
|
623
623
|
paramsCasing,
|
|
624
624
|
pathParamsType,
|
|
625
625
|
dataReturnType,
|
|
@@ -682,7 +682,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, pathParamsType, dat
|
|
|
682
682
|
|
|
683
683
|
//#endregion
|
|
684
684
|
//#region src/components/Query.tsx
|
|
685
|
-
function getParams$
|
|
685
|
+
function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
|
|
686
686
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
687
687
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
688
688
|
if (paramsType === "object") return FunctionParams.factory({
|
|
@@ -780,7 +780,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
780
780
|
typeSchemas,
|
|
781
781
|
paramsCasing
|
|
782
782
|
});
|
|
783
|
-
const params = getParams$
|
|
783
|
+
const params = getParams$3({
|
|
784
784
|
paramsCasing,
|
|
785
785
|
paramsType,
|
|
786
786
|
pathParamsType,
|
|
@@ -816,7 +816,289 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
816
816
|
})
|
|
817
817
|
});
|
|
818
818
|
}
|
|
819
|
-
Query.getParams = getParams$
|
|
819
|
+
Query.getParams = getParams$3;
|
|
820
|
+
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/components/SuspenseInfiniteQuery.tsx
|
|
823
|
+
function getParams$2({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
|
|
824
|
+
if (paramsType === "object") return FunctionParams.factory({
|
|
825
|
+
data: {
|
|
826
|
+
mode: "object",
|
|
827
|
+
children: {
|
|
828
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
829
|
+
typed: true,
|
|
830
|
+
casing: paramsCasing
|
|
831
|
+
}),
|
|
832
|
+
data: typeSchemas.request?.name ? {
|
|
833
|
+
type: typeSchemas.request?.name,
|
|
834
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
835
|
+
} : void 0,
|
|
836
|
+
params: typeSchemas.queryParams?.name ? {
|
|
837
|
+
type: typeSchemas.queryParams?.name,
|
|
838
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
839
|
+
} : void 0,
|
|
840
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
841
|
+
type: typeSchemas.headerParams?.name,
|
|
842
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
843
|
+
} : void 0
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
options: {
|
|
847
|
+
type: `
|
|
848
|
+
{
|
|
849
|
+
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
850
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
851
|
+
}
|
|
852
|
+
`,
|
|
853
|
+
default: "{}"
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
return FunctionParams.factory({
|
|
857
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
858
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
859
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
860
|
+
typed: true,
|
|
861
|
+
casing: paramsCasing
|
|
862
|
+
}),
|
|
863
|
+
optional: isOptional(typeSchemas.pathParams?.schema)
|
|
864
|
+
} : void 0,
|
|
865
|
+
data: typeSchemas.request?.name ? {
|
|
866
|
+
type: typeSchemas.request?.name,
|
|
867
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
868
|
+
} : void 0,
|
|
869
|
+
params: typeSchemas.queryParams?.name ? {
|
|
870
|
+
type: typeSchemas.queryParams?.name,
|
|
871
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
872
|
+
} : void 0,
|
|
873
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
874
|
+
type: typeSchemas.headerParams?.name,
|
|
875
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
876
|
+
} : void 0,
|
|
877
|
+
options: {
|
|
878
|
+
type: `
|
|
879
|
+
{
|
|
880
|
+
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
881
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
882
|
+
}
|
|
883
|
+
`,
|
|
884
|
+
default: "{}"
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, initialPageParam, queryParam }) {
|
|
889
|
+
const responseType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
890
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
891
|
+
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
892
|
+
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
893
|
+
const parts = initialPageParam.split(" as ");
|
|
894
|
+
return parts[parts.length - 1] ?? "unknown";
|
|
895
|
+
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
896
|
+
const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
|
|
897
|
+
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
898
|
+
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
899
|
+
const generics = [
|
|
900
|
+
`TQueryFnData = ${responseType}`,
|
|
901
|
+
`TError = ${errorType}`,
|
|
902
|
+
"TData = InfiniteData<TQueryFnData>",
|
|
903
|
+
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
904
|
+
`TPageParam = ${pageParamType}`
|
|
905
|
+
];
|
|
906
|
+
const queryKeyParams = QueryKey.getParams({
|
|
907
|
+
pathParamsType,
|
|
908
|
+
typeSchemas,
|
|
909
|
+
paramsCasing
|
|
910
|
+
});
|
|
911
|
+
const queryOptionsParams = QueryOptions.getParams({
|
|
912
|
+
paramsType,
|
|
913
|
+
pathParamsType,
|
|
914
|
+
typeSchemas,
|
|
915
|
+
paramsCasing
|
|
916
|
+
});
|
|
917
|
+
const params = getParams$2({
|
|
918
|
+
paramsCasing,
|
|
919
|
+
paramsType,
|
|
920
|
+
pathParamsType,
|
|
921
|
+
typeSchemas,
|
|
922
|
+
pageParamGeneric: "TPageParam"
|
|
923
|
+
});
|
|
924
|
+
const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
|
|
925
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
926
|
+
name,
|
|
927
|
+
isExportable: true,
|
|
928
|
+
isIndexable: true,
|
|
929
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
930
|
+
name,
|
|
931
|
+
export: true,
|
|
932
|
+
generics: generics.join(", "),
|
|
933
|
+
params: params.toConstructor(),
|
|
934
|
+
JSDoc: { comments: getComments(operation) },
|
|
935
|
+
children: `
|
|
936
|
+
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
937
|
+
const { client: queryClient, ...queryOptions } = queryConfig
|
|
938
|
+
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
939
|
+
|
|
940
|
+
const query = useSuspenseInfiniteQuery({
|
|
941
|
+
...${queryOptions},
|
|
942
|
+
queryKey,
|
|
943
|
+
...queryOptions
|
|
944
|
+
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
945
|
+
|
|
946
|
+
query.queryKey = queryKey as TQueryKey
|
|
947
|
+
|
|
948
|
+
return query
|
|
949
|
+
`
|
|
950
|
+
})
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
SuspenseInfiniteQuery.getParams = getParams$2;
|
|
954
|
+
|
|
955
|
+
//#endregion
|
|
956
|
+
//#region src/components/SuspenseInfiniteQueryOptions.tsx
|
|
957
|
+
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
958
|
+
if (paramsType === "object") return FunctionParams.factory({
|
|
959
|
+
data: {
|
|
960
|
+
mode: "object",
|
|
961
|
+
children: {
|
|
962
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
963
|
+
typed: true,
|
|
964
|
+
casing: paramsCasing
|
|
965
|
+
}),
|
|
966
|
+
data: typeSchemas.request?.name ? {
|
|
967
|
+
type: typeSchemas.request?.name,
|
|
968
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
969
|
+
} : void 0,
|
|
970
|
+
params: typeSchemas.queryParams?.name ? {
|
|
971
|
+
type: typeSchemas.queryParams?.name,
|
|
972
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
973
|
+
} : void 0,
|
|
974
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
975
|
+
type: typeSchemas.headerParams?.name,
|
|
976
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
977
|
+
} : void 0
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
config: {
|
|
981
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
982
|
+
default: "{}"
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
return FunctionParams.factory({
|
|
986
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
987
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
988
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
989
|
+
typed: true,
|
|
990
|
+
casing: paramsCasing
|
|
991
|
+
}),
|
|
992
|
+
optional: isOptional(typeSchemas.pathParams?.schema)
|
|
993
|
+
} : void 0,
|
|
994
|
+
data: typeSchemas.request?.name ? {
|
|
995
|
+
type: typeSchemas.request?.name,
|
|
996
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
997
|
+
} : void 0,
|
|
998
|
+
params: typeSchemas.queryParams?.name ? {
|
|
999
|
+
type: typeSchemas.queryParams?.name,
|
|
1000
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
1001
|
+
} : void 0,
|
|
1002
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
1003
|
+
type: typeSchemas.headerParams?.name,
|
|
1004
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
1005
|
+
} : void 0,
|
|
1006
|
+
config: {
|
|
1007
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
1008
|
+
default: "{}"
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1013
|
+
const queryFnDataType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
1014
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
1015
|
+
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1016
|
+
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
1017
|
+
const parts = initialPageParam.split(" as ");
|
|
1018
|
+
return parts[parts.length - 1] ?? "unknown";
|
|
1019
|
+
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1020
|
+
const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
|
|
1021
|
+
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1022
|
+
const params = getParams$1({
|
|
1023
|
+
paramsType,
|
|
1024
|
+
paramsCasing,
|
|
1025
|
+
pathParamsType,
|
|
1026
|
+
typeSchemas
|
|
1027
|
+
});
|
|
1028
|
+
const clientParams = Client.getParams({
|
|
1029
|
+
paramsCasing,
|
|
1030
|
+
typeSchemas,
|
|
1031
|
+
paramsType,
|
|
1032
|
+
pathParamsType,
|
|
1033
|
+
isConfigurable: true
|
|
1034
|
+
});
|
|
1035
|
+
const queryKeyParams = QueryKey.getParams({
|
|
1036
|
+
pathParamsType,
|
|
1037
|
+
typeSchemas,
|
|
1038
|
+
paramsCasing
|
|
1039
|
+
});
|
|
1040
|
+
const queryOptions = [
|
|
1041
|
+
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
1042
|
+
cursorParam ? `getNextPageParam: (lastPage) => lastPage['${cursorParam}']` : void 0,
|
|
1043
|
+
cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']` : void 0,
|
|
1044
|
+
!cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
|
|
1045
|
+
!cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
|
|
1046
|
+
!cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
|
|
1047
|
+
].filter(Boolean);
|
|
1048
|
+
const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
|
|
1049
|
+
params = {
|
|
1050
|
+
...(params ?? {}),
|
|
1051
|
+
['${queryParam}']: pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}'],
|
|
1052
|
+
} as ${typeSchemas.queryParams?.name}` : "";
|
|
1053
|
+
const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => item && !item.optional ? key : void 0).filter(Boolean).join("&& ");
|
|
1054
|
+
const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
|
|
1055
|
+
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
1056
|
+
name,
|
|
1057
|
+
isExportable: true,
|
|
1058
|
+
isIndexable: true,
|
|
1059
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
1060
|
+
name,
|
|
1061
|
+
export: true,
|
|
1062
|
+
params: params.toConstructor(),
|
|
1063
|
+
children: `
|
|
1064
|
+
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
1065
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1066
|
+
${enabledText}
|
|
1067
|
+
queryKey,
|
|
1068
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
1069
|
+
config.signal = signal
|
|
1070
|
+
${infiniteOverrideParams}
|
|
1071
|
+
return ${clientName}(${clientParams.toCall()})
|
|
1072
|
+
},
|
|
1073
|
+
${queryOptions.join(",\n")}
|
|
1074
|
+
})
|
|
1075
|
+
`
|
|
1076
|
+
})
|
|
1077
|
+
});
|
|
1078
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
1079
|
+
name,
|
|
1080
|
+
isExportable: true,
|
|
1081
|
+
isIndexable: true,
|
|
1082
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
1083
|
+
name,
|
|
1084
|
+
export: true,
|
|
1085
|
+
params: params.toConstructor(),
|
|
1086
|
+
children: `
|
|
1087
|
+
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
1088
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1089
|
+
${enabledText}
|
|
1090
|
+
queryKey,
|
|
1091
|
+
queryFn: async ({ signal }) => {
|
|
1092
|
+
config.signal = signal
|
|
1093
|
+
return ${clientName}(${clientParams.toCall()})
|
|
1094
|
+
},
|
|
1095
|
+
${queryOptions.join(",\n")}
|
|
1096
|
+
})
|
|
1097
|
+
`
|
|
1098
|
+
})
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
SuspenseInfiniteQueryOptions.getParams = getParams$1;
|
|
820
1102
|
|
|
821
1103
|
//#endregion
|
|
822
1104
|
//#region src/components/SuspenseQuery.tsx
|
|
@@ -958,5 +1240,5 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
958
1240
|
SuspenseQuery.getParams = getParams;
|
|
959
1241
|
|
|
960
1242
|
//#endregion
|
|
961
|
-
export {
|
|
962
|
-
//# sourceMappingURL=components-
|
|
1243
|
+
export { Mutation as a, InfiniteQueryOptions as c, QueryKey as d, Query as i, InfiniteQuery as l, SuspenseInfiniteQueryOptions as n, MutationOptions as o, SuspenseInfiniteQuery as r, MutationKey as s, SuspenseQuery as t, QueryOptions as u };
|
|
1244
|
+
//# sourceMappingURL=components-K4qy3AIg.js.map
|