json-renderers-run-instructions 1.5.2 → 1.5.4

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 (2) hide show
  1. package/package.json +3 -2
  2. package/src/v5/index.js +68 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers-run-instructions",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Reusable instruction execution and JSON-to-DOM mounting runtime for JSON renderers",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -19,7 +19,8 @@
19
19
  "json-instruction-double": "^1.3.3",
20
20
  "json-instruction-single": "^1.6.2",
21
21
  "json-transformer-funcs-row-on-column": "^1.2.1",
22
- "json-transformer-funcs-column-on-row": "^1.2.1"
22
+ "json-transformer-funcs-column-on-row": "^1.2.1",
23
+ "spec-repo": "^1.7.2"
23
24
  },
24
25
  "devDependencies": {
25
26
  "spec-repo": "^1.7.2"
package/src/v5/index.js CHANGED
@@ -1,68 +1,68 @@
1
- import runSingleInstructions from "json-instruction-single";
2
- import runDoubleInstructions from "json-instruction-double";
3
- import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
4
- import columnOnRowFunc from "json-transformer-funcs-column-on-row";
5
- import writePath from "json-write-path";
6
- import spec from "spec-repo";
7
-
8
- const runRowOnColumnInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
9
- instructions.forEach(instruction => {
10
- const columnSpec = spec[instruction?.templateKey?.columnKey];
11
- const rowSpec = spec[instruction?.templateKey?.rowKey];
12
-
13
- const result = rowOnColumnFunc({
14
- columns: data?.columns,
15
- data: data?.data,
16
- columnSpec,
17
- rowSpec
18
- });
19
-
20
- if (showLog) console.log("[runInstructions:rowOnColumn]", instruction.narration, result);
21
- writePath({ base, data }, instruction.destinationPath, result);
22
- });
23
- };
24
-
25
- const runColumnOnRowInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
26
- instructions.forEach(instruction => {
27
- const columnSpec = spec[instruction?.templateKey?.columnKey];
28
- const rowSpec = spec[instruction?.templateKey?.rowKey];
29
-
30
- const result = columnOnRowFunc({
31
- columns: data?.columns,
32
- data: data?.data,
33
- columnSpec,
34
- rowSpec
35
- });
36
-
37
- if (showLog) console.log("[runInstructions:columnOnRow]", instruction.narration, result);
38
- writePath({ base, data }, instruction.destinationPath, result);
39
- });
40
- };
41
-
42
- export const runInstructions = ({
43
- single = [],
44
- double = [],
45
- rowOnColumn = [],
46
- columnOnRow = [],
47
- base,
48
- data,
49
- showLog = false
50
- } = {}) => {
51
- if (showLog) console.log("runInstructions input:", { single, double, rowOnColumn, columnOnRow, base, data });
52
-
53
- if (!Array.isArray(single)) throw new TypeError("single instructions must be an array");
54
- if (!Array.isArray(double)) throw new TypeError("double instructions must be an array");
55
- if (!Array.isArray(rowOnColumn)) throw new TypeError("rowOnColumn instructions must be an array");
56
- if (!Array.isArray(columnOnRow)) throw new TypeError("columnOnRow instructions must be an array");
57
-
58
- const context = { base, data };
59
-
60
- if (single.length > 0) runSingleInstructions(single, context, showLog);
61
- if (double.length > 0) runDoubleInstructions({ instructions: double, registry: context, showLog });
62
- if (rowOnColumn.length > 0) runRowOnColumnInstructions({ instructions: rowOnColumn, base, data, showLog });
63
- if (columnOnRow.length > 0) runColumnOnRowInstructions({ instructions: columnOnRow, base, data, showLog });
64
-
65
- return base;
66
- };
67
-
68
- export default runInstructions;
1
+ import runSingleInstructions from "json-instruction-single";
2
+ import runDoubleInstructions from "json-instruction-double";
3
+ import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
4
+ import columnOnRowFunc from "json-transformer-funcs-column-on-row";
5
+ import writePath from "json-write-path";
6
+ import spec from "spec-repo";
7
+
8
+ const runRowOnColumnInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
9
+ instructions.forEach(instruction => {
10
+ const columnSpec = spec[instruction?.templateKey?.columnKey];
11
+ const rowSpec = spec[instruction?.templateKey?.rowKey];
12
+
13
+ const result = rowOnColumnFunc({
14
+ columns: data?.columns,
15
+ data: data?.data,
16
+ columnSpec,
17
+ rowSpec
18
+ });
19
+
20
+ if (showLog) console.log("[runInstructions:rowOnColumn]", instruction.narration, result);
21
+ writePath({ base, data }, instruction.destinationPath, result);
22
+ });
23
+ };
24
+
25
+ const runColumnOnRowInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
26
+ instructions.forEach(instruction => {
27
+ const columnSpec = spec[instruction?.templateKey?.columnKey];
28
+ const rowSpec = spec[instruction?.templateKey?.rowKey];
29
+
30
+ const result = columnOnRowFunc({
31
+ columns: data?.columns,
32
+ data: data?.data,
33
+ columnSpec,
34
+ rowSpec
35
+ });
36
+
37
+ if (showLog) console.log("[runInstructions:columnOnRow]", instruction.narration, result);
38
+ writePath({ base, data }, instruction.destinationPath, result);
39
+ });
40
+ };
41
+
42
+ export const runInstructions = ({
43
+ single = [],
44
+ double = [],
45
+ rowOnColumn = [],
46
+ columnOnRow = [],
47
+ base,
48
+ data,
49
+ showLog = false
50
+ } = {}) => {
51
+ if (showLog) console.log("runInstructions input:", { single, double, rowOnColumn, columnOnRow, base, data });
52
+
53
+ if (!Array.isArray(single)) throw new TypeError("single instructions must be an array");
54
+ if (!Array.isArray(double)) throw new TypeError("double instructions must be an array");
55
+ if (!Array.isArray(rowOnColumn)) throw new TypeError("rowOnColumn instructions must be an array");
56
+ if (!Array.isArray(columnOnRow)) throw new TypeError("columnOnRow instructions must be an array");
57
+
58
+ const context = { base, data };
59
+
60
+ if (single.length > 0) runSingleInstructions(single, context, showLog);
61
+ if (double.length > 0) runDoubleInstructions({ instructions: double, registry: context, showLog });
62
+ if (rowOnColumn.length > 0) runRowOnColumnInstructions({ instructions: rowOnColumn, base, data, showLog });
63
+ if (columnOnRow.length > 0) runColumnOnRowInstructions({ instructions: columnOnRow, base, data, showLog });
64
+
65
+ return base;
66
+ };
67
+
68
+ export default runInstructions;