json-renderers-run-instructions 1.11.2 → 1.15.1

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 (48) hide show
  1. package/package.json +2 -5
  2. package/src/index.js +3 -3
  3. package/src/{v11 → v12}/index.js +178 -219
  4. package/src/{v10 → v12}/registerGlobal/index.js +1 -1
  5. package/src/v12/registerGlobal/meta.js +6 -0
  6. package/src/{v10 → v12}/runOptions/index.js +66 -70
  7. package/src/v12/transformers/columnOnRow.js +33 -0
  8. package/src/v12/transformers/index.js +21 -0
  9. package/src/v13/index.js +49 -0
  10. package/src/{v11 → v13}/registerGlobal/index.js +1 -1
  11. package/src/v13/registerGlobal/meta.js +6 -0
  12. package/src/{v11 → v13}/runOptions/index.js +66 -70
  13. package/src/v13/transformers/columnOnRow.js +33 -0
  14. package/src/v13/transformers/index.js +21 -0
  15. package/src/v13/types/columnOnRow.js +34 -0
  16. package/src/v13/types/helpers/guards.js +38 -0
  17. package/src/v13/types/helpers/resolveSource.js +27 -0
  18. package/src/v13/types/helpers/writeResult.js +19 -0
  19. package/src/v13/types/index.js +33 -0
  20. package/src/v13/types/rowOnColumn.js +22 -0
  21. package/src/v13/types/single.js +28 -0
  22. package/src/v14/index.js +48 -0
  23. package/src/v14/registerGlobal/index.js +16 -0
  24. package/src/{v10 → v14}/registerGlobal/meta.js +1 -1
  25. package/src/v14/runOptions/index.js +77 -0
  26. package/src/v15/index.js +48 -0
  27. package/src/v15/registerGlobal/index.js +16 -0
  28. package/src/{v11 → v15}/registerGlobal/meta.js +1 -1
  29. package/src/v15/runOptions/index.js +77 -0
  30. package/src/v10/index.js +0 -218
  31. package/src/v10/runOptions/instructionsWithTargets/index.js +0 -31
  32. package/src/v10-2/index.js +0 -202
  33. package/src/v10-2/runOptions/index.js +0 -52
  34. package/src/v10-2/runOptions/instructionsWithTargets/index.js +0 -31
  35. package/src/v10-old/index.js +0 -195
  36. package/src/v10-old/runOptions/index.js +0 -117
  37. package/src/v10-old/runOptions/instructionsWithTargets/index.js +0 -31
  38. package/src/v11/runOptions/instructionsWithTargets/index.js +0 -31
  39. package/src/v6/index.js +0 -68
  40. package/src/v7/index.js +0 -57
  41. package/src/v8/definitions.json +0 -165
  42. package/src/v8/index.js +0 -193
  43. package/src/v8/instructions.json +0 -275
  44. package/src/v8/spec.json +0 -900
  45. package/src/v9/index.js +0 -195
  46. package/src/v9/runOptions/index.js +0 -48
  47. package/src/v9/runOptions/insertSearch/index.js +0 -28
  48. package/src/v9/runOptions/instructionsWithTargets/index.js +0 -12
package/src/v8/index.js DELETED
@@ -1,193 +0,0 @@
1
- import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
2
- import fromCollection from "json-transformer-funcs-one-dimension";
3
- import applyTemplate from "json-transformer-funcs-primitive";
4
- import writePath from "json-write-path";
5
- import { query } from "jsonpathly";
6
-
7
- import defaultSpec from "./spec.json" with { type: "json" };
8
- import defaultInstructionsJson from "./instructions.json" with { type: "json" };
9
- import definitions from "./definitions.json" with { type: "json" };
10
-
11
- const transformerFunctions = {
12
- fromCollection,
13
- applyTemplate
14
- };
15
-
16
- const resolveSource = (sourcePath, context) => {
17
- if (!sourcePath) return null;
18
-
19
- const root = context[sourcePath.fileName];
20
- if (root === undefined) {
21
- throw new Error(`Context entry not found: ${sourcePath.fileName}`);
22
- }
23
-
24
- if (sourcePath.jsonPath) {
25
- const matches = query(root, sourcePath.jsonPath, { returnArray: true });
26
- if (matches.length === 0) {
27
- return [];
28
- }
29
- return matches.length === 1 ? matches[0] : matches;
30
- }
31
-
32
- if (Array.isArray(sourcePath.filePath) && sourcePath.filePath.length > 0) {
33
- return sourcePath.filePath.reduce((curr, key) => (curr ? curr[key] : undefined), root);
34
- }
35
-
36
- return root;
37
- };
38
-
39
- const checkDestinationExists = (destinationPath, context) => {
40
- if (!destinationPath) return true;
41
- const root = context[destinationPath.fileName];
42
- if (root === undefined) return false;
43
-
44
- if (destinationPath.jsonPath) {
45
- const matches = query(root, destinationPath.jsonPath, { returnArray: true });
46
- return matches.length > 0;
47
- }
48
-
49
- return true;
50
- };
51
-
52
- const executeInstruction = ({ instruction, context, spec = defaultSpec, showLog = false }) => {
53
- if (!instruction) return null;
54
-
55
- // Handle array of sub-instructions (e.g. serial, options, search)
56
- if (Array.isArray(instruction)) {
57
- return instruction.map(step => executeInstruction({ instruction: step, context, spec, showLog }));
58
- }
59
-
60
- // Auto-normalize legacy dataRole to jsonPath
61
- if (instruction.destinationPath?.dataRole && !instruction.destinationPath?.jsonPath) {
62
- instruction.destinationPath.jsonPath = `$..*[?@.attributes['data-role'] == '${instruction.destinationPath.dataRole}']`;
63
- }
64
-
65
- // If destination node does not exist in current base (e.g. footer row on a table without footer), safely skip
66
- if (!checkDestinationExists(instruction.destinationPath, context)) {
67
- if (showLog) {
68
- console.warn(`Destination node not found for ${instruction.destinationPath?.jsonPath}, skipping instruction.`);
69
- }
70
- return null;
71
- }
72
-
73
- const type = instruction.type ?? (instruction.templateKey?.columnKey ? "rowOnColumn" : "single");
74
-
75
- // 1. rowOnColumn instruction (e.g. buildBody for table)
76
- if (type === "rowOnColumn") {
77
- const columnKey = instruction?.templateKey?.columnKey;
78
- const rowKey = instruction?.templateKey?.rowKey;
79
- const columnSpec = spec[columnKey];
80
- const rowSpec = spec[rowKey];
81
-
82
- const columns = context.data?.columns ?? context.columns;
83
- const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows);
84
-
85
- const result = rowOnColumnFunc({
86
- columns,
87
- data: rows,
88
- columnSpec,
89
- rowSpec
90
- });
91
-
92
- writePath(context, instruction.destinationPath, result, showLog);
93
- return result;
94
- }
95
-
96
- // 2. columnOnRow instruction (e.g. buildSelectWithOptions, buildDataListWithOptions)
97
- if (type === "columnOnRow") {
98
- const columnKey = instruction?.templateKey?.columnKey;
99
- const rowKey = instruction?.templateKey?.rowKey;
100
- const columnSpec = spec[columnKey];
101
- const rowSpec = spec[rowKey];
102
-
103
- const columns = context.data?.columns ?? context.columns ?? [];
104
- const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows ?? []);
105
-
106
- const result = columns.map(column => {
107
- const container = applyTemplate(column, columnSpec);
108
-
109
- let optionsList = [];
110
- if (Array.isArray(column.options) && column.options.length > 0) {
111
- optionsList = column.options.map(opt =>
112
- typeof opt === "object" ? opt : { rowValue: opt }
113
- );
114
- } else if (Array.isArray(rows) && rows.length > 0) {
115
- optionsList = rows.map(r => ({
116
- ...r,
117
- rowValue: r[column.columnName] ?? r.value ?? r
118
- }));
119
- }
120
-
121
- container.children = optionsList.map(item => applyTemplate(item, rowSpec));
122
- return container;
123
- });
124
-
125
- if (!instruction.destinationPath?.filePath || instruction.destinationPath.filePath.length === 0) {
126
- context[instruction.destinationPath.fileName] = result;
127
- } else {
128
- writePath(context, instruction.destinationPath, result, showLog);
129
- }
130
- return result;
131
- }
132
-
133
- // 3. single instruction (e.g. buildColgroup, buildHeader, buildFooter, buildFormField, buildOptionsArray)
134
- const template = instruction.templateKey ? spec[instruction.templateKey] : null;
135
- const source = resolveSource(instruction.sourcePath, context);
136
-
137
- let result;
138
- if (instruction.func === null || instruction.func === undefined) {
139
- result = template;
140
- } else if (transformerFunctions[instruction.func]) {
141
- result = transformerFunctions[instruction.func](source, template);
142
- } else {
143
- throw new Error(`Unknown function: ${instruction.func}`);
144
- }
145
-
146
- // If destination filePath is empty (e.g. writing directly into an array base like selectOptionsOnlyBase)
147
- if (!instruction.destinationPath?.filePath || instruction.destinationPath.filePath.length === 0) {
148
- if (Array.isArray(context[instruction.destinationPath.fileName])) {
149
- context[instruction.destinationPath.fileName].push(...(Array.isArray(result) ? result : [result]));
150
- } else {
151
- context[instruction.destinationPath.fileName] = result;
152
- }
153
- } else {
154
- writePath(context, instruction.destinationPath, result, showLog);
155
- }
156
-
157
- return result;
158
- };
159
-
160
- const startFunc = ({
161
- instructionMainKey,
162
- instructionSubKey,
163
- data,
164
- showLog = false
165
- } = {}) => {
166
- const spec = defaultSpec;
167
- const formBaseKey = definitions[instructionMainKey][instructionSubKey].baseFromSpec;
168
- const instructions = definitions[instructionMainKey][instructionSubKey].instructions;
169
-
170
- const base = structuredClone(spec[formBaseKey]);
171
-
172
- const context = { base, data };
173
- const instructionsJson = defaultInstructionsJson;
174
-
175
- instructions.forEach(instructionKeyOrObj => {
176
- if (showLog) console.log("instruction : ", instructionKeyOrObj);
177
-
178
- const instruction = typeof instructionKeyOrObj === "string"
179
- ? instructionsJson[instructionKeyOrObj]
180
- : instructionKeyOrObj;
181
-
182
- if (!instruction) {
183
- if (showLog) console.warn(`Instruction not found: ${instructionKeyOrObj}`);
184
- return;
185
- }
186
-
187
- executeInstruction({ instruction, context, spec, showLog });
188
- });
189
-
190
- return context?.base;
191
- };
192
-
193
- export default startFunc;
@@ -1,275 +0,0 @@
1
- {
2
- "buildColgroup": {
3
- "type": "single",
4
- "narration": "Build column widths",
5
- "destinationPath": {
6
- "fileName": "base",
7
- "filePath": [
8
- "children"
9
- ],
10
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-colgroup']"
11
- },
12
- "sourcePath": {
13
- "fileName": "data",
14
- "jsonPath": "$.columns"
15
- },
16
- "templateKey": "buildColGroup",
17
- "func": "fromCollection"
18
- },
19
- "buildHeader": {
20
- "type": "single",
21
- "narration": "Build table header",
22
- "destinationPath": {
23
- "fileName": "base",
24
- "filePath": [
25
- "children"
26
- ],
27
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-header-row']"
28
- },
29
- "sourcePath": {
30
- "fileName": "data",
31
- "jsonPath": "$.columns"
32
- },
33
- "templateKey": "buildHeader",
34
- "func": "fromCollection"
35
- },
36
- "buildFooter": {
37
- "type": "single",
38
- "narration": "Build table footer",
39
- "destinationPath": {
40
- "fileName": "base",
41
- "filePath": [
42
- "children"
43
- ],
44
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-footer-row']"
45
- },
46
- "sourcePath": {
47
- "fileName": "data",
48
- "jsonPath": "$.columns"
49
- },
50
- "templateKey": "buildFooter",
51
- "func": "fromCollection"
52
- },
53
- "buildBody": {
54
- "type": "rowOnColumn",
55
- "narration": "Build table body",
56
- "destinationPath": {
57
- "fileName": "base",
58
- "filePath": [
59
- "children"
60
- ],
61
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-body']"
62
- },
63
- "templateKey": {
64
- "rowKey": "buildBodyTr",
65
- "columnKey": "buildBodyCell"
66
- }
67
- },
68
- "serial": [
69
- {
70
- "narration": "Prepend the serial column width to the table colgroup.",
71
- "destinationPath": {
72
- "fileName": "base",
73
- "filePath": [
74
- "children"
75
- ],
76
- "action": "unshift",
77
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-colgroup']"
78
- },
79
- "sourcePath": null,
80
- "templateKey": "colGroupForSerial",
81
- "func": null
82
- },
83
- {
84
- "narration": "Prepend the serial header cell to the table header row.",
85
- "destinationPath": {
86
- "fileName": "base",
87
- "filePath": [
88
- "children"
89
- ],
90
- "action": "unshift",
91
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-header-row']"
92
- },
93
- "sourcePath": null,
94
- "templateKey": "headerSerialCell",
95
- "func": null
96
- },
97
- {
98
- "narration": "Prepend the serial number cell into each table body row.",
99
- "destinationPath": {
100
- "fileName": "base",
101
- "filePath": [
102
- "children"
103
- ],
104
- "action": "unshiftSerialToRows",
105
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-body']"
106
- },
107
- "sourcePath": null,
108
- "templateKey": "buildBodyCell",
109
- "func": null
110
- },
111
- {
112
- "narration": "Prepend the serial footer cell to the table footer row.",
113
- "destinationPath": {
114
- "fileName": "base",
115
- "filePath": [
116
- "children"
117
- ],
118
- "action": "unshift",
119
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-footer-row']"
120
- },
121
- "sourcePath": null,
122
- "templateKey": "headerSerialCell",
123
- "func": null
124
- }
125
- ],
126
- "options": [
127
- {
128
- "narration": "Append the options column width to the table colgroup.",
129
- "destinationPath": {
130
- "fileName": "base",
131
- "filePath": [
132
- "children"
133
- ],
134
- "action": "push",
135
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-colgroup']"
136
- },
137
- "sourcePath": null,
138
- "templateKey": "colGroupForOption",
139
- "func": null
140
- },
141
- {
142
- "narration": "Append the options header cell to the table header row.",
143
- "destinationPath": {
144
- "fileName": "base",
145
- "filePath": [
146
- "children"
147
- ],
148
- "action": "push",
149
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-header-row']"
150
- },
151
- "sourcePath": null,
152
- "templateKey": "headerForOption",
153
- "func": null
154
- },
155
- {
156
- "narration": "Append the options button cell into each table body row.",
157
- "destinationPath": {
158
- "fileName": "base",
159
- "filePath": [
160
- "children"
161
- ],
162
- "action": "pushToRows",
163
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-body']"
164
- },
165
- "sourcePath": null,
166
- "templateKey": "optionsButtonCell",
167
- "func": null
168
- },
169
- {
170
- "narration": "Append the options footer cell to the table footer row.",
171
- "destinationPath": {
172
- "fileName": "base",
173
- "filePath": [
174
- "children"
175
- ],
176
- "action": "push",
177
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-footer-row']"
178
- },
179
- "sourcePath": null,
180
- "templateKey": "tdWithButtonSaveWarning",
181
- "func": null
182
- }
183
- ],
184
- "search": [
185
- {
186
- "narration": "Prepend the search row to top of the table.",
187
- "destinationPath": {
188
- "fileName": "base",
189
- "filePath": [
190
- "children"
191
- ],
192
- "action": "unshift",
193
- "jsonPath": "$..*[?@.attributes['data-role'] == 'table-parent']"
194
- },
195
- "sourcePath": null,
196
- "templateKey": "tableSearch",
197
- "func": null
198
- }
199
- ],
200
- "buildFormField": {
201
- "type": "single",
202
- "narration": "Build form fields from columns",
203
- "destinationPath": {
204
- "fileName": "base",
205
- "filePath": [
206
- "children"
207
- ],
208
- "jsonPath": "$..*[?@.attributes['data-role'] == 'form-body']"
209
- },
210
- "sourcePath": {
211
- "fileName": "data",
212
- "jsonPath": "$.columns"
213
- },
214
- "templateKey": "buildFormField",
215
- "func": "fromCollection"
216
- },
217
- "buildSelectWithOptions": {
218
- "type": "columnOnRow",
219
- "narration": "Build selects with options",
220
- "destinationPath": {
221
- "fileName": "base",
222
- "filePath": [
223
- "children"
224
- ]
225
- },
226
- "templateKey": {
227
- "columnKey": "buildSelect",
228
- "rowKey": "buildOption"
229
- }
230
- },
231
- "buildSelectOptions": {
232
- "type": "single",
233
- "narration": "Build select options",
234
- "destinationPath": {
235
- "fileName": "base",
236
- "filePath": [
237
- "children"
238
- ]
239
- },
240
- "sourcePath": {
241
- "fileName": "data",
242
- "jsonPath": "$.data"
243
- },
244
- "templateKey": "buildOption",
245
- "func": "fromCollection"
246
- },
247
- "buildOptionsArray": {
248
- "type": "single",
249
- "narration": "Build options array",
250
- "destinationPath": {
251
- "fileName": "base",
252
- "filePath": []
253
- },
254
- "sourcePath": {
255
- "fileName": "data",
256
- "jsonPath": "$.data"
257
- },
258
- "templateKey": "buildOption",
259
- "func": "fromCollection"
260
- },
261
- "buildDataListWithOptions": {
262
- "type": "columnOnRow",
263
- "narration": "Build datalists with options",
264
- "destinationPath": {
265
- "fileName": "base",
266
- "filePath": [
267
- "children"
268
- ]
269
- },
270
- "templateKey": {
271
- "columnKey": "buildDataList",
272
- "rowKey": "buildOption"
273
- }
274
- }
275
- }