@kubb/plugin-svelte-query 0.0.0-canary-20241104172400

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-CDRGJAED.cjs +452 -0
  4. package/dist/chunk-CDRGJAED.cjs.map +1 -0
  5. package/dist/chunk-JGITTOE5.js +445 -0
  6. package/dist/chunk-JGITTOE5.js.map +1 -0
  7. package/dist/chunk-KRGCKSGR.cjs +527 -0
  8. package/dist/chunk-KRGCKSGR.cjs.map +1 -0
  9. package/dist/chunk-R6ZVBNG7.js +519 -0
  10. package/dist/chunk-R6ZVBNG7.js.map +1 -0
  11. package/dist/components.cjs +28 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +103 -0
  14. package/dist/components.d.ts +103 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +10 -0
  20. package/dist/generators.d.ts +10 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +127 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +120 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-B9W9aYra.d.cts +365 -0
  30. package/dist/types-B9W9aYra.d.ts +365 -0
  31. package/package.json +102 -0
  32. package/src/components/Mutation.tsx +158 -0
  33. package/src/components/MutationKey.tsx +54 -0
  34. package/src/components/Query.tsx +176 -0
  35. package/src/components/QueryKey.tsx +83 -0
  36. package/src/components/QueryOptions.tsx +133 -0
  37. package/src/components/index.ts +5 -0
  38. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  39. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  40. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  41. package/src/generators/__snapshots__/findByTags.ts +51 -0
  42. package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
  49. package/src/generators/index.ts +2 -0
  50. package/src/generators/mutationGenerator.tsx +117 -0
  51. package/src/generators/queryGenerator.tsx +129 -0
  52. package/src/index.ts +2 -0
  53. package/src/plugin.ts +141 -0
  54. package/src/types.ts +135 -0
@@ -0,0 +1,365 @@
1
+ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod, Operation } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
4
+
5
+ type Options$2 = {
6
+ /**
7
+ * Specify the export location for the files and define the behavior of the output
8
+ * @default { path: 'clients', barrelType: 'named' }
9
+ */
10
+ output?: Output;
11
+ /**
12
+ * Group the clients based on the provided name.
13
+ */
14
+ group?: Group;
15
+ /**
16
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
17
+ */
18
+ exclude?: Array<Exclude>;
19
+ /**
20
+ * Array containing include parameters to include tags/operations/methods/paths.
21
+ */
22
+ include?: Array<Include>;
23
+ /**
24
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
25
+ */
26
+ override?: Array<Override<ResolvedOptions$2>>;
27
+ /**
28
+ * Create `operations.ts` file with all operations grouped by methods.
29
+ * @default false
30
+ */
31
+ operations?: boolean;
32
+ /**
33
+ * Path to the client import path that will be used to do the API calls.
34
+ * It will be used as `import client from '${client.importPath}'`.
35
+ * It allows both relative and absolute path but be aware that we will not change the path.
36
+ * @default '@kubb/plugin-client/client'
37
+ */
38
+ importPath?: string;
39
+ /**
40
+ * Allows you to set a custom base url for all generated calls.
41
+ */
42
+ baseURL?: string;
43
+ /**
44
+ * ReturnType that will be used when calling the client.
45
+ * - 'data' will return ResponseConfig[data].
46
+ * - 'full' will return ResponseConfig.
47
+ * @default 'data'
48
+ */
49
+ dataReturnType?: 'data' | 'full';
50
+ /**
51
+ * How to pass your params
52
+ * - 'object' will return the params and pathParams as an object.
53
+ * - 'inline' will return the params as comma separated params.
54
+ * @default 'inline'
55
+ */
56
+ paramsType?: 'object' | 'inline';
57
+ /**
58
+ * How to pass your pathParams.
59
+ * - 'object' will return the pathParams as an object.
60
+ * - 'inline' will return the pathParams as comma separated params.
61
+ * @default 'inline'
62
+ */
63
+ pathParamsType?: 'object' | 'inline';
64
+ /**
65
+ * Which parser can be used before returning the data
66
+ * - 'zod' will use `@kubb/plugin-zod` to parse the data.
67
+ * @default 'client'
68
+ */
69
+ parser?: 'client' | 'zod';
70
+ transformers?: {
71
+ /**
72
+ * Customize the names based on the type that is provided by the plugin.
73
+ */
74
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
75
+ };
76
+ /**
77
+ * Define some generators next to the client generators
78
+ */
79
+ generators?: Array<Generator<PluginClient>>;
80
+ };
81
+ type ResolvedOptions$2 = {
82
+ output: Output;
83
+ group?: Options$2['group'];
84
+ baseURL: string | undefined;
85
+ parser: NonNullable<Options$2['parser']>;
86
+ importPath: NonNullable<Options$2['importPath']>;
87
+ dataReturnType: NonNullable<Options$2['dataReturnType']>;
88
+ pathParamsType: NonNullable<Options$2['pathParamsType']>;
89
+ paramsType: NonNullable<Options$2['paramsType']>;
90
+ };
91
+ type PluginClient = PluginFactoryOptions<'plugin-client', Options$2, ResolvedOptions$2, never, ResolvePathOptions>;
92
+
93
+ type TransformerProps$1 = {
94
+ operation: Operation;
95
+ schemas: OperationSchemas;
96
+ };
97
+ type Transformer$1 = (props: TransformerProps$1) => unknown[];
98
+ type Suspense = object;
99
+ /**
100
+ * Customize the queryKey
101
+ */
102
+ type QueryKey$1 = Transformer$1;
103
+ /**
104
+ * Customize the mutationKey
105
+ */
106
+ type MutationKey$1 = Transformer$1;
107
+ type Query$1 = {
108
+ /**
109
+ * Define which HttpMethods can be used for queries
110
+ * @default ['get']
111
+ */
112
+ methods: Array<HttpMethod>;
113
+ /**
114
+ * Path to the useQuery that will be used to do the useQuery functionality.
115
+ * It will be used as `import { useQuery } from '${importPath}'`.
116
+ * It allows both relative and absolute path.
117
+ * the path will be applied as is, so relative path should be based on the file being generated.
118
+ * @default '@tanstack/react-query'
119
+ */
120
+ importPath?: string;
121
+ };
122
+ type Mutation$1 = {
123
+ /**
124
+ * Define which HttpMethods can be used for mutations
125
+ * @default ['post', 'put', 'delete']
126
+ */
127
+ methods: Array<HttpMethod>;
128
+ /**
129
+ * Path to the useQuery that will be used to do the useQuery functionality.
130
+ * It will be used as `import { useQuery } from '${importPath}'`.
131
+ * It allows both relative and absolute path.
132
+ * the path will be applied as is, so relative path should be based on the file being generated.
133
+ * @default '@tanstack/react-query'
134
+ */
135
+ importPath?: string;
136
+ };
137
+ type Infinite = {
138
+ /**
139
+ * Specify the params key used for `pageParam`.
140
+ * @default 'id'
141
+ */
142
+ queryParam: string;
143
+ /**
144
+ * Which field of the data will be used, set it to undefined when no cursor is known.
145
+ */
146
+ cursorParam?: string | undefined;
147
+ /**
148
+ * The initial value, the value of the first page.
149
+ * @default 0
150
+ */
151
+ initialPageParam: unknown;
152
+ };
153
+ type Options$1 = {
154
+ /**
155
+ * Specify the export location for the files and define the behavior of the output
156
+ * @default { path: 'hooks', barrelType: 'named' }
157
+ */
158
+ output?: Output;
159
+ /**
160
+ * Group the @tanstack/query hooks based on the provided name.
161
+ */
162
+ group?: Group;
163
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
164
+ /**
165
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
166
+ */
167
+ exclude?: Array<Exclude>;
168
+ /**
169
+ * Array containing include parameters to include tags/operations/methods/paths.
170
+ */
171
+ include?: Array<Include>;
172
+ /**
173
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
174
+ */
175
+ override?: Array<Override<ResolvedOptions$1>>;
176
+ /**
177
+ * How to pass your params
178
+ * - 'object' will return the params and pathParams as an object.
179
+ * - 'inline' will return the params as comma separated params.
180
+ * @default 'inline'
181
+ */
182
+ paramsType?: 'object' | 'inline';
183
+ /**
184
+ * How to pass your pathParams.
185
+ * - 'object' will return the pathParams as an object.
186
+ * - 'inline' will return the pathParams as comma separated params.
187
+ * @default 'inline'
188
+ */
189
+ pathParamsType?: PluginClient['options']['pathParamsType'];
190
+ /**
191
+ * When set, an infiniteQuery hooks will be added.
192
+ */
193
+ infinite?: Partial<Infinite> | false;
194
+ /**
195
+ * When set, a suspenseQuery hooks will be added.
196
+ */
197
+ suspense?: Partial<Suspense> | false;
198
+ queryKey?: QueryKey$1;
199
+ /**
200
+ * Override some useQuery behaviours.
201
+ */
202
+ query?: Partial<Query$1> | false;
203
+ mutationKey?: MutationKey$1;
204
+ /**
205
+ * Override some useMutation behaviours.
206
+ */
207
+ mutation?: Partial<Mutation$1> | false;
208
+ /**
209
+ * Which parser should be used before returning the data to `@tanstack/query`.
210
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
211
+ */
212
+ parser?: PluginClient['options']['parser'];
213
+ transformers?: {
214
+ /**
215
+ * Customize the names based on the type that is provided by the plugin.
216
+ */
217
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
218
+ };
219
+ /**
220
+ * Define some generators next to the react-query generators
221
+ */
222
+ generators?: Array<Generator<PluginReactQuery>>;
223
+ };
224
+ type ResolvedOptions$1 = {
225
+ output: Output;
226
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
227
+ baseURL?: string;
228
+ };
229
+ parser: Required<NonNullable<Options$1['parser']>>;
230
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
231
+ paramsType: NonNullable<Options$1['paramsType']>;
232
+ /**
233
+ * Only used of infinite
234
+ */
235
+ infinite: NonNullable<Infinite> | false;
236
+ suspense: Suspense | false;
237
+ queryKey: QueryKey$1 | undefined;
238
+ query: NonNullable<Required<Query$1>> | false;
239
+ mutationKey: MutationKey$1 | undefined;
240
+ mutation: NonNullable<Required<Mutation$1>> | false;
241
+ };
242
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
243
+
244
+ type TransformerProps = {
245
+ operation: Operation;
246
+ schemas: OperationSchemas;
247
+ };
248
+ type Transformer = (props: TransformerProps) => unknown[];
249
+ /**
250
+ * Customize the queryKey
251
+ */
252
+ type QueryKey = Transformer;
253
+ /**
254
+ * Customize the mutationKey
255
+ */
256
+ type MutationKey = Transformer;
257
+ type Query = {
258
+ /**
259
+ * Define which HttpMethods can be used for queries
260
+ * @default ['get']
261
+ */
262
+ methods: Array<HttpMethod>;
263
+ /**
264
+ * Path to the useQuery that will be used to do the useQuery functionality.
265
+ * It will be used as `import { useQuery } from '${importPath}'`.
266
+ * It allows both relative and absolute path.
267
+ * the path will be applied as is, so relative path should be based on the file being generated.
268
+ * @default '@tanstack/svelte-query'
269
+ */
270
+ importPath?: string;
271
+ };
272
+ type Mutation = {
273
+ /**
274
+ * Define which HttpMethods can be used for mutations
275
+ * @default ['post', 'put', 'delete']
276
+ */
277
+ methods: Array<HttpMethod>;
278
+ /**
279
+ * Path to the useQuery that will be used to do the useQuery functionality.
280
+ * It will be used as `import { useQuery } from '${importPath}'`.
281
+ * It allows both relative and absolute path.
282
+ * the path will be applied as is, so relative path should be based on the file being generated.
283
+ * @default '@tanstack/svelte-query'
284
+ */
285
+ importPath?: string;
286
+ };
287
+ type Options = {
288
+ /**
289
+ * Specify the export location for the files and define the behavior of the output
290
+ * @default { path: 'hooks', barrelType: 'named' }
291
+ */
292
+ output?: Output;
293
+ /**
294
+ * Group the @tanstack/query hooks based on the provided name.
295
+ */
296
+ group?: Group;
297
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
298
+ /**
299
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
300
+ */
301
+ exclude?: Array<Exclude>;
302
+ /**
303
+ * Array containing include parameters to include tags/operations/methods/paths.
304
+ */
305
+ include?: Array<Include>;
306
+ /**
307
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
308
+ */
309
+ override?: Array<Override<ResolvedOptions>>;
310
+ /**
311
+ * How to pass your params
312
+ * - 'object' will return the params and pathParams as an object.
313
+ * - 'inline' will return the params as comma separated params.
314
+ * @default 'inline'
315
+ */
316
+ paramsType?: 'object' | 'inline';
317
+ /**
318
+ * How to pass your pathParams.
319
+ * - 'object' will return the pathParams as an object.
320
+ * - 'inline' will return the pathParams as comma separated params.
321
+ * @default 'inline'
322
+ */
323
+ pathParamsType?: PluginClient['options']['pathParamsType'];
324
+ queryKey?: QueryKey;
325
+ /**
326
+ * Override some useQuery behaviours.
327
+ */
328
+ query?: Partial<Query> | false;
329
+ mutationKey?: MutationKey;
330
+ /**
331
+ * Override some useMutation behaviours.
332
+ */
333
+ mutation?: Mutation | false;
334
+ /**
335
+ * Which parser should be used before returning the data to `@tanstack/query`.
336
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
337
+ */
338
+ parser?: PluginClient['options']['parser'];
339
+ transformers?: {
340
+ /**
341
+ * Customize the names based on the type that is provided by the plugin.
342
+ */
343
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
344
+ };
345
+ /**
346
+ * Define some generators next to the svelte-query generators
347
+ */
348
+ generators?: Array<Generator<PluginSvelteQuery>>;
349
+ };
350
+ type ResolvedOptions = {
351
+ output: Output;
352
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
353
+ baseURL?: string;
354
+ };
355
+ parser: Required<NonNullable<Options['parser']>>;
356
+ paramsType: NonNullable<Options['paramsType']>;
357
+ pathParamsType: NonNullable<Options['pathParamsType']>;
358
+ queryKey: QueryKey | undefined;
359
+ query: NonNullable<Required<Query>> | false;
360
+ mutationKey: MutationKey | undefined;
361
+ mutation: NonNullable<Required<Mutation>> | false;
362
+ };
363
+ type PluginSvelteQuery = PluginFactoryOptions<'plugin-svelte-query', Options, ResolvedOptions, never, ResolvePathOptions>;
364
+
365
+ export type { Options as O, PluginSvelteQuery as P, Transformer as T };