ondc-code-generator 0.8.9 → 1.0.0

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 (95) hide show
  1. package/alpha/possible-json-paths.json +34134 -0
  2. package/alpha/table/page/index.html +11487 -0
  3. package/alpha/table/page/style.css +449 -0
  4. package/alpha/table/rag-table-docs/confirm.md +63 -0
  5. package/alpha/table/rag-table-docs/init.md +81 -0
  6. package/alpha/table/rag-table-docs/on_confirm.md +164 -0
  7. package/alpha/table/rag-table-docs/on_init.md +146 -0
  8. package/alpha/table/rag-table-docs/on_search.md +163 -0
  9. package/alpha/table/rag-table-docs/on_select.md +99 -0
  10. package/alpha/table/rag-table-docs/on_status.md +153 -0
  11. package/alpha/table/rag-table-docs/on_update.md +164 -0
  12. package/alpha/table/rag-table-docs/raw_table.json +11198 -0
  13. package/alpha/table/rag-table-docs/search.md +128 -0
  14. package/alpha/table/rag-table-docs/select.md +70 -0
  15. package/alpha/table/rag-table-docs/status.md +44 -0
  16. package/alpha/table/rag-table-docs/update.md +51 -0
  17. package/alpha/table/readme.md +1312 -0
  18. package/alpha/table/validPaths.json +34134 -0
  19. package/alpha/table.zip +0 -0
  20. package/dist/bin/cli.js +4 -0
  21. package/dist/generator/config-compiler.d.ts +16 -2
  22. package/dist/generator/config-compiler.js +57 -19
  23. package/dist/generator/generators/classes/abstract-generator.d.ts +2 -0
  24. package/dist/generator/generators/documentation/md-generator.d.ts +12 -5
  25. package/dist/generator/generators/documentation/md-generator.js +23 -28
  26. package/dist/generator/generators/documentation/templates/index.mustache +162 -26
  27. package/dist/generator/generators/documentation/templates/style.css +387 -142
  28. package/dist/generator/generators/go/go-generator.js +1 -1
  29. package/dist/generator/generators/javascript/js-generator.js +1 -1
  30. package/dist/generator/generators/python/py-generator.js +1 -1
  31. package/dist/generator/generators/rag/rag-generator.d.ts +48 -0
  32. package/dist/generator/generators/rag/rag-generator.js +185 -0
  33. package/dist/generator/generators/rag/rag-table-generator.d.ts +55 -0
  34. package/dist/generator/generators/rag/rag-table-generator.js +269 -0
  35. package/dist/generator/generators/typescript/ts-generator.js +1 -1
  36. package/dist/index.test.js +12 -3
  37. package/dist/types/build.d.ts +4 -0
  38. package/dist/types/compiler-types.d.ts +3 -1
  39. package/dist/types/compiler-types.js +2 -0
  40. package/package.json +1 -1
  41. package/alpha/docs/page/index.html +0 -6137
  42. package/alpha/docs/page/style.css +0 -204
  43. package/alpha/docs/readme.md +0 -5939
  44. package/alpha/docs/validPaths.json +0 -14351
  45. package/alpha/page/index.html +0 -6137
  46. package/alpha/page/style.css +0 -204
  47. package/alpha/readme.md +0 -5939
  48. package/alpha/validationpkg/examples/search.json +0 -143
  49. package/alpha/validationpkg/examples_output/search/case-001/output.json +0 -12
  50. package/alpha/validationpkg/go.mod +0 -8
  51. package/alpha/validationpkg/go.sum +0 -4
  52. package/alpha/validationpkg/jsonvalidations/cancel.go +0 -1289
  53. package/alpha/validationpkg/jsonvalidations/confirm.go +0 -9121
  54. package/alpha/validationpkg/jsonvalidations/init.go +0 -4864
  55. package/alpha/validationpkg/jsonvalidations/issue.go +0 -4868
  56. package/alpha/validationpkg/jsonvalidations/on_cancel.go +0 -7111
  57. package/alpha/validationpkg/jsonvalidations/on_confirm.go +0 -8903
  58. package/alpha/validationpkg/jsonvalidations/on_init.go +0 -4445
  59. package/alpha/validationpkg/jsonvalidations/on_issue.go +0 -2828
  60. package/alpha/validationpkg/jsonvalidations/on_issue_status.go +0 -1938
  61. package/alpha/validationpkg/jsonvalidations/on_search.go +0 -3356
  62. package/alpha/validationpkg/jsonvalidations/on_status.go +0 -8129
  63. package/alpha/validationpkg/jsonvalidations/on_track.go +0 -1415
  64. package/alpha/validationpkg/jsonvalidations/on_update.go +0 -8700
  65. package/alpha/validationpkg/jsonvalidations/search.go +0 -3585
  66. package/alpha/validationpkg/jsonvalidations/status.go +0 -1073
  67. package/alpha/validationpkg/jsonvalidations/track.go +0 -1073
  68. package/alpha/validationpkg/jsonvalidations/update.go +0 -3012
  69. package/alpha/validationpkg/main-validator.go +0 -196
  70. package/alpha/validationpkg/main-validator_test.go +0 -165
  71. package/alpha/validationpkg/storageutils/api_save_utils.go +0 -83
  72. package/alpha/validationpkg/storageutils/cancel.go +0 -30
  73. package/alpha/validationpkg/storageutils/confirm.go +0 -30
  74. package/alpha/validationpkg/storageutils/index.go +0 -132
  75. package/alpha/validationpkg/storageutils/init.go +0 -30
  76. package/alpha/validationpkg/storageutils/issue.go +0 -30
  77. package/alpha/validationpkg/storageutils/on_cancel.go +0 -30
  78. package/alpha/validationpkg/storageutils/on_confirm.go +0 -30
  79. package/alpha/validationpkg/storageutils/on_init.go +0 -30
  80. package/alpha/validationpkg/storageutils/on_issue.go +0 -30
  81. package/alpha/validationpkg/storageutils/on_issue_status.go +0 -30
  82. package/alpha/validationpkg/storageutils/on_search.go +0 -30
  83. package/alpha/validationpkg/storageutils/on_status.go +0 -30
  84. package/alpha/validationpkg/storageutils/on_track.go +0 -30
  85. package/alpha/validationpkg/storageutils/on_update.go +0 -30
  86. package/alpha/validationpkg/storageutils/save_utils.go +0 -75
  87. package/alpha/validationpkg/storageutils/search.go +0 -30
  88. package/alpha/validationpkg/storageutils/status.go +0 -30
  89. package/alpha/validationpkg/storageutils/track.go +0 -30
  90. package/alpha/validationpkg/storageutils/update.go +0 -30
  91. package/alpha/validationpkg/validationutils/json_normalizer.go +0 -152
  92. package/alpha/validationpkg/validationutils/json_path_utils.go +0 -173
  93. package/alpha/validationpkg/validationutils/storage-interface.go +0 -107
  94. package/alpha/validationpkg/validationutils/test-config.go +0 -69
  95. package/alpha/validationpkg/validationutils/validation_utils.go +0 -429
@@ -0,0 +1,185 @@
1
+ import { ConfigSyntax, TestObjectSyntax } from "../../../constants/syntax.js";
2
+ import { CodeGenerator, } from "../classes/abstract-generator.js";
3
+ import { writeFileWithFsExtra } from "../../../utils/fs-utils.js";
4
+ import { markdownMessageGenerator } from "../documentation/markdown-message-generator.js";
5
+ import { buildAstFromInput } from "../../../services/return-complier/combined.js";
6
+ import { CompileToMarkdownForSkip } from "../../../services/return-complier/ast-functions/compile-to-markdown.js";
7
+ import { addBlockquoteToMarkdown, ConvertArrayToStringsInTestObject, } from "../../../utils/general-utils/string-utils.js";
8
+ import Mustache from "mustache";
9
+ /**
10
+ * RagGenerator — produces one Markdown file per API action under ./rag-docs/.
11
+ *
12
+ * Each file is a self-contained, richly structured document intended to be
13
+ * fed directly into a Retrieval-Augmented Generation (RAG) pipeline.
14
+ *
15
+ * Layout per file:
16
+ * ---
17
+ * YAML frontmatter (action, codeName, numTests, generated date)
18
+ * ---
19
+ * # <codeName> — <action> Validations
20
+ * Short context paragraph
21
+ * Numbered list of every test with its human-readable description,
22
+ * error code, scope, and (indented) skip condition when present.
23
+ */
24
+ export class RagGenerator extends CodeGenerator {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.generateValidationCode = async () => {
28
+ // Driven by generateCode
29
+ };
30
+ this.generateCode = async (codeConfig) => {
31
+ const testConfig = this.validationConfig[ConfigSyntax.Tests];
32
+ const { codeName } = codeConfig;
33
+ for (const action of Object.keys(testConfig)) {
34
+ const testArray = testConfig[action];
35
+ const md = this.buildActionMarkdown(action, codeName, testArray);
36
+ writeFileWithFsExtra(this.rootPath, `./rag-docs/${action}.md`, md);
37
+ }
38
+ };
39
+ }
40
+ generateSessionDataCode() {
41
+ // Session-data code not needed for RAG output
42
+ return Promise.resolve();
43
+ }
44
+ generateUnitTestingCode() {
45
+ // Unit-test code not needed for RAG output
46
+ return Promise.resolve();
47
+ }
48
+ // -------------------------------------------------------------------------
49
+ // Private helpers
50
+ // -------------------------------------------------------------------------
51
+ buildActionMarkdown(action, codeName, testArray) {
52
+ const leafCount = this.countLeafTests(testArray);
53
+ const dateStr = new Date().toISOString().split("T")[0];
54
+ // YAML front-matter — picked up as metadata by most RAG loaders
55
+ const frontmatter = [
56
+ "---",
57
+ `action: ${action}`,
58
+ `codeName: ${codeName}`,
59
+ `numTests: ${leafCount}`,
60
+ `generated: ${dateStr}`,
61
+ "---",
62
+ ].join("\n");
63
+ // Human-readable header
64
+ const header = [
65
+ `# ${codeName} — \`${action}\` Validations`,
66
+ "",
67
+ `This document describes the **${leafCount}** validation rule(s) that are`,
68
+ `applied when the \`${action}\` API call is processed in the **${codeName}** flow.`,
69
+ `Each rule maps to a single test object and is evaluated sequentially against the`,
70
+ `request/response payload.`,
71
+ "",
72
+ "---",
73
+ "",
74
+ ].join("\n");
75
+ // One numbered ## section per top-level test object only.
76
+ // Group nodes embed their children as ### sub-sections inside themselves.
77
+ const sections = testArray
78
+ .map((test, idx) => this.buildTestSection(test, idx + 1))
79
+ .join("\n\n");
80
+ return `${frontmatter}\n\n${header}${sections}\n`;
81
+ }
82
+ /** Count only leaf (non-group) tests recursively. */
83
+ countLeafTests(tests) {
84
+ let count = 0;
85
+ for (const test of tests) {
86
+ const ret = test[TestObjectSyntax.Return];
87
+ if (typeof ret === "string") {
88
+ count++;
89
+ }
90
+ else {
91
+ count += this.countLeafTests(ret);
92
+ }
93
+ }
94
+ return count;
95
+ }
96
+ /**
97
+ * Renders a numbered top-level section (##) for a test object.
98
+ *
99
+ * - Leaf test → full human-readable description + metadata badges
100
+ * - Group node → brief intro line + all children rendered as ### sub-sections
101
+ * (recursing further for deeply nested groups)
102
+ *
103
+ * This preserves the parent→child relationship in the output so RAG
104
+ * consumers can see exactly which sub-validations belong to which group.
105
+ */
106
+ buildTestSection(test, index) {
107
+ const name = test[TestObjectSyntax.Name] ?? `test_${index}`;
108
+ const ret = test[TestObjectSyntax.Return];
109
+ if (typeof ret === "string") {
110
+ return this.renderLeaf(test, name, `## ${index}. ${name}`);
111
+ }
112
+ // Group node — render intro + skip (before children) then nest children
113
+ const childSections = ret
114
+ .map((child, i) => this.renderChildSection(child, i + 1, "###"))
115
+ .join("\n\n");
116
+ const groupSkip = this.renderSkipBlock(test);
117
+ return [
118
+ `## ${index}. ${name}`,
119
+ "",
120
+ `Group of **${ret.length}** sub-validation(s). **All** of the following must pass:`,
121
+ ...(groupSkip ? ["", groupSkip] : []),
122
+ "",
123
+ childSections,
124
+ ].join("\n");
125
+ }
126
+ /**
127
+ * Renders a child/nested section at the given heading level.
128
+ * Recurses deeper (####, #####, …) for nested groups.
129
+ */
130
+ renderChildSection(test, index, headingLevel) {
131
+ const name = test[TestObjectSyntax.Name] ?? `sub_test_${index}`;
132
+ const ret = test[TestObjectSyntax.Return];
133
+ const heading = `${headingLevel} ${index}. ${name}`;
134
+ if (typeof ret === "string") {
135
+ return this.renderLeaf(test, name, heading);
136
+ }
137
+ // Nested group — go one heading level deeper
138
+ const nextLevel = headingLevel + "#";
139
+ const childSections = ret
140
+ .map((child, i) => this.renderChildSection(child, i + 1, nextLevel))
141
+ .join("\n\n");
142
+ const groupSkip = this.renderSkipBlock(test);
143
+ return [
144
+ heading,
145
+ "",
146
+ `Group of **${ret.length}** sub-validation(s). **All** of the following must pass:`,
147
+ ...(groupSkip ? ["", groupSkip] : []),
148
+ "",
149
+ childSections,
150
+ ].join("\n");
151
+ }
152
+ /**
153
+ * Renders the skip block for a group node as a blockquote.
154
+ * Returns an empty string when there is no _CONTINUE_ on this node.
155
+ */
156
+ renderSkipBlock(test) {
157
+ const skip = test[TestObjectSyntax.Continue];
158
+ if (!skip)
159
+ return "";
160
+ let skipMarkdown = `**Skip if:**\n`;
161
+ const skAst = buildAstFromInput(skip);
162
+ const skBlock = CompileToMarkdownForSkip(skAst, false, 2, false);
163
+ skipMarkdown += `\n${skBlock}`;
164
+ const rendered = Mustache.render(skipMarkdown, ConvertArrayToStringsInTestObject(test));
165
+ return addBlockquoteToMarkdown(rendered);
166
+ }
167
+ /** Renders a leaf test's heading, metadata badges, and compiled description. */
168
+ renderLeaf(test, name, heading) {
169
+ const scope = test[TestObjectSyntax.Scope];
170
+ const errorCode = test[TestObjectSyntax.ErrorCode];
171
+ const successCode = test[TestObjectSyntax.SuccessCode];
172
+ const skip = test[TestObjectSyntax.Continue];
173
+ const ret = test[TestObjectSyntax.Return];
174
+ const badges = [];
175
+ if (scope)
176
+ badges.push(`**Scope:** \`${scope}\``);
177
+ if (errorCode !== undefined)
178
+ badges.push(`**Error Code:** \`${errorCode}\``);
179
+ if (successCode !== undefined)
180
+ badges.push(`**Success Code:** \`${successCode}\``);
181
+ const badgeLine = badges.length > 0 ? badges.join(" · ") + "\n\n" : "";
182
+ const body = markdownMessageGenerator(ret, test, name, skip ? [skip] : undefined);
183
+ return `${heading}\n\n${badgeLine}${body}`;
184
+ }
185
+ }
@@ -0,0 +1,55 @@
1
+ import { TestObject } from "../../../types/config-types.js";
2
+ import { CodeGenerator, CodeGeneratorProps } from "../classes/abstract-generator.js";
3
+ /**
4
+ * RagTableGenerator — produces one Markdown **table** file per API action
5
+ * under `./rag-table-docs/`.
6
+ *
7
+ * Each file contains:
8
+ * - YAML front-matter (action, codeName, numTests, generated date)
9
+ * - A short summary paragraph
10
+ * - A single GFM table
11
+ *
12
+ * Columns: # | Type | Test Name | Group | Scope | Description | Skip If | Error Code
13
+ *
14
+ * Group nodes ARE rendered as their own rows. Their Description cell lists
15
+ * the immediate child test names and their Skip If cell shows the group's own
16
+ * _CONTINUE_ condition. Child leaf rows follow immediately after, with the
17
+ * Group column showing their parent's name — making hierarchy fully visible.
18
+ *
19
+ * This format is complementary to `RagGenerator` (heading-based): use it
20
+ * when you need a dense, scannable overview of all rules at once.
21
+ */
22
+ export declare class RagTableGenerator extends CodeGenerator {
23
+ generateSessionDataCode(): Promise<void>;
24
+ generateUnitTestingCode(): Promise<void>;
25
+ generateValidationCode: () => Promise<void>;
26
+ generateCode: (codeConfig: CodeGeneratorProps) => Promise<void>;
27
+ /** Collects rows and returns structured JSON for one action. */
28
+ private buildActionJson;
29
+ buildActionMarkdown(action: string, codeName: string, testArray: TestObject[], codeConfig: CodeGeneratorProps): string;
30
+ /**
31
+ * Walks the test tree depth-first.
32
+ *
33
+ * - **Group node** → emits one summary row whose Description lists the
34
+ * immediate child names, and whose Skip If shows the group's own
35
+ * _CONTINUE_. Then recurses so children follow immediately after.
36
+ * - **Leaf node** → emits one row with the compiled description and its
37
+ * own _CONTINUE_ only (no skip inheritance from parents).
38
+ */
39
+ private collectRows;
40
+ /**
41
+ * Renders the GFM table with all rows.
42
+ *
43
+ * Columns shown depend on whether *any* row has a value:
44
+ * - `Group` column hidden when no tests have a group (flat config)
45
+ * - `Scope`, `Skip If`, `Error Code`, `Success Code` similarly pruned
46
+ */
47
+ private renderTable;
48
+ /**
49
+ * Sanitises a string for safe use inside a GFM table cell:
50
+ * - Collapses newlines and excess whitespace to a single space
51
+ * - Escapes pipe characters
52
+ * - Strips any leading `####` heading markers left by the compiler
53
+ */
54
+ private sanitizeCell;
55
+ }
@@ -0,0 +1,269 @@
1
+ import { ConfigSyntax, TestObjectSyntax } from "../../../constants/syntax.js";
2
+ import { CodeGenerator, } from "../classes/abstract-generator.js";
3
+ import { writeFileWithFsExtra } from "../../../utils/fs-utils.js";
4
+ import { markdownMessageGenerator } from "../documentation/markdown-message-generator.js";
5
+ /**
6
+ * RagTableGenerator — produces one Markdown **table** file per API action
7
+ * under `./rag-table-docs/`.
8
+ *
9
+ * Each file contains:
10
+ * - YAML front-matter (action, codeName, numTests, generated date)
11
+ * - A short summary paragraph
12
+ * - A single GFM table
13
+ *
14
+ * Columns: # | Type | Test Name | Group | Scope | Description | Skip If | Error Code
15
+ *
16
+ * Group nodes ARE rendered as their own rows. Their Description cell lists
17
+ * the immediate child test names and their Skip If cell shows the group's own
18
+ * _CONTINUE_ condition. Child leaf rows follow immediately after, with the
19
+ * Group column showing their parent's name — making hierarchy fully visible.
20
+ *
21
+ * This format is complementary to `RagGenerator` (heading-based): use it
22
+ * when you need a dense, scannable overview of all rules at once.
23
+ */
24
+ export class RagTableGenerator extends CodeGenerator {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.generateValidationCode = async () => {
28
+ // Driven by generateCode
29
+ };
30
+ this.generateCode = async (codeConfig) => {
31
+ const testConfig = this.validationConfig[ConfigSyntax.Tests];
32
+ const { codeName } = codeConfig;
33
+ const rawJson = {};
34
+ for (const action of Object.keys(testConfig)) {
35
+ const testArray = testConfig[action];
36
+ const md = this.buildActionMarkdown(action, codeName, testArray, codeConfig);
37
+ writeFileWithFsExtra(this.rootPath, `./rag-table-docs/${action}.md`, md);
38
+ rawJson[action] = this.buildActionJson(action, codeName, testArray);
39
+ }
40
+ writeFileWithFsExtra(this.rootPath, `./rag-table-docs/raw_table.json`, JSON.stringify(rawJson, null, 2));
41
+ };
42
+ }
43
+ generateSessionDataCode() {
44
+ return Promise.resolve();
45
+ }
46
+ generateUnitTestingCode() {
47
+ return Promise.resolve();
48
+ }
49
+ // -------------------------------------------------------------------------
50
+ // Private helpers
51
+ // -------------------------------------------------------------------------
52
+ /** Collects rows and returns structured JSON for one action. */
53
+ buildActionJson(action, codeName, testArray) {
54
+ const rows = [];
55
+ this.collectRows(testArray, rows, "");
56
+ rows.forEach((r, i) => (r.index = i + 1));
57
+ return {
58
+ action,
59
+ codeName,
60
+ numLeafTests: rows.filter((r) => r.rowType === "leaf").length,
61
+ generated: new Date().toISOString().split("T")[0],
62
+ rows: rows.map(({ index: _idx, ...rest }) => rest),
63
+ };
64
+ }
65
+ buildActionMarkdown(action, codeName, testArray, codeConfig) {
66
+ const rows = [];
67
+ this.collectRows(testArray, rows, "");
68
+ // Re-index after collection so numbering is clean
69
+ rows.forEach((r, i) => (r.index = i + 1));
70
+ const dateStr = new Date().toISOString().split("T")[0];
71
+ const domainText = Array.isArray(codeConfig.domain)
72
+ ? codeConfig.domain.join(", ")
73
+ : (codeConfig.domain ?? "-");
74
+ const frontmatter = [
75
+ "---",
76
+ `action: ${action}`,
77
+ `codeName: ${codeName}`,
78
+ `numTests: ${rows.length}`,
79
+ `generated: ${dateStr}`,
80
+ `domain: ${domainText}`,
81
+ `version: ${codeConfig.version ?? "-"}`,
82
+ "---",
83
+ ].join("\n");
84
+ const leafCount = rows.filter((r) => r.rowType === "leaf").length;
85
+ const header = [
86
+ `# ${codeName} — \`${action}\` Validations (Table View)`,
87
+ "",
88
+ `**${leafCount}** leaf validation rule(s) applied to \`${action}\` in the **${codeName}** flow.`,
89
+ `Domain: \`${domainText}\`, Version: \`${codeConfig.version ?? "-"}\``,
90
+ `Group rows (GRP) list their immediate sub-tests. Leaf rows (LF) show the actual validation logic.`,
91
+ "",
92
+ "---",
93
+ "",
94
+ ].join("\n");
95
+ const table = this.renderTable(rows);
96
+ return `${frontmatter}\n\n${header}${table}\n`;
97
+ }
98
+ /**
99
+ * Walks the test tree depth-first.
100
+ *
101
+ * - **Group node** → emits one summary row whose Description lists the
102
+ * immediate child names, and whose Skip If shows the group's own
103
+ * _CONTINUE_. Then recurses so children follow immediately after.
104
+ * - **Leaf node** → emits one row with the compiled description and its
105
+ * own _CONTINUE_ only (no skip inheritance from parents).
106
+ */
107
+ collectRows(tests, acc, parentPath) {
108
+ for (const test of tests) {
109
+ const name = test[TestObjectSyntax.Name] ?? "unknown";
110
+ const ret = test[TestObjectSyntax.Return];
111
+ const ownSkip = test[TestObjectSyntax.Continue];
112
+ if (typeof ret === "string") {
113
+ // ── Leaf row ──────────────────────────────────────────────
114
+ const scope = test[TestObjectSyntax.Scope] ?? "";
115
+ const errorCode = test[TestObjectSyntax.ErrorCode] ?? "30000";
116
+ const successCode = test[TestObjectSyntax.SuccessCode];
117
+ let description;
118
+ try {
119
+ description = markdownMessageGenerator(ret, test, name, undefined)
120
+ .replace(/^#{1,6}\s+\*\*[^*]+\*\*\s*\n\n?/, "")
121
+ .trim();
122
+ }
123
+ catch {
124
+ description = ret;
125
+ }
126
+ let skipText = "";
127
+ if (ownSkip) {
128
+ try {
129
+ skipText = markdownMessageGenerator(ownSkip, test, name, undefined)
130
+ .replace(/^#{1,6}\s+\*\*[^*]+\*\*\s*\n\n?/, "")
131
+ .trim();
132
+ }
133
+ catch {
134
+ skipText = ownSkip;
135
+ }
136
+ }
137
+ acc.push({
138
+ index: acc.length + 1,
139
+ rowType: "leaf",
140
+ name,
141
+ group: parentPath,
142
+ scope: scope ? `\`${scope}\`` : "",
143
+ description: this.sanitizeCell(description),
144
+ skipIf: this.sanitizeCell(skipText),
145
+ errorCode: errorCode !== undefined ? String(errorCode) : "",
146
+ successCode: successCode !== undefined ? String(successCode) : "",
147
+ });
148
+ }
149
+ else {
150
+ // ── Group row ─────────────────────────────────────────────
151
+ const childNames = ret
152
+ .map((c) => c[TestObjectSyntax.Name] ?? "?")
153
+ .join(", ");
154
+ let skipText = "";
155
+ if (ownSkip) {
156
+ try {
157
+ skipText = markdownMessageGenerator(ownSkip, test, name, undefined)
158
+ .replace(/^#{1,6}\s+\*\*[^*]+\*\*\s*\n\n?/, "")
159
+ .trim();
160
+ }
161
+ catch {
162
+ skipText = ownSkip;
163
+ }
164
+ }
165
+ acc.push({
166
+ index: acc.length + 1,
167
+ rowType: "group",
168
+ name: `**${name}**`,
169
+ group: parentPath,
170
+ scope: "",
171
+ description: this.sanitizeCell(`Sub-tests: ${childNames}`),
172
+ skipIf: this.sanitizeCell(skipText),
173
+ errorCode: "",
174
+ successCode: "",
175
+ });
176
+ // Recurse — children follow immediately after the group row
177
+ const newPath = parentPath ? `${parentPath} > ${name}` : name;
178
+ this.collectRows(ret, acc, newPath);
179
+ }
180
+ }
181
+ }
182
+ /**
183
+ * Renders the GFM table with all rows.
184
+ *
185
+ * Columns shown depend on whether *any* row has a value:
186
+ * - `Group` column hidden when no tests have a group (flat config)
187
+ * - `Scope`, `Skip If`, `Error Code`, `Success Code` similarly pruned
188
+ */
189
+ renderTable(rows) {
190
+ const hasGroup = rows.some((r) => r.group !== "");
191
+ const hasScope = rows.some((r) => r.scope !== "");
192
+ const hasSkip = rows.some((r) => r.skipIf !== "");
193
+ const hasSuccess = rows.some((r) => r.successCode !== "");
194
+ const cols = [
195
+ { header: "#", align: "r", value: (r) => String(r.index) },
196
+ {
197
+ header: "Type",
198
+ align: "c",
199
+ value: (r) => (r.rowType === "group" ? "GRP" : "LF"),
200
+ },
201
+ {
202
+ header: "Test Name",
203
+ align: "l",
204
+ // Group rows already have **bold** markers; leaf rows get backticks
205
+ value: (r) => r.rowType === "group" ? r.name : `\`${r.name}\``,
206
+ },
207
+ ...(hasGroup
208
+ ? [
209
+ {
210
+ header: "Group",
211
+ align: "l",
212
+ value: (r) => r.group,
213
+ },
214
+ ]
215
+ : []),
216
+ ...(hasScope
217
+ ? [
218
+ {
219
+ header: "Scope",
220
+ align: "l",
221
+ value: (r) => r.scope,
222
+ },
223
+ ]
224
+ : []),
225
+ { header: "Description", align: "l", value: (r) => r.description },
226
+ ...(hasSkip
227
+ ? [
228
+ {
229
+ header: "Skip If",
230
+ align: "l",
231
+ value: (r) => r.skipIf,
232
+ },
233
+ ]
234
+ : []),
235
+ {
236
+ header: "Error Code",
237
+ align: "c",
238
+ value: (r) => r.errorCode,
239
+ },
240
+ ...(hasSuccess
241
+ ? [
242
+ {
243
+ header: "Success Code",
244
+ align: "c",
245
+ value: (r) => r.successCode,
246
+ },
247
+ ]
248
+ : []),
249
+ ];
250
+ const alignChar = (a) => a === "r" ? "---:" : a === "c" ? ":---:" : ":---";
251
+ const headerRow = `| ${cols.map((c) => c.header).join(" | ")} |`;
252
+ const sepRow = `| ${cols.map((c) => alignChar(c.align)).join(" | ")} |`;
253
+ const dataRows = rows.map((r) => `| ${cols.map((c) => c.value(r) || "—").join(" | ")} |`);
254
+ return [headerRow, sepRow, ...dataRows].join("\n");
255
+ }
256
+ /**
257
+ * Sanitises a string for safe use inside a GFM table cell:
258
+ * - Collapses newlines and excess whitespace to a single space
259
+ * - Escapes pipe characters
260
+ * - Strips any leading `####` heading markers left by the compiler
261
+ */
262
+ sanitizeCell(text) {
263
+ return text
264
+ .replace(/\r?\n/g, " ")
265
+ .replace(/\s{2,}/g, " ")
266
+ .replace(/\|/g, "\\|")
267
+ .trim();
268
+ }
269
+ }
@@ -100,7 +100,7 @@ export class TypescriptGenerator extends CodeGenerator {
100
100
  await this.generateValidationCode();
101
101
  await writeAndFormatCode(this.rootPath, "error.ts", this.generateErrorFile(this.errorCodes), "typescript");
102
102
  await writeAndFormatCode(this.rootPath, "index.ts", this.generateIndexFile(Object.keys(this.validationConfig[ConfigSyntax.Tests]), codeConfig.codeName), "typescript");
103
- await new MarkdownDocGenerator(this.validationConfig, this.errorCodes, this.rootPath).generateCode();
103
+ await new MarkdownDocGenerator(this.validationConfig, this.errorCodes, this.rootPath).generateCode(codeConfig);
104
104
  await this.generateSessionDataCode();
105
105
  };
106
106
  this.generateTestFunction = async (testObject) => {
@@ -14,15 +14,24 @@ const main = async () => {
14
14
  await compiler.initialize(buildYaml);
15
15
  const validPaths = await compiler.generateValidPaths();
16
16
  writeFileSync(path.resolve(__dirname, "../alpha/possible-json-paths.json"), JSON.stringify(validPaths, null, 2), "utf-8");
17
- await compiler.generateCode(valConfig, "L1_validations", false, "./alpha/python/");
17
+ await compiler.generateCode(valConfig, {
18
+ codeName: "L1_validations",
19
+ outputPath: "./alpha/python/",
20
+ });
18
21
  const compilerTy = new ConfigCompiler(SupportedLanguages.Typescript);
19
22
  await compilerTy.initialize(buildYaml);
20
- await compilerTy.generateCode(valConfig, "L1_validations", false, "./alpha/typescript/");
23
+ await compilerTy.generateCode(valConfig, {
24
+ codeName: "L1_validations",
25
+ outputPath: "./alpha/typescript/",
26
+ });
21
27
  await compilerTy.generateL0Schema("./alpha/typescript/L0_schema/");
22
28
  await compilerTy.generateL0Schema("./alpha/json/", "json");
23
29
  const compilerGo = new ConfigCompiler(SupportedLanguages.Golang);
24
30
  await compilerGo.initialize(buildYaml);
25
- await compilerGo.generateCode(valConfig, "L1_validations", false, "./alpha/golang/");
31
+ await compilerGo.generateCode(valConfig, {
32
+ codeName: "L1_validations",
33
+ outputPath: "./alpha/golang/",
34
+ });
26
35
  // JavaScript generation example
27
36
  // const compilerJs = new ConfigCompiler(SupportedLanguages.Javascript);
28
37
  // await compilerJs.initialize(buildYaml);
@@ -41,6 +41,10 @@ export type BuildPath = {
41
41
  };
42
42
  export interface BUILD_TYPE {
43
43
  paths: BuildPath;
44
+ info: {
45
+ domain?: string | string[];
46
+ version?: string;
47
+ };
44
48
  "x-enum": any;
45
49
  "x-attributes": Xattributes;
46
50
  "x-errorcodes": {
@@ -3,5 +3,7 @@ export declare enum SupportedLanguages {
3
3
  Python = "python",
4
4
  Javascript = "javascript",
5
5
  Golang = "go",
6
- Markdown = "md"
6
+ Markdown = "md",
7
+ RAG = "rag",
8
+ RAG_TABLE = "rag_table"
7
9
  }
@@ -5,4 +5,6 @@ export var SupportedLanguages;
5
5
  SupportedLanguages["Javascript"] = "javascript";
6
6
  SupportedLanguages["Golang"] = "go";
7
7
  SupportedLanguages["Markdown"] = "md";
8
+ SupportedLanguages["RAG"] = "rag";
9
+ SupportedLanguages["RAG_TABLE"] = "rag_table";
8
10
  })(SupportedLanguages || (SupportedLanguages = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.8.9",
3
+ "version": "1.0.0",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",