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.
- package/dist/openapi/analyzerModule/analyzerModule.cjs +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/analyzerModule.mjs +21 -21
- package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs +43 -32
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs.map +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.cjs +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.cjs.map +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.d.ts.map +1 -1
- package/dist/openapi/analyzerModule/nodeParsers.mjs +241 -222
- package/dist/openapi/analyzerModule/nodeParsers.mjs.map +1 -1
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs +1 -1
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs.map +1 -1
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts +4 -2
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts.map +1 -1
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs +10 -14
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs.map +1 -1
- package/package.json +1 -1
- package/src/openapi/analyzerModule/analyzerModule.ts +1 -3
- package/src/openapi/analyzerModule/getSourceFileTimestamp.ts +52 -37
- package/src/openapi/analyzerModule/nodeParsers.ts +57 -22
- package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.spec.ts +12 -3
- package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts +2 -7
|
@@ -18,6 +18,16 @@ const implementationCache = new WeakMap<Node, Node>()
|
|
|
18
18
|
const nodeShapeCache = new WeakMap<Node, ShapeOfType['shape']>()
|
|
19
19
|
const typeShapeCache = new WeakMap<object, ShapeOfType['shape']>()
|
|
20
20
|
|
|
21
|
+
const implementationBySymbolCache = new WeakMap<ts.Symbol, Node>()
|
|
22
|
+
|
|
23
|
+
const getCanonicalSymbol = (node: Node): ts.Symbol | undefined => {
|
|
24
|
+
const symbol = node.getSymbol()
|
|
25
|
+
if (!symbol) {
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
return (symbol.getAliasedSymbol() ?? symbol).compilerSymbol
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
export const findNodeImplementation = (node: Node): Node => {
|
|
22
32
|
const cached = implementationCache.get(node)
|
|
23
33
|
if (cached) {
|
|
@@ -25,30 +35,44 @@ export const findNodeImplementation = (node: Node): Node => {
|
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
if (node.getKind() === SyntaxKind.Identifier) {
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
const symbol = getCanonicalSymbol(node)
|
|
39
|
+
if (symbol) {
|
|
40
|
+
const cachedBySymbol = implementationBySymbolCache.get(symbol)
|
|
41
|
+
if (cachedBySymbol) {
|
|
42
|
+
implementationCache.set(node, cachedBySymbol)
|
|
43
|
+
return cachedBySymbol
|
|
34
44
|
}
|
|
35
|
-
const result = findNodeImplementation(assignmentValueNode)
|
|
36
|
-
implementationCache.set(node, result)
|
|
37
|
-
return result
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
const resolve = (): Node => {
|
|
48
|
+
const implementationNode = node.asKind(SyntaxKind.Identifier)!.getImplementations()[0]?.getNode()
|
|
49
|
+
if (implementationNode) {
|
|
50
|
+
const implementationParentNode = implementationNode.getParent()!
|
|
51
|
+
const assignmentValueNode = implementationParentNode.getLastChild()!
|
|
52
|
+
if (assignmentValueNode === node) {
|
|
53
|
+
throw new Error('Recursive implementation found')
|
|
54
|
+
}
|
|
55
|
+
return findNodeImplementation(assignmentValueNode)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const definitionNode = node.asKind(SyntaxKind.Identifier)!.getDefinitions()[0]?.getNode()
|
|
59
|
+
if (definitionNode) {
|
|
60
|
+
const definitionParentNode = definitionNode.getParent()!
|
|
61
|
+
const assignmentValueNode = definitionParentNode.getLastChild()!
|
|
62
|
+
if (assignmentValueNode === node) {
|
|
63
|
+
throw new Error('Recursive implementation found')
|
|
64
|
+
}
|
|
65
|
+
return findNodeImplementation(assignmentValueNode)
|
|
46
66
|
}
|
|
47
|
-
|
|
48
|
-
implementationCache.set(node, result)
|
|
49
|
-
return result
|
|
67
|
+
throw new Error('No implementation nor definition available')
|
|
50
68
|
}
|
|
51
|
-
|
|
69
|
+
|
|
70
|
+
const result = resolve()
|
|
71
|
+
if (symbol) {
|
|
72
|
+
implementationBySymbolCache.set(symbol, result)
|
|
73
|
+
}
|
|
74
|
+
implementationCache.set(node, result)
|
|
75
|
+
return result
|
|
52
76
|
}
|
|
53
77
|
|
|
54
78
|
implementationCache.set(node, node)
|
|
@@ -265,19 +289,30 @@ export const getShapeOfValidatorLiteral = (
|
|
|
265
289
|
return properties || []
|
|
266
290
|
}
|
|
267
291
|
|
|
292
|
+
const returnTypeCache = new WeakMap<Node, Type>()
|
|
293
|
+
const getCallReturnType = (callExpression: Node): Type => {
|
|
294
|
+
const cached = returnTypeCache.get(callExpression)
|
|
295
|
+
if (cached) {
|
|
296
|
+
return cached
|
|
297
|
+
}
|
|
298
|
+
const result = callExpression.asKindOrThrow(SyntaxKind.CallExpression).getReturnType()
|
|
299
|
+
returnTypeCache.set(callExpression, result)
|
|
300
|
+
return result
|
|
301
|
+
}
|
|
302
|
+
|
|
268
303
|
const isZodCallExpression = (node: Node): boolean => {
|
|
269
304
|
const callExpression = node.asKind(SyntaxKind.CallExpression)
|
|
270
305
|
if (!callExpression) {
|
|
271
306
|
return false
|
|
272
307
|
}
|
|
273
|
-
const returnType = callExpression
|
|
308
|
+
const returnType = getCallReturnType(callExpression)
|
|
274
309
|
const typeName = returnType.getSymbol()?.getName() ?? ''
|
|
275
310
|
return typeName.startsWith('Zod')
|
|
276
311
|
}
|
|
277
312
|
|
|
278
313
|
const getZodCallShape = (node: Node): ShapeOfType['shape'] => {
|
|
279
314
|
const callExpression = node.asKind(SyntaxKind.CallExpression)!
|
|
280
|
-
const returnType = callExpression
|
|
315
|
+
const returnType = getCallReturnType(callExpression)
|
|
281
316
|
const outputProp = returnType.getProperty('_output')
|
|
282
317
|
if (outputProp) {
|
|
283
318
|
return getProperTypeShape(outputProp.getTypeAtLocation(callExpression), callExpression)
|
|
@@ -402,7 +437,7 @@ export const getValidatorPropertyShape = (innerLiteralNode: Node): ShapeOfType['
|
|
|
402
437
|
export const getValidatorPropertyOptionality = (node: Node): boolean => {
|
|
403
438
|
if (isZodCallExpression(node)) {
|
|
404
439
|
const callExpression = node.asKind(SyntaxKind.CallExpression)!
|
|
405
|
-
const returnType = callExpression
|
|
440
|
+
const returnType = getCallReturnType(callExpression)
|
|
406
441
|
const typeName = returnType.getSymbol()?.getName() ?? ''
|
|
407
442
|
if (typeName === 'ZodOptional') {
|
|
408
443
|
return true
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { resolve } from 'path'
|
|
2
|
+
import { Project } from 'ts-morph'
|
|
3
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
2
4
|
|
|
3
5
|
import { discoverRouterFiles } from './discoverRouterFiles'
|
|
4
6
|
|
|
5
7
|
describe('discoverRouterFiles', () => {
|
|
8
|
+
let project: Project
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
project = new Project({
|
|
11
|
+
tsConfigFilePath: resolve('./tsconfig.json'),
|
|
12
|
+
skipFileDependencyResolution: true,
|
|
13
|
+
})
|
|
14
|
+
})
|
|
6
15
|
it('discovers routers from folder correctly', () => {
|
|
7
16
|
const { discoveredRouterFiles } = discoverRouterFiles({
|
|
8
17
|
targetPath: resolve(__dirname, '.'),
|
|
9
|
-
|
|
18
|
+
project,
|
|
10
19
|
})
|
|
11
20
|
|
|
12
21
|
expect(discoveredRouterFiles.length).toEqual(2)
|
|
@@ -15,8 +24,8 @@ describe('discoverRouterFiles', () => {
|
|
|
15
24
|
it('respects ignoring files by string', () => {
|
|
16
25
|
const { discoveredRouterFiles } = discoverRouterFiles({
|
|
17
26
|
targetPath: resolve(__dirname, '.'),
|
|
18
|
-
tsConfigPath: resolve('./tsconfig.json'),
|
|
19
27
|
excludedFiles: ['testRouterA'],
|
|
28
|
+
project,
|
|
20
29
|
})
|
|
21
30
|
|
|
22
31
|
expect(discoveredRouterFiles.length).toEqual(1)
|
|
@@ -26,8 +35,8 @@ describe('discoverRouterFiles', () => {
|
|
|
26
35
|
it('respects ignoring files by regex', () => {
|
|
27
36
|
const { discoveredRouterFiles } = discoverRouterFiles({
|
|
28
37
|
targetPath: resolve(__dirname, '.'),
|
|
29
|
-
tsConfigPath: resolve('./tsconfig.json'),
|
|
30
38
|
excludedFiles: [/B/g],
|
|
39
|
+
project,
|
|
31
40
|
})
|
|
32
41
|
|
|
33
42
|
expect(discoveredRouterFiles.length).toEqual(1)
|
|
@@ -8,12 +8,12 @@ export type DiscoveredSourceFile = ReturnType<typeof discoverRouterFiles>['disco
|
|
|
8
8
|
|
|
9
9
|
export const discoverRouterFiles = ({
|
|
10
10
|
targetPath,
|
|
11
|
-
tsConfigPath,
|
|
12
11
|
excludedFiles,
|
|
12
|
+
project,
|
|
13
13
|
}: {
|
|
14
14
|
targetPath: string
|
|
15
|
-
tsConfigPath: string
|
|
16
15
|
excludedFiles?: (string | RegExp)[]
|
|
16
|
+
project: Project
|
|
17
17
|
}) => {
|
|
18
18
|
if (!fs.existsSync(targetPath)) {
|
|
19
19
|
return { discoveredRouterFiles: [], discoveredSourceFiles: [] }
|
|
@@ -41,11 +41,6 @@ export const discoverRouterFiles = ({
|
|
|
41
41
|
return true
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
const project = new Project({
|
|
45
|
-
tsConfigFilePath: tsConfigPath,
|
|
46
|
-
skipFileDependencyResolution: true,
|
|
47
|
-
})
|
|
48
|
-
|
|
49
44
|
const allSourceFiles = files
|
|
50
45
|
.map((fileName) => {
|
|
51
46
|
const filePath = path.resolve(targetPath, fileName)
|