@sdk-it/core 0.19.1 → 0.21.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.d.ts +5 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -976
- package/dist/index.js.map +4 -4
- package/dist/lib/deriver.js +475 -0
- package/dist/lib/deriver.js.map +7 -0
- package/dist/lib/deriver.test.js +417 -0
- package/dist/lib/deriver.test.js.map +7 -0
- package/dist/lib/file-system.d.ts +26 -7
- package/dist/lib/file-system.d.ts.map +1 -1
- package/dist/lib/file-system.js +139 -0
- package/dist/lib/file-system.js.map +7 -0
- package/dist/lib/paths.d.ts +1 -1
- package/dist/lib/paths.js +237 -0
- package/dist/lib/paths.js.map +7 -0
- package/dist/lib/program.js +75 -0
- package/dist/lib/program.js.map +7 -0
- package/dist/lib/ref.d.ts +3 -2
- package/dist/lib/ref.d.ts.map +1 -1
- package/dist/lib/ref.js +83 -0
- package/dist/lib/ref.js.map +7 -0
- package/dist/lib/utils.d.ts +14 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +41 -0
- package/dist/lib/utils.js.map +7 -0
- package/package.json +6 -1
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"
|
|
4
|
-
"sourcesContent": ["import {\n pascalcase as _pascalcase,\n snakecase as _snakecase,\n spinalcase as _spinalcase,\n} from 'stringcase';\nimport type ts from 'typescript';\n\nimport type { TypeDeriver } from './lib/deriver.ts';\nimport type { ResponseItem } from './lib/paths.ts';\n\nexport * from './lib/deriver.ts';\nexport * from './lib/file-system.ts';\nexport * from './lib/paths.ts';\nexport * from './lib/program.ts';\nexport * from './lib/ref.ts';\n\nexport function removeDuplicates<T>(\n data: T[],\n accessor: (item: T) => T[keyof T] | T = (item) => item,\n): T[] {\n return [...new Map(data.map((x) => [accessor(x), x])).values()];\n}\n\nexport type InferRecordValue<T> = T extends Record<string, infer U> ? U : any;\n\nexport function toLitObject<T extends Record<string, any>>(\n obj: T,\n accessor: (value: InferRecordValue<T>) => string = (value) => value,\n) {\n return `{${Object.keys(obj)\n .map((key) => `${key}: ${accessor(obj[key])}`)\n .join(', ')}}`;\n}\n\nexport type NaunceResponseAnalyzerFn = (\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n node: ts.Node,\n) => ResponseItem[];\nexport type NaunceResponseAnalyzer = Record<string, NaunceResponseAnalyzerFn>;\n\nexport type ResponseAnalyzerFn = (\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n) => ResponseItem[];\n\nexport function isEmpty(value: unknown): value is null | undefined | '' {\n if (value === null || value === undefined || value === '') {\n return true;\n }\n if (Array.isArray(value) && value.length === 0) {\n return true;\n }\n if (typeof value === 'object' && Object.keys(value).length === 0) {\n return true;\n }\n return false;\n}\n\nexport function pascalcase(value: string) {\n return _pascalcase(value.split('/').join(' '));\n}\nexport function spinalcase(value: string) {\n return _spinalcase(value.split('/').join(' '));\n}\nexport function snakecase(value: string) {\n return _snakecase(value.split('/').join(' '));\n}\n", "import ts, { TypeFlags, symbolName } from 'typescript';\n\ntype Collector = Record<string, any>;\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\nconst defaults: 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};\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n constructor(checker: ts.TypeChecker) {\n this.checker = checker;\n }\n\n serializeType(type: ts.Type): any {\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 [$types]: ['boolean'],\n };\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: true,\n [$types]: ['null'],\n };\n }\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === 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: '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 console.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 = 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 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 (defaults[symbolName(type.symbol)]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [defaults[type.symbol.name]],\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 }\n 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 }\n }\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [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 console.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 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 props;\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n console.warn(`No symbol found for ${node.name.getText()}`);\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 console.warn(`No symbol found for ${node.name.getText()}`);\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 console.warn(`No symbol found for ${node.name.getText()}`);\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 (defaults[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [defaults[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] = 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 (defaults[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [defaults[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] = 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 console.warn(`No symbol found for ${node.name.getText()}`);\n return null;\n }\n if (!node.type) {\n console.warn(`No type found for ${node.name.getText()}`);\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 console.warn(`Identifer: No symbol found for ${node.getText()}`);\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]: [props],\n };\n }\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: true,\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.isArrayLiteralExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n console.warn(`Unhandled node: ${ts.SyntaxKind[node.kind]} ${node.flags}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n\nfunction isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}\n", "import type { Dirent } from 'node:fs';\nimport { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';\nimport { dirname, extname, isAbsolute, join } from 'node:path';\n\nexport async function getFile(filePath: string) {\n if (await exist(filePath)) {\n return readFile(filePath, 'utf-8');\n }\n return null;\n}\n\nexport async function exist(file: string): Promise<boolean> {\n return stat(file)\n .then(() => true)\n .catch(() => false);\n}\n\nexport async function readFolder(path: string) {\n if (await exist(path)) {\n return readdir(path);\n }\n return [] as string[];\n}\n\nexport async function writeFiles(\n dir: string,\n contents: Record<\n string,\n null | string | { content: string; ignoreIfExists?: boolean }\n >,\n) {\n await Promise.all(\n Object.entries(contents).map(async ([file, content]) => {\n if (content === null) {\n return;\n }\n const filePath = isAbsolute(file) ? file : join(dir, file);\n await mkdir(dirname(filePath), { recursive: true });\n if (typeof content === 'string') {\n await writeFile(filePath, content, 'utf-8');\n } else {\n if (content.ignoreIfExists) {\n if (!(await exist(filePath))) {\n await writeFile(filePath, content.content, 'utf-8');\n }\n } else {\n await writeFile(filePath, content.content, 'utf-8');\n }\n }\n }),\n );\n}\n\nexport async function getFolderExports(\n folder: string,\n includeExtension = true,\n extensions = ['ts'],\n ignore: (dirent: Dirent) => boolean = () => false,\n) {\n const files = await readdir(folder, { withFileTypes: true });\n const exports: string[] = [];\n for (const file of files) {\n if (ignore(file)) {\n continue;\n }\n if (file.isDirectory()) {\n if (await exist(`${file.parentPath}/${file.name}/index.ts`)) {\n exports.push(\n `export * from './${file.name}/index${includeExtension ? '.ts' : ''}';`,\n );\n }\n } else if (\n file.name !== 'index.ts' &&\n extensions.includes(getExt(file.name))\n ) {\n exports.push(\n `export * from './${includeExtension ? file.name : file.name.replace(extname(file.name), '')}';`,\n );\n }\n }\n return exports.join('\\n');\n}\n\nexport async function getFolderExportsV2(\n folder: string,\n options: {\n includeExtension?: boolean;\n extensions: string;\n ignore?: (dirent: Dirent) => boolean;\n exportSyntax: string;\n } = {\n extensions: 'ts',\n ignore: () => false,\n includeExtension: true,\n exportSyntax: 'export * from ',\n },\n) {\n options.includeExtension ??= true;\n if (!(await exist(folder))) {\n return '';\n }\n const files = await readdir(folder, { withFileTypes: true });\n const exports: string[] = [];\n for (const file of files) {\n if (options.ignore?.(file)) {\n continue;\n }\n if (file.isDirectory()) {\n if (\n await exist(\n `${file.parentPath}/${file.name}/index.${options.extensions}`,\n )\n ) {\n exports.push(\n `${options.exportSyntax} './${file.name}/index${options.includeExtension ? `.${options.extensions}` : ''}';`,\n );\n }\n } else if (\n file.name !== `index.${options.extensions}` &&\n options.extensions.includes(getExt(file.name))\n ) {\n exports.push(\n `${options.exportSyntax} './${options.includeExtension ? file.name : file.name.replace(extname(file.name), '')}';`,\n );\n }\n }\n return exports.join('\\n');\n}\n\nexport const getExt = (fileName?: string) => {\n if (!fileName) {\n return ''; // shouldn't happen as there will always be a file name\n }\n const lastDot = fileName.lastIndexOf('.');\n if (lastDot === -1) {\n return '';\n }\n const ext = fileName\n .slice(lastDot + 1)\n .split('/')\n .filter(Boolean)\n .join('');\n if (ext === fileName) {\n // files that have no extension\n return '';\n }\n return ext || 'txt';\n};\n", "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.ts';\n\nexport type Method =\n | 'get'\n | 'post'\n | 'put'\n | 'patch'\n | 'delete'\n | 'trace'\n | 'head';\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 select: string;\n against: string;\n source: SemanticSource;\n nullable: boolean;\n required: boolean;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #commonZodImport?: string;\n #onOperation?: OnOperation;\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 tags?: string[];\n description?: string;\n }> = [];\n\n constructor(config: { commonZodImport?: string; onOperation?: OnOperation }) {\n this.#commonZodImport = config.commonZodImport;\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 tags?: string[],\n description?: string,\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 tags,\n description,\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 const schema = item.response ? toSchema(item.response) : {};\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 return Object.entries(headers).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 if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: selector.required,\n schema: await evalZod(selector.against, this.#commonZodImport),\n };\n continue;\n }\n\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: selector.required,\n schema: await evalZod(selector.against, this.#commonZodImport),\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n async getPaths() {\n const operations: PathsObject = {};\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 for (const [key, value] of Object.entries(bodySchemaProps)) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.tags,\n description: operation.description,\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 ? 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\nasync function evalZod(schema: string, commonZodImport?: string) {\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 commonZodImport ? `const commonZod = require('${commonZodImport}');` : '',\n `const {zodToJsonSchema} = require('zod-to-json-schema');`,\n `const schema = ${schema.replace('.optional()', '').replaceAll('instanceof(File)', 'string().base64()')};`,\n `const jsonSchema = zodToJsonSchema(schema, {\n $refStrategy: 'root',\n basePath: ['#', 'components', 'schemas'],\n target: 'jsonSchema7',\n base64Strategy: 'format:binary',\n });`,\n `export default jsonSchema;`,\n ];\n\n const base64 = Buffer.from(lines.join('\\n')).toString('base64');\n return import(`data:text/javascript;base64,${base64}`)\n .then((mod) => mod.default)\n .then(({ $schema, ...result }) => result);\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 return { allOf: data[$types].map(toSchema) };\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 for (const [key, value] of Object.entries(data)) {\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,\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", "import debug from 'debug';\nimport { dirname, join } from 'node:path';\nimport ts from 'typescript';\n\nconst logger = debug('january:client');\n\nexport function parseTsConfig(tsconfigPath: string) {\n logger(`Using TypeScript version: ${ts.version}`);\n const configContent = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configContent.error) {\n console.error(\n `Failed to read tsconfig file:`,\n ts.formatDiagnosticsWithColorAndContext([configContent.error], {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configContent.config,\n ts.sys,\n dirname(tsconfigPath),\n );\n\n if (parsed.errors.length > 0) {\n console.error(\n `Errors found in tsconfig.json:`,\n ts.formatDiagnosticsWithColorAndContext(parsed.errors, {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n return parsed;\n}\nexport function getProgram(tsconfigPath: string) {\n const tsConfigParseResult = parseTsConfig(tsconfigPath);\n logger(`Parsing tsconfig`);\n return ts.createProgram({\n options: {\n ...tsConfigParseResult.options,\n noEmit: true,\n incremental: true,\n tsBuildInfoFile: join(dirname(tsconfigPath), './.tsbuildinfo'), // not working atm\n },\n rootNames: tsConfigParseResult.fileNames,\n projectReferences: tsConfigParseResult.projectReferences,\n configFileParsingDiagnostics: tsConfigParseResult.errors,\n });\n}\nexport function getPropertyAssignment(node: ts.Node, name: string) {\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties\n .filter((prop) => ts.isPropertyAssignment(prop))\n .find((prop) => prop.name!.getText() === name);\n }\n return undefined;\n}\nexport function isCallExpression(\n node: ts.Node,\n name: string,\n): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n node.expression &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === name\n );\n}\n\nexport function isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}\n", "import { get } from 'lodash-es';\nimport type {\n OpenAPIObject,\n ParameterObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\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 [model] = parts.splice(-1);\n const [namespace] = parts.splice(-1);\n return {\n model,\n namespace,\n path: cleanRef(parts.join('/')),\n };\n}\nexport function followRef<\n T extends SchemaObject | ParameterObject | 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 (entry && '$ref' in entry) {\n return followRef<T>(spec, entry.$ref);\n }\n return entry;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA,OACT;;;ACJP,OAAO,MAAM,WAAW,kBAAkB;AAGnC,IAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,IAAM,SAAS,OAAO,IAAI,OAAO;AACxC,IAAM,WAAmC;AAAA,EACvC,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,wBA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Y,SAAS,GAAG,EAAE,MAAM,GAAG;AACzC,QAAM,QAAQ,IAAI,MAAM,SAAS;AACjC,MAAI,SAAS,UAAU,OAAO;AAC5B,WAAO,UAAa,MAAM,MAAM,IAAI;AAAA,EACtC;AACA,SAAO;AACT;;;ALvBO,SAAS,iBACd,MACA,WAAwC,CAAC,SAAS,MAC7C;AACL,SAAO,CAAC,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AAChE;AAIO,SAAS,YACd,KACA,WAAmD,CAAC,UAAU,OAC9D;AACA,SAAO,IAAI,OAAO,KAAK,GAAG,EACvB,IAAI,CAAC,QAAQ,GAAG,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,CAAC,EAAE,EAC5C,KAAK,IAAI,CAAC;AACf;AAcO,SAAS,QAAQ,OAAgD;AACtE,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,IAAI;AACzD,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GAAG;AAC9C,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,YAAY,OAAO,KAAK,KAAK,EAAE,WAAW,GAAG;AAChE,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,OAAe;AACxC,SAAO,YAAY,MAAM,MAAM,GAAG,EAAE,KAAK,GAAG,CAAC;AAC/C;AACO,SAAS,WAAW,OAAe;AACxC,SAAO,YAAY,MAAM,MAAM,GAAG,EAAE,KAAK,GAAG,CAAC;AAC/C;AACO,SAAS,UAAU,OAAe;AACvC,SAAO,WAAW,MAAM,MAAM,GAAG,EAAE,KAAK,GAAG,CAAC;AAC9C;",
|
|
6
|
-
"names": [
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["\nexport * from './lib/deriver.js';\nexport * from './lib/paths.js';\nexport * from './lib/program.js';\nexport * from './lib/ref.js';\nexport * from './lib/utils.js';\n"],
|
|
5
|
+
"mappings": "AACA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import ts, { TypeFlags, symbolName } from "typescript";
|
|
2
|
+
const deriveSymbol = Symbol.for("serialize");
|
|
3
|
+
const $types = Symbol.for("types");
|
|
4
|
+
const defaults = {
|
|
5
|
+
Readable: "any",
|
|
6
|
+
ReadableStream: "any",
|
|
7
|
+
DateConstructor: "string",
|
|
8
|
+
ArrayBufferConstructor: "any",
|
|
9
|
+
SharedArrayBufferConstructor: "any",
|
|
10
|
+
Int8ArrayConstructor: "any",
|
|
11
|
+
Uint8Array: "any"
|
|
12
|
+
};
|
|
13
|
+
class TypeDeriver {
|
|
14
|
+
collector = {};
|
|
15
|
+
checker;
|
|
16
|
+
constructor(checker) {
|
|
17
|
+
this.checker = checker;
|
|
18
|
+
}
|
|
19
|
+
serializeType(type) {
|
|
20
|
+
const indexType = type.getStringIndexType();
|
|
21
|
+
if (indexType) {
|
|
22
|
+
return {
|
|
23
|
+
[deriveSymbol]: true,
|
|
24
|
+
kind: "record",
|
|
25
|
+
optional: false,
|
|
26
|
+
[$types]: [this.serializeType(indexType)]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (type.flags & TypeFlags.Any) {
|
|
30
|
+
return {
|
|
31
|
+
[deriveSymbol]: true,
|
|
32
|
+
optional: false,
|
|
33
|
+
[$types]: []
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (type.flags & TypeFlags.Unknown) {
|
|
37
|
+
return {
|
|
38
|
+
[deriveSymbol]: true,
|
|
39
|
+
optional: false,
|
|
40
|
+
[$types]: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (type.isStringLiteral()) {
|
|
44
|
+
return {
|
|
45
|
+
[deriveSymbol]: true,
|
|
46
|
+
optional: false,
|
|
47
|
+
kind: "literal",
|
|
48
|
+
value: type.value,
|
|
49
|
+
[$types]: ["string"]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (type.isNumberLiteral()) {
|
|
53
|
+
return {
|
|
54
|
+
[deriveSymbol]: true,
|
|
55
|
+
optional: false,
|
|
56
|
+
kind: "literal",
|
|
57
|
+
value: type.value,
|
|
58
|
+
[$types]: ["number"]
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (type.flags & TypeFlags.BooleanLiteral) {
|
|
62
|
+
return {
|
|
63
|
+
[deriveSymbol]: true,
|
|
64
|
+
optional: false,
|
|
65
|
+
[$types]: ["boolean"]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (type.flags & TypeFlags.TemplateLiteral) {
|
|
69
|
+
return {
|
|
70
|
+
[deriveSymbol]: true,
|
|
71
|
+
optional: false,
|
|
72
|
+
[$types]: ["string"]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (type.flags & TypeFlags.String) {
|
|
76
|
+
return {
|
|
77
|
+
[deriveSymbol]: true,
|
|
78
|
+
optional: false,
|
|
79
|
+
[$types]: ["string"]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (type.flags & TypeFlags.Number) {
|
|
83
|
+
return {
|
|
84
|
+
[deriveSymbol]: true,
|
|
85
|
+
optional: false,
|
|
86
|
+
[$types]: ["number"]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (type.flags & ts.TypeFlags.Boolean) {
|
|
90
|
+
return {
|
|
91
|
+
[deriveSymbol]: true,
|
|
92
|
+
optional: false,
|
|
93
|
+
[$types]: ["boolean"]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (type.flags & TypeFlags.Null) {
|
|
97
|
+
return {
|
|
98
|
+
[deriveSymbol]: true,
|
|
99
|
+
optional: true,
|
|
100
|
+
[$types]: ["null"]
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (type.isIntersection()) {
|
|
104
|
+
let optional;
|
|
105
|
+
const types = [];
|
|
106
|
+
for (const unionType of type.types) {
|
|
107
|
+
if (optional === void 0) {
|
|
108
|
+
optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;
|
|
109
|
+
if (optional) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
types.push(this.serializeType(unionType));
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
[deriveSymbol]: true,
|
|
117
|
+
kind: "intersection",
|
|
118
|
+
optional,
|
|
119
|
+
[$types]: types
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (type.isUnion()) {
|
|
123
|
+
let optional;
|
|
124
|
+
const types = [];
|
|
125
|
+
for (const unionType of type.types) {
|
|
126
|
+
if (optional === void 0) {
|
|
127
|
+
optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;
|
|
128
|
+
if (optional) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
types.push(this.serializeType(unionType));
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
[deriveSymbol]: true,
|
|
136
|
+
kind: "union",
|
|
137
|
+
optional,
|
|
138
|
+
[$types]: types
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (this.checker.isArrayLikeType(type)) {
|
|
142
|
+
const [argType] = this.checker.getTypeArguments(type);
|
|
143
|
+
if (!argType) {
|
|
144
|
+
const typeName = type.symbol?.getName() || "<unknown>";
|
|
145
|
+
console.warn(
|
|
146
|
+
`Could not find generic type argument for array type ${typeName}`
|
|
147
|
+
);
|
|
148
|
+
return {
|
|
149
|
+
[deriveSymbol]: true,
|
|
150
|
+
optional: false,
|
|
151
|
+
kind: "array",
|
|
152
|
+
[$types]: ["any"]
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const typeSymbol = argType.getSymbol();
|
|
156
|
+
if (!typeSymbol) {
|
|
157
|
+
return {
|
|
158
|
+
[deriveSymbol]: true,
|
|
159
|
+
optional: false,
|
|
160
|
+
kind: "array",
|
|
161
|
+
[$types]: [this.serializeType(argType)]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (typeSymbol.valueDeclaration) {
|
|
165
|
+
return {
|
|
166
|
+
kind: "array",
|
|
167
|
+
[deriveSymbol]: true,
|
|
168
|
+
[$types]: [this.serializeNode(typeSymbol.valueDeclaration)]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const maybeDeclaration = typeSymbol.declarations?.[0];
|
|
172
|
+
if (maybeDeclaration) {
|
|
173
|
+
if (ts.isMappedTypeNode(maybeDeclaration)) {
|
|
174
|
+
const resolvedType = this.checker.getPropertiesOfType(argType).reduce((acc, prop) => {
|
|
175
|
+
const propType = this.checker.getTypeOfSymbol(prop);
|
|
176
|
+
acc[prop.name] = this.serializeType(propType);
|
|
177
|
+
return acc;
|
|
178
|
+
}, {});
|
|
179
|
+
return {
|
|
180
|
+
kind: "array",
|
|
181
|
+
optional: false,
|
|
182
|
+
[deriveSymbol]: true,
|
|
183
|
+
[$types]: [resolvedType]
|
|
184
|
+
};
|
|
185
|
+
} else {
|
|
186
|
+
return {
|
|
187
|
+
kind: "array",
|
|
188
|
+
...this.serializeNode(maybeDeclaration)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
kind: "array",
|
|
194
|
+
optional: false,
|
|
195
|
+
[deriveSymbol]: true,
|
|
196
|
+
[$types]: ["any"]
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (type.isClass()) {
|
|
200
|
+
const declaration = type.symbol?.valueDeclaration;
|
|
201
|
+
if (!declaration) {
|
|
202
|
+
return {
|
|
203
|
+
[deriveSymbol]: true,
|
|
204
|
+
optional: false,
|
|
205
|
+
[$types]: [type.symbol.getName()]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return this.serializeNode(declaration);
|
|
209
|
+
}
|
|
210
|
+
if (isInterfaceType(type)) {
|
|
211
|
+
const valueDeclaration = type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];
|
|
212
|
+
if (!valueDeclaration) {
|
|
213
|
+
return {
|
|
214
|
+
[deriveSymbol]: true,
|
|
215
|
+
optional: false,
|
|
216
|
+
[$types]: [type.symbol.getName()]
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return this.serializeNode(valueDeclaration);
|
|
220
|
+
}
|
|
221
|
+
if (type.flags & TypeFlags.Object) {
|
|
222
|
+
if (defaults[symbolName(type.symbol)]) {
|
|
223
|
+
return {
|
|
224
|
+
[deriveSymbol]: true,
|
|
225
|
+
optional: false,
|
|
226
|
+
[$types]: [defaults[type.symbol.name]]
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const properties = this.checker.getPropertiesOfType(type);
|
|
230
|
+
if (properties.length > 0) {
|
|
231
|
+
const serializedProps = {};
|
|
232
|
+
for (const prop of properties) {
|
|
233
|
+
const propAssingment = (prop.getDeclarations() ?? []).find(
|
|
234
|
+
(it) => ts.isPropertyAssignment(it)
|
|
235
|
+
);
|
|
236
|
+
if (propAssingment) {
|
|
237
|
+
const type2 = this.checker.getTypeAtLocation(
|
|
238
|
+
propAssingment.initializer
|
|
239
|
+
);
|
|
240
|
+
serializedProps[prop.name] = this.serializeType(type2);
|
|
241
|
+
}
|
|
242
|
+
if ((prop.getDeclarations() ?? []).find(
|
|
243
|
+
(it) => ts.isPropertySignature(it)
|
|
244
|
+
)) {
|
|
245
|
+
const propType = this.checker.getTypeOfSymbol(prop);
|
|
246
|
+
serializedProps[prop.name] = this.serializeType(propType);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
[deriveSymbol]: true,
|
|
251
|
+
kind: "object",
|
|
252
|
+
optional: false,
|
|
253
|
+
[$types]: [serializedProps]
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const declaration = type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];
|
|
257
|
+
if (!declaration) {
|
|
258
|
+
return {
|
|
259
|
+
[deriveSymbol]: true,
|
|
260
|
+
optional: false,
|
|
261
|
+
[$types]: [type.symbol.getName()]
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return this.serializeNode(declaration);
|
|
265
|
+
}
|
|
266
|
+
console.warn(`Unhandled type: ${type.flags} ${ts.TypeFlags[type.flags]}`);
|
|
267
|
+
return {
|
|
268
|
+
[deriveSymbol]: true,
|
|
269
|
+
optional: false,
|
|
270
|
+
[$types]: [
|
|
271
|
+
this.checker.typeToString(
|
|
272
|
+
type,
|
|
273
|
+
void 0,
|
|
274
|
+
ts.TypeFormatFlags.NoTruncation
|
|
275
|
+
)
|
|
276
|
+
]
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
serializeNode(node) {
|
|
280
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
281
|
+
const symbolType = this.checker.getTypeAtLocation(node);
|
|
282
|
+
const props = {};
|
|
283
|
+
for (const symbol of symbolType.getProperties()) {
|
|
284
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
285
|
+
props[symbol.name] = this.serializeType(type);
|
|
286
|
+
}
|
|
287
|
+
for (const prop of node.properties) {
|
|
288
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
289
|
+
const type = this.checker.getTypeAtLocation(prop.initializer);
|
|
290
|
+
props[prop.name.getText()] = this.serializeType(type);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return props;
|
|
294
|
+
}
|
|
295
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
296
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
297
|
+
if (!symbol) {
|
|
298
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
302
|
+
return this.serializeType(type);
|
|
303
|
+
}
|
|
304
|
+
if (ts.isPropertySignature(node)) {
|
|
305
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
306
|
+
if (!symbol) {
|
|
307
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
311
|
+
return this.serializeType(type);
|
|
312
|
+
}
|
|
313
|
+
if (ts.isPropertyDeclaration(node)) {
|
|
314
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
315
|
+
if (!symbol) {
|
|
316
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
320
|
+
return this.serializeType(type);
|
|
321
|
+
}
|
|
322
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
323
|
+
if (!node.name?.text) {
|
|
324
|
+
throw new Error("Interface has no name");
|
|
325
|
+
}
|
|
326
|
+
if (defaults[node.name.text]) {
|
|
327
|
+
return {
|
|
328
|
+
[deriveSymbol]: true,
|
|
329
|
+
optional: false,
|
|
330
|
+
[$types]: [defaults[node.name.text]]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (!this.collector[node.name.text]) {
|
|
334
|
+
this.collector[node.name.text] = {};
|
|
335
|
+
const members = {};
|
|
336
|
+
for (const member of node.members.filter(ts.isPropertySignature)) {
|
|
337
|
+
members[member.name.getText()] = this.serializeNode(member);
|
|
338
|
+
}
|
|
339
|
+
this.collector[node.name.text] = members;
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
[deriveSymbol]: true,
|
|
343
|
+
optional: false,
|
|
344
|
+
[$types]: [`#/components/schemas/${node.name.text}`]
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (ts.isClassDeclaration(node)) {
|
|
348
|
+
if (!node.name?.text) {
|
|
349
|
+
throw new Error("Class has no name");
|
|
350
|
+
}
|
|
351
|
+
if (defaults[node.name.text]) {
|
|
352
|
+
return {
|
|
353
|
+
[deriveSymbol]: true,
|
|
354
|
+
optional: false,
|
|
355
|
+
[$types]: [defaults[node.name.text]]
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!this.collector[node.name.text]) {
|
|
359
|
+
this.collector[node.name.text] = {};
|
|
360
|
+
const members = {};
|
|
361
|
+
for (const member of node.members.filter(ts.isPropertyDeclaration)) {
|
|
362
|
+
members[member.name.getText()] = this.serializeNode(member);
|
|
363
|
+
}
|
|
364
|
+
this.collector[node.name.text] = members;
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
[deriveSymbol]: true,
|
|
368
|
+
optional: false,
|
|
369
|
+
[$types]: [`#/components/schemas/${node.name.text}`],
|
|
370
|
+
$ref: `#/components/schemas/${node.name.text}`
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (ts.isVariableDeclaration(node)) {
|
|
374
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
375
|
+
if (!symbol) {
|
|
376
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
if (!node.type) {
|
|
380
|
+
console.warn(`No type found for ${node.name.getText()}`);
|
|
381
|
+
return "any";
|
|
382
|
+
}
|
|
383
|
+
const type = this.checker.getTypeFromTypeNode(node.type);
|
|
384
|
+
return this.serializeType(type);
|
|
385
|
+
}
|
|
386
|
+
if (ts.isIdentifier(node)) {
|
|
387
|
+
const symbol = this.checker.getSymbolAtLocation(node);
|
|
388
|
+
if (!symbol) {
|
|
389
|
+
console.warn(`Identifer: No symbol found for ${node.getText()}`);
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
393
|
+
return this.serializeType(type);
|
|
394
|
+
}
|
|
395
|
+
if (ts.isAwaitExpression(node)) {
|
|
396
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
397
|
+
return this.serializeType(type);
|
|
398
|
+
}
|
|
399
|
+
if (ts.isCallExpression(node)) {
|
|
400
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
401
|
+
return this.serializeType(type);
|
|
402
|
+
}
|
|
403
|
+
if (ts.isAsExpression(node)) {
|
|
404
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
405
|
+
return this.serializeType(type);
|
|
406
|
+
}
|
|
407
|
+
if (ts.isTypeLiteralNode(node)) {
|
|
408
|
+
const symbolType = this.checker.getTypeAtLocation(node);
|
|
409
|
+
const props = {};
|
|
410
|
+
for (const symbol of symbolType.getProperties()) {
|
|
411
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
412
|
+
props[symbol.name] = this.serializeType(type);
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
[deriveSymbol]: true,
|
|
416
|
+
optional: false,
|
|
417
|
+
[$types]: [props]
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (node.kind === ts.SyntaxKind.NullKeyword) {
|
|
421
|
+
return {
|
|
422
|
+
[deriveSymbol]: true,
|
|
423
|
+
optional: true,
|
|
424
|
+
[$types]: ["null"]
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
if (node.kind === ts.SyntaxKind.BooleanKeyword) {
|
|
428
|
+
return {
|
|
429
|
+
[deriveSymbol]: true,
|
|
430
|
+
optional: false,
|
|
431
|
+
[$types]: ["boolean"]
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
if (node.kind === ts.SyntaxKind.TrueKeyword) {
|
|
435
|
+
return {
|
|
436
|
+
[deriveSymbol]: true,
|
|
437
|
+
optional: false,
|
|
438
|
+
kind: "literal",
|
|
439
|
+
value: true,
|
|
440
|
+
[$types]: ["boolean"]
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
if (node.kind === ts.SyntaxKind.FalseKeyword) {
|
|
444
|
+
return {
|
|
445
|
+
[deriveSymbol]: true,
|
|
446
|
+
optional: false,
|
|
447
|
+
kind: "literal",
|
|
448
|
+
value: false,
|
|
449
|
+
[$types]: ["boolean"]
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
453
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
454
|
+
return this.serializeType(type);
|
|
455
|
+
}
|
|
456
|
+
console.warn(`Unhandled node: ${ts.SyntaxKind[node.kind]} ${node.flags}`);
|
|
457
|
+
return {
|
|
458
|
+
[deriveSymbol]: true,
|
|
459
|
+
optional: false,
|
|
460
|
+
[$types]: ["any"]
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function isInterfaceType(type) {
|
|
465
|
+
if (type.isClassOrInterface()) {
|
|
466
|
+
return !!(type.symbol.flags & ts.SymbolFlags.Interface);
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
export {
|
|
471
|
+
$types,
|
|
472
|
+
TypeDeriver,
|
|
473
|
+
deriveSymbol
|
|
474
|
+
};
|
|
475
|
+
//# sourceMappingURL=deriver.js.map
|