json-renderers-run-instructions 1.15.2 → 1.20.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.
Files changed (66) hide show
  1. package/package.json +12 -6
  2. package/src/index.js +2 -2
  3. package/src/v16/index.js +50 -0
  4. package/src/v16/registerGlobal/meta.js +6 -0
  5. package/src/v16/runOptions/applyFeature.js +20 -0
  6. package/src/v16/runOptions/applyInstructionBundle.js +45 -0
  7. package/src/v16/runOptions/helpers.js +41 -0
  8. package/src/v16/runOptions/index.js +73 -0
  9. package/src/v17/index.js +50 -0
  10. package/src/v17/registerGlobal/meta.js +6 -0
  11. package/src/v17/runOptions/applyFeature.js +20 -0
  12. package/src/v17/runOptions/applyInstructionBundle.js +45 -0
  13. package/src/v17/runOptions/helpers.js +41 -0
  14. package/src/v17/runOptions/index.js +73 -0
  15. package/src/v18/README.md +21 -0
  16. package/src/v18/data/definitions.json +334 -0
  17. package/src/v18/data/instructions.json +650 -0
  18. package/src/v18/data/spec.json +1605 -0
  19. package/src/v18/index.js +58 -0
  20. package/src/v18/instructions/executeBuildInstruction.js +53 -0
  21. package/src/v18/instructions/executeWriteBundle.js +21 -0
  22. package/src/v18/instructions/index.js +35 -0
  23. package/src/{v13/types/helpers → v18/instructions}/resolveSource.js +24 -27
  24. package/src/v18/instructions/writeResult.js +29 -0
  25. package/src/v18/registerGlobal/index.js +16 -0
  26. package/src/{v13 → v18}/registerGlobal/meta.js +1 -1
  27. package/src/v18/runOptions/index.js +47 -0
  28. package/src/v19/data/definitions.json +149 -0
  29. package/src/v19/data/instructions.json +650 -0
  30. package/src/v19/data/spec.json +1605 -0
  31. package/src/v19/index.js +54 -0
  32. package/src/v19/instructions/executeBuildInstruction.js +53 -0
  33. package/src/v19/instructions/executeWriteBundle.js +21 -0
  34. package/src/v19/instructions/index.js +35 -0
  35. package/src/v19/instructions/resolveSource.js +24 -0
  36. package/src/v19/instructions/writeResult.js +29 -0
  37. package/src/v19/registerGlobal/index.js +16 -0
  38. package/src/{v12 → v19}/registerGlobal/meta.js +6 -6
  39. package/src/v19/runOptions/index.js +78 -0
  40. package/src/v20/index.js +54 -0
  41. package/src/v20/instructions/executeBuildInstruction.js +53 -0
  42. package/src/v20/instructions/executeWriteBundle.js +21 -0
  43. package/src/v20/instructions/index.js +35 -0
  44. package/src/v20/instructions/resolveSource.js +24 -0
  45. package/src/v20/instructions/writeResult.js +29 -0
  46. package/src/v20/registerGlobal/index.js +16 -0
  47. package/src/v20/registerGlobal/meta.js +6 -0
  48. package/src/v20/runOptions/index.js +36 -0
  49. package/src/v20/runOptions/normalizeOptions.js +28 -0
  50. package/src/v20/runOptions/resolveFeatureKeys.js +43 -0
  51. package/src/v12/index.js +0 -178
  52. package/src/v12/runOptions/index.js +0 -66
  53. package/src/v12/transformers/columnOnRow.js +0 -33
  54. package/src/v12/transformers/index.js +0 -21
  55. package/src/v13/index.js +0 -49
  56. package/src/v13/runOptions/index.js +0 -66
  57. package/src/v13/transformers/columnOnRow.js +0 -33
  58. package/src/v13/transformers/index.js +0 -21
  59. package/src/v13/types/columnOnRow.js +0 -34
  60. package/src/v13/types/helpers/guards.js +0 -38
  61. package/src/v13/types/helpers/writeResult.js +0 -19
  62. package/src/v13/types/index.js +0 -33
  63. package/src/v13/types/rowOnColumn.js +0 -22
  64. package/src/v13/types/single.js +0 -28
  65. /package/src/{v12 → v16}/registerGlobal/index.js +0 -0
  66. /package/src/{v13 → v17}/registerGlobal/index.js +0 -0
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "json-renderers-run-instructions",
3
- "version": "1.15.2",
3
+ "version": "1.20.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",
7
7
  "exports": {
8
- ".": "./src/index.js"
8
+ ".": "./src/index.js",
9
+ "./v18": "./src/v18/index.js",
10
+ "./v19": "./src/v19/index.js",
11
+ "./v20": "./src/v20/index.js"
9
12
  },
10
13
  "files": [
11
14
  "src",
@@ -15,10 +18,13 @@
15
18
  "build": "npx @keshavsoft/build-cli"
16
19
  },
17
20
  "dependencies": {
18
- "declarative-definitions": "^1.2.1",
19
- "declarative-spec": "^1.2.1",
20
- "json-renderers-run-instructions-steps": "^1.7.1",
21
- "json-renderers-run-options": "^1.2.1",
21
+ "declarative-definitions": "^1.3.1",
22
+ "declarative-instructions": "^1.2.3",
23
+ "declarative-spec": "^1.4.1",
24
+ "json-transformer-funcs-one-dimension": "^1.9.9",
25
+ "json-transformer-funcs-primitive": "^1.9.3",
26
+ "json-transformer-funcs-two-dimensions": "^1.9.1",
27
+ "json-renderers-run-instructions-steps": "^1.8.2",
22
28
  "json-write-path": "^1.6.1",
23
29
  "jsonpathly": "^4.0.0"
24
30
  },
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./v15/index.js";
1
+ export * from "./v20/index.js";
2
2
 
3
- export { default } from "./v15/index.js";
3
+ export { default } from "./v20/index.js";
@@ -0,0 +1,50 @@
1
+ import { definitions } from "declarative-definitions";
2
+ import { spec } from "declarative-spec";
3
+
4
+ import runInstructions from "json-renderers-run-instructions-steps";
5
+
6
+ import runOptions from "./runOptions/index.js";
7
+ import registerGlobal from "./registerGlobal/index.js";
8
+
9
+ const startFunc = ({
10
+ instructionMainKey,
11
+ instructionSubKey,
12
+ data,
13
+ options,
14
+ showLog = false
15
+ } = {}) => {
16
+ const definition = definitions[instructionMainKey]?.[instructionSubKey];
17
+ if (!definition) {
18
+ throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
19
+ }
20
+
21
+ // The Canvas
22
+ const base = structuredClone(spec[definition.baseFromSpec]);
23
+
24
+ // Task 1: Execute blueprint instructions (Array-based, from dedicated steps package)
25
+ runInstructions({
26
+ instructions: definition.instructions ?? [],
27
+ base,
28
+ data,
29
+ showLog
30
+ });
31
+
32
+ // Task 2: Apply feature options (Key-Value switch-based)
33
+ const optionDefs = (definition.options && typeof definition.options === "object")
34
+ ? definition.options
35
+ : (definitions[instructionMainKey]?.options ?? {});
36
+
37
+ runOptions({
38
+ options,
39
+ optionDefs,
40
+ base,
41
+ data,
42
+ showLog
43
+ });
44
+
45
+ return base;
46
+ };
47
+
48
+ export default startFunc;
49
+
50
+ registerGlobal(startFunc);
@@ -0,0 +1,6 @@
1
+ export const meta = {
2
+ name: "json-renderers-run-instructions",
3
+ version: "1.16.1"
4
+ };
5
+
6
+ export default meta;
@@ -0,0 +1,20 @@
1
+ import {
2
+ getEnabledSwitches,
3
+ shouldInitializeFeature
4
+ } from "./helpers.js";
5
+ import applyInstructionBundle from "./applyInstructionBundle.js";
6
+
7
+ const applyFeature = ({ featureKey, featureSwitches, featureRequest, base, showLog }) => {
8
+ const enabledSwitches = getEnabledSwitches(featureSwitches, featureRequest);
9
+
10
+ if (shouldInitializeFeature(featureSwitches, featureRequest)) {
11
+ applyInstructionBundle(featureSwitches.initialize, base, showLog);
12
+ }
13
+
14
+ for (const { switchKey, instructionKey } of enabledSwitches) {
15
+ if (showLog) console.log(`Enabled switch: ${featureKey}.${switchKey}`);
16
+ applyInstructionBundle(instructionKey, base, showLog);
17
+ }
18
+ };
19
+
20
+ export default applyFeature;
@@ -0,0 +1,45 @@
1
+ import spec from "declarative-spec";
2
+ import instructions from "declarative-instructions";
3
+
4
+ import writePath from "json-write-path";
5
+ import { query } from "jsonpathly";
6
+
7
+ const hasDestination = (base, step) => {
8
+ if (!step.destinationPath?.jsonPath) return true;
9
+
10
+ return query(base, step.destinationPath.jsonPath, { returnArray: true }).length > 0;
11
+ };
12
+
13
+ const shouldSkipInstruction = (base, step) => {
14
+ if (!step.skipIf) return false;
15
+
16
+ return query(base, step.skipIf, { returnArray: true }).length > 0;
17
+ };
18
+
19
+ const applyInstructionBundle = (instructionKey, base, showLog = false) => {
20
+ const steps = instructions[instructionKey];
21
+
22
+ if (!Array.isArray(steps)) {
23
+ if (showLog) console.warn(`Unknown option instruction: ${instructionKey}`);
24
+ return;
25
+ }
26
+
27
+ for (const step of steps) {
28
+ if (shouldSkipInstruction(base, step)) continue;
29
+ if (!hasDestination(base, step)) continue;
30
+
31
+ const template = spec[step.templateKey];
32
+ if (template === undefined) {
33
+ if (showLog) console.warn(`Unknown option template: ${step.templateKey}`);
34
+ continue;
35
+ }
36
+
37
+ writePath({ base }, step.destinationPath, template);
38
+
39
+ if (showLog) {
40
+ console.log(step.narration ?? `Applied option instruction: ${instructionKey}`);
41
+ }
42
+ }
43
+ };
44
+
45
+ export default applyInstructionBundle;
@@ -0,0 +1,41 @@
1
+ const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
+
3
+ const getFeatureRequest = (options, featureKey) => {
4
+ if (!isObject(options)) return null;
5
+
6
+ if (options[featureKey] !== undefined) {
7
+ return options[featureKey];
8
+ }
9
+
10
+ const prefixedKey = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
11
+ return options[prefixedKey] !== undefined ? options[prefixedKey] : null;
12
+ };
13
+
14
+ const isEnabledFeature = featureRequest => {
15
+ if (featureRequest === true) return true;
16
+ return isObject(featureRequest);
17
+ };
18
+
19
+ const getEnabledSwitches = (featureSwitches, featureRequest) => {
20
+ if (!isObject(featureSwitches)) return [];
21
+
22
+ return Object.entries(featureSwitches)
23
+ .filter(([switchKey]) => switchKey !== "initialize")
24
+ .filter(([switchKey]) => featureRequest === true || featureRequest[switchKey] === true)
25
+ .map(([switchKey, instructionKey]) => ({ switchKey, instructionKey }));
26
+ };
27
+
28
+ const shouldInitializeFeature = (featureSwitches, featureRequest) => {
29
+ if (!featureSwitches.initialize) return false;
30
+ if (featureRequest === true) return true;
31
+
32
+ return getEnabledSwitches(featureSwitches, featureRequest).length > 0;
33
+ };
34
+
35
+ export {
36
+ getEnabledSwitches,
37
+ getFeatureRequest,
38
+ isEnabledFeature,
39
+ isObject,
40
+ shouldInitializeFeature
41
+ };
@@ -0,0 +1,73 @@
1
+ // import { spec, instructions } from "spec-repo";
2
+
3
+ import spec from "declarative-spec";
4
+ import instructions from "declarative-instructions";
5
+
6
+ import writePath from "json-write-path";
7
+ import { query } from "jsonpathly";
8
+ import applyFeature from "./applyFeature.js";
9
+ import {
10
+ getFeatureRequest,
11
+ isEnabledFeature,
12
+ isObject
13
+ } from "./helpers.js";
14
+
15
+ const isObjectCheck = value => value !== null && typeof value === "object" && !Array.isArray(value);
16
+
17
+ const getFeatureOptions = (options, featureKey) => {
18
+ if (!isObjectCheck(options)) return null;
19
+ if (options[featureKey] !== undefined) return options[featureKey];
20
+ const prefixed = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
21
+ if (options[prefixed] !== undefined) return options[prefixed];
22
+ return null;
23
+ };
24
+
25
+ const applyOption = (instructionKey, base) => {
26
+ const list = instructions[instructionKey];
27
+ if (!list) return;
28
+
29
+ for (const step of list) {
30
+ if (step.skipIf && query(base, step.skipIf, { returnArray: true }).length > 0) continue;
31
+ const template = spec[step.templateKey];
32
+ try {
33
+ writePath({ base }, step.destinationPath, template);
34
+ } catch {
35
+ // Optional target node not in base (e.g. footer on table without footer)
36
+ }
37
+ }
38
+ };
39
+
40
+ /**
41
+ * Task 2: Applies key-value feature options (search, serial, actions) to base.
42
+ */
43
+ const runOptions = ({
44
+ options = {},
45
+ optionDefs = {},
46
+ base,
47
+ showLog = false
48
+ } = {}) => {
49
+ if (!base || !isObject(options) || !isObject(optionDefs)) {
50
+ return base;
51
+ }
52
+
53
+ for (const [featureKey, featureSwitches] of Object.entries(optionDefs)) {
54
+ if (!isObject(featureSwitches)) continue;
55
+
56
+ const featureRequest = getFeatureRequest(options, featureKey);
57
+ console.log("featureRequest : ", featureRequest);
58
+
59
+ if (!isEnabledFeature(featureRequest)) continue;
60
+
61
+ applyFeature({
62
+ featureKey,
63
+ featureSwitches,
64
+ featureRequest,
65
+ base,
66
+ showLog
67
+ });
68
+ }
69
+
70
+ return base;
71
+ };
72
+
73
+ export default runOptions;
@@ -0,0 +1,50 @@
1
+ import { definitions } from "declarative-definitions";
2
+ import { spec } from "declarative-spec";
3
+
4
+ import runInstructions from "json-renderers-run-instructions-steps";
5
+
6
+ import runOptions from "./runOptions/index.js";
7
+ import registerGlobal from "./registerGlobal/index.js";
8
+
9
+ const startFunc = ({
10
+ instructionMainKey,
11
+ instructionSubKey,
12
+ data,
13
+ options,
14
+ showLog = false
15
+ } = {}) => {
16
+ const definition = definitions[instructionMainKey]?.[instructionSubKey];
17
+ if (!definition) {
18
+ throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
19
+ }
20
+
21
+ // The Canvas
22
+ const base = structuredClone(spec[definition.baseFromSpec]);
23
+
24
+ // Task 1: Execute blueprint instructions (Array-based, from dedicated steps package)
25
+ runInstructions({
26
+ instructions: definition.instructions ?? [],
27
+ base,
28
+ data,
29
+ showLog
30
+ });
31
+
32
+ // Task 2: Apply feature options (Key-Value switch-based)
33
+ const optionDefs = (definition.options && typeof definition.options === "object")
34
+ ? definition.options
35
+ : (definitions[instructionMainKey]?.options ?? {});
36
+
37
+ runOptions({
38
+ options,
39
+ optionDefs,
40
+ base,
41
+ data,
42
+ showLog
43
+ });
44
+
45
+ return base;
46
+ };
47
+
48
+ export default startFunc;
49
+
50
+ registerGlobal(startFunc);
@@ -0,0 +1,6 @@
1
+ export const meta = {
2
+ name: "json-renderers-run-instructions",
3
+ version: "1.17.1"
4
+ };
5
+
6
+ export default meta;
@@ -0,0 +1,20 @@
1
+ import {
2
+ getEnabledSwitches,
3
+ shouldInitializeFeature
4
+ } from "./helpers.js";
5
+ import applyInstructionBundle from "./applyInstructionBundle.js";
6
+
7
+ const applyFeature = ({ featureKey, featureSwitches, featureRequest, base, showLog }) => {
8
+ const enabledSwitches = getEnabledSwitches(featureSwitches, featureRequest);
9
+
10
+ if (shouldInitializeFeature(featureSwitches, featureRequest)) {
11
+ applyInstructionBundle(featureSwitches.initialize, base, showLog);
12
+ }
13
+
14
+ for (const { switchKey, instructionKey } of enabledSwitches) {
15
+ if (showLog) console.log(`Enabled switch: ${featureKey}.${switchKey}`);
16
+ applyInstructionBundle(instructionKey, base, showLog);
17
+ }
18
+ };
19
+
20
+ export default applyFeature;
@@ -0,0 +1,45 @@
1
+ import spec from "declarative-spec";
2
+ import instructions from "declarative-instructions";
3
+
4
+ import writePath from "json-write-path";
5
+ import { query } from "jsonpathly";
6
+
7
+ const hasDestination = (base, step) => {
8
+ if (!step.destinationPath?.jsonPath) return true;
9
+
10
+ return query(base, step.destinationPath.jsonPath, { returnArray: true }).length > 0;
11
+ };
12
+
13
+ const shouldSkipInstruction = (base, step) => {
14
+ if (!step.skipIf) return false;
15
+
16
+ return query(base, step.skipIf, { returnArray: true }).length > 0;
17
+ };
18
+
19
+ const applyInstructionBundle = (instructionKey, base, showLog = false) => {
20
+ const steps = instructions[instructionKey];
21
+
22
+ if (!Array.isArray(steps)) {
23
+ if (showLog) console.warn(`Unknown option instruction: ${instructionKey}`);
24
+ return;
25
+ }
26
+
27
+ for (const step of steps) {
28
+ if (shouldSkipInstruction(base, step)) continue;
29
+ if (!hasDestination(base, step)) continue;
30
+
31
+ const template = spec[step.templateKey];
32
+ if (template === undefined) {
33
+ if (showLog) console.warn(`Unknown option template: ${step.templateKey}`);
34
+ continue;
35
+ }
36
+
37
+ writePath({ base }, step.destinationPath, template);
38
+
39
+ if (showLog) {
40
+ console.log(step.narration ?? `Applied option instruction: ${instructionKey}`);
41
+ }
42
+ }
43
+ };
44
+
45
+ export default applyInstructionBundle;
@@ -0,0 +1,41 @@
1
+ const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
+
3
+ const getFeatureRequest = (options, featureKey) => {
4
+ if (!isObject(options)) return null;
5
+
6
+ if (options[featureKey] !== undefined) {
7
+ return options[featureKey];
8
+ }
9
+
10
+ const prefixedKey = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
11
+ return options[prefixedKey] !== undefined ? options[prefixedKey] : null;
12
+ };
13
+
14
+ const isEnabledFeature = featureRequest => {
15
+ if (featureRequest === true) return true;
16
+ return isObject(featureRequest);
17
+ };
18
+
19
+ const getEnabledSwitches = (featureSwitches, featureRequest) => {
20
+ if (!isObject(featureSwitches)) return [];
21
+
22
+ return Object.entries(featureSwitches)
23
+ .filter(([switchKey]) => switchKey !== "initialize")
24
+ .filter(([switchKey]) => featureRequest === true || featureRequest[switchKey] === true)
25
+ .map(([switchKey, instructionKey]) => ({ switchKey, instructionKey }));
26
+ };
27
+
28
+ const shouldInitializeFeature = (featureSwitches, featureRequest) => {
29
+ if (!featureSwitches.initialize) return false;
30
+ if (featureRequest === true) return true;
31
+
32
+ return getEnabledSwitches(featureSwitches, featureRequest).length > 0;
33
+ };
34
+
35
+ export {
36
+ getEnabledSwitches,
37
+ getFeatureRequest,
38
+ isEnabledFeature,
39
+ isObject,
40
+ shouldInitializeFeature
41
+ };
@@ -0,0 +1,73 @@
1
+ // import { spec, instructions } from "spec-repo";
2
+
3
+ import spec from "declarative-spec";
4
+ import instructions from "declarative-instructions";
5
+
6
+ import writePath from "json-write-path";
7
+ import { query } from "jsonpathly";
8
+ import applyFeature from "./applyFeature.js";
9
+ import {
10
+ getFeatureRequest,
11
+ isEnabledFeature,
12
+ isObject
13
+ } from "./helpers.js";
14
+
15
+ const isObjectCheck = value => value !== null && typeof value === "object" && !Array.isArray(value);
16
+
17
+ const getFeatureOptions = (options, featureKey) => {
18
+ if (!isObjectCheck(options)) return null;
19
+ if (options[featureKey] !== undefined) return options[featureKey];
20
+ const prefixed = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
21
+ if (options[prefixed] !== undefined) return options[prefixed];
22
+ return null;
23
+ };
24
+
25
+ const applyOption = (instructionKey, base) => {
26
+ const list = instructions[instructionKey];
27
+ if (!list) return;
28
+
29
+ for (const step of list) {
30
+ if (step.skipIf && query(base, step.skipIf, { returnArray: true }).length > 0) continue;
31
+ const template = spec[step.templateKey];
32
+ try {
33
+ writePath({ base }, step.destinationPath, template);
34
+ } catch {
35
+ // Optional target node not in base (e.g. footer on table without footer)
36
+ }
37
+ }
38
+ };
39
+
40
+ /**
41
+ * Task 2: Applies key-value feature options (search, serial, actions) to base.
42
+ */
43
+ const runOptions = ({
44
+ options = {},
45
+ optionDefs = {},
46
+ base,
47
+ showLog = false
48
+ } = {}) => {
49
+ if (!base || !isObject(options) || !isObject(optionDefs)) {
50
+ return base;
51
+ }
52
+
53
+ for (const [featureKey, featureSwitches] of Object.entries(optionDefs)) {
54
+ if (!isObject(featureSwitches)) continue;
55
+
56
+ const featureRequest = getFeatureRequest(options, featureKey);
57
+ console.log("featureRequest : ", featureRequest);
58
+
59
+ if (!isEnabledFeature(featureRequest)) continue;
60
+
61
+ applyFeature({
62
+ featureKey,
63
+ featureSwitches,
64
+ featureRequest,
65
+ base,
66
+ showLog
67
+ });
68
+ }
69
+
70
+ return base;
71
+ };
72
+
73
+ export default runOptions;
@@ -0,0 +1,21 @@
1
+ # v18 instruction sequence experiment
2
+
3
+ This version keeps the public options grouped by feature, then resolves enabled
4
+ option steps into one ordered instruction sequence.
5
+
6
+ 1. Clone the component base spec.
7
+ 2. Add the component's normal build instruction keys to the sequence.
8
+ 3. Resolve requested option switches into named keys such as `set-search` and
9
+ `options-show-button`.
10
+ 4. Run each key in order. Object instructions build from data; array
11
+ instructions apply writes to the current spec.
12
+
13
+ The JSON files in `data/` are local snapshots copied from the declarative
14
+ definition, instruction, and spec repositories. The copied table option
15
+ definitions are reshaped here as ordered steps with `when` / `whenAny` gates.
16
+ This lets the runner be worked on before those repositories adopt the new
17
+ option sequence format.
18
+
19
+ The stable package entry point continues to use v17. This experiment is
20
+ available through the `./v18` package subpath and registers its browser global
21
+ at `ks.jsonRenderers.runInstructions.v18`.