@sdk-it/core 0.46.6 → 0.46.8
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 +5 -1
- package/dist/lib/deriver.d.ts.map +1 -1
- package/dist/lib/deriver.js +4 -0
- package/dist/lib/deriver.js.map +2 -2
- package/dist/lib/program.d.ts.map +1 -1
- package/dist/lib/program.js +6 -0
- package/dist/lib/program.js.map +2 -2
- package/dist/lib/zod-jsonschema.d.ts.map +1 -1
- package/dist/lib/zod-jsonschema.js +7 -1
- package/dist/lib/zod-jsonschema.js.map +2 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -11,9 +11,13 @@ the generation pipeline.
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install @sdk-it/core typescript openapi3-ts
|
|
14
|
+
npm install @sdk-it/core zod@^4.3.0 typescript openapi3-ts
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
Schema analysis requires Zod 4.3 or later within major version 4. Imported schemas
|
|
18
|
+
must also use Zod 4, including nested schemas. Separate compatible Zod 4 package
|
|
19
|
+
instances are supported; Zod 3 runtimes and schemas receive a migration error.
|
|
20
|
+
|
|
17
21
|
## Create a TypeScript program
|
|
18
22
|
|
|
19
23
|
```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriver.d.ts","sourceRoot":"","sources":["../../src/lib/deriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,YAAY,CAAC;AAIvD,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAWrC,eAAO,MAAM,YAAY,eAA0B,CAAC;AACpD,eAAO,MAAM,MAAM,eAAsB,CAAC;AAC1C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQlD,CAAC;AAOF,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAA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,EAAE,CAAC,WAAW,CAAC;IACxC,SAAgB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,WAAW,CAAC,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;gBAE3D,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAmB;IAMxD,QAAQ,CAAC,GAAG,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAInD,OAAO,CAAC,IAAI;IAeZ,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;IAIjC,OAAO,CAAC,SAAS;IA0BjB,OAAO,CAAC,iBAAiB;IA6RzB,OAAO,CAAC,cAAc;IAStB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAiDxB,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,eAAe;IAiBvB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;CAsRlC"}
|
package/dist/lib/deriver.js
CHANGED
|
@@ -370,6 +370,10 @@ class TypeDeriver {
|
|
|
370
370
|
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
|
|
371
371
|
if (symbol && !seen.has(symbol) && declaration && ts.isVariableDeclaration(declaration) && ts.isVariableDeclarationList(declaration.parent) && declaration.parent.flags & ts.NodeFlags.Const) {
|
|
372
372
|
seen.add(symbol);
|
|
373
|
+
const narrowed = this.checker.getTypeAtLocation(expression);
|
|
374
|
+
if (narrowed !== this.checker.getTypeAtLocation(declaration.name)) {
|
|
375
|
+
return narrowed;
|
|
376
|
+
}
|
|
373
377
|
if (declaration.type) {
|
|
374
378
|
return this.checker.getTypeFromTypeNode(declaration.type);
|
|
375
379
|
}
|
package/dist/lib/deriver.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/deriver.ts"],
|
|
4
|
-
"sourcesContent": ["import ts, { TypeFlags, symbolName } from 'typescript';\n\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\n\n/**\n * How literal values met while serializing collapse to their base type.\n * - none: keep every literal (top-level response objects).\n * - values: array items are representative, so literals read straight off an\n * item's initializer collapse while declared literal types keep their values.\n * - all: const-asserted tuples collapse every literal.\n */\ntype LiteralWidening = 'none' | 'values' | 'all';\n\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\nexport const defaultTypesMap: Record<string, string> = {\n Readable: 'any',\n ReadableStream: 'any',\n DateConstructor: 'string',\n ArrayBufferConstructor: 'any',\n SharedArrayBufferConstructor: 'any',\n Int8ArrayConstructor: 'any',\n Uint8Array: 'any',\n};\n\ninterface TraceContext {\n file?: string;\n operation?: string;\n}\n\nexport function nodeLocation(node: ts.Node): string | undefined {\n try {\n const sourceFile = node.getSourceFile();\n if (!sourceFile) return undefined;\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(),\n );\n return `${sourceFile.fileName}:${line + 1}:${character + 1}`;\n } catch {\n return undefined;\n }\n}\n\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n public readonly typesMap: Record<string, string>;\n private trace: TraceContext = {};\n private currentNode?: ts.Node;\n private readonly activeAliases = new Map<ts.Type, boolean>();\n constructor(\n checker: ts.TypeChecker,\n typeMappings: Record<string, string> = defaultTypesMap,\n ) {\n this.checker = checker;\n this.typesMap = typeMappings;\n }\n\n setTrace(ctx: { file?: string; operation?: string }) {\n this.trace = { ...ctx };\n }\n\n private warn(message: string, node?: ts.Node) {\n const parts = [`\\x1b[33m\\u26a0 ${message}\\x1b[0m`];\n const resolvedNode = node ?? this.currentNode;\n const location = resolvedNode ? nodeLocation(resolvedNode) : undefined;\n if (location) {\n parts.push(` at \\x1b[36m${location}\\x1b[0m`);\n } else if (this.trace.file) {\n parts.push(` at \\x1b[36m${this.trace.file}\\x1b[0m`);\n }\n if (this.trace.operation) {\n parts.push(` in \\x1b[2m${this.trace.operation}\\x1b[0m`);\n }\n console.warn(parts.join('\\n'));\n }\n\n serializeType(type: ts.Type): any {\n return this.serialize(type, 'none');\n }\n\n private serialize(type: ts.Type, widening: LiteralWidening): unknown {\n const alias = type.aliasSymbol?.getName();\n if (!alias) {\n return this.serializeResolved(type, widening);\n }\n if (this.activeAliases.has(type)) {\n this.activeAliases.set(type, true);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${alias}`],\n };\n }\n\n this.activeAliases.set(type, false);\n try {\n const result = this.serializeResolved(type, widening);\n if (this.activeAliases.get(type)) {\n this.collector[alias] = result;\n }\n return result;\n } finally {\n this.activeAliases.delete(type);\n }\n }\n\n private serializeResolved(type: ts.Type, widening: LiteralWidening): unknown {\n if (this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()],\n ],\n };\n }\n if (type.symbol?.getName() === 'Date') {\n return {\n [deriveSymbol]: true,\n kind: 'date',\n optional: false,\n [$types]: ['string'],\n };\n }\n const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serialize(indexType, widening)],\n };\n }\n if (type.flags & TypeFlags.Any) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & TypeFlags.Unknown) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & (TypeFlags.Never | TypeFlags.Undefined)) {\n return {\n [deriveSymbol]: true,\n kind: 'never',\n optional: (type.flags & TypeFlags.Undefined) !== 0,\n [$types]: [],\n };\n }\n if (type.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all'\n ? {}\n : {\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\n }),\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.TemplateLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.String) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.Number) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['number'],\n };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.Null) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const intersectionType of type.types) {\n if (optional === undefined) {\n optional = (intersectionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(intersectionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'intersection',\n optional,\n [$types]: types,\n };\n }\n if (type.isUnion()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n // ignore undefined\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(unionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const elementType = this.checker.getIndexTypeOfType(\n type,\n ts.IndexKind.Number,\n );\n if (!elementType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(`Could not find element type for array type ${typeName}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const mappedElementType =\n this.typesMap[\n elementType.aliasSymbol?.getName() || elementType.symbol?.getName()\n ];\n const itemWidening: LiteralWidening =\n widening === 'all' || this.checker.isTupleType(type) ? 'all' : 'values';\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: mappedElementType\n ? [mappedElementType]\n : [this.serialize(elementType, itemWidening)],\n };\n }\n if (type.isClass()) {\n const declaration = type.symbol?.valueDeclaration;\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n if (type.symbol?.flags & ts.SymbolFlags.Interface) {\n const name = type.symbol.getName();\n if (!this.collector[name]) {\n this.collector[name] = {};\n const properties: Record<string, unknown> = {};\n for (const property of this.checker.getPropertiesOfType(type)) {\n properties[property.name] = this.serializeType(\n this.checker.getTypeOfSymbol(property),\n );\n }\n this.collector[name] = sortObjectKeys(properties);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${name}`],\n };\n }\n if (type.flags & TypeFlags.Object) {\n if (this.typesMap[symbolName(type.symbol)]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[symbolName(type.symbol)]],\n };\n }\n const properties = this.checker.getPropertiesOfType(type);\n if (properties.length > 0) {\n const serializedProps: Record<string, any> = {};\n for (const prop of properties) {\n const declarations = prop.getDeclarations() ?? [];\n const propAssingment = declarations.find((it) =>\n ts.isPropertyAssignment(it),\n );\n const shorthand = declarations.find((it) =>\n ts.isShorthandPropertyAssignment(it),\n );\n const shorthandType = shorthand\n ? this.typeOfShorthand(shorthand)\n : undefined;\n // get literal properties values if any\n if (propAssingment) {\n serializedProps[prop.name] = this.serializeValue(\n this.typeOfExpression(propAssingment.initializer),\n widening,\n );\n } else if (shorthandType) {\n serializedProps[prop.name] = this.serializeValue(\n shorthandType,\n widening,\n );\n } else {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\n }\n }\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [sortObjectKeys(serializedProps)],\n };\n }\n const declaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n\n this.warn(`Unhandled type: ${type.flags} ${ts.TypeFlags[type.flags]}`);\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.checker.typeToString(\n type,\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n ),\n ],\n };\n }\n\n private serializeValue(type: ts.Type, widening: LiteralWidening): unknown {\n const isLiteral =\n type.isLiteral() || (type.flags & TypeFlags.BooleanLiteral) !== 0;\n return this.serialize(\n type,\n widening === 'values' && isLiteral ? 'all' : widening,\n );\n }\n\n /**\n * Preserve the inferred type of `satisfies` expressions unless the operand is\n * an empty array; only then recover its declared element type.\n */\n private typeOfExpression(\n node: ts.Expression,\n seen = new Set<ts.Symbol>(),\n ): ts.Type {\n const satisfies = this.emptyArraySatisfies(node);\n if (satisfies) {\n return this.checker.getTypeFromTypeNode(satisfies.type);\n }\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n\n if (ts.isIdentifier(expression)) {\n const symbol = this.checker.getSymbolAtLocation(expression);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n symbol &&\n !seen.has(symbol) &&\n declaration &&\n ts.isVariableDeclaration(declaration) &&\n ts.isVariableDeclarationList(declaration.parent) &&\n declaration.parent.flags & ts.NodeFlags.Const\n ) {\n seen.add(symbol);\n if (declaration.type) {\n return this.checker.getTypeFromTypeNode(declaration.type);\n }\n if (declaration.initializer) {\n return this.typeOfExpression(declaration.initializer, seen);\n }\n }\n }\n\n if (\n ts.isArrayLiteralExpression(expression) &&\n expression.elements.length === 1 &&\n ts.isSpreadElement(expression.elements[0])\n ) {\n return this.typeOfExpression(expression.elements[0].expression, seen);\n }\n\n return this.checker.getTypeAtLocation(expression);\n }\n\n private emptyArraySatisfies(\n node: ts.Expression,\n ): ts.SatisfiesExpression | undefined {\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n if (!ts.isSatisfiesExpression(expression)) {\n return undefined;\n }\n let operand = expression.expression;\n while (ts.isParenthesizedExpression(operand)) {\n operand = operand.expression;\n }\n if (!ts.isArrayLiteralExpression(operand) || operand.elements.length > 0) {\n return undefined;\n }\n const annotation = this.checker.getTypeFromTypeNode(expression.type);\n return this.checker.isArrayLikeType(annotation) ? expression : undefined;\n }\n\n private typeOfShorthand(\n node: ts.ShorthandPropertyAssignment,\n ): ts.Type | undefined {\n const symbol = this.checker.getShorthandAssignmentValueSymbol(node);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n !declaration ||\n !ts.isVariableDeclaration(declaration) ||\n !declaration.initializer\n ) {\n return undefined;\n }\n return this.emptyArraySatisfies(declaration.initializer)\n ? this.typeOfExpression(declaration.initializer)\n : this.checker.getTypeAtLocation(node.name);\n }\n\n serializeNode(node: ts.Node): any {\n this.currentNode = node;\n if (ts.isObjectLiteralExpression(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, any> = {};\n\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n props[prop.name.getText()] = this.serializeType(\n this.typeOfExpression(prop.initializer),\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const type = this.typeOfShorthand(prop);\n if (type) {\n props[prop.name.text] = this.serializeType(type);\n }\n }\n }\n\n for (const symbol of symbolType.getProperties()) {\n if (!Object.hasOwn(props, symbol.name)) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n }\n\n return sortObjectKeys(props);\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertySignature(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertyDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isInterfaceDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Interface has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertySignature)) {\n members[member.name.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (ts.isClassDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Class has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, unknown> = {};\n for (const member of node.members.filter(ts.isPropertyDeclaration)) {\n members[member.name!.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n $ref: `#/components/schemas/${node.name.text}`,\n };\n }\n if (ts.isVariableDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n if (!node.type) {\n this.warn(`No type found for ${node.name.getText()}`, node);\n return 'any';\n }\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\n }\n if (ts.isIdentifier(node)) {\n const symbol = this.checker.getSymbolAtLocation(node);\n if (!symbol) {\n this.warn(`No symbol found for identifier ${node.getText()}`, node);\n return null;\n }\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isAwaitExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isCallOrNewExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAsExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isSatisfiesExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n if (ts.isTypeLiteralNode(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, unknown> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [sortObjectKeys(props)],\n };\n }\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (node.kind === ts.SyntaxKind.BooleanKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.TrueKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: true,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.FalseKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: false,\n [$types]: ['boolean'],\n };\n }\n if (ts.isFunctionDeclaration(node)) {\n if (!node.name) {\n this.warn('Function declaration has no name', node);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n\n const functionName = node.name.text;\n if (this.typesMap[functionName]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[functionName]],\n };\n }\n\n if (node.type) {\n const returnType = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(returnType);\n }\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n if (ts.isArrayLiteralExpression(node)) {\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n // Handle template literals in expression position\n if (\n ts.isTemplateExpression(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isTaggedTemplateExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle binary expressions (||, &&, +, -, etc.)\n if (ts.isBinaryExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle conditional/ternary expressions (x ? y : z)\n if (ts.isConditionalExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle parenthesized expressions ((value))\n if (ts.isParenthesizedExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n\n // Handle non-null assertions (value!)\n if (ts.isNonNullExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n this.warn(\n `Unhandled node: ${ts.SyntaxKind[node.kind]} \"${node.getText()}\" (type: ${this.checker.typeToString(\n this.checker.getTypeAtLocation(node),\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n )})`,\n node,\n );\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,MAAM,WAAW,kBAAkB;AAE1C,SAAS,sBAAsB;AAaxB,MAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,MAAM,SAAS,OAAO,IAAI,OAAO;AACjC,MAAM,kBAA0C;AAAA,EACrD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,sBAAsB;AAAA,EACtB,YAAY;AACd;AAOO,SAAS,aAAa,MAAmC;AAC9D,MAAI;AACF,UAAM,aAAa,KAAK,cAAc;AACtC,QAAI,CAAC,WAAY,QAAO;AACxB,UAAM,EAAE,MAAM,UAAU,IAAI,WAAW;AAAA,MACrC,KAAK,SAAS;AAAA,IAChB;AACA,WAAO,GAAG,WAAW,QAAQ,IAAI,OAAO,CAAC,IAAI,YAAY,CAAC;AAAA,EAC5D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,MAAM,YAAY;AAAA,EACP,YAAuB,CAAC;AAAA,EACxB;AAAA,EACA;AAAA,EACR,QAAsB,CAAC;AAAA,EACvB;AAAA,EACS,gBAAgB,oBAAI,IAAsB;AAAA,EAC3D,YACE,SACA,eAAuC,iBACvC;AACA,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,SAAS,KAA4C;AACnD,SAAK,QAAQ,EAAE,GAAG,IAAI;AAAA,EACxB;AAAA,EAEQ,KAAK,SAAiB,MAAgB;AAC5C,UAAM,QAAQ,CAAC,kBAAkB,OAAO,SAAS;AACjD,UAAM,eAAe,QAAQ,KAAK;AAClC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A,GAAG,gBAAgB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,CAAC,YAAY,GAAG;AAAA,MAChB,UAAU;AAAA,MACV,CAAC,MAAM,GAAG,CAAC,KAAK;AAAA,IAClB;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import ts, { TypeFlags, symbolName } from 'typescript';\n\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\n\n/**\n * How literal values met while serializing collapse to their base type.\n * - none: keep every literal (top-level response objects).\n * - values: array items are representative, so literals read straight off an\n * item's initializer collapse while declared literal types keep their values.\n * - all: const-asserted tuples collapse every literal.\n */\ntype LiteralWidening = 'none' | 'values' | 'all';\n\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\nexport const defaultTypesMap: Record<string, string> = {\n Readable: 'any',\n ReadableStream: 'any',\n DateConstructor: 'string',\n ArrayBufferConstructor: 'any',\n SharedArrayBufferConstructor: 'any',\n Int8ArrayConstructor: 'any',\n Uint8Array: 'any',\n};\n\ninterface TraceContext {\n file?: string;\n operation?: string;\n}\n\nexport function nodeLocation(node: ts.Node): string | undefined {\n try {\n const sourceFile = node.getSourceFile();\n if (!sourceFile) return undefined;\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(),\n );\n return `${sourceFile.fileName}:${line + 1}:${character + 1}`;\n } catch {\n return undefined;\n }\n}\n\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n public readonly typesMap: Record<string, string>;\n private trace: TraceContext = {};\n private currentNode?: ts.Node;\n private readonly activeAliases = new Map<ts.Type, boolean>();\n constructor(\n checker: ts.TypeChecker,\n typeMappings: Record<string, string> = defaultTypesMap,\n ) {\n this.checker = checker;\n this.typesMap = typeMappings;\n }\n\n setTrace(ctx: { file?: string; operation?: string }) {\n this.trace = { ...ctx };\n }\n\n private warn(message: string, node?: ts.Node) {\n const parts = [`\\x1b[33m\\u26a0 ${message}\\x1b[0m`];\n const resolvedNode = node ?? this.currentNode;\n const location = resolvedNode ? nodeLocation(resolvedNode) : undefined;\n if (location) {\n parts.push(` at \\x1b[36m${location}\\x1b[0m`);\n } else if (this.trace.file) {\n parts.push(` at \\x1b[36m${this.trace.file}\\x1b[0m`);\n }\n if (this.trace.operation) {\n parts.push(` in \\x1b[2m${this.trace.operation}\\x1b[0m`);\n }\n console.warn(parts.join('\\n'));\n }\n\n serializeType(type: ts.Type): any {\n return this.serialize(type, 'none');\n }\n\n private serialize(type: ts.Type, widening: LiteralWidening): unknown {\n const alias = type.aliasSymbol?.getName();\n if (!alias) {\n return this.serializeResolved(type, widening);\n }\n if (this.activeAliases.has(type)) {\n this.activeAliases.set(type, true);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${alias}`],\n };\n }\n\n this.activeAliases.set(type, false);\n try {\n const result = this.serializeResolved(type, widening);\n if (this.activeAliases.get(type)) {\n this.collector[alias] = result;\n }\n return result;\n } finally {\n this.activeAliases.delete(type);\n }\n }\n\n private serializeResolved(type: ts.Type, widening: LiteralWidening): unknown {\n if (this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()],\n ],\n };\n }\n if (type.symbol?.getName() === 'Date') {\n return {\n [deriveSymbol]: true,\n kind: 'date',\n optional: false,\n [$types]: ['string'],\n };\n }\n const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serialize(indexType, widening)],\n };\n }\n if (type.flags & TypeFlags.Any) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & TypeFlags.Unknown) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & (TypeFlags.Never | TypeFlags.Undefined)) {\n return {\n [deriveSymbol]: true,\n kind: 'never',\n optional: (type.flags & TypeFlags.Undefined) !== 0,\n [$types]: [],\n };\n }\n if (type.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all'\n ? {}\n : {\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\n }),\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.TemplateLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.String) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.Number) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['number'],\n };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.Null) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const intersectionType of type.types) {\n if (optional === undefined) {\n optional = (intersectionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(intersectionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'intersection',\n optional,\n [$types]: types,\n };\n }\n if (type.isUnion()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n // ignore undefined\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(unionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const elementType = this.checker.getIndexTypeOfType(\n type,\n ts.IndexKind.Number,\n );\n if (!elementType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(`Could not find element type for array type ${typeName}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const mappedElementType =\n this.typesMap[\n elementType.aliasSymbol?.getName() || elementType.symbol?.getName()\n ];\n const itemWidening: LiteralWidening =\n widening === 'all' || this.checker.isTupleType(type) ? 'all' : 'values';\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: mappedElementType\n ? [mappedElementType]\n : [this.serialize(elementType, itemWidening)],\n };\n }\n if (type.isClass()) {\n const declaration = type.symbol?.valueDeclaration;\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n if (type.symbol?.flags & ts.SymbolFlags.Interface) {\n const name = type.symbol.getName();\n if (!this.collector[name]) {\n this.collector[name] = {};\n const properties: Record<string, unknown> = {};\n for (const property of this.checker.getPropertiesOfType(type)) {\n properties[property.name] = this.serializeType(\n this.checker.getTypeOfSymbol(property),\n );\n }\n this.collector[name] = sortObjectKeys(properties);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${name}`],\n };\n }\n if (type.flags & TypeFlags.Object) {\n if (this.typesMap[symbolName(type.symbol)]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[symbolName(type.symbol)]],\n };\n }\n const properties = this.checker.getPropertiesOfType(type);\n if (properties.length > 0) {\n const serializedProps: Record<string, any> = {};\n for (const prop of properties) {\n const declarations = prop.getDeclarations() ?? [];\n const propAssingment = declarations.find((it) =>\n ts.isPropertyAssignment(it),\n );\n const shorthand = declarations.find((it) =>\n ts.isShorthandPropertyAssignment(it),\n );\n const shorthandType = shorthand\n ? this.typeOfShorthand(shorthand)\n : undefined;\n // get literal properties values if any\n if (propAssingment) {\n serializedProps[prop.name] = this.serializeValue(\n this.typeOfExpression(propAssingment.initializer),\n widening,\n );\n } else if (shorthandType) {\n serializedProps[prop.name] = this.serializeValue(\n shorthandType,\n widening,\n );\n } else {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\n }\n }\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [sortObjectKeys(serializedProps)],\n };\n }\n const declaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n\n this.warn(`Unhandled type: ${type.flags} ${ts.TypeFlags[type.flags]}`);\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.checker.typeToString(\n type,\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n ),\n ],\n };\n }\n\n private serializeValue(type: ts.Type, widening: LiteralWidening): unknown {\n const isLiteral =\n type.isLiteral() || (type.flags & TypeFlags.BooleanLiteral) !== 0;\n return this.serialize(\n type,\n widening === 'values' && isLiteral ? 'all' : widening,\n );\n }\n\n /**\n * Preserve the inferred type of `satisfies` expressions unless the operand is\n * an empty array; only then recover its declared element type.\n */\n private typeOfExpression(\n node: ts.Expression,\n seen = new Set<ts.Symbol>(),\n ): ts.Type {\n const satisfies = this.emptyArraySatisfies(node);\n if (satisfies) {\n return this.checker.getTypeFromTypeNode(satisfies.type);\n }\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n\n if (ts.isIdentifier(expression)) {\n const symbol = this.checker.getSymbolAtLocation(expression);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n symbol &&\n !seen.has(symbol) &&\n declaration &&\n ts.isVariableDeclaration(declaration) &&\n ts.isVariableDeclarationList(declaration.parent) &&\n declaration.parent.flags & ts.NodeFlags.Const\n ) {\n seen.add(symbol);\n const narrowed = this.checker.getTypeAtLocation(expression);\n if (narrowed !== this.checker.getTypeAtLocation(declaration.name)) {\n return narrowed;\n }\n if (declaration.type) {\n return this.checker.getTypeFromTypeNode(declaration.type);\n }\n if (declaration.initializer) {\n return this.typeOfExpression(declaration.initializer, seen);\n }\n }\n }\n\n if (\n ts.isArrayLiteralExpression(expression) &&\n expression.elements.length === 1 &&\n ts.isSpreadElement(expression.elements[0])\n ) {\n return this.typeOfExpression(expression.elements[0].expression, seen);\n }\n\n return this.checker.getTypeAtLocation(expression);\n }\n\n private emptyArraySatisfies(\n node: ts.Expression,\n ): ts.SatisfiesExpression | undefined {\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n if (!ts.isSatisfiesExpression(expression)) {\n return undefined;\n }\n let operand = expression.expression;\n while (ts.isParenthesizedExpression(operand)) {\n operand = operand.expression;\n }\n if (!ts.isArrayLiteralExpression(operand) || operand.elements.length > 0) {\n return undefined;\n }\n const annotation = this.checker.getTypeFromTypeNode(expression.type);\n return this.checker.isArrayLikeType(annotation) ? expression : undefined;\n }\n\n private typeOfShorthand(\n node: ts.ShorthandPropertyAssignment,\n ): ts.Type | undefined {\n const symbol = this.checker.getShorthandAssignmentValueSymbol(node);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n !declaration ||\n !ts.isVariableDeclaration(declaration) ||\n !declaration.initializer\n ) {\n return undefined;\n }\n return this.emptyArraySatisfies(declaration.initializer)\n ? this.typeOfExpression(declaration.initializer)\n : this.checker.getTypeAtLocation(node.name);\n }\n\n serializeNode(node: ts.Node): any {\n this.currentNode = node;\n if (ts.isObjectLiteralExpression(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, any> = {};\n\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n props[prop.name.getText()] = this.serializeType(\n this.typeOfExpression(prop.initializer),\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const type = this.typeOfShorthand(prop);\n if (type) {\n props[prop.name.text] = this.serializeType(type);\n }\n }\n }\n\n for (const symbol of symbolType.getProperties()) {\n if (!Object.hasOwn(props, symbol.name)) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n }\n\n return sortObjectKeys(props);\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertySignature(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertyDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isInterfaceDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Interface has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertySignature)) {\n members[member.name.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (ts.isClassDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Class has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, unknown> = {};\n for (const member of node.members.filter(ts.isPropertyDeclaration)) {\n members[member.name!.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n $ref: `#/components/schemas/${node.name.text}`,\n };\n }\n if (ts.isVariableDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n if (!node.type) {\n this.warn(`No type found for ${node.name.getText()}`, node);\n return 'any';\n }\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\n }\n if (ts.isIdentifier(node)) {\n const symbol = this.checker.getSymbolAtLocation(node);\n if (!symbol) {\n this.warn(`No symbol found for identifier ${node.getText()}`, node);\n return null;\n }\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isAwaitExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isCallOrNewExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAsExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isSatisfiesExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n if (ts.isTypeLiteralNode(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, unknown> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [sortObjectKeys(props)],\n };\n }\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (node.kind === ts.SyntaxKind.BooleanKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.TrueKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: true,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.FalseKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: false,\n [$types]: ['boolean'],\n };\n }\n if (ts.isFunctionDeclaration(node)) {\n if (!node.name) {\n this.warn('Function declaration has no name', node);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n\n const functionName = node.name.text;\n if (this.typesMap[functionName]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[functionName]],\n };\n }\n\n if (node.type) {\n const returnType = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(returnType);\n }\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n if (ts.isArrayLiteralExpression(node)) {\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n // Handle template literals in expression position\n if (\n ts.isTemplateExpression(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isTaggedTemplateExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle binary expressions (||, &&, +, -, etc.)\n if (ts.isBinaryExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle conditional/ternary expressions (x ? y : z)\n if (ts.isConditionalExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle parenthesized expressions ((value))\n if (ts.isParenthesizedExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n\n // Handle non-null assertions (value!)\n if (ts.isNonNullExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n this.warn(\n `Unhandled node: ${ts.SyntaxKind[node.kind]} \"${node.getText()}\" (type: ${this.checker.typeToString(\n this.checker.getTypeAtLocation(node),\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n )})`,\n node,\n );\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,MAAM,WAAW,kBAAkB;AAE1C,SAAS,sBAAsB;AAaxB,MAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,MAAM,SAAS,OAAO,IAAI,OAAO;AACjC,MAAM,kBAA0C;AAAA,EACrD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,sBAAsB;AAAA,EACtB,YAAY;AACd;AAOO,SAAS,aAAa,MAAmC;AAC9D,MAAI;AACF,UAAM,aAAa,KAAK,cAAc;AACtC,QAAI,CAAC,WAAY,QAAO;AACxB,UAAM,EAAE,MAAM,UAAU,IAAI,WAAW;AAAA,MACrC,KAAK,SAAS;AAAA,IAChB;AACA,WAAO,GAAG,WAAW,QAAQ,IAAI,OAAO,CAAC,IAAI,YAAY,CAAC;AAAA,EAC5D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,MAAM,YAAY;AAAA,EACP,YAAuB,CAAC;AAAA,EACxB;AAAA,EACA;AAAA,EACR,QAAsB,CAAC;AAAA,EACvB;AAAA,EACS,gBAAgB,oBAAI,IAAsB;AAAA,EAC3D,YACE,SACA,eAAuC,iBACvC;AACA,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,SAAS,KAA4C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D;AAGA,QAAI,GAAG,oBAAoB,IAAI,GAAG;AAChC,YAAM,OAAO,KAAK,QAAQ,kBAAkB,IAAI;AAChD,aAAO,KAAK,cAAc,IAAI;AAAA,IAChC;AAEA,SAAK;AAAA,MACH,mBAAmB,GAAG,WAAW,KAAK,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,YAAY,KAAK,QAAQ;AAAA,QACrF,KAAK,QAAQ,kBAAkB,IAAI;AAAA,QACnC;AAAA,QACA,GAAG,gBAAgB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,CAAC,YAAY,GAAG;AAAA,MAChB,UAAU;AAAA,MACV,CAAC,MAAM,GAAG,CAAC,KAAK;AAAA,IAClB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,wBAkCjD;AACD,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,wBAkCjD;AACD,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,cAoB9C;AACD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,qCAOhE;AACD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,IAAI,EAAE,MAAM,GACX,IAAI,IAAI,EAAE,CAAC,cAAc,CAO3B;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAMtD"}
|
package/dist/lib/program.js
CHANGED
|
@@ -40,6 +40,12 @@ function getProgram(tsconfigPath) {
|
|
|
40
40
|
return ts.createProgram({
|
|
41
41
|
options: {
|
|
42
42
|
...tsConfigParseResult.options,
|
|
43
|
+
// Packages may expose their implementation for static analysis while
|
|
44
|
+
// keeping ordinary consumers on declarations and compiled JavaScript.
|
|
45
|
+
customConditions: [
|
|
46
|
+
"@sdk-it/source",
|
|
47
|
+
...tsConfigParseResult.options.customConditions ?? []
|
|
48
|
+
],
|
|
43
49
|
noEmit: true,
|
|
44
50
|
incremental: true,
|
|
45
51
|
tsBuildInfoFile: join(dirname(tsconfigPath), "./.tsbuildinfo")
|
package/dist/lib/program.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/program.ts"],
|
|
4
|
-
"sourcesContent": ["import debug from 'debug';\nimport { dirname, join } from 'node:path';\nimport ts from 'typescript';\n\nconst logger = debug('january:client');\n\nexport function parseTsConfig(tsconfigPath: string) {\n logger(`Using TypeScript version: ${ts.version}`);\n const configContent = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configContent.error) {\n console.error(\n `Failed to read tsconfig file:`,\n ts.formatDiagnosticsWithColorAndContext([configContent.error], {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configContent.config,\n ts.sys,\n dirname(tsconfigPath),\n );\n\n if (parsed.errors.length > 0) {\n console.error(\n `Errors found in tsconfig.json:`,\n ts.formatDiagnosticsWithColorAndContext(parsed.errors, {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n return parsed;\n}\nexport function getProgram(tsconfigPath: string) {\n const tsConfigParseResult = parseTsConfig(tsconfigPath);\n logger(`Parsing tsconfig`);\n return ts.createProgram({\n options: {\n ...tsConfigParseResult.options,\n noEmit: true,\n incremental: true,\n tsBuildInfoFile: join(dirname(tsconfigPath), './.tsbuildinfo'), // not working atm\n },\n rootNames: tsConfigParseResult.fileNames,\n projectReferences: tsConfigParseResult.projectReferences,\n configFileParsingDiagnostics: tsConfigParseResult.errors,\n });\n}\nexport function getPropertyAssignment(node: ts.Node, name: string) {\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties\n .filter((prop) => ts.isPropertyAssignment(prop))\n .find((prop) => prop.name!.getText() === name);\n }\n return undefined;\n}\nexport function isCallExpression(\n node: ts.Node,\n name: string,\n): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n node.expression &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === name\n );\n}\n\nexport function isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,SAAS,YAAY;AAC9B,OAAO,QAAQ;AAEf,MAAM,SAAS,MAAM,gBAAgB;AAE9B,SAAS,cAAc,cAAsB;AAClD,SAAO,6BAA6B,GAAG,OAAO,EAAE;AAChD,QAAM,gBAAgB,GAAG,eAAe,cAAc,GAAG,IAAI,QAAQ;AAErE,MAAI,cAAc,OAAO;AACvB,YAAQ;AAAA,MACN;AAAA,MACA,GAAG,qCAAqC,CAAC,cAAc,KAAK,GAAG;AAAA,QAC7D,sBAAsB,CAAC,SAAS;AAAA,QAChC,qBAAqB,GAAG,IAAI;AAAA,QAC5B,YAAY,MAAM,GAAG,IAAI;AAAA,MAC3B,CAAC;AAAA,IACH;AACA,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,SAAS,GAAG;AAAA,IAChB,cAAc;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,YAAY;AAAA,EACtB;AAEA,MAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,YAAQ;AAAA,MACN;AAAA,MACA,GAAG,qCAAqC,OAAO,QAAQ;AAAA,QACrD,sBAAsB,CAAC,SAAS;AAAA,QAChC,qBAAqB,GAAG,IAAI;AAAA,QAC5B,YAAY,MAAM,GAAG,IAAI;AAAA,MAC3B,CAAC;AAAA,IACH;AACA,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,SAAO;AACT;AACO,SAAS,WAAW,cAAsB;AAC/C,QAAM,sBAAsB,cAAc,YAAY;AACtD,SAAO,kBAAkB;AACzB,SAAO,GAAG,cAAc;AAAA,IACtB,SAAS;AAAA,MACP,GAAG,oBAAoB;AAAA,
|
|
4
|
+
"sourcesContent": ["import debug from 'debug';\nimport { dirname, join } from 'node:path';\nimport ts from 'typescript';\n\nconst logger = debug('january:client');\n\nexport function parseTsConfig(tsconfigPath: string) {\n logger(`Using TypeScript version: ${ts.version}`);\n const configContent = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configContent.error) {\n console.error(\n `Failed to read tsconfig file:`,\n ts.formatDiagnosticsWithColorAndContext([configContent.error], {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configContent.config,\n ts.sys,\n dirname(tsconfigPath),\n );\n\n if (parsed.errors.length > 0) {\n console.error(\n `Errors found in tsconfig.json:`,\n ts.formatDiagnosticsWithColorAndContext(parsed.errors, {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n return parsed;\n}\nexport function getProgram(tsconfigPath: string) {\n const tsConfigParseResult = parseTsConfig(tsconfigPath);\n logger(`Parsing tsconfig`);\n return ts.createProgram({\n options: {\n ...tsConfigParseResult.options,\n // Packages may expose their implementation for static analysis while\n // keeping ordinary consumers on declarations and compiled JavaScript.\n customConditions: [\n '@sdk-it/source',\n ...(tsConfigParseResult.options.customConditions ?? []),\n ],\n noEmit: true,\n incremental: true,\n tsBuildInfoFile: join(dirname(tsconfigPath), './.tsbuildinfo'), // not working atm\n },\n rootNames: tsConfigParseResult.fileNames,\n projectReferences: tsConfigParseResult.projectReferences,\n configFileParsingDiagnostics: tsConfigParseResult.errors,\n });\n}\nexport function getPropertyAssignment(node: ts.Node, name: string) {\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties\n .filter((prop) => ts.isPropertyAssignment(prop))\n .find((prop) => prop.name!.getText() === name);\n }\n return undefined;\n}\nexport function isCallExpression(\n node: ts.Node,\n name: string,\n): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n node.expression &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === name\n );\n}\n\nexport function isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,SAAS,YAAY;AAC9B,OAAO,QAAQ;AAEf,MAAM,SAAS,MAAM,gBAAgB;AAE9B,SAAS,cAAc,cAAsB;AAClD,SAAO,6BAA6B,GAAG,OAAO,EAAE;AAChD,QAAM,gBAAgB,GAAG,eAAe,cAAc,GAAG,IAAI,QAAQ;AAErE,MAAI,cAAc,OAAO;AACvB,YAAQ;AAAA,MACN;AAAA,MACA,GAAG,qCAAqC,CAAC,cAAc,KAAK,GAAG;AAAA,QAC7D,sBAAsB,CAAC,SAAS;AAAA,QAChC,qBAAqB,GAAG,IAAI;AAAA,QAC5B,YAAY,MAAM,GAAG,IAAI;AAAA,MAC3B,CAAC;AAAA,IACH;AACA,UAA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S;AAE7B;AAEO,SAAS,gBAAgB,MAAwB;AACtD,MAAI,KAAK,mBAAmB,GAAG;AAE7B,WAAO,CAAC,EAAE,KAAK,OAAO,QAAQ,GAAG,YAAY;AAAA,EAC/C;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-jsonschema.d.ts","sourceRoot":"","sources":["../../src/lib/zod-jsonschema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,EAAO,
|
|
1
|
+
{"version":3,"file":"zod-jsonschema.d.ts","sourceRoot":"","sources":["../../src/lib/zod-jsonschema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,EAAO,gBA0nBzE"}
|
|
@@ -7,6 +7,9 @@ async function evalZod(schema, imports = []) {
|
|
|
7
7
|
`const filename = "${import.meta.url}";`,
|
|
8
8
|
`const require = createRequire(filename);`,
|
|
9
9
|
`const z = require("zod");`,
|
|
10
|
+
`if (typeof z.toJSONSchema !== 'function') {
|
|
11
|
+
throw new Error('@sdk-it/core requires Zod 4. Install zod@^4.3.0 and migrate Zod 3 schemas before analysis.');
|
|
12
|
+
}`,
|
|
10
13
|
// zod 4 removed ZodString.ip/.cidr; restore them for analyzed user source
|
|
11
14
|
// that still uses the v3 spellings.
|
|
12
15
|
`const stringProto = Object.getPrototypeOf(z.string());
|
|
@@ -106,7 +109,10 @@ async function evalZod(schema, imports = []) {
|
|
|
106
109
|
// runs, which throws on bigint. Mask them as sentinel strings up front
|
|
107
110
|
// and restore after conversion.
|
|
108
111
|
`function maskBigIntDefaults(schema, seen = new Set()) {
|
|
109
|
-
if (!schema ||
|
|
112
|
+
if (!schema?._zod || schema._zod.version?.major !== 4) {
|
|
113
|
+
throw new Error('@sdk-it/core requires Zod 4 schemas; migrate imported Zod 3 schemas before analysis.');
|
|
114
|
+
}
|
|
115
|
+
if (seen.has(schema)) return;
|
|
110
116
|
seen.add(schema);
|
|
111
117
|
const def = schema._zod.def;
|
|
112
118
|
if (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/zod-jsonschema.ts"],
|
|
4
|
-
"sourcesContent": ["export type InjectImport = {\n import: string;\n from: string;\n property?: string;\n};\n\nfunction removeUnsupportedMethods(schema: string) {\n return schema\n .replaceAll('.instanceof(File)', '.string().base64()')\n .replaceAll('.instanceof(Blob)', '.string().base64()')\n .replaceAll('.custom<File>()', '.string().base64()')\n .replaceAll('.custom<Blob>()', '.string().base64()');\n}\n\nexport async function evalZod(schema: string, imports: InjectImport[] = []) {\n // https://github.com/nodejs/node/issues/51956\n const lines = [\n `import { createRequire } from \"node:module\";`,\n `const filename = \"${import.meta.url}\";`,\n `const require = createRequire(filename);`,\n `const z = require(\"zod\");`,\n // zod 4 removed ZodString.ip/.cidr; restore them for analyzed user source\n // that still uses the v3 spellings.\n `const stringProto = Object.getPrototypeOf(z.string());\n const installedShims = [];\n function withReceiverChecks(receiver, format) {\n return (receiver._zod.def.checks ?? []).length\n ? z.intersection(receiver, format)\n : format;\n }\n if (!stringProto.ip) {\n installedShims.push('ip');\n stringProto.ip = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.ipv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.ipv6());\n return withReceiverChecks(this, z.union([z.ipv4(), z.ipv6()]));\n };\n }\n if (!stringProto.cidr) {\n installedShims.push('cidr');\n stringProto.cidr = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.cidrv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.cidrv6());\n return withReceiverChecks(this, z.union([z.cidrv4(), z.cidrv6()]));\n };\n }`,\n ...imports.map(\n (imp) =>\n `const ${imp.import} = require(${JSON.stringify(imp.from)})${\n imp.property ? `[${JSON.stringify(imp.property)}]` : ''\n };`,\n ),\n `let optional = false;`,\n `const WRAPPER_TYPES = new Set([\n 'optional',\n 'nullable',\n 'default',\n 'prefault',\n 'catch',\n 'readonly',\n 'nonoptional',\n ]);`,\n `function unwrapSchemaDef(def) {\n while (def) {\n if (WRAPPER_TYPES.has(def.type)) {\n def = def.innerType?._zod?.def;\n continue;\n }\n if (def.type === 'pipe') {\n def = def.in?._zod?.def;\n continue;\n }\n return def;\n }\n return def;\n }`,\n `function matchesDefType(schema, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (defType === 'number') {\n return schema.type === 'number' || schema.type === 'integer';\n }\n if (defType === 'bigint') {\n return schema.type === 'integer';\n }\n if (defType === 'string') {\n return schema.type === 'string';\n }\n if (defType === 'boolean') {\n return schema.type === 'boolean';\n }\n if (defType === 'date') {\n return schema.type === 'string' && schema.format === 'date-time';\n }\n return typeof schema.type === 'string';\n }`,\n `function applyZodType(schema, zodType, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (schema['x-zod-type']) return true;\n if (matchesDefType(schema, defType)) {\n schema['x-zod-type'] = zodType;\n return true;\n }\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n const candidates = schema[key].filter(\n (candidate) => candidate && candidate.type !== 'null',\n );\n if (candidates.length === 1 && applyZodType(candidates[0], zodType, defType)) {\n return true;\n }\n for (const candidate of candidates) {\n if (applyZodType(candidate, zodType, defType)) {\n return true;\n }\n }\n }\n return false;\n }`,\n `const BIGINT_SENTINEL = '__sdkit_bigint__';`,\n // zod v4 JSON-round-trips default values before the override callback\n // runs, which throws on bigint. Mask them as sentinel strings up front\n // and restore after conversion.\n `function maskBigIntDefaults(schema, seen = new Set()) {\n if (!schema || !schema._zod || seen.has(schema)) return;\n seen.add(schema);\n const def = schema._zod.def;\n if (\n (def.type === 'default' || def.type === 'prefault') &&\n typeof def.defaultValue === 'bigint'\n ) {\n Object.defineProperty(def, 'defaultValue', {\n value: BIGINT_SENTINEL + def.defaultValue.toString(),\n configurable: true,\n });\n }\n for (const key of ['innerType', 'in', 'out', 'element', 'valueType', 'keyType', 'left', 'right', 'catchall', 'rest']) {\n if (def[key]) maskBigIntDefaults(def[key], seen);\n }\n if (typeof def.getter === 'function') {\n const inner = def.getter();\n maskBigIntDefaults(inner, seen);\n Object.defineProperty(def, 'getter', {\n value: () => inner,\n configurable: true,\n });\n }\n if (def.shape) {\n for (const value of Object.values(def.shape)) maskBigIntDefaults(value, seen);\n }\n if (Array.isArray(def.options)) {\n for (const option of def.options) maskBigIntDefaults(option, seen);\n }\n if (Array.isArray(def.items)) {\n for (const item of def.items) maskBigIntDefaults(item, seen);\n }\n }`,\n // int64 is a plain number in sdk-it, so masked bigint defaults unmask to\n // JS numbers \u2014 the spec stays plain JSON with no bigint values to trip up\n // JSON.stringify.\n `function unmaskBigIntDefaults(schema) {\n if (!schema || typeof schema !== 'object') return;\n for (const [key, value] of Object.entries(schema)) {\n if (typeof value === 'string' && value.startsWith(BIGINT_SENTINEL)) {\n schema[key] = Number(value.slice(BIGINT_SENTINEL.length));\n } else if (Array.isArray(value)) {\n value.forEach(unmaskBigIntDefaults);\n } else if (value && typeof value === 'object') {\n unmaskBigIntDefaults(value);\n }\n }\n }`,\n `function hasExplicitRegexCheck(def) {\n return (def.checks ?? []).some(\n (check) => check._zod?.def?.format === 'regex',\n );\n }`,\n `const STANDARD_STRING_FORMATS = new Set([\n 'email',\n 'uri',\n 'url',\n 'uuid',\n 'guid',\n 'date-time',\n 'date',\n 'time',\n 'duration',\n 'ipv4',\n 'ipv6',\n 'hostname',\n 'binary',\n ]);`,\n // Nonstandard formats that sdk-it's own converters map to semantic zod\n // validators. Keep both keys: format for our converters, pattern for\n // third-party validators that do not recognize the format.\n `const MAPPED_NONSTANDARD_FORMATS = new Set(['cidrv4', 'cidrv6']);`,\n `function normalizeDefaultValue(value) {\n return value instanceof Date ? value.toISOString() : value;\n }`,\n `function mergeComparableValue(target, key, value) {\n if (value === undefined) return true;\n const normalized = normalizeDefaultValue(value);\n if (target[key] === undefined) {\n target[key] = normalized;\n return true;\n }\n return Object.is(target[key], normalized);\n }`,\n `function mergeLowerBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value > target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeUpperBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value < target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeEnumValues(target, values) {\n if (!Array.isArray(values)) return false;\n if (!Array.isArray(target.enum)) {\n target.enum = [...values];\n return true;\n }\n target.enum = target.enum.filter((candidate) =>\n values.some((value) => Object.is(candidate, value)),\n );\n return target.enum.length > 0;\n }`,\n `function isMergeablePrimitiveSchema(schema) {\n return (\n schema &&\n typeof schema === 'object' &&\n !schema.$ref &&\n !schema.anyOf &&\n !schema.oneOf &&\n !schema.allOf &&\n (schema.type === 'string' ||\n schema.type === 'boolean' ||\n schema.type === 'number' ||\n schema.type === 'integer')\n );\n }`,\n `function isNumericPair(left, right) {\n return (\n (left.type === 'number' && right.type === 'integer') ||\n (left.type === 'integer' && right.type === 'number')\n );\n }`,\n `function mergePrimitiveSchemas(schemas) {\n const merged = {};\n for (const schema of schemas) {\n if (\n schema &&\n typeof schema === 'object' &&\n Object.keys(schema).length === 0\n ) {\n continue;\n }\n if (!isMergeablePrimitiveSchema(schema)) {\n return null;\n }\n if (merged.type === undefined) {\n merged.type = schema.type;\n } else if (merged.type !== schema.type) {\n if (!isNumericPair(merged, schema)) {\n return null;\n }\n merged.type = 'integer';\n }\n\n for (const [key, value] of Object.entries(schema)) {\n if (key === 'type') {\n continue;\n }\n switch (key) {\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minLength':\n case 'minItems':\n case 'minProperties':\n if (!mergeLowerBound(merged, key, value)) {\n return null;\n }\n break;\n case 'maximum':\n case 'exclusiveMaximum':\n case 'maxLength':\n case 'maxItems':\n case 'maxProperties':\n if (!mergeUpperBound(merged, key, value)) {\n return null;\n }\n break;\n case 'enum':\n if (!mergeEnumValues(merged, value)) {\n return null;\n }\n break;\n default:\n if (!mergeComparableValue(merged, key, value)) {\n return null;\n }\n }\n }\n }\n return merged;\n }`,\n `function normalizeSchema(schema, isIntersectionMember = false) {\n if (!schema || typeof schema !== 'object') {\n return schema;\n }\n\n if (schema.default !== undefined) {\n schema.default = normalizeDefaultValue(schema.default);\n }\n\n if (Array.isArray(schema.items)) {\n schema.items = schema.items.map((item) => normalizeSchema(item));\n } else if (schema.items && typeof schema.items === 'object') {\n schema.items = normalizeSchema(schema.items);\n }\n\n if (schema.properties && typeof schema.properties === 'object') {\n for (const [key, value] of Object.entries(schema.properties)) {\n schema.properties[key] = normalizeSchema(value);\n }\n }\n\n if (\n schema.additionalProperties &&\n typeof schema.additionalProperties === 'object'\n ) {\n schema.additionalProperties = normalizeSchema(schema.additionalProperties);\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n schema[key] = schema[key].map((candidate) =>\n normalizeSchema(candidate, key === 'allOf'),\n );\n }\n\n if (Array.isArray(schema.oneOf) && !schema.anyOf) {\n schema.anyOf = schema.oneOf;\n delete schema.oneOf;\n }\n\n if (\n Array.isArray(schema.anyOf) &&\n schema.anyOf.every(\n (member) =>\n member &&\n typeof member === 'object' &&\n Object.keys(member).length === 1 &&\n typeof member.type === 'string',\n )\n ) {\n const { anyOf, ...rest } = schema;\n schema = { ...rest, type: anyOf.map((member) => member.type) };\n }\n\n if (\n schema.type === 'object' &&\n schema.properties &&\n schema.additionalProperties === undefined &&\n !isIntersectionMember\n ) {\n schema.additionalProperties = false;\n }\n\n if (\n schema.type === 'object' &&\n schema.propertyNames &&\n JSON.stringify(schema.propertyNames) === '{\"type\":\"string\"}'\n ) {\n delete schema.propertyNames;\n }\n\n if (\n typeof schema.$ref === 'string' &&\n !schema.$ref.startsWith('#/components/schemas')\n ) {\n schema.$ref =\n schema.$ref === '#'\n ? '#/components/schemas'\n : schema.$ref.replace(/^#\\\\//, '#/components/schemas/');\n }\n\n if (Array.isArray(schema.allOf)) {\n const merged = mergePrimitiveSchemas(schema.allOf);\n if (merged) {\n const { allOf, ...rest } = schema;\n return { ...rest, ...merged };\n }\n if (schema.allOf.length === 1 && Object.keys(schema).length === 1) {\n return schema.allOf[0];\n }\n }\n\n return schema;\n }`,\n `function escapePointerSegment(segment) {\n return String(segment).replaceAll('~', '~0').replaceAll('/', '~1');\n }`,\n `function componentPointer(path) {\n return ['#', 'components', 'schemas', ...path.map(escapePointerSegment)].join('/');\n }`,\n // Nested toJsonSchema passes (set/map values, pipe outputs) return\n // self-contained draft-7 documents whose '#' and '#/definitions/*' refs\n // are relative to the embedded document root, not the outer schema.\n // Resolve them to outer-root structural pointers before the outer\n // definitions/normalize passes rewrite them into dangling refs.\n `function resolveEmbeddedDocs(root) {\n function process(node, path, docRoot) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => process(item, [...path, index], docRoot));\n return;\n }\n if (node['x-sdkit-embedded-root']) {\n delete node['x-sdkit-embedded-root'];\n const defs = node.definitions ?? Object.create(null);\n delete node.definitions;\n docRoot = { path, defs, firstSite: Object.create(null) };\n }\n if (docRoot && typeof node.$ref === 'string') {\n if (node.$ref === '#') {\n node.$ref = componentPointer(docRoot.path);\n return;\n }\n const match = node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in docRoot.firstSite) {\n node.$ref = docRoot.firstSite[name];\n return;\n }\n docRoot.firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, docRoot.defs[name]);\n }\n }\n for (const [key, value] of Object.entries(node)) {\n process(value, [...path, key], docRoot);\n }\n }\n process(root, [], null);\n return root;\n }`,\n // zod v4 breaks non-root cycles with a draft-7 definitions block plus\n // #/definitions/* refs, which OpenAPI consumers cannot resolve. Inline\n // each definition at its first use site and point the remaining\n // (recursive) refs structurally at that site, mirroring the v3\n // $refStrategy: 'root' output.\n `function inlineDefinitions(root) {\n const defs = root.definitions;\n if (!defs || typeof defs !== 'object') return root;\n delete root.definitions;\n const firstSite = Object.create(null);\n function walk(node, path) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => walk(item, [...path, index]));\n return;\n }\n const match =\n typeof node.$ref === 'string' &&\n node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in firstSite) {\n node.$ref = firstSite[name];\n return;\n }\n firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, defs[name]);\n }\n for (const [key, value] of Object.entries(node)) {\n walk(value, [...path, key]);\n }\n }\n walk(root, []);\n return root;\n }`,\n // Wraps nested conversions: when the embedded document carries refs or a\n // definitions block, tag its root so resolveEmbeddedDocs can rebase them.\n `function convertEmbedded(schema) {\n const { $schema: _ignored, ...doc } = toJsonSchema(schema);\n if (doc.definitions || JSON.stringify(doc).includes('\"$ref\"')) {\n doc['x-sdkit-embedded-root'] = true;\n }\n return doc;\n }`,\n `function toJsonSchema(schema) {\n return z.toJSONSchema(schema, {\n target: 'draft-7',\n io: 'input',\n unrepresentable: 'any',\n override(ctx) {\n const def = ctx.zodSchema._zod.def;\n const json = ctx.jsonSchema;\n if (def.type === 'catch') {\n delete json.default;\n }\n if (def.type === 'date') {\n json.type = 'string';\n json.format = 'date-time';\n json['x-zod-type'] = def.coerce ? 'coerce-date' : 'date';\n }\n if (def.type === 'bigint') {\n json.type = 'integer';\n // z.bigint() carries no format; treat it as int64.\n json.format = ctx.zodSchema._zod.bag.format ?? 'int64';\n if (def.coerce) {\n json['x-zod-type'] = 'coerce-bigint';\n }\n }\n if (def.type === 'set') {\n json.type = 'array';\n json.uniqueItems = true;\n json.items = convertEmbedded(def.valueType);\n }\n if (def.type === 'map') {\n json.type = 'array';\n json.items = {\n type: 'array',\n items: [convertEmbedded(def.keyType), convertEmbedded(def.valueType)],\n minItems: 2,\n maxItems: 2,\n };\n }\n if (def.type === 'string' && json.format === 'base64') {\n json.format = 'binary';\n delete json.pattern;\n delete json.contentEncoding;\n }\n if (\n def.type === 'string' &&\n json.format &&\n json.pattern &&\n !hasExplicitRegexCheck(def)\n ) {\n if (STANDARD_STRING_FORMATS.has(json.format)) {\n delete json.pattern;\n } else if (!MAPPED_NONSTANDARD_FORMATS.has(json.format)) {\n delete json.format;\n }\n }\n if (def.type === 'number') {\n const explicitBound = (kind, value) =>\n (def.checks ?? []).some(\n (check) =>\n check._zod?.def?.check === kind &&\n Number(check._zod.def.value) === value,\n );\n if (\n json.maximum === Number.MAX_SAFE_INTEGER &&\n !explicitBound('less_than', Number.MAX_SAFE_INTEGER)\n ) {\n delete json.maximum;\n }\n if (\n json.minimum === Number.MIN_SAFE_INTEGER &&\n !explicitBound('greater_than', Number.MIN_SAFE_INTEGER)\n ) {\n delete json.minimum;\n }\n }\n if (def.type === 'pipe') {\n const outJson = convertEmbedded(def.out);\n const outKeys = Object.keys(outJson).filter(\n (key) => key !== 'x-sdkit-embedded-root',\n );\n if (outKeys.length > 0) {\n const inJson = { ...json };\n const compatible =\n inJson.type === undefined ||\n outJson.type === undefined ||\n inJson.type === outJson.type ||\n isNumericPair(inJson, outJson);\n if (compatible) {\n for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\n }\n }\n }\n if (def.type === 'tuple' && Array.isArray(json.items)) {\n if (json.minItems === undefined) {\n json.minItems = json.items.length;\n }\n if (\n json.additionalItems === undefined &&\n json.maxItems === undefined\n ) {\n json.maxItems = json.items.length;\n }\n }\n },\n });\n }`,\n `let zodSchema;\n let rawResult;\n try {\n zodSchema = ${removeUnsupportedMethods(schema)};\n maskBigIntDefaults(zodSchema);\n // zod's own input-side flag: 'optional' for optional/nullish/catch,\n // 'defaulted' for default/prefault, undefined once .nonoptional() applies.\n optional = ['optional', 'defaulted'].includes(zodSchema._zod.optin);\n const { $schema, ...converted } = toJsonSchema(zodSchema);\n rawResult = converted;\n } finally {\n // The v3 shims exist only while the analyzed source evaluates and\n // converts (lazy getters can call them mid-conversion); remove them so\n // the shared zod instance is not left with v3 API surface process-wide.\n for (const method of installedShims) delete stringProto[method];\n }\n unmaskBigIntDefaults(rawResult);\n const result = normalizeSchema(\n inlineDefinitions(resolveEmbeddedDocs(rawResult)),\n );`,\n `const innerDef = unwrapSchemaDef(zodSchema._zod.def);\n if (innerDef?.coerce && !result['x-zod-type']) {\n const zodType = 'coerce-' + innerDef.type;\n if (!applyZodType(result, zodType, innerDef.type)) {\n result['x-zod-type'] = zodType;\n }\n }`,\n `export default {schema: result, optional}`,\n ];\n\n const base64 = Buffer.from(lines.join('\\n')).toString('base64');\n return import(\n /* @vite-ignore */\n `data:text/javascript;base64,${base64}`\n ).then((mod) => mod.default);\n}\n"],
|
|
5
|
-
"mappings": "AAMA,SAAS,yBAAyB,QAAgB;AAChD,SAAO,OACJ,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,mBAAmB,oBAAoB,EAClD,WAAW,mBAAmB,oBAAoB;AACvD;AAEA,eAAsB,QAAQ,QAAgB,UAA0B,CAAC,GAAG;AAE1E,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,qBAAqB,YAAY,GAAG;AAAA,IACpC;AAAA,IACA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["export type InjectImport = {\n import: string;\n from: string;\n property?: string;\n};\n\nfunction removeUnsupportedMethods(schema: string) {\n return schema\n .replaceAll('.instanceof(File)', '.string().base64()')\n .replaceAll('.instanceof(Blob)', '.string().base64()')\n .replaceAll('.custom<File>()', '.string().base64()')\n .replaceAll('.custom<Blob>()', '.string().base64()');\n}\n\nexport async function evalZod(schema: string, imports: InjectImport[] = []) {\n // https://github.com/nodejs/node/issues/51956\n const lines = [\n `import { createRequire } from \"node:module\";`,\n `const filename = \"${import.meta.url}\";`,\n `const require = createRequire(filename);`,\n `const z = require(\"zod\");`,\n `if (typeof z.toJSONSchema !== 'function') {\n throw new Error('@sdk-it/core requires Zod 4. Install zod@^4.3.0 and migrate Zod 3 schemas before analysis.');\n }`,\n // zod 4 removed ZodString.ip/.cidr; restore them for analyzed user source\n // that still uses the v3 spellings.\n `const stringProto = Object.getPrototypeOf(z.string());\n const installedShims = [];\n function withReceiverChecks(receiver, format) {\n return (receiver._zod.def.checks ?? []).length\n ? z.intersection(receiver, format)\n : format;\n }\n if (!stringProto.ip) {\n installedShims.push('ip');\n stringProto.ip = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.ipv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.ipv6());\n return withReceiverChecks(this, z.union([z.ipv4(), z.ipv6()]));\n };\n }\n if (!stringProto.cidr) {\n installedShims.push('cidr');\n stringProto.cidr = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.cidrv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.cidrv6());\n return withReceiverChecks(this, z.union([z.cidrv4(), z.cidrv6()]));\n };\n }`,\n ...imports.map(\n (imp) =>\n `const ${imp.import} = require(${JSON.stringify(imp.from)})${\n imp.property ? `[${JSON.stringify(imp.property)}]` : ''\n };`,\n ),\n `let optional = false;`,\n `const WRAPPER_TYPES = new Set([\n 'optional',\n 'nullable',\n 'default',\n 'prefault',\n 'catch',\n 'readonly',\n 'nonoptional',\n ]);`,\n `function unwrapSchemaDef(def) {\n while (def) {\n if (WRAPPER_TYPES.has(def.type)) {\n def = def.innerType?._zod?.def;\n continue;\n }\n if (def.type === 'pipe') {\n def = def.in?._zod?.def;\n continue;\n }\n return def;\n }\n return def;\n }`,\n `function matchesDefType(schema, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (defType === 'number') {\n return schema.type === 'number' || schema.type === 'integer';\n }\n if (defType === 'bigint') {\n return schema.type === 'integer';\n }\n if (defType === 'string') {\n return schema.type === 'string';\n }\n if (defType === 'boolean') {\n return schema.type === 'boolean';\n }\n if (defType === 'date') {\n return schema.type === 'string' && schema.format === 'date-time';\n }\n return typeof schema.type === 'string';\n }`,\n `function applyZodType(schema, zodType, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (schema['x-zod-type']) return true;\n if (matchesDefType(schema, defType)) {\n schema['x-zod-type'] = zodType;\n return true;\n }\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n const candidates = schema[key].filter(\n (candidate) => candidate && candidate.type !== 'null',\n );\n if (candidates.length === 1 && applyZodType(candidates[0], zodType, defType)) {\n return true;\n }\n for (const candidate of candidates) {\n if (applyZodType(candidate, zodType, defType)) {\n return true;\n }\n }\n }\n return false;\n }`,\n `const BIGINT_SENTINEL = '__sdkit_bigint__';`,\n // zod v4 JSON-round-trips default values before the override callback\n // runs, which throws on bigint. Mask them as sentinel strings up front\n // and restore after conversion.\n `function maskBigIntDefaults(schema, seen = new Set()) {\n if (!schema?._zod || schema._zod.version?.major !== 4) {\n throw new Error('@sdk-it/core requires Zod 4 schemas; migrate imported Zod 3 schemas before analysis.');\n }\n if (seen.has(schema)) return;\n seen.add(schema);\n const def = schema._zod.def;\n if (\n (def.type === 'default' || def.type === 'prefault') &&\n typeof def.defaultValue === 'bigint'\n ) {\n Object.defineProperty(def, 'defaultValue', {\n value: BIGINT_SENTINEL + def.defaultValue.toString(),\n configurable: true,\n });\n }\n for (const key of ['innerType', 'in', 'out', 'element', 'valueType', 'keyType', 'left', 'right', 'catchall', 'rest']) {\n if (def[key]) maskBigIntDefaults(def[key], seen);\n }\n if (typeof def.getter === 'function') {\n const inner = def.getter();\n maskBigIntDefaults(inner, seen);\n Object.defineProperty(def, 'getter', {\n value: () => inner,\n configurable: true,\n });\n }\n if (def.shape) {\n for (const value of Object.values(def.shape)) maskBigIntDefaults(value, seen);\n }\n if (Array.isArray(def.options)) {\n for (const option of def.options) maskBigIntDefaults(option, seen);\n }\n if (Array.isArray(def.items)) {\n for (const item of def.items) maskBigIntDefaults(item, seen);\n }\n }`,\n // int64 is a plain number in sdk-it, so masked bigint defaults unmask to\n // JS numbers \u2014 the spec stays plain JSON with no bigint values to trip up\n // JSON.stringify.\n `function unmaskBigIntDefaults(schema) {\n if (!schema || typeof schema !== 'object') return;\n for (const [key, value] of Object.entries(schema)) {\n if (typeof value === 'string' && value.startsWith(BIGINT_SENTINEL)) {\n schema[key] = Number(value.slice(BIGINT_SENTINEL.length));\n } else if (Array.isArray(value)) {\n value.forEach(unmaskBigIntDefaults);\n } else if (value && typeof value === 'object') {\n unmaskBigIntDefaults(value);\n }\n }\n }`,\n `function hasExplicitRegexCheck(def) {\n return (def.checks ?? []).some(\n (check) => check._zod?.def?.format === 'regex',\n );\n }`,\n `const STANDARD_STRING_FORMATS = new Set([\n 'email',\n 'uri',\n 'url',\n 'uuid',\n 'guid',\n 'date-time',\n 'date',\n 'time',\n 'duration',\n 'ipv4',\n 'ipv6',\n 'hostname',\n 'binary',\n ]);`,\n // Nonstandard formats that sdk-it's own converters map to semantic zod\n // validators. Keep both keys: format for our converters, pattern for\n // third-party validators that do not recognize the format.\n `const MAPPED_NONSTANDARD_FORMATS = new Set(['cidrv4', 'cidrv6']);`,\n `function normalizeDefaultValue(value) {\n return value instanceof Date ? value.toISOString() : value;\n }`,\n `function mergeComparableValue(target, key, value) {\n if (value === undefined) return true;\n const normalized = normalizeDefaultValue(value);\n if (target[key] === undefined) {\n target[key] = normalized;\n return true;\n }\n return Object.is(target[key], normalized);\n }`,\n `function mergeLowerBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value > target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeUpperBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value < target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeEnumValues(target, values) {\n if (!Array.isArray(values)) return false;\n if (!Array.isArray(target.enum)) {\n target.enum = [...values];\n return true;\n }\n target.enum = target.enum.filter((candidate) =>\n values.some((value) => Object.is(candidate, value)),\n );\n return target.enum.length > 0;\n }`,\n `function isMergeablePrimitiveSchema(schema) {\n return (\n schema &&\n typeof schema === 'object' &&\n !schema.$ref &&\n !schema.anyOf &&\n !schema.oneOf &&\n !schema.allOf &&\n (schema.type === 'string' ||\n schema.type === 'boolean' ||\n schema.type === 'number' ||\n schema.type === 'integer')\n );\n }`,\n `function isNumericPair(left, right) {\n return (\n (left.type === 'number' && right.type === 'integer') ||\n (left.type === 'integer' && right.type === 'number')\n );\n }`,\n `function mergePrimitiveSchemas(schemas) {\n const merged = {};\n for (const schema of schemas) {\n if (\n schema &&\n typeof schema === 'object' &&\n Object.keys(schema).length === 0\n ) {\n continue;\n }\n if (!isMergeablePrimitiveSchema(schema)) {\n return null;\n }\n if (merged.type === undefined) {\n merged.type = schema.type;\n } else if (merged.type !== schema.type) {\n if (!isNumericPair(merged, schema)) {\n return null;\n }\n merged.type = 'integer';\n }\n\n for (const [key, value] of Object.entries(schema)) {\n if (key === 'type') {\n continue;\n }\n switch (key) {\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minLength':\n case 'minItems':\n case 'minProperties':\n if (!mergeLowerBound(merged, key, value)) {\n return null;\n }\n break;\n case 'maximum':\n case 'exclusiveMaximum':\n case 'maxLength':\n case 'maxItems':\n case 'maxProperties':\n if (!mergeUpperBound(merged, key, value)) {\n return null;\n }\n break;\n case 'enum':\n if (!mergeEnumValues(merged, value)) {\n return null;\n }\n break;\n default:\n if (!mergeComparableValue(merged, key, value)) {\n return null;\n }\n }\n }\n }\n return merged;\n }`,\n `function normalizeSchema(schema, isIntersectionMember = false) {\n if (!schema || typeof schema !== 'object') {\n return schema;\n }\n\n if (schema.default !== undefined) {\n schema.default = normalizeDefaultValue(schema.default);\n }\n\n if (Array.isArray(schema.items)) {\n schema.items = schema.items.map((item) => normalizeSchema(item));\n } else if (schema.items && typeof schema.items === 'object') {\n schema.items = normalizeSchema(schema.items);\n }\n\n if (schema.properties && typeof schema.properties === 'object') {\n for (const [key, value] of Object.entries(schema.properties)) {\n schema.properties[key] = normalizeSchema(value);\n }\n }\n\n if (\n schema.additionalProperties &&\n typeof schema.additionalProperties === 'object'\n ) {\n schema.additionalProperties = normalizeSchema(schema.additionalProperties);\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n schema[key] = schema[key].map((candidate) =>\n normalizeSchema(candidate, key === 'allOf'),\n );\n }\n\n if (Array.isArray(schema.oneOf) && !schema.anyOf) {\n schema.anyOf = schema.oneOf;\n delete schema.oneOf;\n }\n\n if (\n Array.isArray(schema.anyOf) &&\n schema.anyOf.every(\n (member) =>\n member &&\n typeof member === 'object' &&\n Object.keys(member).length === 1 &&\n typeof member.type === 'string',\n )\n ) {\n const { anyOf, ...rest } = schema;\n schema = { ...rest, type: anyOf.map((member) => member.type) };\n }\n\n if (\n schema.type === 'object' &&\n schema.properties &&\n schema.additionalProperties === undefined &&\n !isIntersectionMember\n ) {\n schema.additionalProperties = false;\n }\n\n if (\n schema.type === 'object' &&\n schema.propertyNames &&\n JSON.stringify(schema.propertyNames) === '{\"type\":\"string\"}'\n ) {\n delete schema.propertyNames;\n }\n\n if (\n typeof schema.$ref === 'string' &&\n !schema.$ref.startsWith('#/components/schemas')\n ) {\n schema.$ref =\n schema.$ref === '#'\n ? '#/components/schemas'\n : schema.$ref.replace(/^#\\\\//, '#/components/schemas/');\n }\n\n if (Array.isArray(schema.allOf)) {\n const merged = mergePrimitiveSchemas(schema.allOf);\n if (merged) {\n const { allOf, ...rest } = schema;\n return { ...rest, ...merged };\n }\n if (schema.allOf.length === 1 && Object.keys(schema).length === 1) {\n return schema.allOf[0];\n }\n }\n\n return schema;\n }`,\n `function escapePointerSegment(segment) {\n return String(segment).replaceAll('~', '~0').replaceAll('/', '~1');\n }`,\n `function componentPointer(path) {\n return ['#', 'components', 'schemas', ...path.map(escapePointerSegment)].join('/');\n }`,\n // Nested toJsonSchema passes (set/map values, pipe outputs) return\n // self-contained draft-7 documents whose '#' and '#/definitions/*' refs\n // are relative to the embedded document root, not the outer schema.\n // Resolve them to outer-root structural pointers before the outer\n // definitions/normalize passes rewrite them into dangling refs.\n `function resolveEmbeddedDocs(root) {\n function process(node, path, docRoot) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => process(item, [...path, index], docRoot));\n return;\n }\n if (node['x-sdkit-embedded-root']) {\n delete node['x-sdkit-embedded-root'];\n const defs = node.definitions ?? Object.create(null);\n delete node.definitions;\n docRoot = { path, defs, firstSite: Object.create(null) };\n }\n if (docRoot && typeof node.$ref === 'string') {\n if (node.$ref === '#') {\n node.$ref = componentPointer(docRoot.path);\n return;\n }\n const match = node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in docRoot.firstSite) {\n node.$ref = docRoot.firstSite[name];\n return;\n }\n docRoot.firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, docRoot.defs[name]);\n }\n }\n for (const [key, value] of Object.entries(node)) {\n process(value, [...path, key], docRoot);\n }\n }\n process(root, [], null);\n return root;\n }`,\n // zod v4 breaks non-root cycles with a draft-7 definitions block plus\n // #/definitions/* refs, which OpenAPI consumers cannot resolve. Inline\n // each definition at its first use site and point the remaining\n // (recursive) refs structurally at that site, mirroring the v3\n // $refStrategy: 'root' output.\n `function inlineDefinitions(root) {\n const defs = root.definitions;\n if (!defs || typeof defs !== 'object') return root;\n delete root.definitions;\n const firstSite = Object.create(null);\n function walk(node, path) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => walk(item, [...path, index]));\n return;\n }\n const match =\n typeof node.$ref === 'string' &&\n node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in firstSite) {\n node.$ref = firstSite[name];\n return;\n }\n firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, defs[name]);\n }\n for (const [key, value] of Object.entries(node)) {\n walk(value, [...path, key]);\n }\n }\n walk(root, []);\n return root;\n }`,\n // Wraps nested conversions: when the embedded document carries refs or a\n // definitions block, tag its root so resolveEmbeddedDocs can rebase them.\n `function convertEmbedded(schema) {\n const { $schema: _ignored, ...doc } = toJsonSchema(schema);\n if (doc.definitions || JSON.stringify(doc).includes('\"$ref\"')) {\n doc['x-sdkit-embedded-root'] = true;\n }\n return doc;\n }`,\n `function toJsonSchema(schema) {\n return z.toJSONSchema(schema, {\n target: 'draft-7',\n io: 'input',\n unrepresentable: 'any',\n override(ctx) {\n const def = ctx.zodSchema._zod.def;\n const json = ctx.jsonSchema;\n if (def.type === 'catch') {\n delete json.default;\n }\n if (def.type === 'date') {\n json.type = 'string';\n json.format = 'date-time';\n json['x-zod-type'] = def.coerce ? 'coerce-date' : 'date';\n }\n if (def.type === 'bigint') {\n json.type = 'integer';\n // z.bigint() carries no format; treat it as int64.\n json.format = ctx.zodSchema._zod.bag.format ?? 'int64';\n if (def.coerce) {\n json['x-zod-type'] = 'coerce-bigint';\n }\n }\n if (def.type === 'set') {\n json.type = 'array';\n json.uniqueItems = true;\n json.items = convertEmbedded(def.valueType);\n }\n if (def.type === 'map') {\n json.type = 'array';\n json.items = {\n type: 'array',\n items: [convertEmbedded(def.keyType), convertEmbedded(def.valueType)],\n minItems: 2,\n maxItems: 2,\n };\n }\n if (def.type === 'string' && json.format === 'base64') {\n json.format = 'binary';\n delete json.pattern;\n delete json.contentEncoding;\n }\n if (\n def.type === 'string' &&\n json.format &&\n json.pattern &&\n !hasExplicitRegexCheck(def)\n ) {\n if (STANDARD_STRING_FORMATS.has(json.format)) {\n delete json.pattern;\n } else if (!MAPPED_NONSTANDARD_FORMATS.has(json.format)) {\n delete json.format;\n }\n }\n if (def.type === 'number') {\n const explicitBound = (kind, value) =>\n (def.checks ?? []).some(\n (check) =>\n check._zod?.def?.check === kind &&\n Number(check._zod.def.value) === value,\n );\n if (\n json.maximum === Number.MAX_SAFE_INTEGER &&\n !explicitBound('less_than', Number.MAX_SAFE_INTEGER)\n ) {\n delete json.maximum;\n }\n if (\n json.minimum === Number.MIN_SAFE_INTEGER &&\n !explicitBound('greater_than', Number.MIN_SAFE_INTEGER)\n ) {\n delete json.minimum;\n }\n }\n if (def.type === 'pipe') {\n const outJson = convertEmbedded(def.out);\n const outKeys = Object.keys(outJson).filter(\n (key) => key !== 'x-sdkit-embedded-root',\n );\n if (outKeys.length > 0) {\n const inJson = { ...json };\n const compatible =\n inJson.type === undefined ||\n outJson.type === undefined ||\n inJson.type === outJson.type ||\n isNumericPair(inJson, outJson);\n if (compatible) {\n for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\n }\n }\n }\n if (def.type === 'tuple' && Array.isArray(json.items)) {\n if (json.minItems === undefined) {\n json.minItems = json.items.length;\n }\n if (\n json.additionalItems === undefined &&\n json.maxItems === undefined\n ) {\n json.maxItems = json.items.length;\n }\n }\n },\n });\n }`,\n `let zodSchema;\n let rawResult;\n try {\n zodSchema = ${removeUnsupportedMethods(schema)};\n maskBigIntDefaults(zodSchema);\n // zod's own input-side flag: 'optional' for optional/nullish/catch,\n // 'defaulted' for default/prefault, undefined once .nonoptional() applies.\n optional = ['optional', 'defaulted'].includes(zodSchema._zod.optin);\n const { $schema, ...converted } = toJsonSchema(zodSchema);\n rawResult = converted;\n } finally {\n // The v3 shims exist only while the analyzed source evaluates and\n // converts (lazy getters can call them mid-conversion); remove them so\n // the shared zod instance is not left with v3 API surface process-wide.\n for (const method of installedShims) delete stringProto[method];\n }\n unmaskBigIntDefaults(rawResult);\n const result = normalizeSchema(\n inlineDefinitions(resolveEmbeddedDocs(rawResult)),\n );`,\n `const innerDef = unwrapSchemaDef(zodSchema._zod.def);\n if (innerDef?.coerce && !result['x-zod-type']) {\n const zodType = 'coerce-' + innerDef.type;\n if (!applyZodType(result, zodType, innerDef.type)) {\n result['x-zod-type'] = zodType;\n }\n }`,\n `export default {schema: result, optional}`,\n ];\n\n const base64 = Buffer.from(lines.join('\\n')).toString('base64');\n return import(\n /* @vite-ignore */\n `data:text/javascript;base64,${base64}`\n ).then((mod) => mod.default);\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,yBAAyB,QAAgB;AAChD,SAAO,OACJ,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,mBAAmB,oBAAoB,EAClD,WAAW,mBAAmB,oBAAoB;AACvD;AAEA,eAAsB,QAAQ,QAAgB,UAA0B,CAAC,GAAG;AAE1E,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,qBAAqB,YAAY,GAAG;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAuBA,GAAG,QAAQ;AAAA,MACT,CAAC,QACC,SAAS,IAAI,MAAM,cAAc,KAAK,UAAU,IAAI,IAAI,CAAC,IACvD,IAAI,WAAW,IAAI,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,EACvD;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAc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;AAAA,IACrC,KAAK,CAAC,QAAQ,IAAI,OAAO;AAC7B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/core",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"lodash-es": "^4.17.21"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
+
"zod": "^4.3.0",
|
|
35
36
|
"typescript": "^6.0.3",
|
|
36
37
|
"openapi3-ts": "^4.4.0"
|
|
37
38
|
},
|