@kubb/plugin-react-query 5.0.0-alpha.1 → 5.0.0-alpha.11
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-BHQT9ZLc.cjs.map +1 -1
- package/dist/components-CpyHYGOw.js.map +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/{generators-W_darhpm.cjs → generators-DP07m3rH.cjs} +55 -55
- package/dist/generators-DP07m3rH.cjs.map +1 -0
- package/dist/{generators-CpiBv5eE.js → generators-DkQwKTc2.js} +56 -56
- package/dist/generators-DkQwKTc2.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +61 -53
- package/dist/generators.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/{types--pHE21AC.d.ts → types-D5S7Ny9r.d.ts} +3 -3
- package/package.json +11 -11
- package/src/generators/customHookOptionsFileGenerator.tsx +4 -4
- package/src/generators/hookOptionsGenerator.tsx +5 -5
- package/src/generators/infiniteQueryGenerator.tsx +10 -10
- package/src/generators/mutationGenerator.tsx +10 -10
- package/src/generators/queryGenerator.tsx +10 -10
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +10 -10
- package/src/generators/suspenseQueryGenerator.tsx +10 -10
- package/src/plugin.ts +5 -5
- package/dist/generators-CpiBv5eE.js.map +0 -1
- package/dist/generators-W_darhpm.cjs.map +0 -1
package/dist/generators.d.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { r as PluginReactQuery } from "./types
|
|
3
|
-
import {
|
|
2
|
+
import { r as PluginReactQuery } from "./types-D5S7Ny9r.js";
|
|
3
|
+
import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
4
4
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
5
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
6
5
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
7
|
-
import {
|
|
8
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
6
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
9
7
|
|
|
8
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
9
|
+
/** A function that can be registered as an event listener, synchronous or async. */
|
|
10
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* A typed EventEmitter that awaits all async listeners before resolving.
|
|
13
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
14
|
+
*/
|
|
15
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
|
|
19
|
+
* @default 10
|
|
20
|
+
*/
|
|
21
|
+
constructor(maxListener?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Emits an event and awaits all registered listeners in parallel.
|
|
24
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
25
|
+
*/
|
|
26
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
27
|
+
/** Registers a persistent listener for the given event. */
|
|
28
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
29
|
+
/** Registers a one-shot listener that removes itself after the first invocation. */
|
|
30
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
31
|
+
/** Removes a previously registered listener. */
|
|
32
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
33
|
+
/** Removes all listeners from every event channel. */
|
|
34
|
+
removeAll(): void;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
10
37
|
//#region ../plugin-oas/src/types.d.ts
|
|
11
38
|
type GetOasOptions = {
|
|
12
39
|
validate?: boolean;
|
|
@@ -26,14 +53,14 @@ declare global {
|
|
|
26
53
|
*
|
|
27
54
|
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
28
55
|
*
|
|
29
|
-
* `
|
|
56
|
+
* `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
30
57
|
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
31
58
|
*/
|
|
32
59
|
type Ref = {
|
|
33
60
|
propertyName: string;
|
|
34
61
|
originalName: string;
|
|
35
62
|
path: KubbFile.Path;
|
|
36
|
-
|
|
63
|
+
pluginName?: string;
|
|
37
64
|
};
|
|
38
65
|
type Refs = Record<string, Ref>;
|
|
39
66
|
type OperationSchema = {
|
|
@@ -93,8 +120,8 @@ type ByContentType = {
|
|
|
93
120
|
type: 'contentType';
|
|
94
121
|
pattern: string | RegExp;
|
|
95
122
|
};
|
|
96
|
-
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
97
|
-
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
123
|
+
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
124
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
98
125
|
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
99
126
|
options: Partial<TOptions>;
|
|
100
127
|
};
|
|
@@ -107,7 +134,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
107
134
|
include: Array<Include> | undefined;
|
|
108
135
|
override: Array<Override<TOptions>> | undefined;
|
|
109
136
|
contentType: contentType | undefined;
|
|
110
|
-
|
|
137
|
+
driver: PluginDriver;
|
|
111
138
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
112
139
|
/**
|
|
113
140
|
* Current plugin
|
|
@@ -133,7 +160,7 @@ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = P
|
|
|
133
160
|
method: HttpMethod;
|
|
134
161
|
operation: Operation;
|
|
135
162
|
}>>;
|
|
136
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
163
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
137
164
|
}
|
|
138
165
|
//#endregion
|
|
139
166
|
//#region ../plugin-oas/src/SchemaMapper.d.ts
|
|
@@ -361,7 +388,7 @@ type Schema = {
|
|
|
361
388
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
362
389
|
fabric: Fabric;
|
|
363
390
|
oas: Oas;
|
|
364
|
-
|
|
391
|
+
driver: PluginDriver;
|
|
365
392
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
366
393
|
/**
|
|
367
394
|
* Current plugin
|
|
@@ -423,46 +450,33 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
|
|
|
423
450
|
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
424
451
|
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
425
452
|
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
426
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
453
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
427
454
|
}
|
|
428
455
|
//#endregion
|
|
429
456
|
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
430
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions
|
|
457
|
+
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
431
458
|
name: string;
|
|
432
459
|
type: 'core';
|
|
433
|
-
version:
|
|
434
|
-
operations: (props: OperationsProps<TOptions
|
|
435
|
-
operation: (props: OperationProps<TOptions
|
|
436
|
-
schema: (props: SchemaProps<TOptions
|
|
460
|
+
version: '1';
|
|
461
|
+
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
462
|
+
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
463
|
+
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
437
464
|
};
|
|
438
465
|
//#endregion
|
|
439
466
|
//#region ../plugin-oas/src/generators/types.d.ts
|
|
440
|
-
type
|
|
441
|
-
type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
|
|
467
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
442
468
|
config: Config;
|
|
443
469
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
444
470
|
plugin: Plugin<TOptions>;
|
|
445
471
|
operations: Array<Operation>;
|
|
446
472
|
};
|
|
447
|
-
type
|
|
448
|
-
config: Config;
|
|
449
|
-
plugin: Plugin<TOptions>;
|
|
450
|
-
nodes: Array<OperationNode>;
|
|
451
|
-
};
|
|
452
|
-
type OperationV1Props<TOptions extends PluginFactoryOptions> = {
|
|
473
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
453
474
|
config: Config;
|
|
454
475
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
455
476
|
plugin: Plugin<TOptions>;
|
|
456
477
|
operation: Operation;
|
|
457
478
|
};
|
|
458
|
-
type
|
|
459
|
-
config: Config;
|
|
460
|
-
plugin: Plugin<TOptions>;
|
|
461
|
-
node: OperationNode;
|
|
462
|
-
};
|
|
463
|
-
type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationsV2Props<TOptions> : OperationsV1Props<TOptions>;
|
|
464
|
-
type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationV2Props<TOptions> : OperationV1Props<TOptions>;
|
|
465
|
-
type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
479
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
466
480
|
config: Config;
|
|
467
481
|
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
468
482
|
plugin: Plugin<TOptions>;
|
|
@@ -472,44 +486,38 @@ type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
|
472
486
|
value: SchemaObject;
|
|
473
487
|
};
|
|
474
488
|
};
|
|
475
|
-
type
|
|
476
|
-
config: Config;
|
|
477
|
-
plugin: Plugin<TOptions>;
|
|
478
|
-
node: SchemaNode;
|
|
479
|
-
};
|
|
480
|
-
type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? SchemaV2Props<TOptions> : SchemaV1Props<TOptions>;
|
|
481
|
-
type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> = CoreGenerator<TOptions, TVersion> | ReactGenerator<TOptions, TVersion>;
|
|
489
|
+
type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
|
|
482
490
|
//#endregion
|
|
483
491
|
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
484
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions
|
|
492
|
+
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
485
493
|
name: string;
|
|
486
494
|
type: 'react';
|
|
487
|
-
version:
|
|
488
|
-
Operations: (props: OperationsProps<TOptions
|
|
489
|
-
Operation: (props: OperationProps<TOptions
|
|
490
|
-
Schema: (props: SchemaProps<TOptions
|
|
495
|
+
version: '1';
|
|
496
|
+
Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
|
|
497
|
+
Operation: (props: OperationProps<TOptions>) => FabricReactNode;
|
|
498
|
+
Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
|
|
491
499
|
};
|
|
492
500
|
//#endregion
|
|
493
501
|
//#region src/generators/customHookOptionsFileGenerator.d.ts
|
|
494
|
-
declare const customHookOptionsFileGenerator: ReactGenerator<PluginReactQuery
|
|
502
|
+
declare const customHookOptionsFileGenerator: ReactGenerator<PluginReactQuery>;
|
|
495
503
|
//#endregion
|
|
496
504
|
//#region src/generators/hookOptionsGenerator.d.ts
|
|
497
|
-
declare const hookOptionsGenerator: ReactGenerator<PluginReactQuery
|
|
505
|
+
declare const hookOptionsGenerator: ReactGenerator<PluginReactQuery>;
|
|
498
506
|
//#endregion
|
|
499
507
|
//#region src/generators/infiniteQueryGenerator.d.ts
|
|
500
|
-
declare const infiniteQueryGenerator: ReactGenerator<PluginReactQuery
|
|
508
|
+
declare const infiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
501
509
|
//#endregion
|
|
502
510
|
//#region src/generators/mutationGenerator.d.ts
|
|
503
|
-
declare const mutationGenerator: ReactGenerator<PluginReactQuery
|
|
511
|
+
declare const mutationGenerator: ReactGenerator<PluginReactQuery>;
|
|
504
512
|
//#endregion
|
|
505
513
|
//#region src/generators/queryGenerator.d.ts
|
|
506
|
-
declare const queryGenerator: ReactGenerator<PluginReactQuery
|
|
514
|
+
declare const queryGenerator: ReactGenerator<PluginReactQuery>;
|
|
507
515
|
//#endregion
|
|
508
516
|
//#region src/generators/suspenseInfiniteQueryGenerator.d.ts
|
|
509
|
-
declare const suspenseInfiniteQueryGenerator: ReactGenerator<PluginReactQuery
|
|
517
|
+
declare const suspenseInfiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
510
518
|
//#endregion
|
|
511
519
|
//#region src/generators/suspenseQueryGenerator.d.ts
|
|
512
|
-
declare const suspenseQueryGenerator: ReactGenerator<PluginReactQuery
|
|
520
|
+
declare const suspenseQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
513
521
|
//#endregion
|
|
514
522
|
export { customHookOptionsFileGenerator, hookOptionsGenerator, infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
|
515
523
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-
|
|
1
|
+
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-DkQwKTc2.js";
|
|
2
2
|
export { customHookOptionsFileGenerator, hookOptionsGenerator, infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_components = require("./components-BHQT9ZLc.cjs");
|
|
3
|
-
const require_generators = require("./generators-
|
|
3
|
+
const require_generators = require("./generators-DP07m3rH.cjs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_components.__toESM(node_path);
|
|
6
6
|
let _kubb_core = require("@kubb/core");
|
|
@@ -13,7 +13,7 @@ let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
|
13
13
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
14
14
|
//#region src/plugin.ts
|
|
15
15
|
const pluginReactQueryName = "plugin-react-query";
|
|
16
|
-
const pluginReactQuery = (0, _kubb_core.
|
|
16
|
+
const pluginReactQuery = (0, _kubb_core.createPlugin)((options) => {
|
|
17
17
|
const { output = {
|
|
18
18
|
path: "hooks",
|
|
19
19
|
barrelType: "named"
|
|
@@ -113,7 +113,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
113
113
|
const oas = await this.getOas();
|
|
114
114
|
const baseURL = await this.getBaseURL();
|
|
115
115
|
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
116
|
-
const hasClientPlugin = !!this.
|
|
116
|
+
const hasClientPlugin = !!this.driver.getPluginByName(_kubb_plugin_client.pluginClientName);
|
|
117
117
|
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
|
|
118
118
|
baseName: "fetch.ts",
|
|
119
119
|
path: node_path.default.resolve(root, ".kubb/fetch.ts"),
|
|
@@ -141,7 +141,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
141
141
|
const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
142
142
|
fabric: this.fabric,
|
|
143
143
|
oas,
|
|
144
|
-
|
|
144
|
+
driver: this.driver,
|
|
145
145
|
events: this.events,
|
|
146
146
|
plugin: this.plugin,
|
|
147
147
|
contentType,
|
|
@@ -155,7 +155,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
155
155
|
type: output.barrelType ?? "named",
|
|
156
156
|
root,
|
|
157
157
|
output,
|
|
158
|
-
meta: {
|
|
158
|
+
meta: { pluginName: this.plugin.name }
|
|
159
159
|
});
|
|
160
160
|
await this.upsertFile(...barrelFiles);
|
|
161
161
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","camelCase","pascalCase","pluginClientName","fetchClientSource","axiosClientSource","configSource","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n paramsCasing,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;AAEpC,MAAa,oBAAA,GAAA,WAAA,eAAmD,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa;EACXA,m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K,OAAO,QAAQ,OAAO,WAEvF,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAMH,UAAAA,QAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAO,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAUI,mDAAAA,SAAoBC,mDAAAA;KAC3E,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAML,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAOM,4CAAAA;KACP,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","camelCase","pascalCase","pluginClientName","fetchClientSource","axiosClientSource","configSource","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n paramsCasing,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;AAEpC,MAAa,oBAAA,GAAA,WAAA,eAAmD,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa;EACXA,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA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AW;IACpB,UAAU;IACV,MAAMH,UAAAA,QAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAO,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAUI,mDAAAA,SAAoBC,mDAAAA;KAC3E,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAML,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAOM,4CAAAA;KACP,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as Options, r as PluginReactQuery } from "./types
|
|
2
|
+
import { n as Options, r as PluginReactQuery } from "./types-D5S7Ny9r.js";
|
|
3
3
|
import * as _kubb_core0 from "@kubb/core";
|
|
4
4
|
|
|
5
5
|
//#region src/plugin.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { d as MutationKey, f as camelCase, p as pascalCase, u as QueryKey } from "./components-CpyHYGOw.js";
|
|
3
|
-
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-
|
|
3
|
+
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-DkQwKTc2.js";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
6
6
|
import { pluginClientName } from "@kubb/plugin-client";
|
|
7
7
|
import { source } from "@kubb/plugin-client/templates/clients/axios.source";
|
|
8
8
|
import { source as source$1 } from "@kubb/plugin-client/templates/clients/fetch.source";
|
|
@@ -12,7 +12,7 @@ import { pluginTsName } from "@kubb/plugin-ts";
|
|
|
12
12
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
13
13
|
//#region src/plugin.ts
|
|
14
14
|
const pluginReactQueryName = "plugin-react-query";
|
|
15
|
-
const pluginReactQuery =
|
|
15
|
+
const pluginReactQuery = createPlugin((options) => {
|
|
16
16
|
const { output = {
|
|
17
17
|
path: "hooks",
|
|
18
18
|
barrelType: "named"
|
|
@@ -112,7 +112,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
112
112
|
const oas = await this.getOas();
|
|
113
113
|
const baseURL = await this.getBaseURL();
|
|
114
114
|
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
115
|
-
const hasClientPlugin = !!this.
|
|
115
|
+
const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName);
|
|
116
116
|
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
|
|
117
117
|
baseName: "fetch.ts",
|
|
118
118
|
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
@@ -140,7 +140,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
140
140
|
const files = await new OperationGenerator(this.plugin.options, {
|
|
141
141
|
fabric: this.fabric,
|
|
142
142
|
oas,
|
|
143
|
-
|
|
143
|
+
driver: this.driver,
|
|
144
144
|
events: this.events,
|
|
145
145
|
plugin: this.plugin,
|
|
146
146
|
contentType,
|
|
@@ -154,7 +154,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
154
154
|
type: output.barrelType ?? "named",
|
|
155
155
|
root,
|
|
156
156
|
output,
|
|
157
|
-
meta: {
|
|
157
|
+
meta: { pluginName: this.plugin.name }
|
|
158
158
|
});
|
|
159
159
|
await this.upsertFile(...barrelFiles);
|
|
160
160
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n paramsCasing,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;AAEpC,MAAa,mBAAmB,cAAgC,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,OAAO,QAAQ,EACjB,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,eACA,cACA,aACA,WACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe,KAAA;AAEhH,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,QAAQ,QAAQ;IAChB,SAAS,QAAQ;IACjB,QAAQ;IACR,YAAY,QAAQ,cAAc;IAClC,gBAAgB,QAAQ,kBAAkB;IAC1C;IACA,YAAY;IACZ;IACD;GACD,UAAU,WACN;IACE,YAAY;IACZ,kBAAkB;IAClB,aAAa,KAAA;IACb,WAAW,KAAA;IACX,eAAe,KAAA;IACf,GAAG;IACJ,GACD;GACJ;GACA;GACA,OACE,UAAU,QACN,QACA;IACE,SAAS,CAAC,MAAM;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M,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n paramsCasing,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;AAEpC,MAAa,mBAAmB,cAAgC,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,e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WAAW,UAAUA,WAAoBC;KAC3E,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAOC;KACP,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -4,7 +4,7 @@ import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
|
|
|
4
4
|
import { Exclude, Include, OperationSchemas, Override, ResolvePathOptions } from "@kubb/plugin-oas";
|
|
5
5
|
import { HttpMethod, Oas, Operation, contentType } from "@kubb/oas";
|
|
6
6
|
import { FunctionParams } from "@kubb/react-fabric";
|
|
7
|
-
import { Generator } from "@kubb/plugin-oas/generators";
|
|
7
|
+
import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
|
|
8
8
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
9
9
|
|
|
10
10
|
//#region ../../internals/tanstack-query/src/types.d.ts
|
|
@@ -243,7 +243,7 @@ type Options = {
|
|
|
243
243
|
/**
|
|
244
244
|
* Define some generators next to the react-query generators
|
|
245
245
|
*/
|
|
246
|
-
generators?: Array<Generator<PluginReactQuery>>;
|
|
246
|
+
generators?: Array<Generator$1<PluginReactQuery>>;
|
|
247
247
|
};
|
|
248
248
|
type ResolvedOptions = {
|
|
249
249
|
output: Output<Oas>;
|
|
@@ -267,4 +267,4 @@ type ResolvedOptions = {
|
|
|
267
267
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
268
268
|
//#endregion
|
|
269
269
|
export { MutationKey$1 as a, QueryKey$1 as i, Options as n, PluginReactQuery as r, Infinite as t };
|
|
270
|
-
//# sourceMappingURL=types
|
|
270
|
+
//# sourceMappingURL=types-D5S7Ny9r.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.11",
|
|
4
4
|
"description": "React Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for React applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-query",
|
|
@@ -71,19 +71,19 @@
|
|
|
71
71
|
}
|
|
72
72
|
],
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@kubb/fabric-core": "0.
|
|
75
|
-
"@kubb/react-fabric": "0.
|
|
74
|
+
"@kubb/fabric-core": "0.14.0",
|
|
75
|
+
"@kubb/react-fabric": "0.14.0",
|
|
76
76
|
"remeda": "^2.33.6",
|
|
77
|
-
"@kubb/core": "5.0.0-alpha.
|
|
78
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
79
|
-
"@kubb/plugin-client": "5.0.0-alpha.
|
|
80
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
81
|
-
"@kubb/plugin-ts": "5.0.0-alpha.
|
|
82
|
-
"@kubb/plugin-zod": "5.0.0-alpha.
|
|
77
|
+
"@kubb/core": "5.0.0-alpha.11",
|
|
78
|
+
"@kubb/oas": "5.0.0-alpha.11",
|
|
79
|
+
"@kubb/plugin-client": "5.0.0-alpha.11",
|
|
80
|
+
"@kubb/plugin-oas": "5.0.0-alpha.11",
|
|
81
|
+
"@kubb/plugin-ts": "5.0.0-alpha.11",
|
|
82
|
+
"@kubb/plugin-zod": "5.0.0-alpha.11"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"@kubb/fabric-core": "0.
|
|
86
|
-
"@kubb/react-fabric": "0.
|
|
85
|
+
"@kubb/fabric-core": "0.14.0",
|
|
86
|
+
"@kubb/react-fabric": "0.14.0"
|
|
87
87
|
},
|
|
88
88
|
"engines": {
|
|
89
89
|
"node": ">=22"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
-
import {
|
|
3
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
4
4
|
import type { Operation } from '@kubb/oas'
|
|
5
5
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
6
6
|
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -13,9 +13,9 @@ export const customHookOptionsFileGenerator = createReactGenerator<PluginReactQu
|
|
|
13
13
|
const {
|
|
14
14
|
options,
|
|
15
15
|
options: { output },
|
|
16
|
-
|
|
16
|
+
name: pluginName,
|
|
17
17
|
} = plugin
|
|
18
|
-
const
|
|
18
|
+
const driver = usePluginDriver()
|
|
19
19
|
|
|
20
20
|
const { getFile } = useOperationManager(generator)
|
|
21
21
|
|
|
@@ -37,7 +37,7 @@ export const customHookOptionsFileGenerator = createReactGenerator<PluginReactQu
|
|
|
37
37
|
return getFile(firstOperation, { prefix: 'use' }).path
|
|
38
38
|
}
|
|
39
39
|
// Get the index file of the hooks directory
|
|
40
|
-
return
|
|
40
|
+
return driver.getFile({ name: 'index', extname: '.ts', pluginName }).path
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const ensureExtension = (filePath: string, extname: string) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
2
2
|
import type { Operation } from '@kubb/oas'
|
|
3
3
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
4
4
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -13,9 +13,9 @@ export const hookOptionsGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
13
13
|
const {
|
|
14
14
|
options,
|
|
15
15
|
options: { output },
|
|
16
|
-
|
|
16
|
+
name: pluginName,
|
|
17
17
|
} = plugin
|
|
18
|
-
const
|
|
18
|
+
const driver = usePluginDriver()
|
|
19
19
|
|
|
20
20
|
const oas = useOas()
|
|
21
21
|
const { getName, getFile } = useOperationManager(generator)
|
|
@@ -25,7 +25,7 @@ export const hookOptionsGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const name = 'HookOptions'
|
|
28
|
-
const file =
|
|
28
|
+
const file = driver.getFile({ name, extname: '.ts', pluginName })
|
|
29
29
|
|
|
30
30
|
const getOperationOptions = (operation: Operation) => {
|
|
31
31
|
const operationOptions = generator.getOptions(operation, operation.method)
|
|
@@ -181,7 +181,7 @@ export const hookOptionsGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
181
181
|
baseName={file.baseName}
|
|
182
182
|
path={file.path}
|
|
183
183
|
meta={file.meta}
|
|
184
|
-
banner={getBanner({ oas, output, config:
|
|
184
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
185
185
|
footer={getFooter({ oas, output })}
|
|
186
186
|
>
|
|
187
187
|
{imports}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
2
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
3
3
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
4
4
|
import { Client } from '@kubb/plugin-client/components'
|
|
5
5
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
@@ -19,7 +19,7 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
19
19
|
options,
|
|
20
20
|
options: { output },
|
|
21
21
|
} = plugin
|
|
22
|
-
const
|
|
22
|
+
const driver = usePluginDriver()
|
|
23
23
|
|
|
24
24
|
const oas = useOas()
|
|
25
25
|
const { getSchemas, getName, getFile } = useOperationManager(generator)
|
|
@@ -38,20 +38,20 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
38
38
|
file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const hasClientPlugin = !!
|
|
41
|
+
const hasClientPlugin = !!driver.getPluginByName(pluginClientName)
|
|
42
42
|
// Class-based clients are not compatible with query hooks, so we generate inline clients
|
|
43
43
|
const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'
|
|
44
44
|
const client = {
|
|
45
45
|
name: shouldUseClientPlugin
|
|
46
46
|
? getName(operation, {
|
|
47
47
|
type: 'function',
|
|
48
|
-
|
|
48
|
+
pluginName: pluginClientName,
|
|
49
49
|
})
|
|
50
50
|
: getName(operation, {
|
|
51
51
|
type: 'function',
|
|
52
52
|
suffix: 'infinite',
|
|
53
53
|
}),
|
|
54
|
-
file: getFile(operation, {
|
|
54
|
+
file: getFile(operation, { pluginName: pluginClientName }),
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const queryOptions = {
|
|
@@ -64,14 +64,14 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const type = {
|
|
67
|
-
file: getFile(operation, {
|
|
67
|
+
file: getFile(operation, { pluginName: pluginTsName }),
|
|
68
68
|
//todo remove type?
|
|
69
|
-
schemas: getSchemas(operation, {
|
|
69
|
+
schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const zod = {
|
|
73
|
-
file: getFile(operation, {
|
|
74
|
-
schemas: getSchemas(operation, {
|
|
73
|
+
file: getFile(operation, { pluginName: pluginZodName }),
|
|
74
|
+
schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (!isQuery || isMutation || !infiniteOptions) {
|
|
@@ -96,7 +96,7 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
96
96
|
baseName={query.file.baseName}
|
|
97
97
|
path={query.file.path}
|
|
98
98
|
meta={query.file.meta}
|
|
99
|
-
banner={getBanner({ oas, output, config:
|
|
99
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
100
100
|
footer={getFooter({ oas, output })}
|
|
101
101
|
>
|
|
102
102
|
{options.parser === 'zod' && (
|