@kubb/plugin-solid-query 3.16.2 → 3.16.4
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-CNM6UaoG.js +320 -0
- package/dist/components-CNM6UaoG.js.map +1 -0
- package/dist/components-LAcBpjX8.cjs +366 -0
- package/dist/components-LAcBpjX8.cjs.map +1 -0
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +143 -57
- package/dist/components.d.ts +143 -57
- package/dist/components.js +3 -3
- package/dist/generators-DS71XOIi.cjs +199 -0
- package/dist/generators-DS71XOIi.cjs.map +1 -0
- package/dist/generators-DU74wsZY.js +194 -0
- package/dist/generators-DU74wsZY.js.map +1 -0
- package/dist/generators.cjs +3 -12
- package/dist/generators.d.cts +5 -7
- package/dist/generators.d.ts +5 -7
- package/dist/generators.js +4 -4
- package/dist/index.cjs +97 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +97 -122
- package/dist/index.js.map +1 -1
- package/dist/types-C4Kxe-X1.d.ts +1335 -0
- package/dist/types-DULzisVA.d.cts +1335 -0
- package/package.json +23 -28
- package/dist/chunk-DVQAS6QW.cjs +0 -265
- package/dist/chunk-DVQAS6QW.cjs.map +0 -1
- package/dist/chunk-IH7LFLIP.cjs +0 -161
- package/dist/chunk-IH7LFLIP.cjs.map +0 -1
- package/dist/chunk-U7KQKXOC.js +0 -159
- package/dist/chunk-U7KQKXOC.js.map +0 -1
- package/dist/chunk-XXQM3BYJ.js +0 -261
- package/dist/chunk-XXQM3BYJ.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-Cx6RgBxP.d.cts +0 -114
- package/dist/types-Cx6RgBxP.d.ts +0 -114
package/dist/components.d.ts
CHANGED
|
@@ -1,77 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
|
-
import { P as PluginSolidQuery, T as Transformer } from './types-Cx6RgBxP.js';
|
|
6
|
-
import '@kubb/core';
|
|
7
|
-
import '@kubb/plugin-client';
|
|
1
|
+
import { Operation, OperationSchemas, PluginSolidQuery, Transformer } from "./types-C4Kxe-X1.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
8
3
|
|
|
4
|
+
//#region ../react/src/utils/getFunctionParams.d.ts
|
|
5
|
+
type Param = {
|
|
6
|
+
/**
|
|
7
|
+
* `object` will return the pathParams as an object.
|
|
8
|
+
*
|
|
9
|
+
* `inline` will return the pathParams as comma separated params.
|
|
10
|
+
* @default `'inline'`
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
mode?: 'object' | 'inline' | 'inlineSpread';
|
|
14
|
+
type?: 'string' | 'number' | (string & {});
|
|
15
|
+
optional?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @example test = "default"
|
|
18
|
+
*/
|
|
19
|
+
default?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Used for no TypeScript(with mode object)
|
|
22
|
+
* @example test: "default"
|
|
23
|
+
*/
|
|
24
|
+
value?: string;
|
|
25
|
+
children?: Params;
|
|
26
|
+
};
|
|
27
|
+
type Params = Record<string, Param | undefined>;
|
|
28
|
+
type Options = {
|
|
29
|
+
type: 'constructor' | 'call' | 'object' | 'objectValue';
|
|
30
|
+
transformName?: (name: string) => string;
|
|
31
|
+
transformType?: (type: string) => string;
|
|
32
|
+
};
|
|
33
|
+
declare class FunctionParams {
|
|
34
|
+
#private;
|
|
35
|
+
static factory(params: Params): FunctionParams;
|
|
36
|
+
constructor(params: Params);
|
|
37
|
+
get params(): Params;
|
|
38
|
+
get flatParams(): Params;
|
|
39
|
+
toCall({
|
|
40
|
+
transformName,
|
|
41
|
+
transformType
|
|
42
|
+
}?: Pick<Options, 'transformName' | 'transformType'>): string;
|
|
43
|
+
toObject(): string;
|
|
44
|
+
toObjectValue(): string;
|
|
45
|
+
toConstructor(): string;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/components/Query.d.ts
|
|
9
49
|
type Props$2 = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Name of the function
|
|
52
|
+
*/
|
|
53
|
+
name: string;
|
|
54
|
+
queryOptionsName: string;
|
|
55
|
+
queryKeyName: string;
|
|
56
|
+
queryKeyTypeName: string;
|
|
57
|
+
typeSchemas: OperationSchemas;
|
|
58
|
+
operation: Operation;
|
|
59
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
60
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType'];
|
|
61
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
62
|
+
dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType'];
|
|
23
63
|
};
|
|
24
64
|
type GetParamsProps$2 = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
65
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
66
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType'];
|
|
67
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
68
|
+
dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType'];
|
|
69
|
+
typeSchemas: OperationSchemas;
|
|
30
70
|
};
|
|
31
|
-
declare function Query({
|
|
71
|
+
declare function Query({
|
|
72
|
+
name,
|
|
73
|
+
queryKeyTypeName,
|
|
74
|
+
queryOptionsName,
|
|
75
|
+
queryKeyName,
|
|
76
|
+
paramsCasing,
|
|
77
|
+
paramsType,
|
|
78
|
+
pathParamsType,
|
|
79
|
+
dataReturnType,
|
|
80
|
+
typeSchemas,
|
|
81
|
+
operation
|
|
82
|
+
}: Props$2): ReactNode;
|
|
32
83
|
declare namespace Query {
|
|
33
|
-
|
|
84
|
+
var getParams: ({
|
|
85
|
+
paramsType,
|
|
86
|
+
paramsCasing,
|
|
87
|
+
pathParamsType,
|
|
88
|
+
dataReturnType,
|
|
89
|
+
typeSchemas
|
|
90
|
+
}: GetParamsProps$2) => FunctionParams;
|
|
34
91
|
}
|
|
35
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/components/QueryKey.d.ts
|
|
36
94
|
type Props$1 = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
95
|
+
name: string;
|
|
96
|
+
typeName: string;
|
|
97
|
+
typeSchemas: OperationSchemas;
|
|
98
|
+
operation: Operation;
|
|
99
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
100
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
101
|
+
transformer: Transformer | undefined;
|
|
44
102
|
};
|
|
45
103
|
type GetParamsProps$1 = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
104
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
105
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
106
|
+
typeSchemas: OperationSchemas;
|
|
49
107
|
};
|
|
50
|
-
declare function QueryKey({
|
|
108
|
+
declare function QueryKey({
|
|
109
|
+
name,
|
|
110
|
+
typeSchemas,
|
|
111
|
+
paramsCasing,
|
|
112
|
+
pathParamsType,
|
|
113
|
+
operation,
|
|
114
|
+
typeName,
|
|
115
|
+
transformer
|
|
116
|
+
}: Props$1): ReactNode;
|
|
51
117
|
declare namespace QueryKey {
|
|
52
|
-
|
|
53
|
-
|
|
118
|
+
var getParams: ({
|
|
119
|
+
pathParamsType,
|
|
120
|
+
paramsCasing,
|
|
121
|
+
typeSchemas
|
|
122
|
+
}: GetParamsProps$1) => FunctionParams;
|
|
123
|
+
var getTransformer: Transformer;
|
|
54
124
|
}
|
|
55
|
-
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/components/QueryOptions.d.ts
|
|
56
127
|
type Props = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
128
|
+
name: string;
|
|
129
|
+
clientName: string;
|
|
130
|
+
queryKeyName: string;
|
|
131
|
+
typeSchemas: OperationSchemas;
|
|
132
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
133
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType'];
|
|
134
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
135
|
+
dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType'];
|
|
65
136
|
};
|
|
66
137
|
type GetParamsProps = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
138
|
+
paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing'];
|
|
139
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType'];
|
|
140
|
+
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType'];
|
|
141
|
+
typeSchemas: OperationSchemas;
|
|
71
142
|
};
|
|
72
|
-
declare function QueryOptions({
|
|
143
|
+
declare function QueryOptions({
|
|
144
|
+
name,
|
|
145
|
+
clientName,
|
|
146
|
+
typeSchemas,
|
|
147
|
+
paramsCasing,
|
|
148
|
+
paramsType,
|
|
149
|
+
dataReturnType,
|
|
150
|
+
pathParamsType,
|
|
151
|
+
queryKeyName
|
|
152
|
+
}: Props): ReactNode;
|
|
73
153
|
declare namespace QueryOptions {
|
|
74
|
-
|
|
154
|
+
var getParams: ({
|
|
155
|
+
paramsType,
|
|
156
|
+
paramsCasing,
|
|
157
|
+
pathParamsType,
|
|
158
|
+
typeSchemas
|
|
159
|
+
}: GetParamsProps) => FunctionParams;
|
|
75
160
|
}
|
|
76
|
-
|
|
161
|
+
//#endregion
|
|
77
162
|
export { Query, QueryKey, QueryOptions };
|
|
163
|
+
//# sourceMappingURL=components.d.ts.map
|
package/dist/components.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Query, QueryKey, QueryOptions } from "./components-CNM6UaoG.js";
|
|
2
|
+
|
|
3
|
+
export { Query, QueryKey, QueryOptions };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const require_components = require('./components-LAcBpjX8.cjs');
|
|
2
|
+
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
3
|
+
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
4
|
+
const __kubb_plugin_zod = require_components.__toESM(require("@kubb/plugin-zod"));
|
|
5
|
+
const __kubb_react = require_components.__toESM(require("@kubb/react"));
|
|
6
|
+
const __kubb_plugin_oas_utils = require_components.__toESM(require("@kubb/plugin-oas/utils"));
|
|
7
|
+
const __kubb_react_jsx_runtime = require_components.__toESM(require("@kubb/react/jsx-runtime"));
|
|
8
|
+
const __kubb_plugin_client_components = require_components.__toESM(require("@kubb/plugin-client/components"));
|
|
9
|
+
const __kubb_plugin_client = require_components.__toESM(require("@kubb/plugin-client"));
|
|
10
|
+
const __kubb_plugin_oas_hooks = require_components.__toESM(require("@kubb/plugin-oas/hooks"));
|
|
11
|
+
const remeda = require_components.__toESM(require("remeda"));
|
|
12
|
+
|
|
13
|
+
//#region src/generators/queryGenerator.tsx
|
|
14
|
+
const queryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
15
|
+
name: "svelte-query",
|
|
16
|
+
Operation({ options, operation }) {
|
|
17
|
+
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
18
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
19
|
+
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
20
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
21
|
+
const isMutation = (0, remeda.difference)([
|
|
22
|
+
"post",
|
|
23
|
+
"put",
|
|
24
|
+
"delete",
|
|
25
|
+
"patch"
|
|
26
|
+
], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
27
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/solid-query";
|
|
28
|
+
const query = {
|
|
29
|
+
name: getName(operation, {
|
|
30
|
+
type: "function",
|
|
31
|
+
prefix: "create"
|
|
32
|
+
}),
|
|
33
|
+
typeName: getName(operation, { type: "type" }),
|
|
34
|
+
file: getFile(operation, { prefix: "create" })
|
|
35
|
+
};
|
|
36
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
37
|
+
const client = {
|
|
38
|
+
name: hasClientPlugin ? getName(operation, {
|
|
39
|
+
type: "function",
|
|
40
|
+
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
41
|
+
}) : getName(operation, { type: "function" }),
|
|
42
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
43
|
+
};
|
|
44
|
+
const queryOptions = { name: getName(operation, {
|
|
45
|
+
type: "function",
|
|
46
|
+
suffix: "QueryOptions"
|
|
47
|
+
}) };
|
|
48
|
+
const queryKey = {
|
|
49
|
+
name: getName(operation, {
|
|
50
|
+
type: "const",
|
|
51
|
+
suffix: "QueryKey"
|
|
52
|
+
}),
|
|
53
|
+
typeName: getName(operation, {
|
|
54
|
+
type: "type",
|
|
55
|
+
suffix: "QueryKey"
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
const type = {
|
|
59
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
60
|
+
schemas: getSchemas(operation, {
|
|
61
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
62
|
+
type: "type"
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
const zod = {
|
|
66
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
67
|
+
schemas: getSchemas(operation, {
|
|
68
|
+
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
69
|
+
type: "function"
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
if (!isQuery || isMutation) return null;
|
|
73
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
74
|
+
baseName: query.file.baseName,
|
|
75
|
+
path: query.file.path,
|
|
76
|
+
meta: query.file.meta,
|
|
77
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
78
|
+
oas,
|
|
79
|
+
output,
|
|
80
|
+
config: pluginManager.config
|
|
81
|
+
}),
|
|
82
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
83
|
+
oas,
|
|
84
|
+
output
|
|
85
|
+
}),
|
|
86
|
+
children: [
|
|
87
|
+
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
88
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
89
|
+
root: query.file.path,
|
|
90
|
+
path: zod.file.path
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
93
|
+
name: "fetch",
|
|
94
|
+
path: options.client.importPath
|
|
95
|
+
}),
|
|
96
|
+
!!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
97
|
+
name: [client.name],
|
|
98
|
+
root: query.file.path,
|
|
99
|
+
path: client.file.path
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
102
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
103
|
+
path: options.client.importPath,
|
|
104
|
+
isTypeOnly: true
|
|
105
|
+
}),
|
|
106
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
107
|
+
name: ["ResponseConfig"],
|
|
108
|
+
path: options.client.importPath,
|
|
109
|
+
isTypeOnly: true
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
112
|
+
name: [
|
|
113
|
+
type.schemas.request?.name,
|
|
114
|
+
type.schemas.response.name,
|
|
115
|
+
type.schemas.pathParams?.name,
|
|
116
|
+
type.schemas.queryParams?.name,
|
|
117
|
+
type.schemas.headerParams?.name,
|
|
118
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
119
|
+
].filter(Boolean),
|
|
120
|
+
root: query.file.path,
|
|
121
|
+
path: type.file.path,
|
|
122
|
+
isTypeOnly: true
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
|
|
125
|
+
name: queryKey.name,
|
|
126
|
+
typeName: queryKey.typeName,
|
|
127
|
+
operation,
|
|
128
|
+
paramsCasing: options.paramsCasing,
|
|
129
|
+
pathParamsType: options.pathParamsType,
|
|
130
|
+
typeSchemas: type.schemas,
|
|
131
|
+
transformer: options.queryKey
|
|
132
|
+
}),
|
|
133
|
+
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
134
|
+
name: client.name,
|
|
135
|
+
baseURL: options.client.baseURL,
|
|
136
|
+
operation,
|
|
137
|
+
typeSchemas: type.schemas,
|
|
138
|
+
zodSchemas: zod.schemas,
|
|
139
|
+
dataReturnType: options.client.dataReturnType,
|
|
140
|
+
paramsCasing: options.paramsCasing,
|
|
141
|
+
paramsType: options.paramsType,
|
|
142
|
+
pathParamsType: options.pathParamsType,
|
|
143
|
+
parser: options.parser
|
|
144
|
+
}),
|
|
145
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
146
|
+
name: ["queryOptions"],
|
|
147
|
+
path: importPath
|
|
148
|
+
}),
|
|
149
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryOptions, {
|
|
150
|
+
name: queryOptions.name,
|
|
151
|
+
clientName: client.name,
|
|
152
|
+
queryKeyName: queryKey.name,
|
|
153
|
+
typeSchemas: type.schemas,
|
|
154
|
+
paramsCasing: options.paramsCasing,
|
|
155
|
+
paramsType: options.paramsType,
|
|
156
|
+
pathParamsType: options.pathParamsType,
|
|
157
|
+
dataReturnType: options.client.dataReturnType
|
|
158
|
+
}),
|
|
159
|
+
options.query && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
160
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
161
|
+
name: ["createQuery"],
|
|
162
|
+
path: importPath
|
|
163
|
+
}),
|
|
164
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
165
|
+
name: [
|
|
166
|
+
"QueryKey",
|
|
167
|
+
"QueryClient",
|
|
168
|
+
"UseBaseQueryOptions",
|
|
169
|
+
"UseQueryResult"
|
|
170
|
+
],
|
|
171
|
+
path: importPath,
|
|
172
|
+
isTypeOnly: true
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Query, {
|
|
175
|
+
name: query.name,
|
|
176
|
+
queryOptionsName: queryOptions.name,
|
|
177
|
+
typeSchemas: type.schemas,
|
|
178
|
+
paramsType: options.paramsType,
|
|
179
|
+
pathParamsType: options.pathParamsType,
|
|
180
|
+
operation,
|
|
181
|
+
paramsCasing: options.paramsCasing,
|
|
182
|
+
dataReturnType: options.client.dataReturnType,
|
|
183
|
+
queryKeyName: queryKey.name,
|
|
184
|
+
queryKeyTypeName: queryKey.typeName
|
|
185
|
+
})
|
|
186
|
+
] })
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
Object.defineProperty(exports, 'queryGenerator', {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function () {
|
|
196
|
+
return queryGenerator;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=generators-DS71XOIi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DS71XOIi.cjs","names":["pluginClientName","pluginTsName","pluginZodName","File","QueryKey","Client","QueryOptions","Query"],"sources":["../src/generators/queryGenerator.tsx"],"sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryKey, QueryOptions } from '../components'\nimport type { PluginSolidQuery } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSolidQuery>({\n name: 'svelte-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSolidQuery>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method)\n const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'create' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'create' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n <File.Import name={'fetch'} path={options.client.importPath} />\n {!!hasClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <File.Import name={['queryOptions']} path={importPath} />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n queryKeyName={queryKey.name}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n dataReturnType={options.client.dataReturnType}\n />\n {options.query && (\n <>\n <File.Import name={['createQuery']} path={importPath} />\n <File.Import name={['QueryKey', 'QueryClient', 'UseBaseQueryOptions', 'UseQueryResult']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n paramsCasing={options.paramsCasing}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,6DAAwD;CACnE,MAAM;CACN,UAAU,EAAE,SAAS,WAAW,EAAE;EAChC,MAAM,EACJ,QAAQ,EACN,SAAS,EAAE,QAAQ,EACpB,EACD,eACD,6BAA6B;EAC9B,MAAM,2CAAc;E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DACDC;KACC,MAAM,SAAS;KACf,UAAU,SAAS;KACR;KACX,cAAc,QAAQ;KACtB,gBAAgB,QAAQ;KACxB,aAAa,KAAK;KAClB,aAAa,QAAQ;MACrB;IACD,CAAC,qEACCC;KACC,MAAM,OAAO;KACb,SAAS,QAAQ,OAAO;KACb;KACX,aAAa,KAAK;KAClB,YAAY,IAAI;KAChB,gBAAgB,QAAQ,OAAO;KAC/B,cAAc,QAAQ;KACtB,YAAY,QAAQ;KACpB,gBAAgB,QAAQ;KACxB,QAAQ,QAAQ;MAChB;sDAEHF,kBAAK;KAAO,MAAM,CAAC,cAAe;KAAE,MAAM;MAAc;sDACxDG;KACC,MAAM,aAAa;KACnB,YAAY,OAAO;KACnB,cAAc,SAAS;KACvB,aAAa,KAAK;KAClB,cAAc,QAAQ;KACtB,YAAY,QAAQ;KACpB,gBAAgB,QAAQ;KACxB,gBAAgB,QAAQ,OAAO;MAC/B;IACD,QAAQ;uDAEJH,kBAAK;MAAO,MAAM,CAAC,aAAc;MAAE,MAAM;OAAc;uDACvDA,kBAAK;MAAO,MAAM;OAAC;OAAY;OAAe;OAAuB;MAAiB;MAAE,MAAM;MAAY;OAAa;uDACvHI;MACC,MAAM,MAAM;MACZ,kBAAkB,aAAa;MAC/B,aAAa,KAAK;MAClB,YAAY,QAAQ;MACpB,gBAAgB,QAAQ;MACb;MACX,cAAc,QAAQ;MACtB,gBAAgB,QAAQ,OAAO;MAC/B,cAAc,SAAS;MACvB,kBAAkB,SAAS;OAC3B;QACD;;IAEA;CAEV;AACF,EAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Query, QueryKey, QueryOptions } from "./components-CNM6UaoG.js";
|
|
2
|
+
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
3
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
4
|
+
import { pluginZodName } from "@kubb/plugin-zod";
|
|
5
|
+
import { File, useApp } from "@kubb/react";
|
|
6
|
+
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
8
|
+
import { Client } from "@kubb/plugin-client/components";
|
|
9
|
+
import { pluginClientName } from "@kubb/plugin-client";
|
|
10
|
+
import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
11
|
+
import { difference } from "remeda";
|
|
12
|
+
|
|
13
|
+
//#region src/generators/queryGenerator.tsx
|
|
14
|
+
const queryGenerator = createReactGenerator({
|
|
15
|
+
name: "svelte-query",
|
|
16
|
+
Operation({ options, operation }) {
|
|
17
|
+
const { plugin: { options: { output } }, pluginManager } = useApp();
|
|
18
|
+
const oas = useOas();
|
|
19
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
20
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
21
|
+
const isMutation = difference([
|
|
22
|
+
"post",
|
|
23
|
+
"put",
|
|
24
|
+
"delete",
|
|
25
|
+
"patch"
|
|
26
|
+
], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
27
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/solid-query";
|
|
28
|
+
const query = {
|
|
29
|
+
name: getName(operation, {
|
|
30
|
+
type: "function",
|
|
31
|
+
prefix: "create"
|
|
32
|
+
}),
|
|
33
|
+
typeName: getName(operation, { type: "type" }),
|
|
34
|
+
file: getFile(operation, { prefix: "create" })
|
|
35
|
+
};
|
|
36
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName]);
|
|
37
|
+
const client = {
|
|
38
|
+
name: hasClientPlugin ? getName(operation, {
|
|
39
|
+
type: "function",
|
|
40
|
+
pluginKey: [pluginClientName]
|
|
41
|
+
}) : getName(operation, { type: "function" }),
|
|
42
|
+
file: getFile(operation, { pluginKey: [pluginClientName] })
|
|
43
|
+
};
|
|
44
|
+
const queryOptions = { name: getName(operation, {
|
|
45
|
+
type: "function",
|
|
46
|
+
suffix: "QueryOptions"
|
|
47
|
+
}) };
|
|
48
|
+
const queryKey = {
|
|
49
|
+
name: getName(operation, {
|
|
50
|
+
type: "const",
|
|
51
|
+
suffix: "QueryKey"
|
|
52
|
+
}),
|
|
53
|
+
typeName: getName(operation, {
|
|
54
|
+
type: "type",
|
|
55
|
+
suffix: "QueryKey"
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
const type = {
|
|
59
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
60
|
+
schemas: getSchemas(operation, {
|
|
61
|
+
pluginKey: [pluginTsName],
|
|
62
|
+
type: "type"
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
const zod = {
|
|
66
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
67
|
+
schemas: getSchemas(operation, {
|
|
68
|
+
pluginKey: [pluginZodName],
|
|
69
|
+
type: "function"
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
if (!isQuery || isMutation) return null;
|
|
73
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
74
|
+
baseName: query.file.baseName,
|
|
75
|
+
path: query.file.path,
|
|
76
|
+
meta: query.file.meta,
|
|
77
|
+
banner: getBanner({
|
|
78
|
+
oas,
|
|
79
|
+
output,
|
|
80
|
+
config: pluginManager.config
|
|
81
|
+
}),
|
|
82
|
+
footer: getFooter({
|
|
83
|
+
oas,
|
|
84
|
+
output
|
|
85
|
+
}),
|
|
86
|
+
children: [
|
|
87
|
+
options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
|
|
88
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
89
|
+
root: query.file.path,
|
|
90
|
+
path: zod.file.path
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
93
|
+
name: "fetch",
|
|
94
|
+
path: options.client.importPath
|
|
95
|
+
}),
|
|
96
|
+
!!hasClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
97
|
+
name: [client.name],
|
|
98
|
+
root: query.file.path,
|
|
99
|
+
path: client.file.path
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
102
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
103
|
+
path: options.client.importPath,
|
|
104
|
+
isTypeOnly: true
|
|
105
|
+
}),
|
|
106
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
107
|
+
name: ["ResponseConfig"],
|
|
108
|
+
path: options.client.importPath,
|
|
109
|
+
isTypeOnly: true
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
112
|
+
name: [
|
|
113
|
+
type.schemas.request?.name,
|
|
114
|
+
type.schemas.response.name,
|
|
115
|
+
type.schemas.pathParams?.name,
|
|
116
|
+
type.schemas.queryParams?.name,
|
|
117
|
+
type.schemas.headerParams?.name,
|
|
118
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
119
|
+
].filter(Boolean),
|
|
120
|
+
root: query.file.path,
|
|
121
|
+
path: type.file.path,
|
|
122
|
+
isTypeOnly: true
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ jsx(QueryKey, {
|
|
125
|
+
name: queryKey.name,
|
|
126
|
+
typeName: queryKey.typeName,
|
|
127
|
+
operation,
|
|
128
|
+
paramsCasing: options.paramsCasing,
|
|
129
|
+
pathParamsType: options.pathParamsType,
|
|
130
|
+
typeSchemas: type.schemas,
|
|
131
|
+
transformer: options.queryKey
|
|
132
|
+
}),
|
|
133
|
+
!hasClientPlugin && /* @__PURE__ */ jsx(Client, {
|
|
134
|
+
name: client.name,
|
|
135
|
+
baseURL: options.client.baseURL,
|
|
136
|
+
operation,
|
|
137
|
+
typeSchemas: type.schemas,
|
|
138
|
+
zodSchemas: zod.schemas,
|
|
139
|
+
dataReturnType: options.client.dataReturnType,
|
|
140
|
+
paramsCasing: options.paramsCasing,
|
|
141
|
+
paramsType: options.paramsType,
|
|
142
|
+
pathParamsType: options.pathParamsType,
|
|
143
|
+
parser: options.parser
|
|
144
|
+
}),
|
|
145
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
146
|
+
name: ["queryOptions"],
|
|
147
|
+
path: importPath
|
|
148
|
+
}),
|
|
149
|
+
/* @__PURE__ */ jsx(QueryOptions, {
|
|
150
|
+
name: queryOptions.name,
|
|
151
|
+
clientName: client.name,
|
|
152
|
+
queryKeyName: queryKey.name,
|
|
153
|
+
typeSchemas: type.schemas,
|
|
154
|
+
paramsCasing: options.paramsCasing,
|
|
155
|
+
paramsType: options.paramsType,
|
|
156
|
+
pathParamsType: options.pathParamsType,
|
|
157
|
+
dataReturnType: options.client.dataReturnType
|
|
158
|
+
}),
|
|
159
|
+
options.query && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
160
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
161
|
+
name: ["createQuery"],
|
|
162
|
+
path: importPath
|
|
163
|
+
}),
|
|
164
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
165
|
+
name: [
|
|
166
|
+
"QueryKey",
|
|
167
|
+
"QueryClient",
|
|
168
|
+
"UseBaseQueryOptions",
|
|
169
|
+
"UseQueryResult"
|
|
170
|
+
],
|
|
171
|
+
path: importPath,
|
|
172
|
+
isTypeOnly: true
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsx(Query, {
|
|
175
|
+
name: query.name,
|
|
176
|
+
queryOptionsName: queryOptions.name,
|
|
177
|
+
typeSchemas: type.schemas,
|
|
178
|
+
paramsType: options.paramsType,
|
|
179
|
+
pathParamsType: options.pathParamsType,
|
|
180
|
+
operation,
|
|
181
|
+
paramsCasing: options.paramsCasing,
|
|
182
|
+
dataReturnType: options.client.dataReturnType,
|
|
183
|
+
queryKeyName: queryKey.name,
|
|
184
|
+
queryKeyTypeName: queryKey.typeName
|
|
185
|
+
})
|
|
186
|
+
] })
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { queryGenerator };
|
|
194
|
+
//# sourceMappingURL=generators-DU74wsZY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DU74wsZY.js","names":[],"sources":["../src/generators/queryGenerator.tsx"],"sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryKey, QueryOptions } from '../components'\nimport type { PluginSolidQuery } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSolidQuery>({\n name: 'svelte-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSolidQuery>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method)\n const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'create' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'create' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n <File.Import name={'fetch'} path={options.client.importPath} />\n {!!hasClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <File.Import name={['queryOptions']} path={importPath} />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n queryKeyName={queryKey.name}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n dataReturnType={options.client.dataReturnType}\n />\n {options.query && (\n <>\n <File.Import name={['createQuery']} path={importPath} />\n <File.Import name={['QueryKey', 'QueryClient', 'UseBaseQueryOptions', 'UseQueryResult']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n paramsCasing={options.paramsCasing}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,iBAAiB,qBAAuC;CACnE,MAAM;CACN,UAAU,EAAE,SAAS,WAAW,EAAE;EAChC,MAAM,EACJ,QAAQ,EACN,SAAS,EAAE,QAAQ,EACpB,EACD,eACD,GAAG,QAA0B;EAC9B,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,SAAS,GAAG,qBAAqB;EAE9D,MAAM,UAAU,OAAO,QAAQ,UAAU,YAAY,OAAO,QAAQ,OAAO,QAAQ,KAAK,CAAC,WAAW,UAAU,WAAW,OAAO;EAChI,MAAM,aAAa,WAAW;GAAC;GAAQ;GAAO;GAAU;EAAQ,GAAE,QAAQ,QAAQ,QAAQ,MAAM,UAAU,CAAE,EAAC,CAAC,KAAK,CAAC,WAAW,UAAU,WAAW,OAAO;EAC3J,MAAM,aAAa,QAAQ,QAAQ,QAAQ,MAAM,aAAa;EAE9D,MAAM,QAAQ;GACZ,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;GAAU,EAAC;GAChE,UAAU,QAAQ,WAAW,EAAE,MAAM,OAAQ,EAAC;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