json-renderers-run-instructions 1.6.1 → 1.7.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.
- package/package.json +3 -3
- package/src/index.js +2 -2
- package/src/v7/index.js +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-renderers-run-instructions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"json-instruction-single": "^1.8.1",
|
|
21
21
|
"json-transformer-funcs-row-on-column": "^1.2.1",
|
|
22
22
|
"json-transformer-funcs-column-on-row": "^1.2.1",
|
|
23
|
-
"spec-repo": "^1.
|
|
23
|
+
"spec-repo": "^1.15.1",
|
|
24
24
|
"json-write-path": "^1.6.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"spec-repo": "^1.
|
|
27
|
+
"spec-repo": "^1.15.1"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v7/index.js";
|
|
2
2
|
|
|
3
|
-
export { default } from "./
|
|
3
|
+
export { default } from "./v7/index.js";
|
package/src/v7/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import runSingleInstructions from "json-instruction-single";
|
|
2
|
+
import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
|
|
3
|
+
import columnOnRowFunc from "json-transformer-funcs-column-on-row";
|
|
4
|
+
import writePath from "json-write-path";
|
|
5
|
+
import spec from "spec-repo";
|
|
6
|
+
|
|
7
|
+
const runRowOnColumnInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
|
|
8
|
+
instructions.forEach(instruction => {
|
|
9
|
+
const columnSpec = spec[instruction?.templateKey?.columnKey];
|
|
10
|
+
const rowSpec = spec[instruction?.templateKey?.rowKey];
|
|
11
|
+
const result = rowOnColumnFunc({
|
|
12
|
+
columns: data?.columns,
|
|
13
|
+
data: data?.data,
|
|
14
|
+
columnSpec,
|
|
15
|
+
rowSpec
|
|
16
|
+
});
|
|
17
|
+
if (showLog) console.log("[runInstructions:rowOnColumn]", instruction.narration, result);
|
|
18
|
+
writePath({ base, data }, instruction.destinationPath, result, showLog);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const runColumnOnRowInstructions = ({ instructions = [], base, data, showLog = false } = {}) => {
|
|
23
|
+
instructions.forEach(instruction => {
|
|
24
|
+
const columnSpec = spec[instruction?.templateKey?.columnKey];
|
|
25
|
+
const rowSpec = spec[instruction?.templateKey?.rowKey];
|
|
26
|
+
const result = columnOnRowFunc({
|
|
27
|
+
columns: data?.columns,
|
|
28
|
+
data: data?.data,
|
|
29
|
+
columnSpec,
|
|
30
|
+
rowSpec
|
|
31
|
+
});
|
|
32
|
+
if (showLog) console.log("[runInstructions:columnOnRow]", instruction.narration, result);
|
|
33
|
+
writePath({ base, data }, instruction.destinationPath, result, showLog);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const runInstructions = ({
|
|
38
|
+
single = [],
|
|
39
|
+
rowOnColumn = [],
|
|
40
|
+
columnOnRow = [],
|
|
41
|
+
base,
|
|
42
|
+
data,
|
|
43
|
+
showLog = false
|
|
44
|
+
} = {}) => {
|
|
45
|
+
if (!Array.isArray(single)) throw new TypeError("single instructions must be an array");
|
|
46
|
+
if (!Array.isArray(rowOnColumn)) throw new TypeError("rowOnColumn instructions must be an array");
|
|
47
|
+
if (!Array.isArray(columnOnRow)) throw new TypeError("columnOnRow instructions must be an array");
|
|
48
|
+
|
|
49
|
+
const context = { base, data };
|
|
50
|
+
if (showLog) console.log("runInstructions input:", { single, rowOnColumn, columnOnRow, base, data });
|
|
51
|
+
if (single.length) runSingleInstructions(single, context, showLog);
|
|
52
|
+
if (rowOnColumn.length) runRowOnColumnInstructions({ instructions: rowOnColumn, base, data, showLog });
|
|
53
|
+
if (columnOnRow.length) runColumnOnRowInstructions({ instructions: columnOnRow, base, data, showLog });
|
|
54
|
+
return context;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default runInstructions;
|