ondc-code-generator 0.2.5 → 0.2.7
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:
|
|
18
|
+
duplicateVariablesInChildren: true,
|
|
19
19
|
};
|
|
20
20
|
export class ConfigCompiler {
|
|
21
21
|
constructor(language) {
|
|
@@ -164,6 +164,7 @@ export class TypescriptGenerator extends CodeGenerator {
|
|
|
164
164
|
const masterFunction = `
|
|
165
165
|
export function perform${functionName}(action: string, payload: any,allErrors = false, externalData = {}) {
|
|
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
|
-
|
|
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
|
+
}
|