@kubb/agent 4.34.0 → 4.35.0

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.
@@ -20,12 +20,13 @@ import { createFabric, createReactFabric, App, File, Function as Function$1, Con
20
20
  import { typescriptParser } from '@kubb/react-fabric/parsers';
21
21
  import { fsPlugin } from '@kubb/react-fabric/plugins';
22
22
  import { performance as performance$1 } from 'node:perf_hooks';
23
+ import { deflateSync } from 'fflate';
24
+ import { x } from 'tinyexec';
23
25
  import os$1 from 'node:os';
24
26
  import { pathToFileURL, fileURLToPath } from 'node:url';
25
27
  import * as pkg from 'empathic/package';
26
28
  import { coerce, satisfies } from 'semver';
27
29
  import { sortBy, isFunction, mergeDeep, isPlainObject as isPlainObject$1, uniqueWith, isDeepEqual, isNumber, difference } from 'remeda';
28
- import { x } from 'tinyexec';
29
30
  import { createJiti } from 'jiti';
30
31
  import jsonpointer from 'jsonpointer';
31
32
  import BaseOas from 'oas';
@@ -4649,7 +4650,7 @@ async function disconnect({ sessionId, token, studioUrl }) {
4649
4650
  }
4650
4651
  }
4651
4652
 
4652
- var version = "4.34.0";
4653
+ var version = "4.35.0";
4653
4654
 
4654
4655
  function isCommandMessage(msg) {
4655
4656
  return msg.type === "command";
@@ -4682,6 +4683,103 @@ async function getLatestStudioConfigFromStorage({ sessionId }) {
4682
4683
  return existing[existing.length - 1].config;
4683
4684
  }
4684
4685
 
4686
+ const visitorDepths = {
4687
+ deep: "deep"
4688
+ };
4689
+ function createLimit(concurrency) {
4690
+ let active = 0;
4691
+ const queue = [];
4692
+ function next() {
4693
+ if (active < concurrency && queue.length > 0) {
4694
+ active++;
4695
+ queue.shift()();
4696
+ }
4697
+ }
4698
+ return function limit(fn) {
4699
+ return new Promise((resolve, reject) => {
4700
+ queue.push(() => {
4701
+ Promise.resolve(fn()).then(resolve, reject).finally(() => {
4702
+ active--;
4703
+ next();
4704
+ });
4705
+ });
4706
+ next();
4707
+ });
4708
+ };
4709
+ }
4710
+ function getChildren(node, recurse) {
4711
+ switch (node.kind) {
4712
+ case "Root":
4713
+ return [...node.schemas, ...node.operations];
4714
+ case "Operation":
4715
+ return [
4716
+ ...node.parameters,
4717
+ ...node.requestBody ? [node.requestBody] : [],
4718
+ ...node.responses
4719
+ ];
4720
+ case "Schema": {
4721
+ const children = [];
4722
+ if (!recurse) return [];
4723
+ if ("properties" in node && node.properties) children.push(...node.properties);
4724
+ if ("items" in node && node.items) children.push(...node.items);
4725
+ if ("members" in node && node.members) children.push(...node.members);
4726
+ return children;
4727
+ }
4728
+ case "Property":
4729
+ return [node.schema];
4730
+ case "Parameter":
4731
+ return [node.schema];
4732
+ case "Response":
4733
+ return node.schema ? [node.schema] : [];
4734
+ }
4735
+ }
4736
+ async function walk(node, visitor, options = {}) {
4737
+ var _a, _b;
4738
+ return _walk(node, visitor, ((_a = options.depth) != null ? _a : visitorDepths.deep) === visitorDepths.deep, createLimit((_b = options.concurrency) != null ? _b : 30));
4739
+ }
4740
+ async function _walk(node, visitor, recurse, limit) {
4741
+ switch (node.kind) {
4742
+ case "Root":
4743
+ await limit(() => {
4744
+ var _a;
4745
+ return (_a = visitor.root) == null ? void 0 : _a.call(visitor, node);
4746
+ });
4747
+ break;
4748
+ case "Operation":
4749
+ await limit(() => {
4750
+ var _a;
4751
+ return (_a = visitor.operation) == null ? void 0 : _a.call(visitor, node);
4752
+ });
4753
+ break;
4754
+ case "Schema":
4755
+ await limit(() => {
4756
+ var _a;
4757
+ return (_a = visitor.schema) == null ? void 0 : _a.call(visitor, node);
4758
+ });
4759
+ break;
4760
+ case "Property":
4761
+ await limit(() => {
4762
+ var _a;
4763
+ return (_a = visitor.property) == null ? void 0 : _a.call(visitor, node);
4764
+ });
4765
+ break;
4766
+ case "Parameter":
4767
+ await limit(() => {
4768
+ var _a;
4769
+ return (_a = visitor.parameter) == null ? void 0 : _a.call(visitor, node);
4770
+ });
4771
+ break;
4772
+ case "Response":
4773
+ await limit(() => {
4774
+ var _a;
4775
+ return (_a = visitor.response) == null ? void 0 : _a.call(visitor, node);
4776
+ });
4777
+ break;
4778
+ }
4779
+ const children = getChildren(node, recurse);
4780
+ await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit)));
4781
+ }
4782
+
4685
4783
  var __defProp$h = Object.defineProperty;
4686
4784
  var __typeError$c = (msg) => {
4687
4785
  throw TypeError(msg);
@@ -4701,7 +4799,7 @@ var __privateWrapper$1 = (obj, member, setter, getter) => ({
4701
4799
  return __privateGet$c(obj, member, getter);
4702
4800
  }
4703
4801
  });
4704
- var _emitter, _a$c, _options$c, _URLPath_instances$a, transformParam_fn$a, eachParam_fn$a, _b$2, _head$1, _tail$1, _size$1, _c, _options2$1, _d, _plugins, _usedPluginNames, _promiseManager, _PluginManager_instances, getSortedPlugins_fn, emitProcessingEnd_fn, execute_fn, executeSync_fn, parse_fn, _e, _f, _cache, _cwd, _PackageManager_instances, match_fn, _items, _FunctionParams_static, _g, orderItems_fn, addParams_fn, _cachedLeaves, _h;
4802
+ var _emitter, _a$c, _options$c, _URLPath_instances$a, transformParam_fn$a, eachParam_fn$a, _b$2, _head$1, _tail$1, _size$1, _c, _options2$1, _d, _studioIsOpen, _plugins, _usedPluginNames, _promiseManager, _PluginManager_instances, getSortedPlugins_fn, emitProcessingEnd_fn, execute_fn, executeSync_fn, parse_fn, _e, _f, _cache, _cwd, _PackageManager_instances, match_fn, _items, _FunctionParams_static, _g, orderItems_fn, addParams_fn, _cachedLeaves, _h;
4705
4803
  var ValidationPluginError = class extends Error {
4706
4804
  };
4707
4805
  function toError(value) {
@@ -5059,6 +5157,7 @@ eachParam_fn$a = function(fn) {
5059
5157
  function isInputPath(config) {
5060
5158
  return typeof (config == null ? void 0 : config.input) === "object" && config.input !== null && "path" in config.input;
5061
5159
  }
5160
+ const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
5062
5161
  const BARREL_FILENAME = "index.ts";
5063
5162
  const DEFAULT_BANNER = "simple";
5064
5163
  const DEFAULT_EXTENSION = { ".ts": ".ts" };
@@ -5109,6 +5208,30 @@ const formatters = {
5109
5208
  errorMessage: "Oxfmt not found"
5110
5209
  }
5111
5210
  };
5211
+ function encodeAst(root) {
5212
+ const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(root)));
5213
+ return Buffer.from(compressed).toString("base64url");
5214
+ }
5215
+ function getStudioUrl(root, studioUrl, options = {}) {
5216
+ return `${studioUrl.replace(/\/$/, "")}${options.ast ? "/ast" : ""}?root=${encodeAst(root)}`;
5217
+ }
5218
+ async function openInStudio(root, studioUrl, options = {}) {
5219
+ const url = getStudioUrl(root, studioUrl, options);
5220
+ const cmd = process.platform === "win32" ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open";
5221
+ const args = process.platform === "win32" ? [
5222
+ "/c",
5223
+ "start",
5224
+ "",
5225
+ url
5226
+ ] : [url];
5227
+ try {
5228
+ await x(cmd, args);
5229
+ } catch {
5230
+ console.log(`
5231
+ ${url}
5232
+ `);
5233
+ }
5234
+ }
5112
5235
  var Node$1 = class Node {
5113
5236
  constructor(value) {
5114
5237
  __publicField$b(this, "value");
@@ -5280,6 +5403,12 @@ var PluginManager = (_e = class {
5280
5403
  __privateAdd$c(this, _PluginManager_instances);
5281
5404
  __publicField$b(this, "config");
5282
5405
  __publicField$b(this, "options");
5406
+ /**
5407
+ * The universal `@kubb/ast` `RootNode` produced by the adapter, set by
5408
+ * the build pipeline after the adapter's `parse()` resolves.
5409
+ */
5410
+ __publicField$b(this, "rootNode");
5411
+ __privateAdd$c(this, _studioIsOpen, false);
5283
5412
  __privateAdd$c(this, _plugins, /* @__PURE__ */ new Set());
5284
5413
  __privateAdd$c(this, _usedPluginNames, {});
5285
5414
  __privateAdd$c(this, _promiseManager);
@@ -5334,6 +5463,7 @@ var PluginManager = (_e = class {
5334
5463
  }
5335
5464
  getContext(plugin) {
5336
5465
  const plugins = [...__privateGet$c(this, _plugins)];
5466
+ const pluginManager = this;
5337
5467
  const baseContext = {
5338
5468
  fabric: this.options.fabric,
5339
5469
  config: this.config,
@@ -5346,6 +5476,18 @@ var PluginManager = (_e = class {
5346
5476
  },
5347
5477
  upsertFile: async (...files) => {
5348
5478
  await this.options.fabric.upsertFile(...files);
5479
+ },
5480
+ get rootNode() {
5481
+ return pluginManager.rootNode;
5482
+ },
5483
+ openInStudio(options) {
5484
+ var _a2, _b2;
5485
+ if (typeof pluginManager.config.devtools !== "object") throw new Error("Devtools must be an object");
5486
+ if (!pluginManager.rootNode) throw new Error("RootNode is not defined, make sure you have set the parser in kubb.config.ts");
5487
+ if (__privateGet$c(pluginManager, _studioIsOpen)) return;
5488
+ __privateSet$c(pluginManager, _studioIsOpen, true);
5489
+ const studioUrl = (_b2 = (_a2 = pluginManager.config.devtools) == null ? void 0 : _a2.studioUrl) != null ? _b2 : "https://studio.kubb.dev";
5490
+ return openInStudio(pluginManager.rootNode, studioUrl, options);
5349
5491
  }
5350
5492
  };
5351
5493
  const mergedExtras = {};
@@ -5553,7 +5695,7 @@ var PluginManager = (_e = class {
5553
5695
  }
5554
5696
  return pluginByPluginName;
5555
5697
  }
5556
- }, _plugins = new WeakMap(), _usedPluginNames = new WeakMap(), _promiseManager = new WeakMap(), _PluginManager_instances = new WeakSet(), getSortedPlugins_fn = function(hookName) {
5698
+ }, _studioIsOpen = new WeakMap(), _plugins = new WeakMap(), _usedPluginNames = new WeakMap(), _promiseManager = new WeakMap(), _PluginManager_instances = new WeakSet(), getSortedPlugins_fn = function(hookName) {
5557
5699
  const plugins = [...__privateGet$c(this, _plugins)];
5558
5700
  if (hookName) return plugins.filter((plugin) => hookName in plugin);
5559
5701
  return plugins.map((plugin) => {
@@ -5663,7 +5805,7 @@ executeSync_fn = function({ strategy, hookName, parameters, plugin }) {
5663
5805
  key: [plugin.name, usedPluginNames[plugin.name]].filter(Boolean)
5664
5806
  };
5665
5807
  }, _e);
5666
- var version$1 = "4.34.0";
5808
+ var version$1 = "4.35.0";
5667
5809
  function getDiagnosticInfo() {
5668
5810
  return {
5669
5811
  nodeVersion: version$2,
@@ -5719,6 +5861,10 @@ async function setup(options) {
5719
5861
  defaultBanner: DEFAULT_BANNER,
5720
5862
  ...userConfig.output
5721
5863
  },
5864
+ devtools: userConfig.devtools ? {
5865
+ studioUrl: DEFAULT_STUDIO_URL,
5866
+ ...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
5867
+ } : void 0,
5722
5868
  plugins: userConfig.plugins
5723
5869
  };
5724
5870
  if (definedConfig.output.clean) {
@@ -5765,14 +5911,31 @@ async function setup(options) {
5765
5911
  ` \u2022 Barrel type: ${definedConfig.output.barrelType || "none"}`
5766
5912
  ]
5767
5913
  });
5914
+ const pluginManager = new PluginManager(definedConfig, {
5915
+ fabric,
5916
+ events,
5917
+ concurrency: 15
5918
+ });
5919
+ if (definedConfig.adapter) {
5920
+ const source = inputToAdapterSource(definedConfig);
5921
+ await events.emit("debug", {
5922
+ date: /* @__PURE__ */ new Date(),
5923
+ logs: [`Running adapter: ${definedConfig.adapter.name}`]
5924
+ });
5925
+ pluginManager.rootNode = await definedConfig.adapter.parse(source);
5926
+ await events.emit("debug", {
5927
+ date: /* @__PURE__ */ new Date(),
5928
+ logs: [
5929
+ `\u2713 Adapter '${definedConfig.adapter.name}' resolved RootNode`,
5930
+ ` \u2022 Schemas: ${pluginManager.rootNode.schemas.length}`,
5931
+ ` \u2022 Operations: ${pluginManager.rootNode.operations.length}`
5932
+ ]
5933
+ });
5934
+ }
5768
5935
  return {
5769
5936
  events,
5770
5937
  fabric,
5771
- pluginManager: new PluginManager(definedConfig, {
5772
- fabric,
5773
- events,
5774
- concurrency: 15
5775
- }),
5938
+ pluginManager,
5776
5939
  sources
5777
5940
  };
5778
5941
  }
@@ -5913,6 +6076,20 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
5913
6076
  });
5914
6077
  });
5915
6078
  }
6079
+ function inputToAdapterSource(config) {
6080
+ if (Array.isArray(config.input)) return {
6081
+ type: "paths",
6082
+ paths: config.input.map((i) => resolve(config.root, i.path))
6083
+ };
6084
+ if ("data" in config.input) return {
6085
+ type: "data",
6086
+ data: config.input.data
6087
+ };
6088
+ return {
6089
+ type: "path",
6090
+ path: resolve(config.root, config.input.path)
6091
+ };
6092
+ }
5916
6093
  function definePlugin(build2) {
5917
6094
  return (options) => build2(options != null ? options : {});
5918
6095
  }
@@ -7498,66 +7675,120 @@ function getSchemaFactory(oas) {
7498
7675
  };
7499
7676
  };
7500
7677
  }
7501
- async function buildOperations(operations, { config, fabric, plugin, generator, Component }) {
7502
- if (!Component) return;
7503
- const { pluginManager, oas, mode } = generator.context;
7678
+ function isBuildOperationsV1Options(options) {
7679
+ var _a2;
7680
+ return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7681
+ }
7682
+ async function buildOperations(operationsOrNodes, options) {
7683
+ const { config, fabric, plugin } = options;
7684
+ if (!options.Component) return;
7504
7685
  const fabricChild = createReactFabric();
7505
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
7506
- meta: {
7507
- pluginManager,
7508
- plugin,
7509
- mode,
7510
- oas
7511
- },
7512
- children: /* @__PURE__ */ jsx(Component, {
7513
- config,
7514
- operations,
7515
- generator,
7516
- plugin
7517
- })
7518
- }));
7686
+ if (isBuildOperationsV1Options(options)) {
7687
+ const { generator, Component } = options;
7688
+ const { pluginManager, oas, mode } = generator.context;
7689
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7690
+ meta: {
7691
+ pluginManager,
7692
+ plugin,
7693
+ mode,
7694
+ oas
7695
+ },
7696
+ children: /* @__PURE__ */ jsx(Component, {
7697
+ config,
7698
+ operations: operationsOrNodes,
7699
+ generator,
7700
+ plugin
7701
+ })
7702
+ }));
7703
+ } else {
7704
+ const { Component } = options;
7705
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7706
+ meta: { plugin },
7707
+ children: /* @__PURE__ */ jsx(Component, {
7708
+ config,
7709
+ nodes: operationsOrNodes,
7710
+ plugin
7711
+ })
7712
+ }));
7713
+ }
7519
7714
  await fabric.context.fileManager.upsert(...fabricChild.files);
7520
7715
  fabricChild.unmount();
7521
7716
  }
7522
- async function buildOperation(operation, { config, fabric, plugin, generator, Component }) {
7523
- if (!Component) return;
7524
- const { pluginManager, oas, mode } = generator.context;
7717
+ function isBuildOperationV1Options(options) {
7718
+ var _a2;
7719
+ return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7720
+ }
7721
+ async function buildOperation(operationOrNode, options) {
7722
+ const { config, fabric, plugin } = options;
7723
+ if (!options.Component) return;
7525
7724
  const fabricChild = createReactFabric();
7526
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
7527
- meta: {
7528
- pluginManager,
7529
- plugin,
7530
- mode,
7531
- oas
7532
- },
7533
- children: /* @__PURE__ */ jsx(Component, {
7534
- config,
7535
- operation,
7536
- plugin,
7537
- generator
7538
- })
7539
- }));
7725
+ if (isBuildOperationV1Options(options)) {
7726
+ const { generator, Component } = options;
7727
+ const { pluginManager, oas, mode } = generator.context;
7728
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7729
+ meta: {
7730
+ pluginManager,
7731
+ plugin,
7732
+ mode,
7733
+ oas
7734
+ },
7735
+ children: /* @__PURE__ */ jsx(Component, {
7736
+ config,
7737
+ operation: operationOrNode,
7738
+ plugin,
7739
+ generator
7740
+ })
7741
+ }));
7742
+ } else {
7743
+ const { Component } = options;
7744
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7745
+ meta: { plugin },
7746
+ children: /* @__PURE__ */ jsx(Component, {
7747
+ config,
7748
+ node: operationOrNode,
7749
+ plugin
7750
+ })
7751
+ }));
7752
+ }
7540
7753
  await fabric.context.fileManager.upsert(...fabricChild.files);
7541
7754
  fabricChild.unmount();
7542
7755
  }
7543
- async function buildSchema(schema, { config, fabric, plugin, Component, generator }) {
7544
- if (!Component) return;
7545
- const { pluginManager, oas, mode } = generator.context;
7756
+ function isBuildSchemaV1Options(options) {
7757
+ var _a2;
7758
+ return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7759
+ }
7760
+ async function buildSchema(schema, options) {
7761
+ const { config, fabric, plugin } = options;
7762
+ if (!options.Component) return;
7546
7763
  const fabricChild = createReactFabric();
7547
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
7548
- meta: {
7549
- pluginManager,
7550
- plugin,
7551
- mode,
7552
- oas
7553
- },
7554
- children: /* @__PURE__ */ jsx(Component, {
7555
- config,
7556
- schema,
7557
- plugin,
7558
- generator
7559
- })
7560
- }));
7764
+ if (isBuildSchemaV1Options(options)) {
7765
+ const { generator, Component } = options;
7766
+ const { pluginManager, oas, mode } = generator.context;
7767
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7768
+ meta: {
7769
+ pluginManager,
7770
+ plugin,
7771
+ mode,
7772
+ oas
7773
+ },
7774
+ children: /* @__PURE__ */ jsx(Component, {
7775
+ config,
7776
+ schema,
7777
+ plugin,
7778
+ generator
7779
+ })
7780
+ }));
7781
+ } else {
7782
+ const { Component } = options;
7783
+ await fabricChild.render(/* @__PURE__ */ jsx(App, {
7784
+ meta: { plugin },
7785
+ children: /* @__PURE__ */ jsx(Component, {
7786
+ config,
7787
+ node: schema,
7788
+ plugin
7789
+ })
7790
+ }));
7791
+ }
7561
7792
  await fabric.context.fileManager.upsert(...fabricChild.files);
7562
7793
  fabricChild.unmount();
7563
7794
  }
@@ -8484,6 +8715,8 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
8484
8715
  const generatorLimit = pLimit(GENERATOR_CONCURRENCY);
8485
8716
  const schemaLimit = pLimit(SCHEMA_CONCURRENCY);
8486
8717
  const writeTasks = generators.map((generator) => generatorLimit(async () => {
8718
+ if (generator.version === "2") return [];
8719
+ const v1Generator = generator;
8487
8720
  const schemaTasks = schemaEntries.map(([name, schemaObject]) => schemaLimit(async () => {
8488
8721
  var _a2, _b2;
8489
8722
  const options = __privateMethod$a(this, _SchemaGenerator_instances, getOptions_fn).call(this, name);
@@ -8493,7 +8726,7 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
8493
8726
  parentName: null,
8494
8727
  rootName: name
8495
8728
  });
8496
- if (generator.type === "react") {
8729
+ if (v1Generator.type === "react") {
8497
8730
  await buildSchema({
8498
8731
  name,
8499
8732
  value: schemaObject,
@@ -8501,7 +8734,7 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
8501
8734
  }, {
8502
8735
  config: this.context.pluginManager.config,
8503
8736
  fabric: this.context.fabric,
8504
- Component: generator.Schema,
8737
+ Component: v1Generator.Schema,
8505
8738
  generator: this,
8506
8739
  plugin: {
8507
8740
  ...this.context.plugin,
@@ -8513,7 +8746,7 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
8513
8746
  });
8514
8747
  return [];
8515
8748
  }
8516
- return (_b2 = await ((_a2 = generator.schema) == null ? void 0 : _a2.call(generator, {
8749
+ return (_b2 = await ((_a2 = v1Generator.schema) == null ? void 0 : _a2.call(v1Generator, {
8517
8750
  config: this.context.pluginManager.config,
8518
8751
  generator: this,
8519
8752
  schema: {
@@ -9365,8 +9598,10 @@ ${operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) => g
9365
9598
  StaticClassClient.getParams = Client.getParams;
9366
9599
 
9367
9600
  function createGenerator(generator) {
9601
+ var _a;
9368
9602
  return {
9369
9603
  type: "core",
9604
+ version: (_a = generator.version) != null ? _a : "1",
9370
9605
  async operations() {
9371
9606
  return [];
9372
9607
  },
@@ -9380,8 +9615,10 @@ function createGenerator(generator) {
9380
9615
  };
9381
9616
  }
9382
9617
  function createReactGenerator(generator) {
9618
+ var _a;
9383
9619
  return {
9384
9620
  type: "react",
9621
+ version: (_a = generator.version) != null ? _a : "1",
9385
9622
  Operations() {
9386
9623
  return null;
9387
9624
  },
@@ -9586,14 +9823,16 @@ var OperationGenerator = (_a$7 = class {
9586
9823
  });
9587
9824
  const writeTasks = generators.map((generator) => generatorLimit(async () => {
9588
9825
  var _a3;
9826
+ if (generator.version === "2") return [];
9827
+ const v1Generator = generator;
9589
9828
  const operationTasks = operations.map(({ operation, method }) => operationLimit(async () => {
9590
9829
  var _a4, _b;
9591
9830
  const options = this.getOptions(operation, method);
9592
- if (generator.type === "react") {
9831
+ if (v1Generator.type === "react") {
9593
9832
  await buildOperation(operation, {
9594
9833
  config: this.context.pluginManager.config,
9595
9834
  fabric: this.context.fabric,
9596
- Component: generator.Operation,
9835
+ Component: v1Generator.Operation,
9597
9836
  generator: this,
9598
9837
  plugin: {
9599
9838
  ...this.context.plugin,
@@ -9605,7 +9844,7 @@ var OperationGenerator = (_a$7 = class {
9605
9844
  });
9606
9845
  return [];
9607
9846
  }
9608
- return (_b = await ((_a4 = generator.operation) == null ? void 0 : _a4.call(generator, {
9847
+ return (_b = await ((_a4 = v1Generator.operation) == null ? void 0 : _a4.call(v1Generator, {
9609
9848
  generator: this,
9610
9849
  config: this.context.pluginManager.config,
9611
9850
  operation,
@@ -9619,17 +9858,17 @@ var OperationGenerator = (_a$7 = class {
9619
9858
  }))) != null ? _b : [];
9620
9859
  }));
9621
9860
  const opResultsFlat = (await Promise.all(operationTasks)).flat();
9622
- if (generator.type === "react") {
9861
+ if (v1Generator.type === "react") {
9623
9862
  await buildOperations(operations.map((op) => op.operation), {
9624
9863
  fabric: this.context.fabric,
9625
9864
  config: this.context.pluginManager.config,
9626
- Component: generator.Operations,
9865
+ Component: v1Generator.Operations,
9627
9866
  generator: this,
9628
9867
  plugin: this.context.plugin
9629
9868
  });
9630
9869
  return [];
9631
9870
  }
9632
- const operationsResult = await ((_a3 = generator.operations) == null ? void 0 : _a3.call(generator, {
9871
+ const operationsResult = await ((_a3 = v1Generator.operations) == null ? void 0 : _a3.call(v1Generator, {
9633
9872
  generator: this,
9634
9873
  config: this.context.pluginManager.config,
9635
9874
  operations: operations.map((op) => op.operation),
@@ -209410,6 +209649,7 @@ function printResponseSchema({ baseName, schemas, pluginManager, unknownType })
209410
209649
  }
209411
209650
  const typeGenerator = createReactGenerator({
209412
209651
  name: "typescript",
209652
+ version: "1",
209413
209653
  Operation({ operation, generator, plugin }) {
209414
209654
  const { options, options: { mapper, enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
209415
209655
  const mode = useMode();
@@ -209632,8 +209872,24 @@ const pluginTs = definePlugin((options) => {
209632
209872
  },
209633
209873
  async install() {
209634
209874
  var _a;
209635
- const root = path$2.resolve(this.config.root, this.config.output.path);
209875
+ const { config, fabric, plugin } = this;
209876
+ const root = path$2.resolve(config.root, config.output.path);
209636
209877
  const mode = getMode(path$2.resolve(root, output.path));
209878
+ if (this.rootNode) {
209879
+ await this.openInStudio({ ast: true });
209880
+ await walk(this.rootNode, { async schema(schemaNode) {
209881
+ await generators.map(async (generator) => {
209882
+ if (generator.type === "react" && generator.version === "2") await buildSchema(schemaNode, {
209883
+ config,
209884
+ fabric,
209885
+ Component: generator.Schema,
209886
+ plugin,
209887
+ version: generator.version
209888
+ });
209889
+ });
209890
+ } }, { depth: "shallow" });
209891
+ return;
209892
+ }
209637
209893
  const oas = await this.getOas();
209638
209894
  const schemaFiles = await new SchemaGenerator(this.plugin.options, {
209639
209895
  fabric: this.fabric,
@@ -210082,6 +210338,21 @@ const pluginZod = definePlugin((options) => {
210082
210338
  };
210083
210339
  });
210084
210340
 
210341
+ function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }) {
210342
+ const classCode = `export class ${name} {
210343
+ ${classNames.map((className) => ` readonly ${camelCase$b(className)}: ${className}`).join("\n")}
210344
+
210345
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
210346
+ ${classNames.map((className) => ` this.${camelCase$b(className)} = new ${className}(config)`).join("\n")}
210347
+ }
210348
+ }`;
210349
+ return /* @__PURE__ */ jsx(File.Source, {
210350
+ name,
210351
+ isExportable,
210352
+ isIndexable,
210353
+ children: classCode
210354
+ });
210355
+ }
210085
210356
  const classClientGenerator = createReactGenerator({
210086
210357
  name: "classClient",
210087
210358
  Operations({ operations, generator, plugin, config }) {
@@ -210191,7 +210462,7 @@ const classClientGenerator = createReactGenerator({
210191
210462
  zodFilesByPath
210192
210463
  };
210193
210464
  }
210194
- return controllers.map(({ name, file, operations: ops }) => {
210465
+ const files = controllers.map(({ name, file, operations: ops }) => {
210195
210466
  const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
210196
210467
  const { zodImportsByFile, zodFilesByPath } = options.parser === "zod" ? collectZodImports(ops) : {
210197
210468
  zodImportsByFile: /* @__PURE__ */ new Map(),
@@ -210293,6 +210564,49 @@ const classClientGenerator = createReactGenerator({
210293
210564
  ]
210294
210565
  }, file.path);
210295
210566
  });
210567
+ if (options.wrapper) {
210568
+ const wrapperFile = pluginManager.getFile({
210569
+ name: options.wrapper.className,
210570
+ extname: ".ts",
210571
+ pluginKey
210572
+ });
210573
+ files.push(/* @__PURE__ */ jsxs(File, {
210574
+ baseName: wrapperFile.baseName,
210575
+ path: wrapperFile.path,
210576
+ meta: wrapperFile.meta,
210577
+ banner: getBanner({
210578
+ oas,
210579
+ output: options.output,
210580
+ config: pluginManager.config
210581
+ }),
210582
+ footer: getFooter({
210583
+ oas,
210584
+ output: options.output
210585
+ }),
210586
+ children: [
210587
+ options.importPath ? /* @__PURE__ */ jsx(File.Import, {
210588
+ name: ["Client", "RequestConfig"],
210589
+ path: options.importPath,
210590
+ isTypeOnly: true
210591
+ }) : /* @__PURE__ */ jsx(File.Import, {
210592
+ name: ["Client", "RequestConfig"],
210593
+ root: wrapperFile.path,
210594
+ path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
210595
+ isTypeOnly: true
210596
+ }),
210597
+ controllers.map(({ name, file }) => /* @__PURE__ */ jsx(File.Import, {
210598
+ name: [name],
210599
+ root: wrapperFile.path,
210600
+ path: file.path
210601
+ }, name)),
210602
+ /* @__PURE__ */ jsx(WrapperClient, {
210603
+ name: options.wrapper.className,
210604
+ classNames: controllers.map(({ name }) => name)
210605
+ })
210606
+ ]
210607
+ }, wrapperFile.path));
210608
+ }
210609
+ return files;
210296
210610
  }
210297
210611
  });
210298
210612
  const clientGenerator = createReactGenerator({
@@ -210742,7 +211056,7 @@ const pluginClient = definePlugin((options) => {
210742
211056
  const { output = {
210743
211057
  path: "clients",
210744
211058
  barrelType: "named"
210745
- }, group, urlType = false, exclude = [], include, override = [], transformers = {}, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, baseURL, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, contentType, bundle = false } = options;
211059
+ }, group, urlType = false, exclude = [], include, override = [], transformers = {}, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, baseURL, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, contentType, bundle = false, wrapper } = options;
210746
211060
  const resolvedImportPath = importPath != null ? importPath : !bundle ? `@kubb/plugin-client/clients/${client}` : void 0;
210747
211061
  const defaultGenerators = [
210748
211062
  clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
@@ -210765,7 +211079,8 @@ const pluginClient = definePlugin((options) => {
210765
211079
  paramsCasing,
210766
211080
  pathParamsType,
210767
211081
  baseURL,
210768
- urlType
211082
+ urlType,
211083
+ wrapper
210769
211084
  },
210770
211085
  pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
210771
211086
  resolvePath(baseName, pathMode, options2) {