json-renderers-run-instructions 1.4.1 → 1.5.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.
- package/package.json +2 -2
- package/src/index.js +2 -2
- package/src/v4/index.js +99 -99
- package/src/v5/index.js +68 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-renderers-run-instructions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.3",
|
|
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",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"json-transformer-funcs-column-on-row": "^1.2.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"spec-repo": "^1.7.
|
|
25
|
+
"spec-repo": "^1.7.5"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v5/index.js";
|
|
2
2
|
|
|
3
|
-
export { default } from "./
|
|
3
|
+
export { default } from "./v5/index.js";
|
package/src/v4/index.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
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
|
-
|
|
7
|
-
const runRowOnColumnInstructions = ({ instructions = [], registry = {}, showLog = false } = {}) => {
|
|
8
|
-
const localSpec = registry?.spec;
|
|
9
|
-
const columns = registry?.data?.columns;
|
|
10
|
-
const data = registry?.data?.data;
|
|
11
|
-
|
|
12
|
-
instructions.forEach(instruction => {
|
|
13
|
-
const columnSpec = localSpec ? localSpec[instruction?.templateKey?.columnKey] : undefined;
|
|
14
|
-
const rowSpec = localSpec ? localSpec[instruction?.templateKey?.rowKey] : undefined;
|
|
15
|
-
|
|
16
|
-
const result = rowOnColumnFunc({
|
|
17
|
-
columns,
|
|
18
|
-
data,
|
|
19
|
-
columnSpec,
|
|
20
|
-
rowSpec
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (showLog) console.log("[runInstructions:rowOnColumn]", instruction.narration, result);
|
|
24
|
-
writePath(registry, instruction.destinationPath, result);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const runColumnOnRowInstructions = ({ instructions = [], registry = {}, showLog = false } = {}) => {
|
|
29
|
-
const localSpec = registry?.spec;
|
|
30
|
-
const columns = registry?.data?.columns;
|
|
31
|
-
const data = registry?.data?.data;
|
|
32
|
-
|
|
33
|
-
instructions.forEach(instruction => {
|
|
34
|
-
const columnSpec = localSpec ? localSpec[instruction?.templateKey?.columnKey] : undefined;
|
|
35
|
-
const rowSpec = localSpec ? localSpec[instruction?.templateKey?.rowKey] : undefined;
|
|
36
|
-
|
|
37
|
-
const result = columnOnRowFunc({
|
|
38
|
-
columns,
|
|
39
|
-
data,
|
|
40
|
-
columnSpec,
|
|
41
|
-
rowSpec
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (showLog) console.log("[runInstructions:columnOnRow]", instruction.narration, result);
|
|
45
|
-
writePath(registry, instruction.destinationPath, result);
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const runInstructions = ({
|
|
50
|
-
single = [],
|
|
51
|
-
double = [],
|
|
52
|
-
rowOnColumn = [],
|
|
53
|
-
columnOnRow = [],
|
|
54
|
-
registry = {},
|
|
55
|
-
showLog = false
|
|
56
|
-
} = {}) => {
|
|
57
|
-
if (showLog) console.log("runInstructions input:", { single, double, rowOnColumn, columnOnRow });
|
|
58
|
-
|
|
59
|
-
if (!Array.isArray(single)) throw new TypeError("single instructions must be an array");
|
|
60
|
-
if (!Array.isArray(double)) throw new TypeError("double instructions must be an array");
|
|
61
|
-
if (!Array.isArray(rowOnColumn)) throw new TypeError("rowOnColumn instructions must be an array");
|
|
62
|
-
if (!Array.isArray(columnOnRow)) throw new TypeError("columnOnRow instructions must be an array");
|
|
63
|
-
if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
|
|
64
|
-
throw new TypeError("registry must be an object");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (single.length > 0) {
|
|
68
|
-
runSingleInstructions(single, registry, showLog);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (double.length > 0) {
|
|
72
|
-
runDoubleInstructions({
|
|
73
|
-
instructions: double,
|
|
74
|
-
registry,
|
|
75
|
-
showLog
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (rowOnColumn.length > 0) {
|
|
80
|
-
runRowOnColumnInstructions({
|
|
81
|
-
instructions: rowOnColumn,
|
|
82
|
-
registry,
|
|
83
|
-
showLog
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (columnOnRow.length > 0) {
|
|
88
|
-
runColumnOnRowInstructions({
|
|
89
|
-
instructions: columnOnRow,
|
|
90
|
-
registry,
|
|
91
|
-
showLog
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return registry;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default runInstructions;
|
|
99
|
-
|
|
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
|
+
|
|
7
|
+
const runRowOnColumnInstructions = ({ instructions = [], registry = {}, showLog = false } = {}) => {
|
|
8
|
+
const localSpec = registry?.spec;
|
|
9
|
+
const columns = registry?.data?.columns;
|
|
10
|
+
const data = registry?.data?.data;
|
|
11
|
+
|
|
12
|
+
instructions.forEach(instruction => {
|
|
13
|
+
const columnSpec = localSpec ? localSpec[instruction?.templateKey?.columnKey] : undefined;
|
|
14
|
+
const rowSpec = localSpec ? localSpec[instruction?.templateKey?.rowKey] : undefined;
|
|
15
|
+
|
|
16
|
+
const result = rowOnColumnFunc({
|
|
17
|
+
columns,
|
|
18
|
+
data,
|
|
19
|
+
columnSpec,
|
|
20
|
+
rowSpec
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (showLog) console.log("[runInstructions:rowOnColumn]", instruction.narration, result);
|
|
24
|
+
writePath(registry, instruction.destinationPath, result);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const runColumnOnRowInstructions = ({ instructions = [], registry = {}, showLog = false } = {}) => {
|
|
29
|
+
const localSpec = registry?.spec;
|
|
30
|
+
const columns = registry?.data?.columns;
|
|
31
|
+
const data = registry?.data?.data;
|
|
32
|
+
|
|
33
|
+
instructions.forEach(instruction => {
|
|
34
|
+
const columnSpec = localSpec ? localSpec[instruction?.templateKey?.columnKey] : undefined;
|
|
35
|
+
const rowSpec = localSpec ? localSpec[instruction?.templateKey?.rowKey] : undefined;
|
|
36
|
+
|
|
37
|
+
const result = columnOnRowFunc({
|
|
38
|
+
columns,
|
|
39
|
+
data,
|
|
40
|
+
columnSpec,
|
|
41
|
+
rowSpec
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (showLog) console.log("[runInstructions:columnOnRow]", instruction.narration, result);
|
|
45
|
+
writePath(registry, instruction.destinationPath, result);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const runInstructions = ({
|
|
50
|
+
single = [],
|
|
51
|
+
double = [],
|
|
52
|
+
rowOnColumn = [],
|
|
53
|
+
columnOnRow = [],
|
|
54
|
+
registry = {},
|
|
55
|
+
showLog = false
|
|
56
|
+
} = {}) => {
|
|
57
|
+
if (showLog) console.log("runInstructions input:", { single, double, rowOnColumn, columnOnRow });
|
|
58
|
+
|
|
59
|
+
if (!Array.isArray(single)) throw new TypeError("single instructions must be an array");
|
|
60
|
+
if (!Array.isArray(double)) throw new TypeError("double instructions must be an array");
|
|
61
|
+
if (!Array.isArray(rowOnColumn)) throw new TypeError("rowOnColumn instructions must be an array");
|
|
62
|
+
if (!Array.isArray(columnOnRow)) throw new TypeError("columnOnRow instructions must be an array");
|
|
63
|
+
if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
|
|
64
|
+
throw new TypeError("registry must be an object");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (single.length > 0) {
|
|
68
|
+
runSingleInstructions(single, registry, showLog);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (double.length > 0) {
|
|
72
|
+
runDoubleInstructions({
|
|
73
|
+
instructions: double,
|
|
74
|
+
registry,
|
|
75
|
+
showLog
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (rowOnColumn.length > 0) {
|
|
80
|
+
runRowOnColumnInstructions({
|
|
81
|
+
instructions: rowOnColumn,
|
|
82
|
+
registry,
|
|
83
|
+
showLog
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (columnOnRow.length > 0) {
|
|
88
|
+
runColumnOnRowInstructions({
|
|
89
|
+
instructions: columnOnRow,
|
|
90
|
+
registry,
|
|
91
|
+
showLog
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return registry;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default runInstructions;
|
|
99
|
+
|
package/src/v5/index.js
ADDED
|
@@ -0,0 +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;
|