@kubb/ast 5.25.1 → 5.27.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.
- package/dist/{combineFileMembers-DJHNAZBN.js → combineFileMembers-B-mdjXrG.js} +2 -2
- package/dist/{combineFileMembers-DJHNAZBN.js.map → combineFileMembers-B-mdjXrG.js.map} +1 -1
- package/dist/{combineFileMembers-DmmuOmY8.cjs → combineFileMembers-DZCKxAN0.cjs} +2 -2
- package/dist/{combineFileMembers-DmmuOmY8.cjs.map → combineFileMembers-DZCKxAN0.cjs.map} +1 -1
- package/dist/factory.cjs +2 -2
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{file-HwCmj--S.js → file-BOFEjuUC.js} +2 -2
- package/dist/{file-HwCmj--S.js.map → file-BOFEjuUC.js.map} +1 -1
- package/dist/{file-z3xToonr.cjs → file-DyVzXu0Y.cjs} +2 -2
- package/dist/{file-z3xToonr.cjs.map → file-DyVzXu0Y.cjs.map} +1 -1
- package/dist/file.cjs +2 -2
- package/dist/file.js +2 -2
- package/dist/{graph-DDh1FFrm.cjs → graph-D6Ffy9YD.cjs} +19 -22
- package/dist/graph-D6Ffy9YD.cjs.map +1 -0
- package/dist/{graph-DImDxlJE.js → graph-DWlCmvm6.js} +19 -22
- package/dist/graph-DWlCmvm6.js.map +1 -0
- package/dist/graph.cjs +1 -1
- package/dist/graph.d.cts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.js +1 -1
- package/dist/{guards-l2AsKeHR.d.ts → guards-CTqHwyNs.d.ts} +1 -1
- package/dist/{guards-B6LgmDhJ.d.cts → guards-EpQMJGyF.d.cts} +1 -1
- package/dist/http.d.cts +2 -2
- package/dist/http.d.ts +2 -2
- package/dist/{index-f90iIhHX.d.ts → index-B8ZxUpy4.d.ts} +1 -1
- package/dist/{index-DerFkxlp.d.ts → index-BGhhO3z8.d.ts} +4 -3
- package/dist/{index-D2tWPgnK.d.cts → index-BXv0B9Pd.d.cts} +1 -1
- package/dist/{index-Br4bwEnS.d.ts → index-C0_Y9yA1.d.ts} +1 -1
- package/dist/{index-DfTgdgaH.d.cts → index-C4ZZnf_X.d.cts} +4 -3
- package/dist/{index-DNDNDzyJ.d.cts → index-CKd3ogUZ.d.cts} +2 -2
- package/dist/{index-CCUB1hoV.d.cts → index-CiVsdeOh.d.cts} +3 -3
- package/dist/{index-C5SXJAtZ.d.cts → index-Ck6nqnxZ.d.cts} +1 -1
- package/dist/{index-YTyLBHFN.d.ts → index-CuQPyRve.d.ts} +1 -1
- package/dist/{index-2hzFweaD.d.cts → index-DSW89P6k.d.cts} +1 -1
- package/dist/index-DT-_5NUx.d.cts +5 -0
- package/dist/{index-DXdwkq7X.d.ts → index-DVX6E3vZ.d.ts} +2 -2
- package/dist/{index-BjmAaymt.d.cts → index-DdD4PIY8.d.cts} +1 -1
- package/dist/{index-Bz33tfQo.d.ts → index-DjwCRndP.d.ts} +1 -1
- package/dist/{index-MzcNxet1.d.ts → index-DphKh9u9.d.ts} +3 -3
- package/dist/index-kxuajWM1.d.ts +5 -0
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +6 -6
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{nodes-TtDfZ9qf.cjs → nodes-BGxHocS_.cjs} +2 -2
- package/dist/{nodes-TtDfZ9qf.cjs.map → nodes-BGxHocS_.cjs.map} +1 -1
- package/dist/{nodes-u9i-tqFp.js → nodes-KgbYiyJQ.js} +2 -2
- package/dist/{nodes-u9i-tqFp.js.map → nodes-KgbYiyJQ.js.map} +1 -1
- package/dist/{operation-De4lbIZS.d.cts → operation-B86IER5K.d.cts} +1 -1
- package/dist/{operation-Dd0-l2VB.d.ts → operation-DJ7F0cFp.d.ts} +1 -1
- package/dist/{promise-DScaykew.cjs → promise-DMQPWp6M.cjs} +37 -22
- package/dist/promise-DMQPWp6M.cjs.map +1 -0
- package/dist/{promise-B3YkZ4C8.js → promise-bi4pc8Xr.js} +37 -22
- package/dist/promise-bi4pc8Xr.js.map +1 -0
- package/dist/{ref-Dlxn7eu7.js → ref-BU7sfEFr.js} +2 -2
- package/dist/{ref-Dlxn7eu7.js.map → ref-BU7sfEFr.js.map} +1 -1
- package/dist/{ref-Ck-0j8NV.cjs → ref-CGeCLkAk.cjs} +2 -2
- package/dist/{ref-Ck-0j8NV.cjs.map → ref-CGeCLkAk.cjs.map} +1 -1
- package/dist/ref.cjs +2 -2
- package/dist/ref.d.cts +1 -1
- package/dist/ref.d.ts +1 -1
- package/dist/ref.js +2 -2
- package/dist/{refs-Bgf8_9Ui.js → refs-C0hb_qu-.js} +2 -2
- package/dist/{refs-Bgf8_9Ui.js.map → refs-C0hb_qu-.js.map} +1 -1
- package/dist/{refs-rmr2LFV1.cjs → refs-CJZBa9hL.cjs} +2 -2
- package/dist/{refs-rmr2LFV1.cjs.map → refs-CJZBa9hL.cjs.map} +1 -1
- package/dist/{schema-BvUrXIoX.js → schema-B05JSQRq.js} +3 -3
- package/dist/{schema-BvUrXIoX.js.map → schema-B05JSQRq.js.map} +1 -1
- package/dist/{schema-DfLGJ-oh.cjs → schema-XGRiAvok.cjs} +3 -3
- package/dist/{schema-DfLGJ-oh.cjs.map → schema-XGRiAvok.cjs.map} +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.d.cts +3 -3
- package/dist/schema.d.ts +3 -3
- package/dist/schema.js +1 -1
- package/dist/{visitor-BN5QJX7-.d.cts → visitor-BIldddZd.d.cts} +2 -2
- package/dist/{visitor-BNGMMmpe.d.ts → visitor-xxcbpM5-.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/graph-DDh1FFrm.cjs.map +0 -1
- package/dist/graph-DImDxlJE.js.map +0 -1
- package/dist/index-BiXrjYNm.d.cts +0 -5
- package/dist/index-CC5Rmgcm.d.ts +0 -5
- package/dist/promise-B3YkZ4C8.js.map +0 -1
- package/dist/promise-DScaykew.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph-DImDxlJE.js","names":[],"sources":["../src/utils/schemaGraph.ts","../src/graph/index.ts"],"sourcesContent":["import { memo } from '@internals/utils'\nimport { nodeKinds } from '../constants.ts'\nimport type { Node } from '../nodes/index.ts'\nimport type { OperationNode } from '../nodes/operation.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { collect, visitChildNodes } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\ntype RefEntry = { name: string; hasPointer: boolean }\n\nconst refEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst checkRefEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst schemaRefs = memo.create<SchemaNode, ReadonlySet<string>>({ weak: true })\nconst importedRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\nconst importedCheckRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\n\n/**\n * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved\n * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so\n * each helper below scans a schema once.\n */\nfunction collectRefEntries(node: SchemaNode, { checks }: { checks: boolean }): ReadonlyArray<RefEntry> {\n return memo(checks ? checkRefEntries : refEntries, node, () => {\n const entries: Array<RefEntry> = []\n const walk = (current: Node): boolean => {\n if (current.kind === nodeKinds.schema && current.type === 'ref') {\n const name = resolveRefName(current)\n if (name) entries.push({ name, hasPointer: Boolean(current.ref) })\n }\n visitChildNodes(current, walk, { checks })\n return false\n }\n walk(node)\n return entries\n })\n}\n\n/**\n * Collects the names of every schema a node's subtree references, resolved with `ast.ref.getName`.\n * Each ref contributes its name only, so the schema it points to is never traversed. Memoized by\n * node identity, so repeated calls on one schema scan it once.\n *\n * @example\n * ```ts\n * collectSchemaRefs(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n */\nexport function collectSchemaRefs(node: SchemaNode): ReadonlySet<string> {\n return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)))\n}\n\n/**\n * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in\n * first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result\n * across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.\n *\n * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the\n * same file (a union member created by name) is left out. That leaves exactly the set\n * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with\n * `checks: true`, for a plugin that prints those checks.\n *\n * @example\n * ```ts\n * collectImportedRefNames(petSchema)\n * // ['Category', 'Tag']\n * ```\n */\nexport function collectImportedRefNames(node: SchemaNode, { checks = false }: { checks?: boolean } = {}): ReadonlyArray<string> {\n return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [\n ...new Set(collectRefEntries(node, { checks }).flatMap((entry) => (entry.hasPointer ? [entry.name] : []))),\n ])\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n for (const name of collectSchemaRefs(schema)) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collect<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check a schema's `ast.graph.getRefNames` against the result.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const graph = new Map<string, ReadonlySet<string>>()\n for (const schema of schemas) {\n if (schema.name) graph.set(schema.name, collectSchemaRefs(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n}\n","export {\n collectImportedRefNames as getImportedNames,\n collectSchemaRefs as getRefNames,\n collectUsedSchemaNames as getUsedNames,\n findCircularSchemas as getCircularNames,\n} from '../utils/schemaGraph.ts'\n"],"mappings":"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"}
|
package/dist/index-CC5Rmgcm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-B3YkZ4C8.js","names":[],"sources":["../../../internals/utils/src/promise.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\nexport type Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\nexport type ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain. The first\n * rejection rejects the call, and the other workers start no new item after it.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n let failed = false\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) {\n if (failed) return\n await run(item, index).catch((error: unknown) => {\n failed = true\n throw error\n })\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,KAAmB,OAA4B,KAAW,SAA+B;CACvG,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,GAAG,GAAG,OAAO;CACnD,MAAM,QAAQ,QAAQ;CACtB,MAAM,IAAI,KAAK,KAAK;CACpB,OAAO;AACT;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,MAAM,wBAAQ,IAAI,IAAkB;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,MAAM,OAAO,KAAW,UAAkB;EACxC,IAAI,MAAM,QAAQ,KAAK,MAAM,MAAM;EACnC,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,IAAI,QAAQ,GAAG,OAAO;EAAE,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG;CAAI;CAGxF,MAAM,SAAS,QAAc;EAC3B,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACjC,OAAO;CACT;CACA,OAAO;EAAE,KAAK;EAAO,MAAM,QAAS,MAAM,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;EAAY;CAAI;AACpF;AAEA,KAAK,SAAS"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-DScaykew.cjs","names":[],"sources":["../../../internals/utils/src/promise.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\nexport type Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\nexport type ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain. The first\n * rejection rejects the call, and the other workers start no new item after it.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n let failed = false\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) {\n if (failed) return\n await run(item, index).catch((error: unknown) => {\n failed = true\n throw error\n })\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,KAAmB,OAA4B,KAAW,SAA+B;CACvG,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,GAAG,GAAG,OAAO;CACnD,MAAM,QAAQ,QAAQ;CACtB,MAAM,IAAI,KAAK,KAAK;CACpB,OAAO;AACT;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,MAAM,wBAAQ,IAAI,IAAkB;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,MAAM,OAAO,KAAW,UAAkB;EACxC,IAAI,MAAM,QAAQ,KAAK,MAAM,MAAM;EACnC,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,IAAI,QAAQ,GAAG,OAAO;EAAE,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG;CAAI;CAGxF,MAAM,SAAS,QAAc;EAC3B,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACjC,OAAO;CACT;CACA,OAAO;EAAE,KAAK;EAAO,MAAM,QAAS,MAAM,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;EAAY;CAAI;AACpF;AAEA,KAAK,SAAS"}
|