moonflower 1.6.0 → 1.6.2

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.
Files changed (28) hide show
  1. package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
  2. package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
  3. package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
  4. package/dist/openapi/analyzerModule/analyzerModule.mjs +21 -21
  5. package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -1
  6. package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs +1 -1
  7. package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs.map +1 -1
  8. package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts +1 -1
  9. package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -1
  10. package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs +43 -32
  11. package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs.map +1 -1
  12. package/dist/openapi/analyzerModule/nodeParsers.cjs +1 -1
  13. package/dist/openapi/analyzerModule/nodeParsers.cjs.map +1 -1
  14. package/dist/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
  15. package/dist/openapi/analyzerModule/nodeParsers.mjs +241 -222
  16. package/dist/openapi/analyzerModule/nodeParsers.mjs.map +1 -1
  17. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs +1 -1
  18. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs.map +1 -1
  19. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts +4 -2
  20. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts.map +1 -1
  21. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs +10 -14
  22. package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs.map +1 -1
  23. package/package.json +1 -1
  24. package/src/openapi/analyzerModule/analyzerModule.ts +1 -3
  25. package/src/openapi/analyzerModule/getSourceFileTimestamp.ts +52 -37
  26. package/src/openapi/analyzerModule/nodeParsers.ts +57 -22
  27. package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.spec.ts +12 -3
  28. package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts +2 -7
@@ -1 +1 @@
1
- {"version":3,"file":"nodeParsers.mjs","sources":["../../../src/openapi/analyzerModule/nodeParsers.ts"],"sourcesContent":["import {\n\tNode,\n\tPropertyAccessExpression,\n\tPropertyAssignment,\n\tPropertySignature,\n\tShorthandPropertyAssignment,\n\tSyntaxKind,\n\tts,\n\tType,\n\tTypeReferenceNode,\n} from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { OpenApiManager } from '../manager/OpenApiManager'\nimport { ShapeOfProperty, ShapeOfType, ShapeOfUnionEntry } from './types'\n\nconst implementationCache = new WeakMap<Node, Node>()\nconst nodeShapeCache = new WeakMap<Node, ShapeOfType['shape']>()\nconst typeShapeCache = new WeakMap<object, ShapeOfType['shape']>()\n\nexport const findNodeImplementation = (node: Node): Node => {\n\tconst cached = implementationCache.get(node)\n\tif (cached) {\n\t\treturn cached\n\t}\n\n\tif (node.getKind() === SyntaxKind.Identifier) {\n\t\tconst implementationNode = node.asKind(SyntaxKind.Identifier)!.getImplementations()[0]?.getNode()\n\t\tif (implementationNode) {\n\t\t\tconst implementationParentNode = implementationNode.getParent()!\n\t\t\tconst assignmentValueNode = implementationParentNode.getLastChild()!\n\t\t\tif (assignmentValueNode === node) {\n\t\t\t\tthrow new Error('Recursive implementation found')\n\t\t\t}\n\t\t\tconst result = findNodeImplementation(assignmentValueNode)\n\t\t\timplementationCache.set(node, result)\n\t\t\treturn result\n\t\t}\n\n\t\tconst definitionNode = node.asKind(SyntaxKind.Identifier)!.getDefinitions()[0]?.getNode()\n\t\tif (definitionNode) {\n\t\t\tconst definitionParentNode = definitionNode.getParent()!\n\t\t\tconst assignmentValueNode = definitionParentNode.getLastChild()!\n\t\t\tif (assignmentValueNode === node) {\n\t\t\t\tthrow new Error('Recursive implementation found')\n\t\t\t}\n\t\t\tconst result = findNodeImplementation(assignmentValueNode)\n\t\t\timplementationCache.set(node, result)\n\t\t\treturn result\n\t\t}\n\t\tthrow new Error('No implementation nor definition available')\n\t}\n\n\timplementationCache.set(node, node)\n\treturn node\n}\n\nexport const findPropertyAssignmentValueNode = (\n\tnode:\n\t\t| PropertyAssignment\n\t\t| TypeReferenceNode\n\t\t| PropertySignature\n\t\t| PropertyAccessExpression\n\t\t| ShorthandPropertyAssignment,\n): Node => {\n\tconst identifierChildren = node.getChildrenOfKind(SyntaxKind.Identifier)\n\tif (identifierChildren.length === 2) {\n\t\treturn findNodeImplementation(identifierChildren[1])\n\t}\n\tconst lastMatchingChild = node.getChildren().reverse()\n\treturn lastMatchingChild.find(\n\t\t(child) =>\n\t\t\tchild.getKind() !== SyntaxKind.GreaterThanToken &&\n\t\t\tchild.getKind() !== SyntaxKind.CommaToken &&\n\t\t\tchild.getKind() !== SyntaxKind.SemicolonToken,\n\t)!\n}\n\nexport const getTypeReferenceShape = (node: TypeReferenceNode): ShapeOfType['shape'] => {\n\tconst firstChild = node.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\tif (firstChild.isKind(SyntaxKind.SyntaxList)) {\n\t\treturn getRecursiveNodeShape(firstChild.getFirstChild()!)\n\t} else {\n\t\treturn getRecursiveNodeShape(firstChild)\n\t}\n}\n\nexport const getRecursiveNodeShape = (nodeOrReference: Node): ShapeOfType['shape'] => {\n\tconst cached = nodeShapeCache.get(nodeOrReference)\n\tif (cached !== undefined) {\n\t\treturn cached\n\t}\n\tconst result = computeRecursiveNodeShape(nodeOrReference)\n\tnodeShapeCache.set(nodeOrReference, result)\n\treturn result\n}\n\nconst computeRecursiveNodeShape = (nodeOrReference: Node): ShapeOfType['shape'] => {\n\tconst typeName = nodeOrReference.getSymbol()?.getName()\n\tif (typeName && OpenApiManager.getInstance().hasExposedModel(typeName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'ref',\n\t\t\t\tshape: typeName,\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tconst node = findNodeImplementation(nodeOrReference)\n\n\t// Undefined\n\tconst undefinedNode = node.asKind(SyntaxKind.UndefinedKeyword)\n\tif (undefinedNode) {\n\t\treturn 'undefined'\n\t}\n\n\t// Literal type\n\tconst literalNode = node.asKind(SyntaxKind.LiteralType)\n\tif (literalNode) {\n\t\tif (literalNode.getFirstChildByKind(SyntaxKind.TrueKeyword)) {\n\t\t\treturn 'true'\n\t\t}\n\t\tif (literalNode.getFirstChildByKind(SyntaxKind.FalseKeyword)) {\n\t\t\treturn 'false'\n\t\t}\n\t}\n\n\t// Boolean literal\n\tconst booleanLiteralNode =\n\t\tnode.asKind(SyntaxKind.BooleanKeyword) ||\n\t\tnode.asKind(SyntaxKind.TrueKeyword) ||\n\t\tnode.asKind(SyntaxKind.FalseKeyword)\n\tif (booleanLiteralNode) {\n\t\treturn 'boolean'\n\t}\n\n\t// String literal\n\tconst stringLiteralNode = node.asKind(SyntaxKind.StringKeyword) || node.asKind(SyntaxKind.StringLiteral)\n\tif (stringLiteralNode) {\n\t\treturn 'string'\n\t}\n\n\t// Number literal\n\tconst numberLiteralNode = node.asKind(SyntaxKind.NumberKeyword) || node.asKind(SyntaxKind.NumericLiteral)\n\tif (numberLiteralNode) {\n\t\treturn 'number'\n\t}\n\n\t// BigInt literal\n\tconst bigIntNode = node.asKind(SyntaxKind.BigIntKeyword) || node.asKind(SyntaxKind.BigIntLiteral)\n\tif (bigIntNode) {\n\t\treturn 'bigint'\n\t}\n\n\t// Type literal\n\tconst typeLiteralNode = node.asKind(SyntaxKind.TypeLiteral)\n\tif (typeLiteralNode) {\n\t\tconst properties = typeLiteralNode\n\t\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t\t.getChildrenOfKind(SyntaxKind.PropertySignature)\n\n\t\tconst propertyShapes = properties.map((propNode) => {\n\t\t\tconst identifier = propNode.getFirstChildByKind(SyntaxKind.Identifier)!\n\t\t\tconst valueNode = findPropertyAssignmentValueNode(propNode)\n\t\t\tconst questionMarkToken = identifier.getNextSiblingIfKind(SyntaxKind.QuestionToken)\n\t\t\treturn {\n\t\t\t\trole: 'property' as const,\n\t\t\t\tidentifier: identifier.getText(),\n\t\t\t\tshape: getRecursiveNodeShape(valueNode),\n\t\t\t\toptional: valueNode.getType().isNullable() || !!questionMarkToken,\n\t\t\t}\n\t\t})\n\t\treturn propertyShapes\n\t}\n\n\t// Type reference\n\tconst typeReferenceNode = node.asKind(SyntaxKind.TypeReference)\n\tif (typeReferenceNode) {\n\t\treturn getRecursiveNodeShape(typeReferenceNode.getFirstChild()!)\n\t}\n\n\t// Property access expression\n\tconst propertyAccessNode = node.asKind(SyntaxKind.PropertyAccessExpression)\n\tif (propertyAccessNode) {\n\t\tconst lastChild = findNodeImplementation(node.getLastChild()!)\n\t\treturn getProperTypeShape(lastChild.asKind(SyntaxKind.CallExpression)!.getReturnType(), lastChild)\n\t}\n\n\t// Union type\n\tconst unionTypeNode = node.asKind(SyntaxKind.UnionType)\n\tif (unionTypeNode) {\n\t\treturn getProperTypeShape(unionTypeNode.getType(), node)\n\t}\n\n\t// Typeof query\n\tconst typeQueryNode = node.asKind(SyntaxKind.TypeQuery)\n\tif (typeQueryNode) {\n\t\treturn getRecursiveNodeShape(typeQueryNode.getLastChild()!)\n\t}\n\n\t// Qualified name\n\tconst qualifiedNameNode = node.asKind(SyntaxKind.QualifiedName)\n\tif (qualifiedNameNode) {\n\t\treturn getRecursiveNodeShape(qualifiedNameNode.getLastChild()!)\n\t}\n\n\t// Call expression\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\treturn getProperTypeShape(callExpressionNode.getReturnType(), callExpressionNode)\n\t}\n\n\t// Await expression\n\tconst awaitExpressionNode = node.asKind(SyntaxKind.AwaitExpression)\n\tif (awaitExpressionNode) {\n\t\treturn getRecursiveNodeShape(awaitExpressionNode.getChildAtIndex(1)!)\n\t}\n\n\t// 'As' Expression\n\tconst asExpressionNode = node.asKind(SyntaxKind.AsExpression)\n\tif (asExpressionNode) {\n\t\treturn getRecursiveNodeShape(asExpressionNode.getChildAtIndex(2)!)\n\t}\n\n\t// TODO\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown node type: ${node.getKindName()}`)\n\treturn 'unknown_1'\n}\n\nexport const getShapeOfValidatorLiteral = (\n\tobjectLiteralNode: Node<ts.ObjectLiteralExpression>,\n): (ShapeOfProperty & { description: string; errorMessage: string })[] => {\n\tconst syntaxListNode = objectLiteralNode.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\tconst properties = assignmentNodes.map((node) => {\n\t\tconst identifierNode = node.getFirstChild()!\n\t\tconst identifierName = (() => {\n\t\t\tif (identifierNode.isKind(SyntaxKind.Identifier)) {\n\t\t\t\treturn identifierNode.getText()\n\t\t\t}\n\t\t\tif (identifierNode.isKind(SyntaxKind.StringLiteral)) {\n\t\t\t\treturn identifierNode.getLiteralText()\n\t\t\t}\n\t\t\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\t\t\tLogger.warn(`[${fileName}] Unknown identifier name: ${identifierNode.getText()}`)\n\t\t\treturn 'unknown_30'\n\t\t})()\n\n\t\tconst assignmentValueNode = node.getLastChild()!\n\t\tconst innerLiteralNode = findNodeImplementation(assignmentValueNode)\n\n\t\treturn {\n\t\t\trole: 'property' as const,\n\t\t\tidentifier: identifierName,\n\t\t\tshape: getValidatorPropertyShape(innerLiteralNode),\n\t\t\toptional: getValidatorPropertyOptionality(innerLiteralNode),\n\t\t\tdescription: getValidatorPropertyStringValue(innerLiteralNode, 'description'),\n\t\t\terrorMessage: getValidatorPropertyStringValue(innerLiteralNode, 'errorMessage'),\n\t\t}\n\t})\n\n\treturn properties || []\n}\n\nconst isZodCallExpression = (node: Node): boolean => {\n\tconst callExpression = node.asKind(SyntaxKind.CallExpression)\n\tif (!callExpression) {\n\t\treturn false\n\t}\n\tconst returnType = callExpression.getReturnType()\n\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\treturn typeName.startsWith('Zod')\n}\n\nconst getZodCallShape = (node: Node): ShapeOfType['shape'] => {\n\tconst callExpression = node.asKind(SyntaxKind.CallExpression)!\n\tconst returnType = callExpression.getReturnType()\n\tconst outputProp = returnType.getProperty('_output')\n\tif (outputProp) {\n\t\treturn getProperTypeShape(outputProp.getTypeAtLocation(callExpression), callExpression)\n\t}\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\tLogger.warn(`[${fileName}] Unknown zod type: ${typeName}`)\n\treturn 'unknown_zod'\n}\n\nexport const getValidatorPropertyShape = (innerLiteralNode: Node): ShapeOfType['shape'] => {\n\t// Zod validator (e.g. z.number(), z.string(), z.object({...}), z.array(...))\n\tif (isZodCallExpression(innerLiteralNode)) {\n\t\treturn getZodCallShape(innerLiteralNode)\n\t}\n\n\t// Inline definition with `as Validator<...>` clause\n\tconst inlineValidatorAsExpression = innerLiteralNode\n\t\t.getParent()!\n\t\t.getFirstChildByKind(SyntaxKind.AsExpression)\n\tif (inlineValidatorAsExpression) {\n\t\tconst typeReference = inlineValidatorAsExpression.getLastChildByKind(SyntaxKind.TypeReference)!\n\t\treturn getTypeReferenceShape(typeReference)\n\t}\n\n\t// Variable with `: Validator<...>` clause\n\tconst childTypeReferenceNode = innerLiteralNode.getParent()!.getFirstChildByKind(SyntaxKind.TypeReference)\n\tif (childTypeReferenceNode) {\n\t\treturn getTypeReferenceShape(childTypeReferenceNode)\n\t}\n\n\t// `RequiredParam<...>` inline call expression\n\tif (innerLiteralNode.getParent()!.getChildrenOfKind(SyntaxKind.SyntaxList).length >= 2) {\n\t\tconst typeNode = innerLiteralNode\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t\t.getFirstChild()!\n\t\treturn getRecursiveNodeShape(typeNode)\n\t}\n\n\t// `RequestParam | RequiredParam | OptionalParam` call expression\n\tconst childCallExpressionNode = innerLiteralNode.getParent()!.getFirstChildByKind(SyntaxKind.CallExpression)\n\tif (childCallExpressionNode) {\n\t\tconst callExpressionArgument = findNodeImplementation(\n\t\t\tchildCallExpressionNode.getFirstChildByKind(SyntaxKind.SyntaxList)!.getFirstChild()!,\n\t\t)\n\n\t\t// Param is a type reference\n\t\tconst typeReferenceNode = callExpressionArgument\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.TypeReference)!\n\t\tif (typeReferenceNode) {\n\t\t\treturn getProperTypeShape(typeReferenceNode.getType(), typeReferenceNode, [])\n\t\t}\n\n\t\tconst thingyNode = callExpressionArgument\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.ObjectLiteralExpression)!\n\t\tif (thingyNode) {\n\t\t\treturn getValidatorPropertyShape(thingyNode)\n\t\t}\n\n\t\tif (callExpressionArgument.getKind() === SyntaxKind.CallExpression) {\n\t\t\treturn getValidatorPropertyShape(callExpressionArgument)\n\t\t}\n\n\t\tif (callExpressionArgument.getKind() === SyntaxKind.IntersectionType) {\n\t\t\treturn getValidatorPropertyShape(callExpressionArgument)\n\t\t}\n\n\t\tconst fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop()\n\t\tLogger.warn(`[${fileName}] Unknown call expression argument: ${callExpressionArgument.getKindName()}`)\n\t\treturn 'unknown_3'\n\t}\n\n\t// Attempting to infer type from `parse` function\n\tconst innerNodePropertyAssignments = innerLiteralNode\n\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t.getChildrenOfKind(SyntaxKind.PropertyAssignment)\n\tconst parsePropertyAssignment = innerNodePropertyAssignments.find((prop) => {\n\t\treturn prop.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'parse'\n\t})\n\tif (parsePropertyAssignment) {\n\t\tconst returnType = findPropertyAssignmentValueNode(parsePropertyAssignment)\n\t\t\t.asKind(SyntaxKind.ArrowFunction)!\n\t\t\t.getReturnType()\n\t\treturn getProperTypeShape(returnType, parsePropertyAssignment)\n\t}\n\n\t// Import statement\n\tconst importTypeNode = innerLiteralNode\n\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)\n\t\t?.getFirstChildByKind(SyntaxKind.ImportType)\n\tif (importTypeNode) {\n\t\tconst indexOfGreaterThanToken = importTypeNode\n\t\t\t.getLastChildByKind(SyntaxKind.GreaterThanToken)!\n\t\t\t.getChildIndex()\n\t\tconst targetSyntaxList = importTypeNode.getChildAtIndex(indexOfGreaterThanToken - 1)\n\t\treturn getRecursiveNodeShape(targetSyntaxList.getFirstChild()!)\n\t}\n\n\t// Intersection type with Validator\n\tconst intersectionType = innerLiteralNode.isKind(SyntaxKind.IntersectionType)\n\t\t? innerLiteralNode\n\t\t: innerLiteralNode.getParent()?.isKind(SyntaxKind.VariableDeclaration)\n\t\t\t? innerLiteralNode.getParent()?.getFirstChildByKind(SyntaxKind.IntersectionType)\n\t\t\t: null\n\n\tif (intersectionType) {\n\t\tconst validatorType = intersectionType.getFirstChildByKind(SyntaxKind.TypeReference)\n\t\tif (validatorType) {\n\t\t\treturn getTypeReferenceShape(validatorType)\n\t\t}\n\t}\n\n\tconst fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown import type node`)\n\n\treturn 'unknown_2'\n}\n\nexport const getValidatorPropertyOptionality = (node: Node): boolean => {\n\tif (isZodCallExpression(node)) {\n\t\tconst callExpression = node.asKind(SyntaxKind.CallExpression)!\n\t\tconst returnType = callExpression.getReturnType()\n\t\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\t\tif (typeName === 'ZodOptional') {\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\tconst identifierNode = callExpressionNode.getFirstChildByKind(SyntaxKind.Identifier)\n\t\tif (identifierNode?.getText() === 'OptionalParam') {\n\t\t\treturn true\n\t\t} else if (identifierNode?.getText() === 'RequiredParam') {\n\t\t\treturn false\n\t\t}\n\n\t\tconst syntaxListNode = callExpressionNode.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\tconst literalExpression = findNodeImplementation(syntaxListNode.getFirstChild()!)\n\t\treturn getValidatorPropertyOptionality(literalExpression)\n\t}\n\n\tconst syntaxListNode = node.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\treturn assignmentNodes.some((node) => {\n\t\tconst identifierNode = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tconst identifierName = identifierNode.getText()\n\n\t\tif (identifierName === 'optional') {\n\t\t\tconst value = findPropertyAssignmentValueNode(node)\n\t\t\treturn value.getKind() === SyntaxKind.TrueKeyword\n\t\t}\n\t\treturn false\n\t})\n}\n\nexport const getValidatorPropertyStringValue = (\n\tnodeOrReference: Node,\n\tname: 'description' | 'errorMessage',\n): string => {\n\tif (isZodCallExpression(nodeOrReference)) {\n\t\treturn ''\n\t}\n\n\tconst node = findNodeImplementation(nodeOrReference)\n\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\tconst targetChild = callExpressionNode.getLastChildByKind(SyntaxKind.SyntaxList)!\n\t\treturn getValidatorPropertyStringValue(targetChild, name)\n\t}\n\n\tconst syntaxListNode = node.asKind(SyntaxKind.SyntaxList)\n\tif (syntaxListNode) {\n\t\tconst children = syntaxListNode.getChildren().map((c) => getValidatorPropertyStringValue(c, name))\n\t\treturn children.find((value) => !!value && value !== 'unknown_25') || ''\n\t}\n\n\tconst objectLiteralNode = node.asKind(SyntaxKind.ObjectLiteralExpression)\n\tif (objectLiteralNode) {\n\t\tconst values = getValuesOfObjectLiteral(objectLiteralNode)\n\t\tconst targetValue = values.find((value) => value.identifier === name)\n\t\tif (!targetValue) {\n\t\t\treturn ''\n\t\t}\n\t\tif (Array.isArray(targetValue.value)) {\n\t\t\treturn 'array'\n\t\t}\n\t\treturn targetValue.value || ''\n\t}\n\n\tconst intersectionTypeNode = node.asKind(SyntaxKind.IntersectionType)\n\tif (intersectionTypeNode) {\n\t\treturn (\n\t\t\tintersectionTypeNode\n\t\t\t\t.getTypeNodes()\n\t\t\t\t.flatMap((t) => getValidatorPropertyStringValue(t, name))\n\t\t\t\t.filter((v) => !!v && v !== 'unknown_25')[0] || 'unknown_27'\n\t\t)\n\t}\n\n\tconst typeLiteralNode = node.asKind(SyntaxKind.TypeLiteral)\n\tif (typeLiteralNode) {\n\t\treturn getValidatorPropertyStringValue(typeLiteralNode.getFirstChildByKind(SyntaxKind.SyntaxList)!, name)\n\t}\n\n\tconst propertySignatureNode = node.asKind(SyntaxKind.PropertySignature)\n\tif (propertySignatureNode) {\n\t\tconst identifier = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tif (identifier.getText() === name) {\n\t\t\tconst targetNode = findPropertyAssignmentValueNode(propertySignatureNode).getFirstDescendantByKind(\n\t\t\t\tSyntaxKind.StringLiteral,\n\t\t\t)!\n\t\t\treturn targetNode.getLiteralText()\n\t\t}\n\t}\n\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.dev(`[${fileName}] Unknown property string value node ${node.getKindName()}`)\n\treturn 'unknown_25'\n}\n\nconst isPromise = (type: Type) => {\n\tconst symbol = type.getSymbol()\n\tif (!type.isObject() || !symbol) {\n\t\treturn false\n\t}\n\tconst args = type.getTypeArguments()\n\treturn symbol.getName() === 'Promise' && args.length === 1\n}\n\nexport const getProperTypeShape = (\n\ttypeOrPromise: Type,\n\tatLocation: Node,\n\tstack: Type[] = [],\n): ShapeOfType['shape'] => {\n\tconst typeName = typeOrPromise.getAliasSymbol()?.getName()\n\tif (typeName && OpenApiManager.getInstance().hasExposedModel(typeName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'ref',\n\t\t\t\tshape: typeName,\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tconst type = isPromise(typeOrPromise) ? typeOrPromise.getTypeArguments()[0] : typeOrPromise\n\n\tif (stack.some((previousType) => previousType === type)) {\n\t\treturn 'circular'\n\t}\n\n\tconst cacheKey = type.compilerType\n\tconst cached = typeShapeCache.get(cacheKey)\n\tif (cached !== undefined) {\n\t\treturn cached\n\t}\n\tconst result = computeProperTypeShape(type, atLocation, stack)\n\ttypeShapeCache.set(cacheKey, result)\n\treturn result\n}\n\nconst computeProperTypeShape = (type: Type, atLocation: Node, stack: Type[]): ShapeOfType['shape'] => {\n\tconst nextStack = stack.concat(type)\n\n\tif (type.getText() === 'void') {\n\t\treturn 'void'\n\t}\n\n\tif (type.isAny()) {\n\t\treturn 'any'\n\t}\n\n\tif (type.isUnknown()) {\n\t\treturn 'unknown'\n\t}\n\n\tif (type.isNull()) {\n\t\treturn 'null'\n\t}\n\n\tif (type.isUndefined()) {\n\t\treturn 'undefined'\n\t}\n\n\tif (type.isBoolean() || type.isBooleanLiteral()) {\n\t\treturn 'boolean'\n\t}\n\n\tif (type.isStringLiteral()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'literal_string' as const,\n\t\t\t\tshape: String(type.getLiteralValue()!),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isNumberLiteral()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'literal_number' as const,\n\t\t\t\tshape: String(type.getLiteralValue()!),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isString() || type.isTemplateLiteral()) {\n\t\treturn 'string'\n\t}\n\n\tif (type.isNumber()) {\n\t\treturn 'number'\n\t}\n\n\tif (type.getText() === 'bigint') {\n\t\treturn 'bigint'\n\t}\n\n\tif (type.isTuple()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'tuple' as const,\n\t\t\t\tshape: type.getTupleElements().map((t) => ({\n\t\t\t\t\trole: 'tuple_entry' as const,\n\t\t\t\t\tshape: getProperTypeShape(t, atLocation, nextStack),\n\t\t\t\t\toptional: false,\n\t\t\t\t})),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isArray()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'array' as const,\n\t\t\t\tshape: getProperTypeShape(type.getArrayElementType()!, atLocation, nextStack),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\t// Handles `interface Foo extends Array<T>` (e.g. Prisma's JsonArray)\n\t// which fails type.isArray() but is still array-like\n\tif (type.isObject()) {\n\t\tconst arrayElementType = type.getNumberIndexType()\n\t\tconst baseTypes = type.getBaseTypes()\n\t\tconst arrayBase = baseTypes?.find((base) => base.isArray())\n\t\tif (arrayBase) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\trole: 'array' as const,\n\t\t\t\t\tshape: getProperTypeShape(\n\t\t\t\t\t\tarrayBase.getArrayElementType() ?? arrayElementType!,\n\t\t\t\t\t\tatLocation,\n\t\t\t\t\t\tnextStack,\n\t\t\t\t\t),\n\t\t\t\t\toptional: false,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t}\n\n\tconst typeSymbolName = type.getSymbol()?.getName()\n\n\tconst bufferLikeTypes = new Set([\n\t\t'Buffer',\n\t\t'Uint8Array',\n\t\t'Int8Array',\n\t\t'Uint8ClampedArray',\n\t\t'Int16Array',\n\t\t'Uint16Array',\n\t\t'Int32Array',\n\t\t'Uint32Array',\n\t\t'Float32Array',\n\t\t'Float64Array',\n\t\t'BigInt64Array',\n\t\t'BigUint64Array',\n\t\t'ArrayBuffer',\n\t\t'SharedArrayBuffer',\n\t\t'ReadableStream',\n\t])\n\n\tif (type.isObject() && typeSymbolName && bufferLikeTypes.has(typeSymbolName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'buffer' as const,\n\t\t\t\tshape: 'buffer',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'RegExp') {\n\t\treturn 'string'\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'Map') {\n\t\tconst typeArgs = type.getTypeArguments()\n\t\tconst valueType = typeArgs[1]\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'record' as const,\n\t\t\t\tshape: valueType ? getProperTypeShape(valueType, atLocation, nextStack) : 'unknown',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'Set') {\n\t\tconst typeArgs = type.getTypeArguments()\n\t\tconst elementType = typeArgs[0]\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'array' as const,\n\t\t\t\tshape: elementType ? getProperTypeShape(elementType, atLocation, nextStack) : 'unknown',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && type.getProperties().length === 0) {\n\t\tconst targetType = type.getAliasTypeArguments()[1] ?? type.getStringIndexType()\n\t\tif (targetType) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\trole: 'record' as const,\n\t\t\t\t\tshape: getProperTypeShape(targetType, atLocation, nextStack),\n\t\t\t\t\toptional: false,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t}\n\n\tif (type.isObject()) {\n\t\tif (typeSymbolName === 'Date' || type.getText() === 'Date') {\n\t\t\treturn 'Date'\n\t\t}\n\t\treturn type\n\t\t\t.getProperties()\n\t\t\t.map((prop) => {\n\t\t\t\tconst valueDeclaration = prop.getValueDeclaration() || prop.getDeclarations()[0]!\n\t\t\t\tconst shape = getProperTypeShape(prop.getTypeAtLocation(atLocation), atLocation, nextStack)\n\t\t\t\tif (!valueDeclaration) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\t\tshape,\n\t\t\t\t\t\toptional: false,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst valueDeclarationNode =\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.PropertySignature) ||\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.PropertyAssignment) ||\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.ShorthandPropertyAssignment)\n\n\t\t\t\tif (!valueDeclarationNode) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\t\tshape,\n\t\t\t\t\t\toptional: false,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst isOptional = prop.getTypeAtLocation(atLocation).isNullable()\n\n\t\t\t\treturn {\n\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\tshape,\n\t\t\t\t\toptional: isOptional,\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter((val) => val.shape !== 'undefined')\n\t}\n\n\tif (type.isUnion()) {\n\t\tconst unfilteredShapes: ShapeOfUnionEntry[] = type.getUnionTypes().map((type) => ({\n\t\t\trole: 'union_entry',\n\t\t\tshape: getProperTypeShape(type, atLocation, nextStack),\n\t\t\toptional: false,\n\t\t}))\n\n\t\tconst dedupedShapes = unfilteredShapes.filter(\n\t\t\t(type, index, arr) => !arr.find((dup, dupIndex) => dup.shape === type.shape && dupIndex > index),\n\t\t)\n\t\tconst isNullable = dedupedShapes.some((shape) => shape.shape === 'undefined')\n\t\tconst shapes = dedupedShapes.filter((shape) => shape.shape !== 'undefined')\n\t\tif (shapes.length === 1) {\n\t\t\treturn shapes[0].shape\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'union',\n\t\t\t\tshape: shapes,\n\t\t\t\toptional: isNullable,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isIntersection()) {\n\t\tconst children = type.getIntersectionTypes()\n\t\tconst shapesOfChildren = children\n\t\t\t.map((child) => getProperTypeShape(child, atLocation, nextStack))\n\t\t\t.filter((shape) => typeof shape !== 'string') as ShapeOfProperty[][]\n\t\treturn shapesOfChildren.reduce<ShapeOfType[]>((total, current) => [...total, ...current], [])\n\t}\n\n\tconst fileName = atLocation.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown type shape node ${type.getText()}`)\n\treturn 'unknown_5'\n}\n\nconst getLiteralValueOfNode = (node: Node): string | string[] | unknown[] => {\n\tif (node.isKind(SyntaxKind.Identifier)) {\n\t\treturn getLiteralValueOfNode(findNodeImplementation(node))\n\t} else if (node.isKind(SyntaxKind.StringLiteral)) {\n\t\treturn node.getLiteralValue()\n\t} else if (node.isKind(SyntaxKind.ArrayLiteralExpression)) {\n\t\treturn node.forEachChildAsArray().map((child) => getLiteralValueOfNode(child)) as string[]\n\t} else if (node.isKind(SyntaxKind.PropertyAccessExpression)) {\n\t\treturn getLiteralValueOfNode(findPropertyAssignmentValueNode(node))\n\t} else if (node.isKind(SyntaxKind.ObjectLiteralExpression)) {\n\t\treturn getValuesOfObjectLiteral(node)\n\t}\n\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.dev(`[${fileName}] Unknown literal value node ${node.getKindName()}`)\n\n\treturn 'unknown_6'\n}\n\nexport const resolveEndpointPath = (node: Node): string | null => {\n\tconst callExpression = node.getFirstDescendantByKind(SyntaxKind.CallExpression)\n\tif (!callExpression) return null\n\n\tconst firstArg = callExpression.getArguments()[0]\n\tif (!firstArg) return null\n\n\tconst argType = firstArg.getType()\n\tif (argType.isStringLiteral()) {\n\t\treturn argType.getLiteralValue() as string\n\t}\n\n\treturn null\n}\n\nexport const getValuesOfObjectLiteral = (objectLiteralNode: Node<ts.ObjectLiteralExpression>) => {\n\tconst syntaxListNode = objectLiteralNode.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\tconst properties = assignmentNodes.map((node) => {\n\t\tconst identifierNode = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tconst identifierName = identifierNode.getText()\n\n\t\tconst assignmentValueNode = node.getLastChild()!\n\t\tconst targetNode = findNodeImplementation(assignmentValueNode)\n\t\tconst value = getLiteralValueOfNode(targetNode)\n\n\t\treturn {\n\t\t\tidentifier: identifierName,\n\t\t\tvalue,\n\t\t}\n\t})\n\n\treturn properties || []\n}\n"],"names":["implementationCache","nodeShapeCache","typeShapeCache","findNodeImplementation","node","cached","SyntaxKind","implementationNode","assignmentValueNode","result","definitionNode","findPropertyAssignmentValueNode","identifierChildren","child","getTypeReferenceShape","firstChild","getRecursiveNodeShape","nodeOrReference","computeRecursiveNodeShape","typeName","OpenApiManager","literalNode","typeLiteralNode","propNode","identifier","valueNode","questionMarkToken","typeReferenceNode","lastChild","getProperTypeShape","unionTypeNode","typeQueryNode","qualifiedNameNode","callExpressionNode","awaitExpressionNode","asExpressionNode","fileName","Logger","getShapeOfValidatorLiteral","objectLiteralNode","identifierNode","identifierName","innerLiteralNode","getValidatorPropertyShape","getValidatorPropertyOptionality","getValidatorPropertyStringValue","isZodCallExpression","callExpression","getZodCallShape","returnType","outputProp","inlineValidatorAsExpression","typeReference","childTypeReferenceNode","typeNode","childCallExpressionNode","callExpressionArgument","thingyNode","parsePropertyAssignment","prop","importTypeNode","indexOfGreaterThanToken","targetSyntaxList","intersectionType","validatorType","syntaxListNode","literalExpression","name","targetChild","c","value","targetValue","getValuesOfObjectLiteral","intersectionTypeNode","t","v","propertySignatureNode","isPromise","type","symbol","args","typeOrPromise","atLocation","stack","previousType","cacheKey","computeProperTypeShape","nextStack","arrayElementType","arrayBase","base","typeSymbolName","bufferLikeTypes","valueType","elementType","targetType","valueDeclaration","shape","isOptional","val","dedupedShapes","index","arr","dup","dupIndex","isNullable","shapes","total","current","getLiteralValueOfNode","resolveEndpointPath","firstArg","argType","targetNode"],"mappings":";;;AAgBA,MAAMA,wBAA0B,QAAoB,GAC9CC,wBAAqB,QAAoC,GACzDC,wBAAqB,QAAsC,GAEpDC,IAAyB,CAACC,MAAqB;AACrD,QAAAC,IAASL,EAAoB,IAAII,CAAI;AAC3C,MAAIC;AACI,WAAAA;AAGR,MAAID,EAAK,cAAcE,EAAW,YAAY;AACvC,UAAAC,IAAqBH,EAAK,OAAOE,EAAW,UAAU,EAAG,mBAAmB,EAAE,CAAC,GAAG,QAAQ;AAChG,QAAIC,GAAoB;AAEjB,YAAAC,IAD2BD,EAAmB,UAAU,EACT,aAAa;AAClE,UAAIC,MAAwBJ;AACrB,cAAA,IAAI,MAAM,gCAAgC;AAE3C,YAAAK,IAASN,EAAuBK,CAAmB;AACrC,aAAAR,EAAA,IAAII,GAAMK,CAAM,GAC7BA;AAAA,IAAA;AAGF,UAAAC,IAAiBN,EAAK,OAAOE,EAAW,UAAU,EAAG,eAAe,EAAE,CAAC,GAAG,QAAQ;AACxF,QAAII,GAAgB;AAEb,YAAAF,IADuBE,EAAe,UAAU,EACL,aAAa;AAC9D,UAAIF,MAAwBJ;AACrB,cAAA,IAAI,MAAM,gCAAgC;AAE3C,YAAAK,IAASN,EAAuBK,CAAmB;AACrC,aAAAR,EAAA,IAAII,GAAMK,CAAM,GAC7BA;AAAA,IAAA;AAEF,UAAA,IAAI,MAAM,4CAA4C;AAAA,EAAA;AAGzC,SAAAT,EAAA,IAAII,GAAMA,CAAI,GAC3BA;AACR,GAEaO,IAAkC,CAC9CP,MAMU;AACV,QAAMQ,IAAqBR,EAAK,kBAAkBE,EAAW,UAAU;AACnE,SAAAM,EAAmB,WAAW,IAC1BT,EAAuBS,EAAmB,CAAC,CAAC,IAE1BR,EAAK,YAAY,EAAE,QAAQ,EAC5B;AAAA,IACxB,CAACS,MACAA,EAAM,QAAA,MAAcP,EAAW,oBAC/BO,EAAM,c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AAQ;AAC7B,SAAAC,EAAQ,oBACJA,EAAQ,gBAAgB,IAGzB;AACR,GAEaxC,IAA2B,CAACjC,MACjBA,EAAkB,yBAAyBjC,EAAW,UAAU,EAChD,kBAAkBA,EAAW,kBAAkB,EAEnD,IAAI,CAACF,MAAS;AAE1C,QAAAqC,IADiBrC,EAAK,yBAAyBE,EAAW,UAAU,EACpC,QAAQ,GAExCE,IAAsBJ,EAAK,aAAa,GACxC6G,IAAa9G,EAAuBK,CAAmB,GACvD8D,IAAQuC,EAAsBI,CAAU;AAEvC,SAAA;AAAA,IACN,YAAYxE;AAAA,IACZ,OAAA6B;AAAA,EACD;AAAA,CACA,KAEoB,CAAC;"}
1
+ {"version":3,"file":"nodeParsers.mjs","sources":["../../../src/openapi/analyzerModule/nodeParsers.ts"],"sourcesContent":["import {\n\tNode,\n\tPropertyAccessExpression,\n\tPropertyAssignment,\n\tPropertySignature,\n\tShorthandPropertyAssignment,\n\tSyntaxKind,\n\tts,\n\tType,\n\tTypeReferenceNode,\n} from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { OpenApiManager } from '../manager/OpenApiManager'\nimport { ShapeOfProperty, ShapeOfType, ShapeOfUnionEntry } from './types'\n\nconst implementationCache = new WeakMap<Node, Node>()\nconst nodeShapeCache = new WeakMap<Node, ShapeOfType['shape']>()\nconst typeShapeCache = new WeakMap<object, ShapeOfType['shape']>()\n\nconst implementationBySymbolCache = new WeakMap<ts.Symbol, Node>()\n\nconst getCanonicalSymbol = (node: Node): ts.Symbol | undefined => {\n\tconst symbol = node.getSymbol()\n\tif (!symbol) {\n\t\treturn undefined\n\t}\n\treturn (symbol.getAliasedSymbol() ?? symbol).compilerSymbol\n}\n\nexport const findNodeImplementation = (node: Node): Node => {\n\tconst cached = implementationCache.get(node)\n\tif (cached) {\n\t\treturn cached\n\t}\n\n\tif (node.getKind() === SyntaxKind.Identifier) {\n\t\tconst symbol = getCanonicalSymbol(node)\n\t\tif (symbol) {\n\t\t\tconst cachedBySymbol = implementationBySymbolCache.get(symbol)\n\t\t\tif (cachedBySymbol) {\n\t\t\t\timplementationCache.set(node, cachedBySymbol)\n\t\t\t\treturn cachedBySymbol\n\t\t\t}\n\t\t}\n\n\t\tconst resolve = (): Node => {\n\t\t\tconst implementationNode = node.asKind(SyntaxKind.Identifier)!.getImplementations()[0]?.getNode()\n\t\t\tif (implementationNode) {\n\t\t\t\tconst implementationParentNode = implementationNode.getParent()!\n\t\t\t\tconst assignmentValueNode = implementationParentNode.getLastChild()!\n\t\t\t\tif (assignmentValueNode === node) {\n\t\t\t\t\tthrow new Error('Recursive implementation found')\n\t\t\t\t}\n\t\t\t\treturn findNodeImplementation(assignmentValueNode)\n\t\t\t}\n\n\t\t\tconst definitionNode = node.asKind(SyntaxKind.Identifier)!.getDefinitions()[0]?.getNode()\n\t\t\tif (definitionNode) {\n\t\t\t\tconst definitionParentNode = definitionNode.getParent()!\n\t\t\t\tconst assignmentValueNode = definitionParentNode.getLastChild()!\n\t\t\t\tif (assignmentValueNode === node) {\n\t\t\t\t\tthrow new Error('Recursive implementation found')\n\t\t\t\t}\n\t\t\t\treturn findNodeImplementation(assignmentValueNode)\n\t\t\t}\n\t\t\tthrow new Error('No implementation nor definition available')\n\t\t}\n\n\t\tconst result = resolve()\n\t\tif (symbol) {\n\t\t\timplementationBySymbolCache.set(symbol, result)\n\t\t}\n\t\timplementationCache.set(node, result)\n\t\treturn result\n\t}\n\n\timplementationCache.set(node, node)\n\treturn node\n}\n\nexport const findPropertyAssignmentValueNode = (\n\tnode:\n\t\t| PropertyAssignment\n\t\t| TypeReferenceNode\n\t\t| PropertySignature\n\t\t| PropertyAccessExpression\n\t\t| ShorthandPropertyAssignment,\n): Node => {\n\tconst identifierChildren = node.getChildrenOfKind(SyntaxKind.Identifier)\n\tif (identifierChildren.length === 2) {\n\t\treturn findNodeImplementation(identifierChildren[1])\n\t}\n\tconst lastMatchingChild = node.getChildren().reverse()\n\treturn lastMatchingChild.find(\n\t\t(child) =>\n\t\t\tchild.getKind() !== SyntaxKind.GreaterThanToken &&\n\t\t\tchild.getKind() !== SyntaxKind.CommaToken &&\n\t\t\tchild.getKind() !== SyntaxKind.SemicolonToken,\n\t)!\n}\n\nexport const getTypeReferenceShape = (node: TypeReferenceNode): ShapeOfType['shape'] => {\n\tconst firstChild = node.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\tif (firstChild.isKind(SyntaxKind.SyntaxList)) {\n\t\treturn getRecursiveNodeShape(firstChild.getFirstChild()!)\n\t} else {\n\t\treturn getRecursiveNodeShape(firstChild)\n\t}\n}\n\nexport const getRecursiveNodeShape = (nodeOrReference: Node): ShapeOfType['shape'] => {\n\tconst cached = nodeShapeCache.get(nodeOrReference)\n\tif (cached !== undefined) {\n\t\treturn cached\n\t}\n\tconst result = computeRecursiveNodeShape(nodeOrReference)\n\tnodeShapeCache.set(nodeOrReference, result)\n\treturn result\n}\n\nconst computeRecursiveNodeShape = (nodeOrReference: Node): ShapeOfType['shape'] => {\n\tconst typeName = nodeOrReference.getSymbol()?.getName()\n\tif (typeName && OpenApiManager.getInstance().hasExposedModel(typeName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'ref',\n\t\t\t\tshape: typeName,\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tconst node = findNodeImplementation(nodeOrReference)\n\n\t// Undefined\n\tconst undefinedNode = node.asKind(SyntaxKind.UndefinedKeyword)\n\tif (undefinedNode) {\n\t\treturn 'undefined'\n\t}\n\n\t// Literal type\n\tconst literalNode = node.asKind(SyntaxKind.LiteralType)\n\tif (literalNode) {\n\t\tif (literalNode.getFirstChildByKind(SyntaxKind.TrueKeyword)) {\n\t\t\treturn 'true'\n\t\t}\n\t\tif (literalNode.getFirstChildByKind(SyntaxKind.FalseKeyword)) {\n\t\t\treturn 'false'\n\t\t}\n\t}\n\n\t// Boolean literal\n\tconst booleanLiteralNode =\n\t\tnode.asKind(SyntaxKind.BooleanKeyword) ||\n\t\tnode.asKind(SyntaxKind.TrueKeyword) ||\n\t\tnode.asKind(SyntaxKind.FalseKeyword)\n\tif (booleanLiteralNode) {\n\t\treturn 'boolean'\n\t}\n\n\t// String literal\n\tconst stringLiteralNode = node.asKind(SyntaxKind.StringKeyword) || node.asKind(SyntaxKind.StringLiteral)\n\tif (stringLiteralNode) {\n\t\treturn 'string'\n\t}\n\n\t// Number literal\n\tconst numberLiteralNode = node.asKind(SyntaxKind.NumberKeyword) || node.asKind(SyntaxKind.NumericLiteral)\n\tif (numberLiteralNode) {\n\t\treturn 'number'\n\t}\n\n\t// BigInt literal\n\tconst bigIntNode = node.asKind(SyntaxKind.BigIntKeyword) || node.asKind(SyntaxKind.BigIntLiteral)\n\tif (bigIntNode) {\n\t\treturn 'bigint'\n\t}\n\n\t// Type literal\n\tconst typeLiteralNode = node.asKind(SyntaxKind.TypeLiteral)\n\tif (typeLiteralNode) {\n\t\tconst properties = typeLiteralNode\n\t\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t\t.getChildrenOfKind(SyntaxKind.PropertySignature)\n\n\t\tconst propertyShapes = properties.map((propNode) => {\n\t\t\tconst identifier = propNode.getFirstChildByKind(SyntaxKind.Identifier)!\n\t\t\tconst valueNode = findPropertyAssignmentValueNode(propNode)\n\t\t\tconst questionMarkToken = identifier.getNextSiblingIfKind(SyntaxKind.QuestionToken)\n\t\t\treturn {\n\t\t\t\trole: 'property' as const,\n\t\t\t\tidentifier: identifier.getText(),\n\t\t\t\tshape: getRecursiveNodeShape(valueNode),\n\t\t\t\toptional: valueNode.getType().isNullable() || !!questionMarkToken,\n\t\t\t}\n\t\t})\n\t\treturn propertyShapes\n\t}\n\n\t// Type reference\n\tconst typeReferenceNode = node.asKind(SyntaxKind.TypeReference)\n\tif (typeReferenceNode) {\n\t\treturn getRecursiveNodeShape(typeReferenceNode.getFirstChild()!)\n\t}\n\n\t// Property access expression\n\tconst propertyAccessNode = node.asKind(SyntaxKind.PropertyAccessExpression)\n\tif (propertyAccessNode) {\n\t\tconst lastChild = findNodeImplementation(node.getLastChild()!)\n\t\treturn getProperTypeShape(lastChild.asKind(SyntaxKind.CallExpression)!.getReturnType(), lastChild)\n\t}\n\n\t// Union type\n\tconst unionTypeNode = node.asKind(SyntaxKind.UnionType)\n\tif (unionTypeNode) {\n\t\treturn getProperTypeShape(unionTypeNode.getType(), node)\n\t}\n\n\t// Typeof query\n\tconst typeQueryNode = node.asKind(SyntaxKind.TypeQuery)\n\tif (typeQueryNode) {\n\t\treturn getRecursiveNodeShape(typeQueryNode.getLastChild()!)\n\t}\n\n\t// Qualified name\n\tconst qualifiedNameNode = node.asKind(SyntaxKind.QualifiedName)\n\tif (qualifiedNameNode) {\n\t\treturn getRecursiveNodeShape(qualifiedNameNode.getLastChild()!)\n\t}\n\n\t// Call expression\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\treturn getProperTypeShape(callExpressionNode.getReturnType(), callExpressionNode)\n\t}\n\n\t// Await expression\n\tconst awaitExpressionNode = node.asKind(SyntaxKind.AwaitExpression)\n\tif (awaitExpressionNode) {\n\t\treturn getRecursiveNodeShape(awaitExpressionNode.getChildAtIndex(1)!)\n\t}\n\n\t// 'As' Expression\n\tconst asExpressionNode = node.asKind(SyntaxKind.AsExpression)\n\tif (asExpressionNode) {\n\t\treturn getRecursiveNodeShape(asExpressionNode.getChildAtIndex(2)!)\n\t}\n\n\t// TODO\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown node type: ${node.getKindName()}`)\n\treturn 'unknown_1'\n}\n\nexport const getShapeOfValidatorLiteral = (\n\tobjectLiteralNode: Node<ts.ObjectLiteralExpression>,\n): (ShapeOfProperty & { description: string; errorMessage: string })[] => {\n\tconst syntaxListNode = objectLiteralNode.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\tconst properties = assignmentNodes.map((node) => {\n\t\tconst identifierNode = node.getFirstChild()!\n\t\tconst identifierName = (() => {\n\t\t\tif (identifierNode.isKind(SyntaxKind.Identifier)) {\n\t\t\t\treturn identifierNode.getText()\n\t\t\t}\n\t\t\tif (identifierNode.isKind(SyntaxKind.StringLiteral)) {\n\t\t\t\treturn identifierNode.getLiteralText()\n\t\t\t}\n\t\t\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\t\t\tLogger.warn(`[${fileName}] Unknown identifier name: ${identifierNode.getText()}`)\n\t\t\treturn 'unknown_30'\n\t\t})()\n\n\t\tconst assignmentValueNode = node.getLastChild()!\n\t\tconst innerLiteralNode = findNodeImplementation(assignmentValueNode)\n\n\t\treturn {\n\t\t\trole: 'property' as const,\n\t\t\tidentifier: identifierName,\n\t\t\tshape: getValidatorPropertyShape(innerLiteralNode),\n\t\t\toptional: getValidatorPropertyOptionality(innerLiteralNode),\n\t\t\tdescription: getValidatorPropertyStringValue(innerLiteralNode, 'description'),\n\t\t\terrorMessage: getValidatorPropertyStringValue(innerLiteralNode, 'errorMessage'),\n\t\t}\n\t})\n\n\treturn properties || []\n}\n\nconst returnTypeCache = new WeakMap<Node, Type>()\nconst getCallReturnType = (callExpression: Node): Type => {\n\tconst cached = returnTypeCache.get(callExpression)\n\tif (cached) {\n\t\treturn cached\n\t}\n\tconst result = callExpression.asKindOrThrow(SyntaxKind.CallExpression).getReturnType()\n\treturnTypeCache.set(callExpression, result)\n\treturn result\n}\n\nconst isZodCallExpression = (node: Node): boolean => {\n\tconst callExpression = node.asKind(SyntaxKind.CallExpression)\n\tif (!callExpression) {\n\t\treturn false\n\t}\n\tconst returnType = getCallReturnType(callExpression)\n\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\treturn typeName.startsWith('Zod')\n}\n\nconst getZodCallShape = (node: Node): ShapeOfType['shape'] => {\n\tconst callExpression = node.asKind(SyntaxKind.CallExpression)!\n\tconst returnType = getCallReturnType(callExpression)\n\tconst outputProp = returnType.getProperty('_output')\n\tif (outputProp) {\n\t\treturn getProperTypeShape(outputProp.getTypeAtLocation(callExpression), callExpression)\n\t}\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\tLogger.warn(`[${fileName}] Unknown zod type: ${typeName}`)\n\treturn 'unknown_zod'\n}\n\nexport const getValidatorPropertyShape = (innerLiteralNode: Node): ShapeOfType['shape'] => {\n\t// Zod validator (e.g. z.number(), z.string(), z.object({...}), z.array(...))\n\tif (isZodCallExpression(innerLiteralNode)) {\n\t\treturn getZodCallShape(innerLiteralNode)\n\t}\n\n\t// Inline definition with `as Validator<...>` clause\n\tconst inlineValidatorAsExpression = innerLiteralNode\n\t\t.getParent()!\n\t\t.getFirstChildByKind(SyntaxKind.AsExpression)\n\tif (inlineValidatorAsExpression) {\n\t\tconst typeReference = inlineValidatorAsExpression.getLastChildByKind(SyntaxKind.TypeReference)!\n\t\treturn getTypeReferenceShape(typeReference)\n\t}\n\n\t// Variable with `: Validator<...>` clause\n\tconst childTypeReferenceNode = innerLiteralNode.getParent()!.getFirstChildByKind(SyntaxKind.TypeReference)\n\tif (childTypeReferenceNode) {\n\t\treturn getTypeReferenceShape(childTypeReferenceNode)\n\t}\n\n\t// `RequiredParam<...>` inline call expression\n\tif (innerLiteralNode.getParent()!.getChildrenOfKind(SyntaxKind.SyntaxList).length >= 2) {\n\t\tconst typeNode = innerLiteralNode\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t\t.getFirstChild()!\n\t\treturn getRecursiveNodeShape(typeNode)\n\t}\n\n\t// `RequestParam | RequiredParam | OptionalParam` call expression\n\tconst childCallExpressionNode = innerLiteralNode.getParent()!.getFirstChildByKind(SyntaxKind.CallExpression)\n\tif (childCallExpressionNode) {\n\t\tconst callExpressionArgument = findNodeImplementation(\n\t\t\tchildCallExpressionNode.getFirstChildByKind(SyntaxKind.SyntaxList)!.getFirstChild()!,\n\t\t)\n\n\t\t// Param is a type reference\n\t\tconst typeReferenceNode = callExpressionArgument\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.TypeReference)!\n\t\tif (typeReferenceNode) {\n\t\t\treturn getProperTypeShape(typeReferenceNode.getType(), typeReferenceNode, [])\n\t\t}\n\n\t\tconst thingyNode = callExpressionArgument\n\t\t\t.getParent()!\n\t\t\t.getFirstChildByKind(SyntaxKind.ObjectLiteralExpression)!\n\t\tif (thingyNode) {\n\t\t\treturn getValidatorPropertyShape(thingyNode)\n\t\t}\n\n\t\tif (callExpressionArgument.getKind() === SyntaxKind.CallExpression) {\n\t\t\treturn getValidatorPropertyShape(callExpressionArgument)\n\t\t}\n\n\t\tif (callExpressionArgument.getKind() === SyntaxKind.IntersectionType) {\n\t\t\treturn getValidatorPropertyShape(callExpressionArgument)\n\t\t}\n\n\t\tconst fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop()\n\t\tLogger.warn(`[${fileName}] Unknown call expression argument: ${callExpressionArgument.getKindName()}`)\n\t\treturn 'unknown_3'\n\t}\n\n\t// Attempting to infer type from `parse` function\n\tconst innerNodePropertyAssignments = innerLiteralNode\n\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\t.getChildrenOfKind(SyntaxKind.PropertyAssignment)\n\tconst parsePropertyAssignment = innerNodePropertyAssignments.find((prop) => {\n\t\treturn prop.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'parse'\n\t})\n\tif (parsePropertyAssignment) {\n\t\tconst returnType = findPropertyAssignmentValueNode(parsePropertyAssignment)\n\t\t\t.asKind(SyntaxKind.ArrowFunction)!\n\t\t\t.getReturnType()\n\t\treturn getProperTypeShape(returnType, parsePropertyAssignment)\n\t}\n\n\t// Import statement\n\tconst importTypeNode = innerLiteralNode\n\t\t.getFirstChildByKind(SyntaxKind.SyntaxList)\n\t\t?.getFirstChildByKind(SyntaxKind.ImportType)\n\tif (importTypeNode) {\n\t\tconst indexOfGreaterThanToken = importTypeNode\n\t\t\t.getLastChildByKind(SyntaxKind.GreaterThanToken)!\n\t\t\t.getChildIndex()\n\t\tconst targetSyntaxList = importTypeNode.getChildAtIndex(indexOfGreaterThanToken - 1)\n\t\treturn getRecursiveNodeShape(targetSyntaxList.getFirstChild()!)\n\t}\n\n\t// Intersection type with Validator\n\tconst intersectionType = innerLiteralNode.isKind(SyntaxKind.IntersectionType)\n\t\t? innerLiteralNode\n\t\t: innerLiteralNode.getParent()?.isKind(SyntaxKind.VariableDeclaration)\n\t\t\t? innerLiteralNode.getParent()?.getFirstChildByKind(SyntaxKind.IntersectionType)\n\t\t\t: null\n\n\tif (intersectionType) {\n\t\tconst validatorType = intersectionType.getFirstChildByKind(SyntaxKind.TypeReference)\n\t\tif (validatorType) {\n\t\t\treturn getTypeReferenceShape(validatorType)\n\t\t}\n\t}\n\n\tconst fileName = innerLiteralNode.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown import type node`)\n\n\treturn 'unknown_2'\n}\n\nexport const getValidatorPropertyOptionality = (node: Node): boolean => {\n\tif (isZodCallExpression(node)) {\n\t\tconst callExpression = node.asKind(SyntaxKind.CallExpression)!\n\t\tconst returnType = getCallReturnType(callExpression)\n\t\tconst typeName = returnType.getSymbol()?.getName() ?? ''\n\t\tif (typeName === 'ZodOptional') {\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\tconst identifierNode = callExpressionNode.getFirstChildByKind(SyntaxKind.Identifier)\n\t\tif (identifierNode?.getText() === 'OptionalParam') {\n\t\t\treturn true\n\t\t} else if (identifierNode?.getText() === 'RequiredParam') {\n\t\t\treturn false\n\t\t}\n\n\t\tconst syntaxListNode = callExpressionNode.getFirstChildByKind(SyntaxKind.SyntaxList)!\n\t\tconst literalExpression = findNodeImplementation(syntaxListNode.getFirstChild()!)\n\t\treturn getValidatorPropertyOptionality(literalExpression)\n\t}\n\n\tconst syntaxListNode = node.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\treturn assignmentNodes.some((node) => {\n\t\tconst identifierNode = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tconst identifierName = identifierNode.getText()\n\n\t\tif (identifierName === 'optional') {\n\t\t\tconst value = findPropertyAssignmentValueNode(node)\n\t\t\treturn value.getKind() === SyntaxKind.TrueKeyword\n\t\t}\n\t\treturn false\n\t})\n}\n\nexport const getValidatorPropertyStringValue = (\n\tnodeOrReference: Node,\n\tname: 'description' | 'errorMessage',\n): string => {\n\tif (isZodCallExpression(nodeOrReference)) {\n\t\treturn ''\n\t}\n\n\tconst node = findNodeImplementation(nodeOrReference)\n\n\tconst callExpressionNode = node.asKind(SyntaxKind.CallExpression)\n\tif (callExpressionNode) {\n\t\tconst targetChild = callExpressionNode.getLastChildByKind(SyntaxKind.SyntaxList)!\n\t\treturn getValidatorPropertyStringValue(targetChild, name)\n\t}\n\n\tconst syntaxListNode = node.asKind(SyntaxKind.SyntaxList)\n\tif (syntaxListNode) {\n\t\tconst children = syntaxListNode.getChildren().map((c) => getValidatorPropertyStringValue(c, name))\n\t\treturn children.find((value) => !!value && value !== 'unknown_25') || ''\n\t}\n\n\tconst objectLiteralNode = node.asKind(SyntaxKind.ObjectLiteralExpression)\n\tif (objectLiteralNode) {\n\t\tconst values = getValuesOfObjectLiteral(objectLiteralNode)\n\t\tconst targetValue = values.find((value) => value.identifier === name)\n\t\tif (!targetValue) {\n\t\t\treturn ''\n\t\t}\n\t\tif (Array.isArray(targetValue.value)) {\n\t\t\treturn 'array'\n\t\t}\n\t\treturn targetValue.value || ''\n\t}\n\n\tconst intersectionTypeNode = node.asKind(SyntaxKind.IntersectionType)\n\tif (intersectionTypeNode) {\n\t\treturn (\n\t\t\tintersectionTypeNode\n\t\t\t\t.getTypeNodes()\n\t\t\t\t.flatMap((t) => getValidatorPropertyStringValue(t, name))\n\t\t\t\t.filter((v) => !!v && v !== 'unknown_25')[0] || 'unknown_27'\n\t\t)\n\t}\n\n\tconst typeLiteralNode = node.asKind(SyntaxKind.TypeLiteral)\n\tif (typeLiteralNode) {\n\t\treturn getValidatorPropertyStringValue(typeLiteralNode.getFirstChildByKind(SyntaxKind.SyntaxList)!, name)\n\t}\n\n\tconst propertySignatureNode = node.asKind(SyntaxKind.PropertySignature)\n\tif (propertySignatureNode) {\n\t\tconst identifier = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tif (identifier.getText() === name) {\n\t\t\tconst targetNode = findPropertyAssignmentValueNode(propertySignatureNode).getFirstDescendantByKind(\n\t\t\t\tSyntaxKind.StringLiteral,\n\t\t\t)!\n\t\t\treturn targetNode.getLiteralText()\n\t\t}\n\t}\n\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.dev(`[${fileName}] Unknown property string value node ${node.getKindName()}`)\n\treturn 'unknown_25'\n}\n\nconst isPromise = (type: Type) => {\n\tconst symbol = type.getSymbol()\n\tif (!type.isObject() || !symbol) {\n\t\treturn false\n\t}\n\tconst args = type.getTypeArguments()\n\treturn symbol.getName() === 'Promise' && args.length === 1\n}\n\nexport const getProperTypeShape = (\n\ttypeOrPromise: Type,\n\tatLocation: Node,\n\tstack: Type[] = [],\n): ShapeOfType['shape'] => {\n\tconst typeName = typeOrPromise.getAliasSymbol()?.getName()\n\tif (typeName && OpenApiManager.getInstance().hasExposedModel(typeName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'ref',\n\t\t\t\tshape: typeName,\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tconst type = isPromise(typeOrPromise) ? typeOrPromise.getTypeArguments()[0] : typeOrPromise\n\n\tif (stack.some((previousType) => previousType === type)) {\n\t\treturn 'circular'\n\t}\n\n\tconst cacheKey = type.compilerType\n\tconst cached = typeShapeCache.get(cacheKey)\n\tif (cached !== undefined) {\n\t\treturn cached\n\t}\n\tconst result = computeProperTypeShape(type, atLocation, stack)\n\ttypeShapeCache.set(cacheKey, result)\n\treturn result\n}\n\nconst computeProperTypeShape = (type: Type, atLocation: Node, stack: Type[]): ShapeOfType['shape'] => {\n\tconst nextStack = stack.concat(type)\n\n\tif (type.getText() === 'void') {\n\t\treturn 'void'\n\t}\n\n\tif (type.isAny()) {\n\t\treturn 'any'\n\t}\n\n\tif (type.isUnknown()) {\n\t\treturn 'unknown'\n\t}\n\n\tif (type.isNull()) {\n\t\treturn 'null'\n\t}\n\n\tif (type.isUndefined()) {\n\t\treturn 'undefined'\n\t}\n\n\tif (type.isBoolean() || type.isBooleanLiteral()) {\n\t\treturn 'boolean'\n\t}\n\n\tif (type.isStringLiteral()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'literal_string' as const,\n\t\t\t\tshape: String(type.getLiteralValue()!),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isNumberLiteral()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'literal_number' as const,\n\t\t\t\tshape: String(type.getLiteralValue()!),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isString() || type.isTemplateLiteral()) {\n\t\treturn 'string'\n\t}\n\n\tif (type.isNumber()) {\n\t\treturn 'number'\n\t}\n\n\tif (type.getText() === 'bigint') {\n\t\treturn 'bigint'\n\t}\n\n\tif (type.isTuple()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'tuple' as const,\n\t\t\t\tshape: type.getTupleElements().map((t) => ({\n\t\t\t\t\trole: 'tuple_entry' as const,\n\t\t\t\t\tshape: getProperTypeShape(t, atLocation, nextStack),\n\t\t\t\t\toptional: false,\n\t\t\t\t})),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isArray()) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'array' as const,\n\t\t\t\tshape: getProperTypeShape(type.getArrayElementType()!, atLocation, nextStack),\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\t// Handles `interface Foo extends Array<T>` (e.g. Prisma's JsonArray)\n\t// which fails type.isArray() but is still array-like\n\tif (type.isObject()) {\n\t\tconst arrayElementType = type.getNumberIndexType()\n\t\tconst baseTypes = type.getBaseTypes()\n\t\tconst arrayBase = baseTypes?.find((base) => base.isArray())\n\t\tif (arrayBase) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\trole: 'array' as const,\n\t\t\t\t\tshape: getProperTypeShape(\n\t\t\t\t\t\tarrayBase.getArrayElementType() ?? arrayElementType!,\n\t\t\t\t\t\tatLocation,\n\t\t\t\t\t\tnextStack,\n\t\t\t\t\t),\n\t\t\t\t\toptional: false,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t}\n\n\tconst typeSymbolName = type.getSymbol()?.getName()\n\n\tconst bufferLikeTypes = new Set([\n\t\t'Buffer',\n\t\t'Uint8Array',\n\t\t'Int8Array',\n\t\t'Uint8ClampedArray',\n\t\t'Int16Array',\n\t\t'Uint16Array',\n\t\t'Int32Array',\n\t\t'Uint32Array',\n\t\t'Float32Array',\n\t\t'Float64Array',\n\t\t'BigInt64Array',\n\t\t'BigUint64Array',\n\t\t'ArrayBuffer',\n\t\t'SharedArrayBuffer',\n\t\t'ReadableStream',\n\t])\n\n\tif (type.isObject() && typeSymbolName && bufferLikeTypes.has(typeSymbolName)) {\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'buffer' as const,\n\t\t\t\tshape: 'buffer',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'RegExp') {\n\t\treturn 'string'\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'Map') {\n\t\tconst typeArgs = type.getTypeArguments()\n\t\tconst valueType = typeArgs[1]\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'record' as const,\n\t\t\t\tshape: valueType ? getProperTypeShape(valueType, atLocation, nextStack) : 'unknown',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && typeSymbolName === 'Set') {\n\t\tconst typeArgs = type.getTypeArguments()\n\t\tconst elementType = typeArgs[0]\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'array' as const,\n\t\t\t\tshape: elementType ? getProperTypeShape(elementType, atLocation, nextStack) : 'unknown',\n\t\t\t\toptional: false,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isObject() && type.getProperties().length === 0) {\n\t\tconst targetType = type.getAliasTypeArguments()[1] ?? type.getStringIndexType()\n\t\tif (targetType) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\trole: 'record' as const,\n\t\t\t\t\tshape: getProperTypeShape(targetType, atLocation, nextStack),\n\t\t\t\t\toptional: false,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t}\n\n\tif (type.isObject()) {\n\t\tif (typeSymbolName === 'Date' || type.getText() === 'Date') {\n\t\t\treturn 'Date'\n\t\t}\n\t\treturn type\n\t\t\t.getProperties()\n\t\t\t.map((prop) => {\n\t\t\t\tconst valueDeclaration = prop.getValueDeclaration() || prop.getDeclarations()[0]!\n\t\t\t\tconst shape = getProperTypeShape(prop.getTypeAtLocation(atLocation), atLocation, nextStack)\n\t\t\t\tif (!valueDeclaration) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\t\tshape,\n\t\t\t\t\t\toptional: false,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst valueDeclarationNode =\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.PropertySignature) ||\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.PropertyAssignment) ||\n\t\t\t\t\tvalueDeclaration.asKind(SyntaxKind.ShorthandPropertyAssignment)\n\n\t\t\t\tif (!valueDeclarationNode) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\t\tshape,\n\t\t\t\t\t\toptional: false,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst isOptional = prop.getTypeAtLocation(atLocation).isNullable()\n\n\t\t\t\treturn {\n\t\t\t\t\trole: 'property' as const,\n\t\t\t\t\tidentifier: prop.getName(),\n\t\t\t\t\tshape,\n\t\t\t\t\toptional: isOptional,\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter((val) => val.shape !== 'undefined')\n\t}\n\n\tif (type.isUnion()) {\n\t\tconst unfilteredShapes: ShapeOfUnionEntry[] = type.getUnionTypes().map((type) => ({\n\t\t\trole: 'union_entry',\n\t\t\tshape: getProperTypeShape(type, atLocation, nextStack),\n\t\t\toptional: false,\n\t\t}))\n\n\t\tconst dedupedShapes = unfilteredShapes.filter(\n\t\t\t(type, index, arr) => !arr.find((dup, dupIndex) => dup.shape === type.shape && dupIndex > index),\n\t\t)\n\t\tconst isNullable = dedupedShapes.some((shape) => shape.shape === 'undefined')\n\t\tconst shapes = dedupedShapes.filter((shape) => shape.shape !== 'undefined')\n\t\tif (shapes.length === 1) {\n\t\t\treturn shapes[0].shape\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\trole: 'union',\n\t\t\t\tshape: shapes,\n\t\t\t\toptional: isNullable,\n\t\t\t},\n\t\t]\n\t}\n\n\tif (type.isIntersection()) {\n\t\tconst children = type.getIntersectionTypes()\n\t\tconst shapesOfChildren = children\n\t\t\t.map((child) => getProperTypeShape(child, atLocation, nextStack))\n\t\t\t.filter((shape) => typeof shape !== 'string') as ShapeOfProperty[][]\n\t\treturn shapesOfChildren.reduce<ShapeOfType[]>((total, current) => [...total, ...current], [])\n\t}\n\n\tconst fileName = atLocation.getSourceFile().getFilePath().split('/').pop()\n\tLogger.warn(`[${fileName}] Unknown type shape node ${type.getText()}`)\n\treturn 'unknown_5'\n}\n\nconst getLiteralValueOfNode = (node: Node): string | string[] | unknown[] => {\n\tif (node.isKind(SyntaxKind.Identifier)) {\n\t\treturn getLiteralValueOfNode(findNodeImplementation(node))\n\t} else if (node.isKind(SyntaxKind.StringLiteral)) {\n\t\treturn node.getLiteralValue()\n\t} else if (node.isKind(SyntaxKind.ArrayLiteralExpression)) {\n\t\treturn node.forEachChildAsArray().map((child) => getLiteralValueOfNode(child)) as string[]\n\t} else if (node.isKind(SyntaxKind.PropertyAccessExpression)) {\n\t\treturn getLiteralValueOfNode(findPropertyAssignmentValueNode(node))\n\t} else if (node.isKind(SyntaxKind.ObjectLiteralExpression)) {\n\t\treturn getValuesOfObjectLiteral(node)\n\t}\n\n\tconst fileName = node.getSourceFile().getFilePath().split('/').pop()\n\tLogger.dev(`[${fileName}] Unknown literal value node ${node.getKindName()}`)\n\n\treturn 'unknown_6'\n}\n\nexport const resolveEndpointPath = (node: Node): string | null => {\n\tconst callExpression = node.getFirstDescendantByKind(SyntaxKind.CallExpression)\n\tif (!callExpression) return null\n\n\tconst firstArg = callExpression.getArguments()[0]\n\tif (!firstArg) return null\n\n\tconst argType = firstArg.getType()\n\tif (argType.isStringLiteral()) {\n\t\treturn argType.getLiteralValue() as string\n\t}\n\n\treturn null\n}\n\nexport const getValuesOfObjectLiteral = (objectLiteralNode: Node<ts.ObjectLiteralExpression>) => {\n\tconst syntaxListNode = objectLiteralNode.getFirstDescendantByKind(SyntaxKind.SyntaxList)!\n\tconst assignmentNodes = syntaxListNode.getChildrenOfKind(SyntaxKind.PropertyAssignment)!\n\n\tconst properties = assignmentNodes.map((node) => {\n\t\tconst identifierNode = node.getFirstDescendantByKind(SyntaxKind.Identifier)!\n\t\tconst identifierName = identifierNode.getText()\n\n\t\tconst assignmentValueNode = node.getLastChild()!\n\t\tconst targetNode = findNodeImplementation(assignmentValueNode)\n\t\tconst value = getLiteralValueOfNode(targetNode)\n\n\t\treturn {\n\t\t\tidentifier: identifierName,\n\t\t\tvalue,\n\t\t}\n\t})\n\n\treturn properties || []\n}\n"],"names":["implementationCache","nodeShapeCache","typeShapeCache","implementationBySymbolCache","getCanonicalSymbol","node","symbol","findNodeImplementation","cached","SyntaxKind","cachedBySymbol","result","implementationNode","assignmentValueNode","definitionNode","findPropertyAssignmentValueNode","identifierChildren","child","getTypeReferenceShape","firstChild","getRecursiveNodeShape","nodeOrReference","computeRecursiveNodeShape","typeName","OpenApiManager","literalNode","typeLiteralNode","propNode","identifier","valueNode","questionMarkToken","typeReferenceNode","lastChild","getProperTypeShape","unionTypeNode","typeQueryNode","qualifiedNameNode","callExpressionNode","awaitExpressionNode","asExpressionNode","fileName","Logger","getShapeOfValidatorLiteral","objectLiteralNode","identifierNode","identifierName","innerLiteralNode","getValidatorPropertyShape","getValidatorPropertyOptionality","getValidatorPropertyStringValue","returnTypeCache","getCallReturnType","callExpression","isZodCallExpression","getZodCallShape","returnType","outputProp","inlineValidatorAsExpression","typeReference","childTypeReferenceNode","typeNode","childCallExpressionNode","callExpressionArgument","thingyNode","parsePropertyAssignment","prop","importTypeNode","indexOfGreaterThanToken","targetSyntaxList","intersectionType","validatorType","syntaxListNode","literalExpression","name","targetChild","c","value","targetValue","getValuesOfObjectLiteral","intersectionTypeNode","t","v","propertySignatureNode","isPromise","type","args","typeOrPromise","atLocation","stack","previousType","cacheKey","computeProperTypeShape","nextStack","arrayElementType","arrayBase","base","typeSymbolName","bufferLikeTypes","valueType","elementType","targetType","valueDeclaration","shape","isOptional","val","dedupedShapes","index","arr","dup","dupIndex","isNullable","shapes","total","current","getLiteralValueOfNode","resolveEndpointPath","firstArg","argType","targetNode"],"mappings":";;;AAgBA,MAAMA,wBAA0B,QAAoB,GAC9CC,wBAAqB,QAAoC,GACzDC,wBAAqB,QAAsC,GAE3DC,wBAAkC,QAAyB,GAE3DC,IAAqB,CAACC,MAAsC;AAC3D,QAAAC,IAASD,EAAK,UAAU;AAC9B,MAAKC;AAGG,YAAAA,EAAO,iBAAiB,KAAKA,GAAQ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;AAG/B,QAAAmC,IAAWnC,EAAK,cAAc,EAAE,cAAc,MAAM,GAAG,EAAE,IAAI;AACnE,SAAAoC,EAAO,IAAI,IAAID,CAAQ,gCAAgCnC,EAAK,YAAa,CAAA,EAAE,GAEpE;AACR,GAEa8G,KAAsB,CAAC9G,MAA8B;AACjE,QAAM+C,IAAiB/C,EAAK,yBAAyBI,EAAW,cAAc;AAC1E,MAAA,CAAC2C,EAAuB,QAAA;AAE5B,QAAMgE,IAAWhE,EAAe,aAAa,EAAE,CAAC;AAC5C,MAAA,CAACgE,EAAiB,QAAA;AAEhB,QAAAC,IAAUD,EAAS,QAAQ;AAC7B,SAAAC,EAAQ,oBACJA,EAAQ,gBAAgB,IAGzB;AACR,GAEavC,IAA2B,CAACnC,MACjBA,EAAkB,yBAAyBlC,EAAW,UAAU,EAChD,kBAAkBA,EAAW,kBAAkB,EAEnD,IAAI,CAACJ,MAAS;AAE1C,QAAAwC,IADiBxC,EAAK,yBAAyBI,EAAW,UAAU,EACpC,QAAQ,GAExCI,IAAsBR,EAAK,aAAa,GACxCiH,IAAa/G,EAAuBM,CAAmB,GACvD+D,IAAQsC,EAAsBI,CAAU;AAEvC,SAAA;AAAA,IACN,YAAYzE;AAAA,IACZ,OAAA+B;AAAA,EACD;AAAA,CACA,KAEoB,CAAC;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("fs"),m=require("path"),g=require("ts-morph"),y=require("../discoverRouters/discoverRouters.cjs");function d(r){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return s.default=r,Object.freeze(s)}const l=d(F),v=d(m),S=({targetPath:r,tsConfigPath:s,excludedFiles:t})=>{if(!l.existsSync(r))return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const n=(t??[]).map(e=>typeof e=="string"?new RegExp(`${e}`):e),f=[/^node_modules/,/^\./,/^dist/,/\.d\.ts$/,/\.spec\.ts$/,/\.test\.ts$/].concat(n??[]),a=l.readdirSync(r,{recursive:!0}).filter(e=>!(typeof e!="string"||f.some(o=>o.test(e))||!e.endsWith(".ts"))),p=new g.Project({tsConfigFilePath:s,skipFileDependencyResolution:!0}),c=a.map(e=>{const o=v.resolve(r,e);return{fileName:e,sourceFile:p.getSourceFile(o)}}).filter(e=>!!e.sourceFile);return{discoveredRouterFiles:c.map(e=>{const{fileName:o,sourceFile:u}=e,i=y.discoverRouters(u);return i.named.length===0&&i.anonymous.length===0?null:{fileName:o,sourceFile:u,routers:i}}).filter(e=>e!==null),discoveredSourceFiles:c.map(e=>e.sourceFile)}};exports.discoverRouterFiles=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("fs"),p=require("path"),F=require("../discoverRouters/discoverRouters.cjs");function d(r){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return s.default=r,Object.freeze(s)}const l=d(a),m=d(p),g=({targetPath:r,excludedFiles:s,project:t})=>{if(!l.existsSync(r))return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const n=(s??[]).map(e=>typeof e=="string"?new RegExp(`${e}`):e),f=[/^node_modules/,/^\./,/^dist/,/\.d\.ts$/,/\.spec\.ts$/,/\.test\.ts$/].concat(n??[]),c=l.readdirSync(r,{recursive:!0}).filter(e=>!(typeof e!="string"||f.some(o=>o.test(e))||!e.endsWith(".ts"))).map(e=>{const o=m.resolve(r,e);return{fileName:e,sourceFile:t.getSourceFile(o)}}).filter(e=>!!e.sourceFile);return{discoveredRouterFiles:c.map(e=>{const{fileName:o,sourceFile:u}=e,i=F.discoverRouters(u);return i.named.length===0&&i.anonymous.length===0?null:{fileName:o,sourceFile:u,routers:i}}).filter(e=>e!==null),discoveredSourceFiles:c.map(e=>e.sourceFile)}};exports.discoverRouterFiles=g;
2
2
  //# sourceMappingURL=discoverRouterFiles.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"discoverRouterFiles.cjs","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { Project } from 'ts-morph'\n\nimport { discoverRouters } from '../discoverRouters/discoverRouters'\n\nexport type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['discoveredRouterFiles'][number]\n\nexport const discoverRouterFiles = ({\n\ttargetPath,\n\ttsConfigPath,\n\texcludedFiles,\n}: {\n\ttargetPath: string\n\ttsConfigPath: string\n\texcludedFiles?: (string | RegExp)[]\n}) => {\n\tif (!fs.existsSync(targetPath)) {\n\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t}\n\n\tconst usersExcludedFiles = (excludedFiles ?? []).map((value) =>\n\t\ttypeof value === 'string' ? new RegExp(`${value}`) : value,\n\t)\n\tconst excludedPrefixes = [/^node_modules/, /^\\./, /^dist/, /\\.d\\.ts$/, /\\.spec\\.ts$/, /\\.test\\.ts$/].concat(\n\t\tusersExcludedFiles ?? [],\n\t)\n\n\tconst files = fs.readdirSync(targetPath, { recursive: true }).filter((filePath): filePath is string => {\n\t\tif (typeof filePath !== 'string') {\n\t\t\treturn false\n\t\t}\n\n\t\tif (excludedPrefixes.some((p) => p.test(filePath))) {\n\t\t\treturn false\n\t\t}\n\n\t\tif (!filePath.endsWith('.ts')) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: tsConfigPath,\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst allSourceFiles = files\n\t\t.map((fileName) => {\n\t\t\tconst filePath = path.resolve(targetPath, fileName)\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile: project.getSourceFile(filePath),\n\t\t\t}\n\t\t})\n\t\t.filter(\n\t\t\t(\n\t\t\t\tfile,\n\t\t\t): file is Omit<typeof file, 'sourceFile'> & { sourceFile: NonNullable<(typeof file)['sourceFile']> } =>\n\t\t\t\t!!file.sourceFile,\n\t\t)\n\n\tconst routersInFiles = allSourceFiles\n\t\t.map((file) => {\n\t\t\tconst { fileName, sourceFile } = file\n\t\t\tconst routers = discoverRouters(sourceFile)\n\t\t\tif (routers.named.length === 0 && routers.anonymous.length === 0) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile,\n\t\t\t\trouters,\n\t\t\t}\n\t\t})\n\t\t.filter((file): file is NonNullable<typeof file> => file !== null)\n\treturn {\n\t\tdiscoveredRouterFiles: routersInFiles,\n\t\tdiscoveredSourceFiles: allSourceFiles.map((file) => file.sourceFile),\n\t}\n}\n"],"names":["discoverRouterFiles","targetPath","tsConfigPath","excludedFiles","fs","usersExcludedFiles","value","excludedPrefixes","files","filePath","p","project","Project","allSourceFiles","fileName","path","file","sourceFile","routers","discoverRouters"],"mappings":"meAQaA,EAAsB,CAAC,CACnC,WAAAC,EACA,aAAAC,EACA,cAAAC,CACD,IAIM,CACL,GAAI,CAACC,EAAG,WAAWH,CAAU,EAC5B,MAAO,CAAE,sBAAuB,GAAI,sBAAuB,CAAA,CAAG,EAGzD,MAAAI,GAAsBF,GAAiB,CAAA,GAAI,IAAKG,GACrD,OAAOA,GAAU,SAAW,IAAI,OAAO,GAAGA,CAAK,EAAE,EAAIA,CACtD,EACMC,EAAmB,CAAC,gBAAiB,MAAO,QAAS,WAAY,cAAe,aAAa,EAAE,OACpGF,GAAsB,CAAA,CACvB,EAEMG,EAAQJ,EAAG,YAAYH,EAAY,CAAE,UAAW,GAAM,EAAE,OAAQQ,GACjE,SAAOA,GAAa,UAIpBF,EAAiB,KAAMG,GAAMA,EAAE,KAAKD,CAAQ,CAAC,GAI7C,CAACA,EAAS,SAAS,KAAK,EAI5B,EAEKE,EAAU,IAAIC,UAAQ,CAC3B,iBAAkBV,EAClB,6BAA8B,EAAA,CAC9B,EAEKW,EAAiBL,EACrB,IAAKM,GAAa,CAClB,MAAML,EAAWM,EAAK,QAAQd,EAAYa,CAAQ,EAC3C,MAAA,CACN,SAAAA,EACA,WAAYH,EAAQ,cAAcF,CAAQ,CAC3C,CACA,CAAA,EACA,OAECO,GAEA,CAAC,CAACA,EAAK,UACT,EAgBM,MAAA,CACN,sBAfsBH,EACrB,IAAKG,GAAS,CACR,KAAA,CAAE,SAAAF,EAAU,WAAAG,CAAA,EAAeD,EAC3BE,EAAUC,kBAAgBF,CAAU,EAC1C,OAAIC,EAAQ,MAAM,SAAW,GAAKA,EAAQ,UAAU,SAAW,EACvD,KAED,CACN,SAAAJ,EACA,WAAAG,EACA,QAAAC,CACD,CACA,CAAA,EACA,OAAQF,GAA2CA,IAAS,IAAI,EAGjE,sBAAuBH,EAAe,IAAKG,GAASA,EAAK,UAAU,CACpE,CACD"}
1
+ {"version":3,"file":"discoverRouterFiles.cjs","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { Project } from 'ts-morph'\n\nimport { discoverRouters } from '../discoverRouters/discoverRouters'\n\nexport type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['discoveredRouterFiles'][number]\n\nexport const discoverRouterFiles = ({\n\ttargetPath,\n\texcludedFiles,\n\tproject,\n}: {\n\ttargetPath: string\n\texcludedFiles?: (string | RegExp)[]\n\tproject: Project\n}) => {\n\tif (!fs.existsSync(targetPath)) {\n\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t}\n\n\tconst usersExcludedFiles = (excludedFiles ?? []).map((value) =>\n\t\ttypeof value === 'string' ? new RegExp(`${value}`) : value,\n\t)\n\tconst excludedPrefixes = [/^node_modules/, /^\\./, /^dist/, /\\.d\\.ts$/, /\\.spec\\.ts$/, /\\.test\\.ts$/].concat(\n\t\tusersExcludedFiles ?? [],\n\t)\n\n\tconst files = fs.readdirSync(targetPath, { recursive: true }).filter((filePath): filePath is string => {\n\t\tif (typeof filePath !== 'string') {\n\t\t\treturn false\n\t\t}\n\n\t\tif (excludedPrefixes.some((p) => p.test(filePath))) {\n\t\t\treturn false\n\t\t}\n\n\t\tif (!filePath.endsWith('.ts')) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\n\tconst allSourceFiles = files\n\t\t.map((fileName) => {\n\t\t\tconst filePath = path.resolve(targetPath, fileName)\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile: project.getSourceFile(filePath),\n\t\t\t}\n\t\t})\n\t\t.filter(\n\t\t\t(\n\t\t\t\tfile,\n\t\t\t): file is Omit<typeof file, 'sourceFile'> & { sourceFile: NonNullable<(typeof file)['sourceFile']> } =>\n\t\t\t\t!!file.sourceFile,\n\t\t)\n\n\tconst routersInFiles = allSourceFiles\n\t\t.map((file) => {\n\t\t\tconst { fileName, sourceFile } = file\n\t\t\tconst routers = discoverRouters(sourceFile)\n\t\t\tif (routers.named.length === 0 && routers.anonymous.length === 0) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile,\n\t\t\t\trouters,\n\t\t\t}\n\t\t})\n\t\t.filter((file): file is NonNullable<typeof file> => file !== null)\n\treturn {\n\t\tdiscoveredRouterFiles: routersInFiles,\n\t\tdiscoveredSourceFiles: allSourceFiles.map((file) => file.sourceFile),\n\t}\n}\n"],"names":["discoverRouterFiles","targetPath","excludedFiles","project","fs","usersExcludedFiles","value","excludedPrefixes","allSourceFiles","filePath","p","fileName","path","file","sourceFile","routers","discoverRouters"],"mappings":"6cAQaA,EAAsB,CAAC,CACnC,WAAAC,EACA,cAAAC,EACA,QAAAC,CACD,IAIM,CACL,GAAI,CAACC,EAAG,WAAWH,CAAU,EAC5B,MAAO,CAAE,sBAAuB,GAAI,sBAAuB,CAAA,CAAG,EAGzD,MAAAI,GAAsBH,GAAiB,CAAA,GAAI,IAAKI,GACrD,OAAOA,GAAU,SAAW,IAAI,OAAO,GAAGA,CAAK,EAAE,EAAIA,CACtD,EACMC,EAAmB,CAAC,gBAAiB,MAAO,QAAS,WAAY,cAAe,aAAa,EAAE,OACpGF,GAAsB,CAAA,CACvB,EAiBMG,EAfQJ,EAAG,YAAYH,EAAY,CAAE,UAAW,GAAM,EAAE,OAAQQ,GACjE,SAAOA,GAAa,UAIpBF,EAAiB,KAAMG,GAAMA,EAAE,KAAKD,CAAQ,CAAC,GAI7C,CAACA,EAAS,SAAS,KAAK,EAI5B,EAGC,IAAKE,GAAa,CAClB,MAAMF,EAAWG,EAAK,QAAQX,EAAYU,CAAQ,EAC3C,MAAA,CACN,SAAAA,EACA,WAAYR,EAAQ,cAAcM,CAAQ,CAC3C,CACA,CAAA,EACA,OAECI,GAEA,CAAC,CAACA,EAAK,UACT,EAgBM,MAAA,CACN,sBAfsBL,EACrB,IAAKK,GAAS,CACR,KAAA,CAAE,SAAAF,EAAU,WAAAG,CAAA,EAAeD,EAC3BE,EAAUC,kBAAgBF,CAAU,EAC1C,OAAIC,EAAQ,MAAM,SAAW,GAAKA,EAAQ,UAAU,SAAW,EACvD,KAED,CACN,SAAAJ,EACA,WAAAG,EACA,QAAAC,CACD,CACA,CAAA,EACA,OAAQF,GAA2CA,IAAS,IAAI,EAGjE,sBAAuBL,EAAe,IAAKK,GAASA,EAAK,UAAU,CACpE,CACD"}
@@ -1,8 +1,10 @@
1
+ import { Project } from 'ts-morph';
2
+
1
3
  export type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['discoveredRouterFiles'][number];
2
- export declare const discoverRouterFiles: ({ targetPath, tsConfigPath, excludedFiles, }: {
4
+ export declare const discoverRouterFiles: ({ targetPath, excludedFiles, project, }: {
3
5
  targetPath: string;
4
- tsConfigPath: string;
5
6
  excludedFiles?: (string | RegExp)[];
7
+ project: Project;
6
8
  }) => {
7
9
  discoveredRouterFiles: {
8
10
  fileName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"discoverRouterFiles.d.ts","sourceRoot":"","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1G,eAAO,MAAM,mBAAmB,iDAI7B;IACF,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CACnC;;;;;;;;;;CAiEA,CAAA"}
1
+ {"version":3,"file":"discoverRouterFiles.d.ts","sourceRoot":"","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAIlC,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1G,eAAO,MAAM,mBAAmB,4CAI7B;IACF,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACnC,OAAO,EAAE,OAAO,CAAA;CAChB;;;;;;;;;;CA4DA,CAAA"}
@@ -1,11 +1,10 @@
1
1
  import * as n from "fs";
2
- import * as m from "path";
3
- import { Project as F } from "ts-morph";
4
- import { discoverRouters as a } from "../discoverRouters/discoverRouters.mjs";
5
- const R = ({
2
+ import * as f from "path";
3
+ import { discoverRouters as m } from "../discoverRouters/discoverRouters.mjs";
4
+ const v = ({
6
5
  targetPath: s,
7
- tsConfigPath: c,
8
- excludedFiles: u
6
+ excludedFiles: u,
7
+ project: c
9
8
  }) => {
10
9
  if (!n.existsSync(s))
11
10
  return { discoveredRouterFiles: [], discoveredSourceFiles: [] };
@@ -13,21 +12,18 @@ const R = ({
13
12
  (e) => typeof e == "string" ? new RegExp(`${e}`) : e
14
13
  ), d = [/^node_modules/, /^\./, /^dist/, /\.d\.ts$/, /\.spec\.ts$/, /\.test\.ts$/].concat(
15
14
  l ?? []
16
- ), f = n.readdirSync(s, { recursive: !0 }).filter((e) => !(typeof e != "string" || d.some((r) => r.test(e)) || !e.endsWith(".ts"))), p = new F({
17
- tsConfigFilePath: c,
18
- skipFileDependencyResolution: !0
19
- }), o = f.map((e) => {
20
- const r = m.resolve(s, e);
15
+ ), o = n.readdirSync(s, { recursive: !0 }).filter((e) => !(typeof e != "string" || d.some((r) => r.test(e)) || !e.endsWith(".ts"))).map((e) => {
16
+ const r = f.resolve(s, e);
21
17
  return {
22
18
  fileName: e,
23
- sourceFile: p.getSourceFile(r)
19
+ sourceFile: c.getSourceFile(r)
24
20
  };
25
21
  }).filter(
26
22
  (e) => !!e.sourceFile
27
23
  );
28
24
  return {
29
25
  discoveredRouterFiles: o.map((e) => {
30
- const { fileName: r, sourceFile: i } = e, t = a(i);
26
+ const { fileName: r, sourceFile: i } = e, t = m(i);
31
27
  return t.named.length === 0 && t.anonymous.length === 0 ? null : {
32
28
  fileName: r,
33
29
  sourceFile: i,
@@ -38,6 +34,6 @@ const R = ({
38
34
  };
39
35
  };
40
36
  export {
41
- R as discoverRouterFiles
37
+ v as discoverRouterFiles
42
38
  };
43
39
  //# sourceMappingURL=discoverRouterFiles.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"discoverRouterFiles.mjs","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { Project } from 'ts-morph'\n\nimport { discoverRouters } from '../discoverRouters/discoverRouters'\n\nexport type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['discoveredRouterFiles'][number]\n\nexport const discoverRouterFiles = ({\n\ttargetPath,\n\ttsConfigPath,\n\texcludedFiles,\n}: {\n\ttargetPath: string\n\ttsConfigPath: string\n\texcludedFiles?: (string | RegExp)[]\n}) => {\n\tif (!fs.existsSync(targetPath)) {\n\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t}\n\n\tconst usersExcludedFiles = (excludedFiles ?? []).map((value) =>\n\t\ttypeof value === 'string' ? new RegExp(`${value}`) : value,\n\t)\n\tconst excludedPrefixes = [/^node_modules/, /^\\./, /^dist/, /\\.d\\.ts$/, /\\.spec\\.ts$/, /\\.test\\.ts$/].concat(\n\t\tusersExcludedFiles ?? [],\n\t)\n\n\tconst files = fs.readdirSync(targetPath, { recursive: true }).filter((filePath): filePath is string => {\n\t\tif (typeof filePath !== 'string') {\n\t\t\treturn false\n\t\t}\n\n\t\tif (excludedPrefixes.some((p) => p.test(filePath))) {\n\t\t\treturn false\n\t\t}\n\n\t\tif (!filePath.endsWith('.ts')) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: tsConfigPath,\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst allSourceFiles = files\n\t\t.map((fileName) => {\n\t\t\tconst filePath = path.resolve(targetPath, fileName)\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile: project.getSourceFile(filePath),\n\t\t\t}\n\t\t})\n\t\t.filter(\n\t\t\t(\n\t\t\t\tfile,\n\t\t\t): file is Omit<typeof file, 'sourceFile'> & { sourceFile: NonNullable<(typeof file)['sourceFile']> } =>\n\t\t\t\t!!file.sourceFile,\n\t\t)\n\n\tconst routersInFiles = allSourceFiles\n\t\t.map((file) => {\n\t\t\tconst { fileName, sourceFile } = file\n\t\t\tconst routers = discoverRouters(sourceFile)\n\t\t\tif (routers.named.length === 0 && routers.anonymous.length === 0) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile,\n\t\t\t\trouters,\n\t\t\t}\n\t\t})\n\t\t.filter((file): file is NonNullable<typeof file> => file !== null)\n\treturn {\n\t\tdiscoveredRouterFiles: routersInFiles,\n\t\tdiscoveredSourceFiles: allSourceFiles.map((file) => file.sourceFile),\n\t}\n}\n"],"names":["discoverRouterFiles","targetPath","tsConfigPath","excludedFiles","fs","usersExcludedFiles","value","excludedPrefixes","files","filePath","p","project","Project","allSourceFiles","fileName","path","file","sourceFile","routers","discoverRouters"],"mappings":";;;;AAQO,MAAMA,IAAsB,CAAC;AAAA,EACnC,YAAAC;AAAA,EACA,cAAAC;AAAA,EACA,eAAAC;AACD,MAIM;AACL,MAAI,CAACC,EAAG,WAAWH,CAAU;AAC5B,WAAO,EAAE,uBAAuB,IAAI,uBAAuB,CAAA,EAAG;AAGzD,QAAAI,KAAsBF,KAAiB,CAAA,GAAI;AAAA,IAAI,CAACG,MACrD,OAAOA,KAAU,WAAW,IAAI,OAAO,GAAGA,CAAK,EAAE,IAAIA;AAAA,EACtD,GACMC,IAAmB,CAAC,iBAAiB,OAAO,SAAS,YAAY,eAAe,aAAa,EAAE;AAAA,IACpGF,KAAsB,CAAA;AAAA,EACvB,GAEMG,IAAQJ,EAAG,YAAYH,GAAY,EAAE,WAAW,IAAM,EAAE,OAAO,CAACQ,MACjE,SAAOA,KAAa,YAIpBF,EAAiB,KAAK,CAACG,MAAMA,EAAE,KAAKD,CAAQ,CAAC,KAI7C,CAACA,EAAS,SAAS,KAAK,EAI5B,GAEKE,IAAU,IAAIC,EAAQ;AAAA,IAC3B,kBAAkBV;AAAA,IAClB,8BAA8B;AAAA,EAAA,CAC9B,GAEKW,IAAiBL,EACrB,IAAI,CAACM,MAAa;AAClB,UAAML,IAAWM,EAAK,QAAQd,GAAYa,CAAQ;AAC3C,WAAA;AAAA,MACN,UAAAA;AAAA,MACA,YAAYH,EAAQ,cAAcF,CAAQ;AAAA,IAC3C;AAAA,EACA,CAAA,EACA;AAAA,IACA,CACCO,MAEA,CAAC,CAACA,EAAK;AAAA,EACT;AAgBM,SAAA;AAAA,IACN,uBAfsBH,EACrB,IAAI,CAACG,MAAS;AACR,YAAA,EAAE,UAAAF,GAAU,YAAAG,EAAA,IAAeD,GAC3BE,IAAUC,EAAgBF,CAAU;AAC1C,aAAIC,EAAQ,MAAM,WAAW,KAAKA,EAAQ,UAAU,WAAW,IACvD,OAED;AAAA,QACN,UAAAJ;AAAA,QACA,YAAAG;AAAA,QACA,SAAAC;AAAA,MACD;AAAA,IACA,CAAA,EACA,OAAO,CAACF,MAA2CA,MAAS,IAAI;AAAA,IAGjE,uBAAuBH,EAAe,IAAI,CAACG,MAASA,EAAK,UAAU;AAAA,EACpE;AACD;"}
1
+ {"version":3,"file":"discoverRouterFiles.mjs","sources":["../../../../src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts"],"sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { Project } from 'ts-morph'\n\nimport { discoverRouters } from '../discoverRouters/discoverRouters'\n\nexport type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['discoveredRouterFiles'][number]\n\nexport const discoverRouterFiles = ({\n\ttargetPath,\n\texcludedFiles,\n\tproject,\n}: {\n\ttargetPath: string\n\texcludedFiles?: (string | RegExp)[]\n\tproject: Project\n}) => {\n\tif (!fs.existsSync(targetPath)) {\n\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t}\n\n\tconst usersExcludedFiles = (excludedFiles ?? []).map((value) =>\n\t\ttypeof value === 'string' ? new RegExp(`${value}`) : value,\n\t)\n\tconst excludedPrefixes = [/^node_modules/, /^\\./, /^dist/, /\\.d\\.ts$/, /\\.spec\\.ts$/, /\\.test\\.ts$/].concat(\n\t\tusersExcludedFiles ?? [],\n\t)\n\n\tconst files = fs.readdirSync(targetPath, { recursive: true }).filter((filePath): filePath is string => {\n\t\tif (typeof filePath !== 'string') {\n\t\t\treturn false\n\t\t}\n\n\t\tif (excludedPrefixes.some((p) => p.test(filePath))) {\n\t\t\treturn false\n\t\t}\n\n\t\tif (!filePath.endsWith('.ts')) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\n\tconst allSourceFiles = files\n\t\t.map((fileName) => {\n\t\t\tconst filePath = path.resolve(targetPath, fileName)\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile: project.getSourceFile(filePath),\n\t\t\t}\n\t\t})\n\t\t.filter(\n\t\t\t(\n\t\t\t\tfile,\n\t\t\t): file is Omit<typeof file, 'sourceFile'> & { sourceFile: NonNullable<(typeof file)['sourceFile']> } =>\n\t\t\t\t!!file.sourceFile,\n\t\t)\n\n\tconst routersInFiles = allSourceFiles\n\t\t.map((file) => {\n\t\t\tconst { fileName, sourceFile } = file\n\t\t\tconst routers = discoverRouters(sourceFile)\n\t\t\tif (routers.named.length === 0 && routers.anonymous.length === 0) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfileName,\n\t\t\t\tsourceFile,\n\t\t\t\trouters,\n\t\t\t}\n\t\t})\n\t\t.filter((file): file is NonNullable<typeof file> => file !== null)\n\treturn {\n\t\tdiscoveredRouterFiles: routersInFiles,\n\t\tdiscoveredSourceFiles: allSourceFiles.map((file) => file.sourceFile),\n\t}\n}\n"],"names":["discoverRouterFiles","targetPath","excludedFiles","project","fs","usersExcludedFiles","value","excludedPrefixes","allSourceFiles","filePath","p","fileName","path","file","sourceFile","routers","discoverRouters"],"mappings":";;;AAQO,MAAMA,IAAsB,CAAC;AAAA,EACnC,YAAAC;AAAA,EACA,eAAAC;AAAA,EACA,SAAAC;AACD,MAIM;AACL,MAAI,CAACC,EAAG,WAAWH,CAAU;AAC5B,WAAO,EAAE,uBAAuB,IAAI,uBAAuB,CAAA,EAAG;AAGzD,QAAAI,KAAsBH,KAAiB,CAAA,GAAI;AAAA,IAAI,CAACI,MACrD,OAAOA,KAAU,WAAW,IAAI,OAAO,GAAGA,CAAK,EAAE,IAAIA;AAAA,EACtD,GACMC,IAAmB,CAAC,iBAAiB,OAAO,SAAS,YAAY,eAAe,aAAa,EAAE;AAAA,IACpGF,KAAsB,CAAA;AAAA,EACvB,GAiBMG,IAfQJ,EAAG,YAAYH,GAAY,EAAE,WAAW,IAAM,EAAE,OAAO,CAACQ,MACjE,SAAOA,KAAa,YAIpBF,EAAiB,KAAK,CAACG,MAAMA,EAAE,KAAKD,CAAQ,CAAC,KAI7C,CAACA,EAAS,SAAS,KAAK,EAI5B,EAGC,IAAI,CAACE,MAAa;AAClB,UAAMF,IAAWG,EAAK,QAAQX,GAAYU,CAAQ;AAC3C,WAAA;AAAA,MACN,UAAAA;AAAA,MACA,YAAYR,EAAQ,cAAcM,CAAQ;AAAA,IAC3C;AAAA,EACA,CAAA,EACA;AAAA,IACA,CACCI,MAEA,CAAC,CAACA,EAAK;AAAA,EACT;AAgBM,SAAA;AAAA,IACN,uBAfsBL,EACrB,IAAI,CAACK,MAAS;AACR,YAAA,EAAE,UAAAF,GAAU,YAAAG,EAAA,IAAeD,GAC3BE,IAAUC,EAAgBF,CAAU;AAC1C,aAAIC,EAAQ,MAAM,WAAW,KAAKA,EAAQ,UAAU,WAAW,IACvD,OAED;AAAA,QACN,UAAAJ;AAAA,QACA,YAAAG;AAAA,QACA,SAAAC;AAAA,MACD;AAAA,IACA,CAAA,EACA,OAAO,CAACF,MAA2CA,MAAS,IAAI;AAAA,IAGjE,uBAAuBL,EAAe,IAAI,CAACK,MAASA,EAAK,UAAU;AAAA,EACpE;AACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moonflower",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "author": "tenebrie",
6
6
  "license": "MIT",
@@ -109,7 +109,7 @@ export const prepareOpenApiSpec = async ({
109
109
  const startTime = performance.now()
110
110
  const files = discoverRouterFiles({
111
111
  targetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',
112
- tsConfigPath: tsconfigPath,
112
+ project,
113
113
  })
114
114
  if (profiling !== 'off') {
115
115
  Logger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)
@@ -271,7 +271,6 @@ export const analyzeMultipleSourceFiles = async (
271
271
  pool.terminate()
272
272
  }
273
273
 
274
- // Each result maps 1:1 to a file task.
275
274
  for (let i = 0; i < results.length; i++) {
276
275
  const result = results[i]
277
276
  const fileName = allTasks[i].fileName
@@ -288,7 +287,6 @@ export const analyzeMultipleSourceFiles = async (
288
287
  }
289
288
  }
290
289
 
291
- // Write cache for each uncached file
292
290
  for (const { file, timestamp } of uncached) {
293
291
  const fileResult = byFile.get(file.fileName)!
294
292
  if (fileResult.endpoints.length > 0) {
@@ -1,26 +1,31 @@
1
1
  import fs from 'fs'
2
- import { SourceFile, SyntaxKind } from 'ts-morph'
2
+ import { SourceFile, ts } from 'ts-morph'
3
3
 
4
4
  import { formatTimestamp, Logger } from '../../utils/logger'
5
5
 
6
- export type TimestampCache = Record<string, { dependencies: SourceFile[] }>
7
-
8
- /**
9
- * Per-run cache of file mtimes keyed by absolute path. Router files share large parts of their
10
- * transitive import graphs (common types, utils, models), so without this the same dependency gets
11
- * `statSync`-ed once per importing router — tens of thousands of redundant syscalls across a project
12
- * with dozens of routers. mtimes don't change mid-run, so memoizing is safe.
13
- */
6
+ export type TimestampCache = Record<string, { dependencies: string[] }>
14
7
  export type MtimeCache = Map<string, number>
15
8
 
9
+ const resolutionHost: ts.ModuleResolutionHost = ts.sys
10
+ const resolutionCacheByOptions = new WeakMap<ts.CompilerOptions, ts.ModuleResolutionCache>()
11
+
12
+ const getResolutionCache = (options: ts.CompilerOptions): ts.ModuleResolutionCache => {
13
+ let cache = resolutionCacheByOptions.get(options)
14
+ if (!cache) {
15
+ cache = ts.createModuleResolutionCache(ts.sys.getCurrentDirectory(), (fileName) => fileName, options)
16
+ resolutionCacheByOptions.set(options, cache)
17
+ }
18
+ return cache
19
+ }
20
+
16
21
  export function getSourceFileTimestamp(
17
22
  sourceFile: SourceFile,
18
23
  timestampCache: TimestampCache,
19
24
  mtimeCache: MtimeCache = new Map(),
20
25
  ) {
21
- const dependencies = getFileDependencies(sourceFile, timestampCache)
22
- const timestamps = dependencies.map((dep) => {
23
- const depPath = dep.getFilePath()
26
+ const compilerOptions = sourceFile.getProject().getCompilerOptions()
27
+ const dependencies = getFileDependencies(sourceFile.getFilePath(), compilerOptions, timestampCache)
28
+ const timestamps = dependencies.map((depPath) => {
24
29
  const cached = mtimeCache.get(depPath)
25
30
  if (cached !== undefined) {
26
31
  return cached
@@ -32,49 +37,59 @@ export function getSourceFileTimestamp(
32
37
  const latestTimestamp = Math.max(...timestamps)
33
38
 
34
39
  const fileName = sourceFile.getFilePath().split('/').pop()
35
- const depsCount = dependencies.length
36
40
  Logger.debug(
37
- `[${fileName}] Found ${depsCount} imports, latest touched at ${formatTimestamp(latestTimestamp)}.`,
41
+ `[${fileName}] Found ${dependencies.length} imports, latest touched at ${formatTimestamp(latestTimestamp)}.`,
38
42
  )
39
43
 
40
44
  return latestTimestamp
41
45
  }
42
46
 
43
- function getFileDependencies(sourceFile: SourceFile, timestampCache: TimestampCache): SourceFile[] {
44
- const fileName = sourceFile.getFilePath().split('/').pop()
45
- if (!fileName) {
46
- return []
47
- }
48
-
49
- const cacheHit = timestampCache[sourceFile.getFilePath()]
47
+ function getFileDependencies(
48
+ filePath: string,
49
+ options: ts.CompilerOptions,
50
+ timestampCache: TimestampCache,
51
+ ): string[] {
52
+ const cacheHit = timestampCache[filePath]
50
53
  if (cacheHit) {
51
54
  return cacheHit.dependencies
52
55
  }
53
56
 
54
- // Initialize cache entry early to prevent circular dependencies
55
- timestampCache[sourceFile.getFilePath()] = { dependencies: [] }
57
+ timestampCache[filePath] = { dependencies: [filePath] }
56
58
 
57
- try {
58
- const results = [sourceFile]
59
+ const fileName = filePath.split('/').pop()
60
+ const sourceText = ts.sys.readFile(filePath)
61
+ if (sourceText === undefined) {
62
+ return timestampCache[filePath].dependencies
63
+ }
59
64
 
60
- const importDeclarations = sourceFile.getDescendantsOfKind(SyntaxKind.ImportDeclaration)
65
+ try {
66
+ const closure = new Set<string>([filePath])
67
+ const { importedFiles } = ts.preProcessFile(sourceText, true, true)
68
+ const resolutionCache = getResolutionCache(options)
61
69
 
62
- for (const declaration of importDeclarations) {
63
- const importedSourceFile = declaration.getModuleSpecifierSourceFile()
64
- if (!importedSourceFile) {
65
- Logger.debug(`[${fileName}] Could not resolve import ${declaration.getModuleSpecifierValue()}.`)
70
+ for (const imported of importedFiles) {
71
+ const { resolvedModule } = ts.resolveModuleName(
72
+ imported.fileName,
73
+ filePath,
74
+ options,
75
+ resolutionHost,
76
+ resolutionCache,
77
+ )
78
+ if (!resolvedModule) {
79
+ Logger.debug(`[${fileName}] Could not resolve import ${imported.fileName}.`)
66
80
  continue
67
81
  }
68
-
69
- const deps = getFileDependencies(importedSourceFile, timestampCache)
70
- results.push(...deps)
82
+ for (const dep of getFileDependencies(resolvedModule.resolvedFileName, options, timestampCache)) {
83
+ closure.add(dep)
84
+ }
71
85
  }
72
86
 
73
- timestampCache[sourceFile.getFilePath()] = { dependencies: results }
74
- return results
87
+ const dependencies = [...closure]
88
+ timestampCache[filePath] = { dependencies }
89
+ return dependencies
75
90
  } catch (error) {
76
91
  Logger.warn(`[${fileName}] Caught an error while processing imports:`, error)
77
- timestampCache[sourceFile.getFilePath()] = { dependencies: [] }
78
- return []
92
+ timestampCache[filePath] = { dependencies: [filePath] }
93
+ return timestampCache[filePath].dependencies
79
94
  }
80
95
  }