@kubb/plugin-client 5.0.0-alpha.33 → 5.0.0-alpha.35

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.
@@ -4,7 +4,7 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  const require_chunk = require("../chunk-ByKO4r7w.cjs");
6
6
  let axios = require("axios");
7
- axios = require_chunk.__toESM(axios);
7
+ axios = require_chunk.__toESM(axios, 1);
8
8
  //#region src/clients/axios.ts
9
9
  let _config = {
10
10
  baseURL: typeof AXIOS_BASE !== "undefined" ? AXIOS_BASE : void 0,
package/dist/index.cjs CHANGED
@@ -4,8 +4,8 @@ const require_templates_clients_axios_source = require("./templates/clients/axio
4
4
  const require_templates_clients_fetch_source = require("./templates/clients/fetch.source.cjs");
5
5
  const require_templates_config_source = require("./templates/config.source.cjs");
6
6
  let node_path = require("node:path");
7
+ let node_path$1 = require_chunk.__toESM(node_path, 1);
7
8
  node_path = require_chunk.__toESM(node_path);
8
- let _kubb_ast = require("@kubb/ast");
9
9
  let _kubb_core = require("@kubb/core");
10
10
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
11
11
  let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
@@ -320,11 +320,12 @@ function buildReturnStatement({ dataReturnType, parser, node, zodResolver }) {
320
320
  //#region src/components/Url.tsx
321
321
  const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
322
322
  function getParams$2({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
323
- return (0, _kubb_ast.createOperationParams)({
323
+ const urlNode = {
324
324
  ...node,
325
325
  parameters: node.parameters.filter((p) => p.in === "path"),
326
326
  requestBody: void 0
327
- }, {
327
+ };
328
+ return _kubb_core.ast.createOperationParams(urlNode, {
328
329
  paramsType: paramsType === "object" ? "object" : "inline",
329
330
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
330
331
  paramsCasing,
@@ -343,7 +344,7 @@ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsTyp
343
344
  });
344
345
  const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
345
346
  const originalPathParams = node.parameters.filter((p) => p.in === "path");
346
- const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
347
+ const casedPathParams = _kubb_core.ast.caseParams(originalPathParams, paramsCasing);
347
348
  const pathParamsMapping = paramsCasing ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
348
349
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
349
350
  name,
@@ -372,14 +373,14 @@ Url.getParams = getParams$2;
372
373
  const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
373
374
  function getParams$1({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
374
375
  const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
375
- return (0, _kubb_ast.createOperationParams)(node, {
376
+ return _kubb_core.ast.createOperationParams(node, {
376
377
  paramsType,
377
378
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
378
379
  paramsCasing,
379
380
  resolver: tsResolver,
380
- extraParams: isConfigurable ? [(0, _kubb_ast.createFunctionParameter)({
381
+ extraParams: isConfigurable ? [_kubb_core.ast.createFunctionParameter({
381
382
  name: "config",
382
- type: (0, _kubb_ast.createParamsType)({
383
+ type: _kubb_core.ast.createParamsType({
383
384
  variant: "reference",
384
385
  name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
385
386
  }),
@@ -393,11 +394,11 @@ function Client({ name, isExportable = true, isIndexable = true, returnType, bas
393
394
  const contentType = node.requestBody?.contentType ?? "application/json";
394
395
  const isFormData = contentType === "multipart/form-data";
395
396
  const originalPathParams = node.parameters.filter((p) => p.in === "path");
396
- const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
397
+ const casedPathParams = _kubb_core.ast.caseParams(originalPathParams, paramsCasing);
397
398
  const originalQueryParams = node.parameters.filter((p) => p.in === "query");
398
- const casedQueryParams = (0, _kubb_ast.caseParams)(originalQueryParams, paramsCasing);
399
+ const casedQueryParams = _kubb_core.ast.caseParams(originalQueryParams, paramsCasing);
399
400
  const originalHeaderParams = node.parameters.filter((p) => p.in === "header");
400
- const casedHeaderParams = (0, _kubb_ast.caseParams)(originalHeaderParams, paramsCasing);
401
+ const casedHeaderParams = _kubb_core.ast.caseParams(originalHeaderParams, paramsCasing);
401
402
  const pathParamsMapping = paramsCasing && !urlName ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
402
403
  const queryParamsMapping = paramsCasing ? buildParamsMapping(originalQueryParams, casedQueryParams) : void 0;
403
404
  const headerParamsMapping = paramsCasing ? buildParamsMapping(originalHeaderParams, casedHeaderParams) : void 0;
@@ -868,10 +869,11 @@ function resolveZodImportNames$1(node, zodResolver) {
868
869
  require_chunk.__name(resolveZodImportNames$1, "resolveZodImportNames");
869
870
  const classClientGenerator = (0, _kubb_core.defineGenerator)({
870
871
  name: "classClient",
871
- operations(nodes, options) {
872
- const { adapter, config, driver, resolver, root } = this;
873
- const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options;
874
- const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL;
872
+ renderer: _kubb_renderer_jsx.jsxRenderer,
873
+ operations(nodes, ctx) {
874
+ const { adapter, config, driver, resolver, root } = ctx;
875
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = ctx.options;
876
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
875
877
  const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
876
878
  if (!pluginTs?.resolver) return null;
877
879
  const tsResolver = pluginTs.resolver;
@@ -1138,16 +1140,17 @@ const classClientGenerator = (0, _kubb_core.defineGenerator)({
1138
1140
  //#region src/generators/clientGenerator.tsx
1139
1141
  const clientGenerator = (0, _kubb_core.defineGenerator)({
1140
1142
  name: "client",
1141
- operation(node, options) {
1142
- const { adapter, config, driver, resolver, root } = this;
1143
- const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options;
1144
- const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1143
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1144
+ operation(node, ctx) {
1145
+ const { adapter, config, driver, resolver, root } = ctx;
1146
+ const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = ctx.options;
1147
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1145
1148
  const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1146
1149
  if (!pluginTs?.resolver) return null;
1147
1150
  const tsResolver = pluginTs.resolver;
1148
1151
  const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1149
1152
  const zodResolver = pluginZod?.resolver;
1150
- const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
1153
+ const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
1151
1154
  const pathParams = casedParams.filter((p) => p.in === "path");
1152
1155
  const queryParams = casedParams.filter((p) => p.in === "query");
1153
1156
  const headerParams = casedParams.filter((p) => p.in === "header");
@@ -1281,9 +1284,10 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
1281
1284
  //#region src/generators/groupedClientGenerator.tsx
1282
1285
  const groupedClientGenerator = (0, _kubb_core.defineGenerator)({
1283
1286
  name: "groupedClient",
1284
- operations(nodes, options) {
1285
- const { config, resolver, adapter, root } = this;
1286
- const { output, group } = options;
1287
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1288
+ operations(nodes, ctx) {
1289
+ const { config, resolver, adapter, root } = ctx;
1290
+ const { output, group } = ctx.options;
1287
1291
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: nodes.reduce((acc, operationNode) => {
1288
1292
  if (group?.type === "tag") {
1289
1293
  const tag = operationNode.tags[0];
@@ -1377,9 +1381,10 @@ function Operations({ name, nodes }) {
1377
1381
  //#region src/generators/operationsGenerator.tsx
1378
1382
  const operationsGenerator = (0, _kubb_core.defineGenerator)({
1379
1383
  name: "client",
1380
- operations(nodes, options) {
1381
- const { config, resolver, adapter, root } = this;
1382
- const { output, group } = options;
1384
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1385
+ operations(nodes, ctx) {
1386
+ const { config, resolver, adapter, root } = ctx;
1387
+ const { output, group } = ctx.options;
1383
1388
  const name = "operations";
1384
1389
  const file = resolver.resolveFile({
1385
1390
  name,
@@ -1494,10 +1499,11 @@ function resolveZodImportNames(node, zodResolver) {
1494
1499
  }
1495
1500
  const staticClassClientGenerator = (0, _kubb_core.defineGenerator)({
1496
1501
  name: "staticClassClient",
1497
- operations(nodes, options) {
1498
- const { adapter, config, driver, resolver, root } = this;
1499
- const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options;
1500
- const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1502
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1503
+ operations(nodes, ctx) {
1504
+ const { adapter, config, driver, resolver, root } = ctx;
1505
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = ctx.options;
1506
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1501
1507
  const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1502
1508
  if (!pluginTs?.resolver) return null;
1503
1509
  const tsResolver = pluginTs.resolver;
@@ -1716,9 +1722,6 @@ const staticClassClientGenerator = (0, _kubb_core.defineGenerator)({
1716
1722
  }
1717
1723
  });
1718
1724
  //#endregion
1719
- //#region package.json
1720
- var version = "5.0.0-alpha.33";
1721
- //#endregion
1722
1725
  //#region src/resolvers/resolverClient.ts
1723
1726
  /**
1724
1727
  * Resolver for `@kubb/plugin-client` that provides the default naming
@@ -1767,28 +1770,6 @@ const resolverClientLegacy = (0, _kubb_core.defineResolver)(() => ({
1767
1770
  }
1768
1771
  }));
1769
1772
  //#endregion
1770
- //#region src/presets.ts
1771
- /**
1772
- * Built-in preset registry for `@kubb/plugin-client`.
1773
- *
1774
- * - `default` — uses `resolverClient` with v5 naming conventions.
1775
- * - `kubbV4` — uses `resolverClientLegacy` with backward-compatible naming.
1776
- *
1777
- * Note: Unlike plugin-ts/plugin-zod, generators are not defined here because
1778
- * plugin-client selects generators dynamically based on `clientType`, `group`,
1779
- * and `operations` options. Generator selection happens in `plugin.ts`.
1780
- */
1781
- const presets = (0, _kubb_core.definePresets)({
1782
- default: {
1783
- name: "default",
1784
- resolver: resolverClient
1785
- },
1786
- kubbV4: {
1787
- name: "kubbV4",
1788
- resolver: resolverClientLegacy
1789
- }
1790
- });
1791
- //#endregion
1792
1773
  //#region src/plugin.ts
1793
1774
  /**
1794
1775
  * Canonical plugin name for `@kubb/plugin-client`, used to identify the plugin
@@ -1811,37 +1792,35 @@ const pluginClientName = "plugin-client";
1811
1792
  * })
1812
1793
  * ```
1813
1794
  */
1814
- const pluginClient = (0, _kubb_core.createPlugin)((options) => {
1795
+ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
1815
1796
  const { output = {
1816
1797
  path: "clients",
1817
1798
  barrelType: "named"
1818
- }, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, bundle = false, wrapper, baseURL, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer } = options;
1799
+ }, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, bundle = false, wrapper, baseURL, resolver: userResolver, transformer: userTransformer, compatibilityPreset = "default" } = options;
1800
+ const defaultResolver = compatibilityPreset === "kubbV4" ? resolverClientLegacy : resolverClient;
1819
1801
  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
1820
- const preset = (0, _kubb_core.getPreset)({
1821
- preset: compatibilityPreset,
1822
- presets,
1823
- resolver: userResolver,
1824
- transformer: userTransformer,
1825
- generators: options.generators ?? [
1826
- clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
1827
- group && clientType === "function" ? groupedClientGenerator : void 0,
1828
- operations ? operationsGenerator : void 0
1829
- ].filter((x) => Boolean(x))
1830
- });
1831
- const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
1832
- let resolveNameWarning = false;
1833
- let resolvePathWarning = false;
1802
+ const selectedGenerators = options.generators ?? [
1803
+ clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
1804
+ group && clientType === "function" ? groupedClientGenerator : void 0,
1805
+ operations ? operationsGenerator : void 0
1806
+ ].filter((x) => Boolean(x));
1807
+ const groupConfig = group ? {
1808
+ ...group,
1809
+ name: group.name ? group.name : (ctx) => {
1810
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1811
+ return `${camelCase(ctx.group)}Controller`;
1812
+ }
1813
+ } : void 0;
1834
1814
  return {
1835
1815
  name: pluginClientName,
1836
- version,
1837
- get resolver() {
1838
- return preset.resolver;
1839
- },
1840
- get transformer() {
1841
- return preset.transformer;
1842
- },
1843
- get options() {
1844
- return {
1816
+ options,
1817
+ dependencies: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
1818
+ hooks: { "kubb:plugin:setup"(ctx) {
1819
+ const resolver = userResolver ? {
1820
+ ...defaultResolver,
1821
+ ...userResolver
1822
+ } : defaultResolver;
1823
+ ctx.setOptions({
1845
1824
  client,
1846
1825
  clientType,
1847
1826
  bundle,
@@ -1849,13 +1828,7 @@ const pluginClient = (0, _kubb_core.createPlugin)((options) => {
1849
1828
  exclude,
1850
1829
  include,
1851
1830
  override,
1852
- group: group ? {
1853
- ...group,
1854
- name: group.name ? group.name : (ctx) => {
1855
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1856
- return `${camelCase(ctx.group)}Controller`;
1857
- }
1858
- } : void 0,
1831
+ group: groupConfig,
1859
1832
  parser,
1860
1833
  dataReturnType,
1861
1834
  importPath: resolvedImportPath,
@@ -1865,63 +1838,33 @@ const pluginClient = (0, _kubb_core.createPlugin)((options) => {
1865
1838
  pathParamsType,
1866
1839
  urlType,
1867
1840
  wrapper,
1868
- resolver: preset.resolver
1869
- };
1870
- },
1871
- pre: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
1872
- resolvePath(baseName, pathMode, options) {
1873
- if (!resolvePathWarning) {
1874
- this.warn("Do not use resolvePath for pluginClient, use resolverClient.resolvePath instead");
1875
- resolvePathWarning = true;
1876
- }
1877
- return this.plugin.resolver.resolvePath({
1878
- baseName,
1879
- pathMode,
1880
- tag: options?.group?.tag,
1881
- path: options?.group?.path
1882
- }, {
1883
- root: this.root,
1884
- output,
1885
- group: this.plugin.options.group
1841
+ resolver
1886
1842
  });
1887
- },
1888
- resolveName(name, type) {
1889
- if (!resolveNameWarning) {
1890
- this.warn("Do not use resolveName for pluginClient, use resolverClient.default instead");
1891
- resolveNameWarning = true;
1892
- }
1893
- return this.plugin.resolver.default(name, type);
1894
- },
1895
- async operation(node, options) {
1896
- return mergedGenerator.operation?.call(this, node, options);
1897
- },
1898
- async operations(nodes, options) {
1899
- return mergedGenerator.operations?.call(this, nodes, options);
1900
- },
1901
- async buildStart() {
1902
- const { plugin } = this;
1903
- const root = this.root;
1904
- if (bundle && !plugin.options.importPath) await this.addFile((0, _kubb_ast.createFile)({
1843
+ ctx.setResolver(resolver);
1844
+ if (userTransformer) ctx.setTransformer(userTransformer);
1845
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
1846
+ const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
1847
+ if (bundle && !resolvedImportPath) ctx.injectFile({
1905
1848
  baseName: "fetch.ts",
1906
- path: node_path.default.resolve(root, ".kubb/fetch.ts"),
1907
- sources: [(0, _kubb_ast.createSource)({
1849
+ path: node_path$1.default.resolve(root, ".kubb/fetch.ts"),
1850
+ sources: [_kubb_core.ast.createSource({
1908
1851
  name: "fetch",
1909
- nodes: [(0, _kubb_ast.createText)(plugin.options.client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source)],
1852
+ nodes: [_kubb_core.ast.createText(client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source)],
1910
1853
  isExportable: true,
1911
1854
  isIndexable: true
1912
1855
  })]
1913
- }));
1914
- await this.addFile((0, _kubb_ast.createFile)({
1856
+ });
1857
+ ctx.injectFile({
1915
1858
  baseName: "config.ts",
1916
- path: node_path.default.resolve(root, ".kubb/config.ts"),
1917
- sources: [(0, _kubb_ast.createSource)({
1859
+ path: node_path$1.default.resolve(root, ".kubb/config.ts"),
1860
+ sources: [_kubb_core.ast.createSource({
1918
1861
  name: "config",
1919
- nodes: [(0, _kubb_ast.createText)(require_templates_config_source.source)],
1862
+ nodes: [_kubb_core.ast.createText(require_templates_config_source.source)],
1920
1863
  isExportable: false,
1921
1864
  isIndexable: false
1922
1865
  })]
1923
- }));
1924
- }
1866
+ });
1867
+ } }
1925
1868
  };
1926
1869
  });
1927
1870
  //#endregion
@@ -1934,7 +1877,6 @@ exports.groupedClientGenerator = groupedClientGenerator;
1934
1877
  exports.operationsGenerator = operationsGenerator;
1935
1878
  exports.pluginClient = pluginClient;
1936
1879
  exports.pluginClientName = pluginClientName;
1937
- exports.presets = presets;
1938
1880
  exports.resolverClient = resolverClient;
1939
1881
  exports.resolverClientLegacy = resolverClientLegacy;
1940
1882
  exports.staticClassClientGenerator = staticClassClientGenerator;