@kubb/ast 5.28.6 → 5.29.1
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/README.md +19 -10
- package/dist/factory.cjs +6 -6
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{combineFileMembers-B-mdjXrG.js → file-AcKQt60j.js} +137 -123
- package/dist/file-AcKQt60j.js.map +1 -0
- package/dist/{file-DJqd2j3y.d.cts → file-CLh8vdcR.d.cts} +20 -29
- package/dist/{file-lssk85C8.cjs → file-DVw2Htda.cjs} +13 -13
- package/dist/{file-lssk85C8.cjs.map → file-DVw2Htda.cjs.map} +1 -1
- package/dist/{combineFileMembers-DZCKxAN0.cjs → file-Db_PYobC.cjs} +136 -122
- package/dist/file-Db_PYobC.cjs.map +1 -0
- package/dist/{file-Dg70hXm3.d.ts → file-VRwu7Set.d.ts} +20 -29
- package/dist/{file-CO9KnOvT.js → file-pjdyWLJ0.js} +2 -2
- package/dist/{file-CO9KnOvT.js.map → file-pjdyWLJ0.js.map} +1 -1
- package/dist/file.cjs +6 -6
- package/dist/file.d.cts +1 -1
- package/dist/file.d.ts +1 -1
- package/dist/file.js +2 -2
- package/dist/{graph-DWlCmvm6.js → graph-Cu2-NiKi.js} +78 -15
- package/dist/graph-Cu2-NiKi.js.map +1 -0
- package/dist/{graph-D6Ffy9YD.cjs → graph-CymJtC1M.cjs} +78 -15
- package/dist/graph-CymJtC1M.cjs.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/{index-BGhhO3z8.d.ts → index-B4DY8ewx.d.ts} +2 -2
- package/dist/{index-DjwCRndP.d.ts → index-BEvWuiSq.d.ts} +1 -1
- package/dist/{index-DphKh9u9.d.ts → index-BXHrCLGe.d.ts} +1 -1
- package/dist/{index-C4ZZnf_X.d.cts → index-BgmSdJKJ.d.cts} +2 -2
- package/dist/{index-CKd3ogUZ.d.cts → index-C0YF5kEb.d.cts} +2 -2
- package/dist/{index-Ck6nqnxZ.d.cts → index-CGvAotBX.d.cts} +2 -2
- package/dist/{index-DVX6E3vZ.d.ts → index-CHilsNw-.d.ts} +2 -2
- package/dist/{index-C0_Y9yA1.d.ts → index-CsySa8TT.d.ts} +2 -2
- package/dist/{index-BM3jzSca.d.ts → index-DA-Ztg07.d.ts} +1 -1
- package/dist/{index-CiVsdeOh.d.cts → index-DPGecgel.d.cts} +1 -1
- package/dist/{index-DdD4PIY8.d.cts → index-Dbtc7izw.d.cts} +1 -1
- package/dist/{index-DSW89P6k.d.cts → index-QDfAzfWY.d.cts} +1 -1
- package/dist/{index-B8ZxUpy4.d.ts → index-QZa0vqFW.d.ts} +1 -1
- package/dist/{index-7A3j-6Np.d.cts → index-oY3-BSwC.d.cts} +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +8 -8
- package/dist/isRecord-CwlfDtHp.cjs +16 -0
- package/dist/isRecord-CwlfDtHp.cjs.map +1 -0
- package/dist/isRecord-DaSp13D_.js +11 -0
- package/dist/isRecord-DaSp13D_.js.map +1 -0
- package/dist/{json-DeqPhPUQ.js → json-IKokiUCp.js} +34 -19
- package/dist/json-IKokiUCp.js.map +1 -0
- package/dist/{json-KV2VhBue.cjs → json-mEYdjumm.cjs} +34 -19
- package/dist/json-mEYdjumm.cjs.map +1 -0
- package/dist/json.cjs +1 -1
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/json.js +1 -1
- package/dist/{macro-3uGSg-ic.js → macro-DhgoqDs6.js} +2 -2
- package/dist/{macro-3uGSg-ic.js.map → macro-DhgoqDs6.js.map} +1 -1
- package/dist/{macro-Ywn4-0s5.cjs → macro-h3bm9G48.cjs} +2 -2
- package/dist/{macro-Ywn4-0s5.cjs.map → macro-h3bm9G48.cjs.map} +1 -1
- package/dist/macro.cjs +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/macro.js +1 -1
- package/dist/{node-BeccjrHH.cjs → node-Dhh4jTDv.cjs} +2 -2
- package/dist/{node-BeccjrHH.cjs.map → node-Dhh4jTDv.cjs.map} +1 -1
- package/dist/{node-Dm56432_.js → node-Dy0mq_hi.js} +2 -2
- package/dist/{node-Dm56432_.js.map → node-Dy0mq_hi.js.map} +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{nodes-KgbYiyJQ.js → nodes-B-MW8yk-.js} +2 -2
- package/dist/{nodes-KgbYiyJQ.js.map → nodes-B-MW8yk-.js.map} +1 -1
- package/dist/{nodes-BGxHocS_.cjs → nodes-BjVv21pb.cjs} +12 -12
- package/dist/{nodes-BGxHocS_.cjs.map → nodes-BjVv21pb.cjs.map} +1 -1
- package/dist/promise-DMQPWp6M.cjs.map +1 -1
- package/dist/promise-bi4pc8Xr.js.map +1 -1
- package/dist/{schema-XGRiAvok.cjs → schema-CMe0Dvgd.cjs} +2 -2
- package/dist/{schema-XGRiAvok.cjs.map → schema-CMe0Dvgd.cjs.map} +1 -1
- package/dist/{schema-B05JSQRq.js → schema-CVIk19Mh.js} +2 -2
- package/dist/{schema-B05JSQRq.js.map → schema-CVIk19Mh.js.map} +1 -1
- package/dist/schema.cjs +2 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/{visitor-xxcbpM5-.d.ts → visitor-BWHpwRgc.d.ts} +2 -2
- package/dist/{visitor-BIldddZd.d.cts → visitor-CPlsMCPZ.d.cts} +2 -2
- package/dist/{visitor-DA5yfOJz.js → visitor-CitcdWu0.js} +5 -10
- package/dist/visitor-CitcdWu0.js.map +1 -0
- package/dist/{visitor-DhuKS-7x.cjs → visitor-DT712cxr.cjs} +5 -10
- package/dist/visitor-DT712cxr.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/combineFileMembers-B-mdjXrG.js.map +0 -1
- package/dist/combineFileMembers-DZCKxAN0.cjs.map +0 -1
- package/dist/graph-D6Ffy9YD.cjs.map +0 -1
- package/dist/graph-DWlCmvm6.js.map +0 -1
- package/dist/json-DeqPhPUQ.js.map +0 -1
- package/dist/json-KV2VhBue.cjs.map +0 -1
- package/dist/visitor-DA5yfOJz.js.map +0 -1
- package/dist/visitor-DhuKS-7x.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise-bi4pc8Xr.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\nclass BoundedStore<TKey, TValue> implements Store<TKey, TValue> {\n readonly #entry = new Map<TKey, TValue>()\n readonly #max: number\n\n constructor(max: number) {\n this.#max = max\n }\n\n has(key: TKey): boolean {\n return this.#entry.has(key)\n }\n\n get(key: TKey): TValue | undefined {\n return this.#entry.get(key)\n }\n\n set(key: TKey, value: TValue): void {\n if (this.#entry.size >= this.#max) this.#entry.clear()\n this.#entry.set(key, value)\n }\n}\n\nclass LastEntryStore<TKey, TValue> extends BoundedStore<TKey, TValue> {\n constructor() {\n super(1)\n }\n\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 #touch(key: TKey): boolean {\n if (!super.has(key)) return false\n this.set(key, super.get(key) as TValue)\n return true\n }\n\n override has(key: TKey): boolean {\n return this.#touch(key)\n }\n\n override get(key: TKey): TValue | undefined {\n return this.#touch(key) ? super.get(key) : undefined\n }\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 if (max === undefined) return new Map<TKey, TValue>()\n if (max !== 1) return new BoundedStore<TKey, TValue>(max)\n return new LastEntryStore<TKey, TValue>()\n}\n\nmemo.create = createStore\n\nexport type InParallelOptions<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 }: InParallelOptions<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;AAEA,IAAM,eAAN,MAAgE;CACrD,yBAAS,IAAI,IAAkB;CAC/B;CAET,YAAY,KAAa;EACvB,KAAK,OAAO;CACd;CAEA,IAAI,KAAoB;EACtB,OAAO,KAAK,OAAO,IAAI,GAAG;CAC5B;CAEA,IAAI,KAA+B;EACjC,OAAO,KAAK,OAAO,IAAI,GAAG;CAC5B;CAEA,IAAI,KAAW,OAAqB;EAClC,IAAI,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,OAAO,MAAM;EACrD,KAAK,OAAO,IAAI,KAAK,KAAK;CAC5B;AACF;AAEA,IAAM,iBAAN,cAA2C,aAA2B;CACpE,cAAc;EACZ,MAAM,CAAC;CACT;CAIA,OAAO,KAAoB;EACzB,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACtC,OAAO;CACT;CAES,IAAI,KAAoB;EAC/B,OAAO,KAAK,OAAO,GAAG;CACxB;CAES,IAAI,KAA+B;EAC1C,OAAO,KAAK,OAAO,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;CAC7C;AACF;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,IAAI,QAAQ,KAAA,GAAW,uBAAO,IAAI,IAAkB;CACpD,IAAI,QAAQ,GAAG,OAAO,IAAI,aAA2B,GAAG;CACxD,OAAO,IAAI,eAA6B;AAC1C;AAEA,KAAK,SAAS"}
|
|
1
|
+
{"version":3,"file":"promise-bi4pc8Xr.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\nclass BoundedStore<TKey, TValue> implements Store<TKey, TValue> {\n readonly #entry = new Map<TKey, TValue>()\n readonly #max: number\n\n constructor(max: number) {\n this.#max = max\n }\n\n has(key: TKey): boolean {\n return this.#entry.has(key)\n }\n\n get(key: TKey): TValue | undefined {\n return this.#entry.get(key)\n }\n\n set(key: TKey, value: TValue): void {\n if (this.#entry.size >= this.#max) this.#entry.clear()\n this.#entry.set(key, value)\n }\n}\n\nclass LastEntryStore<TKey, TValue> extends BoundedStore<TKey, TValue> {\n constructor() {\n super(1)\n }\n\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 #touch(key: TKey): boolean {\n if (!super.has(key)) return false\n this.set(key, super.get(key) as TValue)\n return true\n }\n\n override has(key: TKey): boolean {\n return this.#touch(key)\n }\n\n override get(key: TKey): TValue | undefined {\n return this.#touch(key) ? super.get(key) : undefined\n }\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 if (max === undefined) return new Map<TKey, TValue>()\n if (max !== 1) return new BoundedStore<TKey, TValue>(max)\n return new LastEntryStore<TKey, TValue>()\n}\n\nmemo.create = createStore\n\nexport type InParallelOptions<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 * @throws {RangeError} When `limit` is not a positive whole number, which would run no item at all.\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 }: InParallelOptions<TItem>): Promise<void> {\n if (!Number.isInteger(limit) || limit < 1) throw new RangeError(`inParallel needs a limit of 1 or more, got ${limit}`)\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;AAEA,IAAM,eAAN,MAAgE;CACrD,yBAAS,IAAI,IAAkB;CAC/B;CAET,YAAY,KAAa;EACvB,KAAK,OAAO;CACd;CAEA,IAAI,KAAoB;EACtB,OAAO,KAAK,OAAO,IAAI,GAAG;CAC5B;CAEA,IAAI,KAA+B;EACjC,OAAO,KAAK,OAAO,IAAI,GAAG;CAC5B;CAEA,IAAI,KAAW,OAAqB;EAClC,IAAI,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,OAAO,MAAM;EACrD,KAAK,OAAO,IAAI,KAAK,KAAK;CAC5B;AACF;AAEA,IAAM,iBAAN,cAA2C,aAA2B;CACpE,cAAc;EACZ,MAAM,CAAC;CACT;CAIA,OAAO,KAAoB;EACzB,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACtC,OAAO;CACT;CAES,IAAI,KAAoB;EAC/B,OAAO,KAAK,OAAO,GAAG;CACxB;CAES,IAAI,KAA+B;EAC1C,OAAO,KAAK,OAAO,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;CAC7C;AACF;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,IAAI,QAAQ,KAAA,GAAW,uBAAO,IAAI,IAAkB;CACpD,IAAI,QAAQ,GAAG,OAAO,IAAI,aAA2B,GAAG;CACxD,OAAO,IAAI,eAA6B;AAC1C;AAEA,KAAK,SAAS"}
|
|
@@ -2,7 +2,7 @@ const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
|
2
2
|
const require_optionality = require("./optionality-C-qULYxo.cjs");
|
|
3
3
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
4
4
|
const require_guards = require("./guards-4drgx10i.cjs");
|
|
5
|
-
const require_visitor = require("./visitor-
|
|
5
|
+
const require_visitor = require("./visitor-DT712cxr.cjs");
|
|
6
6
|
const require_ref = require("./ref-CGeCLkAk.cjs");
|
|
7
7
|
const require_promise = require("./promise-DMQPWp6M.cjs");
|
|
8
8
|
// src/schema/is.ts
|
|
@@ -211,4 +211,4 @@ Object.defineProperty(exports, "schema_exports", {
|
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
-
//# sourceMappingURL=schema-
|
|
214
|
+
//# sourceMappingURL=schema-CMe0Dvgd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-XGRiAvok.cjs","names":["narrowSchema","mergeSchema","memo"],"sources":["../src/schema/is.ts","../src/utils/schemaProperties.ts","../src/schema/index.ts"],"sourcesContent":["import { narrowSchema } from '../guards.ts'\nimport type { SchemaNode, SchemaType } from '../nodes/schema.ts'\nimport { mergeSchema } from '../ref/index.ts'\n\n/** `string` prints as a plain `string`, `text` is a non-blob string primitive, `const` a one-value enum, `enumLike` an enum or union of them, `untyped` is `void`, `any` or `unknown`. */\nexport type SchemaKind = 'binary' | 'string' | 'text' | 'scalar' | 'const' | 'enumLike' | 'untyped'\n\n/** `ref` jumps to a resolved ref's target, `array` matches when some item matches. */\nexport type SchemaFollow = 'ref' | 'array'\n\nexport type IsOptions = {\n /** Links to look through. Following repeats and stops on a ref cycle. */\n follow?: ReadonlyArray<SchemaFollow>\n}\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'])\nconst scalarTypes = new Set<SchemaType>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst untypedTypes = new Set<SchemaType>(['void', 'any', 'unknown'])\n\nconst kinds: Record<SchemaKind, (node: SchemaNode, test: (child: SchemaNode) => boolean) => boolean> = {\n binary: (node) => node.type === 'blob',\n string: (node) => {\n if (plainStringTypes.has(node.type)) return true\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n return temporal ? temporal.representation !== 'date' : false\n },\n text: (node) => node.type !== 'blob' && node.primitive === 'string',\n scalar: (node) => scalarTypes.has(node.type),\n const: (node) => node.type === 'enum' && (node.namedEnumValues ?? node.enumValues ?? []).length === 1,\n enumLike: (node, test) => node.type === 'enum' || (node.type === 'union' && !!node.members?.length && node.members.every(test)),\n untyped: (node) => untypedTypes.has(node.type),\n}\n\n/** Whether a schema is of `kind`, looking at the node itself unless `follow` names links to look through. */\nexport function is(node: SchemaNode, kind: SchemaKind, { follow = [] }: IsOptions = {}): boolean {\n // `path` holds the ref targets above `current`, so a cycle stops without hiding a target a sibling branch reaches.\n const test = (current: SchemaNode, path: ReadonlySet<SchemaNode>): boolean => {\n if (follow.includes('ref') && current.type === 'ref' && current.schema) {\n return !path.has(current.schema) && test(mergeSchema(current), new Set(path).add(current.schema))\n }\n const child = (next: SchemaNode) => test(next, path)\n return kinds[kind](current, child) || (follow.includes('array') && current.type === 'array' && (current.items ?? []).some(child))\n }\n\n return test(node, new Set())\n}\n","import { memo } from '@internals/utils'\nimport type { PropertyNode } from '../nodes/property.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Finds every matching property exposed by an object, resolved reference, or intersection.\n *\n * References are followed through their parsed `schema`. Circular references terminate without\n * revisiting a node. Unions are not traversed because a property on one branch does not describe\n * every branch.\n *\n * @example Faker discriminator narrowing\n * ```ts\n * const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>\n * getSchemaLiteralValues(schema),\n * )\n * const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`\n * ```\n *\n * @example Zod discriminated unions\n * ```ts\n * const canDiscriminate = union.members?.every(\n * (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,\n * )\n * const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`\n * ```\n *\n * @example TypeScript property lookup\n * ```ts\n * const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })\n * const statusSchemas = properties.map((property) => print(property.schema))\n * ```\n */\nexport function resolveSchemaProperties({ node, propertyName }: { node: SchemaNode; propertyName: string }): ReadonlyArray<PropertyNode> {\n const properties: Array<PropertyNode> = []\n walkSchema(node, 'intersection', (current) => {\n if (current.type !== 'object') return\n const property = current.properties.find((candidate) => candidate.name === propertyName)\n if (property) properties.push(property)\n })\n return properties\n}\n\nfunction walkSchema(node: SchemaNode, through: 'union' | 'intersection', visit: (schema: SchemaNode) => void): void {\n const visited = new WeakSet<SchemaNode>()\n\n function walk(current: SchemaNode | null | undefined): void {\n if (!current || visited.has(current)) return\n visited.add(current)\n visit(current)\n\n if (current.type === 'ref') return walk(current.schema)\n if (current.type === through) for (const member of current.members ?? []) walk(member)\n }\n\n walk(node)\n}\n\n/**\n * Reads the unique literal values represented by an enum, resolved reference, or union.\n *\n * Named enum values take precedence over simple enum values, matching how renderers consume\n * `EnumSchemaNode`.\n *\n * @example\n * ```ts\n * const values = getSchemaLiteralValues(enumNode)\n * // ['cat', 'dog']\n * ```\n */\nexport function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<LiteralValue> {\n return memo(literalValues, node, () => {\n const values = new Set<LiteralValue>()\n walkSchema(node, 'union', (current) => {\n if (current.type !== 'enum') return\n for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value)\n })\n return Object.freeze([...values])\n })\n}\n\nexport type LiteralValue = string | number | boolean | null\n\n// Printers read an enum's values each time they print it.\nconst literalValues = memo.create<SchemaNode, ReadonlyArray<LiteralValue>>({ weak: true })\n\n// Names of every property an object, resolved reference, or intersection exposes.\nfunction collectPropertyNames(node: SchemaNode): Set<string> {\n const names = new Set<string>()\n walkSchema(node, 'intersection', (current) => {\n if (current.type === 'object') for (const property of current.properties) names.add(property.name)\n })\n return names\n}\n\n/**\n * Infers an implicit discriminator: a property every member exposes with a distinct single\n * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.\n */\nexport function inferDiscriminatorPropertyName(members: ReadonlyArray<SchemaNode>): string | undefined {\n if (members.length < 2) return undefined\n\n let candidates: Set<string> | undefined\n for (const member of members) {\n const names = collectPropertyNames(member)\n candidates = candidates ? new Set([...candidates].filter((name) => names.has(name))) : names\n }\n\n for (const name of candidates ?? []) {\n const values = members.map((member) => {\n const literals = new Set(resolveSchemaProperties({ node: member, propertyName: name }).flatMap((property) => getSchemaLiteralValues(property.schema)))\n return literals.size === 1 ? [...literals][0] : undefined\n })\n\n if (values.every((value) => value !== undefined) && new Set(values).size === members.length) {\n return name\n }\n }\n\n return undefined\n}\n","export { applyOptionality } from '../optionality.ts'\nexport { schemaTypes as types } from '../constants.ts'\nexport { narrowSchema as narrow } from '../guards.ts'\nexport { findSchema as find } from '../visitor.ts'\nexport { getEmbeddedJson } from './embeddedJson.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { is } from './is.ts'\n\nexport { is } from './is.ts'\nexport type { IsOptions, SchemaFollow, SchemaKind } from './is.ts'\nexport {\n getSchemaLiteralValues as getLiterals,\n inferDiscriminatorPropertyName as inferDiscriminator,\n resolveSchemaProperties as findProperties,\n} from '../utils/schemaProperties.ts'\n\n/** @deprecated Use `ast.schema.is(node, 'string')`. Removed in Kubb v6. */\nexport function isString(node: SchemaNode): boolean {\n return is(node, 'string')\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,mCAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAC;AAC3F,MAAM,8BAAc,IAAI,IAAgB;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAgB;CAAC;CAAQ;CAAO;AAAS,CAAC;AAEnE,MAAM,QAAiG;CACrG,SAAS,SAAS,KAAK,SAAS;CAChC,SAAS,SAAS;EAChB,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAAG,OAAO;EAC5C,MAAM,WAAWA,eAAAA,aAAa,MAAM,MAAM,KAAKA,eAAAA,aAAa,MAAM,MAAM;EACxE,OAAO,WAAW,SAAS,mBAAmB,SAAS;CACzD;CACA,OAAO,SAAS,KAAK,SAAS,UAAU,KAAK,cAAc;CAC3D,SAAS,SAAS,YAAY,IAAI,KAAK,IAAI;CAC3C,QAAQ,SAAS,KAAK,SAAS,WAAW,KAAK,mBAAmB,KAAK,cAAc,CAAC,EAAA,CAAG,WAAW;CAC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AC,SAAS,aAAa,uBAAuB,SAAS,MAAM,CAAC,CAAC;GACrJ,OAAO,SAAS,SAAS,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,KAAA;EAClD,CAAC;EAED,IAAI,OAAO,OAAO,UAAU,UAAU,KAAA,CAAS,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,QAAQ,QACnF,OAAO;CAEX;AAGF;;;;;;;;;;;;;;;ACvGA,SAAgB,SAAS,MAA2B;CAClD,OAAO,GAAG,MAAM,QAAQ;AAC1B"}
|
|
1
|
+
{"version":3,"file":"schema-CMe0Dvgd.cjs","names":["narrowSchema","mergeSchema","memo"],"sources":["../src/schema/is.ts","../src/utils/schemaProperties.ts","../src/schema/index.ts"],"sourcesContent":["import { narrowSchema } from '../guards.ts'\nimport type { SchemaNode, SchemaType } from '../nodes/schema.ts'\nimport { mergeSchema } from '../ref/index.ts'\n\n/** `string` prints as a plain `string`, `text` is a non-blob string primitive, `const` a one-value enum, `enumLike` an enum or union of them, `untyped` is `void`, `any` or `unknown`. */\nexport type SchemaKind = 'binary' | 'string' | 'text' | 'scalar' | 'const' | 'enumLike' | 'untyped'\n\n/** `ref` jumps to a resolved ref's target, `array` matches when some item matches. */\nexport type SchemaFollow = 'ref' | 'array'\n\nexport type IsOptions = {\n /** Links to look through. Following repeats and stops on a ref cycle. */\n follow?: ReadonlyArray<SchemaFollow>\n}\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'])\nconst scalarTypes = new Set<SchemaType>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst untypedTypes = new Set<SchemaType>(['void', 'any', 'unknown'])\n\nconst kinds: Record<SchemaKind, (node: SchemaNode, test: (child: SchemaNode) => boolean) => boolean> = {\n binary: (node) => node.type === 'blob',\n string: (node) => {\n if (plainStringTypes.has(node.type)) return true\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n return temporal ? temporal.representation !== 'date' : false\n },\n text: (node) => node.type !== 'blob' && node.primitive === 'string',\n scalar: (node) => scalarTypes.has(node.type),\n const: (node) => node.type === 'enum' && (node.namedEnumValues ?? node.enumValues ?? []).length === 1,\n enumLike: (node, test) => node.type === 'enum' || (node.type === 'union' && !!node.members?.length && node.members.every(test)),\n untyped: (node) => untypedTypes.has(node.type),\n}\n\n/** Whether a schema is of `kind`, looking at the node itself unless `follow` names links to look through. */\nexport function is(node: SchemaNode, kind: SchemaKind, { follow = [] }: IsOptions = {}): boolean {\n // `path` holds the ref targets above `current`, so a cycle stops without hiding a target a sibling branch reaches.\n const test = (current: SchemaNode, path: ReadonlySet<SchemaNode>): boolean => {\n if (follow.includes('ref') && current.type === 'ref' && current.schema) {\n return !path.has(current.schema) && test(mergeSchema(current), new Set(path).add(current.schema))\n }\n const child = (next: SchemaNode) => test(next, path)\n return kinds[kind](current, child) || (follow.includes('array') && current.type === 'array' && (current.items ?? []).some(child))\n }\n\n return test(node, new Set())\n}\n","import { memo } from '@internals/utils'\nimport type { PropertyNode } from '../nodes/property.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Finds every matching property exposed by an object, resolved reference, or intersection.\n *\n * References are followed through their parsed `schema`. Circular references terminate without\n * revisiting a node. Unions are not traversed because a property on one branch does not describe\n * every branch.\n *\n * @example Faker discriminator narrowing\n * ```ts\n * const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>\n * getSchemaLiteralValues(schema),\n * )\n * const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`\n * ```\n *\n * @example Zod discriminated unions\n * ```ts\n * const canDiscriminate = union.members?.every(\n * (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,\n * )\n * const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`\n * ```\n *\n * @example TypeScript property lookup\n * ```ts\n * const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })\n * const statusSchemas = properties.map((property) => print(property.schema))\n * ```\n */\nexport function resolveSchemaProperties({ node, propertyName }: { node: SchemaNode; propertyName: string }): ReadonlyArray<PropertyNode> {\n const properties: Array<PropertyNode> = []\n walkSchema(node, 'intersection', (current) => {\n if (current.type !== 'object') return\n const property = current.properties.find((candidate) => candidate.name === propertyName)\n if (property) properties.push(property)\n })\n return properties\n}\n\nfunction walkSchema(node: SchemaNode, through: 'union' | 'intersection', visit: (schema: SchemaNode) => void): void {\n const visited = new WeakSet<SchemaNode>()\n\n function walk(current: SchemaNode | null | undefined): void {\n if (!current || visited.has(current)) return\n visited.add(current)\n visit(current)\n\n if (current.type === 'ref') return walk(current.schema)\n if (current.type === through) for (const member of current.members ?? []) walk(member)\n }\n\n walk(node)\n}\n\n/**\n * Reads the unique literal values represented by an enum, resolved reference, or union.\n *\n * Named enum values take precedence over simple enum values, matching how renderers consume\n * `EnumSchemaNode`.\n *\n * @example\n * ```ts\n * const values = getSchemaLiteralValues(enumNode)\n * // ['cat', 'dog']\n * ```\n */\nexport function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<LiteralValue> {\n return memo(literalValues, node, () => {\n const values = new Set<LiteralValue>()\n walkSchema(node, 'union', (current) => {\n if (current.type !== 'enum') return\n for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value)\n })\n return Object.freeze([...values])\n })\n}\n\nexport type LiteralValue = string | number | boolean | null\n\n// Printers read an enum's values each time they print it.\nconst literalValues = memo.create<SchemaNode, ReadonlyArray<LiteralValue>>({ weak: true })\n\n// Names of every property an object, resolved reference, or intersection exposes.\nfunction collectPropertyNames(node: SchemaNode): Set<string> {\n const names = new Set<string>()\n walkSchema(node, 'intersection', (current) => {\n if (current.type === 'object') for (const property of current.properties) names.add(property.name)\n })\n return names\n}\n\n/**\n * Infers an implicit discriminator: a property every member exposes with a distinct single\n * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.\n */\nexport function inferDiscriminatorPropertyName(members: ReadonlyArray<SchemaNode>): string | undefined {\n if (members.length < 2) return undefined\n\n let candidates: Set<string> | undefined\n for (const member of members) {\n const names = collectPropertyNames(member)\n candidates = candidates ? new Set([...candidates].filter((name) => names.has(name))) : names\n }\n\n for (const name of candidates ?? []) {\n const values = members.map((member) => {\n const literals = new Set(resolveSchemaProperties({ node: member, propertyName: name }).flatMap((property) => getSchemaLiteralValues(property.schema)))\n return literals.size === 1 ? [...literals][0] : undefined\n })\n\n if (values.every((value) => value !== undefined) && new Set(values).size === members.length) {\n return name\n }\n }\n\n return undefined\n}\n","export { applyOptionality } from '../optionality.ts'\nexport { schemaTypes as types } from '../constants.ts'\nexport { narrowSchema as narrow } from '../guards.ts'\nexport { findSchema as find } from '../visitor.ts'\nexport { getEmbeddedJson } from './embeddedJson.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { is } from './is.ts'\n\nexport { is } from './is.ts'\nexport type { IsOptions, SchemaFollow, SchemaKind } from './is.ts'\nexport {\n getSchemaLiteralValues as getLiterals,\n inferDiscriminatorPropertyName as inferDiscriminator,\n resolveSchemaProperties as findProperties,\n} from '../utils/schemaProperties.ts'\n\n/** @deprecated Use `ast.schema.is(node, 'string')`. Removed in Kubb v6. */\nexport function isString(node: SchemaNode): boolean {\n return is(node, 'string')\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,mCAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAC;AAC3F,MAAM,8BAAc,IAAI,IAAgB;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAgB;CAAC;CAAQ;CAAO;AAAS,CAAC;AAEnE,MAAM,QAAiG;CACrG,SAAS,SAAS,KAAK,SAAS;CAChC,SAAS,SAAS;EAChB,IAAI,iBAAiB,IAAI,KAAK,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,SAAS;EAC5B,MAAM,QAAQ,qBAAqB,MAAM;EACzC,aAAa,aAAa,IAAI,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,QAAQ,SAAS,MAAM,IAAI,IAAI,CAAC,CAAC,IAAI;CACzF;CAEA,KAAK,MAAM,QAAQ,cAAc,CAAC,GAAG;EACnC,MAAM,SAAS,QAAQ,KAAK,WAAW;GACrC,MAAM,WAAW,IAAI,IAAI,wBAAwB;IAAE,MAAM;IAAQ,cAAc;GAAK,CAAC,CAAC,CAAC,SAAS,aAAa,uBAAuB,SAAS,MAAM,CAAC,CAAC;GACrJ,OAAO,SAAS,SAAS,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,KAAA;EAClD,CAAC;EAED,IAAI,OAAO,OAAO,UAAU,UAAU,KAAA,CAAS,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,QAAQ,QACnF,OAAO;CAEX;AAGF;;;;;;;;;;;;;;;ACvGA,SAAgB,SAAS,MAA2B;CAClD,OAAO,GAAG,MAAM,QAAQ;AAC1B"}
|
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
|
2
2
|
import { t as applyOptionality } from "./optionality-FkRredTC.js";
|
|
3
3
|
import { n as schemaTypes } from "./constants-UorsTFsa.js";
|
|
4
4
|
import { n as narrowSchema } from "./guards-DKw4uwc5.js";
|
|
5
|
-
import { n as findSchema, o as getEmbeddedJson } from "./visitor-
|
|
5
|
+
import { n as findSchema, o as getEmbeddedJson } from "./visitor-CitcdWu0.js";
|
|
6
6
|
import { n as mergeSchema } from "./ref-BU7sfEFr.js";
|
|
7
7
|
import { t as memo } from "./promise-bi4pc8Xr.js";
|
|
8
8
|
// src/schema/is.ts
|
|
@@ -176,4 +176,4 @@ function isString(node) {
|
|
|
176
176
|
}
|
|
177
177
|
export { resolveSchemaProperties as a, inferDiscriminatorPropertyName as i, schema_exports as n, is as o, getSchemaLiteralValues as r, isString as t };
|
|
178
178
|
|
|
179
|
-
//# sourceMappingURL=schema-
|
|
179
|
+
//# sourceMappingURL=schema-CVIk19Mh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-B05JSQRq.js","names":[],"sources":["../src/schema/is.ts","../src/utils/schemaProperties.ts","../src/schema/index.ts"],"sourcesContent":["import { narrowSchema } from '../guards.ts'\nimport type { SchemaNode, SchemaType } from '../nodes/schema.ts'\nimport { mergeSchema } from '../ref/index.ts'\n\n/** `string` prints as a plain `string`, `text` is a non-blob string primitive, `const` a one-value enum, `enumLike` an enum or union of them, `untyped` is `void`, `any` or `unknown`. */\nexport type SchemaKind = 'binary' | 'string' | 'text' | 'scalar' | 'const' | 'enumLike' | 'untyped'\n\n/** `ref` jumps to a resolved ref's target, `array` matches when some item matches. */\nexport type SchemaFollow = 'ref' | 'array'\n\nexport type IsOptions = {\n /** Links to look through. Following repeats and stops on a ref cycle. */\n follow?: ReadonlyArray<SchemaFollow>\n}\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'])\nconst scalarTypes = new Set<SchemaType>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst untypedTypes = new Set<SchemaType>(['void', 'any', 'unknown'])\n\nconst kinds: Record<SchemaKind, (node: SchemaNode, test: (child: SchemaNode) => boolean) => boolean> = {\n binary: (node) => node.type === 'blob',\n string: (node) => {\n if (plainStringTypes.has(node.type)) return true\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n return temporal ? temporal.representation !== 'date' : false\n },\n text: (node) => node.type !== 'blob' && node.primitive === 'string',\n scalar: (node) => scalarTypes.has(node.type),\n const: (node) => node.type === 'enum' && (node.namedEnumValues ?? node.enumValues ?? []).length === 1,\n enumLike: (node, test) => node.type === 'enum' || (node.type === 'union' && !!node.members?.length && node.members.every(test)),\n untyped: (node) => untypedTypes.has(node.type),\n}\n\n/** Whether a schema is of `kind`, looking at the node itself unless `follow` names links to look through. */\nexport function is(node: SchemaNode, kind: SchemaKind, { follow = [] }: IsOptions = {}): boolean {\n // `path` holds the ref targets above `current`, so a cycle stops without hiding a target a sibling branch reaches.\n const test = (current: SchemaNode, path: ReadonlySet<SchemaNode>): boolean => {\n if (follow.includes('ref') && current.type === 'ref' && current.schema) {\n return !path.has(current.schema) && test(mergeSchema(current), new Set(path).add(current.schema))\n }\n const child = (next: SchemaNode) => test(next, path)\n return kinds[kind](current, child) || (follow.includes('array') && current.type === 'array' && (current.items ?? []).some(child))\n }\n\n return test(node, new Set())\n}\n","import { memo } from '@internals/utils'\nimport type { PropertyNode } from '../nodes/property.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Finds every matching property exposed by an object, resolved reference, or intersection.\n *\n * References are followed through their parsed `schema`. Circular references terminate without\n * revisiting a node. Unions are not traversed because a property on one branch does not describe\n * every branch.\n *\n * @example Faker discriminator narrowing\n * ```ts\n * const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>\n * getSchemaLiteralValues(schema),\n * )\n * const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`\n * ```\n *\n * @example Zod discriminated unions\n * ```ts\n * const canDiscriminate = union.members?.every(\n * (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,\n * )\n * const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`\n * ```\n *\n * @example TypeScript property lookup\n * ```ts\n * const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })\n * const statusSchemas = properties.map((property) => print(property.schema))\n * ```\n */\nexport function resolveSchemaProperties({ node, propertyName }: { node: SchemaNode; propertyName: string }): ReadonlyArray<PropertyNode> {\n const properties: Array<PropertyNode> = []\n walkSchema(node, 'intersection', (current) => {\n if (current.type !== 'object') return\n const property = current.properties.find((candidate) => candidate.name === propertyName)\n if (property) properties.push(property)\n })\n return properties\n}\n\nfunction walkSchema(node: SchemaNode, through: 'union' | 'intersection', visit: (schema: SchemaNode) => void): void {\n const visited = new WeakSet<SchemaNode>()\n\n function walk(current: SchemaNode | null | undefined): void {\n if (!current || visited.has(current)) return\n visited.add(current)\n visit(current)\n\n if (current.type === 'ref') return walk(current.schema)\n if (current.type === through) for (const member of current.members ?? []) walk(member)\n }\n\n walk(node)\n}\n\n/**\n * Reads the unique literal values represented by an enum, resolved reference, or union.\n *\n * Named enum values take precedence over simple enum values, matching how renderers consume\n * `EnumSchemaNode`.\n *\n * @example\n * ```ts\n * const values = getSchemaLiteralValues(enumNode)\n * // ['cat', 'dog']\n * ```\n */\nexport function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<LiteralValue> {\n return memo(literalValues, node, () => {\n const values = new Set<LiteralValue>()\n walkSchema(node, 'union', (current) => {\n if (current.type !== 'enum') return\n for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value)\n })\n return Object.freeze([...values])\n })\n}\n\nexport type LiteralValue = string | number | boolean | null\n\n// Printers read an enum's values each time they print it.\nconst literalValues = memo.create<SchemaNode, ReadonlyArray<LiteralValue>>({ weak: true })\n\n// Names of every property an object, resolved reference, or intersection exposes.\nfunction collectPropertyNames(node: SchemaNode): Set<string> {\n const names = new Set<string>()\n walkSchema(node, 'intersection', (current) => {\n if (current.type === 'object') for (const property of current.properties) names.add(property.name)\n })\n return names\n}\n\n/**\n * Infers an implicit discriminator: a property every member exposes with a distinct single\n * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.\n */\nexport function inferDiscriminatorPropertyName(members: ReadonlyArray<SchemaNode>): string | undefined {\n if (members.length < 2) return undefined\n\n let candidates: Set<string> | undefined\n for (const member of members) {\n const names = collectPropertyNames(member)\n candidates = candidates ? new Set([...candidates].filter((name) => names.has(name))) : names\n }\n\n for (const name of candidates ?? []) {\n const values = members.map((member) => {\n const literals = new Set(resolveSchemaProperties({ node: member, propertyName: name }).flatMap((property) => getSchemaLiteralValues(property.schema)))\n return literals.size === 1 ? [...literals][0] : undefined\n })\n\n if (values.every((value) => value !== undefined) && new Set(values).size === members.length) {\n return name\n }\n }\n\n return undefined\n}\n","export { applyOptionality } from '../optionality.ts'\nexport { schemaTypes as types } from '../constants.ts'\nexport { narrowSchema as narrow } from '../guards.ts'\nexport { findSchema as find } from '../visitor.ts'\nexport { getEmbeddedJson } from './embeddedJson.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { is } from './is.ts'\n\nexport { is } from './is.ts'\nexport type { IsOptions, SchemaFollow, SchemaKind } from './is.ts'\nexport {\n getSchemaLiteralValues as getLiterals,\n inferDiscriminatorPropertyName as inferDiscriminator,\n resolveSchemaProperties as findProperties,\n} from '../utils/schemaProperties.ts'\n\n/** @deprecated Use `ast.schema.is(node, 'string')`. Removed in Kubb v6. */\nexport function isString(node: SchemaNode): boolean {\n return is(node, 'string')\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,mCAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAC;AAC3F,MAAM,8BAAc,IAAI,IAAgB;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAgB;CAAC;CAAQ;CAAO;AAAS,CAAC;AAEnE,MAAM,QAAiG;CACrG,SAAS,SAAS,KAAK,SAAS;CAChC,SAAS,SAAS;EAChB,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAAG,OAAO;EAC5C,MAAM,WAAW,aAAa,MAAM,MAAM,KAAK,aAAa,MAAM,MAAM;EACxE,OAAO,WAAW,SAAS,mBAAmB,SAAS;CACzD;CACA,OAAO,SAAS,KAAK,SAAS,UAAU,KAAK,cAAc;CAC3D,SAAS,SAAS,YAAY,IAAI,KAAK,IAAI;CAC3C,QAAQ,SAAS,KAAK,SAAS,WAAW,KAAK,mB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K,CAAC,CAAC,CAAC,SAAS,aAAa,uBAAuB,SAAS,MAAM,CAAC,CAAC;GACrJ,OAAO,SAAS,SAAS,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,KAAA;EAClD,CAAC;EAED,IAAI,OAAO,OAAO,UAAU,UAAU,KAAA,CAAS,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,QAAQ,QACnF,OAAO;CAEX;AAGF;;;;;;;;;;;;;;;ACvGA,SAAgB,SAAS,MAA2B;CAClD,OAAO,GAAG,MAAM,QAAQ;AAC1B"}
|
|
1
|
+
{"version":3,"file":"schema-CVIk19Mh.js","names":[],"sources":["../src/schema/is.ts","../src/utils/schemaProperties.ts","../src/schema/index.ts"],"sourcesContent":["import { narrowSchema } from '../guards.ts'\nimport type { SchemaNode, SchemaType } from '../nodes/schema.ts'\nimport { mergeSchema } from '../ref/index.ts'\n\n/** `string` prints as a plain `string`, `text` is a non-blob string primitive, `const` a one-value enum, `enumLike` an enum or union of them, `untyped` is `void`, `any` or `unknown`. */\nexport type SchemaKind = 'binary' | 'string' | 'text' | 'scalar' | 'const' | 'enumLike' | 'untyped'\n\n/** `ref` jumps to a resolved ref's target, `array` matches when some item matches. */\nexport type SchemaFollow = 'ref' | 'array'\n\nexport type IsOptions = {\n /** Links to look through. Following repeats and stops on a ref cycle. */\n follow?: ReadonlyArray<SchemaFollow>\n}\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'])\nconst scalarTypes = new Set<SchemaType>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst untypedTypes = new Set<SchemaType>(['void', 'any', 'unknown'])\n\nconst kinds: Record<SchemaKind, (node: SchemaNode, test: (child: SchemaNode) => boolean) => boolean> = {\n binary: (node) => node.type === 'blob',\n string: (node) => {\n if (plainStringTypes.has(node.type)) return true\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n return temporal ? temporal.representation !== 'date' : false\n },\n text: (node) => node.type !== 'blob' && node.primitive === 'string',\n scalar: (node) => scalarTypes.has(node.type),\n const: (node) => node.type === 'enum' && (node.namedEnumValues ?? node.enumValues ?? []).length === 1,\n enumLike: (node, test) => node.type === 'enum' || (node.type === 'union' && !!node.members?.length && node.members.every(test)),\n untyped: (node) => untypedTypes.has(node.type),\n}\n\n/** Whether a schema is of `kind`, looking at the node itself unless `follow` names links to look through. */\nexport function is(node: SchemaNode, kind: SchemaKind, { follow = [] }: IsOptions = {}): boolean {\n // `path` holds the ref targets above `current`, so a cycle stops without hiding a target a sibling branch reaches.\n const test = (current: SchemaNode, path: ReadonlySet<SchemaNode>): boolean => {\n if (follow.includes('ref') && current.type === 'ref' && current.schema) {\n return !path.has(current.schema) && test(mergeSchema(current), new Set(path).add(current.schema))\n }\n const child = (next: SchemaNode) => test(next, path)\n return kinds[kind](current, child) || (follow.includes('array') && current.type === 'array' && (current.items ?? []).some(child))\n }\n\n return test(node, new Set())\n}\n","import { memo } from '@internals/utils'\nimport type { PropertyNode } from '../nodes/property.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Finds every matching property exposed by an object, resolved reference, or intersection.\n *\n * References are followed through their parsed `schema`. Circular references terminate without\n * revisiting a node. Unions are not traversed because a property on one branch does not describe\n * every branch.\n *\n * @example Faker discriminator narrowing\n * ```ts\n * const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>\n * getSchemaLiteralValues(schema),\n * )\n * const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`\n * ```\n *\n * @example Zod discriminated unions\n * ```ts\n * const canDiscriminate = union.members?.every(\n * (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,\n * )\n * const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`\n * ```\n *\n * @example TypeScript property lookup\n * ```ts\n * const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })\n * const statusSchemas = properties.map((property) => print(property.schema))\n * ```\n */\nexport function resolveSchemaProperties({ node, propertyName }: { node: SchemaNode; propertyName: string }): ReadonlyArray<PropertyNode> {\n const properties: Array<PropertyNode> = []\n walkSchema(node, 'intersection', (current) => {\n if (current.type !== 'object') return\n const property = current.properties.find((candidate) => candidate.name === propertyName)\n if (property) properties.push(property)\n })\n return properties\n}\n\nfunction walkSchema(node: SchemaNode, through: 'union' | 'intersection', visit: (schema: SchemaNode) => void): void {\n const visited = new WeakSet<SchemaNode>()\n\n function walk(current: SchemaNode | null | undefined): void {\n if (!current || visited.has(current)) return\n visited.add(current)\n visit(current)\n\n if (current.type === 'ref') return walk(current.schema)\n if (current.type === through) for (const member of current.members ?? []) walk(member)\n }\n\n walk(node)\n}\n\n/**\n * Reads the unique literal values represented by an enum, resolved reference, or union.\n *\n * Named enum values take precedence over simple enum values, matching how renderers consume\n * `EnumSchemaNode`.\n *\n * @example\n * ```ts\n * const values = getSchemaLiteralValues(enumNode)\n * // ['cat', 'dog']\n * ```\n */\nexport function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<LiteralValue> {\n return memo(literalValues, node, () => {\n const values = new Set<LiteralValue>()\n walkSchema(node, 'union', (current) => {\n if (current.type !== 'enum') return\n for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value)\n })\n return Object.freeze([...values])\n })\n}\n\nexport type LiteralValue = string | number | boolean | null\n\n// Printers read an enum's values each time they print it.\nconst literalValues = memo.create<SchemaNode, ReadonlyArray<LiteralValue>>({ weak: true })\n\n// Names of every property an object, resolved reference, or intersection exposes.\nfunction collectPropertyNames(node: SchemaNode): Set<string> {\n const names = new Set<string>()\n walkSchema(node, 'intersection', (current) => {\n if (current.type === 'object') for (const property of current.properties) names.add(property.name)\n })\n return names\n}\n\n/**\n * Infers an implicit discriminator: a property every member exposes with a distinct single\n * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.\n */\nexport function inferDiscriminatorPropertyName(members: ReadonlyArray<SchemaNode>): string | undefined {\n if (members.length < 2) return undefined\n\n let candidates: Set<string> | undefined\n for (const member of members) {\n const names = collectPropertyNames(member)\n candidates = candidates ? new Set([...candidates].filter((name) => names.has(name))) : names\n }\n\n for (const name of candidates ?? []) {\n const values = members.map((member) => {\n const literals = new Set(resolveSchemaProperties({ node: member, propertyName: name }).flatMap((property) => getSchemaLiteralValues(property.schema)))\n return literals.size === 1 ? [...literals][0] : undefined\n })\n\n if (values.every((value) => value !== undefined) && new Set(values).size === members.length) {\n return name\n }\n }\n\n return undefined\n}\n","export { applyOptionality } from '../optionality.ts'\nexport { schemaTypes as types } from '../constants.ts'\nexport { narrowSchema as narrow } from '../guards.ts'\nexport { findSchema as find } from '../visitor.ts'\nexport { getEmbeddedJson } from './embeddedJson.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { is } from './is.ts'\n\nexport { is } from './is.ts'\nexport type { IsOptions, SchemaFollow, SchemaKind } from './is.ts'\nexport {\n getSchemaLiteralValues as getLiterals,\n inferDiscriminatorPropertyName as inferDiscriminator,\n resolveSchemaProperties as findProperties,\n} from '../utils/schemaProperties.ts'\n\n/** @deprecated Use `ast.schema.is(node, 'string')`. Removed in Kubb v6. */\nexport function isString(node: SchemaNode): boolean {\n return is(node, 'string')\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,mCAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAC;AAC3F,MAAM,8BAAc,IAAI,IAAgB;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAgB;CAAC;CAAQ;CAAO;AAAS,CAAC;AAEnE,MAAM,QAAiG;CACrG,SAAS,SAAS,KAAK,SAAS;CAChC,SAAS,SAAS;EAChB,IAAI,iBAAiB,IAAI,KAAK,IAAI,G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a,aAAa,IAAI,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,QAAQ,SAAS,MAAM,IAAI,IAAI,CAAC,CAAC,IAAI;CACzF;CAEA,KAAK,MAAM,QAAQ,cAAc,CAAC,GAAG;EACnC,MAAM,SAAS,QAAQ,KAAK,WAAW;GACrC,MAAM,WAAW,IAAI,IAAI,wBAAwB;IAAE,MAAM;IAAQ,cAAc;GAAK,CAAC,CAAC,CAAC,SAAS,aAAa,uBAAuB,SAAS,MAAM,CAAC,CAAC;GACrJ,OAAO,SAAS,SAAS,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,KAAA;EAClD,CAAC;EAED,IAAI,OAAO,OAAO,UAAU,UAAU,KAAA,CAAS,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,QAAQ,QACnF,OAAO;CAEX;AAGF;;;;;;;;;;;;;;;ACvGA,SAAgB,SAAS,MAA2B;CAClD,OAAO,GAAG,MAAM,QAAQ;AAC1B"}
|
package/dist/schema.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
3
|
-
const require_visitor = require("./visitor-
|
|
3
|
+
const require_visitor = require("./visitor-DT712cxr.cjs");
|
|
4
4
|
const require_guards = require("./guards-4drgx10i.cjs");
|
|
5
5
|
const require_optionality = require("./optionality-C-qULYxo.cjs");
|
|
6
|
-
const require_schema = require("./schema-
|
|
6
|
+
const require_schema = require("./schema-CMe0Dvgd.cjs");
|
|
7
7
|
exports.applyOptionality = require_optionality.applyOptionality;
|
|
8
8
|
exports.find = require_visitor.findSchema;
|
|
9
9
|
exports.findProperties = require_schema.resolveSchemaProperties;
|
package/dist/schema.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as schemaTypes } from "./base-CyJhBRMi.cjs";
|
|
2
2
|
import { n as narrowSchema } from "./guards-EpQMJGyF.cjs";
|
|
3
|
-
import { a as resolveSchemaProperties, c as SchemaKind, d as applyOptionality, i as inferDiscriminatorPropertyName, l as is, n as isString, o as IsOptions, r as getSchemaLiteralValues, s as SchemaFollow, u as getEmbeddedJson } from "./index-
|
|
4
|
-
import { o as findSchema } from "./visitor-
|
|
3
|
+
import { a as resolveSchemaProperties, c as SchemaKind, d as applyOptionality, i as inferDiscriminatorPropertyName, l as is, n as isString, o as IsOptions, r as getSchemaLiteralValues, s as SchemaFollow, u as getEmbeddedJson } from "./index-DPGecgel.cjs";
|
|
4
|
+
import { o as findSchema } from "./visitor-CPlsMCPZ.cjs";
|
|
5
5
|
export { type IsOptions, type SchemaFollow, type SchemaKind, applyOptionality, findSchema as find, resolveSchemaProperties as findProperties, getEmbeddedJson, getSchemaLiteralValues as getLiterals, inferDiscriminatorPropertyName as inferDiscriminator, is, isString, narrowSchema as narrow, schemaTypes as types };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as schemaTypes } from "./base-A-xF4pUL.js";
|
|
2
2
|
import { n as narrowSchema } from "./guards-CTqHwyNs.js";
|
|
3
|
-
import { a as resolveSchemaProperties, c as SchemaKind, d as applyOptionality, i as inferDiscriminatorPropertyName, l as is, n as isString, o as IsOptions, r as getSchemaLiteralValues, s as SchemaFollow, u as getEmbeddedJson } from "./index-
|
|
4
|
-
import { o as findSchema } from "./visitor-
|
|
3
|
+
import { a as resolveSchemaProperties, c as SchemaKind, d as applyOptionality, i as inferDiscriminatorPropertyName, l as is, n as isString, o as IsOptions, r as getSchemaLiteralValues, s as SchemaFollow, u as getEmbeddedJson } from "./index-BXHrCLGe.js";
|
|
4
|
+
import { o as findSchema } from "./visitor-BWHpwRgc.js";
|
|
5
5
|
export { type IsOptions, type SchemaFollow, type SchemaKind, applyOptionality, findSchema as find, resolveSchemaProperties as findProperties, getEmbeddedJson, getSchemaLiteralValues as getLiterals, inferDiscriminatorPropertyName as inferDiscriminator, is, isString, narrowSchema as narrow, schemaTypes as types };
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as schemaTypes } from "./constants-UorsTFsa.js";
|
|
2
|
-
import { n as findSchema, o as getEmbeddedJson } from "./visitor-
|
|
2
|
+
import { n as findSchema, o as getEmbeddedJson } from "./visitor-CitcdWu0.js";
|
|
3
3
|
import { n as narrowSchema } from "./guards-DKw4uwc5.js";
|
|
4
4
|
import { t as applyOptionality } from "./optionality-FkRredTC.js";
|
|
5
|
-
import { a as resolveSchemaProperties, i as inferDiscriminatorPropertyName, o as is, r as getSchemaLiteralValues, t as isString } from "./schema-
|
|
5
|
+
import { a as resolveSchemaProperties, i as inferDiscriminatorPropertyName, o as is, r as getSchemaLiteralValues, t as isString } from "./schema-CVIk19Mh.js";
|
|
6
6
|
export { applyOptionality, findSchema as find, resolveSchemaProperties as findProperties, getEmbeddedJson, getSchemaLiteralValues as getLiterals, inferDiscriminatorPropertyName as inferDiscriminator, is, isString, narrowSchema as narrow, schemaTypes as types };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Node } from "./index-
|
|
1
|
+
import { t as Node } from "./index-BEvWuiSq.js";
|
|
2
2
|
import { D as InputNode, K as SchemaNode, et as PropertyNode, h as ParameterNode, i as OperationNode, l as ResponseNode } from "./operation-DJ7F0cFp.js";
|
|
3
3
|
/**
|
|
4
4
|
* Traversal depth for AST visitor utilities.
|
|
@@ -84,7 +84,7 @@ type TraversalOptions = {
|
|
|
84
84
|
*/
|
|
85
85
|
depth?: VisitorDepth;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* The parent the visitor sees for the root of a subtree. Nested nodes always get their real parent.
|
|
88
88
|
*/
|
|
89
89
|
parent?: Node;
|
|
90
90
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Node } from "./index-
|
|
1
|
+
import { t as Node } from "./index-Dbtc7izw.cjs";
|
|
2
2
|
import { D as InputNode, K as SchemaNode, et as PropertyNode, h as ParameterNode, i as OperationNode, l as ResponseNode } from "./operation-B86IER5K.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Traversal depth for AST visitor utilities.
|
|
@@ -84,7 +84,7 @@ type TraversalOptions = {
|
|
|
84
84
|
*/
|
|
85
85
|
depth?: VisitorDepth;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* The parent the visitor sees for the root of a subtree. Nested nodes always get their real parent.
|
|
88
88
|
*/
|
|
89
89
|
parent?: Node;
|
|
90
90
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./rolldown-runtime-BYyVTPww.js";
|
|
2
2
|
import { t as nodeKinds } from "./constants-UorsTFsa.js";
|
|
3
3
|
import { n as isJson } from "./mediaType-DXQCNYdM.js";
|
|
4
|
+
import { t as isRecord } from "./isRecord-DaSp13D_.js";
|
|
4
5
|
// src/schema/embeddedJson.ts
|
|
5
6
|
/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */
|
|
6
7
|
function getEmbeddedJson({ content }) {
|
|
@@ -69,12 +70,6 @@ const VISITOR_KEY_BY_KIND = {
|
|
|
69
70
|
function isNode(value) {
|
|
70
71
|
return typeof value === "object" && value !== null && typeof value.kind === "string";
|
|
71
72
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Returns `true` for a plain object that maps names to nodes, such as `patternProperties`.
|
|
74
|
-
*/
|
|
75
|
-
function isNodeRecord(value) {
|
|
76
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
77
|
-
}
|
|
78
73
|
function isNeverPrinted({ node, key }) {
|
|
79
74
|
if (node.kind !== nodeKinds.schema) return false;
|
|
80
75
|
if (key === "contains" && (node.type === "array" || node.type === "tuple")) return node.contains?.min === 0 && node.contains.max === void 0;
|
|
@@ -124,14 +119,14 @@ function visitChildNodes(node, visit, { checks = false } = {}) {
|
|
|
124
119
|
rest: void 0
|
|
125
120
|
};
|
|
126
121
|
if (Array.isArray(value)) {
|
|
127
|
-
for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) :
|
|
122
|
+
for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : isRecord(item) && visitRecord(item, seen, visit)) return true;
|
|
128
123
|
continue;
|
|
129
124
|
}
|
|
130
125
|
if (isNode(value)) {
|
|
131
126
|
if (visitOnce(value, seen, visit)) return true;
|
|
132
127
|
continue;
|
|
133
128
|
}
|
|
134
|
-
if (
|
|
129
|
+
if (isRecord(value) && visitRecord(value, seen, visit)) return true;
|
|
135
130
|
}
|
|
136
131
|
return false;
|
|
137
132
|
}
|
|
@@ -299,7 +294,7 @@ function transformChildren(node, visitor, recurse) {
|
|
|
299
294
|
if (next !== value) (updates ??= {})[key] = next;
|
|
300
295
|
continue;
|
|
301
296
|
}
|
|
302
|
-
if (
|
|
297
|
+
if (isRecord(value)) {
|
|
303
298
|
let mapped;
|
|
304
299
|
for (const [name, item] of Object.entries(value)) {
|
|
305
300
|
const next = isNode(item) ? transformOnce(item) : item;
|
|
@@ -344,4 +339,4 @@ function collectInto(node, visitor, recurse, parent, result) {
|
|
|
344
339
|
}
|
|
345
340
|
export { visitorKeys as a, visitChildNodes as i, findSchema as n, getEmbeddedJson as o, transform as r, collect as t };
|
|
346
341
|
|
|
347
|
-
//# sourceMappingURL=visitor-
|
|
342
|
+
//# sourceMappingURL=visitor-CitcdWu0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor-CitcdWu0.js","names":[],"sources":["../src/schema/embeddedJson.ts","../src/visitor.ts"],"sourcesContent":["import { isJson } from '../mediaType/index.ts'\nimport type { SchemaNode, StringSchemaNode } from '../nodes/schema.ts'\n\n/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */\nexport function getEmbeddedJson({ content }: Pick<StringSchemaNode, 'content'>): SchemaNode | undefined {\n // shortcut: an encoded document (`contentEncoding`) is not decoded, so only its encoding is checked; decode it once a spec needs both.\n if (!content?.schema || content.encoding || !content.mediaType) return undefined\n return isJson(content.mediaType) ? content.schema : undefined\n}\n","import { nodeKinds } from './constants.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { InputNode } from './nodes/input.ts'\nimport type { NodeKind } from './nodes/base.ts'\nimport type { OperationNode } from './nodes/operation.ts'\nimport type { ParameterNode } from './nodes/parameter.ts'\nimport type { PropertyNode } from './nodes/property.ts'\nimport type { ResponseNode } from './nodes/response.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { getEmbeddedJson } from './schema/embeddedJson.ts'\nimport { isRecord } from './utils/isRecord.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as\n * leaves: a schema node itself is visited, but its children are not.\n * - `'deep'` recursively visits all descendant nodes, including schema subtrees.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n */\nconst VISITOR_KEYS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Input: ['schemas', 'operations'],\n Operations: ['operations'],\n Operation: ['parameters', 'requestBody', 'responses'],\n RequestBody: ['content'],\n Content: ['schema', 'stream'],\n Response: ['content', 'headers'],\n Schema: ['properties', 'items', 'members', 'additionalProperties', 'patternProperties', 'propertyNames', 'rest'],\n Property: ['schema'],\n Parameter: ['schema'],\n}\n\n/**\n * Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.\n * `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.\n */\nconst schemaCheckKeys = ['conditionals', 'contains', 'content'] as const\n\n/** Visitor callback names in traversal order, the keys of {@link Visitor}. */\nexport const visitorKeys = ['input', 'operation', 'schema', 'property', 'parameter', 'response'] as const\n\nexport type VisitorKey = (typeof visitorKeys)[number]\n\n/**\n * Maps a node kind to the matching visitor callback name.\n */\nconst VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, VisitorKey>> = {\n Input: 'input',\n Operation: 'operation',\n Schema: 'schema',\n Property: 'property',\n Parameter: 'parameter',\n Response: 'response',\n}\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent is the node that holds this schema, or undefined at the root\n * },\n * }\n * ```\n */\nexport type VisitorContext = {\n /**\n * Parent node of the currently visited node. For the root node, this is `undefined`.\n */\n parent?: Node\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites the AST before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext): undefined | null | InputNode\n operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode\n}\n\n/**\n * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it\n * so a visitor can yield values instead of replacement nodes.\n *\n * @example\n * ```ts\n * const visitor: VisitorOf<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\nexport type VisitorOf<TResult> = {\n [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined\n}\n\nexport type TraversalOptions = {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * The parent the visitor sees for the root of a subtree. Nested nodes always get their real parent.\n */\n parent?: Node\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & TraversalOptions\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = VisitorOf<T> & TraversalOptions\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && typeof (value as { kind?: unknown }).kind === 'string'\n}\n\n// A check no printer emits: a `contains` that any array meets (`min: 0`, no `max`), or `content` that is not JSON.\nfunction isNeverPrinted({ node, key }: { node: Node; key: string }): boolean {\n if (node.kind !== nodeKinds.schema) return false\n if (key === 'contains' && (node.type === 'array' || node.type === 'tuple')) return node.contains?.min === 0 && node.contains.max === undefined\n if (key === 'content' && node.type === 'string') return !getEmbeddedJson(node)\n return false\n}\n\n/**\n * Child keys of a schema walked with `checks: true`: the shape keys, then {@link schemaCheckKeys}.\n */\nconst SCHEMA_CHECK_VISITOR_KEYS: ReadonlyArray<string> = [...VISITOR_KEYS.Schema!, ...schemaCheckKeys]\n\n/**\n * Children a node already passed to `visit`. A node under two keys, such as a stream item under `schema` and\n * `stream`, is visited once. The `Set` is only created once a node has a second child.\n */\ntype SeenChildren = { first: Node | undefined; rest: Set<Node> | undefined }\n\nfunction visitOnce(child: Node, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n if (seen.first === undefined) {\n seen.first = child\n return visit(child)\n }\n if (seen.first === child || seen.rest?.has(child)) return false\n ;(seen.rest ??= new Set()).add(child)\n return visit(child)\n}\n\nfunction visitRecord(value: Record<string, unknown>, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n for (const name in value) {\n if (!Object.hasOwn(value, name)) continue\n const item = value[name]\n if (isNode(item) && visitOnce(item, seen, visit)) return true\n }\n return false\n}\n\n/**\n * Calls `visit` for each direct child node and stops at the first call that returns `true`.\n * With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too, except checks that cannot fail.\n */\nexport function visitChildNodes(node: Node, visit: (child: Node) => boolean, { checks = false }: { checks?: boolean } = {}): boolean {\n const withChecks = checks && node.kind === nodeKinds.schema\n const keys = withChecks ? SCHEMA_CHECK_VISITOR_KEYS : VISITOR_KEYS[node.kind]\n if (!keys) return false\n\n const record = node as unknown as Record<string, unknown>\n let seen: SeenChildren | undefined\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (withChecks && isNeverPrinted({ node, key })) continue\n seen ??= { first: undefined, rest: undefined }\n if (Array.isArray(value)) {\n // Items can be plain objects that hold nodes, such as the `{ if, then, else }` entries of `conditionals`.\n for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : isRecord(item) && visitRecord(item, seen, visit)) return true\n continue\n }\n if (isNode(value)) {\n if (visitOnce(value, seen, visit)) return true\n continue\n }\n if (isRecord(value) && visitRecord(value, seen, visit)) return true\n }\n return false\n}\n\ntype FindResult = { found: SchemaNode | undefined; low: number }\n\nconst notFound: FindResult = { found: undefined, low: Number.POSITIVE_INFINITY }\n\n/**\n * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.\n *\n * @example\n * ```ts\n * const firstString = findSchema(operationNode, {\n * predicate: (schema) => schema.type === 'string',\n * })\n * ```\n */\nexport function findSchema(\n node: Node,\n {\n predicate,\n follow,\n followRefs = false,\n cache,\n }: {\n predicate: (schema: SchemaNode) => boolean\n /**\n * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.\n * @default []\n */\n follow?: ReadonlyArray<'ref'>\n /**\n * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.\n */\n followRefs?: boolean\n /**\n * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.\n * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.\n * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.\n */\n cache?: WeakMap<SchemaNode, SchemaNode | null>\n },\n): SchemaNode | undefined {\n const followsRefs = followRefs || (follow?.includes('ref') ?? false)\n // When following refs, as in Tarjan's algorithm: the visit order of a schema still being walked, or for a finished\n // schema without a match the lowest visit order of an unfinished schema its subtree reached. Only a schema whose\n // subtree reached nothing visited before it has a final no-match; until then it waits in `pending`.\n const state = followsRefs ? new Map<SchemaNode, number>() : undefined\n const pending: Array<SchemaNode> = []\n let order = 0\n\n const walkChildren = (current: Node, initial: FindResult): FindResult => {\n let result = initial\n visitChildNodes(current, (child) => {\n const next = walk(child)\n result = next.found || next.low < result.low ? next : result\n return next.found !== undefined\n })\n return result\n }\n\n const walkSchema = (current: SchemaNode): FindResult => {\n const target = state && current.type === 'ref' && current.schema ? walk(current.schema) : notFound\n if (target.found) return target\n return walkChildren(current, target)\n }\n\n const walk = (current: Node): FindResult => {\n if (current.kind !== nodeKinds.schema) return walkChildren(current, notFound)\n\n const cached = cache?.get(current)\n if (cached === null) return notFound\n if (cached) return { found: cached, low: Number.POSITIVE_INFINITY }\n if (predicate(current)) {\n cache?.set(current, current)\n return { found: current, low: Number.POSITIVE_INFINITY }\n }\n const known = state?.get(current)\n if (known !== undefined) return { found: undefined, low: known }\n\n const index = order++\n const start = pending.length\n state?.set(current, index)\n const result = walkSchema(current)\n if (result.found) {\n cache?.set(current, result.found)\n return result\n }\n if (!state) {\n cache?.set(current, null)\n return notFound\n }\n if (result.low < index) {\n state.set(current, result.low)\n pending.push(current)\n return result\n }\n for (const done of [...pending.splice(start), current]) {\n state.set(done, Number.POSITIVE_INFINITY)\n cache?.set(done, null)\n }\n return notFound\n }\n\n return walk(node).found\n}\n\n/**\n * Runs the visitor callback that matches `node.kind` with the traversal\n * context. The result is a replacement node, a collected value, or `undefined`\n * when no callback is registered for the kind.\n *\n * Shared by `transform` and `collect` so node-kind dispatch lives in one place.\n * `TResult` is the caller's expected return: the same node type for `transform`,\n * the collected value type for `collect`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | VisitorOf<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback can return a\n * replacement node. Returning `undefined` keeps the original.\n *\n * The original tree is never mutated, a new tree is returned. Pass\n * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Rewrite the root node without walking its schemas\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform<T extends Node>(node: T, options: TransformOptions): T {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? 'deep') === 'deep'\n\n // Split the visitor out once and pass it, `recurse`, and `parent` as plain arguments, so the\n // recursion builds no options object per node.\n return transformNode(node, visitor, recurse, parent) as T\n}\n\n/**\n * Visits a single node, then immutably rebuilds its children. Returns the original\n * reference when neither the visitor nor the child rebuild changed anything, so callers\n * can detect \"nothing changed\" by identity and ancestors avoid reallocating.\n */\nfunction transformNode(node: Node, visitor: Visitor, recurse: boolean, parent: Node | undefined): Node {\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n return transformChildren(visited, visitor, recurse)\n}\n\n/**\n * Immutably rebuilds a node's children, transforming each child node and leaving non-node values\n * (e.g. `additionalProperties: true`) intact.\n */\nfunction transformChildren(node: Node, visitor: Visitor, recurse: boolean): Node {\n const keys = node.kind === nodeKinds.schema && !recurse ? undefined : VISITOR_KEYS[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n let updates: Record<string, unknown> | undefined\n // A node under two keys is transformed once, so both keys keep pointing at one node. Leaves never create the map.\n let done: Map<Node, Node> | undefined\n const transformOnce = (child: Node) => {\n done ??= new Map()\n const next = done.get(child) ?? transformNode(child, visitor, recurse, node)\n done.set(child, next)\n return next\n }\n\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) {\n // Rebuild the array lazily: allocate a new array only once a child actually changes, copying\n // the unchanged prefix at that point. An unchanged array keeps its original reference and\n // allocates nothing.\n let mapped: Array<unknown> | undefined\n for (const [i, item] of value.entries()) {\n const next = isNode(item) ? transformOnce(item) : item\n if (mapped) {\n mapped.push(next)\n continue\n }\n if (next !== item) mapped = [...value.slice(0, i), next]\n }\n if (mapped) (updates ??= {})[key] = mapped\n continue\n }\n if (isNode(value)) {\n const next = transformOnce(value)\n if (next !== value) (updates ??= {})[key] = next\n continue\n }\n if (isRecord(value)) {\n let mapped: Record<string, unknown> | undefined\n for (const [name, item] of Object.entries(value)) {\n const next = isNode(item) ? transformOnce(item) : item\n if (next !== item) (mapped ??= { ...value })[name] = next\n }\n if (mapped) (updates ??= {})[key] = mapped\n }\n }\n\n if (!updates) return node\n const merged = { ...node, ...updates }\n return merged as Node\n}\n\n/**\n * Depth-first collection pass. Gathers every non-null value the visitor\n * callbacks return into an array.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const result: Array<T> = []\n // Plain recursion: draining nested generators costs a `yield*` hop per level for every value.\n collectInto<T>(node, visitor, (depth ?? 'deep') === 'deep', parent, result)\n return result\n}\n\nfunction collectInto<T>(node: Node, visitor: VisitorOf<T>, recurse: boolean, parent: Node | undefined, result: Array<T>): void {\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) result.push(v)\n\n if (node.kind === nodeKinds.schema && !recurse) return\n visitChildNodes(node, (child) => {\n collectInto<T>(child, visitor, recurse, node, result)\n return false\n })\n}\n"],"mappings":";;;;;;AAIA,SAAgB,gBAAgB,EAAE,WAAsE;CAEtG,IAAI,CAAC,SAAS,UAAU,QAAQ,YAAY,CAAC,QAAQ,WAAW,OAAO,KAAA;CACvE,OAAO,OAAO,QAAQ,SAAS,IAAI,QAAQ,SAAS,KAAA;AACtD;;;;;ACgBA,MAAM,eAAiE;CACrE,OAAO,CAAC,WAAW,YAAY;CAC/B,YAAY,CAAC,YAAY;CACzB,WAAW;EAAC;EAAc;EAAe;CAAW;CACpD,aAAa,CAAC,SAAS;CACvB,SAAS,CAAC,UAAU,QAAQ;CAC5B,UAAU,CAAC,WAAW,SAAS;CAC/B,QAAQ;EAAC;EAAc;EAAS;EAAW;EAAwB;EAAqB;EAAiB;CAAM;CAC/G,UAAU,CAAC,QAAQ;CACnB,WAAW,CAAC,QAAQ;AACtB;;;;;AAMA,MAAM,kBAAkB;CAAC;CAAgB;CAAY;AAAS;;AAG9D,MAAa,cAAc;CAAC;CAAS;CAAa;CAAU;CAAY;CAAa;AAAU;;;;AAO/F,MAAM,sBAA6D;CACjE,OAAO;CACP,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;AACZ;;;;AAkHA,SAAS,OAAO,OAA+B;CAC7C,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAA6B,SAAS;AACtG;AAGA,SAAS,eAAe,EAAE,MAAM,OAA6C;CAC3E,IAAI,KAAK,SAAS,UAAU,QAAQ,OAAO;CAC3C,IAAI,QAAQ,eAAe,KAAK,SAAS,WAAW,KAAK,SAAS,UAAU,OAAO,KAAK,UAAU,QAAQ,KAAK,KAAK,SAAS,QAAQ,KAAA;CACrI,IAAI,QAAQ,aAAa,KAAK,SAAS,UAAU,OAAO,CAAC,gBAA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AsC;CAC3E,MAAM,EAAE,OAAO,QAAQ,GAAG,YAAY;CACtC,MAAM,SAAmB,CAAC;CAE1B,YAAe,MAAM,UAAU,SAAS,YAAY,QAAQ,QAAQ,MAAM;CAC1E,OAAO;AACT;AAEA,SAAS,YAAe,MAAY,SAAuB,SAAkB,QAA0B,QAAwB;CAC7H,MAAM,IAAI,aAAgB,MAAM,SAAS,MAAM;CAC/C,IAAI,KAAK,MAAM,OAAO,KAAK,CAAC;CAE5B,IAAI,KAAK,SAAS,UAAU,UAAU,CAAC,SAAS;CAChD,gBAAgB,OAAO,UAAU;EAC/B,YAAe,OAAO,SAAS,SAAS,MAAM,MAAM;EACpD,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
2
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
3
3
|
const require_mediaType = require("./mediaType-BbIfudh0.cjs");
|
|
4
|
+
const require_isRecord = require("./isRecord-CwlfDtHp.cjs");
|
|
4
5
|
// src/schema/embeddedJson.ts
|
|
5
6
|
/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */
|
|
6
7
|
function getEmbeddedJson({ content }) {
|
|
@@ -69,12 +70,6 @@ const VISITOR_KEY_BY_KIND = {
|
|
|
69
70
|
function isNode(value) {
|
|
70
71
|
return typeof value === "object" && value !== null && typeof value.kind === "string";
|
|
71
72
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Returns `true` for a plain object that maps names to nodes, such as `patternProperties`.
|
|
74
|
-
*/
|
|
75
|
-
function isNodeRecord(value) {
|
|
76
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
77
|
-
}
|
|
78
73
|
function isNeverPrinted({ node, key }) {
|
|
79
74
|
if (node.kind !== require_constants.nodeKinds.schema) return false;
|
|
80
75
|
if (key === "contains" && (node.type === "array" || node.type === "tuple")) return node.contains?.min === 0 && node.contains.max === void 0;
|
|
@@ -124,14 +119,14 @@ function visitChildNodes(node, visit, { checks = false } = {}) {
|
|
|
124
119
|
rest: void 0
|
|
125
120
|
};
|
|
126
121
|
if (Array.isArray(value)) {
|
|
127
|
-
for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) :
|
|
122
|
+
for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : require_isRecord.isRecord(item) && visitRecord(item, seen, visit)) return true;
|
|
128
123
|
continue;
|
|
129
124
|
}
|
|
130
125
|
if (isNode(value)) {
|
|
131
126
|
if (visitOnce(value, seen, visit)) return true;
|
|
132
127
|
continue;
|
|
133
128
|
}
|
|
134
|
-
if (
|
|
129
|
+
if (require_isRecord.isRecord(value) && visitRecord(value, seen, visit)) return true;
|
|
135
130
|
}
|
|
136
131
|
return false;
|
|
137
132
|
}
|
|
@@ -299,7 +294,7 @@ function transformChildren(node, visitor, recurse) {
|
|
|
299
294
|
if (next !== value) (updates ??= {})[key] = next;
|
|
300
295
|
continue;
|
|
301
296
|
}
|
|
302
|
-
if (
|
|
297
|
+
if (require_isRecord.isRecord(value)) {
|
|
303
298
|
let mapped;
|
|
304
299
|
for (const [name, item] of Object.entries(value)) {
|
|
305
300
|
const next = isNode(item) ? transformOnce(item) : item;
|
|
@@ -379,4 +374,4 @@ Object.defineProperty(exports, "visitorKeys", {
|
|
|
379
374
|
}
|
|
380
375
|
});
|
|
381
376
|
|
|
382
|
-
//# sourceMappingURL=visitor-
|
|
377
|
+
//# sourceMappingURL=visitor-DT712cxr.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor-DT712cxr.cjs","names":["isJson","nodeKinds","isRecord"],"sources":["../src/schema/embeddedJson.ts","../src/visitor.ts"],"sourcesContent":["import { isJson } from '../mediaType/index.ts'\nimport type { SchemaNode, StringSchemaNode } from '../nodes/schema.ts'\n\n/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */\nexport function getEmbeddedJson({ content }: Pick<StringSchemaNode, 'content'>): SchemaNode | undefined {\n // shortcut: an encoded document (`contentEncoding`) is not decoded, so only its encoding is checked; decode it once a spec needs both.\n if (!content?.schema || content.encoding || !content.mediaType) return undefined\n return isJson(content.mediaType) ? content.schema : undefined\n}\n","import { nodeKinds } from './constants.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { InputNode } from './nodes/input.ts'\nimport type { NodeKind } from './nodes/base.ts'\nimport type { OperationNode } from './nodes/operation.ts'\nimport type { ParameterNode } from './nodes/parameter.ts'\nimport type { PropertyNode } from './nodes/property.ts'\nimport type { ResponseNode } from './nodes/response.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { getEmbeddedJson } from './schema/embeddedJson.ts'\nimport { isRecord } from './utils/isRecord.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as\n * leaves: a schema node itself is visited, but its children are not.\n * - `'deep'` recursively visits all descendant nodes, including schema subtrees.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n */\nconst VISITOR_KEYS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Input: ['schemas', 'operations'],\n Operations: ['operations'],\n Operation: ['parameters', 'requestBody', 'responses'],\n RequestBody: ['content'],\n Content: ['schema', 'stream'],\n Response: ['content', 'headers'],\n Schema: ['properties', 'items', 'members', 'additionalProperties', 'patternProperties', 'propertyNames', 'rest'],\n Property: ['schema'],\n Parameter: ['schema'],\n}\n\n/**\n * Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.\n * `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.\n */\nconst schemaCheckKeys = ['conditionals', 'contains', 'content'] as const\n\n/** Visitor callback names in traversal order, the keys of {@link Visitor}. */\nexport const visitorKeys = ['input', 'operation', 'schema', 'property', 'parameter', 'response'] as const\n\nexport type VisitorKey = (typeof visitorKeys)[number]\n\n/**\n * Maps a node kind to the matching visitor callback name.\n */\nconst VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, VisitorKey>> = {\n Input: 'input',\n Operation: 'operation',\n Schema: 'schema',\n Property: 'property',\n Parameter: 'parameter',\n Response: 'response',\n}\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent is the node that holds this schema, or undefined at the root\n * },\n * }\n * ```\n */\nexport type VisitorContext = {\n /**\n * Parent node of the currently visited node. For the root node, this is `undefined`.\n */\n parent?: Node\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites the AST before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext): undefined | null | InputNode\n operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode\n}\n\n/**\n * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it\n * so a visitor can yield values instead of replacement nodes.\n *\n * @example\n * ```ts\n * const visitor: VisitorOf<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\nexport type VisitorOf<TResult> = {\n [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined\n}\n\nexport type TraversalOptions = {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * The parent the visitor sees for the root of a subtree. Nested nodes always get their real parent.\n */\n parent?: Node\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & TraversalOptions\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = VisitorOf<T> & TraversalOptions\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && typeof (value as { kind?: unknown }).kind === 'string'\n}\n\n// A check no printer emits: a `contains` that any array meets (`min: 0`, no `max`), or `content` that is not JSON.\nfunction isNeverPrinted({ node, key }: { node: Node; key: string }): boolean {\n if (node.kind !== nodeKinds.schema) return false\n if (key === 'contains' && (node.type === 'array' || node.type === 'tuple')) return node.contains?.min === 0 && node.contains.max === undefined\n if (key === 'content' && node.type === 'string') return !getEmbeddedJson(node)\n return false\n}\n\n/**\n * Child keys of a schema walked with `checks: true`: the shape keys, then {@link schemaCheckKeys}.\n */\nconst SCHEMA_CHECK_VISITOR_KEYS: ReadonlyArray<string> = [...VISITOR_KEYS.Schema!, ...schemaCheckKeys]\n\n/**\n * Children a node already passed to `visit`. A node under two keys, such as a stream item under `schema` and\n * `stream`, is visited once. The `Set` is only created once a node has a second child.\n */\ntype SeenChildren = { first: Node | undefined; rest: Set<Node> | undefined }\n\nfunction visitOnce(child: Node, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n if (seen.first === undefined) {\n seen.first = child\n return visit(child)\n }\n if (seen.first === child || seen.rest?.has(child)) return false\n ;(seen.rest ??= new Set()).add(child)\n return visit(child)\n}\n\nfunction visitRecord(value: Record<string, unknown>, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n for (const name in value) {\n if (!Object.hasOwn(value, name)) continue\n const item = value[name]\n if (isNode(item) && visitOnce(item, seen, visit)) return true\n }\n return false\n}\n\n/**\n * Calls `visit` for each direct child node and stops at the first call that returns `true`.\n * With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too, except checks that cannot fail.\n */\nexport function visitChildNodes(node: Node, visit: (child: Node) => boolean, { checks = false }: { checks?: boolean } = {}): boolean {\n const withChecks = checks && node.kind === nodeKinds.schema\n const keys = withChecks ? SCHEMA_CHECK_VISITOR_KEYS : VISITOR_KEYS[node.kind]\n if (!keys) return false\n\n const record = node as unknown as Record<string, unknown>\n let seen: SeenChildren | undefined\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (withChecks && isNeverPrinted({ node, key })) continue\n seen ??= { first: undefined, rest: undefined }\n if (Array.isArray(value)) {\n // Items can be plain objects that hold nodes, such as the `{ if, then, else }` entries of `conditionals`.\n for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : isRecord(item) && visitRecord(item, seen, visit)) return true\n continue\n }\n if (isNode(value)) {\n if (visitOnce(value, seen, visit)) return true\n continue\n }\n if (isRecord(value) && visitRecord(value, seen, visit)) return true\n }\n return false\n}\n\ntype FindResult = { found: SchemaNode | undefined; low: number }\n\nconst notFound: FindResult = { found: undefined, low: Number.POSITIVE_INFINITY }\n\n/**\n * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.\n *\n * @example\n * ```ts\n * const firstString = findSchema(operationNode, {\n * predicate: (schema) => schema.type === 'string',\n * })\n * ```\n */\nexport function findSchema(\n node: Node,\n {\n predicate,\n follow,\n followRefs = false,\n cache,\n }: {\n predicate: (schema: SchemaNode) => boolean\n /**\n * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.\n * @default []\n */\n follow?: ReadonlyArray<'ref'>\n /**\n * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.\n */\n followRefs?: boolean\n /**\n * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.\n * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.\n * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.\n */\n cache?: WeakMap<SchemaNode, SchemaNode | null>\n },\n): SchemaNode | undefined {\n const followsRefs = followRefs || (follow?.includes('ref') ?? false)\n // When following refs, as in Tarjan's algorithm: the visit order of a schema still being walked, or for a finished\n // schema without a match the lowest visit order of an unfinished schema its subtree reached. Only a schema whose\n // subtree reached nothing visited before it has a final no-match; until then it waits in `pending`.\n const state = followsRefs ? new Map<SchemaNode, number>() : undefined\n const pending: Array<SchemaNode> = []\n let order = 0\n\n const walkChildren = (current: Node, initial: FindResult): FindResult => {\n let result = initial\n visitChildNodes(current, (child) => {\n const next = walk(child)\n result = next.found || next.low < result.low ? next : result\n return next.found !== undefined\n })\n return result\n }\n\n const walkSchema = (current: SchemaNode): FindResult => {\n const target = state && current.type === 'ref' && current.schema ? walk(current.schema) : notFound\n if (target.found) return target\n return walkChildren(current, target)\n }\n\n const walk = (current: Node): FindResult => {\n if (current.kind !== nodeKinds.schema) return walkChildren(current, notFound)\n\n const cached = cache?.get(current)\n if (cached === null) return notFound\n if (cached) return { found: cached, low: Number.POSITIVE_INFINITY }\n if (predicate(current)) {\n cache?.set(current, current)\n return { found: current, low: Number.POSITIVE_INFINITY }\n }\n const known = state?.get(current)\n if (known !== undefined) return { found: undefined, low: known }\n\n const index = order++\n const start = pending.length\n state?.set(current, index)\n const result = walkSchema(current)\n if (result.found) {\n cache?.set(current, result.found)\n return result\n }\n if (!state) {\n cache?.set(current, null)\n return notFound\n }\n if (result.low < index) {\n state.set(current, result.low)\n pending.push(current)\n return result\n }\n for (const done of [...pending.splice(start), current]) {\n state.set(done, Number.POSITIVE_INFINITY)\n cache?.set(done, null)\n }\n return notFound\n }\n\n return walk(node).found\n}\n\n/**\n * Runs the visitor callback that matches `node.kind` with the traversal\n * context. The result is a replacement node, a collected value, or `undefined`\n * when no callback is registered for the kind.\n *\n * Shared by `transform` and `collect` so node-kind dispatch lives in one place.\n * `TResult` is the caller's expected return: the same node type for `transform`,\n * the collected value type for `collect`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | VisitorOf<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback can return a\n * replacement node. Returning `undefined` keeps the original.\n *\n * The original tree is never mutated, a new tree is returned. Pass\n * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Rewrite the root node without walking its schemas\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform<T extends Node>(node: T, options: TransformOptions): T {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? 'deep') === 'deep'\n\n // Split the visitor out once and pass it, `recurse`, and `parent` as plain arguments, so the\n // recursion builds no options object per node.\n return transformNode(node, visitor, recurse, parent) as T\n}\n\n/**\n * Visits a single node, then immutably rebuilds its children. Returns the original\n * reference when neither the visitor nor the child rebuild changed anything, so callers\n * can detect \"nothing changed\" by identity and ancestors avoid reallocating.\n */\nfunction transformNode(node: Node, visitor: Visitor, recurse: boolean, parent: Node | undefined): Node {\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n return transformChildren(visited, visitor, recurse)\n}\n\n/**\n * Immutably rebuilds a node's children, transforming each child node and leaving non-node values\n * (e.g. `additionalProperties: true`) intact.\n */\nfunction transformChildren(node: Node, visitor: Visitor, recurse: boolean): Node {\n const keys = node.kind === nodeKinds.schema && !recurse ? undefined : VISITOR_KEYS[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n let updates: Record<string, unknown> | undefined\n // A node under two keys is transformed once, so both keys keep pointing at one node. Leaves never create the map.\n let done: Map<Node, Node> | undefined\n const transformOnce = (child: Node) => {\n done ??= new Map()\n const next = done.get(child) ?? transformNode(child, visitor, recurse, node)\n done.set(child, next)\n return next\n }\n\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) {\n // Rebuild the array lazily: allocate a new array only once a child actually changes, copying\n // the unchanged prefix at that point. An unchanged array keeps its original reference and\n // allocates nothing.\n let mapped: Array<unknown> | undefined\n for (const [i, item] of value.entries()) {\n const next = isNode(item) ? transformOnce(item) : item\n if (mapped) {\n mapped.push(next)\n continue\n }\n if (next !== item) mapped = [...value.slice(0, i), next]\n }\n if (mapped) (updates ??= {})[key] = mapped\n continue\n }\n if (isNode(value)) {\n const next = transformOnce(value)\n if (next !== value) (updates ??= {})[key] = next\n continue\n }\n if (isRecord(value)) {\n let mapped: Record<string, unknown> | undefined\n for (const [name, item] of Object.entries(value)) {\n const next = isNode(item) ? transformOnce(item) : item\n if (next !== item) (mapped ??= { ...value })[name] = next\n }\n if (mapped) (updates ??= {})[key] = mapped\n }\n }\n\n if (!updates) return node\n const merged = { ...node, ...updates }\n return merged as Node\n}\n\n/**\n * Depth-first collection pass. Gathers every non-null value the visitor\n * callbacks return into an array.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const result: Array<T> = []\n // Plain recursion: draining nested generators costs a `yield*` hop per level for every value.\n collectInto<T>(node, visitor, (depth ?? 'deep') === 'deep', parent, result)\n return result\n}\n\nfunction collectInto<T>(node: Node, visitor: VisitorOf<T>, recurse: boolean, parent: Node | undefined, result: Array<T>): void {\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) result.push(v)\n\n if (node.kind === nodeKinds.schema && !recurse) return\n visitChildNodes(node, (child) => {\n collectInto<T>(child, visitor, recurse, node, result)\n return false\n })\n}\n"],"mappings":";;;;;;AAIA,SAAgB,gBAAgB,EAAE,WAAsE;CAEtG,IAAI,CAAC,SAAS,UAAU,QAAQ,YAAY,CAAC,QAAQ,WAAW,OAAO,KAAA;CACvE,OAAOA,kBAAAA,OAAO,QAAQ,SAAS,IAAI,QAAQ,SAAS,KAAA;AACtD;;;;;ACgBA,MAAM,eAAiE;CACrE,OAAO,CAAC,WAAW,YAAY;CAC/B,YAAY,CAAC,YAAY;CACzB,WAAW;EAAC;EAAc;EAAe;CAAW;CACpD,aAAa,CAAC,SAAS;CACvB,SAAS,CAAC,UAAU,QAAQ;CAC5B,UAAU,CAAC,WAAW,SAAS;CAC/B,QAAQ;EAAC;EAAc;EAAS;EAAW;EAAwB;EAAqB;EAAiB;CAAM;CAC/G,UAAU,CAAC,QAAQ;CACnB,WAAW,CAAC,QAAQ;AACtB;;;;;AAMA,MAAM,kBAAkB;CAAC;CAAgB;CAAY;AAAS;;AAG9D,MAAa,cAAc;CAAC;CAAS;CAAa;CAAU;CAAY;CAAa;AAAU;;;;AAO/F,MAAM,sBAA6D;CACjE,OAAO;CACP,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;AACZ;;;;AAkHA,SAAS,OAAO,OAA+B;CAC7C,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAA6B,SAAS;AACtG;AAGA,SAAS,eAAe,EAAE,MAAM,OAA6C;CAC3E,IAAI,KAAK,SAASC,kBAAAA,UAAU,QAAQ,OAAO;CAC3C,IAAI,QAAQ,eAAe,KAAK,SAAS,WAAW,KAAK,SAAS,UAAU,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