ondc-code-generator 0.6.22 → 0.7.3

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.
Files changed (42) hide show
  1. package/.github/copilot-instructions.md +128 -0
  2. package/GOLANG_IMPLEMENTATION.md +156 -0
  3. package/README.md +10 -1
  4. package/dist/bin/cli-tool.d.ts +70 -0
  5. package/dist/bin/cli-tool.js +310 -0
  6. package/dist/bin/cli.d.ts +2 -0
  7. package/dist/bin/cli.js +80 -0
  8. package/dist/generator/config-compiler.d.ts +1 -0
  9. package/dist/generator/config-compiler.js +14 -0
  10. package/dist/generator/generators/go/go-ast.d.ts +1 -0
  11. package/dist/generator/generators/go/go-ast.js +60 -0
  12. package/dist/generator/generators/go/go-generator.d.ts +13 -0
  13. package/dist/generator/generators/go/go-generator.js +322 -0
  14. package/dist/generator/generators/go/templates/api-tests.mustache +65 -0
  15. package/dist/generator/generators/go/templates/go-mod.mustache +3 -0
  16. package/dist/generator/generators/go/templates/index.mustache +34 -0
  17. package/dist/generator/generators/go/templates/json-normalizer.mustache +155 -0
  18. package/dist/generator/generators/go/templates/json-path-utils.mustache +63 -0
  19. package/dist/generator/generators/go/templates/storage-templates/api-save-utils.mustache +84 -0
  20. package/dist/generator/generators/go/templates/storage-templates/api-save.mustache +44 -0
  21. package/dist/generator/generators/go/templates/storage-templates/index.mustache +72 -0
  22. package/dist/generator/generators/go/templates/storage-templates/save-utils.mustache +75 -0
  23. package/dist/generator/generators/go/templates/storage-templates/storage-interface.mustache +107 -0
  24. package/dist/generator/generators/go/templates/test-config.mustache +62 -0
  25. package/dist/generator/generators/go/templates/test-object.mustache +52 -0
  26. package/dist/generator/generators/go/templates/validation-code.mustache +66 -0
  27. package/dist/generator/generators/go/templates/validation-utils.mustache +321 -0
  28. package/dist/generator/generators/typescript/templates/index.mustache +1 -1
  29. package/dist/generator/generators/typescript/ts-generator.js +2 -2
  30. package/dist/index.d.ts +7 -1
  31. package/dist/index.js +6 -1
  32. package/dist/index.test.js +8 -1
  33. package/dist/types/build.d.ts +2 -0
  34. package/dist/types/compiler-types.d.ts +2 -1
  35. package/dist/types/compiler-types.js +1 -0
  36. package/dist/utils/fs-utils.d.ts +1 -0
  37. package/dist/utils/fs-utils.js +24 -0
  38. package/dist/utils/general-utils/string-utils.d.ts +1 -0
  39. package/dist/utils/general-utils/string-utils.js +11 -0
  40. package/package.json +5 -1
  41. package/sample.md +273 -0
  42. package/test-python-session.js +0 -0
@@ -0,0 +1,52 @@
1
+ var {{name}} = func (input validationutils.ValidationInput) ([]validationutils.ValidationOutput, error) {
2
+ scope := validationutils.GetJsonPath(input.Payload,"{{{scopePath}}}",true)
3
+
4
+ subResults := make([]validationutils.ValidationOutput, 0)
5
+ valid := true
6
+ configureDebugInfo := ""
7
+ for _, testObj := range scope {
8
+ testObjMap, ok := validationutils.DeepCloneJSON(testObj).(map[string]interface{})
9
+ if !ok {
10
+ return nil, fmt.Errorf("Invalid object structure in scope for test {{name}}")
11
+ }
12
+
13
+ testObjMap["_EXTERNAL"] = validationutils.DeepCloneJSON(input.ExternalData)
14
+
15
+ {{#variables}}
16
+ {{name}} := {{{value}}}
17
+ validationutils.UnusedFunction({{name}})
18
+ {{/variables}}
19
+
20
+ {{#hasContinue}}
21
+ skipCheck := {{{skipCheckStatement}}}
22
+ if( skipCheck ) {
23
+ continue
24
+ }
25
+ {{/hasContinue}}
26
+
27
+ {{{validationCode}}}
28
+
29
+ delete(testObjMap, "_EXTERNAL")
30
+ }
31
+
32
+ result := validationutils.ValidationOutput{
33
+ TestName: "{{name}}",
34
+ Valid: valid,
35
+ Code: 0,
36
+ DebugInfo: &validationutils.DebugInfo{
37
+ FedConfig: configureDebugInfo,
38
+ },
39
+ }
40
+
41
+ if valid {
42
+ result.Code = {{successCode}}
43
+ } else {
44
+ result.Code = {{errorCode}}
45
+ }
46
+
47
+ results := make([]validationutils.ValidationOutput, 0, len(subResults)+1)
48
+ results = append(results, result)
49
+ results = append(results, subResults...)
50
+
51
+ return results,nil
52
+ }
@@ -0,0 +1,66 @@
1
+
2
+
3
+ {{#isNested}}
4
+
5
+ {{{nestedFunctions}}}
6
+
7
+ var testFunctions = validationutils.TestFunctionArray{
8
+ {{#names}}
9
+ {{name}},
10
+ {{/names}}
11
+ }
12
+
13
+ allResults := make([]validationutils.ValidationOutput, 0)
14
+
15
+ for _, testFunc := range testFunctions {
16
+ results, err := testFunc(input)
17
+ if err != nil {
18
+ return nil, err
19
+ }
20
+ allResults = append(allResults, results...)
21
+ }
22
+
23
+ subResults = allResults
24
+ // if all subResults are valid, then valid is true
25
+ valid = true
26
+ for _, res := range subResults {
27
+ if !res.Valid {
28
+ valid = false
29
+ break
30
+ }
31
+ }
32
+
33
+ configureDebugInfo = `NESTED_TEST_OBJECT`
34
+
35
+ {{/isNested}}
36
+
37
+ {{^isNested}}
38
+
39
+ {{#isStateFull}}
40
+ validate := true
41
+ if( input.Config.StateFullValidations == false ) {
42
+ validate = {{{returnStatement}}}
43
+ }
44
+ {{/isStateFull}}
45
+
46
+ {{^isStateFull}}
47
+ validate := {{{returnStatement}}}
48
+ {{/isStateFull}}
49
+
50
+ configureDebugInfo = `{{{TEST_OBJECT}}}`
51
+
52
+ if(!validate){
53
+ result := validationutils.ValidationOutput{
54
+ TestName: "{{testName}}",
55
+ Valid: false,
56
+ Code: {{errorCode}},
57
+ Description: `{{{errorDescription}}}`,
58
+ DebugInfo: &validationutils.DebugInfo{
59
+ FedConfig: configureDebugInfo,
60
+ },
61
+ }
62
+ delete(testObjMap, "_EXTERNAL")
63
+ return []validationutils.ValidationOutput{result},nil
64
+ }
65
+
66
+ {{/isNested}}
@@ -0,0 +1,321 @@
1
+ // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
+
3
+ package validationutils
4
+
5
+ import (
6
+ "fmt"
7
+ "strconv"
8
+ "time"
9
+
10
+ "github.com/dlclark/regexp2"
11
+ )
12
+
13
+ // toStringSlice converts []interface{} to []string, returns false if any element is not a string
14
+ func toStringSlice(operand []interface{}) ([]string, bool) {
15
+ result := make([]string, len(operand))
16
+ for i, v := range operand {
17
+ str, ok := v.(string)
18
+ if !ok {
19
+ // Try to convert to string
20
+ if v == nil {
21
+ result[i] = "null"
22
+ } else {
23
+ result[i] = fmt.Sprintf("%v", v)
24
+ }
25
+ } else {
26
+ result[i] = str
27
+ }
28
+ }
29
+ return result, true
30
+ }
31
+
32
+ func AreUnique(operand []interface{}) bool {
33
+ strs, ok := toStringSlice(operand)
34
+ if !ok {
35
+ return false
36
+ }
37
+
38
+ valuesSet := make(map[string]struct{})
39
+ for _, v := range strs {
40
+ valuesSet[v] = struct{}{}
41
+ }
42
+ return len(valuesSet) == len(strs)
43
+ }
44
+
45
+ func ArePresent(operand []interface{}) bool {
46
+ strs, ok := toStringSlice(operand)
47
+ if !ok {
48
+ return false
49
+ }
50
+ return NoneIn(operand, []interface{}{"null", "undefined"}) && len(strs) > 0
51
+ }
52
+
53
+ func AllIn(left []interface{}, right []interface{}) bool {
54
+ leftStrs, ok1 := toStringSlice(left)
55
+ rightStrs, ok2 := toStringSlice(right)
56
+ if !ok1 || !ok2 {
57
+ return false
58
+ }
59
+
60
+ if len(leftStrs) == 0 && len(rightStrs) != 0 {
61
+ return false
62
+ }
63
+ for _, v := range leftStrs {
64
+ if !contains(rightStrs, v) {
65
+ return false
66
+ }
67
+ }
68
+ return true
69
+ }
70
+
71
+ func AnyIn(left []interface{}, right []interface{}) bool {
72
+ leftStrs, ok1 := toStringSlice(left)
73
+ rightStrs, ok2 := toStringSlice(right)
74
+ if !ok1 || !ok2 {
75
+ return false
76
+ }
77
+
78
+ if len(leftStrs) == 0 && len(rightStrs) != 0 {
79
+ return false
80
+ }
81
+ for _, v := range leftStrs {
82
+ if contains(rightStrs, v) {
83
+ return true
84
+ }
85
+ }
86
+ return false
87
+ }
88
+
89
+ func NoneIn(left []interface{}, right []interface{}) bool {
90
+ leftStrs, ok1 := toStringSlice(left)
91
+ rightStrs, ok2 := toStringSlice(right)
92
+ if !ok1 || !ok2 {
93
+ return false
94
+ }
95
+
96
+ for _, v := range leftStrs {
97
+ if contains(rightStrs, v) {
98
+ return false
99
+ }
100
+ }
101
+ return true
102
+ }
103
+
104
+ func EqualTo(left []interface{}, right []interface{}) bool {
105
+ leftStrs, ok1 := toStringSlice(left)
106
+ rightStrs, ok2 := toStringSlice(right)
107
+ if !ok1 || !ok2 {
108
+ return false
109
+ }
110
+
111
+ if len(leftStrs) != len(rightStrs) {
112
+ return false
113
+ }
114
+ for i, v := range leftStrs {
115
+ if v != rightStrs[i] {
116
+ return false
117
+ }
118
+ }
119
+ return true
120
+ }
121
+
122
+ func GreaterThan(left []interface{}, right []interface{}) bool {
123
+ leftStrs, ok1 := toStringSlice(left)
124
+ rightStrs, ok2 := toStringSlice(right)
125
+ if !ok1 || !ok2 {
126
+ return false
127
+ }
128
+
129
+ areAllISO := func(arr []string) bool {
130
+ for _, v := range arr {
131
+ if !isISO8601(v) {
132
+ return false
133
+ }
134
+ }
135
+ return true
136
+ }
137
+
138
+ areAllNumbers := func(arr []string) bool {
139
+ for _, v := range arr {
140
+ if _, err := strconv.ParseFloat(v, 64); err != nil {
141
+ return false
142
+ }
143
+ }
144
+ return true
145
+ }
146
+
147
+ if areAllISO(leftStrs) && areAllISO(rightStrs) {
148
+ leftDates := make([]int64, len(leftStrs))
149
+ for i, date := range leftStrs {
150
+ t, _ := time.Parse(time.RFC3339, date)
151
+ leftDates[i] = t.UnixMilli()
152
+ }
153
+
154
+ rightDates := make([]int64, len(rightStrs))
155
+ for i, date := range rightStrs {
156
+ t, _ := time.Parse(time.RFC3339, date)
157
+ rightDates[i] = t.UnixMilli()
158
+ }
159
+
160
+ for i, ld := range leftDates {
161
+ if i >= len(rightDates) || ld <= rightDates[i] {
162
+ if i < len(rightDates) {
163
+ return false
164
+ }
165
+ }
166
+ }
167
+ return true
168
+ } else if areAllNumbers(leftStrs) && areAllNumbers(rightStrs) {
169
+ leftNumbers := make([]float64, len(leftStrs))
170
+ for i, v := range leftStrs {
171
+ leftNumbers[i], _ = strconv.ParseFloat(v, 64)
172
+ }
173
+
174
+ rightNumbers := make([]float64, len(rightStrs))
175
+ for i, v := range rightStrs {
176
+ rightNumbers[i], _ = strconv.ParseFloat(v, 64)
177
+ }
178
+
179
+ for i, ln := range leftNumbers {
180
+ if i >= len(rightNumbers) || ln <= rightNumbers[i] {
181
+ if i < len(rightNumbers) {
182
+ return false
183
+ }
184
+ }
185
+ }
186
+ return true
187
+ }
188
+
189
+ return false
190
+ }
191
+
192
+ func LessThan(left []interface{}, right []interface{}) bool {
193
+ leftStrs, ok1 := toStringSlice(left)
194
+ rightStrs, ok2 := toStringSlice(right)
195
+ if !ok1 || !ok2 {
196
+ return false
197
+ }
198
+
199
+ areAllISO := func(arr []string) bool {
200
+ for _, v := range arr {
201
+ if !isISO8601(v) {
202
+ return false
203
+ }
204
+ }
205
+ return true
206
+ }
207
+
208
+ areAllNumbers := func(arr []string) bool {
209
+ for _, v := range arr {
210
+ if _, err := strconv.ParseFloat(v, 64); err != nil {
211
+ return false
212
+ }
213
+ }
214
+ return true
215
+ }
216
+
217
+ if areAllISO(leftStrs) && areAllISO(rightStrs) {
218
+ leftDates := make([]int64, len(leftStrs))
219
+ for i, date := range leftStrs {
220
+ t, _ := time.Parse(time.RFC3339, date)
221
+ leftDates[i] = t.UnixMilli()
222
+ }
223
+
224
+ rightDates := make([]int64, len(rightStrs))
225
+ for i, date := range rightStrs {
226
+ t, _ := time.Parse(time.RFC3339, date)
227
+ rightDates[i] = t.UnixMilli()
228
+ }
229
+
230
+ for i, ld := range leftDates {
231
+ if i >= len(rightDates) || ld >= rightDates[i] {
232
+ if i < len(rightDates) {
233
+ return false
234
+ }
235
+ }
236
+ }
237
+ return true
238
+ } else if areAllNumbers(leftStrs) && areAllNumbers(rightStrs) {
239
+ leftNumbers := make([]float64, len(leftStrs))
240
+ for i, v := range leftStrs {
241
+ leftNumbers[i], _ = strconv.ParseFloat(v, 64)
242
+ }
243
+
244
+ rightNumbers := make([]float64, len(rightStrs))
245
+ for i, v := range rightStrs {
246
+ rightNumbers[i], _ = strconv.ParseFloat(v, 64)
247
+ }
248
+
249
+ for i, ln := range leftNumbers {
250
+ if i >= len(rightNumbers) || ln >= rightNumbers[i] {
251
+ if i < len(rightNumbers) {
252
+ return false
253
+ }
254
+ }
255
+ }
256
+ return true
257
+ }
258
+
259
+ return false
260
+ }
261
+
262
+ func FollowRegex(left []interface{}, regexArray []interface{}) bool {
263
+ leftStrs, ok1 := toStringSlice(left)
264
+ regexStrs, ok2 := toStringSlice(regexArray)
265
+ if !ok1 || !ok2 {
266
+ return false
267
+ }
268
+
269
+ if len(leftStrs) == 0 && len(regexStrs) != 0 {
270
+ return false
271
+ }
272
+ for _, regexStr := range regexStrs {
273
+ re, err := regexp2.Compile(regexStr, 0)
274
+ if err != nil {
275
+ return false
276
+ }
277
+ for _, v := range leftStrs {
278
+ match, err := re.MatchString(v)
279
+ if err != nil || !match {
280
+ return false
281
+ }
282
+ }
283
+ }
284
+ return true
285
+ }
286
+
287
+ func isISO8601(str string) bool {
288
+ iso8601Regex, err := regexp2.Compile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$`, 0)
289
+ if err != nil {
290
+ return false
291
+ }
292
+
293
+ match, err := iso8601Regex.MatchString(str)
294
+ if err != nil || !match {
295
+ return false
296
+ }
297
+
298
+ _, err = time.Parse(time.RFC3339, str)
299
+ return err == nil
300
+ }
301
+
302
+ func contains(slice []string, item string) bool {
303
+ for _, v := range slice {
304
+ if v == item {
305
+ return true
306
+ }
307
+ }
308
+ return false
309
+ }
310
+
311
+ // StringSliceToInterface converts []string to []interface{}
312
+ func StringSliceToInterface(strs []string) []interface{} {
313
+ result := make([]interface{}, len(strs))
314
+ for i, v := range strs {
315
+ result[i] = v
316
+ }
317
+ return result
318
+ }
319
+
320
+ // UnusedFunction to avoid unused variable errors
321
+ func UnusedFunction(item interface{}) {}
@@ -30,4 +30,4 @@
30
30
  * // e.g. out[0] => { testName, valid, code, description?, _debugInfo? }
31
31
  * ```
32
32
  */
33
- {{{masterFunction}}}
33
+ {{{masterFunction}}}
@@ -89,7 +89,7 @@ export class TypescriptGenerator extends CodeGenerator {
89
89
  this.generateCode = async (codeConfig) => {
90
90
  this.codeConfig = codeConfig;
91
91
  const jsonPathUtilsCode = readFileSync(path.resolve(__dirname, "./templates/json-path-utils.mustache"), "utf-8");
92
- const validtionUtils = readFileSync(path.resolve(__dirname, "./templates/validation-utils.mustache"), "utf-8");
92
+ const validationUtils = readFileSync(path.resolve(__dirname, "./templates/validation-utils.mustache"), "utf-8");
93
93
  const typesTemplate = readFileSync(path.resolve(__dirname, "./templates/test-config.mustache"), "utf-8");
94
94
  const normalizerTemplate = readFileSync(path.resolve(__dirname, "./templates/json-normalizer.mustache"), "utf-8");
95
95
  const typesCode = Mustache.render(typesTemplate, {
@@ -97,7 +97,7 @@ export class TypescriptGenerator extends CodeGenerator {
97
97
  });
98
98
  writeAndFormatCode(this.rootPath, "./utils/json-path-utils.ts", jsonPathUtilsCode, "typescript");
99
99
  writeAndFormatCode(this.rootPath, "./utils/json-normalizer.ts", normalizerTemplate, "typescript");
100
- writeAndFormatCode(this.rootPath, "./utils/validation-utils.ts", validtionUtils, "typescript");
100
+ writeAndFormatCode(this.rootPath, "./utils/validation-utils.ts", validationUtils, "typescript");
101
101
  writeAndFormatCode(this.rootPath, "./types/test-config.ts", typesCode, "typescript");
102
102
  await this.generateValidationCode();
103
103
  await writeAndFormatCode(this.rootPath, "error.ts", this.generateErrorFile(this.errorCodes), "typescript");
package/dist/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
1
  import { ConfigCompiler } from "./generator/config-compiler.js";
2
- export { ConfigCompiler };
2
+ import { SupportedLanguages } from "./types/compiler-types.js";
3
+ export { ConfigCompiler, SupportedLanguages };
4
+ declare const _default: {
5
+ ConfigCompiler: typeof ConfigCompiler;
6
+ SupportedLanguages: typeof SupportedLanguages;
7
+ };
8
+ export default _default;
package/dist/index.js CHANGED
@@ -1,2 +1,7 @@
1
1
  import { ConfigCompiler } from "./generator/config-compiler.js";
2
- export { ConfigCompiler };
2
+ import { SupportedLanguages } from "./types/compiler-types.js";
3
+ export { ConfigCompiler, SupportedLanguages };
4
+ export default {
5
+ ConfigCompiler,
6
+ SupportedLanguages,
7
+ };
@@ -1,4 +1,4 @@
1
- import { readFileSync } from "fs";
1
+ import { readFileSync, writeFileSync } from "fs";
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  import { ConfigCompiler } from "./generator/config-compiler.js";
@@ -12,10 +12,17 @@ const main = async () => {
12
12
  const buildYaml = readFileSync(buildPath, "utf-8");
13
13
  const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
14
14
  await compiler.initialize(buildYaml);
15
+ const validPaths = await compiler.generateValidPaths();
16
+ writeFileSync(path.resolve(__dirname, "../alpha/possible-json-paths.json"), JSON.stringify(validPaths, null, 2), "utf-8");
15
17
  await compiler.generateCode(valConfig, "L1_validations", false, "./alpha/python/");
16
18
  const compilerTy = new ConfigCompiler(SupportedLanguages.Typescript);
17
19
  await compilerTy.initialize(buildYaml);
18
20
  await compilerTy.generateCode(valConfig, "L1_validations", false, "./alpha/typescript/");
21
+ await compilerTy.generateL0Schema("./alpha/typescript/L0_schema/");
22
+ await compilerTy.generateL0Schema("./alpha/json/", "json");
23
+ const compilerGo = new ConfigCompiler(SupportedLanguages.Golang);
24
+ await compilerGo.initialize(buildYaml);
25
+ await compilerGo.generateCode(valConfig, "L1_validations", false, "./alpha/golang/");
19
26
  // JavaScript generation example
20
27
  // const compilerJs = new ConfigCompiler(SupportedLanguages.Javascript);
21
28
  // await compilerJs.initialize(buildYaml);
@@ -1,3 +1,4 @@
1
+ import { ValidationConfig } from "./config-types";
1
2
  import { ErrorDefinition } from "./error-codes";
2
3
  export interface Xattributes {
3
4
  [key: string]: AttributeSet;
@@ -45,4 +46,5 @@ export interface BUILD_TYPE {
45
46
  "x-errorcodes": {
46
47
  code: ErrorDefinition[];
47
48
  };
49
+ "x-validations"?: ValidationConfig;
48
50
  }
@@ -1,5 +1,6 @@
1
1
  export declare enum SupportedLanguages {
2
2
  Typescript = "typescript",
3
3
  Python = "python",
4
- Javascript = "javascript"
4
+ Javascript = "javascript",
5
+ Golang = "go"
5
6
  }
@@ -3,4 +3,5 @@ export var SupportedLanguages;
3
3
  SupportedLanguages["Typescript"] = "typescript";
4
4
  SupportedLanguages["Python"] = "python";
5
5
  SupportedLanguages["Javascript"] = "javascript";
6
+ SupportedLanguages["Golang"] = "go";
6
7
  })(SupportedLanguages || (SupportedLanguages = {}));
@@ -1,3 +1,4 @@
1
1
  export declare function writeFileWithFsExtra(rootPath: string, relativeFilePath: string, content: string): void;
2
2
  export declare function formatCode(code: string, lang: string): Promise<string>;
3
+ export declare function formatGo(code: string): string;
3
4
  export declare function writeAndFormatCode(rootPath: string, relativeFilePath: string, content: string, lang: string): Promise<void>;
@@ -2,6 +2,7 @@ import fs from "fs-extra";
2
2
  import * as path from "path";
3
3
  import prettier from "prettier";
4
4
  import logger from "./logger.js";
5
+ import { spawnSync } from "node:child_process";
5
6
  export function writeFileWithFsExtra(rootPath, relativeFilePath, content) {
6
7
  // Resolve the full file path
7
8
  const filePath = path.resolve(rootPath, relativeFilePath);
@@ -17,6 +18,10 @@ export async function formatCode(code, lang) {
17
18
  // Basic Python formatting - clean up extra whitespace and blank lines
18
19
  return formatPythonCode(code);
19
20
  }
21
+ if (lang === "go") {
22
+ // Basic Go formatting - clean up extra whitespace and blank lines
23
+ return formatGo(code);
24
+ }
20
25
  return await prettier.format(code, {
21
26
  parser: lang,
22
27
  tabWidth: 4,
@@ -57,7 +62,26 @@ function formatPythonCode(code) {
57
62
  }
58
63
  return cleanedLines.join("\n") + "\n";
59
64
  }
65
+ export function formatGo(code) {
66
+ // return code;
67
+ const result = spawnSync("gofmt", [], {
68
+ input: code,
69
+ encoding: "utf8",
70
+ // stdio: "inherit",
71
+ maxBuffer: 10 * 1024 * 1024, // 10MB (default is 200KB)
72
+ });
73
+ if (result.error) {
74
+ // throw result.error;
75
+ return code; // If gofmt is not available, return the original code
76
+ }
77
+ if (result.status !== 0) {
78
+ // throw new Error(result.stderr);
79
+ return code; // If gofmt fails, return the original code
80
+ }
81
+ return result.stdout;
82
+ }
60
83
  export async function writeAndFormatCode(rootPath, relativeFilePath, content, lang) {
84
+ // console.log(`Formatting and writing file: ${relativeFilePath}`);
61
85
  const formattedCode = await formatCode(content, lang);
62
86
  writeFileWithFsExtra(rootPath, relativeFilePath, formattedCode);
63
87
  }
@@ -25,4 +25,5 @@ export declare function ConvertArrayToStringsInTestObject(testObject: TestObject
25
25
  _DESCRIPTION_?: string;
26
26
  };
27
27
  export declare function ConvertArrayToString(arr: any[]): string;
28
+ export declare function ConvertArrayToStringGoStyle(arr: any[]): string;
28
29
  export declare function addTabToMarkdown(markdown: string): string;
@@ -61,6 +61,17 @@ export function ConvertArrayToString(arr) {
61
61
  values = values.replace(/\\\\\\/g, "\\");
62
62
  return values;
63
63
  }
64
+ export function ConvertArrayToStringGoStyle(arr) {
65
+ for (const a of arr) {
66
+ if (typeof a !== "string") {
67
+ console.log(arr);
68
+ throw new Error(`Array contains non-string element: ${a}`);
69
+ }
70
+ }
71
+ let values = arr.map((v) => `\`${v}\``).join(", ");
72
+ values = values.replace(/\\\\/g, "\\");
73
+ return `validationutils.StringSliceToInterface([]string{${values}})`;
74
+ }
64
75
  export function addTabToMarkdown(markdown) {
65
76
  // Split the markdown into lines, add a tab to each line, and rejoin
66
77
  return markdown
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.6.22",
3
+ "version": "0.7.3",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
+ "bin": {
8
+ "ondc-code-generator": "dist/bin/cli.js"
9
+ },
7
10
  "scripts": {
8
11
  "build": "tsc && copyfiles -u 1 \"src/**/*.{yaml,html,css,mustache}\" dist/",
9
12
  "start": "node ./dist/index.js",
@@ -31,6 +34,7 @@
31
34
  "@apidevtools/json-schema-ref-parser": "^11.7.2",
32
35
  "chalk": "^4.1.2",
33
36
  "chevrotain": "^11.0.3",
37
+ "commander": "^14.0.2",
34
38
  "fs-extra": "^11.2.0",
35
39
  "js-yaml": "^4.1.0",
36
40
  "json-schema": "^0.4.0",