json-renderers-run-instructions 1.2.1 → 1.2.3

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 CHANGED
@@ -1,14 +1,178 @@
1
- # json-renderers-run-instructions
2
-
3
- Reusable runtime extracted from `json-renderers-build-table`.
4
-
5
- ## v1 exports
6
-
7
- - `runInstructions({ single, double, registry, showLog })` — executes single- and double-target instruction arrays against a caller-provided registry.
8
- - `renderJsonToDom({ jsonSpec, targetHtmlId, appendPosition, showLog })` — mounts a completed JSON spec using `@keshavsoft/json-to-dom`.
9
-
10
- This package is generic. It does not import `spec-repo`, understand tables, or construct table definitions. Table-specific spec generation remains in `json-renderers-build-table`.
11
-
12
- ## Source discipline
13
-
14
- The public entry point is `src/index.js`; the implementation lives in `src/v1/`.
1
+ # json-renderers-run-instructions
2
+
3
+ > **Universal, declarative instruction runner for JSON-driven specification builders.**
4
+ > Decouples instruction dispatch from component semantics — zero DOM, pure data transformation.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/json-renderers-run-instructions.svg?color=cb3837&logo=npm)](https://www.npmjs.com/package/json-renderers-run-instructions)
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
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
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
+ ---
12
+
13
+ ## 📖 The Story: Why This Exists
14
+
15
+ ### The Monolithic Problem
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
+
18
+ This created three architectural hurdles:
19
+ 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
+ 2. **Untestable Side Effects**: Mixing instruction traversal with spec repository lookups (`spec-repo`) made unit tests dependent on specific schema definitions.
21
+ 3. **Rigid Pipelines**: Transforming two-dimensional structures (such as rows × columns) required bespoke nested loops duplicated across every new component builder.
22
+
23
+ ### The Extraction: Pure Instruction Runtime
24
+ `json-renderers-run-instructions` extracts the core execution engine into a standalone, ultra-lean runtime.
25
+
26
+ - **It knows nothing about HTML or the DOM.**
27
+ - **It knows nothing about tables, cells, or CSS.**
28
+ - **It knows nothing about `spec-repo` definitions.**
29
+
30
+ Its sole responsibility is deterministic instruction dispatch: taking declarative **1D (Single)** and **2D (Double)** instruction sequences and executing them against a **Shared Registry**.
31
+
32
+ ---
33
+
34
+ ## 🏗️ Architecture & Concept
35
+
36
+ ### The Shared Registry Pattern
37
+ 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
+
39
+ ```
40
+ ┌───────────────────────────────┐
41
+ │ Registry │
42
+ │ ┌──────────────┬──────────┐ │
43
+ │ │ data / source│ options │ │
44
+ │ ├──────────────┴──────────┤ │
45
+ │ │ base (target spec) │ │
46
+ │ └─────────────────────────┘ │
47
+ └───────────────┬───────────────┘
48
+ │
49
+ ┌───────────────────────┴───────────────────────┐
50
+ │ │
51
+ ▼ Phase 1: 1D Traversal ▼ Phase 2: 2D Traversal
52
+ ┌───────────────────────────────────┐ ┌───────────────────────────────────┐
53
+ │ json-instruction-single │ │ json-instruction-double │
54
+ │ │ │ │
55
+ │ - Column headers │ │ - Matrix generation (rows×cols) │
56
+ │ - Colgroup widths │ │ - Nested cell calculations │
57
+ │ - Linear arrays │ │ - 2D grid population │
58
+ └─────────────────┬─────────────────┘ └─────────────────┬─────────────────┘
59
+ │ │
60
+ └───────────────────────┬───────────────────────┘
61
+ │
62
+ ▼
63
+ ┌─────────────────────────────────┐
64
+ │ Completed JSON Specification │
65
+ │ (Ready for json-to-dom / API) │
66
+ └─────────────────────────────────┘
67
+ ```
68
+
69
+ ---
70
+
71
+ ## 📦 Installation
72
+
73
+ ### Via npm
74
+ ```bash
75
+ npm install json-renderers-run-instructions
76
+ ```
77
+
78
+ ### Via Browser CDN (ES Module)
79
+ ```html
80
+ <script type="module">
81
+ import { runInstructions } from "https://keshavsoft.github.io/json-renderers-run-instructions/dist/min.js";
82
+ </script>
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 🚀 Quick Start
88
+
89
+ ```javascript
90
+ import { runInstructions } from "json-renderers-run-instructions";
91
+
92
+ // 1. Prepare target base specification and source data
93
+ const base = {
94
+ tagName: "table",
95
+ children: [
96
+ { tagName: "thead", children: [{ tagName: "tr", children: [] }] },
97
+ { tagName: "tbody", children: [] }
98
+ ]
99
+ };
100
+
101
+ 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
108
+ };
109
+
110
+ // 2. Define single (1D) and double (2D) instructions
111
+ const single = [
112
+ // Array of instructions executed by json-instruction-single
113
+ ];
114
+
115
+ const double = [
116
+ // Array of instructions executed by json-instruction-double
117
+ ];
118
+
119
+ // 3. Execute instructions against the registry
120
+ runInstructions({
121
+ single,
122
+ double,
123
+ registry,
124
+ showLog: false
125
+ });
126
+
127
+ // `registry.base` now contains the fully resolved specification!
128
+ console.log(registry.base);
129
+ ```
130
+
131
+ ---
132
+
133
+ ## 📚 API Reference
134
+
135
+ ### `runInstructions({ single, double, registry, showLog })`
136
+
137
+ Executes single- and double-target instruction arrays against the shared registry.
138
+
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. |
145
+
146
+ **Returns**: The mutated `registry` object.
147
+
148
+ **Throws**:
149
+ - `TypeError("single instructions must be an array")`
150
+ - `TypeError("double instructions must be an array")`
151
+ - `TypeError("registry must be an object")`
152
+
153
+ ---
154
+
155
+ ## 🧩 The Instruction Pipeline
156
+
157
+ ### 1. Single Instructions (`json-instruction-single`)
158
+ 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
+
160
+ ### 2. Double Instructions (`json-instruction-double`)
161
+ 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
+
163
+ ---
164
+
165
+ ## 🌐 Related Ecosystem Projects
166
+
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. |
171
+ | **[`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. |
173
+
174
+ ---
175
+
176
+ ## 📄 License
177
+
178
+ MIT © [KeshavSoft](https://github.com/keshavsoft)
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
- {
2
- "name": "json-renderers-run-instructions",
3
- "version": "1.2.1",
4
- "description": "Reusable instruction execution and JSON-to-DOM mounting runtime for JSON renderers",
5
- "type": "module",
6
- "main": "src/index.js",
7
- "exports": {
8
- ".": "./src/index.js"
9
- },
10
- "files": [
11
- "src",
12
- "README.md"
13
- ],
14
- "scripts": {
15
- "test": "node --test"
16
- },
17
- "dependencies": {
18
- "json-instruction-double": "^1.3.2",
19
- "json-instruction-single": "^1.5.3"
20
- }
21
- }
1
+ {
2
+ "name": "json-renderers-run-instructions",
3
+ "version": "1.2.3",
4
+ "description": "Reusable instruction execution and JSON-to-DOM mounting runtime for JSON renderers",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "test": "node --test",
16
+ "build": "npx @keshavsoft/build-cli"
17
+ },
18
+ "dependencies": {
19
+ "json-instruction-double": "^1.3.3",
20
+ "json-instruction-single": "^1.5.3"
21
+ },
22
+ "devDependencies": {
23
+ "spec-repo": "^1.6.1"
24
+ }
25
+ }
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./v2/index.js";
2
- export { default } from "./v2/index.js";
1
+ export * from "./v2/index.js";
2
+ export { default } from "./v2/index.js";
package/src/v1/index.js CHANGED
@@ -1,60 +1,60 @@
1
- import runSingleInstructions from "json-instruction-single";
2
- import runDoubleInstructions from "json-instruction-double";
3
- import jsonToDom from "@keshavsoft/json-to-dom";
4
-
5
- /**
6
- * Executes the single- and double-target instruction lists against a shared registry.
7
- * This module deliberately knows nothing about tables or table definitions.
8
- */
9
- export const runInstructions = ({
10
- single = [],
11
- double = [],
12
- registry = {},
13
- showLog = false
14
- } = {}) => {
15
- if (!Array.isArray(single)) {
16
- throw new TypeError("single instructions must be an array");
17
- }
18
- if (!Array.isArray(double)) {
19
- throw new TypeError("double instructions must be an array");
20
- }
21
- if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
22
- throw new TypeError("registry must be an object");
23
- }
24
-
25
- if (single.length > 0) {
26
- runSingleInstructions(single, registry, showLog);
27
- }
28
- if (double.length > 0) {
29
- runDoubleInstructions(double, registry);
30
- }
31
-
32
- return registry;
33
- };
34
-
35
- /**
36
- * Mounts a generated JSON specification into the DOM.
37
- * The caller owns spec generation and supplies the completed JSON spec.
38
- */
39
- export const renderJsonToDom = ({
40
- jsonSpec,
41
- targetHtmlId,
42
- appendPosition,
43
- showLog = false
44
- } = {}) => {
45
- if (!jsonSpec || typeof jsonSpec !== "object" || Array.isArray(jsonSpec)) {
46
- throw new TypeError("jsonSpec must be a JSON object");
47
- }
48
-
49
- return jsonToDom({
50
- jsonSpec,
51
- targetHtmlId,
52
- appendPosition,
53
- showLog
54
- });
55
- };
56
-
57
- export default {
58
- runInstructions,
59
- renderJsonToDom
60
- };
1
+ import runSingleInstructions from "json-instruction-single";
2
+ import runDoubleInstructions from "json-instruction-double";
3
+ import jsonToDom from "@keshavsoft/json-to-dom";
4
+
5
+ /**
6
+ * Executes the single- and double-target instruction lists against a shared registry.
7
+ * This module deliberately knows nothing about tables or table definitions.
8
+ */
9
+ export const runInstructions = ({
10
+ single = [],
11
+ double = [],
12
+ registry = {},
13
+ showLog = false
14
+ } = {}) => {
15
+ if (!Array.isArray(single)) {
16
+ throw new TypeError("single instructions must be an array");
17
+ }
18
+ if (!Array.isArray(double)) {
19
+ throw new TypeError("double instructions must be an array");
20
+ }
21
+ if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
22
+ throw new TypeError("registry must be an object");
23
+ }
24
+
25
+ if (single.length > 0) {
26
+ runSingleInstructions(single, registry, showLog);
27
+ }
28
+ if (double.length > 0) {
29
+ runDoubleInstructions(double, registry);
30
+ }
31
+
32
+ return registry;
33
+ };
34
+
35
+ /**
36
+ * Mounts a generated JSON specification into the DOM.
37
+ * The caller owns spec generation and supplies the completed JSON spec.
38
+ */
39
+ export const renderJsonToDom = ({
40
+ jsonSpec,
41
+ targetHtmlId,
42
+ appendPosition,
43
+ showLog = false
44
+ } = {}) => {
45
+ if (!jsonSpec || typeof jsonSpec !== "object" || Array.isArray(jsonSpec)) {
46
+ throw new TypeError("jsonSpec must be a JSON object");
47
+ }
48
+
49
+ return jsonToDom({
50
+ jsonSpec,
51
+ targetHtmlId,
52
+ appendPosition,
53
+ showLog
54
+ });
55
+ };
56
+
57
+ export default {
58
+ runInstructions,
59
+ renderJsonToDom
60
+ };
package/src/v2/index.js CHANGED
@@ -1,34 +1,35 @@
1
- import runSingleInstructions from "json-instruction-single";
2
- import runDoubleInstructions from "json-instruction-double";
3
-
4
- /**
5
- * Executes the single- and double-target instruction lists against a shared registry.
6
- * This module deliberately knows nothing about tables or table definitions.
7
- */
8
- export const runInstructions = ({
9
- single = [],
10
- double = [],
11
- registry = {},
12
- showLog = false
13
- } = {}) => {
14
- if (!Array.isArray(single)) {
15
- throw new TypeError("single instructions must be an array");
16
- }
17
- if (!Array.isArray(double)) {
18
- throw new TypeError("double instructions must be an array");
19
- }
20
- if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
21
- throw new TypeError("registry must be an object");
22
- }
23
-
24
- if (single.length > 0) {
25
- runSingleInstructions(single, registry, showLog);
26
- }
27
- if (double.length > 0) {
28
- runDoubleInstructions(double, registry);
29
- }
30
-
31
- return registry;
32
- };
33
-
1
+ import runSingleInstructions from "json-instruction-single";
2
+ import runDoubleInstructions from "json-instruction-double";
3
+
4
+ export const runInstructions = ({
5
+ single = [],
6
+ double = [],
7
+ registry = {},
8
+ showLog = false
9
+ } = {}) => {
10
+ if (!Array.isArray(single)) {
11
+ throw new TypeError("single instructions must be an array");
12
+ }
13
+ if (!Array.isArray(double)) {
14
+ throw new TypeError("double instructions must be an array");
15
+ }
16
+ if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
17
+ throw new TypeError("registry must be an object");
18
+ };
19
+ console.log("aaaaaaaaa : ", single, double);
20
+
21
+
22
+ if (single.length > 0) {
23
+ runSingleInstructions(single, registry, showLog);
24
+ }
25
+ if (double.length > 0) {
26
+ runDoubleInstructions({
27
+ instructions: double,
28
+ registry
29
+ });
30
+ };
31
+
32
+ return registry;
33
+ };
34
+
34
35
  export default runInstructions;