json-instruction-single 1.6.2 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-instruction-single",
3
- "version": "1.6.2",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -12,9 +12,10 @@
12
12
  ],
13
13
  "dependencies": {
14
14
  "json-source-path": "^1.2.1",
15
- "json-transformer-funcs-one-dimension": "^1.8.2",
15
+ "json-transformer-funcs-one-dimension": "^1.9.9",
16
16
  "json-transformer-funcs-primitive": "^1.9.3",
17
- "json-write-path": "^1.4.1",
18
- "spec-repo": "^1.4.2"
17
+ "json-write-path": "^1.6.1",
18
+ "jsonpathly": "^4.0.0",
19
+ "spec-repo": "^1.10.1"
19
20
  }
20
21
  }
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export * from "./v6/index.js";
2
- export { default, runSingleInstruction, getResult } from "./v6/index.js";
1
+ export * from "./v8/index.js";
2
+
3
+ export { default, runSingleInstruction, getResult } from "./v8/index.js";
@@ -0,0 +1,12 @@
1
+ import runSingleInstruction, { getResult } from "./runSingleInstruction.js";
2
+
3
+ const startFunc = (instructions, registry, showLog, returnLog) => {
4
+ instructions.forEach(instruction => {
5
+ runSingleInstruction(instruction, registry, showLog, returnLog);
6
+ });
7
+
8
+ return registry;
9
+ };
10
+
11
+ export { runSingleInstruction, getResult };
12
+ export default startFunc;
@@ -0,0 +1,24 @@
1
+ import writePath from "json-write-path";
2
+
3
+ import getResult from "../v6/getResult.js";
4
+
5
+ const startFunc = (instruction, registry, showLog) => {
6
+ if (showLog) {
7
+ console.log("runSingleInstruction v7:", instruction);
8
+ }
9
+
10
+ // Stage 1 + 2: resolve the source and build the transformed result.
11
+ const result = getResult(instruction, registry, showLog);
12
+
13
+ if (showLog) {
14
+ console.log("runSingleInstruction v7 result:", result);
15
+ }
16
+
17
+ // Stage 3: resolve destination node, destination property, and action.
18
+ writePath(registry, instruction.destinationPath, result, showLog);
19
+
20
+ return result;
21
+ };
22
+
23
+ export { getResult };
24
+ export default startFunc;
@@ -0,0 +1,5 @@
1
+ # json-instruction-single V8
2
+
3
+ V8 adds JSONPath source selection while retaining the existing instruction pipeline. `sourcePath.jsonPath` selects the input value; `destinationPath.jsonPath` selects the destination node. Existing `templateKey`, `func`, `filePath`, and `action` continue to perform transformation and writing. If a source JSONPath is absent, the existing `json-source-path` resolver remains available for older instructions.
4
+
5
+ The focused sample is `samples/v8/tableSimple`; it exercises only the `table.simple.single` instructions (column group and header).
@@ -0,0 +1,36 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+ import resolvePath from "json-source-path";
4
+ import { query } from "jsonpathly";
5
+ import fallbackSpec from "spec-repo";
6
+
7
+ const functions = { applyTemplate, fromCollection };
8
+
9
+ const getSource = (instruction, registry, showLog) => {
10
+ const sourcePath = instruction?.sourcePath;
11
+ if (sourcePath === null) return null;
12
+ if (sourcePath?.jsonPath) {
13
+ const root = registry?.[sourcePath.fileName];
14
+ if (root === undefined) throw new Error(`Registry entry not found: ${sourcePath.fileName}`);
15
+ const matches = query(root, sourcePath.jsonPath, { returnArray: true });
16
+ if (matches.length !== 1) {
17
+ throw new Error(`Source JSONPath must identify exactly one value; matched ${matches.length}: ${sourcePath.jsonPath}`);
18
+ }
19
+ if (showLog) console.log("json-instruction-single v8 source:", sourcePath, matches[0]);
20
+ return matches[0];
21
+ }
22
+ return resolvePath(registry, sourcePath);
23
+ };
24
+
25
+ const startFunc = (instruction, registry, showLog) => {
26
+ const localSpec = registry?.spec ?? fallbackSpec;
27
+ const template = localSpec[instruction.templateKey];
28
+ const source = getSource(instruction, registry, showLog);
29
+ const localFuncResult = instruction?.func === null
30
+ ? template
31
+ : functions[instruction.func](source, template);
32
+ return source === null ? template : localFuncResult;
33
+ };
34
+
35
+ export { getSource };
36
+ export default startFunc;
@@ -0,0 +1,9 @@
1
+ import runSingleInstruction, { getResult } from "./runSingleInstruction.js";
2
+
3
+ const startFunc = (instructions, registry, showLog, returnLog) => {
4
+ instructions.forEach(instruction => runSingleInstruction(instruction, registry, showLog, returnLog));
5
+ return registry;
6
+ };
7
+
8
+ export { runSingleInstruction, getResult };
9
+ export default startFunc;
@@ -0,0 +1,13 @@
1
+ import writePath from "json-write-path";
2
+ import getResult from "./getResult.js";
3
+
4
+ const startFunc = (instruction, registry, showLog) => {
5
+ if (showLog) console.log("runSingleInstruction v8:", instruction);
6
+ const result = getResult(instruction, registry, showLog);
7
+ if (showLog) console.log("runSingleInstruction v8 result:", result);
8
+ writePath(registry, instruction.destinationPath, result, showLog);
9
+ return result;
10
+ };
11
+
12
+ export { getResult };
13
+ export default startFunc;