json-renderers-run-instructions 1.15.1 → 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 (68) hide show
  1. package/README.md +42 -31
  2. package/package.json +13 -6
  3. package/src/index.js +2 -2
  4. package/src/v15/index.js +5 -1
  5. package/src/v16/index.js +50 -0
  6. package/src/v16/registerGlobal/meta.js +6 -0
  7. package/src/v16/runOptions/applyFeature.js +20 -0
  8. package/src/v16/runOptions/applyInstructionBundle.js +45 -0
  9. package/src/v16/runOptions/helpers.js +41 -0
  10. package/src/v16/runOptions/index.js +73 -0
  11. package/src/v17/index.js +50 -0
  12. package/src/v17/registerGlobal/meta.js +6 -0
  13. package/src/v17/runOptions/applyFeature.js +20 -0
  14. package/src/v17/runOptions/applyInstructionBundle.js +45 -0
  15. package/src/v17/runOptions/helpers.js +41 -0
  16. package/src/v17/runOptions/index.js +73 -0
  17. package/src/v18/README.md +21 -0
  18. package/src/v18/data/definitions.json +334 -0
  19. package/src/v18/data/instructions.json +650 -0
  20. package/src/v18/data/spec.json +1605 -0
  21. package/src/v18/index.js +58 -0
  22. package/src/v18/instructions/executeBuildInstruction.js +53 -0
  23. package/src/v18/instructions/executeWriteBundle.js +21 -0
  24. package/src/v18/instructions/index.js +35 -0
  25. package/src/{v13/types/helpers → v18/instructions}/resolveSource.js +24 -27
  26. package/src/v18/instructions/writeResult.js +29 -0
  27. package/src/v18/registerGlobal/index.js +16 -0
  28. package/src/{v13 → v18}/registerGlobal/meta.js +1 -1
  29. package/src/v18/runOptions/index.js +47 -0
  30. package/src/v19/data/definitions.json +149 -0
  31. package/src/v19/data/instructions.json +650 -0
  32. package/src/v19/data/spec.json +1605 -0
  33. package/src/v19/index.js +54 -0
  34. package/src/v19/instructions/executeBuildInstruction.js +53 -0
  35. package/src/v19/instructions/executeWriteBundle.js +21 -0
  36. package/src/v19/instructions/index.js +35 -0
  37. package/src/v19/instructions/resolveSource.js +24 -0
  38. package/src/v19/instructions/writeResult.js +29 -0
  39. package/src/v19/registerGlobal/index.js +16 -0
  40. package/src/{v12 → v19}/registerGlobal/meta.js +6 -6
  41. package/src/v19/runOptions/index.js +78 -0
  42. package/src/v20/index.js +54 -0
  43. package/src/v20/instructions/executeBuildInstruction.js +53 -0
  44. package/src/v20/instructions/executeWriteBundle.js +21 -0
  45. package/src/v20/instructions/index.js +35 -0
  46. package/src/v20/instructions/resolveSource.js +24 -0
  47. package/src/v20/instructions/writeResult.js +29 -0
  48. package/src/v20/registerGlobal/index.js +16 -0
  49. package/src/v20/registerGlobal/meta.js +6 -0
  50. package/src/v20/runOptions/index.js +36 -0
  51. package/src/v20/runOptions/normalizeOptions.js +28 -0
  52. package/src/v20/runOptions/resolveFeatureKeys.js +43 -0
  53. package/src/v12/index.js +0 -178
  54. package/src/v12/runOptions/index.js +0 -66
  55. package/src/v12/transformers/columnOnRow.js +0 -33
  56. package/src/v12/transformers/index.js +0 -21
  57. package/src/v13/index.js +0 -49
  58. package/src/v13/runOptions/index.js +0 -66
  59. package/src/v13/transformers/columnOnRow.js +0 -33
  60. package/src/v13/transformers/index.js +0 -21
  61. package/src/v13/types/columnOnRow.js +0 -34
  62. package/src/v13/types/helpers/guards.js +0 -38
  63. package/src/v13/types/helpers/writeResult.js +0 -19
  64. package/src/v13/types/index.js +0 -33
  65. package/src/v13/types/rowOnColumn.js +0 -22
  66. package/src/v13/types/single.js +0 -28
  67. /package/src/{v12 → v16}/registerGlobal/index.js +0 -0
  68. /package/src/{v13 → v17}/registerGlobal/index.js +0 -0
package/README.md CHANGED
@@ -7,21 +7,23 @@
7
7
  [![npm downloads](https://img.shields.io/npm/dm/json-renderers-run-instructions.svg?color=2563eb)](https://www.npmjs.com/package/json-renderers-run-instructions)
8
8
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
9
9
  [![CDN Bundle](https://img.shields.io/badge/CDN-dist%2Fmin.js-orange.svg)](https://keshavsoft.github.io/json-renderers-run-instructions/dist/min.js)
10
-
11
- ---
10
+ [![Documentation](https://img.shields.io/badge/Documentation-Live%20Docs-2563eb.svg)](https://keshavsoft.github.io/json-renderers-run-instructions/)
12
11
 
13
12
  ## 📖 The Story: Why This Exists
14
13
 
15
14
  ### The Monolithic Problem
15
+
16
16
  In early declarative architectures, specification builders (such as `json-renderers-build-table`) were monolithic. The logic that iterated over columns, stamped table headers, computed cells, and mounted elements to the DOM was tightly fused with the instruction execution mechanism.
17
17
 
18
18
  This created three architectural hurdles:
19
+
19
20
  1. **Tight Coupling**: You could not run declarative JSON instructions for other UI structures (lists, forms, cards, navigation trees) without importing table-specific baggage.
20
21
  2. **Untestable Side Effects**: Mixing instruction traversal with spec repository lookups (`spec-repo`) made unit tests dependent on specific schema definitions.
21
22
  3. **Rigid Pipelines**: Transforming two-dimensional structures (such as rows × columns) required bespoke nested loops duplicated across every new component builder.
22
23
 
23
24
  ### The Extraction: Pure Instruction Runtime
24
- `json-renderers-run-instructions` extracts the core execution engine into a standalone, ultra-lean runtime.
25
+
26
+ `json-renderers-run-instructions` extracts the core execution engine into a standalone, ultra-lean runtime.
25
27
 
26
28
  - **It knows nothing about HTML or the DOM.**
27
29
  - **It knows nothing about tables, cells, or CSS.**
@@ -34,6 +36,7 @@ Its sole responsibility is deterministic instruction dispatch: taking declarativ
34
36
  ## 🏗️ Architecture & Concept
35
37
 
36
38
  ### The Shared Registry Pattern
39
+
37
40
  Instead of passing data through fragile intermediate stages, `runInstructions` operates on an in-memory **Registry** blackboard. The caller provisions the inputs (source arrays, options) and an initial specification shell (`base`). The instruction runners mutate and populate the specification in-place.
38
41
 
39
42
  ```
@@ -71,11 +74,13 @@ Instead of passing data through fragile intermediate stages, `runInstructions` o
71
74
  ## 📦 Installation
72
75
 
73
76
  ### Via npm
77
+
74
78
  ```bash
75
79
  npm install json-renderers-run-instructions
76
80
  ```
77
81
 
78
82
  ### Via Browser CDN (ES Module)
83
+
79
84
  ```html
80
85
  <script type="module">
81
86
  import { runInstructions } from "https://keshavsoft.github.io/json-renderers-run-instructions/dist/min.js";
@@ -91,37 +96,40 @@ import { runInstructions } from "json-renderers-run-instructions";
91
96
 
92
97
  // 1. Prepare target base specification and source data
93
98
  const base = {
94
- tagName: "table",
95
- children: [
96
- { tagName: "thead", children: [{ tagName: "tr", children: [] }] },
97
- { tagName: "tbody", children: [] }
98
- ]
99
+ tagName: "table",
100
+ children: [
101
+ { tagName: "thead", children: [{ tagName: "tr", children: [] }] },
102
+ { tagName: "tbody", children: [] },
103
+ ],
99
104
  };
100
105
 
101
106
  const registry = {
102
- data: {
103
- columns: [{ columnName: "item" }, { columnName: "qty" }],
104
- data: [{ item: "Apples", qty: 10 }, { item: "Oranges", qty: 25 }]
105
- },
106
- base,
107
- showSerial: true
107
+ data: {
108
+ columns: [{ columnName: "item" }, { columnName: "qty" }],
109
+ data: [
110
+ { item: "Apples", qty: 10 },
111
+ { item: "Oranges", qty: 25 },
112
+ ],
113
+ },
114
+ base,
115
+ showSerial: true,
108
116
  };
109
117
 
110
118
  // 2. Define single (1D) and double (2D) instructions
111
119
  const single = [
112
- // Array of instructions executed by json-instruction-single
120
+ // Array of instructions executed by json-instruction-single
113
121
  ];
114
122
 
115
123
  const double = [
116
- // Array of instructions executed by json-instruction-double
124
+ // Array of instructions executed by json-instruction-double
117
125
  ];
118
126
 
119
127
  // 3. Execute instructions against the registry
120
128
  runInstructions({
121
- single,
122
- double,
123
- registry,
124
- showLog: false
129
+ single,
130
+ double,
131
+ registry,
132
+ showLog: false,
125
133
  });
126
134
 
127
135
  // `registry.base` now contains the fully resolved specification!
@@ -136,16 +144,17 @@ console.log(registry.base);
136
144
 
137
145
  Executes single- and double-target instruction arrays against the shared registry.
138
146
 
139
- | Parameter | Type | Default | Description |
140
- |---|---|---|---|
141
- | `single` | `Array` | `[]` | List of 1D single-target instructions passed to `json-instruction-single`. |
142
- | `double` | `Array` | `[]` | List of 2D double-target instructions passed to `json-instruction-double`. |
143
- | `registry` | `Object` | `{}` | Shared state blackboard holding `data`, `base`, and optional configurations. |
144
- | `showLog` | `boolean` | `false` | Enable console diagnostic logs during execution. |
147
+ | Parameter | Type | Default | Description |
148
+ | ---------- | --------- | ------- | ---------------------------------------------------------------------------- |
149
+ | `single` | `Array` | `[]` | List of 1D single-target instructions passed to `json-instruction-single`. |
150
+ | `double` | `Array` | `[]` | List of 2D double-target instructions passed to `json-instruction-double`. |
151
+ | `registry` | `Object` | `{}` | Shared state blackboard holding `data`, `base`, and optional configurations. |
152
+ | `showLog` | `boolean` | `false` | Enable console diagnostic logs during execution. |
145
153
 
146
154
  **Returns**: The mutated `registry` object.
147
155
 
148
156
  **Throws**:
157
+
149
158
  - `TypeError("single instructions must be an array")`
150
159
  - `TypeError("double instructions must be an array")`
151
160
  - `TypeError("registry must be an object")`
@@ -155,21 +164,23 @@ Executes single- and double-target instruction arrays against the shared registr
155
164
  ## 🧩 The Instruction Pipeline
156
165
 
157
166
  ### 1. Single Instructions (`json-instruction-single`)
167
+
158
168
  Single instructions handle linear, one-dimensional collections. They read from a 1D source path in the registry (e.g., `data.columns`) and stamp out corresponding element specifications (e.g., `<col>`, `<th>`).
159
169
 
160
170
  ### 2. Double Instructions (`json-instruction-double`)
171
+
161
172
  Double instructions handle nested Cartesian products and 2D grid spaces. They iterate over an outer collection (e.g., data rows) and an inner collection (e.g., column definitions), stamping out multidimensional specs (e.g., `<tr>` rows holding `<td>` cells).
162
173
 
163
174
  ---
164
175
 
165
176
  ## 🌐 Related Ecosystem Projects
166
177
 
167
- | Package | Purpose |
168
- |---|---|
169
- | **[`json-instruction-single`](https://www.npmjs.com/package/json-instruction-single)** | Low-level 1D single-target instruction executor. |
170
- | **[`json-instruction-double`](https://www.npmjs.com/package/json-instruction-double)** | Low-level 2D grid / matrix instruction executor. |
178
+ | Package | Purpose |
179
+ | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
180
+ | **[`json-instruction-single`](https://www.npmjs.com/package/json-instruction-single)** | Low-level 1D single-target instruction executor. |
181
+ | **[`json-instruction-double`](https://www.npmjs.com/package/json-instruction-double)** | Low-level 2D grid / matrix instruction executor. |
171
182
  | **[`json-renderers-from-instructions`](https://github.com/keshavsoft/json-renderers-from-instructions)** | Instruction-driven table specification builder built on top of this runner. |
172
- | **[`@keshavsoft/json-to-dom`](https://www.npmjs.com/package/@keshavsoft/json-to-dom)** | Zero-dependency DOM mounting engine for rendered JSON specifications. |
183
+ | **[`@keshavsoft/json-to-dom`](https://www.npmjs.com/package/@keshavsoft/json-to-dom)** | Zero-dependency DOM mounting engine for rendered JSON specifications. |
173
184
 
174
185
  ---
175
186
 
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "json-renderers-run-instructions",
3
- "version": "1.15.1",
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,11 +18,15 @@
15
18
  "build": "npx @keshavsoft/build-cli"
16
19
  },
17
20
  "dependencies": {
18
- "json-renderers-run-instructions-steps": "^1.3.1",
19
- "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",
20
28
  "json-write-path": "^1.6.1",
21
- "jsonpathly": "^4.0.0",
22
- "spec-repo": "^1.19.2"
29
+ "jsonpathly": "^4.0.0"
23
30
  },
24
31
  "devDependencies": {
25
32
  "spec-repo": "^1.19.2"
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./v14/index.js";
1
+ export * from "./v20/index.js";
2
2
 
3
- export { default } from "./v14/index.js";
3
+ export { default } from "./v20/index.js";
package/src/v15/index.js CHANGED
@@ -1,4 +1,8 @@
1
- import { spec, definitions } from "spec-repo";
1
+ // import { spec, definitions } from "spec-repo";
2
+
3
+ import { definitions } from "declarative-definitions";
4
+ import { spec } from "declarative-spec";
5
+
2
6
  import runInstructions from "json-renderers-run-instructions-steps";
3
7
 
4
8
  import runOptions from "./runOptions/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
+ };