moonflower 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +26 -0
- package/.prettierrc.js +7 -0
- package/README.md +383 -0
- package/cli/cli.ts +59 -0
- package/cli/entry.cjs +3 -0
- package/cli/prettyprint.ts +16 -0
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +79 -0
- package/dist/cli/prettyprint.d.ts +4 -0
- package/dist/cli/prettyprint.d.ts.map +1 -0
- package/dist/cli/prettyprint.js +18 -0
- package/dist/src/errors/BaseHttpError.d.ts +13 -0
- package/dist/src/errors/BaseHttpError.d.ts.map +1 -0
- package/dist/src/errors/BaseHttpError.js +13 -0
- package/dist/src/errors/HttpErrorHandler.d.ts +3 -0
- package/dist/src/errors/HttpErrorHandler.d.ts.map +1 -0
- package/dist/src/errors/HttpErrorHandler.js +23 -0
- package/dist/src/errors/UserFacingErrors.d.ts +11 -0
- package/dist/src/errors/UserFacingErrors.d.ts.map +1 -0
- package/dist/src/errors/UserFacingErrors.js +23 -0
- package/dist/src/hooks/authentication/useAuth.d.ts +3 -0
- package/dist/src/hooks/authentication/useAuth.d.ts.map +1 -0
- package/dist/src/hooks/authentication/useAuth.js +7 -0
- package/dist/src/hooks/authentication/useOptionalAuth.d.ts +3 -0
- package/dist/src/hooks/authentication/useOptionalAuth.d.ts.map +1 -0
- package/dist/src/hooks/authentication/useOptionalAuth.js +16 -0
- package/dist/src/hooks/useApiEndpoint.d.ts +8 -0
- package/dist/src/hooks/useApiEndpoint.d.ts.map +1 -0
- package/dist/src/hooks/useApiEndpoint.js +7 -0
- package/dist/src/hooks/useApiHeader/index.d.ts +2 -0
- package/dist/src/hooks/useApiHeader/index.d.ts.map +1 -0
- package/dist/src/hooks/useApiHeader/index.js +17 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.d.ts +3 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.d.ts.map +1 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.js +6 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.spec.data.d.ts +2 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.spec.data.d.ts.map +1 -0
- package/dist/src/hooks/useApiHeader/useApiHeader.spec.data.js +22 -0
- package/dist/src/hooks/useCookieParams.d.ts +9 -0
- package/dist/src/hooks/useCookieParams.d.ts.map +1 -0
- package/dist/src/hooks/useCookieParams.js +50 -0
- package/dist/src/hooks/useExposeApiModel/index.d.ts +2 -0
- package/dist/src/hooks/useExposeApiModel/index.d.ts.map +1 -0
- package/dist/src/hooks/useExposeApiModel/index.js +17 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.d.ts +3 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.d.ts.map +1 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.js +9 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.d.ts +2 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.d.ts.map +1 -0
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.js +16 -0
- package/dist/src/hooks/useHeaderParams.d.ts +12 -0
- package/dist/src/hooks/useHeaderParams.d.ts.map +1 -0
- package/dist/src/hooks/useHeaderParams.js +52 -0
- package/dist/src/hooks/usePathParams.d.ts +22 -0
- package/dist/src/hooks/usePathParams.d.ts.map +1 -0
- package/dist/src/hooks/usePathParams.js +46 -0
- package/dist/src/hooks/useQueryParams.d.ts +9 -0
- package/dist/src/hooks/useQueryParams.d.ts.map +1 -0
- package/dist/src/hooks/useQueryParams.js +50 -0
- package/dist/src/hooks/useRequestBody.d.ts +9 -0
- package/dist/src/hooks/useRequestBody.d.ts.map +1 -0
- package/dist/src/hooks/useRequestBody.js +59 -0
- package/dist/src/hooks/useRequestRawBody.d.ts +7 -0
- package/dist/src/hooks/useRequestRawBody.d.ts.map +1 -0
- package/dist/src/hooks/useRequestRawBody.js +34 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +33 -0
- package/dist/src/openapi/analyzerModule/analyzerModule.d.ts +18 -0
- package/dist/src/openapi/analyzerModule/analyzerModule.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/analyzerModule.js +192 -0
- package/dist/src/openapi/analyzerModule/nodeParsers.d.ts +19 -0
- package/dist/src/openapi/analyzerModule/nodeParsers.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/nodeParsers.js +521 -0
- package/dist/src/openapi/analyzerModule/parseEndpoint.d.ts +4 -0
- package/dist/src/openapi/analyzerModule/parseEndpoint.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/parseEndpoint.js +246 -0
- package/dist/src/openapi/analyzerModule/parseExposedModels.d.ts +5 -0
- package/dist/src/openapi/analyzerModule/parseExposedModels.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/parseExposedModels.js +32 -0
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.d.ts +2 -0
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.js +400 -0
- package/dist/src/openapi/analyzerModule/types.d.ts +53 -0
- package/dist/src/openapi/analyzerModule/types.d.ts.map +1 -0
- package/dist/src/openapi/analyzerModule/types.js +2 -0
- package/dist/src/openapi/discoveryModule/discoverImports/discoverImports.d.ts +8 -0
- package/dist/src/openapi/discoveryModule/discoverImports/discoverImports.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverImports/discoverImports.js +33 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts +4 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.js +8 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts +4 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.js +8 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts +17 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.js +80 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.d.ts +6 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.js +31 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts +5 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.js +38 -0
- package/dist/src/openapi/discoveryModule/index.d.ts +3 -0
- package/dist/src/openapi/discoveryModule/index.d.ts.map +1 -0
- package/dist/src/openapi/discoveryModule/index.js +18 -0
- package/dist/src/openapi/generatorModule/generateComponentSchemas.d.ts +4 -0
- package/dist/src/openapi/generatorModule/generateComponentSchemas.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/generateComponentSchemas.js +12 -0
- package/dist/src/openapi/generatorModule/generatePaths.d.ts +10 -0
- package/dist/src/openapi/generatorModule/generatePaths.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/generatePaths.js +116 -0
- package/dist/src/openapi/generatorModule/generatorModule.d.ts +16 -0
- package/dist/src/openapi/generatorModule/generatorModule.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/generatorModule.js +18 -0
- package/dist/src/openapi/generatorModule/getSchema.d.ts +36 -0
- package/dist/src/openapi/generatorModule/getSchema.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/getSchema.js +133 -0
- package/dist/src/openapi/generatorModule/index.d.ts +5 -0
- package/dist/src/openapi/generatorModule/index.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/index.js +20 -0
- package/dist/src/openapi/generatorModule/test/openApiGenerator.spec.data.d.ts +515 -0
- package/dist/src/openapi/generatorModule/test/openApiGenerator.spec.data.d.ts.map +1 -0
- package/dist/src/openapi/generatorModule/test/openApiGenerator.spec.data.js +1119 -0
- package/dist/src/openapi/initOpenApiEngine.d.ts +4 -0
- package/dist/src/openapi/initOpenApiEngine.d.ts.map +1 -0
- package/dist/src/openapi/initOpenApiEngine.js +14 -0
- package/dist/src/openapi/manager/OpenApiManager.d.ts +67 -0
- package/dist/src/openapi/manager/OpenApiManager.d.ts.map +1 -0
- package/dist/src/openapi/manager/OpenApiManager.js +86 -0
- package/dist/src/openapi/router/OpenApiRouter.d.ts +4 -0
- package/dist/src/openapi/router/OpenApiRouter.d.ts.map +1 -0
- package/dist/src/openapi/router/OpenApiRouter.js +11 -0
- package/dist/src/openapi/types.d.ts +81 -0
- package/dist/src/openapi/types.d.ts.map +1 -0
- package/dist/src/openapi/types.js +2 -0
- package/dist/src/router/Router.d.ts +23 -0
- package/dist/src/router/Router.d.ts.map +1 -0
- package/dist/src/router/Router.js +81 -0
- package/dist/src/router/responseValueToJson.d.ts +2 -0
- package/dist/src/router/responseValueToJson.d.ts.map +1 -0
- package/dist/src/router/responseValueToJson.js +10 -0
- package/dist/src/setupTests.d.ts +1 -0
- package/dist/src/setupTests.d.ts.map +1 -0
- package/dist/src/setupTests.js +3 -0
- package/dist/src/test/TestAppRouter.d.ts +8 -0
- package/dist/src/test/TestAppRouter.d.ts.map +1 -0
- package/dist/src/test/TestAppRouter.js +58 -0
- package/dist/src/test/app.d.ts +3 -0
- package/dist/src/test/app.d.ts.map +1 -0
- package/dist/src/test/app.js +41 -0
- package/dist/src/utils/TypeUtils.d.ts +22 -0
- package/dist/src/utils/TypeUtils.d.ts.map +1 -0
- package/dist/src/utils/TypeUtils.js +2 -0
- package/dist/src/utils/fromZodSchema.d.ts +2 -0
- package/dist/src/utils/fromZodSchema.d.ts.map +1 -0
- package/dist/src/utils/fromZodSchema.js +6 -0
- package/dist/src/utils/loadTestData.d.ts +2 -0
- package/dist/src/utils/loadTestData.d.ts.map +1 -0
- package/dist/src/utils/loadTestData.js +39 -0
- package/dist/src/utils/mockContext.d.ts +20 -0
- package/dist/src/utils/mockContext.d.ts.map +1 -0
- package/dist/src/utils/mockContext.js +85 -0
- package/dist/src/utils/nameOf.d.ts +5 -0
- package/dist/src/utils/nameOf.d.ts.map +1 -0
- package/dist/src/utils/nameOf.js +7 -0
- package/dist/src/utils/object.d.ts +7 -0
- package/dist/src/utils/object.d.ts.map +1 -0
- package/dist/src/utils/object.js +21 -0
- package/dist/src/utils/printers.d.ts +6 -0
- package/dist/src/utils/printers.d.ts.map +1 -0
- package/dist/src/utils/printers.js +76 -0
- package/dist/src/utils/validationMessages.d.ts +18 -0
- package/dist/src/utils/validationMessages.d.ts.map +1 -0
- package/dist/src/utils/validationMessages.js +43 -0
- package/dist/src/validators/BuiltInValidators.d.ts +61 -0
- package/dist/src/validators/BuiltInValidators.d.ts.map +1 -0
- package/dist/src/validators/BuiltInValidators.js +66 -0
- package/dist/src/validators/InternalParamWrappers.d.ts +5 -0
- package/dist/src/validators/InternalParamWrappers.d.ts.map +1 -0
- package/dist/src/validators/InternalParamWrappers.js +5 -0
- package/dist/src/validators/ParamWrappers.d.ts +11 -0
- package/dist/src/validators/ParamWrappers.d.ts.map +1 -0
- package/dist/src/validators/ParamWrappers.js +9 -0
- package/dist/src/validators/types.d.ts +18 -0
- package/dist/src/validators/types.d.ts.map +1 -0
- package/dist/src/validators/types.js +2 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +59 -0
- package/src/errors/BaseHttpError.ts +16 -0
- package/src/errors/HttpErrorHandler.ts +20 -0
- package/src/errors/UserFacingErrors.ts +39 -0
- package/src/hooks/authentication/useAuth.ts +8 -0
- package/src/hooks/authentication/useOptionalAuth.ts +17 -0
- package/src/hooks/useApiEndpoint.spec.ts +11 -0
- package/src/hooks/useApiEndpoint.ts +10 -0
- package/src/hooks/useApiHeader/index.ts +1 -0
- package/src/hooks/useApiHeader/useApiHeader.spec.data.ts +22 -0
- package/src/hooks/useApiHeader/useApiHeader.spec.ts +34 -0
- package/src/hooks/useApiHeader/useApiHeader.ts +6 -0
- package/src/hooks/useCookieParams.spec.ts +174 -0
- package/src/hooks/useCookieParams.ts +73 -0
- package/src/hooks/useExposeApiModel/index.ts +1 -0
- package/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.ts +48 -0
- package/src/hooks/useExposeApiModel/useExposeApiModel.spec.ts +388 -0
- package/src/hooks/useExposeApiModel/useExposeApiModel.ts +9 -0
- package/src/hooks/useHeaderParams.spec.ts +186 -0
- package/src/hooks/useHeaderParams.ts +83 -0
- package/src/hooks/usePathParams.spec.ts +161 -0
- package/src/hooks/usePathParams.ts +89 -0
- package/src/hooks/useQueryParams.spec.ts +224 -0
- package/src/hooks/useQueryParams.ts +73 -0
- package/src/hooks/useRequestBody.spec.ts +215 -0
- package/src/hooks/useRequestBody.ts +94 -0
- package/src/hooks/useRequestRawBody.spec.ts +154 -0
- package/src/hooks/useRequestRawBody.ts +56 -0
- package/src/index.ts +17 -0
- package/src/openapi/analyzerModule/analyzerModule.ts +228 -0
- package/src/openapi/analyzerModule/nodeParsers.ts +648 -0
- package/src/openapi/analyzerModule/parseEndpoint.ts +305 -0
- package/src/openapi/analyzerModule/parseExposedModels.ts +34 -0
- package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.ts +521 -0
- package/src/openapi/analyzerModule/test/openApiAnalyzer.spec.ts +1043 -0
- package/src/openapi/analyzerModule/types.ts +72 -0
- package/src/openapi/discoveryModule/discoverImports/discoverImports.ts +43 -0
- package/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.ts +7 -0
- package/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.ts +7 -0
- package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.spec.ts +36 -0
- package/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.ts +80 -0
- package/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.ts +42 -0
- package/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.ts +18 -0
- package/src/openapi/discoveryModule/discoverRouters/discoverRouters.ts +39 -0
- package/src/openapi/discoveryModule/index.ts +2 -0
- package/src/openapi/generatorModule/generateComponentSchemas.ts +12 -0
- package/src/openapi/generatorModule/generatePaths.ts +138 -0
- package/src/openapi/generatorModule/generatorModule.ts +17 -0
- package/src/openapi/generatorModule/getSchema.ts +169 -0
- package/src/openapi/generatorModule/index.ts +4 -0
- package/src/openapi/generatorModule/test/openApiGenerator.spec.data.ts +1119 -0
- package/src/openapi/generatorModule/test/openApiGenerator.spec.ts +783 -0
- package/src/openapi/initOpenApiEngine.ts +20 -0
- package/src/openapi/manager/OpenApiManager.ts +153 -0
- package/src/openapi/router/OpenApiRouter.ts +11 -0
- package/src/openapi/types.ts +86 -0
- package/src/router/Router.ts +123 -0
- package/src/router/responseValueToJson.ts +6 -0
- package/src/setupTests.ts +3 -0
- package/src/test/TestAppRouter.ts +76 -0
- package/src/test/app.spec.ts +130 -0
- package/src/test/app.ts +43 -0
- package/src/utils/TypeUtils.ts +51 -0
- package/src/utils/loadTestData.ts +15 -0
- package/src/utils/mockContext.ts +86 -0
- package/src/utils/nameOf.ts +7 -0
- package/src/utils/object.spec.ts +27 -0
- package/src/utils/object.ts +17 -0
- package/src/utils/printers.spec.ts +103 -0
- package/src/utils/printers.ts +49 -0
- package/src/utils/validationMessages.ts +65 -0
- package/src/validators/BuiltInValidators.ts +64 -0
- package/src/validators/InternalParamWrappers.ts +14 -0
- package/src/validators/ParamWrappers.ts +22 -0
- package/src/validators/types.ts +35 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.json +29 -0
- package/vite.config.ts +16 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValuesOfObjectLiteral = exports.getProperTypeShape = exports.getValidatorPropertyStringValue = exports.getValidatorPropertyOptionality = exports.getValidatorPropertyShape = exports.getShapeOfValidatorLiteral = exports.getRecursiveNodeShape = exports.getTypeReferenceShape = exports.findPropertyAssignmentValueNode = exports.findNodeImplementation = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const OpenApiManager_1 = require("../manager/OpenApiManager");
|
|
6
|
+
const findNodeImplementation = (node) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if (node.getKind() === ts_morph_1.SyntaxKind.Identifier) {
|
|
9
|
+
const implementationNode = (_a = node.asKind(ts_morph_1.SyntaxKind.Identifier).getImplementations()[0]) === null || _a === void 0 ? void 0 : _a.getNode();
|
|
10
|
+
if (implementationNode) {
|
|
11
|
+
const implementationParentNode = implementationNode.getParent();
|
|
12
|
+
const assignmentValueNode = implementationParentNode.getLastChild();
|
|
13
|
+
if (assignmentValueNode === node) {
|
|
14
|
+
throw new Error('Recursive implementation found');
|
|
15
|
+
}
|
|
16
|
+
return (0, exports.findNodeImplementation)(assignmentValueNode);
|
|
17
|
+
}
|
|
18
|
+
const definitionNode = (_b = node.asKind(ts_morph_1.SyntaxKind.Identifier).getDefinitions()[0]) === null || _b === void 0 ? void 0 : _b.getNode();
|
|
19
|
+
if (definitionNode) {
|
|
20
|
+
const definitionParentNode = definitionNode.getParent();
|
|
21
|
+
const assignmentValueNode = definitionParentNode.getLastChild();
|
|
22
|
+
if (assignmentValueNode === node) {
|
|
23
|
+
throw new Error('Recursive implementation found');
|
|
24
|
+
}
|
|
25
|
+
return (0, exports.findNodeImplementation)(assignmentValueNode);
|
|
26
|
+
}
|
|
27
|
+
throw new Error('No implementation nor definition available');
|
|
28
|
+
}
|
|
29
|
+
return node;
|
|
30
|
+
};
|
|
31
|
+
exports.findNodeImplementation = findNodeImplementation;
|
|
32
|
+
const findPropertyAssignmentValueNode = (node) => {
|
|
33
|
+
const identifierChildren = node.getChildrenOfKind(ts_morph_1.SyntaxKind.Identifier);
|
|
34
|
+
if (identifierChildren.length === 2) {
|
|
35
|
+
return (0, exports.findNodeImplementation)(identifierChildren[1]);
|
|
36
|
+
}
|
|
37
|
+
const lastMatchingChild = node.getChildren().reverse();
|
|
38
|
+
return lastMatchingChild.find((child) => child.getKind() !== ts_morph_1.SyntaxKind.GreaterThanToken &&
|
|
39
|
+
child.getKind() !== ts_morph_1.SyntaxKind.CommaToken &&
|
|
40
|
+
child.getKind() !== ts_morph_1.SyntaxKind.SemicolonToken);
|
|
41
|
+
};
|
|
42
|
+
exports.findPropertyAssignmentValueNode = findPropertyAssignmentValueNode;
|
|
43
|
+
const getTypeReferenceShape = (node) => {
|
|
44
|
+
const firstChild = node.getFirstChild();
|
|
45
|
+
if (firstChild.isKind(ts_morph_1.SyntaxKind.SyntaxList)) {
|
|
46
|
+
return (0, exports.getRecursiveNodeShape)(firstChild.getFirstChild());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return (0, exports.getRecursiveNodeShape)(firstChild);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.getTypeReferenceShape = getTypeReferenceShape;
|
|
53
|
+
const getRecursiveNodeShape = (nodeOrReference) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const typeName = (_a = nodeOrReference.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName();
|
|
56
|
+
if (typeName && OpenApiManager_1.OpenApiManager.getInstance().hasExposedModel(typeName)) {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
role: 'ref',
|
|
60
|
+
shape: typeName,
|
|
61
|
+
optional: false,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
const node = (0, exports.findNodeImplementation)(nodeOrReference);
|
|
66
|
+
const undefinedNode = node.asKind(ts_morph_1.SyntaxKind.UndefinedKeyword);
|
|
67
|
+
if (undefinedNode) {
|
|
68
|
+
return 'undefined';
|
|
69
|
+
}
|
|
70
|
+
const literalNode = node.asKind(ts_morph_1.SyntaxKind.LiteralType);
|
|
71
|
+
if (literalNode) {
|
|
72
|
+
if (literalNode.getFirstChildByKind(ts_morph_1.SyntaxKind.TrueKeyword)) {
|
|
73
|
+
return 'true';
|
|
74
|
+
}
|
|
75
|
+
if (literalNode.getFirstChildByKind(ts_morph_1.SyntaxKind.FalseKeyword)) {
|
|
76
|
+
return 'false';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const booleanLiteralNode = node.asKind(ts_morph_1.SyntaxKind.BooleanKeyword) ||
|
|
80
|
+
node.asKind(ts_morph_1.SyntaxKind.TrueKeyword) ||
|
|
81
|
+
node.asKind(ts_morph_1.SyntaxKind.FalseKeyword);
|
|
82
|
+
if (booleanLiteralNode) {
|
|
83
|
+
return 'boolean';
|
|
84
|
+
}
|
|
85
|
+
const stringLiteralNode = node.asKind(ts_morph_1.SyntaxKind.StringKeyword) || node.asKind(ts_morph_1.SyntaxKind.StringLiteral);
|
|
86
|
+
if (stringLiteralNode) {
|
|
87
|
+
return 'string';
|
|
88
|
+
}
|
|
89
|
+
const numberLiteralNode = node.asKind(ts_morph_1.SyntaxKind.NumberKeyword) || node.asKind(ts_morph_1.SyntaxKind.NumericLiteral);
|
|
90
|
+
if (numberLiteralNode) {
|
|
91
|
+
return 'number';
|
|
92
|
+
}
|
|
93
|
+
const bigIntNode = node.asKind(ts_morph_1.SyntaxKind.BigIntKeyword) || node.asKind(ts_morph_1.SyntaxKind.BigIntLiteral);
|
|
94
|
+
if (bigIntNode) {
|
|
95
|
+
return 'bigint';
|
|
96
|
+
}
|
|
97
|
+
const typeLiteralNode = node.asKind(ts_morph_1.SyntaxKind.TypeLiteral);
|
|
98
|
+
if (typeLiteralNode) {
|
|
99
|
+
const properties = typeLiteralNode
|
|
100
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList)
|
|
101
|
+
.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertySignature);
|
|
102
|
+
const propertyShapes = properties.map((propNode) => {
|
|
103
|
+
const identifier = propNode.getFirstChildByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
104
|
+
const valueNode = (0, exports.findPropertyAssignmentValueNode)(propNode);
|
|
105
|
+
const questionMarkToken = identifier.getNextSiblingIfKind(ts_morph_1.SyntaxKind.QuestionToken);
|
|
106
|
+
return {
|
|
107
|
+
role: 'property',
|
|
108
|
+
identifier: identifier.getText(),
|
|
109
|
+
shape: (0, exports.getRecursiveNodeShape)(valueNode),
|
|
110
|
+
optional: valueNode.getType().isNullable() || !!questionMarkToken,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
return propertyShapes;
|
|
114
|
+
}
|
|
115
|
+
const typeReferenceNode = node.asKind(ts_morph_1.SyntaxKind.TypeReference);
|
|
116
|
+
if (typeReferenceNode) {
|
|
117
|
+
return (0, exports.getRecursiveNodeShape)(typeReferenceNode.getFirstChild());
|
|
118
|
+
}
|
|
119
|
+
const propertyAccessNode = node.asKind(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
120
|
+
if (propertyAccessNode) {
|
|
121
|
+
const lastChild = (0, exports.findNodeImplementation)(node.getLastChild());
|
|
122
|
+
return (0, exports.getProperTypeShape)(lastChild.asKind(ts_morph_1.SyntaxKind.CallExpression).getReturnType(), lastChild);
|
|
123
|
+
}
|
|
124
|
+
const unionTypeNode = node.asKind(ts_morph_1.SyntaxKind.UnionType);
|
|
125
|
+
if (unionTypeNode) {
|
|
126
|
+
return (0, exports.getProperTypeShape)(unionTypeNode.getType(), node);
|
|
127
|
+
}
|
|
128
|
+
const typeQueryNode = node.asKind(ts_morph_1.SyntaxKind.TypeQuery);
|
|
129
|
+
if (typeQueryNode) {
|
|
130
|
+
return (0, exports.getRecursiveNodeShape)(typeQueryNode.getLastChild());
|
|
131
|
+
}
|
|
132
|
+
const qualifiedNameNode = node.asKind(ts_morph_1.SyntaxKind.QualifiedName);
|
|
133
|
+
if (qualifiedNameNode) {
|
|
134
|
+
return (0, exports.getRecursiveNodeShape)(qualifiedNameNode.getLastChild());
|
|
135
|
+
}
|
|
136
|
+
const callExpressionNode = node.asKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
137
|
+
if (callExpressionNode) {
|
|
138
|
+
return (0, exports.getProperTypeShape)(callExpressionNode.getReturnType(), callExpressionNode);
|
|
139
|
+
}
|
|
140
|
+
const awaitExpressionNode = node.asKind(ts_morph_1.SyntaxKind.AwaitExpression);
|
|
141
|
+
if (awaitExpressionNode) {
|
|
142
|
+
return (0, exports.getRecursiveNodeShape)(awaitExpressionNode.getChildAtIndex(1));
|
|
143
|
+
}
|
|
144
|
+
const asExpressionNode = node.asKind(ts_morph_1.SyntaxKind.AsExpression);
|
|
145
|
+
if (asExpressionNode) {
|
|
146
|
+
return (0, exports.getRecursiveNodeShape)(asExpressionNode.getChildAtIndex(2));
|
|
147
|
+
}
|
|
148
|
+
return 'unknown_1';
|
|
149
|
+
};
|
|
150
|
+
exports.getRecursiveNodeShape = getRecursiveNodeShape;
|
|
151
|
+
const getShapeOfValidatorLiteral = (objectLiteralNode) => {
|
|
152
|
+
const syntaxListNode = objectLiteralNode.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
153
|
+
const assignmentNodes = syntaxListNode.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
154
|
+
const properties = assignmentNodes.map((node) => {
|
|
155
|
+
const identifierNode = node.getFirstChild();
|
|
156
|
+
const identifierName = (() => {
|
|
157
|
+
if (identifierNode.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
158
|
+
return identifierNode.getText();
|
|
159
|
+
}
|
|
160
|
+
if (identifierNode.isKind(ts_morph_1.SyntaxKind.StringLiteral)) {
|
|
161
|
+
return identifierNode.getLiteralText();
|
|
162
|
+
}
|
|
163
|
+
return 'unknown_30';
|
|
164
|
+
})();
|
|
165
|
+
const assignmentValueNode = node.getLastChild();
|
|
166
|
+
const innerLiteralNode = (0, exports.findNodeImplementation)(assignmentValueNode);
|
|
167
|
+
return {
|
|
168
|
+
role: 'property',
|
|
169
|
+
identifier: identifierName,
|
|
170
|
+
shape: (0, exports.getValidatorPropertyShape)(innerLiteralNode),
|
|
171
|
+
optional: (0, exports.getValidatorPropertyOptionality)(innerLiteralNode),
|
|
172
|
+
description: (0, exports.getValidatorPropertyStringValue)(innerLiteralNode, 'description'),
|
|
173
|
+
errorMessage: (0, exports.getValidatorPropertyStringValue)(innerLiteralNode, 'errorMessage'),
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
return properties || [];
|
|
177
|
+
};
|
|
178
|
+
exports.getShapeOfValidatorLiteral = getShapeOfValidatorLiteral;
|
|
179
|
+
const getValidatorPropertyShape = (innerLiteralNode) => {
|
|
180
|
+
var _a;
|
|
181
|
+
const inlineValidatorAsExpression = innerLiteralNode
|
|
182
|
+
.getParent()
|
|
183
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.AsExpression);
|
|
184
|
+
if (inlineValidatorAsExpression) {
|
|
185
|
+
const typeReference = inlineValidatorAsExpression.getLastChildByKind(ts_morph_1.SyntaxKind.TypeReference);
|
|
186
|
+
return (0, exports.getTypeReferenceShape)(typeReference);
|
|
187
|
+
}
|
|
188
|
+
const childTypeReferenceNode = innerLiteralNode.getParent().getFirstChildByKind(ts_morph_1.SyntaxKind.TypeReference);
|
|
189
|
+
if (childTypeReferenceNode) {
|
|
190
|
+
return (0, exports.getTypeReferenceShape)(childTypeReferenceNode);
|
|
191
|
+
}
|
|
192
|
+
if (innerLiteralNode.getParent().getChildrenOfKind(ts_morph_1.SyntaxKind.SyntaxList).length >= 2) {
|
|
193
|
+
const typeNode = innerLiteralNode
|
|
194
|
+
.getParent()
|
|
195
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList)
|
|
196
|
+
.getFirstChild();
|
|
197
|
+
return (0, exports.getRecursiveNodeShape)(typeNode);
|
|
198
|
+
}
|
|
199
|
+
const childCallExpressionNode = innerLiteralNode.getParent().getFirstChildByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
200
|
+
if (childCallExpressionNode) {
|
|
201
|
+
const callExpressionArgument = (0, exports.findNodeImplementation)(childCallExpressionNode.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList).getFirstChild());
|
|
202
|
+
const typeReferenceNode = callExpressionArgument
|
|
203
|
+
.getParent()
|
|
204
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.TypeReference);
|
|
205
|
+
if (typeReferenceNode) {
|
|
206
|
+
return (0, exports.getProperTypeShape)(typeReferenceNode.getType(), typeReferenceNode, []);
|
|
207
|
+
}
|
|
208
|
+
const thingyNode = callExpressionArgument
|
|
209
|
+
.getParent()
|
|
210
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
211
|
+
if (thingyNode) {
|
|
212
|
+
return (0, exports.getValidatorPropertyShape)(thingyNode);
|
|
213
|
+
}
|
|
214
|
+
if (callExpressionArgument.getKind() === ts_morph_1.SyntaxKind.CallExpression) {
|
|
215
|
+
return (0, exports.getValidatorPropertyShape)(callExpressionArgument);
|
|
216
|
+
}
|
|
217
|
+
if (callExpressionArgument.getKind() === ts_morph_1.SyntaxKind.IntersectionType) {
|
|
218
|
+
return (0, exports.getValidatorPropertyShape)(callExpressionArgument);
|
|
219
|
+
}
|
|
220
|
+
return 'unknown_3';
|
|
221
|
+
}
|
|
222
|
+
const innerNodePropertyAssignments = innerLiteralNode
|
|
223
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList)
|
|
224
|
+
.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
225
|
+
const parsePropertyAssignment = innerNodePropertyAssignments.find((prop) => {
|
|
226
|
+
var _a;
|
|
227
|
+
return ((_a = prop.getFirstChildByKind(ts_morph_1.SyntaxKind.Identifier)) === null || _a === void 0 ? void 0 : _a.getText()) === 'parse';
|
|
228
|
+
});
|
|
229
|
+
if (parsePropertyAssignment) {
|
|
230
|
+
const returnType = (0, exports.findPropertyAssignmentValueNode)(parsePropertyAssignment)
|
|
231
|
+
.asKind(ts_morph_1.SyntaxKind.ArrowFunction)
|
|
232
|
+
.getReturnType();
|
|
233
|
+
return (0, exports.getProperTypeShape)(returnType, parsePropertyAssignment);
|
|
234
|
+
}
|
|
235
|
+
const importTypeNode = (_a = innerLiteralNode
|
|
236
|
+
.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList)) === null || _a === void 0 ? void 0 : _a.getFirstChildByKind(ts_morph_1.SyntaxKind.ImportType);
|
|
237
|
+
if (importTypeNode) {
|
|
238
|
+
const indexOfGreaterThanToken = importTypeNode
|
|
239
|
+
.getLastChildByKind(ts_morph_1.SyntaxKind.GreaterThanToken)
|
|
240
|
+
.getChildIndex();
|
|
241
|
+
const targetSyntaxList = importTypeNode.getChildAtIndex(indexOfGreaterThanToken - 1);
|
|
242
|
+
return (0, exports.getRecursiveNodeShape)(targetSyntaxList.getFirstChild());
|
|
243
|
+
}
|
|
244
|
+
return 'unknown_2';
|
|
245
|
+
};
|
|
246
|
+
exports.getValidatorPropertyShape = getValidatorPropertyShape;
|
|
247
|
+
const getValidatorPropertyOptionality = (node) => {
|
|
248
|
+
const callExpressionNode = node.asKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
249
|
+
if (callExpressionNode) {
|
|
250
|
+
const identifierNode = callExpressionNode.getFirstChildByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
251
|
+
if ((identifierNode === null || identifierNode === void 0 ? void 0 : identifierNode.getText()) === 'OptionalParam') {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
else if ((identifierNode === null || identifierNode === void 0 ? void 0 : identifierNode.getText()) === 'RequiredParam') {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const syntaxListNode = callExpressionNode.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
258
|
+
const literalExpression = (0, exports.findNodeImplementation)(syntaxListNode.getFirstChild());
|
|
259
|
+
return (0, exports.getValidatorPropertyOptionality)(literalExpression);
|
|
260
|
+
}
|
|
261
|
+
const syntaxListNode = node.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
262
|
+
const assignmentNodes = syntaxListNode.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
263
|
+
return assignmentNodes.some((node) => {
|
|
264
|
+
const identifierNode = node.getFirstDescendantByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
265
|
+
const identifierName = identifierNode.getText();
|
|
266
|
+
if (identifierName === 'optional') {
|
|
267
|
+
const value = (0, exports.findPropertyAssignmentValueNode)(node);
|
|
268
|
+
return value.getKind() === ts_morph_1.SyntaxKind.TrueKeyword;
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
exports.getValidatorPropertyOptionality = getValidatorPropertyOptionality;
|
|
274
|
+
const getValidatorPropertyStringValue = (nodeOrReference, name) => {
|
|
275
|
+
const node = (0, exports.findNodeImplementation)(nodeOrReference);
|
|
276
|
+
const callExpressionNode = node.asKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
277
|
+
if (callExpressionNode) {
|
|
278
|
+
const targetChild = callExpressionNode.getLastChildByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
279
|
+
return (0, exports.getValidatorPropertyStringValue)(targetChild, name);
|
|
280
|
+
}
|
|
281
|
+
const syntaxListNode = node.asKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
282
|
+
if (syntaxListNode) {
|
|
283
|
+
const children = syntaxListNode.getChildren().map((c) => (0, exports.getValidatorPropertyStringValue)(c, name));
|
|
284
|
+
return children.find((value) => !!value && value !== 'unknown_25') || '';
|
|
285
|
+
}
|
|
286
|
+
const objectLiteralNode = node.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
287
|
+
if (objectLiteralNode) {
|
|
288
|
+
const values = (0, exports.getValuesOfObjectLiteral)(objectLiteralNode);
|
|
289
|
+
const targetValue = values.find((value) => value.identifier === name);
|
|
290
|
+
if (!targetValue) {
|
|
291
|
+
return '';
|
|
292
|
+
}
|
|
293
|
+
if (Array.isArray(targetValue.value)) {
|
|
294
|
+
return 'array';
|
|
295
|
+
}
|
|
296
|
+
return targetValue.value || '';
|
|
297
|
+
}
|
|
298
|
+
const intersectionTypeNode = node.asKind(ts_morph_1.SyntaxKind.IntersectionType);
|
|
299
|
+
if (intersectionTypeNode) {
|
|
300
|
+
return (intersectionTypeNode
|
|
301
|
+
.getTypeNodes()
|
|
302
|
+
.flatMap((t) => (0, exports.getValidatorPropertyStringValue)(t, name))
|
|
303
|
+
.filter((v) => !!v && v !== 'unknown_25')[0] || 'unknown_27');
|
|
304
|
+
}
|
|
305
|
+
const typeLiteralNode = node.asKind(ts_morph_1.SyntaxKind.TypeLiteral);
|
|
306
|
+
if (typeLiteralNode) {
|
|
307
|
+
return (0, exports.getValidatorPropertyStringValue)(typeLiteralNode.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList), name);
|
|
308
|
+
}
|
|
309
|
+
const propertySignatureNode = node.asKind(ts_morph_1.SyntaxKind.PropertySignature);
|
|
310
|
+
if (propertySignatureNode) {
|
|
311
|
+
const identifier = node.getFirstDescendantByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
312
|
+
if (identifier.getText() === name) {
|
|
313
|
+
const targetNode = (0, exports.findPropertyAssignmentValueNode)(propertySignatureNode).getFirstDescendantByKind(ts_morph_1.SyntaxKind.StringLiteral);
|
|
314
|
+
return targetNode.getLiteralText();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return 'unknown_25';
|
|
318
|
+
};
|
|
319
|
+
exports.getValidatorPropertyStringValue = getValidatorPropertyStringValue;
|
|
320
|
+
const isPromise = (type) => {
|
|
321
|
+
const symbol = type.getSymbol();
|
|
322
|
+
if (!type.isObject() || !symbol) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
const args = type.getTypeArguments();
|
|
326
|
+
return symbol.getName() === 'Promise' && args.length === 1;
|
|
327
|
+
};
|
|
328
|
+
const getProperTypeShape = (typeOrPromise, atLocation, stack = []) => {
|
|
329
|
+
var _a;
|
|
330
|
+
const typeName = (_a = typeOrPromise.getAliasSymbol()) === null || _a === void 0 ? void 0 : _a.getName();
|
|
331
|
+
if (typeName && OpenApiManager_1.OpenApiManager.getInstance().hasExposedModel(typeName)) {
|
|
332
|
+
return [
|
|
333
|
+
{
|
|
334
|
+
role: 'ref',
|
|
335
|
+
shape: typeName,
|
|
336
|
+
optional: false,
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
const type = isPromise(typeOrPromise) ? typeOrPromise.getTypeArguments()[0] : typeOrPromise;
|
|
341
|
+
if (stack.some((previousType) => previousType === type)) {
|
|
342
|
+
return 'circular';
|
|
343
|
+
}
|
|
344
|
+
const nextStack = stack.concat(type);
|
|
345
|
+
if (type.getText() === 'void') {
|
|
346
|
+
return 'void';
|
|
347
|
+
}
|
|
348
|
+
if (type.isAny()) {
|
|
349
|
+
return 'any';
|
|
350
|
+
}
|
|
351
|
+
if (type.isNull()) {
|
|
352
|
+
return 'null';
|
|
353
|
+
}
|
|
354
|
+
if (type.isUndefined()) {
|
|
355
|
+
return 'undefined';
|
|
356
|
+
}
|
|
357
|
+
if (type.isBoolean() || type.isBooleanLiteral()) {
|
|
358
|
+
return 'boolean';
|
|
359
|
+
}
|
|
360
|
+
if (type.isStringLiteral()) {
|
|
361
|
+
return [
|
|
362
|
+
{
|
|
363
|
+
role: 'literal_string',
|
|
364
|
+
shape: String(type.getLiteralValue()),
|
|
365
|
+
optional: false,
|
|
366
|
+
},
|
|
367
|
+
];
|
|
368
|
+
}
|
|
369
|
+
if (type.isNumberLiteral()) {
|
|
370
|
+
return [
|
|
371
|
+
{
|
|
372
|
+
role: 'literal_number',
|
|
373
|
+
shape: String(type.getLiteralValue()),
|
|
374
|
+
optional: false,
|
|
375
|
+
},
|
|
376
|
+
];
|
|
377
|
+
}
|
|
378
|
+
if (type.isString() || type.isTemplateLiteral()) {
|
|
379
|
+
return 'string';
|
|
380
|
+
}
|
|
381
|
+
if (type.isNumber()) {
|
|
382
|
+
return 'number';
|
|
383
|
+
}
|
|
384
|
+
if (type.getText() === 'bigint') {
|
|
385
|
+
return 'bigint';
|
|
386
|
+
}
|
|
387
|
+
if (type.isTuple()) {
|
|
388
|
+
return [
|
|
389
|
+
{
|
|
390
|
+
role: 'tuple',
|
|
391
|
+
shape: type.getTupleElements().map((t) => ({
|
|
392
|
+
role: 'tuple_entry',
|
|
393
|
+
shape: (0, exports.getProperTypeShape)(t, atLocation, nextStack),
|
|
394
|
+
optional: false,
|
|
395
|
+
})),
|
|
396
|
+
optional: false,
|
|
397
|
+
},
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
if (type.isArray()) {
|
|
401
|
+
return [
|
|
402
|
+
{
|
|
403
|
+
role: 'array',
|
|
404
|
+
shape: (0, exports.getProperTypeShape)(type.getArrayElementType(), atLocation, nextStack),
|
|
405
|
+
optional: false,
|
|
406
|
+
},
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
if (type.isObject() && type.getProperties().length === 0) {
|
|
410
|
+
const targetType = type.getAliasTypeArguments()[1];
|
|
411
|
+
return [
|
|
412
|
+
{
|
|
413
|
+
role: 'record',
|
|
414
|
+
shape: (0, exports.getProperTypeShape)(targetType, atLocation, nextStack),
|
|
415
|
+
optional: false,
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
if (type.isObject()) {
|
|
420
|
+
if (type.getText() === 'Date') {
|
|
421
|
+
return 'Date';
|
|
422
|
+
}
|
|
423
|
+
return type
|
|
424
|
+
.getProperties()
|
|
425
|
+
.map((prop) => {
|
|
426
|
+
const valueDeclaration = prop.getValueDeclaration() || prop.getDeclarations()[0];
|
|
427
|
+
if (!valueDeclaration) {
|
|
428
|
+
return {
|
|
429
|
+
role: 'property',
|
|
430
|
+
identifier: prop.getName(),
|
|
431
|
+
shape: (0, exports.getProperTypeShape)(prop.getTypeAtLocation(atLocation), atLocation, nextStack),
|
|
432
|
+
optional: false,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
const valueDeclarationNode = valueDeclaration.asKind(ts_morph_1.SyntaxKind.PropertySignature) ||
|
|
436
|
+
valueDeclaration.asKind(ts_morph_1.SyntaxKind.PropertyAssignment) ||
|
|
437
|
+
valueDeclaration.asKind(ts_morph_1.SyntaxKind.ShorthandPropertyAssignment);
|
|
438
|
+
if (!valueDeclarationNode) {
|
|
439
|
+
return {
|
|
440
|
+
role: 'property',
|
|
441
|
+
identifier: prop.getName(),
|
|
442
|
+
shape: (0, exports.getProperTypeShape)(prop.getTypeAtLocation(atLocation), atLocation, nextStack),
|
|
443
|
+
optional: false,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
const isOptional = prop.getTypeAtLocation(atLocation).isNullable();
|
|
447
|
+
const shape = (0, exports.getProperTypeShape)(prop.getTypeAtLocation(atLocation), atLocation, nextStack);
|
|
448
|
+
return {
|
|
449
|
+
role: 'property',
|
|
450
|
+
identifier: prop.getName(),
|
|
451
|
+
shape: shape,
|
|
452
|
+
optional: isOptional,
|
|
453
|
+
};
|
|
454
|
+
})
|
|
455
|
+
.filter((val) => val.shape !== 'undefined');
|
|
456
|
+
}
|
|
457
|
+
if (type.isUnion()) {
|
|
458
|
+
const unfilteredShapes = type.getUnionTypes().map((type) => ({
|
|
459
|
+
role: 'union_entry',
|
|
460
|
+
shape: (0, exports.getProperTypeShape)(type, atLocation, nextStack),
|
|
461
|
+
optional: false,
|
|
462
|
+
}));
|
|
463
|
+
const dedupedShapes = unfilteredShapes.filter((type, index, arr) => !arr.find((dup, dupIndex) => dup.shape === type.shape && dupIndex > index));
|
|
464
|
+
const isNullable = dedupedShapes.some((shape) => shape.shape === 'undefined');
|
|
465
|
+
const shapes = dedupedShapes.filter((shape) => shape.shape !== 'undefined');
|
|
466
|
+
if (shapes.length === 1) {
|
|
467
|
+
return shapes[0].shape;
|
|
468
|
+
}
|
|
469
|
+
return [
|
|
470
|
+
{
|
|
471
|
+
role: 'union',
|
|
472
|
+
shape: shapes,
|
|
473
|
+
optional: isNullable,
|
|
474
|
+
},
|
|
475
|
+
];
|
|
476
|
+
}
|
|
477
|
+
if (type.isIntersection()) {
|
|
478
|
+
const children = type.getIntersectionTypes();
|
|
479
|
+
const shapesOfChildren = children
|
|
480
|
+
.map((child) => (0, exports.getProperTypeShape)(child, atLocation, nextStack))
|
|
481
|
+
.filter((shape) => typeof shape !== 'string');
|
|
482
|
+
return shapesOfChildren.reduce((total, current) => [...total, ...current], []);
|
|
483
|
+
}
|
|
484
|
+
return 'unknown_5';
|
|
485
|
+
};
|
|
486
|
+
exports.getProperTypeShape = getProperTypeShape;
|
|
487
|
+
const getLiteralValueOfNode = (node) => {
|
|
488
|
+
if (node.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
489
|
+
return getLiteralValueOfNode((0, exports.findNodeImplementation)(node));
|
|
490
|
+
}
|
|
491
|
+
else if (node.isKind(ts_morph_1.SyntaxKind.StringLiteral)) {
|
|
492
|
+
return node.getLiteralValue();
|
|
493
|
+
}
|
|
494
|
+
else if (node.isKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression)) {
|
|
495
|
+
return node.forEachChildAsArray().map((child) => getLiteralValueOfNode(child));
|
|
496
|
+
}
|
|
497
|
+
else if (node.isKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)) {
|
|
498
|
+
return getLiteralValueOfNode((0, exports.findPropertyAssignmentValueNode)(node));
|
|
499
|
+
}
|
|
500
|
+
else if (node.isKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)) {
|
|
501
|
+
return (0, exports.getValuesOfObjectLiteral)(node);
|
|
502
|
+
}
|
|
503
|
+
return 'unknown_6';
|
|
504
|
+
};
|
|
505
|
+
const getValuesOfObjectLiteral = (objectLiteralNode) => {
|
|
506
|
+
const syntaxListNode = objectLiteralNode.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
507
|
+
const assignmentNodes = syntaxListNode.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
508
|
+
const properties = assignmentNodes.map((node) => {
|
|
509
|
+
const identifierNode = node.getFirstDescendantByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
510
|
+
const identifierName = identifierNode.getText();
|
|
511
|
+
const assignmentValueNode = node.getLastChild();
|
|
512
|
+
const targetNode = (0, exports.findNodeImplementation)(assignmentValueNode);
|
|
513
|
+
const value = getLiteralValueOfNode(targetNode);
|
|
514
|
+
return {
|
|
515
|
+
identifier: identifierName,
|
|
516
|
+
value,
|
|
517
|
+
};
|
|
518
|
+
});
|
|
519
|
+
return properties || [];
|
|
520
|
+
};
|
|
521
|
+
exports.getValuesOfObjectLiteral = getValuesOfObjectLiteral;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEndpoint.d.ts","sourceRoot":"","sources":["../../../../src/openapi/analyzerModule/parseEndpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAE,MAAM,UAAU,CAAA;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAWvC,eAAO,MAAM,aAAa,SAAU,KAAK,OAAO,CAAC,kBAAkB,MAAM,iBAqHxE,CAAA"}
|