ondc-code-generator 0.0.2 → 0.0.4
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/constants/operations.d.ts +6 -0
- package/dist/constants/syntax.d.ts +15 -0
- package/dist/generator/config-compiler.d.ts +23 -0
- package/dist/generator/generators/classes/abstract-generator.d.ts +11 -0
- package/dist/generator/generators/documentation/markdown-message-generator.d.ts +2 -0
- package/dist/generator/generators/documentation/md-generator.d.ts +9 -0
- package/dist/generator/generators/typescript/templates/json-path-utils.d.ts +5 -0
- package/dist/generator/generators/typescript/templates/validation-utils.d.ts +21 -0
- package/dist/generator/generators/typescript/ts-ast.d.ts +1 -0
- package/dist/generator/generators/typescript/ts-generator.d.ts +17 -0
- package/dist/generator/validators/abstract-validator.d.ts +17 -0
- package/dist/generator/validators/config-validator.d.ts +11 -0
- package/dist/generator/validators/session-data-config/session-data-validator.d.ts +9 -0
- package/dist/generator/validators/tests-config/sub-validations.d.ts +38 -0
- package/dist/generator/validators/tests-config/test-list-validator.d.ts +10 -0
- package/dist/generator/validators/tests-config/test-validator.d.ts +7 -0
- package/dist/services/return-complier/ast-functions/compile-to-markdown.d.ts +2 -0
- package/dist/services/return-complier/ast-functions/semantic-validations.d.ts +2 -0
- package/dist/services/return-complier/ast.d.ts +42 -0
- package/dist/services/return-complier/combined.d.ts +2 -0
- package/dist/services/return-complier/parser.d.ts +14 -0
- package/dist/services/return-complier/tokens.d.ts +22 -0
- package/dist/services/schema-service.d.ts +6 -0
- package/dist/types/build.d.ts +48 -0
- package/dist/types/compiler-types.d.ts +3 -0
- package/dist/types/config-types.d.ts +21 -0
- package/dist/types/error-codes.d.ts +6 -0
- package/dist/utils/config-utils/json-schema-utils.d.ts +7 -0
- package/dist/utils/config-utils/yaml.d.ts +1 -0
- package/dist/utils/fs-utils.d.ts +3 -0
- package/dist/utils/general-utils/string-utils.d.ts +27 -0
- package/dist/utils/general-utils/test-object-utils.d.ts +2 -0
- package/dist/utils/general-utils/validation-utils.d.ts +5 -0
- package/dist/utils/json-path-utils/extract-string-paths.d.ts +8 -0
- package/dist/utils/json-path-utils/paths.d.ts +9 -0
- package/dist/utils/logger.d.ts +3 -0
- package/package.json +2 -3
- package/generated/L1-validations/api-tests/cancel.ts +0 -569
- package/generated/L1-validations/api-tests/confirm.ts +0 -1162
- package/generated/L1-validations/api-tests/init.ts +0 -1063
- package/generated/L1-validations/api-tests/on_cancel.ts +0 -2069
- package/generated/L1-validations/api-tests/on_confirm.ts +0 -2219
- package/generated/L1-validations/api-tests/on_init.ts +0 -1949
- package/generated/L1-validations/api-tests/on_search.ts +0 -1574
- package/generated/L1-validations/api-tests/on_select.ts +0 -1723
- package/generated/L1-validations/api-tests/on_status.ts +0 -2221
- package/generated/L1-validations/api-tests/on_update.ts +0 -1969
- package/generated/L1-validations/api-tests/search.ts +0 -695
- package/generated/L1-validations/api-tests/select.ts +0 -994
- package/generated/L1-validations/api-tests/status.ts +0 -443
- package/generated/L1-validations/api-tests/update.ts +0 -898
- package/generated/L1-validations/error.ts +0 -64
- package/generated/L1-validations/index.ts +0 -138
- package/generated/L1-validations/page/index.html +0 -2118
- package/generated/L1-validations/page/style.css +0 -225
- package/generated/L1-validations/readme.md +0 -1779
- package/generated/L1-validations/types/test-config.ts +0 -27
- package/generated/L1-validations/utils/json-path-utils.ts +0 -17
- package/generated/L1-validations/utils/validation-utils.ts +0 -116
- package/generated-structure/api-tests/search.ts +0 -24
- package/generated-structure/types/test-config.ts +0 -21
- package/samples/build.yaml +0 -24799
- package/samples/output.md +0 -91
- package/samples/output.ts +0 -27
- package/samples/selections.json +0 -216
- package/samples/validation-config.json +0 -3422
- package/samples/x-validations.yaml +0 -2893
- package/src/constants/operations.ts +0 -19
- package/src/constants/syntax.ts +0 -81
- package/src/example.ts +0 -25
- package/src/generator/config-compiler.ts +0 -122
- package/src/generator/generators/classes/abstract-generator.ts +0 -29
- package/src/generator/generators/documentation/markdown-message-generator.ts +0 -43
- package/src/generator/generators/documentation/md-generator.ts +0 -76
- package/src/generator/generators/documentation/templates/index.mustache +0 -36
- package/src/generator/generators/documentation/templates/style.css +0 -204
- package/src/generator/generators/python/py-generator.ts +0 -0
- package/src/generator/generators/typescript/templates/api-test.mustache +0 -7
- package/src/generator/generators/typescript/templates/json-path-utils.ts +0 -17
- package/src/generator/generators/typescript/templates/schema-template.mustache +0 -18
- package/src/generator/generators/typescript/templates/test-config.mustache +0 -28
- package/src/generator/generators/typescript/templates/test-object.mustache +0 -20
- package/src/generator/generators/typescript/templates/validation-code.mustache +0 -39
- package/src/generator/generators/typescript/templates/validation-utils.ts +0 -117
- package/src/generator/generators/typescript/ts-ast.ts +0 -72
- package/src/generator/generators/typescript/ts-generator.ts +0 -275
- package/src/generator/validators/abstract-validator.ts +0 -23
- package/src/generator/validators/config-validator.ts +0 -55
- package/src/generator/validators/session-data-config/session-data-validator.ts +0 -58
- package/src/generator/validators/tests-config/sub-validations.ts +0 -302
- package/src/generator/validators/tests-config/test-list-validator.ts +0 -59
- package/src/generator/validators/tests-config/test-validator.ts +0 -69
- package/src/services/return-complier/ast-functions/compile-to-markdown.ts +0 -152
- package/src/services/return-complier/ast-functions/semantic-validations.ts +0 -44
- package/src/services/return-complier/ast.ts +0 -147
- package/src/services/return-complier/combined.ts +0 -8
- package/src/services/return-complier/parser.ts +0 -128
- package/src/services/return-complier/tokens.ts +0 -184
- package/src/services/schema-service.ts +0 -42
- package/src/types/build.ts +0 -51
- package/src/types/compiler-types.ts +0 -3
- package/src/types/config-types.ts +0 -27
- package/src/types/error-codes.ts +0 -6
- package/src/utils/config-utils/json-schema-utils.ts +0 -150
- package/src/utils/config-utils/yaml.ts +0 -17
- package/src/utils/fs-utils.ts +0 -32
- package/src/utils/general-utils/string-utils.ts +0 -76
- package/src/utils/general-utils/test-object-utils.ts +0 -14
- package/src/utils/general-utils/validation-utils.ts +0 -30
- package/src/utils/json-path-utils/extract-string-paths.ts +0 -139
- package/src/utils/json-path-utils/paths.ts +0 -44
- package/src/utils/logger.ts +0 -53
- package/tsconfig.json +0 -17
- /package/{generated-structure/error.ts → dist/example.d.ts} +0 -0
- /package/{generated-structure/index.ts → dist/generator/generators/python/py-generator.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/types/general-types.ts → dist/types/general-types.d.ts} +0 -0
|
@@ -1,147 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
}
|
package/src/types/build.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|