@kubb/ast 5.26.0 → 5.27.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/dist/{combineFileMembers-DJHNAZBN.js → combineFileMembers-B-mdjXrG.js} +2 -2
- package/dist/{combineFileMembers-DJHNAZBN.js.map → combineFileMembers-B-mdjXrG.js.map} +1 -1
- package/dist/{combineFileMembers-DmmuOmY8.cjs → combineFileMembers-DZCKxAN0.cjs} +2 -2
- package/dist/{combineFileMembers-DmmuOmY8.cjs.map → combineFileMembers-DZCKxAN0.cjs.map} +1 -1
- package/dist/factory.cjs +2 -2
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{file-z3xToonr.cjs → file-D9kqBrBl.cjs} +55 -7
- package/dist/file-D9kqBrBl.cjs.map +1 -0
- package/dist/{file-HwCmj--S.js → file-F3pgfoe4.js} +55 -7
- package/dist/file-F3pgfoe4.js.map +1 -0
- package/dist/file.cjs +2 -2
- package/dist/file.js +2 -2
- package/dist/{graph-D-0CbFIv.cjs → graph-D6Ffy9YD.cjs} +3 -3
- package/dist/{graph-D-0CbFIv.cjs.map → graph-D6Ffy9YD.cjs.map} +1 -1
- package/dist/{graph-CePbhGIt.js → graph-DWlCmvm6.js} +3 -3
- package/dist/{graph-CePbhGIt.js.map → graph-DWlCmvm6.js.map} +1 -1
- package/dist/graph.cjs +1 -1
- package/dist/graph.d.cts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.js +1 -1
- package/dist/{guards-l2AsKeHR.d.ts → guards-CTqHwyNs.d.ts} +1 -1
- package/dist/{guards-B6LgmDhJ.d.cts → guards-EpQMJGyF.d.cts} +1 -1
- package/dist/http.d.cts +2 -2
- package/dist/http.d.ts +2 -2
- package/dist/{index-f90iIhHX.d.ts → index-B8ZxUpy4.d.ts} +1 -1
- package/dist/{index-BfNUrkK6.d.ts → index-BGhhO3z8.d.ts} +1 -1
- package/dist/{index-D2tWPgnK.d.cts → index-BXv0B9Pd.d.cts} +1 -1
- package/dist/{index-Br4bwEnS.d.ts → index-C0_Y9yA1.d.ts} +1 -1
- package/dist/{index-BNf4pYPx.d.cts → index-C4ZZnf_X.d.cts} +1 -1
- package/dist/{index-DNDNDzyJ.d.cts → index-CKd3ogUZ.d.cts} +2 -2
- package/dist/{index-CCUB1hoV.d.cts → index-CiVsdeOh.d.cts} +3 -3
- package/dist/{index-C5SXJAtZ.d.cts → index-Ck6nqnxZ.d.cts} +1 -1
- package/dist/{index-YTyLBHFN.d.ts → index-CuQPyRve.d.ts} +1 -1
- package/dist/{index-2hzFweaD.d.cts → index-DSW89P6k.d.cts} +1 -1
- package/dist/index-DT-_5NUx.d.cts +5 -0
- package/dist/{index-DXdwkq7X.d.ts → index-DVX6E3vZ.d.ts} +2 -2
- package/dist/{index-BjmAaymt.d.cts → index-DdD4PIY8.d.cts} +1 -1
- package/dist/{index-Bz33tfQo.d.ts → index-DjwCRndP.d.ts} +1 -1
- package/dist/{index-MzcNxet1.d.ts → index-DphKh9u9.d.ts} +3 -3
- package/dist/index-kxuajWM1.d.ts +5 -0
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +6 -6
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{nodes-TtDfZ9qf.cjs → nodes-BGxHocS_.cjs} +2 -2
- package/dist/{nodes-TtDfZ9qf.cjs.map → nodes-BGxHocS_.cjs.map} +1 -1
- package/dist/{nodes-u9i-tqFp.js → nodes-KgbYiyJQ.js} +2 -2
- package/dist/{nodes-u9i-tqFp.js.map → nodes-KgbYiyJQ.js.map} +1 -1
- package/dist/{operation-De4lbIZS.d.cts → operation-B86IER5K.d.cts} +1 -1
- package/dist/{operation-Dd0-l2VB.d.ts → operation-DJ7F0cFp.d.ts} +1 -1
- package/dist/{promise-DScaykew.cjs → promise-DMQPWp6M.cjs} +37 -22
- package/dist/promise-DMQPWp6M.cjs.map +1 -0
- package/dist/{promise-B3YkZ4C8.js → promise-bi4pc8Xr.js} +37 -22
- package/dist/promise-bi4pc8Xr.js.map +1 -0
- package/dist/{ref-Dlxn7eu7.js → ref-BU7sfEFr.js} +2 -2
- package/dist/{ref-Dlxn7eu7.js.map → ref-BU7sfEFr.js.map} +1 -1
- package/dist/{ref-Ck-0j8NV.cjs → ref-CGeCLkAk.cjs} +2 -2
- package/dist/{ref-Ck-0j8NV.cjs.map → ref-CGeCLkAk.cjs.map} +1 -1
- package/dist/ref.cjs +2 -2
- package/dist/ref.d.cts +1 -1
- package/dist/ref.d.ts +1 -1
- package/dist/ref.js +2 -2
- package/dist/{refs-Bgf8_9Ui.js → refs-C0hb_qu-.js} +2 -2
- package/dist/{refs-Bgf8_9Ui.js.map → refs-C0hb_qu-.js.map} +1 -1
- package/dist/{refs-rmr2LFV1.cjs → refs-CJZBa9hL.cjs} +2 -2
- package/dist/{refs-rmr2LFV1.cjs.map → refs-CJZBa9hL.cjs.map} +1 -1
- package/dist/{schema-BvUrXIoX.js → schema-B05JSQRq.js} +3 -3
- package/dist/{schema-BvUrXIoX.js.map → schema-B05JSQRq.js.map} +1 -1
- package/dist/{schema-DfLGJ-oh.cjs → schema-XGRiAvok.cjs} +3 -3
- package/dist/{schema-DfLGJ-oh.cjs.map → schema-XGRiAvok.cjs.map} +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.d.cts +3 -3
- package/dist/schema.d.ts +3 -3
- package/dist/schema.js +1 -1
- package/dist/{visitor-BN5QJX7-.d.cts → visitor-BIldddZd.d.cts} +2 -2
- package/dist/{visitor-BNGMMmpe.d.ts → visitor-xxcbpM5-.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/file-HwCmj--S.js.map +0 -1
- package/dist/file-z3xToonr.cjs.map +0 -1
- package/dist/index-BiXrjYNm.d.cts +0 -5
- package/dist/index-CC5Rmgcm.d.ts +0 -5
- package/dist/promise-B3YkZ4C8.js.map +0 -1
- package/dist/promise-DScaykew.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-BvUrXIoX.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;CAC3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AAI,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"}
|
|
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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5B,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"}
|
|
@@ -3,8 +3,8 @@ 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
5
|
const require_visitor = require("./visitor-DhuKS-7x.cjs");
|
|
6
|
-
const require_ref = require("./ref-
|
|
7
|
-
const require_promise = require("./promise-
|
|
6
|
+
const require_ref = require("./ref-CGeCLkAk.cjs");
|
|
7
|
+
const require_promise = require("./promise-DMQPWp6M.cjs");
|
|
8
8
|
// src/schema/is.ts
|
|
9
9
|
const plainStringTypes = /* @__PURE__ */ new Set([
|
|
10
10
|
"string",
|
|
@@ -211,4 +211,4 @@ Object.defineProperty(exports, "schema_exports", {
|
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
-
//# sourceMappingURL=schema-
|
|
214
|
+
//# sourceMappingURL=schema-XGRiAvok.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-DfLGJ-oh.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,W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AAC,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-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,K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UAAU,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"}
|
package/dist/schema.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
|
3
3
|
const require_visitor = require("./visitor-DhuKS-7x.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-XGRiAvok.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
|
-
import { n as narrowSchema } from "./guards-
|
|
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-
|
|
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-CiVsdeOh.cjs";
|
|
4
|
+
import { o as findSchema } from "./visitor-BIldddZd.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
|
-
import { n as narrowSchema } from "./guards-
|
|
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-
|
|
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-DphKh9u9.js";
|
|
4
|
+
import { o as findSchema } from "./visitor-xxcbpM5-.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
|
@@ -2,5 +2,5 @@ import { n as schemaTypes } from "./constants-UorsTFsa.js";
|
|
|
2
2
|
import { n as findSchema, o as getEmbeddedJson } from "./visitor-DA5yfOJz.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-B05JSQRq.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,5 +1,5 @@
|
|
|
1
|
-
import { t as Node } from "./index-
|
|
2
|
-
import {
|
|
1
|
+
import { t as Node } from "./index-DdD4PIY8.cjs";
|
|
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.
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Node } from "./index-
|
|
2
|
-
import {
|
|
1
|
+
import { t as Node } from "./index-DjwCRndP.js";
|
|
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.
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-HwCmj--S.js","names":[],"sources":["../src/utils/inline.ts","../src/file/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { CodeNode } from '../nodes/code.ts'\nimport { createFile, createImport } from '../nodes/file.ts'\nimport type { FileNode, ImportNode, SourceNode } from '../nodes/file.ts'\nimport { getNames } from './moduleNames.ts'\nimport { CODE_NODE_TEXT_FIELDS, getNodeText } from './nodeText.ts'\n\nexport type InlineFilesResult = {\n /**\n * Files that imported an inline name, rewritten to hold its definition.\n */\n files: Array<FileNode>\n /**\n * Paths of the virtual files, which are not written.\n */\n virtualPaths: Array<string>\n /**\n * One message per name that could not be inlined.\n */\n problems: Array<{ path: string; message: string }>\n}\n\ntype Definition = { expression: string; imports: Array<ImportNode> }\n\n/**\n * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.\n */\nexport type InlineLanguage = {\n /**\n * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.\n */\n replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string\n /**\n * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.\n */\n wrap(expression: string): string\n}\n\nexport type InlineFilesOptions = {\n /**\n * The inline support for a file's language, or `undefined` when it has none.\n */\n language: (file: FileNode) => InlineLanguage | undefined\n}\n\n/**\n * Replaces every name a file imports from a virtual file (one marked `inline`, so it is never written) with the body of that name's\n * declaration, until no inline names are left. The definitions' own imports move to the importing file.\n */\nexport function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult {\n const virtualFiles = new Map(files.filter(isInlineFile).map((file) => [file.path, file]))\n const result: InlineFilesResult = { files: [], virtualPaths: [...virtualFiles.keys()], problems: [] }\n if (virtualFiles.size === 0) return result\n\n // `null` marks a definition that is being resolved, so a name that reaches itself is a cycle.\n const definitions = new Map<string, Definition | null>()\n\n function define(path: string, name: string, from: string, lang: InlineLanguage): Definition | undefined {\n const key = `${path}\\0${name}`\n if (definitions.has(key)) {\n const definition = definitions.get(key)\n if (definition === null) result.problems.push({ path: from, message: `\"${name}\" from \"${path}\" is defined in terms of itself.` })\n return definition ?? undefined\n }\n\n const file = virtualFiles.get(path)!\n const expression = bodyOf(file.sources.find((source) => source.name === name))\n if (expression === undefined) {\n result.problems.push({ path: from, message: `\"${name}\" is imported from \"${path}\", which never writes it and has no inline definition for it.` })\n return undefined\n }\n\n definitions.set(key, null)\n const imports: Array<ImportNode> = []\n const { text, used } = replaceNames(expression, file, lang, imports)\n imports.push(...file.imports.flatMap((imp) => (virtualFiles.has(imp.path) ? [] : pickNames(imp, used))))\n\n const definition = { expression: text, imports }\n definitions.set(key, definition)\n return definition\n }\n\n // Pushes the imports the replaced definitions need onto `imports`; `used` holds the names left as they are.\n function replaceNames(input: string, file: FileNode, lang: InlineLanguage, imports: Array<ImportNode>) {\n const used = new Set<string>()\n const text = lang.replaceIdentifiers(input, (local) => {\n const target = findTarget(file, local)\n const definition = target && define(target.path, target.name, file.path, lang)\n if (!definition) {\n used.add(local)\n return undefined\n }\n\n imports.push(...definition.imports)\n return lang.wrap(definition.expression)\n })\n\n return { text, used }\n }\n\n function findTarget(file: FileNode, local: string): { path: string; name: string } | undefined {\n if (virtualFiles.has(file.path) && file.sources.some((source) => source.name === local)) return { path: file.path, name: local }\n\n for (const imp of file.imports) {\n const item = virtualFiles.has(imp.path) && getNames(imp).find((item) => (item.alias ?? item.name) === local)\n if (item) return { path: imp.path, name: item.name }\n }\n\n return undefined\n }\n\n for (const file of files) {\n if (virtualFiles.has(file.path) || !file.imports.some((imp) => virtualFiles.has(imp.path))) continue\n\n const lang = language(file)\n if (!lang) {\n result.problems.push({ path: file.path, message: `No parser for \"${file.extname}\" files supports inline sources.` })\n continue\n }\n\n const carried: Array<ImportNode> = []\n const sources = file.sources.map((source) => ({ ...source, nodes: rewriteNodes(source.nodes, (text) => replaceNames(text, file, lang, carried).text) }))\n\n // A carried import keeps its target; `root` moves to the importing file so the relative path is computed from there.\n const imports = [...file.imports.filter((imp) => !virtualFiles.has(imp.path)), ...carried.map((imp) => (imp.root ? { ...imp, root: file.path } : imp))]\n\n result.files.push(createFile({ ...file, sources, imports }))\n }\n\n return result\n}\n\n// A file of only deprecated per-source `inline` counts as inline too.\nfunction isInlineFile(file: FileNode): boolean {\n return !!file.inline || (file.sources.length > 0 && file.sources.every((source) => source.inline))\n}\n\n// The right-hand side of a `Const` or `Type`. A function body is not an expression, and printed text such as `Code` has none.\nfunction bodyOf(source: SourceNode | undefined): string | undefined {\n if (source?.inline) return source.inline.expression\n const node = source?.nodes?.length === 1 ? source.nodes[0] : undefined\n if (node?.kind !== nodeKinds.const && node?.kind !== nodeKinds.type) return undefined\n return getNodeText(node.nodes) || undefined\n}\n\nfunction pickNames(imp: ImportNode, used: ReadonlySet<string>): Array<ImportNode> {\n const names = getNames(imp).filter((item) => used.has(item.alias ?? item.name))\n return names.length > 0 ? [createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names })] : []\n}\n\n// Rewrites the string fields `getNodeText` reads; JSDoc stays as written.\nfunction rewriteNodes(nodes: Array<CodeNode> | undefined, rewrite: (text: string) => string): Array<CodeNode> | undefined {\n return nodes?.map((node): CodeNode => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return rewrite(node) as unknown as CodeNode\n if (node.kind === nodeKinds.break) return node\n\n const next = { ...node } as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = next[field]\n if (Array.isArray(value)) next[field] = value.map(rewrite)\n if (typeof value === 'string' && value) next[field] = rewrite(value)\n }\n if ('nodes' in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite)\n return next as unknown as CodeNode\n })\n}\n","export { getRelativePath } from '../utils/combineFileMembers.ts'\nexport { inlineFiles as inline } from '../utils/inline.ts'\nexport { getNames, getSpace, isExported } from '../utils/moduleNames.ts'\n"],"mappings":";;;;;;;;;AAiDA,SAAgB,YAAY,OAAgC,EAAE,YAAmD;CAC/G,MAA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,KAAK,GAAG,KAAK,SAAS,MAAM,IAAI,OAAO;GACzD,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,SAAS,QAAQ,KAAK;EACrE;EACA,IAAI,WAAW,QAAQ,KAAK,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,OAAO;EAChF,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-z3xToonr.cjs","names":["getNames","createFile","nodeKinds","getNodeText","createImport","CODE_NODE_TEXT_FIELDS"],"sources":["../src/utils/inline.ts","../src/file/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { CodeNode } from '../nodes/code.ts'\nimport { createFile, createImport } from '../nodes/file.ts'\nimport type { FileNode, ImportNode, SourceNode } from '../nodes/file.ts'\nimport { getNames } from './moduleNames.ts'\nimport { CODE_NODE_TEXT_FIELDS, getNodeText } from './nodeText.ts'\n\nexport type InlineFilesResult = {\n /**\n * Files that imported an inline name, rewritten to hold its definition.\n */\n files: Array<FileNode>\n /**\n * Paths of the virtual files, which are not written.\n */\n virtualPaths: Array<string>\n /**\n * One message per name that could not be inlined.\n */\n problems: Array<{ path: string; message: string }>\n}\n\ntype Definition = { expression: string; imports: Array<ImportNode> }\n\n/**\n * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.\n */\nexport type InlineLanguage = {\n /**\n * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.\n */\n replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string\n /**\n * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.\n */\n wrap(expression: string): string\n}\n\nexport type InlineFilesOptions = {\n /**\n * The inline support for a file's language, or `undefined` when it has none.\n */\n language: (file: FileNode) => InlineLanguage | undefined\n}\n\n/**\n * Replaces every name a file imports from a virtual file (one marked `inline`, so it is never written) with the body of that name's\n * declaration, until no inline names are left. The definitions' own imports move to the importing file.\n */\nexport function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult {\n const virtualFiles = new Map(files.filter(isInlineFile).map((file) => [file.path, file]))\n const result: InlineFilesResult = { files: [], virtualPaths: [...virtualFiles.keys()], problems: [] }\n if (virtualFiles.size === 0) return result\n\n // `null` marks a definition that is being resolved, so a name that reaches itself is a cycle.\n const definitions = new Map<string, Definition | null>()\n\n function define(path: string, name: string, from: string, lang: InlineLanguage): Definition | undefined {\n const key = `${path}\\0${name}`\n if (definitions.has(key)) {\n const definition = definitions.get(key)\n if (definition === null) result.problems.push({ path: from, message: `\"${name}\" from \"${path}\" is defined in terms of itself.` })\n return definition ?? undefined\n }\n\n const file = virtualFiles.get(path)!\n const expression = bodyOf(file.sources.find((source) => source.name === name))\n if (expression === undefined) {\n result.problems.push({ path: from, message: `\"${name}\" is imported from \"${path}\", which never writes it and has no inline definition for it.` })\n return undefined\n }\n\n definitions.set(key, null)\n const imports: Array<ImportNode> = []\n const { text, used } = replaceNames(expression, file, lang, imports)\n imports.push(...file.imports.flatMap((imp) => (virtualFiles.has(imp.path) ? [] : pickNames(imp, used))))\n\n const definition = { expression: text, imports }\n definitions.set(key, definition)\n return definition\n }\n\n // Pushes the imports the replaced definitions need onto `imports`; `used` holds the names left as they are.\n function replaceNames(input: string, file: FileNode, lang: InlineLanguage, imports: Array<ImportNode>) {\n const used = new Set<string>()\n const text = lang.replaceIdentifiers(input, (local) => {\n const target = findTarget(file, local)\n const definition = target && define(target.path, target.name, file.path, lang)\n if (!definition) {\n used.add(local)\n return undefined\n }\n\n imports.push(...definition.imports)\n return lang.wrap(definition.expression)\n })\n\n return { text, used }\n }\n\n function findTarget(file: FileNode, local: string): { path: string; name: string } | undefined {\n if (virtualFiles.has(file.path) && file.sources.some((source) => source.name === local)) return { path: file.path, name: local }\n\n for (const imp of file.imports) {\n const item = virtualFiles.has(imp.path) && getNames(imp).find((item) => (item.alias ?? item.name) === local)\n if (item) return { path: imp.path, name: item.name }\n }\n\n return undefined\n }\n\n for (const file of files) {\n if (virtualFiles.has(file.path) || !file.imports.some((imp) => virtualFiles.has(imp.path))) continue\n\n const lang = language(file)\n if (!lang) {\n result.problems.push({ path: file.path, message: `No parser for \"${file.extname}\" files supports inline sources.` })\n continue\n }\n\n const carried: Array<ImportNode> = []\n const sources = file.sources.map((source) => ({ ...source, nodes: rewriteNodes(source.nodes, (text) => replaceNames(text, file, lang, carried).text) }))\n\n // A carried import keeps its target; `root` moves to the importing file so the relative path is computed from there.\n const imports = [...file.imports.filter((imp) => !virtualFiles.has(imp.path)), ...carried.map((imp) => (imp.root ? { ...imp, root: file.path } : imp))]\n\n result.files.push(createFile({ ...file, sources, imports }))\n }\n\n return result\n}\n\n// A file of only deprecated per-source `inline` counts as inline too.\nfunction isInlineFile(file: FileNode): boolean {\n return !!file.inline || (file.sources.length > 0 && file.sources.every((source) => source.inline))\n}\n\n// The right-hand side of a `Const` or `Type`. A function body is not an expression, and printed text such as `Code` has none.\nfunction bodyOf(source: SourceNode | undefined): string | undefined {\n if (source?.inline) return source.inline.expression\n const node = source?.nodes?.length === 1 ? source.nodes[0] : undefined\n if (node?.kind !== nodeKinds.const && node?.kind !== nodeKinds.type) return undefined\n return getNodeText(node.nodes) || undefined\n}\n\nfunction pickNames(imp: ImportNode, used: ReadonlySet<string>): Array<ImportNode> {\n const names = getNames(imp).filter((item) => used.has(item.alias ?? item.name))\n return names.length > 0 ? [createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names })] : []\n}\n\n// Rewrites the string fields `getNodeText` reads; JSDoc stays as written.\nfunction rewriteNodes(nodes: Array<CodeNode> | undefined, rewrite: (text: string) => string): Array<CodeNode> | undefined {\n return nodes?.map((node): CodeNode => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return rewrite(node) as unknown as CodeNode\n if (node.kind === nodeKinds.break) return node\n\n const next = { ...node } as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = next[field]\n if (Array.isArray(value)) next[field] = value.map(rewrite)\n if (typeof value === 'string' && value) next[field] = rewrite(value)\n }\n if ('nodes' in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite)\n return next as unknown as CodeNode\n })\n}\n","export { getRelativePath } from '../utils/combineFileMembers.ts'\nexport { inlineFiles as inline } from '../utils/inline.ts'\nexport { getNames, getSpace, isExported } from '../utils/moduleNames.ts'\n"],"mappings":";;;;;;;;;AAiDA,SAAgB,YAAY,OAAgC,EAAE,YAAmD;CAC/G,MAAM,eAAe,IAAI,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC;CACxF,MAAM,SAA4B;EAAE,OAAO,CAAC;EAAG,cAAc,CAAC,GAAG,aAAa,KAAK,CAAC;EAAG,UAAU,CAAC;CAAE;CACpG,IAAI,aAAa,SAAS,GAAG,OAAO;CAGpC,MAAM,8BAAc,IAAI,IAA+B;CAEvD,SAAS,OAAO,MAAc,MAAc,MAAc,MAA8C;EACtG,MAAM,MAAM,GAAG,KAAK,IAAI;EACxB,IAAI,YAAY,IAAI,GAAG,GAAG;GACxB,MAAM,aAAa,YAAY,IAAI,GAAG;GACtC,IAAI,eAAe,MAAM,OAAO,SAAS,KAAK;IAAE,MAAM;IAAM,SAAS,IAAI,KAAK,UAAU,KAAK;GAAkC,CAAC;GAChI,OAAO,cAAc,KAAA;EACvB;EAEA,MAAM,OAAO,aAAa,IAAI,IAAI;EAClC,MAAM,aAAa,OAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,CAAC;EAC7E,IAAI,eAAe,KAAA,GAAW;GAC5B,OAAO,SAAS,KAAK;IAAE,MAAM;IAAM,SAAS,IAAI,KAAK,sBAAsB,KAAK;GAA+D,CAAC;GAChJ;EACF;EAEA,YAAY,IAAI,KAAK,IAAI;EACzB,MAAM,UAA6B,CAAC;EACpC,MAAM,EAAE,MAAM,SAAS,aAAa,YAAY,MAAM,MAAM,OAA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,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;EAAI;CAAM,CAAC,CAAC,IAAI,CAAC;AAC1H;AAGA,SAAS,aAAa,OAAoC,SAAgE;CACxH,OAAO,OAAO,KAAK,SAAmB;EAEpC,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,IAAI;EACjD,IAAI,KAAK,SAASF,kBAAAA,UAAU,OAAO,OAAO;EAE1C,MAAM,OAAO,EAAE,GAAG,KAAK;EACvB,KAAK,MAAM,SAASG,iBAAAA,sBAAsB,KAAK,SAAS,CAAC,GAAG;GAC1D,MAAM,QAAQ,KAAK;GACnB,IAAI,MAAM,QAAQ,KAAK,GAAG,KAAK,SAAS,MAAM,IAAI,OAAO;GACzD,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,SAAS,QAAQ,KAAK;EACrE;EACA,IAAI,WAAW,QAAQ,KAAK,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,OAAO;EAChF,OAAO;CACT,CAAC;AACH"}
|
package/dist/index-CC5Rmgcm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-B3YkZ4C8.js","names":[],"sources":["../../../internals/utils/src/promise.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\nexport type Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\nexport type ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain. The first\n * rejection rejects the call, and the other workers start no new item after it.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n let failed = false\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) {\n if (failed) return\n await run(item, index).catch((error: unknown) => {\n failed = true\n throw error\n })\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,KAAmB,OAA4B,KAAW,SAA+B;CACvG,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,GAAG,GAAG,OAAO;CACnD,MAAM,QAAQ,QAAQ;CACtB,MAAM,IAAI,KAAK,KAAK;CACpB,OAAO;AACT;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,MAAM,wBAAQ,IAAI,IAAkB;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,MAAM,OAAO,KAAW,UAAkB;EACxC,IAAI,MAAM,QAAQ,KAAK,MAAM,MAAM;EACnC,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,IAAI,QAAQ,GAAG,OAAO;EAAE,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG;CAAI;CAGxF,MAAM,SAAS,QAAc;EAC3B,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACjC,OAAO;CACT;CACA,OAAO;EAAE,KAAK;EAAO,MAAM,QAAS,MAAM,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;EAAY;CAAI;AACpF;AAEA,KAAK,SAAS"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-DScaykew.cjs","names":[],"sources":["../../../internals/utils/src/promise.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\nexport type Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\nexport type ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain. The first\n * rejection rejects the call, and the other workers start no new item after it.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n let failed = false\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) {\n if (failed) return\n await run(item, index).catch((error: unknown) => {\n failed = true\n throw error\n })\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,KAAmB,OAA4B,KAAW,SAA+B;CACvG,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,GAAG,GAAG,OAAO;CACnD,MAAM,QAAQ,QAAQ;CACtB,MAAM,IAAI,KAAK,KAAK;CACpB,OAAO;AACT;AA2BA,SAAS,YAA0B,EAAE,MAAM,QAA0C,CAAC,GAAwB;CAC5G,IAAI,MAAM,uBAAO,IAAI,QAAyB;CAC9C,MAAM,wBAAQ,IAAI,IAAkB;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,MAAM,OAAO,KAAW,UAAkB;EACxC,IAAI,MAAM,QAAQ,KAAK,MAAM,MAAM;EACnC,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,IAAI,QAAQ,GAAG,OAAO;EAAE,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG,MAAM,QAAQ,MAAM,IAAI,GAAG;EAAG;CAAI;CAGxF,MAAM,SAAS,QAAc;EAC3B,IAAI,CAAC,MAAM,IAAI,GAAG,GAAG,OAAO;EAC5B,IAAI,KAAK,MAAM,IAAI,GAAG,CAAW;EACjC,OAAO;CACT;CACA,OAAO;EAAE,KAAK;EAAO,MAAM,QAAS,MAAM,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,KAAA;EAAY;CAAI;AACpF;AAEA,KAAK,SAAS"}
|