ondc-code-generator 0.0.1

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 (139) hide show
  1. package/.idea/code-generator.iml +12 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/LICENSE +21 -0
  5. package/README.md +0 -0
  6. package/custom-loader.js +4 -0
  7. package/dist/Generator/config-compiler.js +53 -0
  8. package/dist/Generator/config-validator.js +21 -0
  9. package/dist/Generator/generators/classes/abstract-generator.js +16 -0
  10. package/dist/Generator/generators/documentation/markdown-message-generator.js +37 -0
  11. package/dist/Generator/generators/documentation/md-generator.js +57 -0
  12. package/dist/Generator/generators/markdown-message-generator.js +25 -0
  13. package/dist/Generator/generators/python/py-generator.js +1 -0
  14. package/dist/Generator/generators/typescript/templates/json-path-utils.js +15 -0
  15. package/dist/Generator/generators/typescript/templates/validation-utils.js +91 -0
  16. package/dist/Generator/generators/typescript/ts-ast.js +50 -0
  17. package/dist/Generator/generators/typescript/ts-generator.js +184 -0
  18. package/dist/Generator/pipline.js +1 -0
  19. package/dist/Generator/validators/abstract-validator.js +6 -0
  20. package/dist/Generator/validators/config-validator.js +32 -0
  21. package/dist/Generator/validators/session-data-config/session-data-validator.js +35 -0
  22. package/dist/Generator/validators/tests-config/sub-validations.js +194 -0
  23. package/dist/Generator/validators/tests-config/test-list-validator.js +36 -0
  24. package/dist/Generator/validators/tests-config/test-validator.js +24 -0
  25. package/dist/Generator/validators/validation-error.js +9 -0
  26. package/dist/constants/operations.js +17 -0
  27. package/dist/constants/syntax.js +75 -0
  28. package/dist/index.js +39 -0
  29. package/dist/services/rename-later/main.js +1 -0
  30. package/dist/services/rename-later/parser.js +22 -0
  31. package/dist/services/rename-later/tokens.js +32 -0
  32. package/dist/services/rename-later/tokens1.js +33 -0
  33. package/dist/services/return-complier/ast-functions/compile-to-markdown.js +66 -0
  34. package/dist/services/return-complier/ast-functions/semantic-validations.js +30 -0
  35. package/dist/services/return-complier/ast.js +92 -0
  36. package/dist/services/return-complier/combined.js +7 -0
  37. package/dist/services/return-complier/parser.js +95 -0
  38. package/dist/services/return-complier/tokens.js +144 -0
  39. package/dist/services/schema-service.js +29 -0
  40. package/dist/types/build.js +1 -0
  41. package/dist/types/compiler-types.js +4 -0
  42. package/dist/types/config-types.js +1 -0
  43. package/dist/types/error-codes.js +1 -0
  44. package/dist/types/general-types.js +1 -0
  45. package/dist/utils/config-utils/json-schema-utils.js +91 -0
  46. package/dist/utils/config-utils/yaml.js +16 -0
  47. package/dist/utils/file-system.js +1 -0
  48. package/dist/utils/fs-utils.js +20 -0
  49. package/dist/utils/general-utils/string-utils.js +56 -0
  50. package/dist/utils/general-utils/test-object-utils.js +12 -0
  51. package/dist/utils/general-utils/validation-utils.js +21 -0
  52. package/dist/utils/json-path-utils/extract-string-paths.js +113 -0
  53. package/dist/utils/json-path-utils/paths.js +46 -0
  54. package/dist/utils/logger.js +41 -0
  55. package/docs/error-gen.md +33 -0
  56. package/docs/return-grammer.md +23 -0
  57. package/docs/sampleConfig.md +39 -0
  58. package/generated/L1-validations/api-tests/cancel.ts +569 -0
  59. package/generated/L1-validations/api-tests/confirm.ts +1162 -0
  60. package/generated/L1-validations/api-tests/init.ts +1063 -0
  61. package/generated/L1-validations/api-tests/on_cancel.ts +2069 -0
  62. package/generated/L1-validations/api-tests/on_confirm.ts +2219 -0
  63. package/generated/L1-validations/api-tests/on_init.ts +1949 -0
  64. package/generated/L1-validations/api-tests/on_search.ts +1574 -0
  65. package/generated/L1-validations/api-tests/on_select.ts +1723 -0
  66. package/generated/L1-validations/api-tests/on_status.ts +2221 -0
  67. package/generated/L1-validations/api-tests/on_update.ts +1969 -0
  68. package/generated/L1-validations/api-tests/search.ts +695 -0
  69. package/generated/L1-validations/api-tests/select.ts +994 -0
  70. package/generated/L1-validations/api-tests/status.ts +443 -0
  71. package/generated/L1-validations/api-tests/update.ts +898 -0
  72. package/generated/L1-validations/error.ts +64 -0
  73. package/generated/L1-validations/index.ts +138 -0
  74. package/generated/L1-validations/page/index.html +2118 -0
  75. package/generated/L1-validations/page/style.css +225 -0
  76. package/generated/L1-validations/readme.md +1779 -0
  77. package/generated/L1-validations/types/test-config.ts +27 -0
  78. package/generated/L1-validations/utils/json-path-utils.ts +17 -0
  79. package/generated/L1-validations/utils/validation-utils.ts +116 -0
  80. package/generated-structure/api-tests/search.ts +24 -0
  81. package/generated-structure/error.ts +0 -0
  82. package/generated-structure/index.ts +0 -0
  83. package/generated-structure/types/test-config.ts +21 -0
  84. package/nodemon.json +5 -0
  85. package/package.json +40 -0
  86. package/samples/build.yaml +24799 -0
  87. package/samples/output.md +91 -0
  88. package/samples/output.ts +27 -0
  89. package/samples/selections.json +216 -0
  90. package/samples/validation-config.json +3422 -0
  91. package/samples/x-validations.yaml +2893 -0
  92. package/src/constants/operations.ts +19 -0
  93. package/src/constants/syntax.ts +81 -0
  94. package/src/example.ts +25 -0
  95. package/src/generator/config-compiler.ts +122 -0
  96. package/src/generator/generators/classes/abstract-generator.ts +29 -0
  97. package/src/generator/generators/documentation/markdown-message-generator.ts +43 -0
  98. package/src/generator/generators/documentation/md-generator.ts +76 -0
  99. package/src/generator/generators/documentation/templates/index.mustache +36 -0
  100. package/src/generator/generators/documentation/templates/style.css +204 -0
  101. package/src/generator/generators/python/py-generator.ts +0 -0
  102. package/src/generator/generators/typescript/templates/api-test.mustache +7 -0
  103. package/src/generator/generators/typescript/templates/json-path-utils.ts +17 -0
  104. package/src/generator/generators/typescript/templates/schema-template.mustache +18 -0
  105. package/src/generator/generators/typescript/templates/test-config.mustache +28 -0
  106. package/src/generator/generators/typescript/templates/test-object.mustache +20 -0
  107. package/src/generator/generators/typescript/templates/validation-code.mustache +39 -0
  108. package/src/generator/generators/typescript/templates/validation-utils.ts +117 -0
  109. package/src/generator/generators/typescript/ts-ast.ts +72 -0
  110. package/src/generator/generators/typescript/ts-generator.ts +275 -0
  111. package/src/generator/validators/abstract-validator.ts +23 -0
  112. package/src/generator/validators/config-validator.ts +55 -0
  113. package/src/generator/validators/session-data-config/session-data-validator.ts +58 -0
  114. package/src/generator/validators/tests-config/sub-validations.ts +302 -0
  115. package/src/generator/validators/tests-config/test-list-validator.ts +59 -0
  116. package/src/generator/validators/tests-config/test-validator.ts +69 -0
  117. package/src/index.ts +2 -0
  118. package/src/services/return-complier/ast-functions/compile-to-markdown.ts +152 -0
  119. package/src/services/return-complier/ast-functions/semantic-validations.ts +44 -0
  120. package/src/services/return-complier/ast.ts +147 -0
  121. package/src/services/return-complier/combined.ts +8 -0
  122. package/src/services/return-complier/parser.ts +128 -0
  123. package/src/services/return-complier/tokens.ts +184 -0
  124. package/src/services/schema-service.ts +42 -0
  125. package/src/types/build.ts +51 -0
  126. package/src/types/compiler-types.ts +3 -0
  127. package/src/types/config-types.ts +27 -0
  128. package/src/types/error-codes.ts +6 -0
  129. package/src/types/general-types.ts +2 -0
  130. package/src/utils/config-utils/json-schema-utils.ts +150 -0
  131. package/src/utils/config-utils/yaml.ts +17 -0
  132. package/src/utils/fs-utils.ts +32 -0
  133. package/src/utils/general-utils/string-utils.ts +76 -0
  134. package/src/utils/general-utils/test-object-utils.ts +14 -0
  135. package/src/utils/general-utils/validation-utils.ts +30 -0
  136. package/src/utils/json-path-utils/extract-string-paths.ts +139 -0
  137. package/src/utils/json-path-utils/paths.ts +44 -0
  138. package/src/utils/logger.ts +53 -0
  139. package/tsconfig.json +17 -0
@@ -0,0 +1,147 @@
1
+ import { CstNode } from "chevrotain";
2
+ import { ReturnParserInstance } from "./parser.js";
3
+
4
+ export interface AstNode {
5
+ type:
6
+ | "returnStatement"
7
+ | "binaryOperator"
8
+ | "notOperator"
9
+ | "customBinaryFunction"
10
+ | "customUniaryFunction"
11
+ | "identifier";
12
+ }
13
+
14
+ export interface ReturnStatementNode extends AstNode {
15
+ expression: AstNode;
16
+ }
17
+
18
+ export interface BinaryOperatorNode extends AstNode {
19
+ operator: "&&" | "||";
20
+ lhs: AstNode;
21
+ rhs: AstNode;
22
+ }
23
+
24
+ export interface NotOperatorNode extends AstNode {
25
+ operator: "!";
26
+ expression: AstNode;
27
+ }
28
+
29
+ export interface CustomBinaryFunction extends AstNode {
30
+ customFunction: string;
31
+ lhs: IdentifierNode;
32
+ rhs: IdentifierNode;
33
+ }
34
+
35
+ export interface CustomUniaryFunction extends AstNode {
36
+ customFunction: string;
37
+ expression: IdentifierNode;
38
+ }
39
+
40
+ export interface IdentifierNode extends AstNode {
41
+ name: string;
42
+ }
43
+
44
+ export class AstBuilder extends ReturnParserInstance.getBaseCstVisitorConstructor() {
45
+ constructor() {
46
+ super();
47
+ this.validateVisitor();
48
+ }
49
+
50
+ returnStatement(ctx: any): ReturnStatementNode {
51
+ return {
52
+ type: "returnStatement",
53
+ expression: this.visit(ctx.orExpression),
54
+ };
55
+ }
56
+
57
+ orExpression(ctx: any): BinaryOperatorNode | AstNode {
58
+ let left = this.visit(ctx.lhs);
59
+ if (!ctx.operator) return left;
60
+
61
+ if (ctx.operator) {
62
+ for (let i = 0; i < ctx.operator.length; i++) {
63
+ left = {
64
+ type: "binaryOperator",
65
+ operator: ctx.operator[i].image,
66
+ lhs: left,
67
+ rhs: this.visit(ctx.rhs[i]),
68
+ };
69
+ }
70
+ }
71
+ return left;
72
+ }
73
+
74
+ andExpression(ctx: any): BinaryOperatorNode | AstNode {
75
+ let left = this.visit(ctx.lhs);
76
+ if (!ctx.operator) return left;
77
+
78
+ if (ctx.operator) {
79
+ for (let i = 0; i < ctx.operator.length; i++) {
80
+ left = {
81
+ type: "binaryOperator",
82
+ operator: ctx.operator[i].image,
83
+ lhs: left,
84
+ rhs: this.visit(ctx.rhs[i]),
85
+ };
86
+ }
87
+ }
88
+ return left;
89
+ }
90
+
91
+ notExpression(ctx: any): NotOperatorNode | AstNode {
92
+ if (ctx.operator) {
93
+ return {
94
+ type: "notOperator",
95
+ operator: ctx.operator[0].image,
96
+ expression: this.visit(ctx.parentheisizedExpression),
97
+ };
98
+ }
99
+ return this.visit(ctx.primaryExpression);
100
+ }
101
+
102
+ primaryExpression(
103
+ ctx: any
104
+ ): ReturnStatementNode | CustomBinaryFunction | CustomUniaryFunction {
105
+ if (ctx.parentheisizedExpression) {
106
+ return this.visit(ctx.parentheisizedExpression);
107
+ }
108
+ if (ctx.atomicCustomExpression) {
109
+ return this.visit(ctx.atomicCustomExpression);
110
+ }
111
+ throw new Error("Invalid primary expression");
112
+ }
113
+
114
+ parentheisizedExpression(ctx: any): ReturnStatementNode {
115
+ return this.visit(ctx.returnStatement);
116
+ }
117
+
118
+ atomicCustomExpression(
119
+ ctx: any
120
+ ): CustomBinaryFunction | CustomUniaryFunction {
121
+ if (ctx.rhs) {
122
+ return {
123
+ type: "customBinaryFunction",
124
+ customFunction: ctx.function[0].image,
125
+ lhs: this.visitIdentifier(ctx.lhs[0]),
126
+ rhs: this.visitIdentifier(ctx.rhs[0]),
127
+ };
128
+ }
129
+ return {
130
+ type: "customUniaryFunction",
131
+ customFunction: ctx.function[0].image,
132
+ expression: this.visitIdentifier(ctx.lhs[0]),
133
+ };
134
+ }
135
+
136
+ visitIdentifier(token: any): IdentifierNode {
137
+ return {
138
+ type: "identifier",
139
+ name: token.image,
140
+ };
141
+ }
142
+ }
143
+
144
+ export function buildAst(cst: CstNode): AstNode {
145
+ const astBuilder = new AstBuilder();
146
+ return astBuilder.visit(cst);
147
+ }
@@ -0,0 +1,8 @@
1
+ import { AstNode, buildAst } from "./ast.js";
2
+ import { parseReturnInput } from "./parser.js";
3
+
4
+ export function buildAstFromInput(input: string): AstNode {
5
+ const cst = parseReturnInput(input);
6
+ const ast = buildAst(cst);
7
+ return ast;
8
+ }
@@ -0,0 +1,128 @@
1
+ import { CstNode, CstParser } from "chevrotain";
2
+ import {
3
+ allTokens,
4
+ AndOperator,
5
+ CustomBinaryFunctions,
6
+ CustomUniaryFunctions,
7
+ Identifier,
8
+ LParen,
9
+ NotOperator,
10
+ OrOperator,
11
+ ReturnTokenize,
12
+ RParen,
13
+ } from "./tokens.js";
14
+
15
+ class ReturnParser extends CstParser {
16
+ public returnStatement!: () => CstNode;
17
+ public orExpression!: () => CstNode;
18
+ public andExpression!: () => CstNode;
19
+ public notExpression!: () => CstNode;
20
+ public primaryExpression!: () => CstNode;
21
+ public atomicCustomExpression!: () => CstNode;
22
+ public parentheisizedExpression!: () => CstNode;
23
+ constructor() {
24
+ super(allTokens);
25
+ const $ = this;
26
+
27
+ $.RULE("returnStatement", () => {
28
+ $.SUBRULE($.orExpression);
29
+ });
30
+
31
+ $.RULE("orExpression", () => {
32
+ $.SUBRULE($.andExpression, { LABEL: "lhs" });
33
+ $.MANY(() => {
34
+ $.CONSUME(OrOperator, { LABEL: "operator" });
35
+ $.SUBRULE2($.andExpression, { LABEL: "rhs" });
36
+ });
37
+ });
38
+
39
+ $.RULE("andExpression", () => {
40
+ $.SUBRULE($.notExpression, { LABEL: "lhs" });
41
+ $.MANY(() => {
42
+ $.CONSUME(AndOperator, { LABEL: "operator" });
43
+ $.SUBRULE2($.notExpression, { LABEL: "rhs" });
44
+ });
45
+ });
46
+
47
+ $.notExpression = $.RULE("notExpression", () => {
48
+ $.OR([
49
+ {
50
+ ALT: () => {
51
+ $.CONSUME(NotOperator, { LABEL: "operator" });
52
+ $.SUBRULE($.parentheisizedExpression);
53
+ },
54
+ },
55
+ {
56
+ ALT: () => {
57
+ $.SUBRULE($.primaryExpression);
58
+ },
59
+ },
60
+ ]);
61
+ });
62
+
63
+ $.RULE("primaryExpression", () => {
64
+ $.OR([
65
+ {
66
+ ALT: () => {
67
+ $.SUBRULE($.parentheisizedExpression);
68
+ },
69
+ },
70
+ {
71
+ ALT: () => {
72
+ $.SUBRULE($.atomicCustomExpression);
73
+ },
74
+ },
75
+ ]);
76
+ });
77
+
78
+ $.RULE("parentheisizedExpression", () => {
79
+ $.CONSUME(LParen);
80
+ $.SUBRULE($.returnStatement);
81
+ $.CONSUME(RParen);
82
+ });
83
+
84
+ $.RULE("atomicCustomExpression", () => {
85
+ $.OR([
86
+ {
87
+ ALT: () => {
88
+ $.CONSUME1(Identifier, { LABEL: "lhs" });
89
+ $.CONSUME(CustomBinaryFunctions, { LABEL: "function" });
90
+ $.CONSUME2(Identifier, { LABEL: "rhs" });
91
+ },
92
+ },
93
+ {
94
+ ALT: () => {
95
+ $.CONSUME3(Identifier, { LABEL: "lhs" });
96
+ $.CONSUME(CustomUniaryFunctions, { LABEL: "function" });
97
+ },
98
+ },
99
+ ]);
100
+ });
101
+
102
+ $.performSelfAnalysis();
103
+ }
104
+ }
105
+
106
+ export const ReturnParserInstance = new ReturnParser();
107
+
108
+ export function parseReturnInput(inputText: string) {
109
+ // Step 1: Tokenize the input
110
+ const lexResult = ReturnTokenize(inputText);
111
+
112
+ // Step 3: Set the parser's input
113
+ ReturnParserInstance.input = lexResult.tokens;
114
+
115
+ // Step 4: Parse the input starting from the 'returnStatement' rule
116
+ const cst = ReturnParserInstance.returnStatement();
117
+
118
+ // Step 5: Check for parsing errors
119
+ if (ReturnParserInstance.errors.length > 0) {
120
+ const parseErrors = ReturnParserInstance.errors
121
+ .map((error) => error.message)
122
+ .join("\n");
123
+ throw new Error(`Parsing errors detected:\n${parseErrors}`);
124
+ }
125
+
126
+ // If no errors, return the CST
127
+ return cst;
128
+ }
@@ -0,0 +1,184 @@
1
+ import {
2
+ createToken,
3
+ Lexer,
4
+ ILexerErrorMessageProvider,
5
+ IToken,
6
+ ILexingResult,
7
+ } from "chevrotain";
8
+
9
+ export const Identifier = createToken({
10
+ name: "Identifier",
11
+ pattern: /[a-zA-Z_][a-zA-Z0-9_]*/,
12
+ });
13
+
14
+ export const CustomBinaryFunctions = createToken({
15
+ name: "CustomFunctions",
16
+ pattern: Lexer.NA,
17
+ });
18
+
19
+ export const CustomUniaryFunctions = createToken({
20
+ name: "CustomUniaryFunctions",
21
+ pattern: Lexer.NA,
22
+ });
23
+
24
+ export const AllIn = createToken({
25
+ name: "AllIn",
26
+ pattern: /all in/i,
27
+ categories: CustomBinaryFunctions,
28
+ label: "all in",
29
+ });
30
+
31
+ export const AnyIn = createToken({
32
+ name: "AnyIn",
33
+ pattern: /any in/i,
34
+ categories: CustomBinaryFunctions,
35
+ label: "any in",
36
+ });
37
+
38
+ export const AreUnique = createToken({
39
+ name: "AreUnique",
40
+ pattern: /are unique/i,
41
+ categories: CustomUniaryFunctions,
42
+ label: "are unique",
43
+ });
44
+
45
+ export const ArePresent = createToken({
46
+ name: "ArePresent",
47
+ pattern: /are present/i,
48
+ categories: CustomUniaryFunctions,
49
+ label: "are present",
50
+ });
51
+
52
+ export const FollowRegex = createToken({
53
+ name: "FollowRegex",
54
+ pattern: /follow regex/i,
55
+ categories: CustomBinaryFunctions,
56
+ label: "follow regex",
57
+ });
58
+
59
+ export const NoneIn = createToken({
60
+ name: "NoneIn",
61
+ pattern: /none in/i,
62
+ categories: CustomBinaryFunctions,
63
+ label: "none in",
64
+ });
65
+
66
+ export const EqualTo = createToken({
67
+ name: "EqualTo",
68
+ pattern: /equal to/i,
69
+ categories: CustomBinaryFunctions,
70
+ label: "equal to",
71
+ });
72
+
73
+ export const GreaterThan = createToken({
74
+ name: "GreaterThan",
75
+ pattern: /greater than/i,
76
+ categories: CustomBinaryFunctions,
77
+ label: "greater than",
78
+ });
79
+
80
+ export const LessThan = createToken({
81
+ name: "LessThan",
82
+ pattern: /less than/i,
83
+ categories: CustomBinaryFunctions,
84
+ label: "less than",
85
+ });
86
+
87
+ export const WhiteSpace = createToken({
88
+ name: "WhiteSpace",
89
+ pattern: /\s+/,
90
+ group: Lexer.SKIPPED,
91
+ });
92
+
93
+ export const LParen = createToken({
94
+ name: "LParen",
95
+ pattern: /\(/,
96
+ label: "(",
97
+ });
98
+ export const RParen = createToken({
99
+ name: "RParen",
100
+ pattern: /\)/,
101
+ label: ")",
102
+ });
103
+
104
+ export const BinaryOperator = createToken({
105
+ name: "BinaryOperator",
106
+ pattern: Lexer.NA,
107
+ });
108
+
109
+ export const AndOperator = createToken({
110
+ name: "AndOperator",
111
+ pattern: /&&/,
112
+ categories: BinaryOperator,
113
+ label: "&&",
114
+ });
115
+
116
+ export const OrOperator = createToken({
117
+ name: "OrOperator",
118
+ pattern: /\|\|/,
119
+ categories: BinaryOperator,
120
+ label: "||",
121
+ });
122
+
123
+ export const NotOperator = createToken({
124
+ name: "NotOperator",
125
+ pattern: /!/,
126
+ label: "!",
127
+ });
128
+
129
+ export const allTokens = [
130
+ WhiteSpace,
131
+ LParen,
132
+ RParen,
133
+ AndOperator,
134
+ OrOperator,
135
+ NotOperator,
136
+ AreUnique,
137
+ ArePresent,
138
+ AllIn,
139
+ AnyIn,
140
+ EqualTo,
141
+ GreaterThan,
142
+ LessThan,
143
+ FollowRegex,
144
+ NoneIn,
145
+ CustomUniaryFunctions,
146
+ CustomBinaryFunctions,
147
+ BinaryOperator,
148
+ Identifier,
149
+ ];
150
+
151
+ const lexerErrorMessageProvider: ILexerErrorMessageProvider = {
152
+ buildUnableToPopLexerModeMessage: function (token: IToken): string {
153
+ return `Unable to pop Lexer Mode at line ${token.startLine}, column ${token.startColumn}. Token: ${token.image}.`;
154
+ },
155
+ buildUnexpectedCharactersMessage: function (
156
+ fullText: string,
157
+ startOffset: number,
158
+ length: number,
159
+ line: number,
160
+ column: number
161
+ ): string {
162
+ const unexpectedText = fullText.substring(
163
+ startOffset,
164
+ startOffset + length
165
+ );
166
+ return `Unexpected character sequence: '${unexpectedText}' at line ${line}, column ${column}.`;
167
+ },
168
+ };
169
+ const ReturnLexer = new Lexer(allTokens, {
170
+ errorMessageProvider: lexerErrorMessageProvider,
171
+ positionTracking: "full",
172
+ });
173
+
174
+ export function ReturnTokenize(inputText: string) {
175
+ const lexerResult: ILexingResult = ReturnLexer.tokenize(inputText);
176
+
177
+ if (lexerResult.errors.length > 0) {
178
+ const errorMessages = lexerResult.errors
179
+ .map((error) => error.message)
180
+ .join("\n");
181
+ throw new Error(`Lexing errors encountered:\n${errorMessages}`);
182
+ }
183
+ return lexerResult;
184
+ }
@@ -0,0 +1,42 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ import { BUID_TYPE } from "../types/build.js";
3
+ import { removeRequiredAndEnum } from "../utils/config-utils/json-schema-utils.js";
4
+ import { getAllJsonPaths } from "../utils/json-path-utils/extract-string-paths.js";
5
+
6
+ export class SchemaExtactionService {
7
+ extractSchemas = async (
8
+ data: BUID_TYPE,
9
+ removeRequired: boolean,
10
+ removeEnums: boolean
11
+ ) => {
12
+ const paths = data.paths;
13
+ const apis = Object.keys(paths).map((key) => {
14
+ return key.split("/")[1];
15
+ });
16
+ const output: any = { paths: {} };
17
+ for (const targetApi of apis) {
18
+ const existingSchema =
19
+ paths[`/${targetApi}`].post.requestBody.content["application/json"]
20
+ .schema;
21
+ output["response"] =
22
+ paths[`/${targetApi}`].post.responses.default.content[
23
+ "application/json"
24
+ ].schema;
25
+ const filtteredSchema = removeRequiredAndEnum(
26
+ existingSchema,
27
+ removeEnums,
28
+ removeRequired
29
+ );
30
+ output[targetApi] = filtteredSchema;
31
+ }
32
+ return output as Record<string, JSONSchema7>;
33
+ };
34
+
35
+ extractPossiblePaths = (schemas: Record<string, JSONSchema7>) => {
36
+ const paths: Record<string, string[]> = {};
37
+ for (const [key, schema] of Object.entries(schemas)) {
38
+ paths[key] = getAllJsonPaths(schema);
39
+ }
40
+ return paths;
41
+ };
42
+ }
@@ -0,0 +1,51 @@
1
+ import { ErrorDefinition } from "./error-codes";
2
+
3
+ export interface Xattributes {
4
+ [key: string]: AttributeSet;
5
+ }
6
+ export interface AttributeSet {
7
+ attribute_set: AttributeSection;
8
+ }
9
+ export interface Attribute {
10
+ required?: string;
11
+ usage?: any;
12
+ description?: string;
13
+ owner?: string;
14
+ type?: string;
15
+ }
16
+ export interface AttributeSection {
17
+ [key: string]: Attribute | AttributeSection;
18
+ }
19
+
20
+ export type BuildPath = {
21
+ [key: string]: {
22
+ post: {
23
+ description: string;
24
+ requestBody: {
25
+ content: {
26
+ "application/json": {
27
+ schema: any;
28
+ };
29
+ };
30
+ };
31
+ responses: {
32
+ default: {
33
+ content: {
34
+ "application/json": {
35
+ schema: any;
36
+ };
37
+ };
38
+ };
39
+ };
40
+ };
41
+ };
42
+ };
43
+
44
+ export interface BUID_TYPE {
45
+ paths: BuildPath;
46
+ "x-enum": any;
47
+ "x-attributes": Xattributes;
48
+ "x-errorcodes": {
49
+ code: ErrorDefinition[];
50
+ };
51
+ }
@@ -0,0 +1,3 @@
1
+ export enum SupportedLanguages {
2
+ Typescript = "typescript",
3
+ }
@@ -0,0 +1,27 @@
1
+ import { ConfigSyntax, TestObjectSyntax } from "../constants/syntax.js";
2
+ import { Primitive } from "./general-types.js";
3
+
4
+ export type TestObject = {
5
+ [TestObjectSyntax.Name]: string;
6
+ [TestObjectSyntax.Return]: string | TestObject[];
7
+ [TestObjectSyntax.Scope]?: string;
8
+ [TestObjectSyntax.ErrorCode]?: number;
9
+ [TestObjectSyntax.SuccessCode]?: number;
10
+ [TestObjectSyntax.Continue]?: string;
11
+ [key: string]: ConfigVariable | number | TestObject[] | undefined;
12
+ };
13
+
14
+ export type ConfigVariable = string | Primitive[];
15
+
16
+ export type TestArray = TestObject[];
17
+
18
+ export type SessionDataValue = string | Primitive[] | null;
19
+
20
+ export type SessionDataApi = {
21
+ [key: string]: SessionDataValue;
22
+ };
23
+
24
+ export type ValidationConfig = {
25
+ [ConfigSyntax.Tests]: Record<string, TestArray>;
26
+ [ConfigSyntax.SessionData]: Record<string, SessionDataApi>;
27
+ };
@@ -0,0 +1,6 @@
1
+ export type ErrorDefinition = {
2
+ code: number;
3
+ Description: string;
4
+ From?: string;
5
+ Event?: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ export type Primitive = number | string | boolean | null;
2
+ export type ValidVariableLine = string | Primitive[];