@kubb/core 5.0.0-beta.69 → 5.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -95,47 +95,6 @@ function randomCliColor(text) {
95
95
  }
96
96
  //#endregion
97
97
  //#region ../../internals/utils/src/promise.ts
98
- function* chunks(arr, size) {
99
- for (let i = 0; i < arr.length; i += size) yield arr.slice(i, i + size);
100
- }
101
- /**
102
- * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.
103
- * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).
104
- *
105
- * `process` controls whether items inside a batch run in parallel; this helper only
106
- * controls batch size and per-batch flushing.
107
- *
108
- * @example
109
- * ```ts
110
- * // parallel dispatch inside each batch
111
- * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })
112
- *
113
- * // async iterable with a flush after every batch
114
- * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })
115
- * ```
116
- */
117
- async function forBatches(source, process, options) {
118
- const { concurrency, flush } = options;
119
- if (Array.isArray(source)) {
120
- for (const batch of chunks(source, concurrency)) {
121
- await process(batch);
122
- if (flush) await flush();
123
- }
124
- return;
125
- }
126
- const batch = [];
127
- for await (const item of source) {
128
- batch.push(item);
129
- if (batch.length >= concurrency) {
130
- await process(batch.splice(0));
131
- if (flush) await flush();
132
- }
133
- }
134
- if (batch.length > 0) {
135
- await process(batch.splice(0));
136
- if (flush) await flush();
137
- }
138
- }
139
98
  /** Returns `true` when `result` is a thenable `Promise`.
140
99
  *
141
100
  * @example
@@ -445,7 +404,7 @@ function createAdapter(build) {
445
404
  /**
446
405
  * Docs major version, derived from the package version so the link tracks the published major.
447
406
  */
448
- const docsMajor = "5.0.0-beta.69".split(".")[0] ?? "5";
407
+ const docsMajor = "5.0.0-beta.70".split(".")[0] ?? "5";
449
408
  /**
450
409
  * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
451
410
  *
@@ -1910,27 +1869,28 @@ var KubbDriver = class {
1910
1869
  checkAllowedNames: false,
1911
1870
  emit: emitsOperationHook ? (node, ctx) => this.hooks.emit("kubb:generate:operation", node, ctx) : null
1912
1871
  };
1872
+ const dispatchPass = async (state, nodes, dispatch) => {
1873
+ let sinceFlush = 0;
1874
+ for (const node of nodes) {
1875
+ await dispatchNode(state, node, dispatch);
1876
+ if (++sinceFlush >= 8) {
1877
+ sinceFlush = 0;
1878
+ await flushPending();
1879
+ }
1880
+ }
1881
+ if (sinceFlush > 0) await flushPending();
1882
+ };
1913
1883
  for (const state of states) {
1914
- const needsCollectedOperations = emitsOperationsHook || state.generators.some((gen) => !!gen.operations);
1915
- const collectedOperations = needsCollectedOperations ? [] : void 0;
1916
- await forBatches(schemasBuffer, (nodes) => Promise.all(nodes.map((node) => dispatchNode(state, node, schemaDispatch))), {
1917
- concurrency: 8,
1918
- flush: flushPending
1919
- });
1920
- await forBatches(operationsBuffer, (nodes) => {
1921
- if (needsCollectedOperations) collectedOperations?.push(...nodes);
1922
- return Promise.all(nodes.map((node) => dispatchNode(state, node, operationDispatch)));
1923
- }, {
1924
- concurrency: 8,
1925
- flush: flushPending
1926
- });
1927
- if (!state.failed && needsCollectedOperations) try {
1884
+ const needsOperationsAggregate = emitsOperationsHook || state.generators.some((gen) => !!gen.operations);
1885
+ await dispatchPass(state, schemasBuffer, schemaDispatch);
1886
+ await dispatchPass(state, operationsBuffer, operationDispatch);
1887
+ if (!state.failed && needsOperationsAggregate) try {
1928
1888
  const { plugin, generatorContext, generators } = state;
1929
1889
  const ctx = {
1930
1890
  ...generatorContext,
1931
1891
  options: plugin.options
1932
1892
  };
1933
- const pluginOperations = (collectedOperations ?? []).reduce((acc, node) => {
1893
+ const pluginOperations = operationsBuffer.reduce((acc, node) => {
1934
1894
  const resolved = resolveForPlugin(state, node);
1935
1895
  if (resolved) acc.push(resolved.transformedNode);
1936
1896
  return acc;