json-to-spec 19.1.0
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/README.md +118 -0
- package/docs/demo.html +426 -0
- package/docs/dist/min.js +164 -0
- package/docs/dist/v1/min.js +124 -0
- package/docs/dist/v17/min.js +355 -0
- package/docs/dist/v18/min.js +160 -0
- package/docs/dist/v19/min.js +164 -0
- package/docs/dist/v2/min.js +129 -0
- package/docs/dist/v3/min.js +201 -0
- package/docs/index.html +248 -0
- package/docs/pages/architecture.html +115 -0
- package/docs/pages/how-it-works.html +125 -0
- package/docs/pages/what-not.html +100 -0
- package/docs/pages/what.html +105 -0
- package/docs/pages/why.html +88 -0
- package/docs/samples/form.html +265 -0
- package/docs/samples/index.html +112 -0
- package/docs/samples/table.html +306 -0
- package/index.js +2 -0
- package/package.json +50 -0
- package/samples/dataList/index.html +31 -0
- package/samples/dataList/index.js +62 -0
- package/samples/dataList/input/data.json +5043 -0
- package/samples/dataList/input/structure.json +38 -0
- package/samples/dataList copy/index.html +30 -0
- package/samples/dataList copy/index.js +61 -0
- package/samples/dataList copy/input/data.json +35307 -0
- package/samples/dataList copy/input/structure.json +18 -0
- package/samples/form/index.html +29 -0
- package/samples/form/index.js +64 -0
- package/samples/form/input/data.json +9 -0
- package/samples/form/input/structure.json +192 -0
- package/samples/form-/data.json +42 -0
- package/samples/form-/structure.json +110 -0
- package/samples/select/index.html +31 -0
- package/samples/select/index.js +61 -0
- package/samples/select/input/data.json +35287 -0
- package/samples/select/input/select.json +18 -0
- package/samples/select/input/structure.json +47 -0
- package/samples/table/index.html +29 -0
- package/samples/table/index.js +61 -0
- package/samples/table/input/data.json +35287 -0
- package/samples/table/input/structure copy.json +47 -0
- package/samples/table/input/structure.json +86 -0
- package/samples/table/input/table.json +135 -0
- package/samples/table-/data.json +68 -0
- package/samples/table-/structure.json +235 -0
- package/src/index.js +2 -0
- package/src/v10/index.js +96 -0
- package/src/v10/instructionEngine/compile/compileTree.js +191 -0
- package/src/v10/instructionEngine/compileTree.js +1 -0
- package/src/v10/instructionEngine/expandIteration.js +1 -0
- package/src/v10/instructionEngine/index.js +29 -0
- package/src/v10/instructionEngine/interpolate.js +2 -0
- package/src/v10/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v10/instructionEngine/operation/operation.js +237 -0
- package/src/v10/instructionEngine/other/other.js +150 -0
- package/src/v10/instructionEngine/pipeline/pipeline.js +47 -0
- package/src/v10/instructionEngine/replace/replace.js +173 -0
- package/src/v10/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v10/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v10/instructionEngine/resolvePath.js +1 -0
- package/src/v10/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v10/instructionEngine/story/storyInjector.js +50 -0
- package/src/v10/instructionEngine/storyInjector.js +1 -0
- package/src/v10/instructionEngine/value/interpolate.js +38 -0
- package/src/v11/index.js +116 -0
- package/src/v11/iterate.js +270 -0
- package/src/v11/replace.js +169 -0
- package/src/v11/resolvePath.js +29 -0
- package/src/v12/index.js +122 -0
- package/src/v12/iterate/bindFormValues.js +74 -0
- package/src/v12/iterate/expandIteration.js +181 -0
- package/src/v12/iterate/index.js +10 -0
- package/src/v12/iterate/iterate.js +56 -0
- package/src/v12/iterate/iterateNode.js +86 -0
- package/src/v12/iterate/resolveCollection.js +37 -0
- package/src/v12/iterate.js +270 -0
- package/src/v12/replace.js +169 -0
- package/src/v12/resolvePath.js +29 -0
- package/src/v13/index.js +110 -0
- package/src/v13/iterate/bindFormValues.js +74 -0
- package/src/v13/iterate/expandIteration.js +188 -0
- package/src/v13/iterate/index.js +9 -0
- package/src/v13/iterate/iterate.js +32 -0
- package/src/v13/iterate/iterateNode.js +86 -0
- package/src/v13/iterate/resolveCollection.js +37 -0
- package/src/v13/iterate/walk.js +90 -0
- package/src/v13/iterate.js +270 -0
- package/src/v13/replace.js +169 -0
- package/src/v13/resolvePath.js +29 -0
- package/src/v14/index.js +112 -0
- package/src/v14/iterate/bindFormValues.js +74 -0
- package/src/v14/iterate/expandIteration.js +188 -0
- package/src/v14/iterate/index.js +9 -0
- package/src/v14/iterate/iterate.js +32 -0
- package/src/v14/iterate/resolveCollection.js +37 -0
- package/src/v14/iterate/walk/walk copy 2.js +114 -0
- package/src/v14/iterate/walk/walk copy.js +90 -0
- package/src/v14/iterate/walk/walk.js +98 -0
- package/src/v14/iterate.js +270 -0
- package/src/v14/replace/index.js +16 -0
- package/src/v14/replace/walk.js +90 -0
- package/src/v14/replace.js +153 -0
- package/src/v14/resolvePath.js +29 -0
- package/src/v15/index.js +123 -0
- package/src/v15/iterate/bindFormValues.js +74 -0
- package/src/v15/iterate/expandIteration.js +188 -0
- package/src/v15/iterate/index.js +9 -0
- package/src/v15/iterate/iterate.js +32 -0
- package/src/v15/iterate/resolveCollection.js +37 -0
- package/src/v15/iterate/walk/walk copy 2.js +114 -0
- package/src/v15/iterate/walk/walk copy.js +90 -0
- package/src/v15/iterate/walk/walk.js +195 -0
- package/src/v15/iterate.js +270 -0
- package/src/v15/replace/index.js +16 -0
- package/src/v15/replace/walk.js +90 -0
- package/src/v15/replace.js +155 -0
- package/src/v15/resolvePath.js +29 -0
- package/src/v16/index.js +129 -0
- package/src/v16/iterate/bindFormValues.js +74 -0
- package/src/v16/iterate/expandIteration.js +188 -0
- package/src/v16/iterate/index.js +9 -0
- package/src/v16/iterate/iterate.js +32 -0
- package/src/v16/iterate/resolveCollection.js +37 -0
- package/src/v16/iterate/walk/walk copy 2.js +114 -0
- package/src/v16/iterate/walk/walk copy.js +90 -0
- package/src/v16/iterate/walk/walk.js +196 -0
- package/src/v16/iterate.js +270 -0
- package/src/v16/replace/index.js +16 -0
- package/src/v16/replace/walk.js +90 -0
- package/src/v16/replace.js +155 -0
- package/src/v16/resolvePath.js +29 -0
- package/src/v17/index.js +119 -0
- package/src/v17/iterate/bindFormValues.js +74 -0
- package/src/v17/iterate/expandIteration.js +188 -0
- package/src/v17/iterate/index.js +9 -0
- package/src/v17/iterate/iterate.js +32 -0
- package/src/v17/iterate/resolveCollection.js +37 -0
- package/src/v17/iterate/walk/iterateDo.js +42 -0
- package/src/v17/iterate/walk/replaceWithData.js +60 -0
- package/src/v17/iterate/walk/walk.js +94 -0
- package/src/v17/iterate.js +270 -0
- package/src/v17/replace/index.js +16 -0
- package/src/v17/replace/walk.js +90 -0
- package/src/v17/replace.js +160 -0
- package/src/v17/resolvePath.js +29 -0
- package/src/v18/index.js +66 -0
- package/src/v18/meta.js +7 -0
- package/src/v18/registerGlobal.js +17 -0
- package/src/v18/replace.js +18 -0
- package/src/v18/resolvePath.js +29 -0
- package/src/v18/walk/iterate/v1/index.js +42 -0
- package/src/v18/walk/iterate/v2/index.js +32 -0
- package/src/v18/walk/iterate/v3/index.js +46 -0
- package/src/v18/walk/iterate/v4/createChildren.js +24 -0
- package/src/v18/walk/iterate/v4/index.js +25 -0
- package/src/v18/walk/replaceWithData/v1/index.js +42 -0
- package/src/v18/walk/replaceWithData/v1/replaceCommon.js +21 -0
- package/src/v18/walk/replaceWithData/v2/index.js +105 -0
- package/src/v18/walk/replaceWithData/v2/replaceCommon.js +21 -0
- package/src/v18/walk/replaceWithData/v3/index.js +15 -0
- package/src/v18/walk/replaceWithData/v3/replaceAttributes.js +29 -0
- package/src/v18/walk/replaceWithData/v3/replaceCommon.js +23 -0
- package/src/v18/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
- package/src/v18/walk/walk.js +94 -0
- package/src/v19/index.js +55 -0
- package/src/v19/meta.js +7 -0
- package/src/v19/registerGlobal.js +17 -0
- package/src/v19/replace.js +18 -0
- package/src/v19/resolvePath.js +29 -0
- package/src/v19/walk/iterate/v1/index.js +42 -0
- package/src/v19/walk/iterate/v2/index.js +32 -0
- package/src/v19/walk/iterate/v3/index.js +46 -0
- package/src/v19/walk/iterate/v4/createChildren.js +27 -0
- package/src/v19/walk/iterate/v4/index.js +25 -0
- package/src/v19/walk/replaceWithData/v1/index.js +42 -0
- package/src/v19/walk/replaceWithData/v1/replaceCommon.js +21 -0
- package/src/v19/walk/replaceWithData/v2/index.js +105 -0
- package/src/v19/walk/replaceWithData/v2/replaceCommon.js +21 -0
- package/src/v19/walk/replaceWithData/v3/index.js +15 -0
- package/src/v19/walk/replaceWithData/v3/replaceAttributes.js +29 -0
- package/src/v19/walk/replaceWithData/v3/replaceCommon.js +23 -0
- package/src/v19/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
- package/src/v19/walk/walk.js +97 -0
- package/src/v8/index.js +69 -0
- package/src/v8/instructionEngine/compile/compileTree.js +191 -0
- package/src/v8/instructionEngine/compileTree.js +1 -0
- package/src/v8/instructionEngine/expandIteration.js +1 -0
- package/src/v8/instructionEngine/index.js +16 -0
- package/src/v8/instructionEngine/interpolate.js +2 -0
- package/src/v8/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v8/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v8/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v8/instructionEngine/resolvePath.js +1 -0
- package/src/v8/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v8/instructionEngine/story/storyInjector.js +50 -0
- package/src/v8/instructionEngine/storyInjector.js +1 -0
- package/src/v8/instructionEngine/value/interpolate.js +38 -0
- package/src/v9/index.js +96 -0
- package/src/v9/instructionEngine/compile/compileTree.js +191 -0
- package/src/v9/instructionEngine/compileTree.js +1 -0
- package/src/v9/instructionEngine/expandIteration.js +1 -0
- package/src/v9/instructionEngine/index.js +29 -0
- package/src/v9/instructionEngine/interpolate.js +2 -0
- package/src/v9/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v9/instructionEngine/operation/operation.js +237 -0
- package/src/v9/instructionEngine/other/other.js +150 -0
- package/src/v9/instructionEngine/pipeline/pipeline.js +47 -0
- package/src/v9/instructionEngine/replace/replace.js +173 -0
- package/src/v9/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v9/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v9/instructionEngine/resolvePath.js +1 -0
- package/src/v9/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v9/instructionEngine/story/storyInjector.js +50 -0
- package/src/v9/instructionEngine/storyInjector.js +1 -0
- package/src/v9/instructionEngine/value/interpolate.js +38 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const startFunc = ({ inData, inDataKey }) => {
|
|
2
|
+
const dataKey = inDataKey;
|
|
3
|
+
// console.log("dataKey : ", dataKey, inData);
|
|
4
|
+
|
|
5
|
+
let valueToReturn = inData[dataKey];
|
|
6
|
+
|
|
7
|
+
if (dataKey.includes(".")) {
|
|
8
|
+
const keysOfArray = dataKey.split(".");
|
|
9
|
+
|
|
10
|
+
const value = keysOfArray.reduce(
|
|
11
|
+
(current, key) => current?.[key],
|
|
12
|
+
inData
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
valueToReturn = value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return valueToReturn;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default startFunc;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import replaceNodeValue from "./replaceNodeValue.js";
|
|
2
|
+
import replaceAttributes from "./replaceAttributes.js";
|
|
3
|
+
|
|
4
|
+
const startFunc = ({
|
|
5
|
+
inNode,
|
|
6
|
+
inData,
|
|
7
|
+
} = {}) => {
|
|
8
|
+
const localNode = inNode;
|
|
9
|
+
const localData = inData;
|
|
10
|
+
|
|
11
|
+
replaceNodeValue({ inNode: localNode, inData: localData });
|
|
12
|
+
replaceAttributes({ inNode: localNode, inData: localData });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default startFunc;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import replaceCommonFunc from "./replaceCommon.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if ("attributes" in localNode) {
|
|
11
|
+
const attributes = Object.fromEntries(
|
|
12
|
+
Object.entries(localNode.attributes || {}).map(([key, value]) => [
|
|
13
|
+
key,
|
|
14
|
+
typeof value === "string" && value.includes("${")
|
|
15
|
+
? replaceCommonFunc({
|
|
16
|
+
inData: localData,
|
|
17
|
+
inDataKey: value
|
|
18
|
+
.replace(/^\$\{/, "")
|
|
19
|
+
.replace(/\}$/, "")
|
|
20
|
+
})
|
|
21
|
+
: value
|
|
22
|
+
])
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
localNode.attributes = { ...attributes };
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default startFunc;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const startFunc = ({ inData, inDataKey }) => {
|
|
2
|
+
const dataKey = inDataKey;
|
|
3
|
+
// console.log("dataKey : ", dataKey, inData);
|
|
4
|
+
|
|
5
|
+
if (dataKey === "") return inData;
|
|
6
|
+
|
|
7
|
+
let valueToReturn = inData[dataKey];
|
|
8
|
+
|
|
9
|
+
if (dataKey.includes(".")) {
|
|
10
|
+
const keysOfArray = dataKey.split(".");
|
|
11
|
+
|
|
12
|
+
const value = keysOfArray.reduce(
|
|
13
|
+
(current, key) => current?.[key],
|
|
14
|
+
inData
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
valueToReturn = value;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return valueToReturn;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default startFunc;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import replaceCommonFunc from "./replaceCommon.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if (!localNode?.textContent) return "no-textContent";
|
|
11
|
+
|
|
12
|
+
if (typeof localNode.textContent !== "string") return "not-a-string";
|
|
13
|
+
|
|
14
|
+
if (!localNode.textContent.includes("${")) return "no-template-token";
|
|
15
|
+
|
|
16
|
+
const dataKey = localNode.textContent
|
|
17
|
+
.replace(/^\$\{/, "")
|
|
18
|
+
.replace(/\}$/, "");
|
|
19
|
+
|
|
20
|
+
localNode.textContent = replaceCommonFunc({
|
|
21
|
+
inData: localData,
|
|
22
|
+
inDataKey: dataKey
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default startFunc;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import replaceWithData from "./replaceWithData/v3/index.js";
|
|
2
|
+
import iterateDo from "./iterate/v4/index.js";
|
|
3
|
+
|
|
4
|
+
const forArray = ({ inNode, inData, inOperation }) => {
|
|
5
|
+
const localNode = inNode;
|
|
6
|
+
const localData = inData;
|
|
7
|
+
const localOperation = inOperation;
|
|
8
|
+
|
|
9
|
+
// console.log("forArray : ", inNode, inOperation);
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(localNode)) {
|
|
12
|
+
const results = [];
|
|
13
|
+
|
|
14
|
+
for (const child of localNode) {
|
|
15
|
+
const result = walk({
|
|
16
|
+
inNode: child,
|
|
17
|
+
inData, inOperation: localOperation
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(result)) {
|
|
21
|
+
results.push(...result);
|
|
22
|
+
} else if (result !== null && result !== undefined) {
|
|
23
|
+
results.push(result);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return results;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Recursively walks a JSON structure.
|
|
33
|
+
*
|
|
34
|
+
* The walker knows only how to traverse.
|
|
35
|
+
* The supplied operation decides what to do with each node.
|
|
36
|
+
*/
|
|
37
|
+
const walk = ({
|
|
38
|
+
inNode,
|
|
39
|
+
inData = {},
|
|
40
|
+
inOperation
|
|
41
|
+
} = {}) => {
|
|
42
|
+
const localNode = inNode;
|
|
43
|
+
const localData = inData;
|
|
44
|
+
const localOperation = inOperation;
|
|
45
|
+
// debugger
|
|
46
|
+
if (localNode === null || localNode === undefined) {
|
|
47
|
+
return localNode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Array.isArray(localNode)) {
|
|
51
|
+
return forArray({
|
|
52
|
+
inNode: localNode, inData,
|
|
53
|
+
inOperation: localOperation
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if ("children" in localNode) {
|
|
58
|
+
if (Array.isArray(localNode?.children)) {
|
|
59
|
+
localNode.children = forArray({
|
|
60
|
+
inNode: localNode?.children,
|
|
61
|
+
inData, inOperation: localOperation
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (typeof localNode !== "object") {
|
|
67
|
+
return localNode;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// console.log("localOperation :", localOperation);
|
|
71
|
+
|
|
72
|
+
switch (localOperation) {
|
|
73
|
+
case "replace":
|
|
74
|
+
if (typeof localNode === "object") {
|
|
75
|
+
// console.log("yyyyyyyyyy :", typeof localNode === "object");
|
|
76
|
+
replaceWithData({
|
|
77
|
+
inNode: localNode,
|
|
78
|
+
inData
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
break;
|
|
82
|
+
case "iterateDo":
|
|
83
|
+
iterateDo({
|
|
84
|
+
inNode: localNode,
|
|
85
|
+
inData
|
|
86
|
+
});
|
|
87
|
+
default:
|
|
88
|
+
break;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return localNode;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default walk;
|
package/src/v19/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import registerGlobal from "./registerGlobal.js";
|
|
2
|
+
import meta from "./meta.js";
|
|
3
|
+
/**
|
|
4
|
+
* json-to-spec v11
|
|
5
|
+
*
|
|
6
|
+
* Minimalist 2-Layer Specification Compiler:
|
|
7
|
+
* 1. replace: Pure ${...} token replacement across JSON structures.
|
|
8
|
+
* 2. iterate: Evaluates jsonToSpec operations, expanding collections into clean children.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { replace } from "./replace.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Main compiler entry point:
|
|
15
|
+
* 1. Replace values: replace(structure, data)
|
|
16
|
+
* 2. Iterate/Operate: iterate(replacedStructure, data)
|
|
17
|
+
*/
|
|
18
|
+
export const compile = (inStructureOrOptions, inData = {}, inShowLog = false) => {
|
|
19
|
+
let localStructure = inStructureOrOptions;
|
|
20
|
+
let localData = inData;
|
|
21
|
+
|
|
22
|
+
if (inShowLog) console.log(meta.name, localStructure, localData);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const iteratedData = replace({
|
|
26
|
+
inStructureAsJson: localStructure,
|
|
27
|
+
inDataAsJson: localData,
|
|
28
|
+
inOperation: "iterateDo",
|
|
29
|
+
inShowLog
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const replacedData = replace({
|
|
33
|
+
inStructureAsJson: iteratedData,
|
|
34
|
+
inDataAsJson: localData,
|
|
35
|
+
inOperation: "replace",
|
|
36
|
+
inShowLog
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (inShowLog) console.log("iteratedData : ", iteratedData, replacedData);
|
|
40
|
+
|
|
41
|
+
// const spec = iterate({
|
|
42
|
+
// inStructure: replaced,
|
|
43
|
+
// inData: localData
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
return replacedData;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error("[json-to-spec/v19] compile error:", err);
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
registerGlobal(compile);
|
|
54
|
+
|
|
55
|
+
export default compile;
|
package/src/v19/meta.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import meta from "./meta.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 3. registerGlobal - Orchestration Step 3
|
|
5
|
+
* Safely registers the json-to-dom public API onto globalThis.ks in browser / SSR environments.
|
|
6
|
+
*/
|
|
7
|
+
export const registerGlobal = (inFuncDefinition) => {
|
|
8
|
+
if (typeof globalThis === "undefined" || !inFuncDefinition) return;
|
|
9
|
+
|
|
10
|
+
globalThis.ks ??= {};
|
|
11
|
+
globalThis.ks["json-to-spec"] = {
|
|
12
|
+
meta,
|
|
13
|
+
compile: inFuncDefinition
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default registerGlobal;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import walk from "./walk/walk.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Main replace function: (structure, data) -> replaced JSON structure
|
|
5
|
+
*/
|
|
6
|
+
export const replace = ({ inStructureAsJson, inDataAsJson, inOperation, inShowLog }) => {
|
|
7
|
+
try {
|
|
8
|
+
return walk({
|
|
9
|
+
inNode: inStructureAsJson,
|
|
10
|
+
inData: inDataAsJson, inOperation, inShowLog
|
|
11
|
+
});
|
|
12
|
+
} catch (err) {
|
|
13
|
+
console.error("[json-to-spec/v17] replace error:", err);
|
|
14
|
+
throw err;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default replace;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a dot-delimited path or array of keys from a data object.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} inArgs
|
|
5
|
+
* @param {Object} inArgs.inData - Target object to resolve from
|
|
6
|
+
* @param {string|Array} inArgs.inPath - Key or dot-path (e.g. "meta.formTitle", "columns")
|
|
7
|
+
* @returns {*} Resolved value or undefined
|
|
8
|
+
*/
|
|
9
|
+
export const resolvePath = ({ inData, inPath }) => {
|
|
10
|
+
const localData = inData;
|
|
11
|
+
const localPath = inPath;
|
|
12
|
+
|
|
13
|
+
if (localData === null || localData === undefined) return undefined;
|
|
14
|
+
if (localPath === undefined || localPath === null || localPath === "" || localPath === ".") {
|
|
15
|
+
return localData;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const segments = Array.isArray(localPath) ? localPath : String(localPath).split(".");
|
|
19
|
+
let current = localData;
|
|
20
|
+
|
|
21
|
+
for (const segment of segments) {
|
|
22
|
+
if (current === null || current === undefined) return undefined;
|
|
23
|
+
current = current[segment];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return current;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default resolvePath;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import walk from "../../walk.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if ("jsonToSpec" in localNode) {
|
|
11
|
+
|
|
12
|
+
if ("operation" in localNode?.jsonToSpec) {
|
|
13
|
+
if (localNode?.jsonToSpec?.operation === "iterate") {
|
|
14
|
+
|
|
15
|
+
if ("source" in localNode?.jsonToSpec) {
|
|
16
|
+
const sourceValues = inData[localNode?.jsonToSpec?.source];
|
|
17
|
+
|
|
18
|
+
const newChildren = sourceValues.map(loopColumn => {
|
|
19
|
+
const clone = structuredClone(localNode?.jsonToSpec?.template);
|
|
20
|
+
|
|
21
|
+
const k1 = walk({
|
|
22
|
+
inNode: clone,
|
|
23
|
+
inData: loopColumn,
|
|
24
|
+
inOperation: "replace"
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return k1
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
localNode.children = newChildren;
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// console.log("localNode : ", localNode);
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default startFunc;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import walk from "../../walk.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if (!("jsonToSpec" in localNode)) return;
|
|
11
|
+
if (!("operation" in localNode.jsonToSpec)) return;
|
|
12
|
+
if (localNode.jsonToSpec.operation !== "iterate") return;
|
|
13
|
+
if (!("source" in localNode.jsonToSpec)) return;
|
|
14
|
+
|
|
15
|
+
const sourceValues = localData[localNode.jsonToSpec.source];
|
|
16
|
+
|
|
17
|
+
const newChildren = sourceValues.map(loopColumn => {
|
|
18
|
+
const clone = structuredClone(localNode.jsonToSpec.template);
|
|
19
|
+
|
|
20
|
+
const k1 = walk({
|
|
21
|
+
inNode: clone,
|
|
22
|
+
inData: loopColumn,
|
|
23
|
+
inOperation: "replace"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return k1;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
localNode.children = newChildren;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default startFunc;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import walk from "../../walk.js";
|
|
2
|
+
|
|
3
|
+
const createChildren = ({
|
|
4
|
+
inTemplate,
|
|
5
|
+
inSourceValues,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const sourceValues = inSourceValues;
|
|
8
|
+
|
|
9
|
+
const newChildren = sourceValues.map(loopColumn => {
|
|
10
|
+
const clone = structuredClone(inTemplate);
|
|
11
|
+
|
|
12
|
+
const walkResult = walk({
|
|
13
|
+
inNode: clone,
|
|
14
|
+
inData: loopColumn,
|
|
15
|
+
inOperation: "replace"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return walkResult;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return newChildren;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const startFunc = ({
|
|
25
|
+
inNode,
|
|
26
|
+
inData,
|
|
27
|
+
} = {}) => {
|
|
28
|
+
const localNode = inNode;
|
|
29
|
+
const localData = inData;
|
|
30
|
+
|
|
31
|
+
if (!("jsonToSpec" in localNode)) return;
|
|
32
|
+
if (!("operation" in localNode.jsonToSpec)) return;
|
|
33
|
+
if (localNode.jsonToSpec.operation !== "iterate") return;
|
|
34
|
+
if (!("source" in localNode.jsonToSpec)) return;
|
|
35
|
+
|
|
36
|
+
const sourceValues = localData[localNode.jsonToSpec.source];
|
|
37
|
+
|
|
38
|
+
const newChildren = createChildren({
|
|
39
|
+
inTemplate: localNode.jsonToSpec.template,
|
|
40
|
+
inSourceValues: sourceValues,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
localNode.children = newChildren;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default startFunc;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import walk from "../../walk.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inTemplate,
|
|
5
|
+
inSourceValues,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const sourceValues = inSourceValues;
|
|
8
|
+
// console.log(" inTemplate----------- :", inTemplate, inSourceValues);
|
|
9
|
+
|
|
10
|
+
if (sourceValues === undefined) return;
|
|
11
|
+
|
|
12
|
+
const newChildren = sourceValues.map(loopColumn => {
|
|
13
|
+
const clone = structuredClone(inTemplate);
|
|
14
|
+
|
|
15
|
+
const walkResult = walk({
|
|
16
|
+
inNode: clone,
|
|
17
|
+
inData: loopColumn,
|
|
18
|
+
inOperation: "replace"
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return walkResult;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return newChildren;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default startFunc;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import createChildren from "./createChildren.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData, inShowLog
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if (!("jsonToSpec" in localNode)) return;
|
|
11
|
+
if (!("operation" in localNode.jsonToSpec)) return;
|
|
12
|
+
if (localNode.jsonToSpec.operation !== "iterate") return;
|
|
13
|
+
if (!("source" in localNode.jsonToSpec)) return;
|
|
14
|
+
|
|
15
|
+
const sourceValues = localData[localNode.jsonToSpec.source];
|
|
16
|
+
|
|
17
|
+
const newChildren = createChildren({
|
|
18
|
+
inTemplate: localNode.jsonToSpec.template,
|
|
19
|
+
inSourceValues: sourceValues, inShowLog
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
localNode.children = newChildren;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default startFunc;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import replaceCommonFunc from "./replaceCommon.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if ("textContent" in inNode) {
|
|
11
|
+
if (inNode.textContent.includes("${")) {
|
|
12
|
+
const dataKey = inNode.textContent
|
|
13
|
+
.replace(/^\$\{/, "")
|
|
14
|
+
.replace(/\}$/, "");
|
|
15
|
+
|
|
16
|
+
inNode.textContent = replaceCommonFunc({ inData, inDataKey: dataKey });
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
if ("attributes" in inNode) {
|
|
22
|
+
const attributes = Object.fromEntries(
|
|
23
|
+
Object.entries(inNode.attributes || {}).map(([key, value]) => [
|
|
24
|
+
key,
|
|
25
|
+
typeof value === "string" && value.includes("${")
|
|
26
|
+
? replaceCommonFunc({
|
|
27
|
+
inData,
|
|
28
|
+
inDataKey: value
|
|
29
|
+
.replace(/^\$\{/, "")
|
|
30
|
+
.replace(/\}$/, "")
|
|
31
|
+
})
|
|
32
|
+
: value
|
|
33
|
+
])
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// console.log("attributes----- : ", inNode, attributes);
|
|
37
|
+
|
|
38
|
+
inNode.attributes = { ...attributes };
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default startFunc;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const startFunc = ({ inData, inDataKey }) => {
|
|
2
|
+
const dataKey = inDataKey;
|
|
3
|
+
// console.log("dataKey : ", dataKey, inData);
|
|
4
|
+
|
|
5
|
+
let valueToReturn = inData[dataKey];
|
|
6
|
+
|
|
7
|
+
if (dataKey.includes(".")) {
|
|
8
|
+
const keysOfArray = dataKey.split(".");
|
|
9
|
+
|
|
10
|
+
const value = keysOfArray.reduce(
|
|
11
|
+
(current, key) => current?.[key],
|
|
12
|
+
inData
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
valueToReturn = value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return valueToReturn;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default startFunc;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import replaceCommonFunc from "./replaceCommon.js";
|
|
2
|
+
|
|
3
|
+
const replaceNodeValue = ({
|
|
4
|
+
inNode,
|
|
5
|
+
inData,
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const localNode = inNode;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if (localNode?.textContent) {
|
|
11
|
+
if (localNode.textContent.includes("${")) {
|
|
12
|
+
const dataKey = localNode.textContent
|
|
13
|
+
.replace(/^\$\{/, "")
|
|
14
|
+
.replace(/\}$/, "");
|
|
15
|
+
|
|
16
|
+
localNode.textContent = replaceCommonFunc({
|
|
17
|
+
inData: localData,
|
|
18
|
+
inDataKey: dataKey
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const startFunc1 = ({
|
|
26
|
+
inNode,
|
|
27
|
+
inData,
|
|
28
|
+
} = {}) => {
|
|
29
|
+
const localNode = inNode;
|
|
30
|
+
const localData = inData;
|
|
31
|
+
|
|
32
|
+
replaceNodeValue({ inNode: localNode, inData: localData });
|
|
33
|
+
|
|
34
|
+
// if ("textContent" in localNode) {
|
|
35
|
+
// console.log("localNode : ", localNode);
|
|
36
|
+
|
|
37
|
+
// if (localNode.textContent.includes("${")) {
|
|
38
|
+
// const dataKey = localNode.textContent
|
|
39
|
+
// .replace(/^\$\{/, "")
|
|
40
|
+
// .replace(/\}$/, "");
|
|
41
|
+
|
|
42
|
+
// localNode.textContent = replaceCommonFunc({
|
|
43
|
+
// inData: localData,
|
|
44
|
+
// inDataKey: dataKey
|
|
45
|
+
// });
|
|
46
|
+
// };
|
|
47
|
+
// };
|
|
48
|
+
|
|
49
|
+
if ("attributes" in localNode) {
|
|
50
|
+
const attributes = Object.fromEntries(
|
|
51
|
+
Object.entries(localNode.attributes || {}).map(([key, value]) => [
|
|
52
|
+
key,
|
|
53
|
+
typeof value === "string" && value.includes("${")
|
|
54
|
+
? replaceCommonFunc({
|
|
55
|
+
inData,
|
|
56
|
+
inDataKey: value
|
|
57
|
+
.replace(/^\$\{/, "")
|
|
58
|
+
.replace(/\}$/, "")
|
|
59
|
+
})
|
|
60
|
+
: value
|
|
61
|
+
])
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
inNode.attributes = { ...attributes };
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const replaceAttributes = ({
|
|
69
|
+
inNode,
|
|
70
|
+
inData,
|
|
71
|
+
} = {}) => {
|
|
72
|
+
const localNode = inNode;
|
|
73
|
+
const localData = inData;
|
|
74
|
+
|
|
75
|
+
if ("attributes" in localNode) {
|
|
76
|
+
const attributes = Object.fromEntries(
|
|
77
|
+
Object.entries(localNode.attributes || {}).map(([key, value]) => [
|
|
78
|
+
key,
|
|
79
|
+
typeof value === "string" && value.includes("${")
|
|
80
|
+
? replaceCommonFunc({
|
|
81
|
+
inData: localData,
|
|
82
|
+
inDataKey: value
|
|
83
|
+
.replace(/^\$\{/, "")
|
|
84
|
+
.replace(/\}$/, "")
|
|
85
|
+
})
|
|
86
|
+
: value
|
|
87
|
+
])
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
localNode.attributes = { ...attributes };
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const startFunc = ({
|
|
95
|
+
inNode,
|
|
96
|
+
inData,
|
|
97
|
+
} = {}) => {
|
|
98
|
+
const localNode = inNode;
|
|
99
|
+
const localData = inData;
|
|
100
|
+
|
|
101
|
+
replaceNodeValue({ inNode: localNode, inData: localData });
|
|
102
|
+
replaceAttributes({ inNode: localNode, inData: localData });
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default startFunc;
|