@sdk-it/core 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -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/paths.d.ts.map +1 -1
- package/dist/lib/paths.js.map +2 -2
- package/dist/lib/ref.d.ts +3 -3
- package/dist/lib/ref.d.ts.map +1 -1
- package/dist/lib/ref.js.map +2 -2
- package/dist/lib/zod-jsonschema.d.ts +1 -0
- package/dist/lib/zod-jsonschema.d.ts.map +1 -1
- package/dist/lib/zod-jsonschema.js +3 -1
- package/dist/lib/zod-jsonschema.js.map +2 -2
- package/package.json +3 -4
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/deriver.js';\nexport * from './lib/paths.js';\nexport * from './lib/program.js';\nexport * from './lib/ref.js';\nexport * from './lib/utils.js';\nexport * from './lib/zod-jsonschema.js';\n
|
|
4
|
+
"sourcesContent": ["export * from './lib/deriver.js';\nexport * from './lib/paths.js';\nexport * from './lib/program.js';\nexport * from './lib/ref.js';\nexport * from './lib/utils.js';\nexport * from './lib/zod-jsonschema.js';\n"],
|
|
5
5
|
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriver.d.ts","sourceRoot":"","sources":["../../src/lib/deriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,YAAY,CAAC;AAKvD,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAErC,eAAO,MAAM,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AW9D;AAED,qBAAa,WAAW;IACtB,SAAgB,SAAS,EAAE,SAAS,CAAM;IAC1C,SAAgB,OAAO,EAAE,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;gBAE5B,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;IAkSjC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;CAoRlC"}
|
package/dist/lib/deriver.js
CHANGED
|
@@ -455,6 +455,10 @@ class TypeDeriver {
|
|
|
455
455
|
const type = this.checker.getTypeAtLocation(node);
|
|
456
456
|
return this.serializeType(type);
|
|
457
457
|
}
|
|
458
|
+
if (ts.isSatisfiesExpression(node)) {
|
|
459
|
+
const type = this.checker.getTypeFromTypeNode(node.type);
|
|
460
|
+
return this.serializeType(type);
|
|
461
|
+
}
|
|
458
462
|
if (ts.isTypeLiteralNode(node)) {
|
|
459
463
|
const symbolType = this.checker.getTypeAtLocation(node);
|
|
460
464
|
const props = {};
|
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 { isInterfaceType } from './program.js';\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\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 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 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 const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serializeType(indexType)],\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.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: type.value,\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: type.value,\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\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.serializeType(intersectionType));\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.serializeType(unionType));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const [argType] = this.checker.getTypeArguments(type as ts.TypeReference);\n if (!argType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(\n `Could not find generic type argument for array type ${typeName}`,\n );\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const typeSymbol = argType.getSymbol();\n if (!typeSymbol) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: [this.serializeType(argType)],\n };\n }\n\n if (typeSymbol.valueDeclaration) {\n return {\n kind: 'array',\n [deriveSymbol]: true,\n [$types]: [this.serializeNode(typeSymbol.valueDeclaration)],\n };\n }\n const maybeDeclaration = typeSymbol.declarations?.[0];\n if (maybeDeclaration) {\n if (ts.isMappedTypeNode(maybeDeclaration)) {\n const resolvedType = sortObjectKeys(\n this.checker\n .getPropertiesOfType(argType)\n .reduce<Record<string, unknown>>((acc, prop) => {\n const propType = this.checker.getTypeOfSymbol(prop);\n acc[prop.name] = this.serializeType(propType);\n return acc;\n }, {}),\n );\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: [resolvedType],\n };\n } else {\n return {\n kind: 'array',\n ...this.serializeNode(maybeDeclaration),\n };\n }\n }\n\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: ['any'],\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 (isInterfaceType(type)) {\n const valueDeclaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!valueDeclaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(valueDeclaration);\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 propAssingment = (prop.getDeclarations() ?? []).find((it) =>\n ts.isPropertyAssignment(it),\n );\n // get literal properties values if any\n if (propAssingment) {\n const type = this.checker.getTypeAtLocation(\n propAssingment.initializer,\n );\n serializedProps[prop.name] = this.serializeType(type);\n } else if (\n (prop.getDeclarations() ?? []).find((it) =>\n ts.isPropertySignature(it),\n )\n ) {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\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 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 for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n\n // get literal properties values if any\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const type = this.checker.getTypeAtLocation(prop.initializer);\n props[prop.name.getText()] = 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.checker.getTypeAtLocation(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.isCallExpression(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.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.checker.getTypeAtLocation(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 const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\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,uBAAuB;AAChC,SAAS,sBAAsB;AAIxB,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,EACR,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,UAAM,WAAW,eAAe,aAAa,YAAY,IAAI;AAC7D,QAAI,UAAU;AACZ,YAAM,KAAK,gBAAgB,Q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B,IAAI;AAChD,aAAO,KAAK,cAAc,IAAI;AAAA,IAChC;AAGA,QAAI,GAAG,wBAAwB,IAAI,GAAG;AACpC,YAAM,OAAO,KAAK,QAAQ,kBAAkB,IAAI;AAChD,aAAO,KAAK,cAAc,IAAI;AAAA,IAChC;AAGA,QAAI,GAAG,0BAA0B,IAAI,GAAG;AACtC,YAAM,OAAO,KAAK,QAAQ,kBAAkB,IAAI;AAChD,aAAO,KAAK,cAAc,IAAI;AAAA,IAChC;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;",
|
|
4
|
+
"sourcesContent": ["import ts, { TypeFlags, symbolName } from 'typescript';\n\nimport { isInterfaceType } from './program.js';\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\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 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 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 const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serializeType(indexType)],\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.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: type.value,\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: type.value,\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\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.serializeType(intersectionType));\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.serializeType(unionType));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const [argType] = this.checker.getTypeArguments(type as ts.TypeReference);\n if (!argType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(\n `Could not find generic type argument for array type ${typeName}`,\n );\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const typeSymbol = argType.getSymbol();\n if (!typeSymbol) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: [this.serializeType(argType)],\n };\n }\n\n if (typeSymbol.valueDeclaration) {\n return {\n kind: 'array',\n [deriveSymbol]: true,\n [$types]: [this.serializeNode(typeSymbol.valueDeclaration)],\n };\n }\n const maybeDeclaration = typeSymbol.declarations?.[0];\n if (maybeDeclaration) {\n if (ts.isMappedTypeNode(maybeDeclaration)) {\n const resolvedType = sortObjectKeys(\n this.checker\n .getPropertiesOfType(argType)\n .reduce<Record<string, unknown>>((acc, prop) => {\n const propType = this.checker.getTypeOfSymbol(prop);\n acc[prop.name] = this.serializeType(propType);\n return acc;\n }, {}),\n );\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: [resolvedType],\n };\n } else {\n return {\n kind: 'array',\n ...this.serializeNode(maybeDeclaration),\n };\n }\n }\n\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: ['any'],\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 (isInterfaceType(type)) {\n const valueDeclaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!valueDeclaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(valueDeclaration);\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 propAssingment = (prop.getDeclarations() ?? []).find((it) =>\n ts.isPropertyAssignment(it),\n );\n // get literal properties values if any\n if (propAssingment) {\n const type = this.checker.getTypeAtLocation(\n propAssingment.initializer,\n );\n serializedProps[prop.name] = this.serializeType(type);\n } else if (\n (prop.getDeclarations() ?? []).find((it) =>\n ts.isPropertySignature(it),\n )\n ) {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\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 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 for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n\n // get literal properties values if any\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const type = this.checker.getTypeAtLocation(prop.initializer);\n props[prop.name.getText()] = 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.checker.getTypeAtLocation(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.isCallExpression(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 // Unlike `as`, `satisfies` checks the operand without widening it, so the\n // node's own type is the narrow inferred one -- `[] satisfies Share[]` is\n // `never[]`, which carries no schema. The annotation is the declared\n // contract callers code against, so derive from that instead.\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\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.checker.getTypeAtLocation(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 const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\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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CAAC,CAAC,EAAE,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,WAAW,GAAG,CACxB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,eAAe,KACvB,WAAW,CAAC;AACjB,qBAAa,KAAK;;gBAeJ,MAAM,EAAE;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE;IAK1E,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,YAAY,EAAE,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa;IAyHrB,OAAO,IAAI,MAAM,EAAE;IAcnB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAI1C,QAAQ;CA0Ef;AAED,UAAU,QAAQ;IAChB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CA0DxE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,MAAM,CAEzD"}
|
package/dist/lib/paths.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/paths.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HeadersObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './deriver.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n};\nexport type Method =\n | 'get'\n | 'post'\n | 'put'\n | 'patch'\n | 'delete'\n | 'trace'\n | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nexport type SemanticSource =\n | 'query'\n | 'queries'\n | 'body'\n | 'params'\n | 'headers';\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\nexport interface Selector {\n name: string;\n against: string;\n source: SemanticSource;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: ResponsesObject = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema = item.response ? toSchema(item.response) : {};\n\n // Deduplicate named middleware responses via $ref\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n if (!this.#sharedResponses.has(sharedKey)) {\n this.#sharedResponses.set(sharedKey, schema);\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n if (!responsesObject[item.statusCode]) {\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty'\n ? {\n [ct]:\n ct === 'application/octet-stream'\n ? { schema: { type: 'string', format: 'binary' } }\n : { schema },\n }\n : undefined,\n headers: item.headers.length\n ? item.headers.reduce<HeadersObject>((acc, current) => {\n const headers =\n typeof current === 'string' ? { [current]: [] } : current;\n const sortedHeaders = Object.entries(sortObjectKeys(headers));\n return sortedHeaders.reduce<HeadersObject>(\n (subAcc, [key, value]) => {\n const header: HeadersObject = {\n [key]: {\n schema: {\n type: 'string',\n enum: value.length ? value : undefined,\n },\n },\n };\n return { ...subAcc, ...header };\n },\n acc,\n );\n }, {})\n : undefined,\n } satisfies ResponseObject;\n } else {\n if (!responsesObject[item.statusCode].content[ct]) {\n responsesObject[item.statusCode].content[ct] = { schema };\n } else {\n const existing = responsesObject[item.statusCode].content[ct]\n .schema as SchemaObject;\n if (existing.oneOf) {\n if (\n !existing.oneOf.find(\n (it) => JSON.stringify(it) === JSON.stringify(schema),\n )\n ) {\n existing.oneOf.push(schema);\n }\n } else if (JSON.stringify(existing) !== JSON.stringify(schema)) {\n responsesObject[item.statusCode].content[ct].schema = {\n oneOf: [existing, schema],\n };\n }\n }\n }\n }\n return responsesObject;\n }\n\n async #selectosToParameters(selectors: Selector[]) {\n const parameters: ParameterObject[] = [];\n const bodySchemaProps: Record<\n string,\n { required: boolean; schema: SchemaObject }\n > = {};\n for (const selector of selectors) {\n const { optional, schema } = await evalZod(\n selector.against,\n this.#imports,\n );\n if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n getSharedSchemas(): Record<string, SchemaObject> {\n return Object.fromEntries(this.#sharedResponses);\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, bodySchemaProps } =\n await this.#selectosToParameters(selectors);\n const bodySchema: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const sortedBodySchemaProps = Object.entries(\n sortObjectKeys(bodySchemaProps),\n );\n for (const [key, value] of sortedBodySchemaProps) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: Object.keys(bodySchema).length\n ? {\n required: required.length ? true : false,\n content: {\n [operation.contentType || 'application/json']: {\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: bodySchema,\n },\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\nexport function toSchema(data: DateType | string | null | undefined): any {\n if (data === null || data === undefined) {\n return { type: 'any' };\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n return { anyOf: data[$types].map(toSchema) };\n } else if (data.kind === 'intersection') {\n // TS gives anonymous/empty object types the synthetic symbol name \"__type\".\n // Members like `& {}` (the autocomplete-trick wrapper) contribute no schema\n // info \u2014 drop them so `(string & {})` emits as plain `{type:'string'}`.\n const ANON_OBJECT = '__type';\n const meaningful = (data[$types] as unknown[]).filter((m) => {\n if (!m || typeof m !== 'object') return true;\n const node = m as { kind?: unknown; [$types]?: readonly unknown[] };\n return !(\n !node.kind &&\n node[$types]?.length === 1 &&\n node[$types][0] === ANON_OBJECT\n );\n });\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1)\n return toSchema(meaningful[0] as DateType | string);\n return { allOf: meaningful.map((m) => toSchema(m as DateType | string)) };\n } else if ($types in data) {\n return data[$types].map(toSchema)[0] ?? {};\n } else {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value as any);\n if (!(value as any).optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
-
"mappings": "AAUA,SAAS,cAAc;AACvB,SAAS,WAAW,sBAAsB;AAC1C,SAA4B,eAAe;
|
|
4
|
+
"sourcesContent": ["import type {\n HeadersObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './deriver.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n};\nexport type Method =\n 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nexport type SemanticSource =\n 'query' | 'queries' | 'body' | 'params' | 'headers';\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\nexport interface Selector {\n name: string;\n against: string;\n source: SemanticSource;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: ResponsesObject = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema = item.response ? toSchema(item.response) : {};\n\n // Deduplicate named middleware responses via $ref\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n if (!this.#sharedResponses.has(sharedKey)) {\n this.#sharedResponses.set(sharedKey, schema);\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n if (!responsesObject[item.statusCode]) {\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty'\n ? {\n [ct]:\n ct === 'application/octet-stream'\n ? { schema: { type: 'string', format: 'binary' } }\n : { schema },\n }\n : undefined,\n headers: item.headers.length\n ? item.headers.reduce<HeadersObject>((acc, current) => {\n const headers =\n typeof current === 'string' ? { [current]: [] } : current;\n const sortedHeaders = Object.entries(sortObjectKeys(headers));\n return sortedHeaders.reduce<HeadersObject>(\n (subAcc, [key, value]) => {\n const header: HeadersObject = {\n [key]: {\n schema: {\n type: 'string',\n enum: value.length ? value : undefined,\n },\n },\n };\n return { ...subAcc, ...header };\n },\n acc,\n );\n }, {})\n : undefined,\n } satisfies ResponseObject;\n } else {\n if (!responsesObject[item.statusCode].content[ct]) {\n responsesObject[item.statusCode].content[ct] = { schema };\n } else {\n const existing = responsesObject[item.statusCode].content[ct]\n .schema as SchemaObject;\n if (existing.oneOf) {\n if (\n !existing.oneOf.find(\n (it) => JSON.stringify(it) === JSON.stringify(schema),\n )\n ) {\n existing.oneOf.push(schema);\n }\n } else if (JSON.stringify(existing) !== JSON.stringify(schema)) {\n responsesObject[item.statusCode].content[ct].schema = {\n oneOf: [existing, schema],\n };\n }\n }\n }\n }\n return responsesObject;\n }\n\n async #selectosToParameters(selectors: Selector[]) {\n const parameters: ParameterObject[] = [];\n const bodySchemaProps: Record<\n string,\n { required: boolean; schema: SchemaObject }\n > = {};\n for (const selector of selectors) {\n const { optional, schema } = await evalZod(\n selector.against,\n this.#imports,\n );\n if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n getSharedSchemas(): Record<string, SchemaObject> {\n return Object.fromEntries(this.#sharedResponses);\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, bodySchemaProps } =\n await this.#selectosToParameters(selectors);\n const bodySchema: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const sortedBodySchemaProps = Object.entries(\n sortObjectKeys(bodySchemaProps),\n );\n for (const [key, value] of sortedBodySchemaProps) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: Object.keys(bodySchema).length\n ? {\n required: required.length ? true : false,\n content: {\n [operation.contentType || 'application/json']: {\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: bodySchema,\n },\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\nexport function toSchema(data: DateType | string | null | undefined): any {\n if (data === null || data === undefined) {\n return { type: 'any' };\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n return { anyOf: data[$types].map(toSchema) };\n } else if (data.kind === 'intersection') {\n // TS gives anonymous/empty object types the synthetic symbol name \"__type\".\n // Members like `& {}` (the autocomplete-trick wrapper) contribute no schema\n // info \u2014 drop them so `(string & {})` emits as plain `{type:'string'}`.\n const ANON_OBJECT = '__type';\n const meaningful = (data[$types] as unknown[]).filter((m) => {\n if (!m || typeof m !== 'object') return true;\n const node = m as { kind?: unknown; [$types]?: readonly unknown[] };\n return !(\n !node.kind &&\n node[$types]?.length === 1 &&\n node[$types][0] === ANON_OBJECT\n );\n });\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1)\n return toSchema(meaningful[0] as DateType | string);\n return { allOf: meaningful.map((m) => toSchema(m as DateType | string)) };\n } else if ($types in data) {\n return data[$types].map(toSchema)[0] ?? {};\n } else {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value as any);\n if (!(value as any).optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,cAAc;AACvB,SAAS,WAAW,sBAAsB;AAC1C,SAA4B,eAAe;AAYpC,MAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,MAAM,0BAA0B;AAAA,EAC9B,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AACV;AAqBO,MAAM,MAAM;AAAA,EACjB,WAA2B,CAAC;AAAA,EAC5B;AAAA,EACA,mBAAmB,oBAAI,IAA0B;AAAA,EACjD,cASK,CAAC;AAAA,EAEN,YAAY,QAAgE;AAC1E,SAAK,WAAW,OAAO;AACvB,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA,EAEA,QACE,MACA,MACA,QACA,aACA,WACA,WACA,YACA,MACA;AACA,UAAM,kBAAkB,KAAK,yBAAyB,SAAS;AAE/D,SAAK,YAAY,KAAK;AAAA,MACpB;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,yBAAyB,WAA4C;AACnE,UAAM,kBAAmC,CAAC;AAC1C,eAAW,QAAQ,WAAW;AAC5B,YAAM,KAAK,KAAK;AAChB,UAAI,SAAS,KAAK,WAAW,SAAS,KAAK,QAAQ,IAAI,CAAC;AAGxD,UAAI,KAAK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AC7C,WAAW,KAAK,SAAS,gBAAgB;AAIvC,UAAM,cAAc;AACpB,UAAM,aAAc,KAAK,MAAM,EAAgB,OAAO,CAAC,MAAM;AAC3D,UAAI,CAAC,KAAK,OAAO,MAAM,SAAU,QAAO;AACxC,YAAM,OAAO;AACb,aAAO,EACL,CAAC,KAAK,QACN,KAAK,MAAM,GAAG,WAAW,KACzB,KAAK,MAAM,EAAE,CAAC,MAAM;AAAA,IAExB,CAAC;AACD,QAAI,WAAW,WAAW,EAAG,QAAO,CAAC;AACrC,QAAI,WAAW,WAAW;AACxB,aAAO,SAAS,WAAW,CAAC,CAAsB;AACpD,WAAO,EAAE,OAAO,WAAW,IAAI,CAAC,MAAM,SAAS,CAAsB,CAAC,EAAE;AAAA,EAC1E,WAAW,UAAU,MAAM;AACzB,WAAO,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC,KAAK,CAAC;AAAA,EAC3C,OAAO;AACL,UAAM,QAAiC,CAAC;AACxC,UAAM,WAAqB,CAAC;AAC5B,UAAM,gBAAgB,OAAO,QAAQ,eAAe,IAAI,CAAC;AACzD,eAAW,CAAC,KAAK,KAAK,KAAK,eAAe;AACxC,YAAM,GAAG,IAAI,SAAS,KAAY;AAClC,UAAI,CAAE,MAAc,UAAU;AAC5B,iBAAS,KAAK,GAAG;AAAA,MACnB;AAAA,IACF;AACA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU,UAAU,QAAQ;AAAA,MAC5B,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF;AAEO,SAAS,aAAa,MAA8B;AACzD,SAAO,CAAC,OAAO,QAAQ,OAAO,UAAU,OAAO,EAAE,SAAS,IAAI;AAChE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/ref.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HeaderObject, OpenAPIObject, ParameterObject, ReferenceObject, RequestBodyObject, SchemaObject, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
1
|
+
import type { HeaderObject, OpenAPIObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, SchemaObject, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
2
2
|
export declare function isRef(obj: any): obj is ReferenceObject;
|
|
3
3
|
export declare function notRef(obj: any): obj is SchemaObject;
|
|
4
4
|
export declare function cleanRef(ref: string): string;
|
|
@@ -7,8 +7,8 @@ export declare function parseRef(ref: string): {
|
|
|
7
7
|
namespace: string;
|
|
8
8
|
path: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function resolveRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject | ParameterObject | SecuritySchemeObject | HeaderObject): T;
|
|
11
|
-
export declare function followRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, ref: string): T;
|
|
10
|
+
export declare function resolveRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject | ParameterObject | PathItemObject | SecuritySchemeObject | HeaderObject): T;
|
|
11
|
+
export declare function followRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, ref: string): T;
|
|
12
12
|
export declare function tapRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject): T;
|
|
13
13
|
export declare function distillRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: ReferenceObject | SchemaObject): T;
|
|
14
14
|
//# sourceMappingURL=ref.d.ts.map
|
package/dist/lib/ref.d.ts.map
CHANGED
|
@@ -1 +1 @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G,YAAY,GAAG,CAAC,CA8ClE"}
|
package/dist/lib/ref.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/ref.ts"],
|
|
4
|
-
"sourcesContent": ["import { get } from 'lodash-es';\nimport type {\n HeaderObject,\n OpenAPIObject,\n ParameterObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\n\nimport { isEmpty } from './utils.js';\n\nexport function isRef(obj: any): obj is ReferenceObject {\n return obj && '$ref' in obj;\n}\nexport function notRef(obj: any): obj is SchemaObject {\n return !isRef(obj);\n}\n\nexport function cleanRef(ref: string) {\n return ref.replace(/^#\\//, '');\n}\n\nexport function parseRef(ref: string) {\n const parts = ref.split('/');\n const names: string[] = [];\n const [model] = parts.splice(-1);\n names.push(model);\n while (parts.lastIndexOf('properties') !== -1) {\n parts.splice(parts.lastIndexOf('properties'), 1);\n const [model] = parts.splice(-1);\n names.push(model);\n }\n const [namespace] = parts.splice(-1);\n return {\n model: names.reverse().join(' '),\n namespace,\n path: cleanRef(parts.join('/')),\n };\n}\n\nexport function resolveRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(\n spec: OpenAPIObject,\n maybeRef:\n | SchemaObject\n | ReferenceObject\n | ParameterObject\n | SecuritySchemeObject\n | HeaderObject,\n): T {\n if (isRef(maybeRef)) {\n return followRef<T>(spec, maybeRef.$ref!);\n }\n return maybeRef as T;\n}\n\nexport function followRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, ref: string): T {\n const pathParts = cleanRef(ref).split('/');\n const entry = get(spec, pathParts) as T | ReferenceObject;\n if (isRef(entry)) {\n return followRef<T>(spec, entry.$ref!);\n }\n return entry;\n}\n\nexport function tapRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject): T {\n if (isRef(maybeRef)) {\n const pathParts = cleanRef(maybeRef.$ref).split('/');\n return get(spec, pathParts) as T;\n }\n return maybeRef as T;\n}\n\nexport function distillRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, maybeRef: ReferenceObject | SchemaObject): T {\n const def = resolveRef<T>(spec, maybeRef);\n if (!def) {\n return def;\n }\n\n if ('properties' in def) {\n def.properties ??= {};\n for (const key in def.properties) {\n const prop = def.properties[key];\n if (isRef(prop)) {\n def.properties[key] = distillRef(spec, prop);\n }\n }\n }\n if ('items' in def) {\n if (isRef(def.items)) {\n def.items = distillRef<SchemaObject>(spec, def.items);\n }\n }\n if ('allOf' in def && !isEmpty(def.allOf)) {\n def.allOf = def.allOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('oneOf' in def && !isEmpty(def.oneOf)) {\n def.oneOf = def.oneOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('anyOf' in def && !isEmpty(def.anyOf)) {\n def.anyOf = def.anyOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n\n return def;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;
|
|
4
|
+
"sourcesContent": ["import { get } from 'lodash-es';\nimport type {\n HeaderObject,\n OpenAPIObject,\n ParameterObject,\n PathItemObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\n\nimport { isEmpty } from './utils.js';\n\nexport function isRef(obj: any): obj is ReferenceObject {\n return obj && '$ref' in obj;\n}\nexport function notRef(obj: any): obj is SchemaObject {\n return !isRef(obj);\n}\n\nexport function cleanRef(ref: string) {\n return ref.replace(/^#\\//, '');\n}\n\nexport function parseRef(ref: string) {\n const parts = ref.split('/');\n const names: string[] = [];\n const [model] = parts.splice(-1);\n names.push(model);\n while (parts.lastIndexOf('properties') !== -1) {\n parts.splice(parts.lastIndexOf('properties'), 1);\n const [model] = parts.splice(-1);\n names.push(model);\n }\n const [namespace] = parts.splice(-1);\n return {\n model: names.reverse().join(' '),\n namespace,\n path: cleanRef(parts.join('/')),\n };\n}\n\nexport function resolveRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | PathItemObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(\n spec: OpenAPIObject,\n maybeRef:\n | SchemaObject\n | ReferenceObject\n | ParameterObject\n | PathItemObject\n | SecuritySchemeObject\n | HeaderObject,\n): T {\n if (isRef(maybeRef)) {\n return followRef<T>(spec, maybeRef.$ref!);\n }\n return maybeRef as T;\n}\n\nexport function followRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | PathItemObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, ref: string): T {\n const pathParts = cleanRef(ref).split('/');\n const entry = get(spec, pathParts) as T | ReferenceObject;\n if (isRef(entry)) {\n return followRef<T>(spec, entry.$ref!);\n }\n return entry;\n}\n\nexport function tapRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject): T {\n if (isRef(maybeRef)) {\n const pathParts = cleanRef(maybeRef.$ref).split('/');\n return get(spec, pathParts) as T;\n }\n return maybeRef as T;\n}\n\nexport function distillRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(spec: OpenAPIObject, maybeRef: ReferenceObject | SchemaObject): T {\n const def = resolveRef<T>(spec, maybeRef);\n if (!def) {\n return def;\n }\n\n if ('properties' in def) {\n def.properties ??= {};\n for (const key in def.properties) {\n const prop = def.properties[key];\n if (isRef(prop)) {\n def.properties[key] = distillRef(spec, prop);\n }\n }\n }\n if ('items' in def) {\n if (isRef(def.items)) {\n def.items = distillRef<SchemaObject>(spec, def.items);\n }\n }\n if ('allOf' in def && !isEmpty(def.allOf)) {\n def.allOf = def.allOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('oneOf' in def && !isEmpty(def.oneOf)) {\n def.oneOf = def.oneOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('anyOf' in def && !isEmpty(def.anyOf)) {\n def.anyOf = def.anyOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n\n return def;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AAYpB,SAAS,eAAe;AAEjB,SAAS,MAAM,KAAkC;AACtD,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,OAAO,KAA+B;AACpD,SAAO,CAAC,MAAM,GAAG;AACnB;AAEO,SAAS,SAAS,KAAa;AACpC,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;AAEO,SAAS,SAAS,KAAa;AACpC,QAAM,QAAQ,IAAI,MAAM,GAAG;AAC3B,QAAM,QAAkB,CAAC;AACzB,QAAM,CAAC,KAAK,IAAI,MAAM,OAAO,EAAE;AAC/B,QAAM,KAAK,KAAK;AAChB,SAAO,MAAM,YAAY,YAAY,MAAM,IAAI;AAC7C,UAAM,OAAO,MAAM,YAAY,YAAY,GAAG,CAAC;AAC/C,UAAM,CAACA,MAAK,IAAI,MAAM,OAAO,EAAE;AAC/B,UAAM,KAAKA,MAAK;AAAA,EAClB;AACA,QAAM,CAAC,SAAS,IAAI,MAAM,OAAO,EAAE;AACnC,SAAO;AAAA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AAG;AACf,eAAO,WAAyB,MAAM,IAAI;AAAA,MAC5C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,MAAI,WAAW,OAAO,CAAC,QAAQ,IAAI,KAAK,GAAG;AACzC,QAAI,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AAClC,UAAI,MAAM,IAAI,GAAG;AACf,eAAO,WAAyB,MAAM,IAAI;AAAA,MAC5C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,MAAI,WAAW,OAAO,CAAC,QAAQ,IAAI,KAAK,GAAG;AACzC,QAAI,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AAClC,UAAI,MAAM,IAAI,GAAG;AACf,eAAO,WAAyB,MAAM,IAAI;AAAA,MAC5C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": ["model"]
|
|
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;
|
|
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,gBA0mBzE"}
|
|
@@ -32,7 +32,9 @@ async function evalZod(schema, imports = []) {
|
|
|
32
32
|
return withReceiverChecks(this, z.union([z.cidrv4(), z.cidrv6()]));
|
|
33
33
|
};
|
|
34
34
|
}`,
|
|
35
|
-
...imports.map(
|
|
35
|
+
...imports.map(
|
|
36
|
+
(imp) => `const ${imp.import} = require(${JSON.stringify(imp.from)})${imp.property ? `[${JSON.stringify(imp.property)}]` : ""};`
|
|
37
|
+
),
|
|
36
38
|
`let optional = false;`,
|
|
37
39
|
`const WRAPPER_TYPES = new Set([
|
|
38
40
|
'optional',
|
|
@@ -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};\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((imp) => `const ${imp.import} = require('${imp.from}');`),\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 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 const numericPair =\n (merged.type === 'number' && schema.type === 'integer') ||\n (merged.type === 'integer' && schema.type === 'number');\n if (!numericPair) {\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 === 'optional') {\n optional = true;\n }\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 for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\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 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": "
|
|
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 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 const numericPair =\n (merged.type === 'number' && schema.type === 'integer') ||\n (merged.type === 'integer' && schema.type === 'number');\n if (!numericPair) {\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 === 'optional') {\n optional = true;\n }\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 for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\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 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,IAGA;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;AA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,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.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,9 +32,8 @@
|
|
|
32
32
|
"lodash-es": "^4.17.21"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"typescript": "^
|
|
36
|
-
"openapi3-ts": "^4.4.0"
|
|
37
|
-
"zod": "^4.3.0"
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"openapi3-ts": "^4.4.0"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/debug": "^4.1.12"
|