@kubb/agent 5.0.0-beta.15 → 5.0.0-beta.16

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "date": "2026-05-17T11:30:55.157Z",
2
+ "date": "2026-05-18T11:01:06.223Z",
3
3
  "preset": "node-server",
4
4
  "framework": {
5
5
  "name": "nitro",
@@ -4708,12 +4708,6 @@ async function disconnect({ sessionId, token, studioUrl }) {
4708
4708
  }
4709
4709
  }
4710
4710
 
4711
- var __defProp$2 = Object.defineProperty;
4712
- var __name = (target, value) => __defProp$2(target, "name", {
4713
- value,
4714
- configurable: true
4715
- });
4716
-
4717
4711
  const visitorDepths = {
4718
4712
  deep: "deep"
4719
4713
  };
@@ -5551,6 +5545,11 @@ var PluginDriver = (_b$1 = class {
5551
5545
  * the build pipeline after the adapter's `parse()` resolves.
5552
5546
  */
5553
5547
  __publicField$1(this, "inputNode");
5548
+ /**
5549
+ * Set when the adapter returns a streaming `InputStreamNode` (large specs).
5550
+ * Mutually exclusive with `inputNode` — exactly one is set after adapter setup.
5551
+ */
5552
+ __publicField$1(this, "inputStreamNode");
5554
5553
  __publicField$1(this, "adapter");
5555
5554
  __privateAdd$1(this, _studioIsOpen, false);
5556
5555
  /**
@@ -5745,6 +5744,7 @@ var PluginDriver = (_b$1 = class {
5745
5744
  __privateGet$1(this, _defaultResolvers).clear();
5746
5745
  this.fileManager.dispose();
5747
5746
  this.inputNode = void 0;
5747
+ this.inputStreamNode = void 0;
5748
5748
  }
5749
5749
  /**
5750
5750
  * Merges `partial` with the plugin's default resolver and stores the result.
@@ -5787,7 +5787,13 @@ var PluginDriver = (_b$1 = class {
5787
5787
  driver.fileManager.upsert(...files);
5788
5788
  },
5789
5789
  get inputNode() {
5790
- return driver.inputNode;
5790
+ var _a2, _b2;
5791
+ return (_b2 = driver.inputNode) != null ? _b2 : {
5792
+ kind: "Input",
5793
+ schemas: [],
5794
+ operations: [],
5795
+ meta: (_a2 = driver.inputStreamNode) == null ? void 0 : _a2.meta
5796
+ };
5791
5797
  },
5792
5798
  get adapter() {
5793
5799
  return driver.adapter;
@@ -5884,15 +5890,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
5884
5890
  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);
5885
5891
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
5886
5892
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
5887
- var __privateWrapper = (obj, member, setter, getter) => ({
5888
- set _(value) {
5889
- __privateSet(obj, member, value);
5890
- },
5891
- get _() {
5892
- return __privateGet(obj, member, getter);
5893
- }
5894
- });
5895
- var _emitter, _a, _options, _URLPath_instances, transformParam_fn, eachParam_fn, _b, _c, _head, _tail, _size, _d, _limit, _e;
5893
+ var _emitter, _a, _options, _URLPath_instances, transformParam_fn, eachParam_fn, _b;
5896
5894
  var BuildError = class extends Error {
5897
5895
  constructor(message, options) {
5898
5896
  super(message, { cause: options.cause });
@@ -6270,141 +6268,16 @@ eachParam_fn = function(fn) {
6270
6268
  fn(raw, __privateMethod(this, _URLPath_instances, transformParam_fn).call(this, raw));
6271
6269
  }
6272
6270
  }, _b);
6273
- var version$1 = "5.0.0-beta.15";
6271
+ var version$1 = "5.0.0-beta.16";
6274
6272
  function createStorage(build2) {
6275
6273
  return (options) => build2(options != null ? options : {});
6276
6274
  }
6277
- var Node$1 = (_c = class {
6278
- constructor(value) {
6279
- __publicField(this, "value");
6280
- __publicField(this, "next");
6281
- this.value = value;
6282
- }
6283
- }, __name(_c, "Node"), _c);
6284
- var Queue = (_d = class {
6285
- constructor() {
6286
- __privateAdd(this, _head);
6287
- __privateAdd(this, _tail);
6288
- __privateAdd(this, _size);
6289
- this.clear();
6290
- }
6291
- enqueue(value) {
6292
- const node = new Node$1(value);
6293
- if (__privateGet(this, _head)) {
6294
- __privateGet(this, _tail).next = node;
6295
- __privateSet(this, _tail, node);
6296
- } else {
6297
- __privateSet(this, _head, node);
6298
- __privateSet(this, _tail, node);
6299
- }
6300
- __privateWrapper(this, _size)._++;
6301
- }
6302
- dequeue() {
6303
- const current = __privateGet(this, _head);
6304
- if (!current) return;
6305
- __privateSet(this, _head, __privateGet(this, _head).next);
6306
- __privateWrapper(this, _size)._--;
6307
- if (!__privateGet(this, _head)) __privateSet(this, _tail, void 0);
6308
- return current.value;
6309
- }
6310
- peek() {
6311
- if (!__privateGet(this, _head)) return;
6312
- return __privateGet(this, _head).value;
6313
- }
6314
- clear() {
6315
- __privateSet(this, _head, void 0);
6316
- __privateSet(this, _tail, void 0);
6317
- __privateSet(this, _size, 0);
6318
- }
6319
- get size() {
6320
- return __privateGet(this, _size);
6321
- }
6322
- *[Symbol.iterator]() {
6323
- let current = __privateGet(this, _head);
6324
- while (current) {
6325
- yield current.value;
6326
- current = current.next;
6327
- }
6328
- }
6329
- *drain() {
6330
- while (__privateGet(this, _head)) yield this.dequeue();
6331
- }
6332
- }, _head = new WeakMap(), _tail = new WeakMap(), _size = new WeakMap(), _d);
6333
- function pLimit(concurrency) {
6334
- let rejectOnClear = false;
6335
- if (typeof concurrency === "object") ({ concurrency, rejectOnClear = false } = concurrency);
6336
- validateConcurrency(concurrency);
6337
- if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
6338
- const queue = new Queue();
6339
- let activeCount = 0;
6340
- const resumeNext = () => {
6341
- if (activeCount < concurrency && queue.size > 0) {
6342
- activeCount++;
6343
- queue.dequeue().run();
6344
- }
6345
- };
6346
- const next = () => {
6347
- activeCount--;
6348
- resumeNext();
6349
- };
6350
- const run = async (function_, resolve2, arguments_) => {
6351
- const result = (async () => function_(...arguments_))();
6352
- resolve2(result);
6353
- try {
6354
- await result;
6355
- } catch {
6356
- }
6357
- next();
6358
- };
6359
- const enqueue = (function_, resolve2, reject, arguments_) => {
6360
- const queueItem = { reject };
6361
- new Promise((internalResolve) => {
6362
- queueItem.run = internalResolve;
6363
- queue.enqueue(queueItem);
6364
- }).then(run.bind(void 0, function_, resolve2, arguments_));
6365
- if (activeCount < concurrency) resumeNext();
6366
- };
6367
- const generator = (function_, ...arguments_) => new Promise((resolve2, reject) => {
6368
- enqueue(function_, resolve2, reject, arguments_);
6369
- });
6370
- Object.defineProperties(generator, {
6371
- activeCount: { get: () => activeCount },
6372
- pendingCount: { get: () => queue.size },
6373
- clearQueue: { value() {
6374
- if (!rejectOnClear) {
6375
- queue.clear();
6376
- return;
6377
- }
6378
- const abortError = AbortSignal.abort().reason;
6379
- while (queue.size > 0) queue.dequeue().reject(abortError);
6380
- } },
6381
- concurrency: {
6382
- get: () => concurrency,
6383
- set(newConcurrency) {
6384
- validateConcurrency(newConcurrency);
6385
- concurrency = newConcurrency;
6386
- queueMicrotask(() => {
6387
- while (activeCount < concurrency && queue.size > 0) resumeNext();
6388
- });
6389
- }
6390
- },
6391
- map: { async value(iterable, function_) {
6392
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
6393
- return Promise.all(promises);
6394
- } }
6395
- });
6396
- return generator;
6397
- }
6398
- function validateConcurrency(concurrency) {
6399
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
6400
- }
6401
6275
  function joinSources(file) {
6402
6276
  return file.sources.map((item) => extractStringsFromNodes(item.nodes)).filter(Boolean).join("\n\n");
6403
6277
  }
6404
- var FileProcessor = (_e = class {
6278
+ var FileProcessor = class {
6405
6279
  constructor() {
6406
6280
  __publicField(this, "events", new AsyncEventEmitter());
6407
- __privateAdd(this, _limit, pLimit(16));
6408
6281
  }
6409
6282
  async parse(file, { parsers, extension } = {}) {
6410
6283
  const parseExtName = (extension == null ? void 0 : extension[file.extname]) || void 0;
@@ -6413,31 +6286,41 @@ var FileProcessor = (_e = class {
6413
6286
  if (!parser) return joinSources(file);
6414
6287
  return parser.parse(file, { extname: parseExtName });
6415
6288
  }
6416
- async run(files, { parsers, mode = "sequential", extension } = {}) {
6417
- await this.events.emit("start", files);
6289
+ /**
6290
+ * Streams parsed files one at a time as each is processed.
6291
+ *
6292
+ * Unlike `run()`, files are yielded immediately after parsing rather than batched.
6293
+ * Storage writes can begin as soon as the first file is ready, keeping peak
6294
+ * memory proportional to one file at a time instead of the full batch.
6295
+ */
6296
+ async *stream(files, options = {}) {
6418
6297
  const total = files.length;
6419
6298
  let processed = 0;
6420
- const processOne = async (file) => {
6421
- const source = await this.parse(file, {
6422
- extension,
6423
- parsers
6424
- });
6425
- const currentProcessed = ++processed;
6426
- const percentage = currentProcessed / total * 100;
6427
- await this.events.emit("update", {
6299
+ for (const file of files) {
6300
+ const source = await this.parse(file, options);
6301
+ processed++;
6302
+ yield {
6428
6303
  file,
6429
6304
  source,
6430
- processed: currentProcessed,
6431
- percentage,
6432
- total
6433
- });
6434
- };
6435
- if (mode === "sequential") for (const file of files) await processOne(file);
6436
- else await Promise.all(files.map((file) => __privateGet(this, _limit).call(this, () => processOne(file))));
6305
+ processed,
6306
+ total,
6307
+ percentage: processed / total * 100
6308
+ };
6309
+ }
6310
+ }
6311
+ async run(files, options = {}) {
6312
+ await this.events.emit("start", files);
6313
+ for await (const { file, source, processed, total, percentage } of this.stream(files, options)) await this.events.emit("update", {
6314
+ file,
6315
+ source,
6316
+ processed,
6317
+ percentage,
6318
+ total
6319
+ });
6437
6320
  await this.events.emit("end", files);
6438
6321
  return files;
6439
6322
  }
6440
- }, _limit = new WeakMap(), _e);
6323
+ };
6441
6324
  const fsStorage = createStorage(() => ({
6442
6325
  name: "fs",
6443
6326
  async hasItem(key) {
@@ -6516,7 +6399,7 @@ function createSourcesView(storage) {
6516
6399
  }))();
6517
6400
  }
6518
6401
  async function setup(userConfig, options = {}) {
6519
- var _a2, _b2, _c2, _d2, _e2, _f, _g, _h, _i;
6402
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
6520
6403
  const hooks = (_a2 = options.hooks) != null ? _a2 : new AsyncEventEmitter();
6521
6404
  const config = {
6522
6405
  ...userConfig,
@@ -6530,12 +6413,12 @@ async function setup(userConfig, options = {}) {
6530
6413
  defaultBanner: DEFAULT_BANNER,
6531
6414
  ...userConfig.output
6532
6415
  },
6533
- storage: (_c2 = userConfig.storage) != null ? _c2 : fsStorage(),
6416
+ storage: (_c = userConfig.storage) != null ? _c : fsStorage(),
6534
6417
  devtools: userConfig.devtools ? {
6535
6418
  studioUrl: DEFAULT_STUDIO_URL,
6536
6419
  ...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
6537
6420
  } : void 0,
6538
- plugins: (_d2 = userConfig.plugins) != null ? _d2 : []
6421
+ plugins: (_d = userConfig.plugins) != null ? _d : []
6539
6422
  };
6540
6423
  const driver = new PluginDriver(config, { hooks });
6541
6424
  const storage = createSourcesView(config.storage);
@@ -6546,7 +6429,7 @@ async function setup(userConfig, options = {}) {
6546
6429
  "Configuration:",
6547
6430
  ` \u2022 Name: ${userConfig.name || "unnamed"}`,
6548
6431
  ` \u2022 Root: ${userConfig.root || process.cwd()}`,
6549
- ` \u2022 Output: ${((_e2 = userConfig.output) == null ? void 0 : _e2.path) || "not specified"}`,
6432
+ ` \u2022 Output: ${((_e = userConfig.output) == null ? void 0 : _e.path) || "not specified"}`,
6550
6433
  ` \u2022 Plugins: ${((_f = userConfig.plugins) == null ? void 0 : _f.length) || 0}`,
6551
6434
  "Output Settings:",
6552
6435
  ` \u2022 Storage: ${config.storage.name}`,
@@ -6593,15 +6476,40 @@ async function setup(userConfig, options = {}) {
6593
6476
  logs: [`Running adapter: ${config.adapter.name}`]
6594
6477
  });
6595
6478
  driver.adapter = config.adapter;
6596
- driver.inputNode = await config.adapter.parse(source);
6597
- await hooks.emit("kubb:debug", {
6598
- date: /* @__PURE__ */ new Date(),
6599
- logs: [
6600
- `\u2713 Adapter '${config.adapter.name}' resolved InputNode`,
6601
- ` \u2022 Schemas: ${driver.inputNode.schemas.length}`,
6602
- ` \u2022 Operations: ${driver.inputNode.operations.length}`
6603
- ]
6604
- });
6479
+ if (config.adapter.count && config.adapter.stream) {
6480
+ const { schemas: schemaCount, operations: operationCount } = await config.adapter.count(source);
6481
+ if (schemaCount > 100) {
6482
+ driver.inputStreamNode = await config.adapter.stream(source);
6483
+ await hooks.emit("kubb:debug", {
6484
+ date: /* @__PURE__ */ new Date(),
6485
+ logs: [
6486
+ `\u2713 Adapter '${config.adapter.name}' streaming InputStreamNode`,
6487
+ ` \u2022 Schemas: ${schemaCount} (threshold: 100)`,
6488
+ ` \u2022 Operations: ${operationCount}`
6489
+ ]
6490
+ });
6491
+ } else {
6492
+ driver.inputNode = await config.adapter.parse(source);
6493
+ await hooks.emit("kubb:debug", {
6494
+ date: /* @__PURE__ */ new Date(),
6495
+ logs: [
6496
+ `\u2713 Adapter '${config.adapter.name}' resolved InputNode`,
6497
+ ` \u2022 Schemas: ${driver.inputNode.schemas.length}`,
6498
+ ` \u2022 Operations: ${driver.inputNode.operations.length}`
6499
+ ]
6500
+ });
6501
+ }
6502
+ } else {
6503
+ driver.inputNode = await config.adapter.parse(source);
6504
+ await hooks.emit("kubb:debug", {
6505
+ date: /* @__PURE__ */ new Date(),
6506
+ logs: [
6507
+ `\u2713 Adapter '${config.adapter.name}' resolved InputNode`,
6508
+ ` \u2022 Schemas: ${driver.inputNode.schemas.length}`,
6509
+ ` \u2022 Operations: ${driver.inputNode.operations.length}`
6510
+ ]
6511
+ });
6512
+ }
6605
6513
  }
6606
6514
  return {
6607
6515
  config,
@@ -6614,8 +6522,130 @@ async function setup(userConfig, options = {}) {
6614
6522
  }
6615
6523
  };
6616
6524
  }
6525
+ async function runPluginStreamHooks(inputStreamNode, entries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles) {
6526
+ function resolveRendererFor(gen, state) {
6527
+ var _a2, _b2;
6528
+ return gen.renderer === null ? void 0 : (_b2 = (_a2 = gen.renderer) != null ? _a2 : state.plugin.renderer) != null ? _b2 : state.generatorContext.config.renderer;
6529
+ }
6530
+ const states = entries.map(({ plugin, context, hrStart }) => {
6531
+ var _a2;
6532
+ return {
6533
+ plugin,
6534
+ generatorContext: {
6535
+ ...context,
6536
+ resolver: driver.getResolver(plugin.name)
6537
+ },
6538
+ generators: (_a2 = plugin.generators) != null ? _a2 : [],
6539
+ hrStart,
6540
+ failed: false,
6541
+ error: void 0
6542
+ };
6543
+ });
6544
+ let schemasProcessed = 0;
6545
+ for await (const node of inputStreamNode.schemas) {
6546
+ for (const state of states) {
6547
+ if (state.failed) continue;
6548
+ try {
6549
+ const { plugin, generatorContext, generators } = state;
6550
+ const { exclude, include, override } = plugin.options;
6551
+ const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6552
+ const options = generatorContext.resolver.resolveOptions(transformedNode, {
6553
+ options: plugin.options,
6554
+ exclude,
6555
+ include,
6556
+ override
6557
+ });
6558
+ if (options === null) continue;
6559
+ const ctx = {
6560
+ ...generatorContext,
6561
+ options
6562
+ };
6563
+ for (const gen of generators) {
6564
+ if (!gen.schema) continue;
6565
+ await applyHookResult(await gen.schema(transformedNode, ctx), driver, resolveRendererFor(gen, state));
6566
+ }
6567
+ await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
6568
+ } catch (caughtError) {
6569
+ state.failed = true;
6570
+ state.error = caughtError;
6571
+ }
6572
+ }
6573
+ schemasProcessed++;
6574
+ if (schemasProcessed % 50 === 0) await flushPendingFiles();
6575
+ }
6576
+ const collectedOperations = [];
6577
+ for await (const node of inputStreamNode.operations) {
6578
+ collectedOperations.push(node);
6579
+ for (const state of states) {
6580
+ if (state.failed) continue;
6581
+ try {
6582
+ const { plugin, generatorContext, generators } = state;
6583
+ const { exclude, include, override } = plugin.options;
6584
+ const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
6585
+ const options = generatorContext.resolver.resolveOptions(transformedNode, {
6586
+ options: plugin.options,
6587
+ exclude,
6588
+ include,
6589
+ override
6590
+ });
6591
+ if (options === null) continue;
6592
+ const ctx = {
6593
+ ...generatorContext,
6594
+ options
6595
+ };
6596
+ for (const gen of generators) {
6597
+ if (!gen.operation) continue;
6598
+ await applyHookResult(await gen.operation(transformedNode, ctx), driver, resolveRendererFor(gen, state));
6599
+ }
6600
+ await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
6601
+ } catch (caughtError) {
6602
+ state.failed = true;
6603
+ state.error = caughtError;
6604
+ }
6605
+ }
6606
+ }
6607
+ for (const state of states) {
6608
+ if (!state.failed) try {
6609
+ const { plugin, generatorContext, generators } = state;
6610
+ const ctx = {
6611
+ ...generatorContext,
6612
+ options: plugin.options
6613
+ };
6614
+ for (const gen of generators) {
6615
+ if (!gen.operations) continue;
6616
+ await applyHookResult(await gen.operations(collectedOperations, ctx), driver, resolveRendererFor(gen, state));
6617
+ }
6618
+ await driver.hooks.emit("kubb:generate:operations", collectedOperations, ctx);
6619
+ } catch (caughtError) {
6620
+ state.failed = true;
6621
+ state.error = caughtError;
6622
+ }
6623
+ const duration = getElapsedMs(state.hrStart);
6624
+ pluginTimings.set(state.plugin.name, duration);
6625
+ await hooks.emit("kubb:plugin:end", {
6626
+ plugin: state.plugin,
6627
+ duration,
6628
+ success: !state.failed,
6629
+ ...state.failed && state.error ? { error: state.error } : {},
6630
+ config,
6631
+ get files() {
6632
+ return driver.fileManager.files;
6633
+ },
6634
+ upsertFile: (...files) => driver.fileManager.upsert(...files)
6635
+ });
6636
+ if (state.failed && state.error) failedPlugins.add({
6637
+ plugin: state.plugin,
6638
+ error: state.error
6639
+ });
6640
+ await hooks.emit("kubb:debug", {
6641
+ date: /* @__PURE__ */ new Date(),
6642
+ logs: [state.failed ? "\u2717 Plugin start failed" : `\u2713 Plugin started successfully (${formatMs(duration)})`]
6643
+ });
6644
+ }
6645
+ await flushPendingFiles();
6646
+ }
6617
6647
  async function runPluginAstHooks(plugin, context) {
6618
- var _a2, _b2, _c2;
6648
+ var _a2, _b2, _c;
6619
6649
  const { adapter, inputNode, resolver, driver } = context;
6620
6650
  const { exclude, include, override } = plugin.options;
6621
6651
  if (!adapter || !inputNode) throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. adapterOas()) before this plugin in your Kubb config.`);
@@ -6637,7 +6667,7 @@ async function runPluginAstHooks(plugin, context) {
6637
6667
  "contentType"
6638
6668
  ]);
6639
6669
  const hasOperationBasedIncludes = (_b2 = include == null ? void 0 : include.some(({ type }) => operationFilterTypes.has(type))) != null ? _b2 : false;
6640
- const hasSchemaNameIncludes = (_c2 = include == null ? void 0 : include.some(({ type }) => type === "schemaName")) != null ? _c2 : false;
6670
+ const hasSchemaNameIncludes = (_c = include == null ? void 0 : include.some(({ type }) => type === "schemaName")) != null ? _c : false;
6641
6671
  let allowedSchemaNames;
6642
6672
  if (hasOperationBasedIncludes && !hasSchemaNameIncludes) allowedSchemaNames = collectUsedSchemaNames(inputNode.operations.filter((op) => resolver.resolveOptions(op, {
6643
6673
  options: plugin.options,
@@ -6696,7 +6726,7 @@ async function runPluginAstHooks(plugin, context) {
6696
6726
  }
6697
6727
  }
6698
6728
  async function safeBuild(setupResult) {
6699
- var _a2;
6729
+ var _a2, _b2, _c, _d;
6700
6730
  const { driver, hooks, storage } = setupResult;
6701
6731
  const failedPlugins = /* @__PURE__ */ new Set();
6702
6732
  const pluginTimings = /* @__PURE__ */ new Map();
@@ -6705,54 +6735,90 @@ async function safeBuild(setupResult) {
6705
6735
  const parsersMap = /* @__PURE__ */ new Map();
6706
6736
  for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
6707
6737
  const fileProcessor = new FileProcessor();
6708
- fileProcessor.events.on("start", async (processingFiles) => {
6709
- await hooks.emit("kubb:files:processing:start", { files: processingFiles });
6710
- });
6711
- fileProcessor.events.on("update", async ({ file, source, processed, total, percentage }) => {
6712
- await hooks.emit("kubb:file:processing:update", {
6713
- file,
6714
- source,
6715
- processed,
6716
- total,
6717
- percentage,
6718
- config
6719
- });
6720
- if (source) await storage.setItem(file.path, source);
6721
- });
6722
- fileProcessor.events.on("end", async (processed) => {
6723
- await hooks.emit("kubb:files:processing:end", { files: processed });
6724
- await hooks.emit("kubb:debug", {
6725
- date: /* @__PURE__ */ new Date(),
6726
- logs: [`\u2713 File write process completed for ${processed.length} files`]
6727
- });
6728
- });
6729
- async function flushPendingFiles() {
6730
- const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path));
6738
+ async function flushPendingFiles(snapshot) {
6739
+ const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path) && (!snapshot || !snapshot.has(f.path)));
6731
6740
  if (files.length === 0) return;
6732
6741
  await hooks.emit("kubb:debug", {
6733
6742
  date: /* @__PURE__ */ new Date(),
6734
6743
  logs: [`Writing ${files.length} files...`]
6735
6744
  });
6736
- await fileProcessor.run(files, {
6745
+ await hooks.emit("kubb:files:processing:start", { files });
6746
+ const stream = fileProcessor.stream(files, {
6737
6747
  parsers: parsersMap,
6738
- mode: "parallel",
6739
6748
  extension: config.output.extension
6740
6749
  });
6741
- for (const file of files) writtenPaths.add(file.path);
6750
+ for await (const { file, source, processed, total, percentage } of stream) {
6751
+ await hooks.emit("kubb:file:processing:update", {
6752
+ file,
6753
+ source,
6754
+ processed,
6755
+ total,
6756
+ percentage,
6757
+ config
6758
+ });
6759
+ if (source) await storage.setItem(file.path, source);
6760
+ writtenPaths.add(file.path);
6761
+ }
6762
+ await hooks.emit("kubb:files:processing:end", { files });
6763
+ await hooks.emit("kubb:debug", {
6764
+ date: /* @__PURE__ */ new Date(),
6765
+ logs: [`\u2713 File write process completed for ${files.length} files`]
6766
+ });
6742
6767
  }
6743
6768
  try {
6744
6769
  await driver.emitSetupHooks();
6745
- if (driver.adapter && driver.inputNode) await hooks.emit("kubb:build:start", {
6770
+ if (driver.adapter && (driver.inputNode || driver.inputStreamNode)) await hooks.emit("kubb:build:start", {
6746
6771
  config,
6747
6772
  adapter: driver.adapter,
6748
- inputNode: driver.inputNode,
6773
+ inputNode: (_b2 = driver.inputNode) != null ? _b2 : {
6774
+ kind: "Input",
6775
+ schemas: [],
6776
+ operations: [],
6777
+ meta: (_a2 = driver.inputStreamNode) == null ? void 0 : _a2.meta
6778
+ },
6749
6779
  getPlugin: driver.getPlugin.bind(driver),
6750
6780
  get files() {
6751
6781
  return driver.fileManager.files;
6752
6782
  },
6753
6783
  upsertFile: (...files2) => driver.fileManager.upsert(...files2)
6754
6784
  });
6755
- for (const plugin of driver.plugins.values()) {
6785
+ const inputStreamNode = driver.inputStreamNode;
6786
+ if (inputStreamNode) {
6787
+ const streamPluginEntries = [];
6788
+ for (const plugin of driver.plugins.values()) {
6789
+ const context = driver.getContext(plugin);
6790
+ const hrStart = process.hrtime();
6791
+ await hooks.emit("kubb:plugin:start", { plugin });
6792
+ await hooks.emit("kubb:debug", {
6793
+ date: /* @__PURE__ */ new Date(),
6794
+ logs: ["Starting plugin...", ` \u2022 Plugin Name: ${plugin.name}`]
6795
+ });
6796
+ if (((_c = plugin.generators) == null ? void 0 : _c.length) || driver.hasRegisteredGenerators(plugin.name)) streamPluginEntries.push({
6797
+ plugin,
6798
+ context,
6799
+ hrStart
6800
+ });
6801
+ else {
6802
+ const duration = getElapsedMs(hrStart);
6803
+ pluginTimings.set(plugin.name, duration);
6804
+ await hooks.emit("kubb:plugin:end", {
6805
+ plugin,
6806
+ duration,
6807
+ success: true,
6808
+ config,
6809
+ get files() {
6810
+ return driver.fileManager.files;
6811
+ },
6812
+ upsertFile: (...files2) => driver.fileManager.upsert(...files2)
6813
+ });
6814
+ await hooks.emit("kubb:debug", {
6815
+ date: /* @__PURE__ */ new Date(),
6816
+ logs: [`\u2713 Plugin started successfully (${formatMs(duration)})`]
6817
+ });
6818
+ }
6819
+ }
6820
+ if (streamPluginEntries.length > 0) await runPluginStreamHooks(inputStreamNode, streamPluginEntries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles);
6821
+ } else for (const plugin of driver.plugins.values()) {
6756
6822
  const context = driver.getContext(plugin);
6757
6823
  const hrStart = process.hrtime();
6758
6824
  try {
@@ -6762,7 +6828,7 @@ async function safeBuild(setupResult) {
6762
6828
  date: timestamp,
6763
6829
  logs: ["Starting plugin...", ` \u2022 Plugin Name: ${plugin.name}`]
6764
6830
  });
6765
- if (((_a2 = plugin.generators) == null ? void 0 : _a2.length) || driver.hasRegisteredGenerators(plugin.name)) await runPluginAstHooks(plugin, context);
6831
+ if (((_d = plugin.generators) == null ? void 0 : _d.length) || driver.hasRegisteredGenerators(plugin.name)) await runPluginAstHooks(plugin, context);
6766
6832
  const duration = getElapsedMs(hrStart);
6767
6833
  pluginTimings.set(plugin.name, duration);
6768
6834
  await hooks.emit("kubb:plugin:end", {
@@ -6809,6 +6875,7 @@ async function safeBuild(setupResult) {
6809
6875
  error
6810
6876
  });
6811
6877
  }
6878
+ await flushPendingFiles();
6812
6879
  }
6813
6880
  await hooks.emit("kubb:plugins:end", {
6814
6881
  config,
@@ -6953,7 +7020,7 @@ const memoryStorage = createStorage(() => {
6953
7020
  };
6954
7021
  });
6955
7022
 
6956
- var version = "5.0.0-beta.15";
7023
+ var version = "5.0.0-beta.16";
6957
7024
 
6958
7025
  function isCommandMessage(msg) {
6959
7026
  return msg.type === "command";
@@ -1 +1 @@
1
- {"version":3,"file":"nitro.mjs","sources":["../../../../../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs","../../../../../../node_modules/.pnpm/ufo@1.6.4/node_modules/ufo/dist/index.mjs","../../../../../../node_modules/.pnpm/radix3@1.1.2/node_modules/radix3/dist/index.mjs","../../../../../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs","../../../../../../node_modules/.pnpm/node-mock-http@1.0.4/node_modules/node-mock-http/dist/index.mjs","../../../../../../node_modules/.pnpm/h3@1.15.11/node_modules/h3/dist/index.mjs","../../../../../../node_modules/.pnpm/hookable@5.5.3/node_modules/hookable/dist/index.mjs","../../../../../../node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/native.mjs","../../../../../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs","../../../../../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/dist/shared/unstorage.zVDD2mZo.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/dist/index.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/utils/index.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/utils/node-fs.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/fs.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/fs-lite.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/storage.mjs","../../../../../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/node/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/hash.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/cache.mjs","../../../../../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/dist/index.mjs","../../../../../../node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/utils.env.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/config.mjs","../../../../../../node_modules/.pnpm/unctx@2.5.0/node_modules/unctx/dist/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/context.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/route-rules-utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/route-rules.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/error/utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/error/prod.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/plugin.mjs","../../../../server/utils/logger.ts","../../../../server/plugins/fetch-logger.ts","../../../../../../internals/utils/dist/index.js","../../../../server/plugins/heartbeat.ts","../../../../server/utils/token.ts","../../../../server/utils/api.ts","../../../../../core/dist/chunk--u3MIqq1.js","../../../../../ast/dist/index.js","../../../../../core/dist/PluginDriver-CGypdXHg.js","../../../../../core/dist/index.js","../../../../server/types/agent.ts","../../../../server/utils/agentCache.ts","../../../../server/utils/executeHooks.ts","../../../../server/utils/generate.ts","../../../../server/utils/getCosmiConfig.ts","../../../../server/utils/loadConfig.ts","../../../../server/utils/resolvePlugins.ts","../../../../server/utils/mergePlugins.ts","../../../../server/utils/publish.ts","../../../../server/utils/setupHookListener.ts","../../../../server/constants.ts","../../../../server/utils/ws.ts","../../../../server/utils/connectStudio.ts","../../../../server/utils/runtimeConfig.ts","../../../../server/plugins/studio.ts","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/app.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/lib/http-graceful-shutdown.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/runtime/internal/shutdown.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.0/node_modules/nitropack/dist/presets/node/runtime/node-server.mjs"],"names":["createRouter","f","h","i","l","createError","mergeHeaders","s","nodeFetch","Headers","Headers$1","AbortController$1","normalizeKey","defineDriver","DRIVER_NAME","createStorage","fsPromises","PATH_TRAVERSE_RE","fsp","_inlineAppConfig","createRadixRouter","formatMs","resolve","_a","process","__defProp","path","_b","extname","__privateAdd","__privateMethod","__privateGet","__privateSet","__publicField","readFile","writeFile","build","walk","readdir","_c","_d","_e","files","error","version","nitroApp","callNodeRequestHandler","fetchNodeRequestHandler","gracefulShutdown","HttpsServer","HttpServer"],"mappings":"","x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,57,58,59,60]}
1
+ {"version":3,"file":"nitro.mjs","sources":["../../../../../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs","../../../../../../node_modules/.pnpm/ufo@1.6.4/node_modules/ufo/dist/index.mjs","../../../../../../node_modules/.pnpm/radix3@1.1.2/node_modules/radix3/dist/index.mjs","../../../../../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs","../../../../../../node_modules/.pnpm/node-mock-http@1.0.4/node_modules/node-mock-http/dist/index.mjs","../../../../../../node_modules/.pnpm/h3@1.15.11/node_modules/h3/dist/index.mjs","../../../../../../node_modules/.pnpm/hookable@5.5.3/node_modules/hookable/dist/index.mjs","../../../../../../node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/native.mjs","../../../../../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs","../../../../../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/dist/shared/unstorage.zVDD2mZo.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/dist/index.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/utils/index.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/utils/node-fs.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/fs.mjs","../../../../../../node_modules/.pnpm/unstorage@1.17.5_db0@0.3.4_ioredis@5.10.1/node_modules/unstorage/drivers/fs-lite.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/storage.mjs","../../../../../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/node/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/hash.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/cache.mjs","../../../../../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/dist/index.mjs","../../../../../../node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/utils.env.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/config.mjs","../../../../../../node_modules/.pnpm/unctx@2.5.0/node_modules/unctx/dist/index.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/context.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/route-rules-utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/route-rules.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/error/utils.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/error/prod.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/plugin.mjs","../../../../server/utils/logger.ts","../../../../server/plugins/fetch-logger.ts","../../../../../../internals/utils/dist/index.js","../../../../server/plugins/heartbeat.ts","../../../../server/utils/token.ts","../../../../server/utils/api.ts","../../../../../ast/dist/index.js","../../../../../core/dist/PluginDriver-CT33kVoQ.js","../../../../../core/dist/index.js","../../../../server/types/agent.ts","../../../../server/utils/agentCache.ts","../../../../server/utils/executeHooks.ts","../../../../server/utils/generate.ts","../../../../server/utils/getCosmiConfig.ts","../../../../server/utils/loadConfig.ts","../../../../server/utils/resolvePlugins.ts","../../../../server/utils/mergePlugins.ts","../../../../server/utils/publish.ts","../../../../server/utils/setupHookListener.ts","../../../../server/constants.ts","../../../../server/utils/ws.ts","../../../../server/utils/connectStudio.ts","../../../../server/utils/runtimeConfig.ts","../../../../server/plugins/studio.ts","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/app.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/lib/http-graceful-shutdown.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/runtime/internal/shutdown.mjs","../../../../../../node_modules/.pnpm/nitropack@2.13.4_rolldown@1.0.1/node_modules/nitropack/dist/presets/node/runtime/node-server.mjs"],"names":["createRouter","f","h","i","l","createError","mergeHeaders","s","nodeFetch","Headers","Headers$1","AbortController$1","normalizeKey","defineDriver","DRIVER_NAME","createStorage","fsPromises","PATH_TRAVERSE_RE","fsp","_inlineAppConfig","createRadixRouter","formatMs","resolve","_a","process","path","_b","extname","__privateAdd","__privateMethod","__privateGet","__privateSet","__publicField","readFile","writeFile","build","walk","readdir","files","error","version","nitroApp","callNodeRequestHandler","fetchNodeRequestHandler","gracefulShutdown","HttpsServer","HttpServer"],"mappings":"","x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,56,57,58,59]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/agent-prod",
3
- "version": "5.0.0-beta.15",
3
+ "version": "5.0.0-beta.16",
4
4
  "type": "module",
5
5
  "private": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/agent",
3
- "version": "5.0.0-beta.15",
3
+ "version": "5.0.0-beta.16",
4
4
  "description": "HTTP agent server for Kubb. Exposes code generation via REST API and WebSocket with real-time Kubb Studio integration, machine binding, and Docker support.",
5
5
  "keywords": [
6
6
  "agent",
@@ -43,18 +43,18 @@
43
43
  "tinyexec": "^1.1.2",
44
44
  "unstorage": "^1.17.5",
45
45
  "ws": "^8.20.1",
46
- "@kubb/ast": "5.0.0-beta.15",
47
- "@kubb/core": "5.0.0-beta.15"
46
+ "@kubb/ast": "5.0.0-beta.16",
47
+ "@kubb/core": "5.0.0-beta.16"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/ws": "^8.18.1",
51
51
  "msw": "^2.14.6",
52
52
  "nitropack": "^2.13.4",
53
- "vite": "^8.0.12",
53
+ "vite": "^8.0.13",
54
54
  "@internals/utils": "0.0.0",
55
- "@kubb/adapter-oas": "5.0.0-beta.15",
56
- "@kubb/parser-ts": "5.0.0-beta.15",
57
- "@kubb/renderer-jsx": "5.0.0-beta.15"
55
+ "@kubb/adapter-oas": "5.0.0-beta.16",
56
+ "@kubb/parser-ts": "5.0.0-beta.16",
57
+ "@kubb/renderer-jsx": "5.0.0-beta.16"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22"