@kubb/agent 5.0.0-beta.18 → 5.0.0-beta.19

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.
@@ -4428,13 +4428,15 @@ function sendToBetterStack(level, tag, message, ctx) {
4428
4428
  if (level === "error") {
4429
4429
  client.error(fullMessage, context).then(() => client.flush()).catch(() => {
4430
4430
  });
4431
- } else if (level === "warn") {
4431
+ return;
4432
+ }
4433
+ if (level === "warn") {
4432
4434
  client.warn(fullMessage, context).then(() => client.flush()).catch(() => {
4433
4435
  });
4434
- } else {
4435
- client.info(fullMessage, context).then(() => client.flush()).catch(() => {
4436
- });
4436
+ return;
4437
4437
  }
4438
+ client.info(fullMessage, context).then(() => client.flush()).catch(() => {
4439
+ });
4438
4440
  } catch (_e) {
4439
4441
  }
4440
4442
  }
@@ -4833,14 +4835,12 @@ async function _walk(node, visitor, recurse, limit, parent) {
4833
4835
  for (const child of children) await _walk(child, visitor, recurse, limit, node);
4834
4836
  }
4835
4837
  function transform(node, options) {
4836
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4838
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
4837
4839
  const { depth, parent, ...visitor } = options;
4838
4840
  const recurse = (depth != null ? depth : visitorDepths.deep) === visitorDepths.deep;
4839
4841
  switch (node.kind) {
4840
4842
  case "Input": {
4841
- let input = node;
4842
- const replaced = (_a = visitor.input) == null ? void 0 : _a.call(visitor, input, { parent });
4843
- if (replaced) input = replaced;
4843
+ const input = (_b = (_a = visitor.input) == null ? void 0 : _a.call(visitor, node, { parent })) != null ? _b : node;
4844
4844
  return {
4845
4845
  ...input,
4846
4846
  schemas: input.schemas.map((s) => transform(s, {
@@ -4853,16 +4853,10 @@ function transform(node, options) {
4853
4853
  }))
4854
4854
  };
4855
4855
  }
4856
- case "Output": {
4857
- let output = node;
4858
- const replaced = (_b = visitor.output) == null ? void 0 : _b.call(visitor, output, { parent });
4859
- if (replaced) output = replaced;
4860
- return output;
4861
- }
4856
+ case "Output":
4857
+ return (_d = (_c = visitor.output) == null ? void 0 : _c.call(visitor, node, { parent })) != null ? _d : node;
4862
4858
  case "Operation": {
4863
- let op = node;
4864
- const replaced = (_c = visitor.operation) == null ? void 0 : _c.call(visitor, op, { parent });
4865
- if (replaced) op = replaced;
4859
+ const op = (_f = (_e = visitor.operation) == null ? void 0 : _e.call(visitor, node, { parent })) != null ? _f : node;
4866
4860
  return {
4867
4861
  ...op,
4868
4862
  parameters: op.parameters.map((p) => transform(p, {
@@ -4871,7 +4865,7 @@ function transform(node, options) {
4871
4865
  })),
4872
4866
  requestBody: op.requestBody ? {
4873
4867
  ...op.requestBody,
4874
- content: (_d = op.requestBody.content) == null ? void 0 : _d.map((c) => ({
4868
+ content: (_g = op.requestBody.content) == null ? void 0 : _g.map((c) => ({
4875
4869
  ...c,
4876
4870
  schema: c.schema ? transform(c.schema, {
4877
4871
  ...options,
@@ -4886,9 +4880,7 @@ function transform(node, options) {
4886
4880
  };
4887
4881
  }
4888
4882
  case "Schema": {
4889
- let schema = node;
4890
- const replaced = (_e = visitor.schema) == null ? void 0 : _e.call(visitor, schema, { parent });
4891
- if (replaced) schema = replaced;
4883
+ const schema = (_i = (_h = visitor.schema) == null ? void 0 : _h.call(visitor, node, { parent })) != null ? _i : node;
4892
4884
  const childOptions = {
4893
4885
  ...options,
4894
4886
  parent: schema
@@ -4896,15 +4888,13 @@ function transform(node, options) {
4896
4888
  return {
4897
4889
  ...schema,
4898
4890
  ..."properties" in schema && recurse ? { properties: schema.properties.map((p) => transform(p, childOptions)) } : {},
4899
- ..."items" in schema && recurse ? { items: (_f = schema.items) == null ? void 0 : _f.map((i) => transform(i, childOptions)) } : {},
4900
- ..."members" in schema && recurse ? { members: (_g = schema.members) == null ? void 0 : _g.map((m) => transform(m, childOptions)) } : {},
4891
+ ..."items" in schema && recurse ? { items: (_j = schema.items) == null ? void 0 : _j.map((i) => transform(i, childOptions)) } : {},
4892
+ ..."members" in schema && recurse ? { members: (_k = schema.members) == null ? void 0 : _k.map((m) => transform(m, childOptions)) } : {},
4901
4893
  ..."additionalProperties" in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true ? { additionalProperties: transform(schema.additionalProperties, childOptions) } : {}
4902
4894
  };
4903
4895
  }
4904
4896
  case "Property": {
4905
- let prop = node;
4906
- const replaced = (_h = visitor.property) == null ? void 0 : _h.call(visitor, prop, { parent });
4907
- if (replaced) prop = replaced;
4897
+ const prop = (_m = (_l = visitor.property) == null ? void 0 : _l.call(visitor, node, { parent })) != null ? _m : node;
4908
4898
  return createProperty({
4909
4899
  ...prop,
4910
4900
  schema: transform(prop.schema, {
@@ -4914,9 +4904,7 @@ function transform(node, options) {
4914
4904
  });
4915
4905
  }
4916
4906
  case "Parameter": {
4917
- let param = node;
4918
- const replaced = (_i = visitor.parameter) == null ? void 0 : _i.call(visitor, param, { parent });
4919
- if (replaced) param = replaced;
4907
+ const param = (_o = (_n = visitor.parameter) == null ? void 0 : _n.call(visitor, node, { parent })) != null ? _o : node;
4920
4908
  return createParameter({
4921
4909
  ...param,
4922
4910
  schema: transform(param.schema, {
@@ -4926,9 +4914,7 @@ function transform(node, options) {
4926
4914
  });
4927
4915
  }
4928
4916
  case "Response": {
4929
- let response = node;
4930
- const replaced = (_j = visitor.response) == null ? void 0 : _j.call(visitor, response, { parent });
4931
- if (replaced) response = replaced;
4917
+ const response = (_q = (_p = visitor.response) == null ? void 0 : _p.call(visitor, node, { parent })) != null ? _q : node;
4932
4918
  return {
4933
4919
  ...response,
4934
4920
  schema: transform(response.schema, {
@@ -5145,7 +5131,15 @@ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
5145
5131
  for (const name of collectSchemaRefs(node)) out.add(name);
5146
5132
  return out;
5147
5133
  }
5134
+ const usedSchemaNamesCache = /* @__PURE__ */ new WeakMap();
5148
5135
  function collectUsedSchemaNames(operations, schemas) {
5136
+ let byOps = usedSchemaNamesCache.get(operations);
5137
+ if (!byOps) {
5138
+ byOps = /* @__PURE__ */ new WeakMap();
5139
+ usedSchemaNamesCache.set(operations, byOps);
5140
+ }
5141
+ const cached = byOps.get(schemas);
5142
+ if (cached) return cached;
5149
5143
  const schemaMap = /* @__PURE__ */ new Map();
5150
5144
  for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
5151
5145
  const result = /* @__PURE__ */ new Set();
@@ -5161,6 +5155,7 @@ function collectUsedSchemaNames(operations, schemas) {
5161
5155
  depth: "shallow",
5162
5156
  schema: (node) => node
5163
5157
  })) visitSchema(schema);
5158
+ byOps.set(schemas, result);
5164
5159
  return result;
5165
5160
  }
5166
5161
  function syncOptionality(schema, required) {
@@ -5298,12 +5293,12 @@ function matchesSchemaPattern(node, type, pattern) {
5298
5293
  }
5299
5294
  }
5300
5295
  function defaultResolver(name, type) {
5301
- let resolvedName = camelCase(name);
5302
- if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
5303
- if (type === "type") resolvedName = pascalCase(name);
5304
- return resolvedName;
5296
+ if (type === "file" || type === "function") return camelCase(name, { isFile: type === "file" });
5297
+ if (type === "type") return pascalCase(name);
5298
+ return camelCase(name);
5305
5299
  }
5306
- function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
5300
+ const resolveOptionsCache = /* @__PURE__ */ new WeakMap();
5301
+ function computeOptions(node, options, exclude, include, override) {
5307
5302
  var _a2, _b2;
5308
5303
  if (isOperationNode(node)) {
5309
5304
  if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
@@ -5328,19 +5323,34 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
5328
5323
  }
5329
5324
  return options;
5330
5325
  }
5326
+ function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
5327
+ const optionsKey = options;
5328
+ let byOptions = resolveOptionsCache.get(optionsKey);
5329
+ if (!byOptions) {
5330
+ byOptions = /* @__PURE__ */ new WeakMap();
5331
+ resolveOptionsCache.set(optionsKey, byOptions);
5332
+ }
5333
+ const cached = byOptions.get(node);
5334
+ if (cached !== void 0) return cached.value;
5335
+ const result = computeOptions(node, options, exclude, include, override);
5336
+ byOptions.set(node, { value: result });
5337
+ return result;
5338
+ }
5331
5339
  function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
5332
- var _a2;
5333
5340
  if ((pathMode != null ? pathMode : getMode(path$1.resolve(root, output.path))) === "single") return path$1.resolve(root, output.path);
5334
- let result;
5335
- if (group && (groupPath || tag)) {
5336
- const groupValue = group.type === "path" ? groupPath : tag;
5337
- const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
5338
- const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
5339
- return segment ? camelCase(segment) : "";
5340
- };
5341
- const resolveName = (_a2 = group.name) != null ? _a2 : defaultName;
5342
- result = path$1.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
5343
- } else result = path$1.resolve(root, output.path, baseName);
5341
+ const result = (() => {
5342
+ var _a2;
5343
+ if (group && (groupPath || tag)) {
5344
+ const groupValue = group.type === "path" ? groupPath : tag;
5345
+ const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
5346
+ const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
5347
+ return segment ? camelCase(segment) : "";
5348
+ };
5349
+ const resolveName = (_a2 = group.name) != null ? _a2 : defaultName;
5350
+ return path$1.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
5351
+ }
5352
+ return path$1.resolve(root, output.path, baseName);
5353
+ })();
5344
5354
  const outputDir = path$1.resolve(root, output.path);
5345
5355
  const outputDirWithSep = outputDir.endsWith(path$1.sep) ? outputDir : `${outputDir}${path$1.sep}`;
5346
5356
  if (result !== outputDir && !result.startsWith(outputDirWithSep)) throw new Error(`[Kubb] Resolved path "${result}" is outside the output directory "${outputDir}". This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.`);
@@ -5366,12 +5376,16 @@ function defaultResolveFile({ name, extname: extname2, tag, path: groupPath }, c
5366
5376
  }
5367
5377
  function buildDefaultBanner({ title, description, version, config }) {
5368
5378
  try {
5369
- let source = "";
5370
- if (Array.isArray(config.input)) {
5371
- const first = config.input[0];
5372
- if (first && "path" in first) source = path$1.basename(first.path);
5373
- } else if (config.input && "path" in config.input) source = path$1.basename(config.input.path);
5374
- else if (config.input && "data" in config.input) source = "text content";
5379
+ const source = (() => {
5380
+ if (Array.isArray(config.input)) {
5381
+ const first = config.input[0];
5382
+ if (first && "path" in first) return path$1.basename(first.path);
5383
+ return "";
5384
+ }
5385
+ if (config.input && "path" in config.input) return path$1.basename(config.input.path);
5386
+ if (config.input && "data" in config.input) return "text content";
5387
+ return "";
5388
+ })();
5375
5389
  let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
5376
5390
  if (config.output.defaultBanner === "simple") {
5377
5391
  banner += "*/\n";
@@ -5700,7 +5714,11 @@ var PluginDriver = (_b$1 = class {
5700
5714
  if (gen.schema) {
5701
5715
  const schemaHandler = async (node, ctx) => {
5702
5716
  if (ctx.plugin.name !== pluginName) return;
5703
- await applyHookResult(await gen.schema(node, ctx), this, resolveRenderer());
5717
+ await applyHookResult({
5718
+ result: await gen.schema(node, ctx),
5719
+ driver: this,
5720
+ rendererFactory: resolveRenderer()
5721
+ });
5704
5722
  };
5705
5723
  this.hooks.on("kubb:generate:schema", schemaHandler);
5706
5724
  __privateMethod$1(this, _PluginDriver_instances, trackHookListener_fn).call(this, "kubb:generate:schema", schemaHandler);
@@ -5708,7 +5726,11 @@ var PluginDriver = (_b$1 = class {
5708
5726
  if (gen.operation) {
5709
5727
  const operationHandler = async (node, ctx) => {
5710
5728
  if (ctx.plugin.name !== pluginName) return;
5711
- await applyHookResult(await gen.operation(node, ctx), this, resolveRenderer());
5729
+ await applyHookResult({
5730
+ result: await gen.operation(node, ctx),
5731
+ driver: this,
5732
+ rendererFactory: resolveRenderer()
5733
+ });
5712
5734
  };
5713
5735
  this.hooks.on("kubb:generate:operation", operationHandler);
5714
5736
  __privateMethod$1(this, _PluginDriver_instances, trackHookListener_fn).call(this, "kubb:generate:operation", operationHandler);
@@ -5716,7 +5738,11 @@ var PluginDriver = (_b$1 = class {
5716
5738
  if (gen.operations) {
5717
5739
  const operationsHandler = async (nodes, ctx) => {
5718
5740
  if (ctx.plugin.name !== pluginName) return;
5719
- await applyHookResult(await gen.operations(nodes, ctx), this, resolveRenderer());
5741
+ await applyHookResult({
5742
+ result: await gen.operations(nodes, ctx),
5743
+ driver: this,
5744
+ rendererFactory: resolveRenderer()
5745
+ });
5720
5746
  };
5721
5747
  this.hooks.on("kubb:generate:operations", operationsHandler);
5722
5748
  __privateMethod$1(this, _PluginDriver_instances, trackHookListener_fn).call(this, "kubb:generate:operations", operationsHandler);
@@ -5793,8 +5819,9 @@ var PluginDriver = (_b$1 = class {
5793
5819
  driver.fileManager.upsert(...files);
5794
5820
  },
5795
5821
  get inputNode() {
5796
- var _a2, _b2;
5797
- return (_b2 = driver.inputNode) != null ? _b2 : {
5822
+ var _a2;
5823
+ if (driver.inputNode) return driver.inputNode;
5824
+ return {
5798
5825
  kind: "Input",
5799
5826
  schemas: [],
5800
5827
  operations: [],
@@ -5872,7 +5899,7 @@ normalizePlugin_fn = function(hookPlugin) {
5872
5899
  __privateGet$1(this, _defaultResolvers).set(pluginName, resolver);
5873
5900
  return resolver;
5874
5901
  }, _b$1);
5875
- async function applyHookResult(result, driver, rendererFactory) {
5902
+ function applyHookResult({ result, driver, rendererFactory }) {
5876
5903
  if (!result) return;
5877
5904
  if (Array.isArray(result)) {
5878
5905
  driver.fileManager.upsert(...result);
@@ -5880,11 +5907,20 @@ async function applyHookResult(result, driver, rendererFactory) {
5880
5907
  }
5881
5908
  if (!rendererFactory) return;
5882
5909
  const renderer = rendererFactory();
5883
- if (renderer.stream) for await (const file of renderer.stream(result)) driver.fileManager.upsert(file);
5884
- else {
5885
- await renderer.render(result);
5886
- driver.fileManager.upsert(...renderer.files);
5910
+ if (renderer.stream) {
5911
+ for (const file of renderer.stream(result)) driver.fileManager.upsert(file);
5912
+ renderer.unmount();
5913
+ return;
5887
5914
  }
5915
+ return applyAsyncRender({
5916
+ renderer,
5917
+ result,
5918
+ driver
5919
+ });
5920
+ }
5921
+ async function applyAsyncRender({ renderer, result, driver }) {
5922
+ await renderer.render(result);
5923
+ driver.fileManager.upsert(...renderer.files);
5888
5924
  renderer.unmount();
5889
5925
  }
5890
5926
 
@@ -5899,7 +5935,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
5899
5935
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5900
5936
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
5901
5937
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
5902
- var _emitter, _a, _options, _URLPath_instances, transformParam_fn, eachParam_fn, _b;
5938
+ var _emitter, _AsyncEventEmitter_instances, emitAll_fn, _a, _options, _URLPath_instances, transformParam_fn, eachParam_fn, _b;
5903
5939
  var BuildError = class extends Error {
5904
5940
  constructor(message, options) {
5905
5941
  super(message, { cause: options.cause });
@@ -5917,6 +5953,7 @@ var AsyncEventEmitter = (_a = class {
5917
5953
  * @default 10
5918
5954
  */
5919
5955
  constructor(maxListener = 10) {
5956
+ __privateAdd(this, _AsyncEventEmitter_instances);
5920
5957
  __privateAdd(this, _emitter, new EventEmitter());
5921
5958
  __privateGet(this, _emitter).setMaxListeners(maxListener);
5922
5959
  }
@@ -5929,20 +5966,10 @@ var AsyncEventEmitter = (_a = class {
5929
5966
  * await emitter.emit('build', 'petstore')
5930
5967
  * ```
5931
5968
  */
5932
- async emit(eventName, ...eventArgs) {
5969
+ emit(eventName, ...eventArgs) {
5933
5970
  const listeners = __privateGet(this, _emitter).listeners(eventName);
5934
5971
  if (listeners.length === 0) return;
5935
- for (const listener of listeners) try {
5936
- await listener(...eventArgs);
5937
- } catch (err) {
5938
- let serializedArgs;
5939
- try {
5940
- serializedArgs = JSON.stringify(eventArgs);
5941
- } catch {
5942
- serializedArgs = String(eventArgs);
5943
- }
5944
- throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
5945
- }
5972
+ return __privateMethod(this, _AsyncEventEmitter_instances, emitAll_fn).call(this, eventName, listeners, eventArgs);
5946
5973
  }
5947
5974
  /**
5948
5975
  * Registers a persistent listener for `eventName`.
@@ -6004,7 +6031,19 @@ var AsyncEventEmitter = (_a = class {
6004
6031
  removeAll() {
6005
6032
  __privateGet(this, _emitter).removeAllListeners();
6006
6033
  }
6007
- }, _emitter = new WeakMap(), _a);
6034
+ }, _emitter = new WeakMap(), _AsyncEventEmitter_instances = new WeakSet(), emitAll_fn = async function(eventName, listeners, eventArgs) {
6035
+ for (const listener of listeners) try {
6036
+ await listener(...eventArgs);
6037
+ } catch (err) {
6038
+ let serializedArgs;
6039
+ try {
6040
+ serializedArgs = JSON.stringify(eventArgs);
6041
+ } catch {
6042
+ serializedArgs = String(eventArgs);
6043
+ }
6044
+ throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
6045
+ }
6046
+ }, _a);
6008
6047
  function getElapsedMs(hrStart) {
6009
6048
  const [seconds, nanoseconds] = process.hrtime(hrStart);
6010
6049
  const ms = seconds * 1e3 + nanoseconds / 1e6;
@@ -6055,6 +6094,9 @@ async function clean(path) {
6055
6094
  force: true
6056
6095
  });
6057
6096
  }
6097
+ function isPromise(result) {
6098
+ return result !== null && result !== void 0 && typeof result["then"] === "function";
6099
+ }
6058
6100
  const reservedWords = /* @__PURE__ */ new Set([
6059
6101
  "abstract",
6060
6102
  "arguments",
@@ -6277,36 +6319,37 @@ eachParam_fn = function(fn) {
6277
6319
  fn(raw, __privateMethod(this, _URLPath_instances, transformParam_fn).call(this, raw));
6278
6320
  }
6279
6321
  }, _b);
6280
- var version$1 = "5.0.0-beta.18";
6322
+ var version$1 = "5.0.0-beta.19";
6281
6323
  function createStorage(build2) {
6282
6324
  return (options) => build2(options != null ? options : {});
6283
6325
  }
6284
6326
  function joinSources(file) {
6285
- return file.sources.map((item) => extractStringsFromNodes(item.nodes)).filter(Boolean).join("\n\n");
6327
+ const sources = file.sources;
6328
+ if (sources.length === 0) return "";
6329
+ const parts = [];
6330
+ for (const source of sources) {
6331
+ const s = extractStringsFromNodes(source.nodes);
6332
+ if (s) parts.push(s);
6333
+ }
6334
+ return parts.join("\n\n");
6286
6335
  }
6287
6336
  var FileProcessor = class {
6288
6337
  constructor() {
6289
6338
  __publicField(this, "events", new AsyncEventEmitter());
6290
6339
  }
6291
- async parse(file, { parsers, extension } = {}) {
6340
+ parse(file, { parsers, extension } = {}) {
6292
6341
  const parseExtName = (extension == null ? void 0 : extension[file.extname]) || void 0;
6293
6342
  if (!parsers || !file.extname) return joinSources(file);
6294
6343
  const parser = parsers.get(file.extname);
6295
6344
  if (!parser) return joinSources(file);
6296
6345
  return parser.parse(file, { extname: parseExtName });
6297
6346
  }
6298
- /**
6299
- * Streams parsed files one at a time as each is processed.
6300
- *
6301
- * Unlike `run()`, files are yielded immediately after parsing rather than batched.
6302
- * Storage writes can begin as soon as the first file is ready, keeping peak
6303
- * memory proportional to one file at a time instead of the full batch.
6304
- */
6305
- async *stream(files, options = {}) {
6347
+ *stream(files, options = {}) {
6306
6348
  const total = files.length;
6349
+ if (total === 0) return;
6307
6350
  let processed = 0;
6308
6351
  for (const file of files) {
6309
- const source = await this.parse(file, options);
6352
+ const source = this.parse(file, options);
6310
6353
  processed++;
6311
6354
  yield {
6312
6355
  file,
@@ -6319,7 +6362,7 @@ var FileProcessor = class {
6319
6362
  }
6320
6363
  async run(files, options = {}) {
6321
6364
  await this.events.emit("start", files);
6322
- for await (const { file, source, processed, total, percentage } of this.stream(files, options)) await this.events.emit("update", {
6365
+ for (const { file, source, processed, total, percentage } of this.stream(files, options)) await this.events.emit("update", {
6323
6366
  file,
6324
6367
  source,
6325
6368
  processed,
@@ -6555,18 +6598,9 @@ async function setup(userConfig, options = {}) {
6555
6598
  ` \u2022 Operations: ${operationCount}`
6556
6599
  ]
6557
6600
  });
6558
- } else {
6559
- driver.inputNode = await config.adapter.parse(source);
6560
- await hooks.emit("kubb:debug", {
6561
- date: /* @__PURE__ */ new Date(),
6562
- logs: [
6563
- `\u2713 Adapter '${config.adapter.name}' resolved InputNode`,
6564
- ` \u2022 Schemas: ${driver.inputNode.schemas.length}`,
6565
- ` \u2022 Operations: ${driver.inputNode.operations.length}`
6566
- ]
6567
- });
6568
6601
  }
6569
- } else {
6602
+ }
6603
+ if (!driver.inputStreamNode) {
6570
6604
  driver.inputNode = await config.adapter.parse(source);
6571
6605
  await hooks.emit("kubb:debug", {
6572
6606
  date: /* @__PURE__ */ new Date(),
@@ -6591,13 +6625,18 @@ async function setup(userConfig, options = {}) {
6591
6625
  for (const [event, handler] of middlewareListeners) hooks.off(event, handler);
6592
6626
  }
6593
6627
  }
6594
- async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles) {
6628
+ async function runPluginStreamHooks({ entries, driver, pluginTimings, failedPlugins }) {
6629
+ const inputStreamNode = driver.inputStreamNode;
6595
6630
  function resolveRendererFor(gen, state) {
6596
6631
  var _a2, _b2;
6597
6632
  return gen.renderer === null ? void 0 : (_b2 = (_a2 = gen.renderer) != null ? _a2 : state.plugin.renderer) != null ? _b2 : state.generatorContext.config.renderer;
6598
6633
  }
6599
6634
  const states = entries.map(({ plugin, context, hrStart }) => {
6600
6635
  var _a2;
6636
+ const { exclude, include, override } = plugin.options;
6637
+ const hasExclude = Array.isArray(exclude) && exclude.length > 0;
6638
+ const hasInclude = Array.isArray(include) && include.length > 0;
6639
+ const hasOverride = Array.isArray(override) && override.length > 0;
6601
6640
  return {
6602
6641
  plugin,
6603
6642
  generatorContext: {
@@ -6607,72 +6646,82 @@ async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, con
6607
6646
  generators: (_a2 = plugin.generators) != null ? _a2 : [],
6608
6647
  hrStart,
6609
6648
  failed: false,
6610
- error: void 0
6649
+ error: void 0,
6650
+ optionsAreStatic: !hasExclude && !hasInclude && !hasOverride
6611
6651
  };
6612
6652
  });
6613
- let schemasProcessed = 0;
6614
- for await (const node of inputStreamNode.schemas) {
6615
- for (const state of states) {
6616
- if (state.failed) continue;
6617
- try {
6618
- const { plugin, generatorContext, generators } = state;
6619
- const { exclude, include, override } = plugin.options;
6620
- const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6621
- const options = generatorContext.resolver.resolveOptions(transformedNode, {
6622
- options: plugin.options,
6623
- exclude,
6624
- include,
6625
- override
6653
+ async function dispatchSchema(state, node) {
6654
+ if (state.failed) return;
6655
+ try {
6656
+ const { plugin, generatorContext, generators } = state;
6657
+ const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6658
+ const { exclude, include, override } = plugin.options;
6659
+ const options = state.optionsAreStatic ? plugin.options : generatorContext.resolver.resolveOptions(transformedNode, {
6660
+ options: plugin.options,
6661
+ exclude,
6662
+ include,
6663
+ override
6664
+ });
6665
+ if (options === null) return;
6666
+ const ctx = {
6667
+ ...generatorContext,
6668
+ options
6669
+ };
6670
+ for (const gen of generators) {
6671
+ if (!gen.schema) continue;
6672
+ const raw = gen.schema(transformedNode, ctx);
6673
+ const applied = applyHookResult({
6674
+ result: isPromise(raw) ? await raw : raw,
6675
+ driver,
6676
+ rendererFactory: resolveRendererFor(gen, state)
6626
6677
  });
6627
- if (options === null) continue;
6628
- const ctx = {
6629
- ...generatorContext,
6630
- options
6631
- };
6632
- for (const gen of generators) {
6633
- if (!gen.schema) continue;
6634
- await applyHookResult(await gen.schema(transformedNode, ctx), driver, resolveRendererFor(gen, state));
6635
- }
6636
- await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
6637
- } catch (caughtError) {
6638
- state.failed = true;
6639
- state.error = caughtError;
6678
+ if (isPromise(applied)) await applied;
6640
6679
  }
6680
+ await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
6681
+ } catch (caughtError) {
6682
+ state.failed = true;
6683
+ state.error = caughtError;
6641
6684
  }
6642
- schemasProcessed++;
6643
- if (schemasProcessed % 50 === 0) await flushPendingFiles();
6644
6685
  }
6645
- const collectedOperations = [];
6646
- for await (const node of inputStreamNode.operations) {
6647
- collectedOperations.push(node);
6648
- for (const state of states) {
6649
- if (state.failed) continue;
6650
- try {
6651
- const { plugin, generatorContext, generators } = state;
6652
- const { exclude, include, override } = plugin.options;
6653
- const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6654
- const options = generatorContext.resolver.resolveOptions(transformedNode, {
6655
- options: plugin.options,
6656
- exclude,
6657
- include,
6658
- override
6686
+ async function dispatchOperation(state, node) {
6687
+ if (state.failed) return;
6688
+ try {
6689
+ const { plugin, generatorContext, generators } = state;
6690
+ const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6691
+ const { exclude, include, override } = plugin.options;
6692
+ const options = state.optionsAreStatic ? plugin.options : generatorContext.resolver.resolveOptions(transformedNode, {
6693
+ options: plugin.options,
6694
+ exclude,
6695
+ include,
6696
+ override
6697
+ });
6698
+ if (options === null) return;
6699
+ const ctx = {
6700
+ ...generatorContext,
6701
+ options
6702
+ };
6703
+ for (const gen of generators) {
6704
+ if (!gen.operation) continue;
6705
+ const raw = gen.operation(transformedNode, ctx);
6706
+ const applied = applyHookResult({
6707
+ result: isPromise(raw) ? await raw : raw,
6708
+ driver,
6709
+ rendererFactory: resolveRendererFor(gen, state)
6659
6710
  });
6660
- if (options === null) continue;
6661
- const ctx = {
6662
- ...generatorContext,
6663
- options
6664
- };
6665
- for (const gen of generators) {
6666
- if (!gen.operation) continue;
6667
- await applyHookResult(await gen.operation(transformedNode, ctx), driver, resolveRendererFor(gen, state));
6668
- }
6669
- await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
6670
- } catch (caughtError) {
6671
- state.failed = true;
6672
- state.error = caughtError;
6711
+ if (isPromise(applied)) await applied;
6673
6712
  }
6713
+ await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
6714
+ } catch (caughtError) {
6715
+ state.failed = true;
6716
+ state.error = caughtError;
6674
6717
  }
6675
6718
  }
6719
+ for await (const node of inputStreamNode.schemas) await Promise.all(states.map((state) => dispatchSchema(state, node)));
6720
+ const collectedOperations = [];
6721
+ for await (const node of inputStreamNode.operations) {
6722
+ collectedOperations.push(node);
6723
+ await Promise.all(states.map((state) => dispatchOperation(state, node)));
6724
+ }
6676
6725
  for (const state of states) {
6677
6726
  if (!state.failed) try {
6678
6727
  const { plugin, generatorContext, generators } = state;
@@ -6682,7 +6731,11 @@ async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, con
6682
6731
  };
6683
6732
  for (const gen of generators) {
6684
6733
  if (!gen.operations) continue;
6685
- await applyHookResult(await gen.operations(collectedOperations, ctx), driver, resolveRendererFor(gen, state));
6734
+ await applyHookResult({
6735
+ result: await gen.operations(collectedOperations, ctx),
6736
+ driver,
6737
+ rendererFactory: resolveRendererFor(gen, state)
6738
+ });
6686
6739
  }
6687
6740
  await driver.hooks.emit("kubb:generate:operations", collectedOperations, ctx);
6688
6741
  } catch (caughtError) {
@@ -6691,12 +6744,12 @@ async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, con
6691
6744
  }
6692
6745
  const duration = getElapsedMs(state.hrStart);
6693
6746
  pluginTimings.set(state.plugin.name, duration);
6694
- await hooks.emit("kubb:plugin:end", {
6747
+ await driver.hooks.emit("kubb:plugin:end", {
6695
6748
  plugin: state.plugin,
6696
6749
  duration,
6697
6750
  success: !state.failed,
6698
6751
  ...state.failed && state.error ? { error: state.error } : {},
6699
- config,
6752
+ config: driver.config,
6700
6753
  get files() {
6701
6754
  return driver.fileManager.files;
6702
6755
  },
@@ -6706,12 +6759,11 @@ async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, con
6706
6759
  plugin: state.plugin,
6707
6760
  error: state.error
6708
6761
  });
6709
- await hooks.emit("kubb:debug", {
6762
+ await driver.hooks.emit("kubb:debug", {
6710
6763
  date: /* @__PURE__ */ new Date(),
6711
6764
  logs: [state.failed ? "\u2717 Plugin start failed" : `\u2713 Plugin started successfully (${formatMs(duration)})`]
6712
6765
  });
6713
6766
  }
6714
- await flushPendingFiles();
6715
6767
  }
6716
6768
  async function runPluginAstHooks(plugin, context) {
6717
6769
  var _a2, _b2, _c;
@@ -6737,13 +6789,15 @@ async function runPluginAstHooks(plugin, context) {
6737
6789
  ]);
6738
6790
  const hasOperationBasedIncludes = (_b2 = include == null ? void 0 : include.some(({ type }) => operationFilterTypes.has(type))) != null ? _b2 : false;
6739
6791
  const hasSchemaNameIncludes = (_c = include == null ? void 0 : include.some(({ type }) => type === "schemaName")) != null ? _c : false;
6740
- let allowedSchemaNames;
6741
- if (hasOperationBasedIncludes && !hasSchemaNameIncludes) allowedSchemaNames = collectUsedSchemaNames(inputNode.operations.filter((op) => resolver.resolveOptions(op, {
6742
- options: plugin.options,
6743
- exclude,
6744
- include,
6745
- override
6746
- }) !== null), inputNode.schemas);
6792
+ const allowedSchemaNames = (() => {
6793
+ if (!hasOperationBasedIncludes || hasSchemaNameIncludes) return void 0;
6794
+ return collectUsedSchemaNames(inputNode.operations.filter((op) => resolver.resolveOptions(op, {
6795
+ options: plugin.options,
6796
+ exclude,
6797
+ include,
6798
+ override
6799
+ }) !== null), inputNode.schemas);
6800
+ })();
6747
6801
  await walk(inputNode, {
6748
6802
  depth: "shallow",
6749
6803
  async schema(node) {
@@ -6761,7 +6815,11 @@ async function runPluginAstHooks(plugin, context) {
6761
6815
  options
6762
6816
  };
6763
6817
  await Promise.all(generators.filter((gen) => gen.schema).map(async (gen) => {
6764
- return applyHookResult(await gen.schema(transformedNode, ctx), driver, resolveRenderer(gen));
6818
+ return applyHookResult({
6819
+ result: await gen.schema(transformedNode, ctx),
6820
+ driver,
6821
+ rendererFactory: resolveRenderer(gen)
6822
+ });
6765
6823
  }));
6766
6824
  await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
6767
6825
  },
@@ -6773,17 +6831,20 @@ async function runPluginAstHooks(plugin, context) {
6773
6831
  include,
6774
6832
  override
6775
6833
  });
6776
- if (options !== null) {
6777
- collectedOperations.push(transformedNode);
6778
- const ctx = {
6779
- ...generatorContext,
6780
- options
6781
- };
6782
- await Promise.all(generators.filter((gen) => gen.operation).map(async (gen) => {
6783
- return applyHookResult(await gen.operation(transformedNode, ctx), driver, resolveRenderer(gen));
6784
- }));
6785
- await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
6786
- }
6834
+ if (options === null) return;
6835
+ collectedOperations.push(transformedNode);
6836
+ const ctx = {
6837
+ ...generatorContext,
6838
+ options
6839
+ };
6840
+ await Promise.all(generators.filter((gen) => gen.operation).map(async (gen) => {
6841
+ return applyHookResult({
6842
+ result: await gen.operation(transformedNode, ctx),
6843
+ driver,
6844
+ rendererFactory: resolveRenderer(gen)
6845
+ });
6846
+ }));
6847
+ await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
6787
6848
  }
6788
6849
  });
6789
6850
  if (collectedOperations.length > 0) {
@@ -6793,7 +6854,11 @@ async function runPluginAstHooks(plugin, context) {
6793
6854
  };
6794
6855
  for (const gen of generators) {
6795
6856
  if (!gen.operations) continue;
6796
- await applyHookResult(await gen.operations(collectedOperations, ctx), driver, resolveRenderer(gen));
6857
+ await applyHookResult({
6858
+ result: await gen.operations(collectedOperations, ctx),
6859
+ driver,
6860
+ rendererFactory: resolveRenderer(gen)
6861
+ });
6797
6862
  }
6798
6863
  await driver.hooks.emit("kubb:generate:operations", collectedOperations, ctx);
6799
6864
  }
@@ -6811,8 +6876,8 @@ async function safeBuild(setupResult) {
6811
6876
  const parsersMap = /* @__PURE__ */ new Map();
6812
6877
  for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
6813
6878
  const fileProcessor = new FileProcessor();
6814
- async function flushPendingFiles(snapshot) {
6815
- const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path) && (!snapshot || !snapshot.has(f.path)));
6879
+ async function flushPendingFiles() {
6880
+ const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path));
6816
6881
  if (files.length === 0) return;
6817
6882
  await hooks.emit("kubb:debug", {
6818
6883
  date: /* @__PURE__ */ new Date(),
@@ -6823,7 +6888,7 @@ async function safeBuild(setupResult) {
6823
6888
  parsers: parsersMap,
6824
6889
  extension: config.output.extension
6825
6890
  });
6826
- for await (const { file, source, processed, total, percentage } of stream) {
6891
+ for (const { file, source, processed, total, percentage } of stream) {
6827
6892
  await hooks.emit("kubb:file:processing:update", {
6828
6893
  file,
6829
6894
  source,
@@ -6858,8 +6923,7 @@ async function safeBuild(setupResult) {
6858
6923
  },
6859
6924
  upsertFile: (...files2) => driver.fileManager.upsert(...files2)
6860
6925
  });
6861
- const inputStreamNode = driver.inputStreamNode;
6862
- if (inputStreamNode) {
6926
+ if (driver.inputStreamNode) {
6863
6927
  const streamPluginEntries = [];
6864
6928
  for (const plugin of driver.plugins.values()) {
6865
6929
  const context = driver.getContext(plugin);
@@ -6869,31 +6933,40 @@ async function safeBuild(setupResult) {
6869
6933
  date: /* @__PURE__ */ new Date(),
6870
6934
  logs: ["Starting plugin...", ` \u2022 Plugin Name: ${plugin.name}`]
6871
6935
  });
6872
- if (((_c = plugin.generators) == null ? void 0 : _c.length) || driver.hasRegisteredGenerators(plugin.name)) streamPluginEntries.push({
6873
- plugin,
6874
- context,
6875
- hrStart
6876
- });
6877
- else {
6878
- const duration = getElapsedMs(hrStart);
6879
- pluginTimings.set(plugin.name, duration);
6880
- await hooks.emit("kubb:plugin:end", {
6936
+ if (((_c = plugin.generators) == null ? void 0 : _c.length) || driver.hasRegisteredGenerators(plugin.name)) {
6937
+ streamPluginEntries.push({
6881
6938
  plugin,
6882
- duration,
6883
- success: true,
6884
- config,
6885
- get files() {
6886
- return driver.fileManager.files;
6887
- },
6888
- upsertFile: (...files2) => driver.fileManager.upsert(...files2)
6889
- });
6890
- await hooks.emit("kubb:debug", {
6891
- date: /* @__PURE__ */ new Date(),
6892
- logs: [`\u2713 Plugin started successfully (${formatMs(duration)})`]
6939
+ context,
6940
+ hrStart
6893
6941
  });
6942
+ continue;
6894
6943
  }
6944
+ const duration = getElapsedMs(hrStart);
6945
+ pluginTimings.set(plugin.name, duration);
6946
+ await hooks.emit("kubb:plugin:end", {
6947
+ plugin,
6948
+ duration,
6949
+ success: true,
6950
+ config,
6951
+ get files() {
6952
+ return driver.fileManager.files;
6953
+ },
6954
+ upsertFile: (...files2) => driver.fileManager.upsert(...files2)
6955
+ });
6956
+ await hooks.emit("kubb:debug", {
6957
+ date: /* @__PURE__ */ new Date(),
6958
+ logs: [`\u2713 Plugin started successfully (${formatMs(duration)})`]
6959
+ });
6960
+ }
6961
+ if (streamPluginEntries.length > 0) {
6962
+ await runPluginStreamHooks({
6963
+ entries: streamPluginEntries,
6964
+ driver,
6965
+ pluginTimings,
6966
+ failedPlugins
6967
+ });
6968
+ await flushPendingFiles();
6895
6969
  }
6896
- if (streamPluginEntries.length > 0) await runPluginStreamHooks(inputStreamNode, streamPluginEntries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles);
6897
6970
  } else for (const plugin of driver.plugins.values()) {
6898
6971
  const context = driver.getContext(plugin);
6899
6972
  const hrStart = process.hrtime();
@@ -7099,7 +7172,7 @@ const memoryStorage = createStorage(() => {
7099
7172
  };
7100
7173
  });
7101
7174
 
7102
- var version = "5.0.0-beta.18";
7175
+ var version = "5.0.0-beta.19";
7103
7176
 
7104
7177
  function isCommandMessage(msg) {
7105
7178
  return msg.type === "command";