ondc-code-generator 0.3.2 → 0.3.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.
@@ -20,7 +20,7 @@ export declare class ConfigCompiler {
20
20
  initialize: (buildYaml: string, generatorConfig?: Partial<CodeGeneratorConfig>) => Promise<void>;
21
21
  performValidations: (valConfig: ValidationConfig) => Promise<void>;
22
22
  withMinimalValidations: (valConfig: ValidationConfig) => Promise<void>;
23
- generateCode: (valConfig: ValidationConfig, codeName?: string, minimal?: boolean) => Promise<void>;
23
+ generateCode: (valConfig: ValidationConfig, codeName?: string, minimal?: boolean, outputPath?: string) => Promise<void>;
24
24
  generateL0Schema: () => Promise<void>;
25
25
  generateValidPaths: () => Promise<Record<string, string[]>>;
26
26
  }
@@ -57,7 +57,7 @@ export class ConfigCompiler {
57
57
  throw new Error("validation failed");
58
58
  }
59
59
  };
60
- this.generateCode = async (valConfig, codeName = "L1-Validations", minimal = false) => {
60
+ this.generateCode = async (valConfig, codeName = "L1-Validations", minimal = false, outputPath = "./") => {
61
61
  valConfig = JSON.parse(JSON.stringify(valConfig));
62
62
  if (this.generatorConfig?.duplicateVariablesInChildren) {
63
63
  console.log("Duplicating variables");
@@ -70,9 +70,12 @@ export class ConfigCompiler {
70
70
  await this.performValidations(valConfig);
71
71
  }
72
72
  // Generate code based on the language
73
+ const targetPath = path.resolve(outputPath, `/generated/${codeName}`);
73
74
  switch (this.language) {
74
75
  case SupportedLanguages.Typescript:
75
- await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [], `./generated/${codeName}`).generateCode({
76
+ await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [],
77
+ // `./generated/${codeName}`
78
+ targetPath).generateCode({
76
79
  codeName: codeName,
77
80
  });
78
81
  break;
@@ -1,35 +1,17 @@
1
1
  import jsonpath from "jsonpath";
2
-
3
- function isPrimitive(val: any): boolean {
4
- return val === null || ['string', 'number', 'boolean'].includes(typeof val);
5
- }
6
-
7
- function isListOfStringsOrNull(arr: any[]): boolean {
8
- return Array.isArray(arr) && arr.every((item) => typeof item === 'string' || item === null);
9
- }
10
-
11
2
  function getJsonPath(payload: any, path: string) {
12
3
  let output = jsonpath.query(payload, path);
13
-
14
- if (!Array.isArray(output)) {
15
- throw new Error(`Expected output to be an array, got ${typeof output}`);
16
- }
17
-
18
- // Check if all items are primitive
19
- const allPrimitives = output.every(isPrimitive);
20
-
21
- if (!allPrimitives) {
22
- throw new Error(`Expected output to be a list of primitives, but found complex types.`);
23
- }
24
-
25
- // Handle nulls
26
4
  if (isListOfStringsOrNull(output)) {
27
5
  output = output.map((o) => (o === null ? "null" : o));
28
6
  }
29
-
30
7
  return output.length === 0 ? [] : output;
31
8
  }
32
-
9
+ function isListOfStringsOrNull(variable: any): boolean {
10
+ return (
11
+ Array.isArray(variable) &&
12
+ variable.every((item) => item === null || typeof item === "string")
13
+ );
14
+ }
33
15
  export default {
34
16
  getJsonPath,
35
- };
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",