@kubb/plugin-react-query 4.5.1 → 4.5.2
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.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/index.cjs +6 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-DgN61fGy.d.ts → types-BOMcjyzP.d.ts} +45 -38
- package/dist/{types-XOFOCTil.d.cts → types-CZA77t3-.d.cts} +45 -38
- package/package.json +9 -9
- package/src/plugin.ts +7 -10
package/dist/components.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Operation, i as Transformer, o as OperationSchemas, r as PluginReactQuery, t as Infinite } from "./types-
|
|
1
|
+
import { c as Operation, i as Transformer, o as OperationSchemas, r as PluginReactQuery, t as Infinite } from "./types-CZA77t3-.cjs";
|
|
2
2
|
import { FunctionParams } from "@kubb/react-fabric";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Operation, i as Transformer, o as OperationSchemas, r as PluginReactQuery, t as Infinite } from "./types-
|
|
1
|
+
import { c as Operation, i as Transformer, o as OperationSchemas, r as PluginReactQuery, t as Infinite } from "./types-BOMcjyzP.js";
|
|
2
2
|
import { FunctionParams } from "@kubb/react-fabric";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ReactGenerator, r as PluginReactQuery } from "./types-
|
|
1
|
+
import { a as ReactGenerator, r as PluginReactQuery } from "./types-CZA77t3-.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/generators/infiniteQueryGenerator.d.ts
|
|
4
4
|
declare const infiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ReactGenerator, r as PluginReactQuery } from "./types-
|
|
1
|
+
import { a as ReactGenerator, r as PluginReactQuery } from "./types-BOMcjyzP.js";
|
|
2
2
|
|
|
3
3
|
//#region src/generators/infiniteQueryGenerator.d.ts
|
|
4
4
|
declare const infiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ __kubb_plugin_zod = require_components.__toESM(__kubb_plugin_zod);
|
|
|
19
19
|
|
|
20
20
|
//#region src/plugin.ts
|
|
21
21
|
const pluginReactQueryName = "plugin-react-query";
|
|
22
|
-
const pluginReactQuery = (0, __kubb_core.
|
|
22
|
+
const pluginReactQuery = (0, __kubb_core.definePlugin)((options) => {
|
|
23
23
|
const { output = {
|
|
24
24
|
path: "hooks",
|
|
25
25
|
barrelType: "named"
|
|
@@ -98,15 +98,14 @@ const pluginReactQuery = (0, __kubb_core.createPlugin)((options) => {
|
|
|
98
98
|
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
99
99
|
return resolvedName;
|
|
100
100
|
},
|
|
101
|
-
async
|
|
102
|
-
const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
|
|
103
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
101
|
+
async install() {
|
|
104
102
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
105
103
|
const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
106
|
-
const
|
|
104
|
+
const oas = await this.getOas();
|
|
105
|
+
const baseURL = await this.getBaseURL();
|
|
107
106
|
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
108
107
|
const hasClientPlugin = !!this.pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
109
|
-
const containsFetcher = this.
|
|
108
|
+
const containsFetcher = this.fabric.files.some((file) => file.baseName === "fetcher.ts");
|
|
110
109
|
if (!hasClientPlugin && !this.plugin.options.client.importPath && !containsFetcher) await this.addFile({
|
|
111
110
|
baseName: "fetcher.ts",
|
|
112
111
|
path: node_path.default.resolve(root, ".kubb/fetcher.ts"),
|
|
@@ -127,7 +126,7 @@ const pluginReactQuery = (0, __kubb_core.createPlugin)((options) => {
|
|
|
127
126
|
mode
|
|
128
127
|
}).build(...generators);
|
|
129
128
|
await this.addFile(...files);
|
|
130
|
-
const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.
|
|
129
|
+
const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
131
130
|
type: output.barrelType ?? "named",
|
|
132
131
|
root,
|
|
133
132
|
output,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\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 { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } 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 = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n paramsCasing,\n contentType,\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n client: 'axios',\n dataReturnType: 'data',\n pathParamsType,\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: 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 methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\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 const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!hasClientPlugin && !this.plugin.options.client.importPath && !containsFetcher) {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...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 logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAaA,MAAa,uB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Za,IAAII,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-
|
|
1
|
+
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-CZA77t3-.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-
|
|
1
|
+
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-BOMcjyzP.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as MutationKey, l as QueryKey } from "./components-By3fyxDp.js";
|
|
2
2
|
import { i as infiniteQueryGenerator, n as queryGenerator, r as mutationGenerator, t as suspenseQueryGenerator } from "./generators-BTb-fJYl.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
6
6
|
import { resolveModuleSource } from "@kubb/core/utils";
|
|
7
7
|
import { pluginClientName } from "@kubb/plugin-client";
|
|
@@ -11,7 +11,7 @@ import { pluginZodName } from "@kubb/plugin-zod";
|
|
|
11
11
|
|
|
12
12
|
//#region src/plugin.ts
|
|
13
13
|
const pluginReactQueryName = "plugin-react-query";
|
|
14
|
-
const pluginReactQuery =
|
|
14
|
+
const pluginReactQuery = definePlugin((options) => {
|
|
15
15
|
const { output = {
|
|
16
16
|
path: "hooks",
|
|
17
17
|
barrelType: "named"
|
|
@@ -90,15 +90,14 @@ const pluginReactQuery = createPlugin((options) => {
|
|
|
90
90
|
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
91
91
|
return resolvedName;
|
|
92
92
|
},
|
|
93
|
-
async
|
|
94
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
95
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
93
|
+
async install() {
|
|
96
94
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
97
95
|
const mode = getMode(path.resolve(root, output.path));
|
|
98
|
-
const
|
|
96
|
+
const oas = await this.getOas();
|
|
97
|
+
const baseURL = await this.getBaseURL();
|
|
99
98
|
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
100
99
|
const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName]);
|
|
101
|
-
const containsFetcher = this.
|
|
100
|
+
const containsFetcher = this.fabric.files.some((file) => file.baseName === "fetcher.ts");
|
|
102
101
|
if (!hasClientPlugin && !this.plugin.options.client.importPath && !containsFetcher) await this.addFile({
|
|
103
102
|
baseName: "fetcher.ts",
|
|
104
103
|
path: path.resolve(root, ".kubb/fetcher.ts"),
|
|
@@ -119,7 +118,7 @@ const pluginReactQuery = createPlugin((options) => {
|
|
|
119
118
|
mode
|
|
120
119
|
}).build(...generators);
|
|
121
120
|
await this.addFile(...files);
|
|
122
|
-
const barrelFiles = await getBarrelFiles(this.
|
|
121
|
+
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
123
122
|
type: output.barrelType ?? "named",
|
|
124
123
|
root,
|
|
125
124
|
output,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\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 { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } 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 = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n paramsCasing,\n contentType,\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n client: 'axios',\n dataReturnType: 'data',\n pathParamsType,\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: 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 methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\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 const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!hasClientPlugin && !this.plugin.options.client.importPath && !containsFetcher) {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...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 logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAaA,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;EAAC;EAAgB;EAAwB;EAAwB;EAAkB,CAAC,OAAO,QAAQ,EAChH,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,cACA,gBACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,QAAQ;IACR,gBAAgB;IAChB;IACA,GAAG,QAAQ;IACZ;GACD,UAAU,WACN;IACE,YAAY;IACZ,kBAAkB;IAClB,aAAa;IACb,GAAG;IACJ,GACD;GAC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AK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAC/B,MAAM,UAAU,MAAM,KAAK,YAAY;AAEvC,OAAI,QACF,MAAK,OAAO,QAAQ,OAAO,UAAU;GAGvC,MAAM,kBAAkB,CAAC,CAAC,KAAK,cAAc,eAAe,CAAC,iBAAiB,CAAC;GAC/E,MAAM,kBAAkB,KAAK,OAAO,MAAM,MAAM,SAAS,KAAK,aAAa,aAAa;AAExF,OAAI,CAAC,mBAAmB,CAAC,KAAK,OAAO,QAAQ,OAAO,cAAc,CAAC,gBAEjE,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,mBAAmB;IAC5C,SAAS,CACP;KACE,MAAM;KACN,OAAO,oBACL,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAU,gDAAgD,8CACjG,CAAC;KACH,CACF;IACF,CAAC;GAeJ,MAAM,QAAQ,MAZa,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fabric
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
2
2
|
import * as OasTypes from "oas/types";
|
|
3
3
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
4
4
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -110,6 +110,21 @@ type Logger = {
|
|
|
110
110
|
type PossiblePromise<T> = Promise<T> | T;
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region ../core/src/types.d.ts
|
|
113
|
+
declare global {
|
|
114
|
+
namespace Kubb {
|
|
115
|
+
interface PluginContext {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Config used in `kubb.config.ts`
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* import { defineConfig } from '@kubb/core'
|
|
123
|
+
* export default defineConfig({
|
|
124
|
+
* ...
|
|
125
|
+
* })
|
|
126
|
+
*/
|
|
127
|
+
|
|
113
128
|
type InputPath = {
|
|
114
129
|
/**
|
|
115
130
|
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
264
279
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
265
280
|
*/
|
|
266
281
|
post?: Array<string>;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
} : {
|
|
270
|
-
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
271
|
-
});
|
|
282
|
+
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
283
|
+
};
|
|
272
284
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
273
285
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
274
286
|
/**
|
|
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
294
306
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
295
307
|
*/
|
|
296
308
|
options: TOptions['resolvedOptions'];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
309
|
+
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
|
|
312
|
+
*/
|
|
313
|
+
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
314
|
+
};
|
|
302
315
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
303
316
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
304
317
|
/**
|
|
305
318
|
* Start of the lifecycle of a plugin.
|
|
306
319
|
* @type hookParallel
|
|
307
320
|
*/
|
|
308
|
-
|
|
321
|
+
install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
309
322
|
/**
|
|
310
323
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
311
324
|
* Options can als be included.
|
|
312
325
|
* @type hookFirst
|
|
313
326
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
314
327
|
*/
|
|
315
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.
|
|
328
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
|
|
316
329
|
/**
|
|
317
330
|
* Resolve to a name based on a string.
|
|
318
331
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
320
333
|
* @example ('pet') => 'Pet'
|
|
321
334
|
*/
|
|
322
335
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
323
|
-
/**
|
|
324
|
-
* End of the plugin lifecycle.
|
|
325
|
-
* @type hookParallel
|
|
326
|
-
*/
|
|
327
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
328
336
|
};
|
|
329
337
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
330
338
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
@@ -351,24 +359,15 @@ type ResolveNameParams = {
|
|
|
351
359
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
352
360
|
fabric: Fabric;
|
|
353
361
|
config: Config;
|
|
354
|
-
/**
|
|
355
|
-
* @deprecated
|
|
356
|
-
*/
|
|
357
|
-
fileManager: FileManager;
|
|
358
362
|
pluginManager: PluginManager;
|
|
359
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<
|
|
360
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
361
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
363
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
362
364
|
logger: Logger;
|
|
363
|
-
|
|
364
|
-
* All plugins
|
|
365
|
-
*/
|
|
366
|
-
plugins: Plugin[];
|
|
365
|
+
mode: KubbFile.Mode;
|
|
367
366
|
/**
|
|
368
367
|
* Current plugin
|
|
369
368
|
*/
|
|
370
369
|
plugin: Plugin<TOptions>;
|
|
371
|
-
};
|
|
370
|
+
} & Kubb.PluginContext;
|
|
372
371
|
/**
|
|
373
372
|
* Specify the export location for the files and define the behavior of the output
|
|
374
373
|
*/
|
|
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
|
|
|
443
442
|
};
|
|
444
443
|
declare class PluginManager {
|
|
445
444
|
#private;
|
|
446
|
-
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
447
445
|
readonly events: EventEmitter<Events>;
|
|
448
446
|
readonly config: Config;
|
|
449
447
|
readonly executed: Array<Executer>;
|
|
450
448
|
readonly logger: Logger;
|
|
451
449
|
readonly options: Options$3;
|
|
452
450
|
constructor(config: Config, options: Options$3);
|
|
451
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
452
|
+
get plugins(): Array<Plugin>;
|
|
453
453
|
getFile<TOptions = object>({
|
|
454
454
|
name,
|
|
455
455
|
mode,
|
|
@@ -459,7 +459,7 @@ declare class PluginManager {
|
|
|
459
459
|
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
460
460
|
pluginKey: Plugin['key'];
|
|
461
461
|
}>;
|
|
462
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.
|
|
462
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
463
463
|
resolveName: (params: ResolveNameParams) => string;
|
|
464
464
|
/**
|
|
465
465
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
@@ -547,11 +547,9 @@ declare class PluginManager {
|
|
|
547
547
|
}): Promise<void>;
|
|
548
548
|
getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
|
|
549
549
|
getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
|
|
550
|
-
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
551
|
-
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
552
550
|
}
|
|
553
551
|
//#endregion
|
|
554
|
-
//#region ../core/src/
|
|
552
|
+
//#region ../core/src/utils/getBarrelFiles.d.ts
|
|
555
553
|
type FileMetaBase = {
|
|
556
554
|
pluginKey?: Plugin['key'];
|
|
557
555
|
};
|
|
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
|
|
|
669
667
|
/**
|
|
670
668
|
* Full qualified path.
|
|
671
669
|
*/
|
|
672
|
-
path: KubbFile.
|
|
670
|
+
path: KubbFile.Path;
|
|
673
671
|
/**
|
|
674
672
|
* When true `File.Import` will be used.
|
|
675
673
|
* When false a reference will be used inside the current file.
|
|
@@ -774,6 +772,15 @@ type Schema = {
|
|
|
774
772
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
775
773
|
//#endregion
|
|
776
774
|
//#region ../plugin-oas/src/types.d.ts
|
|
775
|
+
type Context$2 = {
|
|
776
|
+
getOas(): Promise<Oas>;
|
|
777
|
+
getBaseURL(): Promise<string | undefined>;
|
|
778
|
+
};
|
|
779
|
+
declare global {
|
|
780
|
+
namespace Kubb {
|
|
781
|
+
interface PluginContext extends Context$2 {}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
777
784
|
type ResolvePathOptions = {
|
|
778
785
|
pluginKey?: Plugin['key'];
|
|
779
786
|
group?: {
|
|
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
|
|
|
794
801
|
type Ref = {
|
|
795
802
|
propertyName: string;
|
|
796
803
|
originalName: string;
|
|
797
|
-
path: KubbFile.
|
|
804
|
+
path: KubbFile.Path;
|
|
798
805
|
pluginKey?: Plugin['key'];
|
|
799
806
|
};
|
|
800
807
|
type Refs = Record<string, Ref>;
|
|
@@ -1270,4 +1277,4 @@ type ResolvedOptions = {
|
|
|
1270
1277
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1271
1278
|
//#endregion
|
|
1272
1279
|
export { ReactGenerator as a, Operation$1 as c, Transformer as i, Options$1 as n, OperationSchemas as o, PluginReactQuery as r, UserPluginWithLifeCycle as s, Infinite as t };
|
|
1273
|
-
//# sourceMappingURL=types-
|
|
1280
|
+
//# sourceMappingURL=types-BOMcjyzP.d.ts.map
|
|
@@ -5,7 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
5
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
6
|
import BaseOas from "oas";
|
|
7
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric
|
|
8
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -110,6 +110,21 @@ type Logger = {
|
|
|
110
110
|
type PossiblePromise<T> = Promise<T> | T;
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region ../core/src/types.d.ts
|
|
113
|
+
declare global {
|
|
114
|
+
namespace Kubb {
|
|
115
|
+
interface PluginContext {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Config used in `kubb.config.ts`
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* import { defineConfig } from '@kubb/core'
|
|
123
|
+
* export default defineConfig({
|
|
124
|
+
* ...
|
|
125
|
+
* })
|
|
126
|
+
*/
|
|
127
|
+
|
|
113
128
|
type InputPath = {
|
|
114
129
|
/**
|
|
115
130
|
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
264
279
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
265
280
|
*/
|
|
266
281
|
post?: Array<string>;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
} : {
|
|
270
|
-
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
271
|
-
});
|
|
282
|
+
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
283
|
+
};
|
|
272
284
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
273
285
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
274
286
|
/**
|
|
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
294
306
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
295
307
|
*/
|
|
296
308
|
options: TOptions['resolvedOptions'];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
309
|
+
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
|
|
312
|
+
*/
|
|
313
|
+
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
314
|
+
};
|
|
302
315
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
303
316
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
304
317
|
/**
|
|
305
318
|
* Start of the lifecycle of a plugin.
|
|
306
319
|
* @type hookParallel
|
|
307
320
|
*/
|
|
308
|
-
|
|
321
|
+
install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
309
322
|
/**
|
|
310
323
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
311
324
|
* Options can als be included.
|
|
312
325
|
* @type hookFirst
|
|
313
326
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
314
327
|
*/
|
|
315
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.
|
|
328
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
|
|
316
329
|
/**
|
|
317
330
|
* Resolve to a name based on a string.
|
|
318
331
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
320
333
|
* @example ('pet') => 'Pet'
|
|
321
334
|
*/
|
|
322
335
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
323
|
-
/**
|
|
324
|
-
* End of the plugin lifecycle.
|
|
325
|
-
* @type hookParallel
|
|
326
|
-
*/
|
|
327
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
328
336
|
};
|
|
329
337
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
330
338
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
@@ -351,24 +359,15 @@ type ResolveNameParams = {
|
|
|
351
359
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
352
360
|
fabric: Fabric;
|
|
353
361
|
config: Config;
|
|
354
|
-
/**
|
|
355
|
-
* @deprecated
|
|
356
|
-
*/
|
|
357
|
-
fileManager: FileManager;
|
|
358
362
|
pluginManager: PluginManager;
|
|
359
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<
|
|
360
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
361
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
363
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
362
364
|
logger: Logger;
|
|
363
|
-
|
|
364
|
-
* All plugins
|
|
365
|
-
*/
|
|
366
|
-
plugins: Plugin[];
|
|
365
|
+
mode: KubbFile.Mode;
|
|
367
366
|
/**
|
|
368
367
|
* Current plugin
|
|
369
368
|
*/
|
|
370
369
|
plugin: Plugin<TOptions>;
|
|
371
|
-
};
|
|
370
|
+
} & Kubb.PluginContext;
|
|
372
371
|
/**
|
|
373
372
|
* Specify the export location for the files and define the behavior of the output
|
|
374
373
|
*/
|
|
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
|
|
|
443
442
|
};
|
|
444
443
|
declare class PluginManager {
|
|
445
444
|
#private;
|
|
446
|
-
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
447
445
|
readonly events: EventEmitter<Events>;
|
|
448
446
|
readonly config: Config;
|
|
449
447
|
readonly executed: Array<Executer>;
|
|
450
448
|
readonly logger: Logger;
|
|
451
449
|
readonly options: Options$3;
|
|
452
450
|
constructor(config: Config, options: Options$3);
|
|
451
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
452
|
+
get plugins(): Array<Plugin>;
|
|
453
453
|
getFile<TOptions = object>({
|
|
454
454
|
name,
|
|
455
455
|
mode,
|
|
@@ -459,7 +459,7 @@ declare class PluginManager {
|
|
|
459
459
|
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
460
460
|
pluginKey: Plugin['key'];
|
|
461
461
|
}>;
|
|
462
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.
|
|
462
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
463
463
|
resolveName: (params: ResolveNameParams) => string;
|
|
464
464
|
/**
|
|
465
465
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
@@ -547,11 +547,9 @@ declare class PluginManager {
|
|
|
547
547
|
}): Promise<void>;
|
|
548
548
|
getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
|
|
549
549
|
getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
|
|
550
|
-
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
551
|
-
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
552
550
|
}
|
|
553
551
|
//#endregion
|
|
554
|
-
//#region ../core/src/
|
|
552
|
+
//#region ../core/src/utils/getBarrelFiles.d.ts
|
|
555
553
|
type FileMetaBase = {
|
|
556
554
|
pluginKey?: Plugin['key'];
|
|
557
555
|
};
|
|
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
|
|
|
669
667
|
/**
|
|
670
668
|
* Full qualified path.
|
|
671
669
|
*/
|
|
672
|
-
path: KubbFile.
|
|
670
|
+
path: KubbFile.Path;
|
|
673
671
|
/**
|
|
674
672
|
* When true `File.Import` will be used.
|
|
675
673
|
* When false a reference will be used inside the current file.
|
|
@@ -774,6 +772,15 @@ type Schema = {
|
|
|
774
772
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
775
773
|
//#endregion
|
|
776
774
|
//#region ../plugin-oas/src/types.d.ts
|
|
775
|
+
type Context$2 = {
|
|
776
|
+
getOas(): Promise<Oas>;
|
|
777
|
+
getBaseURL(): Promise<string | undefined>;
|
|
778
|
+
};
|
|
779
|
+
declare global {
|
|
780
|
+
namespace Kubb {
|
|
781
|
+
interface PluginContext extends Context$2 {}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
777
784
|
type ResolvePathOptions = {
|
|
778
785
|
pluginKey?: Plugin['key'];
|
|
779
786
|
group?: {
|
|
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
|
|
|
794
801
|
type Ref = {
|
|
795
802
|
propertyName: string;
|
|
796
803
|
originalName: string;
|
|
797
|
-
path: KubbFile.
|
|
804
|
+
path: KubbFile.Path;
|
|
798
805
|
pluginKey?: Plugin['key'];
|
|
799
806
|
};
|
|
800
807
|
type Refs = Record<string, Ref>;
|
|
@@ -1270,4 +1277,4 @@ type ResolvedOptions = {
|
|
|
1270
1277
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1271
1278
|
//#endregion
|
|
1272
1279
|
export { ReactGenerator as a, Operation$1 as c, Transformer as i, Options$1 as n, OperationSchemas as o, PluginReactQuery as r, UserPluginWithLifeCycle as s, Infinite as t };
|
|
1273
|
-
//# sourceMappingURL=types-
|
|
1280
|
+
//# sourceMappingURL=types-CZA77t3-.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.2",
|
|
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",
|
|
@@ -67,18 +67,18 @@
|
|
|
67
67
|
}
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@kubb/react-fabric": "0.2.
|
|
70
|
+
"@kubb/react-fabric": "0.2.19",
|
|
71
71
|
"remeda": "^2.32.0",
|
|
72
|
-
"@kubb/core": "4.5.
|
|
73
|
-
"@kubb/oas": "4.5.
|
|
74
|
-
"@kubb/plugin-client": "4.5.
|
|
75
|
-
"@kubb/plugin-oas": "4.5.
|
|
76
|
-
"@kubb/plugin-ts": "4.5.
|
|
77
|
-
"@kubb/plugin-zod": "4.5.
|
|
72
|
+
"@kubb/core": "4.5.2",
|
|
73
|
+
"@kubb/oas": "4.5.2",
|
|
74
|
+
"@kubb/plugin-client": "4.5.2",
|
|
75
|
+
"@kubb/plugin-oas": "4.5.2",
|
|
76
|
+
"@kubb/plugin-ts": "4.5.2",
|
|
77
|
+
"@kubb/plugin-zod": "4.5.2"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@kubb/react-fabric": "0.2.
|
|
81
|
+
"@kubb/react-fabric": "0.2.19"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=20"
|
package/src/plugin.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
2
|
+
import { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
|
|
3
3
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
4
4
|
import { resolveModuleSource } from '@kubb/core/utils'
|
|
5
5
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
6
|
-
import type { PluginOas } from '@kubb/plugin-oas'
|
|
7
6
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
8
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
@@ -14,7 +13,7 @@ import type { PluginReactQuery } from './types.ts'
|
|
|
14
13
|
|
|
15
14
|
export const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']
|
|
16
15
|
|
|
17
|
-
export const pluginReactQuery =
|
|
16
|
+
export const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {
|
|
18
17
|
const {
|
|
19
18
|
output = { path: 'hooks', barrelType: 'named' },
|
|
20
19
|
group,
|
|
@@ -129,20 +128,18 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
129
128
|
|
|
130
129
|
return resolvedName
|
|
131
130
|
},
|
|
132
|
-
async
|
|
133
|
-
const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
|
|
134
|
-
|
|
135
|
-
const oas = await swaggerPlugin.context.getOas()
|
|
131
|
+
async install() {
|
|
136
132
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
137
133
|
const mode = getMode(path.resolve(root, output.path))
|
|
138
|
-
const
|
|
134
|
+
const oas = await this.getOas()
|
|
135
|
+
const baseURL = await this.getBaseURL()
|
|
139
136
|
|
|
140
137
|
if (baseURL) {
|
|
141
138
|
this.plugin.options.client.baseURL = baseURL
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])
|
|
145
|
-
const containsFetcher = this.
|
|
142
|
+
const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')
|
|
146
143
|
|
|
147
144
|
if (!hasClientPlugin && !this.plugin.options.client.importPath && !containsFetcher) {
|
|
148
145
|
// pre add bundled fetcher
|
|
@@ -175,7 +172,7 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
175
172
|
const files = await operationGenerator.build(...generators)
|
|
176
173
|
await this.addFile(...files)
|
|
177
174
|
|
|
178
|
-
const barrelFiles = await getBarrelFiles(this.
|
|
175
|
+
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
179
176
|
type: output.barrelType ?? 'named',
|
|
180
177
|
root,
|
|
181
178
|
output,
|