ondc-code-generator 0.3.0 → 0.3.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.
@@ -49,7 +49,7 @@ export class ConfigCompiler {
49
49
  this.withMinimalValidations = async (valConfig) => {
50
50
  try {
51
51
  await new ConfigValidator("", valConfig, {}, [], {
52
- skipJsonPathTest: true,
52
+ minimal: true,
53
53
  }).validate();
54
54
  }
55
55
  catch (e) {
@@ -14,5 +14,5 @@ export interface TestsValidatorDependencies {
14
14
  stringJsonPaths: string[];
15
15
  errorDefinitions: ErrorDefinition[];
16
16
  externalVariables: string[];
17
- skipJsonPathTest?: boolean;
17
+ minimal: boolean;
18
18
  }
@@ -7,10 +7,10 @@ export declare class ConfigValidator implements IValidator {
7
7
  stringJsonPaths: Record<string, string[]>;
8
8
  errorDefinitions: ErrorDefinition[];
9
9
  validatorSettings: {
10
- skipJsonPathTest: boolean;
10
+ minimal: boolean;
11
11
  };
12
12
  constructor(validationPath: string, config: ValidationConfig, stringJsonPaths: Record<string, string[]>, errorDefinitions: ErrorDefinition[], settings?: {
13
- skipJsonPathTest: boolean;
13
+ minimal: boolean;
14
14
  });
15
15
  validate: () => Promise<void>;
16
16
  }
@@ -20,6 +20,7 @@ export class ConfigValidator {
20
20
  stringJsonPaths: this.stringJsonPaths[api],
21
21
  errorDefinitions: this.errorDefinitions,
22
22
  externalVariables: externalVariables,
23
+ minimal: this.validatorSettings.minimal,
23
24
  };
24
25
  await new TestsValidator(testList, path, dependencies).validate();
25
26
  }
@@ -33,7 +34,7 @@ export class ConfigValidator {
33
34
  }
34
35
  else {
35
36
  this.validatorSettings = {
36
- skipJsonPathTest: false,
37
+ minimal: false,
37
38
  };
38
39
  }
39
40
  }
@@ -9,19 +9,21 @@ export declare class NameValidator extends TestObjectValidator {
9
9
  }
10
10
  export declare class ScopeValidator extends TestObjectValidator {
11
11
  impossiblePaths: string[];
12
- constructor(testObject: TestObject, path: string, impossiblePaths: string[]);
12
+ minimal: boolean;
13
+ constructor(testObject: TestObject, path: string, impossiblePaths: string[], minimal?: boolean);
13
14
  validate: () => Promise<void>;
14
15
  }
15
16
  export declare class ErrorCodeValidator extends TestObjectValidator {
16
17
  possibleErrorCodes: ErrorDefinition[];
17
- constructor(testObject: TestObject, path: string, possibleErrorCodes: ErrorDefinition[]);
18
+ minimal: boolean;
19
+ constructor(testObject: TestObject, path: string, possibleErrorCodes: ErrorDefinition[], minimal?: boolean);
18
20
  validate: () => Promise<void>;
19
21
  }
20
22
  export declare class VariableValidator extends TestObjectValidator {
21
23
  possibleJsonPaths: string[];
22
24
  externalVariables: string[];
23
- skipJsonPathTest: boolean;
24
- constructor(testObject: TestObject, path: string, posibleJsonPaths: string[], externalVariables: string[], skipJsonPathTest?: boolean);
25
+ minimal: boolean;
26
+ constructor(testObject: TestObject, path: string, posibleJsonPaths: string[], externalVariables: string[], minimal?: boolean);
25
27
  validate: () => Promise<void>;
26
28
  validateKey(key: string): void;
27
29
  validateExternalData(path: string, definedExternalValues: string[]): void;
@@ -41,8 +41,9 @@ export class NameValidator extends TestObjectValidator {
41
41
  }
42
42
  }
43
43
  export class ScopeValidator extends TestObjectValidator {
44
- constructor(testObject, path, impossiblePaths) {
44
+ constructor(testObject, path, impossiblePaths, minimal = false) {
45
45
  super(testObject, path);
46
+ this.minimal = false;
46
47
  this.validate = async () => {
47
48
  const path = this.targetObject[TestObjectSyntax.Scope];
48
49
  if (typeof path !== "string") {
@@ -54,16 +55,20 @@ export class ScopeValidator extends TestObjectValidator {
54
55
  if (!path.startsWith(`$.`)) {
55
56
  throw new Error(`${TestObjectSyntax.Scope} json path should start with $. at ${this.validationPath}`);
56
57
  }
58
+ if (this.minimal)
59
+ return;
57
60
  if (this.impossiblePaths.includes(replaceBracketsWithAsteriskNested(path))) {
58
61
  throw new Error(`${TestObjectSyntax.Scope} can't be a path that returns a array of string it must be a json path which returns a array of objects at path ${this.validationPath}`);
59
62
  }
60
63
  };
61
64
  this.impossiblePaths = impossiblePaths;
65
+ this.minimal = minimal;
62
66
  }
63
67
  }
64
68
  export class ErrorCodeValidator extends TestObjectValidator {
65
- constructor(testObject, path, possibleErrorCodes) {
69
+ constructor(testObject, path, possibleErrorCodes, minimal = false) {
66
70
  super(testObject, path);
71
+ this.minimal = false;
67
72
  this.validate = async () => {
68
73
  if (!this.targetObject[TestObjectSyntax.ErrorCode]) {
69
74
  return;
@@ -74,6 +79,8 @@ export class ErrorCodeValidator extends TestObjectValidator {
74
79
  if (typeof this.targetObject[TestObjectSyntax.ErrorCode] !== "number") {
75
80
  throw new Error(`${TestObjectSyntax.ErrorCode} should be a number at path ${this.validationPath}`);
76
81
  }
82
+ if (this.minimal)
83
+ return;
77
84
  const errorCode = this.targetObject[TestObjectSyntax.ErrorCode];
78
85
  if (!this.possibleErrorCodes.some((code) => code.code === errorCode)) {
79
86
  throw new Error(`${TestObjectSyntax.ErrorCode} don't exist in error codes at path ${this.validationPath}`);
@@ -86,12 +93,13 @@ export class ErrorCodeValidator extends TestObjectValidator {
86
93
  }
87
94
  };
88
95
  this.possibleErrorCodes = possibleErrorCodes;
96
+ this.minimal = minimal;
89
97
  }
90
98
  }
91
99
  export class VariableValidator extends TestObjectValidator {
92
- constructor(testObject, path, posibleJsonPaths, externalVariables, skipJsonPathTest = false) {
100
+ constructor(testObject, path, posibleJsonPaths, externalVariables, minimal = false) {
93
101
  super(testObject, path);
94
- this.skipJsonPathTest = false;
102
+ this.minimal = false;
95
103
  this.validate = async () => {
96
104
  for (const key in this.targetObject) {
97
105
  if (Object.values(TestObjectSyntax).includes(key)) {
@@ -120,8 +128,9 @@ export class VariableValidator extends TestObjectValidator {
120
128
  path = `${scope}.${pathWithoutDollar}`;
121
129
  }
122
130
  const replaced = replaceBracketsWithAsteriskNested(path);
123
- if (!this.possibleJsonPaths.includes(replaced) &&
124
- !this.skipJsonPathTest) {
131
+ if (this.minimal)
132
+ return;
133
+ if (!this.possibleJsonPaths.includes(replaced)) {
125
134
  throw new Error(`Variable: ${key} should be a jsonPath that returns a array of strings or the path don't exist in the schema, at ${this.validationPath} found original ${path} replaces: ${replaced}`);
126
135
  }
127
136
  }
@@ -129,7 +138,7 @@ export class VariableValidator extends TestObjectValidator {
129
138
  };
130
139
  this.externalVariables = externalVariables;
131
140
  this.possibleJsonPaths = posibleJsonPaths;
132
- this.skipJsonPathTest = skipJsonPathTest;
141
+ this.minimal = minimal;
133
142
  }
134
143
  validateKey(key) {
135
144
  if (nodeReservedKeywords.has(key)) {
@@ -8,12 +8,12 @@ export class CompleteTestObjectValidator extends TestObjectValidator {
8
8
  await new RequiredFieldsValidator(this.targetObject, this.validationPath).validate();
9
9
  await new NameValidator(this.targetObject, this.validationPath).validate();
10
10
  if (this.targetObject[TestObjectSyntax.Scope]) {
11
- await new ScopeValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths).validate();
11
+ await new ScopeValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.minimal).validate();
12
12
  }
13
13
  if (this.targetObject[TestObjectSyntax.ErrorCode]) {
14
- await new ErrorCodeValidator(this.targetObject, this.validationPath, this.dependencies.errorDefinitions).validate();
14
+ await new ErrorCodeValidator(this.targetObject, this.validationPath, this.dependencies.errorDefinitions, this.dependencies.minimal).validate();
15
15
  }
16
- await new VariableValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.externalVariables, this.dependencies.skipJsonPathTest).validate();
16
+ await new VariableValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.externalVariables, this.dependencies.minimal).validate();
17
17
  if (this.targetObject[TestObjectSyntax.Continue]) {
18
18
  await new ContinueValidator(this.targetObject, this.validationPath).validate();
19
19
  }
package/dist/index.js CHANGED
@@ -1,23 +1,20 @@
1
1
  import { ConfigCompiler } from "./generator/config-compiler.js";
2
2
  export { ConfigCompiler };
3
- // import { readFileSync } from "fs";
4
- // import path from "path";
5
- // import { fileURLToPath } from "url";
6
- // const __filename = fileURLToPath(import.meta.url);
7
- // const __dirname = path.dirname(__filename);
8
- // import { SupportedLanguages } from "./types/compiler-types.js";
9
- // const main = async () => {
10
- // const compiler = new ConfigCompiler(SupportedLanguages.Typescript);
11
- // const buildPath = path.resolve(__dirname, "../samples/build.yaml");
12
- // const valConfigPath = path.resolve(
13
- // __dirname,
14
- // "../samples/validation-config.json"
15
- // );
16
- // const buildYaml = readFileSync(buildPath, "utf-8");
17
- // const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
18
- // await compiler.initialize(buildYaml);
19
- // await compiler.generateCode(valConfig, "L1-validations");
20
- // };
21
- // (async () => {
22
- // await main();
23
- // })();
3
+ import { readFileSync } from "fs";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ import { SupportedLanguages } from "./types/compiler-types.js";
9
+ const main = async () => {
10
+ const compiler = new ConfigCompiler(SupportedLanguages.Typescript);
11
+ const buildPath = path.resolve(__dirname, "../samples/build.yaml");
12
+ const valConfigPath = path.resolve(__dirname, "../samples/validation-config.json");
13
+ const buildYaml = readFileSync(buildPath, "utf-8");
14
+ const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
15
+ await compiler.initialize(buildYaml);
16
+ await compiler.generateCode(valConfig, "L1-validations", true);
17
+ };
18
+ (async () => {
19
+ await main();
20
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",