ondc-code-generator 0.2.5 → 0.2.8

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.
@@ -15,7 +15,7 @@ const __dirname = path.dirname(__filename);
15
15
  const defaultConfig = {
16
16
  removeRequiredFromSchema: true,
17
17
  removeEnumsFromSchema: true,
18
- duplicateVariablesInChildren: false,
18
+ duplicateVariablesInChildren: true,
19
19
  };
20
20
  export class ConfigCompiler {
21
21
  constructor(language) {
@@ -4,8 +4,7 @@ function areUnique(operand: string[]) {
4
4
  }
5
5
 
6
6
  function arePresent(operand: string[]) {
7
-
8
- return noneIn(operand, ["", "null", "undefined"]) && operand.length > 0;
7
+ return noneIn(operand, ["null", "undefined"]) && operand.length > 0;
9
8
  }
10
9
 
11
10
 
@@ -162,8 +162,9 @@ export class TypescriptGenerator extends CodeGenerator {
162
162
  .map((api) => `import ${api} from "./api-tests/${api}";`)
163
163
  .join("\n");
164
164
  const masterFunction = `
165
- export function perform${functionName}(action: string, payload: any,allErrors = false, externalData = {}) {
165
+ export function perform${functionName}(action: string, payload: any,allErrors = false, externalData : any = {}) {
166
166
  const normalizedPayload = normalizeKeys(payload);
167
+ externalData._SELF = normalizedPayload;
167
168
  switch (action) {
168
169
  ${apis
169
170
  .map((api) => `case "${api}": return ${api}({
@@ -10,11 +10,19 @@ export function duplicateVariablesInChildren(valConfig) {
10
10
  }
11
11
  }
12
12
  // console.log(JSON.stringify(valConfig, null, 2));
13
+ if (valConfig[ConfigSyntax.SessionData]["search"]) {
14
+ valConfig[ConfigSyntax.SessionData]["search"]._SELF = null;
15
+ }
16
+ else {
17
+ valConfig[ConfigSyntax.SessionData]["search"] = {
18
+ _SELF: null,
19
+ };
20
+ }
13
21
  return valConfig;
14
22
  }
15
23
  function duplicateVariables(test, parentVariables) {
16
24
  const variables = getVariablesFromTest(test);
17
- const extractedVariables = {};
25
+ let extractedVariables = {};
18
26
  for (const v of variables) {
19
27
  const value = test[v];
20
28
  if (typeof value === "string") {
@@ -25,6 +33,7 @@ function duplicateVariables(test, parentVariables) {
25
33
  extractedVariables[v] = value;
26
34
  }
27
35
  }
36
+ extractedVariables = convertToDuplicatePaths(extractedVariables);
28
37
  if (Array.isArray(test[TestObjectSyntax.Return])) {
29
38
  const returnArray = test[TestObjectSyntax.Return];
30
39
  for (const returnTest of returnArray) {
@@ -40,3 +49,12 @@ function duplicateVariables(test, parentVariables) {
40
49
  // console.log(test);
41
50
  }
42
51
  }
52
+ function convertToDuplicatePaths(current) {
53
+ for (const key in current) {
54
+ if (typeof current[key] === "string") {
55
+ const value = current[key].slice(2);
56
+ current[key] = `$._EXTERNAL._SELF.${value}`;
57
+ }
58
+ }
59
+ return current;
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.2.5",
3
+ "version": "0.2.8",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",