json-instructions 1.2.1 → 1.4.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 -2
- package/src/guards/index.js +10 -0
- package/src/guards/references/func/index.js +8 -0
- package/src/guards/references/index.js +9 -0
- package/src/guards/references/templateKey/index.js +8 -0
- package/src/guards/structure/destinationPath/index.js +8 -0
- package/src/guards/structure/func/index.js +8 -0
- package/src/guards/structure/index.js +15 -0
- package/src/guards/structure/sourcePath/index.js +8 -0
- package/src/guards/structure/templateKey/index.js +9 -0
- package/src/index.js +2 -2
- package/src/singleInstruction/index.js +28 -0
- package/src/v3/index.js +25 -0
- package/src/v3/insertOptions/index.js +47 -0
- package/src/v3/insertOptions/instructions/footer.json +22 -0
- package/src/v3/insertOptions/instructions/single.json +62 -0
- package/src/v3/insertSearch/index.js +7 -0
- package/src/v3/insertSearch/instructions/template.json +20 -0
- package/src/v3/insertSerial/index.js +47 -0
- package/src/v3/insertSerial/instructions/footer.json +22 -0
- package/src/v3/insertSerial/instructions/single.json +62 -0
- package/src/v3/spec.json +107 -0
- package/src/v4/guards/index.js +10 -0
- package/src/v4/guards/references/func/index.js +8 -0
- package/src/v4/guards/references/index.js +9 -0
- package/src/v4/guards/references/templateKey/index.js +8 -0
- package/src/v4/guards/structure/destinationPath/index.js +8 -0
- package/src/v4/guards/structure/func/index.js +8 -0
- package/src/v4/guards/structure/index.js +15 -0
- package/src/v4/guards/structure/sourcePath/index.js +8 -0
- package/src/v4/guards/structure/templateKey/index.js +9 -0
- package/src/v4/index.js +28 -0
- package/src/v4/spec.json +107 -0
- package/src/v4/writePath/index.js +62 -0
- package/src/writePath/index.js +62 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-instructions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Focused table specification builder with configurable rows and cells",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"build": "vite build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@keshavsoft/json-to-dom": "^42.1.3",
|
|
20
21
|
"json-transformer-funcs": "^1.24.8",
|
|
21
22
|
"json-transformer-funcs-primitive": "^1.9.3"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"vite": "^8.3.4"
|
|
25
26
|
}
|
|
26
|
-
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import checkStructure from "./structure/index.js";
|
|
2
|
+
import checkReferences from "./references/index.js";
|
|
3
|
+
|
|
4
|
+
const checkInstruction = (instruction, functions, spec, showLog, returnLog) => {
|
|
5
|
+
const structurePassed = checkStructure(instruction, showLog, returnLog);
|
|
6
|
+
if (!structurePassed) return false;
|
|
7
|
+
return checkReferences(instruction, functions, spec, showLog, returnLog);
|
|
8
|
+
};
|
|
9
|
+
export { checkStructure, checkReferences, checkInstruction };
|
|
10
|
+
export default checkInstruction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkFunctionReference = (instruction, functions, showLog, returnLog) => {
|
|
2
|
+
const passed = typeof functions[instruction.func] === "function";
|
|
3
|
+
const message = `references/func (${instruction.func}): ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkFunctionReference;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import checkFunctionReference from "./func/index.js";
|
|
2
|
+
import checkSpecReference from "./templateKey/index.js";
|
|
3
|
+
|
|
4
|
+
const checkReferences = (instruction, functions, spec, showLog, returnLog) => {
|
|
5
|
+
const functionPassed = checkFunctionReference(instruction, functions, showLog, returnLog);
|
|
6
|
+
const specPassed = checkSpecReference(instruction, spec, showLog, returnLog);
|
|
7
|
+
return functionPassed && specPassed;
|
|
8
|
+
};
|
|
9
|
+
export default checkReferences;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkSpecReference = (instruction, spec, showLog, returnLog) => {
|
|
2
|
+
const passed = instruction.templateKey === undefined || Object.hasOwn(spec, instruction.templateKey);
|
|
3
|
+
const message = `references/templateKey${instruction.templateKey === undefined ? " (not used)" : ` (${instruction.templateKey})`}: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkSpecReference;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkDestinationPath = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = Boolean(instruction.destinationPath?.fileName && Array.isArray(instruction.destinationPath?.filePath));
|
|
3
|
+
const message = `structure/destinationPath: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkDestinationPath;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkFunc = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = typeof instruction.func === "string" && instruction.func.length > 0;
|
|
3
|
+
const message = `structure/func: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkFunc;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import checkSourcePath from "./sourcePath/index.js";
|
|
2
|
+
import checkDestinationPath from "./destinationPath/index.js";
|
|
3
|
+
import checkTemplateKey from "./templateKey/index.js";
|
|
4
|
+
import checkFunc from "./func/index.js";
|
|
5
|
+
|
|
6
|
+
const checkStructure = (instruction, showLog, returnLog) => {
|
|
7
|
+
const results = [
|
|
8
|
+
checkSourcePath(instruction, showLog, returnLog),
|
|
9
|
+
checkDestinationPath(instruction, showLog, returnLog),
|
|
10
|
+
checkTemplateKey(instruction, showLog, returnLog),
|
|
11
|
+
checkFunc(instruction, showLog, returnLog)
|
|
12
|
+
];
|
|
13
|
+
return results.every(Boolean);
|
|
14
|
+
};
|
|
15
|
+
export default checkStructure;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkSourcePath = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = Boolean(instruction.sourcePath?.fileName && Array.isArray(instruction.sourcePath?.filePath));
|
|
3
|
+
const message = `structure/sourcePath: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkSourcePath;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const checkTemplateKey = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = instruction.templateKey === undefined ||
|
|
3
|
+
(typeof instruction.templateKey === "string" && instruction.templateKey.length > 0);
|
|
4
|
+
const message = `structure/templateKey: ${passed ? "passed" : "failed"}`;
|
|
5
|
+
returnLog.push(message);
|
|
6
|
+
if (showLog) console.log(message);
|
|
7
|
+
return passed;
|
|
8
|
+
};
|
|
9
|
+
export default checkTemplateKey;
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v4/index.js";
|
|
2
|
+
export { default } from "./v4/index.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolvePath } from "json-transformer-funcs";
|
|
2
|
+
import writePath from "../writePath/index.js";
|
|
3
|
+
import checkInstruction from "../guards/index.js";
|
|
4
|
+
|
|
5
|
+
const runSingleInstruction = (instruction, registry, functions, spec, showLog, returnLog) => {
|
|
6
|
+
if (!checkInstruction(instruction, functions, spec, showLog, returnLog)) return;
|
|
7
|
+
|
|
8
|
+
const localShowLog = showLog;
|
|
9
|
+
const localSpec = spec;
|
|
10
|
+
const templateKey = instruction.templateKey;
|
|
11
|
+
const localSpecKey = localSpec[templateKey];
|
|
12
|
+
|
|
13
|
+
if (localShowLog) console.log("singleInstruction ; ", templateKey, localSpecKey);
|
|
14
|
+
|
|
15
|
+
const source = resolvePath(registry, instruction.sourcePath);
|
|
16
|
+
const result = functions[instruction.func](source, localSpecKey);
|
|
17
|
+
|
|
18
|
+
writePath(registry, instruction.destinationPath, result);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const runSingleInstructions = (instructions, registry, functions, spec, showLog, returnLog) => {
|
|
22
|
+
instructions.forEach(instruction => {
|
|
23
|
+
runSingleInstruction(instruction, registry, functions, spec, showLog, returnLog);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { runSingleInstruction, runSingleInstructions };
|
|
28
|
+
export default runSingleInstructions;
|
package/src/v3/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import insertSerial from "./insertSerial/index.js";
|
|
2
|
+
import insertOptions from "./insertOptions/index.js";
|
|
3
|
+
import insertSearch from "./insertSearch/index.js";
|
|
4
|
+
|
|
5
|
+
const startFunc = ({ inOptions = {}, inBase, showLog = false, returnLog = [] }) => {
|
|
6
|
+
const localOptions = inOptions;
|
|
7
|
+
|
|
8
|
+
const localBase = inBase;
|
|
9
|
+
|
|
10
|
+
if (localOptions.showSerial || localOptions.serial) {
|
|
11
|
+
insertSerial(localBase, localOptions.serial || {}, showLog, returnLog);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (localOptions.showOptions || localOptions.options) {
|
|
15
|
+
insertOptions(localBase, localOptions.options || {}, showLog, returnLog);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (localOptions.showSearch) {
|
|
19
|
+
insertSearch();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return localBase;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default startFunc;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import applyTemplate from "json-transformer-funcs-primitive";
|
|
2
|
+
import { findByRole } from "json-transformer-funcs";
|
|
3
|
+
|
|
4
|
+
import spec from "../spec.json" with { type: "json" };
|
|
5
|
+
import singleInstructions from "./instructions/single.json" with { type: "json" };
|
|
6
|
+
import footerInstructions from "./instructions/footer.json" with { type: "json" };
|
|
7
|
+
|
|
8
|
+
import runSingleInstructions from "../../singleInstruction/index.js";
|
|
9
|
+
|
|
10
|
+
const functions = { applyTemplate };
|
|
11
|
+
|
|
12
|
+
const insertOptions = (input = {}, config = {}, showLog = false, returnLog = []) => {
|
|
13
|
+
let localTableSpec = input;
|
|
14
|
+
let localOptions = config;
|
|
15
|
+
|
|
16
|
+
if (input && typeof input === "object" && "inTableSpec" in input) {
|
|
17
|
+
localTableSpec = input.inTableSpec;
|
|
18
|
+
localOptions = input.inOptions || config;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const localOptionsMerged = {
|
|
22
|
+
col: { width: "100px" },
|
|
23
|
+
header: { columnName: "options" },
|
|
24
|
+
body: { columnName: "show" },
|
|
25
|
+
footer: {},
|
|
26
|
+
...localOptions
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const registry = {
|
|
30
|
+
data: {
|
|
31
|
+
options: localOptionsMerged
|
|
32
|
+
},
|
|
33
|
+
base: localTableSpec,
|
|
34
|
+
spec
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
|
|
38
|
+
|
|
39
|
+
const footerRow = findByRole(localTableSpec, "table-footer-row");
|
|
40
|
+
if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
|
|
41
|
+
runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return localTableSpec;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default insertOptions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Append an empty cell into the table footer row if footer row is present.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-footer-row",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
],
|
|
10
|
+
"action": "push"
|
|
11
|
+
},
|
|
12
|
+
"sourcePath": {
|
|
13
|
+
"fileName": "data",
|
|
14
|
+
"filePath": [
|
|
15
|
+
"options",
|
|
16
|
+
"footer"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"templateKey": "emptyCell",
|
|
20
|
+
"func": "applyTemplate"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Append the options column width to the table colgroup.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-colgroup",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
],
|
|
10
|
+
"action": "push"
|
|
11
|
+
},
|
|
12
|
+
"sourcePath": {
|
|
13
|
+
"fileName": "data",
|
|
14
|
+
"filePath": [
|
|
15
|
+
"options",
|
|
16
|
+
"col"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"templateKey": "buildColGroup",
|
|
20
|
+
"func": "applyTemplate"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"narration": "Append the options header cell to the table header row.",
|
|
24
|
+
"destinationPath": {
|
|
25
|
+
"fileName": "base",
|
|
26
|
+
"dataRole": "table-header-row",
|
|
27
|
+
"filePath": [
|
|
28
|
+
"children"
|
|
29
|
+
],
|
|
30
|
+
"action": "push"
|
|
31
|
+
},
|
|
32
|
+
"sourcePath": {
|
|
33
|
+
"fileName": "data",
|
|
34
|
+
"filePath": [
|
|
35
|
+
"options",
|
|
36
|
+
"header"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"templateKey": "buildHeader",
|
|
40
|
+
"func": "applyTemplate"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"narration": "Append the options button cell into each table body row.",
|
|
44
|
+
"destinationPath": {
|
|
45
|
+
"fileName": "base",
|
|
46
|
+
"dataRole": "table-body",
|
|
47
|
+
"filePath": [
|
|
48
|
+
"children"
|
|
49
|
+
],
|
|
50
|
+
"action": "pushToRows"
|
|
51
|
+
},
|
|
52
|
+
"sourcePath": {
|
|
53
|
+
"fileName": "data",
|
|
54
|
+
"filePath": [
|
|
55
|
+
"options",
|
|
56
|
+
"body"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"templateKey": "optionsButtonCell",
|
|
60
|
+
"func": "applyTemplate"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tagName": "div",
|
|
3
|
+
"children": [
|
|
4
|
+
{
|
|
5
|
+
"tagName": "label",
|
|
6
|
+
"textContent": "KeshavSoft"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tagName": "input",
|
|
10
|
+
"attributes": {
|
|
11
|
+
"value": "KeshavSoft",
|
|
12
|
+
"placeholder": "KeshavSoft"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"tagName": "button",
|
|
17
|
+
"textContent": "show"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import applyTemplate from "json-transformer-funcs-primitive";
|
|
2
|
+
import { findByRole } from "json-transformer-funcs";
|
|
3
|
+
|
|
4
|
+
import spec from "../spec.json" with { type: "json" };
|
|
5
|
+
import singleInstructions from "./instructions/single.json" with { type: "json" };
|
|
6
|
+
import footerInstructions from "./instructions/footer.json" with { type: "json" };
|
|
7
|
+
|
|
8
|
+
import runSingleInstructions from "../../singleInstruction/index.js";
|
|
9
|
+
|
|
10
|
+
const functions = { applyTemplate };
|
|
11
|
+
|
|
12
|
+
const insertSerial = (input = {}, config = {}, showLog = false, returnLog = []) => {
|
|
13
|
+
let localTableSpec = input;
|
|
14
|
+
let localSerial = config;
|
|
15
|
+
|
|
16
|
+
if (input && typeof input === "object" && "inTableSpec" in input) {
|
|
17
|
+
localTableSpec = input.inTableSpec;
|
|
18
|
+
localSerial = input.inSerial || config;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const localSerialMerged = {
|
|
22
|
+
col: { width: "50px" },
|
|
23
|
+
header: { columnName: "#" },
|
|
24
|
+
body: {},
|
|
25
|
+
footer: {},
|
|
26
|
+
...localSerial
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const registry = {
|
|
30
|
+
data: {
|
|
31
|
+
serial: localSerialMerged
|
|
32
|
+
},
|
|
33
|
+
base: localTableSpec,
|
|
34
|
+
spec
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
|
|
38
|
+
|
|
39
|
+
const footerRow = findByRole(localTableSpec, "table-footer-row");
|
|
40
|
+
if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
|
|
41
|
+
runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return localTableSpec;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default insertSerial;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Prepend an empty cell into the table footer row if footer row is present.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-footer-row",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
],
|
|
10
|
+
"action": "unshift"
|
|
11
|
+
},
|
|
12
|
+
"sourcePath": {
|
|
13
|
+
"fileName": "data",
|
|
14
|
+
"filePath": [
|
|
15
|
+
"serial",
|
|
16
|
+
"footer"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"templateKey": "emptyCell",
|
|
20
|
+
"func": "applyTemplate"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Prepend the serial column width to the table colgroup.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-colgroup",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
],
|
|
10
|
+
"action": "unshift"
|
|
11
|
+
},
|
|
12
|
+
"sourcePath": {
|
|
13
|
+
"fileName": "data",
|
|
14
|
+
"filePath": [
|
|
15
|
+
"serial",
|
|
16
|
+
"col"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"templateKey": "buildColGroup",
|
|
20
|
+
"func": "applyTemplate"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"narration": "Prepend the serial header cell to the table header row.",
|
|
24
|
+
"destinationPath": {
|
|
25
|
+
"fileName": "base",
|
|
26
|
+
"dataRole": "table-header-row",
|
|
27
|
+
"filePath": [
|
|
28
|
+
"children"
|
|
29
|
+
],
|
|
30
|
+
"action": "unshift"
|
|
31
|
+
},
|
|
32
|
+
"sourcePath": {
|
|
33
|
+
"fileName": "data",
|
|
34
|
+
"filePath": [
|
|
35
|
+
"serial",
|
|
36
|
+
"header"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"templateKey": "buildHeader",
|
|
40
|
+
"func": "applyTemplate"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"narration": "Prepend the serial number cell into each table body row.",
|
|
44
|
+
"destinationPath": {
|
|
45
|
+
"fileName": "base",
|
|
46
|
+
"dataRole": "table-body",
|
|
47
|
+
"filePath": [
|
|
48
|
+
"children"
|
|
49
|
+
],
|
|
50
|
+
"action": "unshiftSerialToRows"
|
|
51
|
+
},
|
|
52
|
+
"sourcePath": {
|
|
53
|
+
"fileName": "data",
|
|
54
|
+
"filePath": [
|
|
55
|
+
"serial",
|
|
56
|
+
"body"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"templateKey": "buildBodyCell",
|
|
60
|
+
"func": "applyTemplate"
|
|
61
|
+
}
|
|
62
|
+
]
|
package/src/v3/spec.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildBodyTr": {
|
|
3
|
+
"tagName": "tr",
|
|
4
|
+
"attributes": {
|
|
5
|
+
"class": "align-middle"
|
|
6
|
+
},
|
|
7
|
+
"children": []
|
|
8
|
+
},
|
|
9
|
+
"buildColGroup": {
|
|
10
|
+
"tagName": "col",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"width": "${width}"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"buildHeader": {
|
|
16
|
+
"tagName": "th",
|
|
17
|
+
"textContent": "${columnName}",
|
|
18
|
+
"attributes": {
|
|
19
|
+
"class": "py-3 px-3 fw-semibold text-uppercase small"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"buildFooter": {
|
|
23
|
+
"tagName": "td",
|
|
24
|
+
"children": [
|
|
25
|
+
{
|
|
26
|
+
"tagName": "input",
|
|
27
|
+
"attributes": {
|
|
28
|
+
"type": "text",
|
|
29
|
+
"placeholder": "enter ${columnName}",
|
|
30
|
+
"name": "${columnName}",
|
|
31
|
+
"id": "${columnName}",
|
|
32
|
+
"list": "${columnName}",
|
|
33
|
+
"class": "form-control"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"buildBodyCell": {
|
|
39
|
+
"tagName": "td",
|
|
40
|
+
"textContent": "${rowValue}",
|
|
41
|
+
"attributes": {
|
|
42
|
+
"class": "py-3 px-3 text-secondary"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"button": {
|
|
46
|
+
"tagName": "button",
|
|
47
|
+
"textContent": "${columnName}",
|
|
48
|
+
"attributes": {
|
|
49
|
+
"class": "btn btn-primary btn-sm"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"buttonCell": {
|
|
53
|
+
"tagName": "td",
|
|
54
|
+
"attributes": {
|
|
55
|
+
"class": "py-2 px-3 text-center"
|
|
56
|
+
},
|
|
57
|
+
"children": [
|
|
58
|
+
{
|
|
59
|
+
"tagName": "button",
|
|
60
|
+
"textContent": "${agg:count}",
|
|
61
|
+
"attributes": {
|
|
62
|
+
"class": "btn btn-primary btn-sm"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"optionsButtonCell": {
|
|
68
|
+
"tagName": "td",
|
|
69
|
+
"attributes": {
|
|
70
|
+
"class": "py-2 px-3 text-center"
|
|
71
|
+
},
|
|
72
|
+
"children": [
|
|
73
|
+
{
|
|
74
|
+
"tagName": "button",
|
|
75
|
+
"textContent": "${columnName}",
|
|
76
|
+
"attributes": {
|
|
77
|
+
"class": "btn btn-primary btn-sm"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"buildOption": {
|
|
83
|
+
"tagName": "option",
|
|
84
|
+
"textContent": "${rowValue}",
|
|
85
|
+
"attributes": {
|
|
86
|
+
"value": "${rowValue}"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"buildSelect": {
|
|
90
|
+
"tagName": "select",
|
|
91
|
+
"attributes": {
|
|
92
|
+
"id": "LedgerName"
|
|
93
|
+
},
|
|
94
|
+
"children": []
|
|
95
|
+
},
|
|
96
|
+
"buildDataList": {
|
|
97
|
+
"tagName": "datalist",
|
|
98
|
+
"attributes": {
|
|
99
|
+
"data-name": "${columnName}"
|
|
100
|
+
},
|
|
101
|
+
"children": []
|
|
102
|
+
},
|
|
103
|
+
"emptyCell": {
|
|
104
|
+
"tagName": "td",
|
|
105
|
+
"children": []
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import checkStructure from "./structure/index.js";
|
|
2
|
+
import checkReferences from "./references/index.js";
|
|
3
|
+
|
|
4
|
+
const checkInstruction = (instruction, functions, spec, showLog, returnLog) => {
|
|
5
|
+
const structurePassed = checkStructure(instruction, showLog, returnLog);
|
|
6
|
+
if (!structurePassed) return false;
|
|
7
|
+
return checkReferences(instruction, functions, spec, showLog, returnLog);
|
|
8
|
+
};
|
|
9
|
+
export { checkStructure, checkReferences, checkInstruction };
|
|
10
|
+
export default checkInstruction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkFunctionReference = (instruction, functions, showLog, returnLog) => {
|
|
2
|
+
const passed = typeof functions[instruction.func] === "function";
|
|
3
|
+
const message = `references/func (${instruction.func}): ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkFunctionReference;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import checkFunctionReference from "./func/index.js";
|
|
2
|
+
import checkSpecReference from "./templateKey/index.js";
|
|
3
|
+
|
|
4
|
+
const checkReferences = (instruction, functions, spec, showLog, returnLog) => {
|
|
5
|
+
const functionPassed = checkFunctionReference(instruction, functions, showLog, returnLog);
|
|
6
|
+
const specPassed = checkSpecReference(instruction, spec, showLog, returnLog);
|
|
7
|
+
return functionPassed && specPassed;
|
|
8
|
+
};
|
|
9
|
+
export default checkReferences;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkSpecReference = (instruction, spec, showLog, returnLog) => {
|
|
2
|
+
const passed = instruction.templateKey === undefined || Object.hasOwn(spec, instruction.templateKey);
|
|
3
|
+
const message = `references/templateKey${instruction.templateKey === undefined ? " (not used)" : ` (${instruction.templateKey})`}: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkSpecReference;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkDestinationPath = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = Boolean(instruction.destinationPath?.fileName && Array.isArray(instruction.destinationPath?.filePath));
|
|
3
|
+
const message = `structure/destinationPath: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkDestinationPath;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkFunc = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = typeof instruction.func === "string" && instruction.func.length > 0;
|
|
3
|
+
const message = `structure/func: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkFunc;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import checkSourcePath from "./sourcePath/index.js";
|
|
2
|
+
import checkDestinationPath from "./destinationPath/index.js";
|
|
3
|
+
import checkTemplateKey from "./templateKey/index.js";
|
|
4
|
+
import checkFunc from "./func/index.js";
|
|
5
|
+
|
|
6
|
+
const checkStructure = (instruction, showLog, returnLog) => {
|
|
7
|
+
const results = [
|
|
8
|
+
checkSourcePath(instruction, showLog, returnLog),
|
|
9
|
+
checkDestinationPath(instruction, showLog, returnLog),
|
|
10
|
+
checkTemplateKey(instruction, showLog, returnLog),
|
|
11
|
+
checkFunc(instruction, showLog, returnLog)
|
|
12
|
+
];
|
|
13
|
+
return results.every(Boolean);
|
|
14
|
+
};
|
|
15
|
+
export default checkStructure;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const checkSourcePath = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = Boolean(instruction.sourcePath?.fileName && Array.isArray(instruction.sourcePath?.filePath));
|
|
3
|
+
const message = `structure/sourcePath: ${passed ? "passed" : "failed"}`;
|
|
4
|
+
returnLog.push(message);
|
|
5
|
+
if (showLog) console.log(message);
|
|
6
|
+
return passed;
|
|
7
|
+
};
|
|
8
|
+
export default checkSourcePath;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const checkTemplateKey = (instruction, showLog, returnLog) => {
|
|
2
|
+
const passed = instruction.templateKey === undefined ||
|
|
3
|
+
(typeof instruction.templateKey === "string" && instruction.templateKey.length > 0);
|
|
4
|
+
const message = `structure/templateKey: ${passed ? "passed" : "failed"}`;
|
|
5
|
+
returnLog.push(message);
|
|
6
|
+
if (showLog) console.log(message);
|
|
7
|
+
return passed;
|
|
8
|
+
};
|
|
9
|
+
export default checkTemplateKey;
|
package/src/v4/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolvePath } from "json-transformer-funcs";
|
|
2
|
+
import writePath from "./writePath/index.js";
|
|
3
|
+
import checkInstruction from "./guards/index.js";
|
|
4
|
+
|
|
5
|
+
const runSingleInstruction = (instruction, registry, functions, spec, showLog, returnLog) => {
|
|
6
|
+
if (!checkInstruction(instruction, functions, spec, showLog, returnLog)) return;
|
|
7
|
+
|
|
8
|
+
const localShowLog = showLog;
|
|
9
|
+
const localSpec = spec;
|
|
10
|
+
const templateKey = instruction.templateKey;
|
|
11
|
+
const localSpecKey = localSpec[templateKey];
|
|
12
|
+
|
|
13
|
+
if (localShowLog) console.log("singleInstruction ; ", templateKey, localSpecKey);
|
|
14
|
+
|
|
15
|
+
const source = resolvePath(registry, instruction.sourcePath);
|
|
16
|
+
const result = functions[instruction.func](source, localSpecKey);
|
|
17
|
+
|
|
18
|
+
writePath(registry, instruction.destinationPath, result);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const runSingleInstructions = (instructions, registry, functions, spec, showLog, returnLog) => {
|
|
22
|
+
instructions.forEach(instruction => {
|
|
23
|
+
runSingleInstruction(instruction, registry, functions, spec, showLog, returnLog);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { runSingleInstruction, runSingleInstructions };
|
|
28
|
+
export default runSingleInstructions;
|
package/src/v4/spec.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildBodyTr": {
|
|
3
|
+
"tagName": "tr",
|
|
4
|
+
"attributes": {
|
|
5
|
+
"class": "align-middle"
|
|
6
|
+
},
|
|
7
|
+
"children": []
|
|
8
|
+
},
|
|
9
|
+
"buildColGroup": {
|
|
10
|
+
"tagName": "col",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"width": "${width}"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"buildHeader": {
|
|
16
|
+
"tagName": "th",
|
|
17
|
+
"textContent": "${columnName}",
|
|
18
|
+
"attributes": {
|
|
19
|
+
"class": "py-3 px-3 fw-semibold text-uppercase small"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"buildFooter": {
|
|
23
|
+
"tagName": "td",
|
|
24
|
+
"children": [
|
|
25
|
+
{
|
|
26
|
+
"tagName": "input",
|
|
27
|
+
"attributes": {
|
|
28
|
+
"type": "text",
|
|
29
|
+
"placeholder": "enter ${columnName}",
|
|
30
|
+
"name": "${columnName}",
|
|
31
|
+
"id": "${columnName}",
|
|
32
|
+
"list": "${columnName}",
|
|
33
|
+
"class": "form-control"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"buildBodyCell": {
|
|
39
|
+
"tagName": "td",
|
|
40
|
+
"textContent": "${rowValue}",
|
|
41
|
+
"attributes": {
|
|
42
|
+
"class": "py-3 px-3 text-secondary"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"button": {
|
|
46
|
+
"tagName": "button",
|
|
47
|
+
"textContent": "${columnName}",
|
|
48
|
+
"attributes": {
|
|
49
|
+
"class": "btn btn-primary btn-sm"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"buttonCell": {
|
|
53
|
+
"tagName": "td",
|
|
54
|
+
"attributes": {
|
|
55
|
+
"class": "py-2 px-3 text-center"
|
|
56
|
+
},
|
|
57
|
+
"children": [
|
|
58
|
+
{
|
|
59
|
+
"tagName": "button",
|
|
60
|
+
"textContent": "${agg:count}",
|
|
61
|
+
"attributes": {
|
|
62
|
+
"class": "btn btn-primary btn-sm"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"optionsButtonCell": {
|
|
68
|
+
"tagName": "td",
|
|
69
|
+
"attributes": {
|
|
70
|
+
"class": "py-2 px-3 text-center"
|
|
71
|
+
},
|
|
72
|
+
"children": [
|
|
73
|
+
{
|
|
74
|
+
"tagName": "button",
|
|
75
|
+
"textContent": "${columnName}",
|
|
76
|
+
"attributes": {
|
|
77
|
+
"class": "btn btn-primary btn-sm"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"buildOption": {
|
|
83
|
+
"tagName": "option",
|
|
84
|
+
"textContent": "${rowValue}",
|
|
85
|
+
"attributes": {
|
|
86
|
+
"value": "${rowValue}"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"buildSelect": {
|
|
90
|
+
"tagName": "select",
|
|
91
|
+
"attributes": {
|
|
92
|
+
"id": "LedgerName"
|
|
93
|
+
},
|
|
94
|
+
"children": []
|
|
95
|
+
},
|
|
96
|
+
"buildDataList": {
|
|
97
|
+
"tagName": "datalist",
|
|
98
|
+
"attributes": {
|
|
99
|
+
"data-name": "${columnName}"
|
|
100
|
+
},
|
|
101
|
+
"children": []
|
|
102
|
+
},
|
|
103
|
+
"emptyCell": {
|
|
104
|
+
"tagName": "td",
|
|
105
|
+
"children": []
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { findByRole } from "json-transformer-funcs";
|
|
2
|
+
|
|
3
|
+
const toArray = value => Array.isArray(value) ? value : [value];
|
|
4
|
+
|
|
5
|
+
const set = (parent, key, value) => {
|
|
6
|
+
parent[key] = value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const push = (parent, key, value) => {
|
|
10
|
+
parent[key].push(...toArray(value));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const unshift = (parent, key, value) => {
|
|
14
|
+
parent[key].unshift(...toArray(value));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const pushToRows = (parent, key, value) => {
|
|
18
|
+
parent[key].forEach(row => {
|
|
19
|
+
row.children.push(...structuredClone(toArray(value)));
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const unshiftToRows = (parent, key, value) => {
|
|
24
|
+
parent[key].forEach(row => {
|
|
25
|
+
row.children.unshift(...structuredClone(toArray(value)));
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const unshiftSerialToRows = (parent, key, value) => {
|
|
30
|
+
parent[key].forEach((row, rowIndex) => {
|
|
31
|
+
const item = structuredClone(value);
|
|
32
|
+
item.textContent = rowIndex + 1;
|
|
33
|
+
row.children.unshift(item);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const actions = {
|
|
38
|
+
set,
|
|
39
|
+
push,
|
|
40
|
+
unshift,
|
|
41
|
+
pushToRows,
|
|
42
|
+
unshiftToRows,
|
|
43
|
+
unshiftSerialToRows
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const resolveParent = (registry, path) => {
|
|
47
|
+
const root = path.dataRole
|
|
48
|
+
? findByRole(registry[path.fileName], path.dataRole)
|
|
49
|
+
: registry[path.fileName];
|
|
50
|
+
const keys = [...(path.filePath ?? [])];
|
|
51
|
+
const key = keys.pop();
|
|
52
|
+
const parent = keys.reduce((current, nextKey) => current[nextKey], root);
|
|
53
|
+
return { parent, key };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const writePath = (registry, path, value) => {
|
|
57
|
+
const { parent, key } = resolveParent(registry, path);
|
|
58
|
+
const action = actions[path.action] || set;
|
|
59
|
+
action(parent, key, value);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default writePath;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { findByRole } from "json-transformer-funcs";
|
|
2
|
+
|
|
3
|
+
const toArray = value => Array.isArray(value) ? value : [value];
|
|
4
|
+
|
|
5
|
+
const set = (parent, key, value) => {
|
|
6
|
+
parent[key] = value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const push = (parent, key, value) => {
|
|
10
|
+
parent[key].push(...toArray(value));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const unshift = (parent, key, value) => {
|
|
14
|
+
parent[key].unshift(...toArray(value));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const pushToRows = (parent, key, value) => {
|
|
18
|
+
parent[key].forEach(row => {
|
|
19
|
+
row.children.push(...structuredClone(toArray(value)));
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const unshiftToRows = (parent, key, value) => {
|
|
24
|
+
parent[key].forEach(row => {
|
|
25
|
+
row.children.unshift(...structuredClone(toArray(value)));
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const unshiftSerialToRows = (parent, key, value) => {
|
|
30
|
+
parent[key].forEach((row, rowIndex) => {
|
|
31
|
+
const item = structuredClone(value);
|
|
32
|
+
item.textContent = rowIndex + 1;
|
|
33
|
+
row.children.unshift(item);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const actions = {
|
|
38
|
+
set,
|
|
39
|
+
push,
|
|
40
|
+
unshift,
|
|
41
|
+
pushToRows,
|
|
42
|
+
unshiftToRows,
|
|
43
|
+
unshiftSerialToRows
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const resolveParent = (registry, path) => {
|
|
47
|
+
const root = path.dataRole
|
|
48
|
+
? findByRole(registry[path.fileName], path.dataRole)
|
|
49
|
+
: registry[path.fileName];
|
|
50
|
+
const keys = [...(path.filePath ?? [])];
|
|
51
|
+
const key = keys.pop();
|
|
52
|
+
const parent = keys.reduce((current, nextKey) => current[nextKey], root);
|
|
53
|
+
return { parent, key };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const writePath = (registry, path, value) => {
|
|
57
|
+
const { parent, key } = resolveParent(registry, path);
|
|
58
|
+
const action = actions[path.action] || set;
|
|
59
|
+
action(parent, key, value);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default writePath;
|