json-renderers-run-instructions-steps-single 1.2.1 → 1.3.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 +3 -3
- package/src/index.js +2 -2
- package/src/{v1/single/runStep → v3}/index.js +6 -1
- package/src/{v1 → v3}/registerGlobal/index.js +2 -1
- package/src/v3/registerGlobal/meta.js +6 -0
- package/src/v1/STORY.md +0 -33
- package/src/v1/executeStep.js +0 -26
- package/src/v1/index.js +0 -23
- package/src/v1/multi/guard/index.js +0 -15
- package/src/v1/multi/index.js +0 -15
- package/src/v1/multi/readInstructionSteps.js +0 -5
- package/src/v1/multi/runStepsInOrder.js +0 -11
- package/src/v1/registerGlobal/meta.js +0 -6
- package/src/v1/single/guard/destinationPath.js +0 -27
- package/src/v1/single/guard/error.js +0 -9
- package/src/v1/single/guard/func.js +0 -23
- package/src/v1/single/guard/index.js +0 -15
- package/src/v1/single/guard/sourcePath.js +0 -29
- package/src/v1/single/guard/templateKey.js +0 -32
- package/src/v1/single/index.js +0 -18
- package/src/v1/single/runStep.js +0 -1
- /package/src/{v1/single/runStep → v3}/applyStaticInstruction.js +0 -0
- /package/src/{v1/single/runStep → v3}/buildResult.js +0 -0
- /package/src/{v1/single/runStep → v3}/readSource.js +0 -0
- /package/src/{v1/single/runStep → v3}/shouldSkip.js +0 -0
- /package/src/{v1/single/runStep → v3}/writeResult.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-renderers-run-instructions-steps-single",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Sequential blueprint instruction step runner for JSON renderers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"homepage": "https://keshavsoft.github.io/json-renderers-run-instructions-steps-single/",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"declarative-spec": "^1.4.1",
|
|
38
|
-
"json-transformer-funcs-one-dimension": "^1.
|
|
38
|
+
"json-transformer-funcs-one-dimension": "^1.10.1",
|
|
39
39
|
"json-transformer-funcs-primitive": "^1.9.3",
|
|
40
40
|
"json-transformer-funcs-two-dimensions": "^1.10.1",
|
|
41
41
|
"jsonpathly": "^4.0.0"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v3/index.js";
|
|
2
2
|
|
|
3
|
-
export { default } from "./
|
|
3
|
+
export { default } from "./v3/index.js";
|
|
@@ -3,11 +3,12 @@ import buildResult from "./buildResult.js";
|
|
|
3
3
|
import readSource from "./readSource.js";
|
|
4
4
|
import shouldSkip from "./shouldSkip.js";
|
|
5
5
|
import writeResult from "./writeResult.js";
|
|
6
|
-
|
|
6
|
+
import registerGlobal from "./registerGlobal/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Runs one instruction as a short sequence: skip, read, build, and write.
|
|
9
9
|
*/
|
|
10
10
|
const runStep = (step, state, showLog = false) => {
|
|
11
|
+
if (showLog) console.log("start : ", step, state);
|
|
11
12
|
if (shouldSkip(step, state)) {
|
|
12
13
|
return state;
|
|
13
14
|
}
|
|
@@ -17,7 +18,9 @@ const runStep = (step, state, showLog = false) => {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const source = readSource(step, state);
|
|
21
|
+
if (showLog) console.log("source : ", source);
|
|
20
22
|
const result = buildResult(step, source);
|
|
23
|
+
if (showLog) console.log("result : ", result);
|
|
21
24
|
writeResult(step, state, result);
|
|
22
25
|
|
|
23
26
|
if (showLog) console.log("state : ", state);
|
|
@@ -25,3 +28,5 @@ const runStep = (step, state, showLog = false) => {
|
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
export default runStep;
|
|
31
|
+
|
|
32
|
+
registerGlobal(runStep);
|
|
@@ -6,8 +6,9 @@ const registerGlobal = (runInstructions) => {
|
|
|
6
6
|
globalThis.ks ??= {};
|
|
7
7
|
globalThis.ks.jsonRenderers ??= {};
|
|
8
8
|
globalThis.ks.jsonRenderers.runInstructions ??= {};
|
|
9
|
+
globalThis.ks.jsonRenderers.runInstructions.steps ??= {};
|
|
9
10
|
|
|
10
|
-
globalThis.ks.jsonRenderers.runInstructions.steps = {
|
|
11
|
+
globalThis.ks.jsonRenderers.runInstructions.steps.single = {
|
|
11
12
|
meta,
|
|
12
13
|
runInstructions
|
|
13
14
|
};
|
package/src/v1/STORY.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Version 13 Story: Pure Orchestration Across Single & Multi Folders
|
|
2
|
-
|
|
3
|
-
## Why v13 Exists
|
|
4
|
-
|
|
5
|
-
Building a real UI table revealed two truths at the same time:
|
|
6
|
-
|
|
7
|
-
1. **Some table operations change one slot (`single`)**: building `colgroup`, headers, rows, footer inputs, search slots, or row serial cells.
|
|
8
|
-
2. **Other table operations touch every column slot in lockstep (`multi`)**: adding a serial header + width + footer (`set-serial`), or appending an options column header + width + row button + footer action (`options-show-button`, `options-show-edit-button`, `options-show-delete-button`).
|
|
9
|
-
|
|
10
|
-
When both lived in one giant `declarative-instructions` catalog and one `executeStep.js` file, the runner carried too many responsibilities: importing catalogs, guessing array vs object shapes, dispatching transforms, and mutating rows—all in the same place.
|
|
11
|
-
|
|
12
|
-
## The v13 Design: Orchestrator Above, Workers Below
|
|
13
|
-
|
|
14
|
-
In `v13`, the layers split strictly by job:
|
|
15
|
-
|
|
16
|
-
```text
|
|
17
|
-
Caller ({ instructions: [{ type, key }, ...], base, data })
|
|
18
|
-
│
|
|
19
|
-
▼
|
|
20
|
-
v13/index.js ──▶ v13/executeStep.js (Pure Orchestrator)
|
|
21
|
-
├── type === "single" ──▶ single/index.js (declarative-instructions-single)
|
|
22
|
-
└── type === "multi" ──▶ multi/index.js (declarative-instructions-multi)
|
|
23
|
-
└──▶ shares single/runStep.js
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
- **`index.js` & `executeStep.js` are orchestration only**: They loop over descriptors, validate `{ type, key }`, and hand control to `single/` or `multi/`—zero knowledge of specs, JSONPaths, or DOM templates.
|
|
27
|
-
- **`single/index.js`** owns looking up atomic instructions in `declarative-instructions-single` and running each step onto `base` via `single/runStep.js`.
|
|
28
|
-
- **`multi/index.js`** owns looking up composite sequences in `declarative-instructions-multi` and running each step sequentially using the same shared `single/runStep.js` primitive.
|
|
29
|
-
- **No legacy `declarative-instructions` dependency**: Because `single` and `multi` replaced the mixed catalog cleanly, the old monolithic catalog package is gone from dependencies.
|
|
30
|
-
|
|
31
|
-
## What You Gain Next
|
|
32
|
-
|
|
33
|
-
Because execution order is explicit right at the call site (`single` → `multi` → `single` → `multi`), callers control exact table assembly order while keeping every module small enough to read in seconds—and leaving `declarative-definitions` ready to store those ordered `{ type, key }` recipes whenever a table layout is finalized.
|
package/src/v1/executeStep.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import runSingle from "./single/index.js";
|
|
2
|
-
import runMulti from "./multi/index.js";
|
|
3
|
-
|
|
4
|
-
const stepHandlers = {
|
|
5
|
-
single: runSingle,
|
|
6
|
-
multi: runMulti
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Pure orchestrator: inspects `{ type, key }` and delegates to `single/` or `multi/`.
|
|
11
|
-
*/
|
|
12
|
-
const executeStep = (stepRef, state, showLog = false) => {
|
|
13
|
-
if (!stepRef || typeof stepRef !== "object") {
|
|
14
|
-
throw new Error(`Invalid instruction descriptor: expected { type, key }, got ${String(stepRef)}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { type, key } = stepRef;
|
|
18
|
-
const handler = stepHandlers[type];
|
|
19
|
-
if (!handler) {
|
|
20
|
-
throw new Error(`Unsupported instruction type "${type}" for key "${key}". Expected "single" or "multi".`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return handler(key, state, showLog);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default executeStep;
|
package/src/v1/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import executeStep from "./executeStep.js";
|
|
2
|
-
import registerGlobal from "./registerGlobal/index.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Executes an ordered array of `{ type: "single" | "multi", key }` descriptors on `base`.
|
|
6
|
-
*/
|
|
7
|
-
const runInstructions = ({
|
|
8
|
-
instructions = [],
|
|
9
|
-
base,
|
|
10
|
-
data,
|
|
11
|
-
showLog = false
|
|
12
|
-
} = {}) => {
|
|
13
|
-
instructions.forEach(step => {
|
|
14
|
-
executeStep(step, { base, data }, showLog);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return base;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { executeStep };
|
|
21
|
-
export default runInstructions;
|
|
22
|
-
|
|
23
|
-
registerGlobal(runInstructions);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import guardSingleStep from "../../single/guard/index.js";
|
|
2
|
-
|
|
3
|
-
const guardMultiSteps = (key, steps) => {
|
|
4
|
-
if (!Array.isArray(steps)) {
|
|
5
|
-
throw new Error(`Multi instruction not found: ${key}`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
steps.forEach((step, stepIndex) => {
|
|
9
|
-
guardSingleStep(key, step, { type: "multi", stepIndex });
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
return steps;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default guardMultiSteps;
|
package/src/v1/multi/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import guardMultiSteps from "./guard/index.js";
|
|
2
|
-
import readInstructionSteps from "./readInstructionSteps.js";
|
|
3
|
-
import runStepsInOrder from "./runStepsInOrder.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Executes a multi-step instruction array from `declarative-instructions-multi` sequentially.
|
|
7
|
-
*/
|
|
8
|
-
const runMulti = (key, state, showLog = false) => {
|
|
9
|
-
const steps = readInstructionSteps(key);
|
|
10
|
-
const guardedSteps = guardMultiSteps(key, steps);
|
|
11
|
-
|
|
12
|
-
return runStepsInOrder(guardedSteps, state, showLog);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default runMulti;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import throwGuardError from "./error.js";
|
|
2
|
-
|
|
3
|
-
const supportedStaticActions = new Set([
|
|
4
|
-
"unshift",
|
|
5
|
-
"push",
|
|
6
|
-
"unshiftSerialToRows",
|
|
7
|
-
"pushToRows"
|
|
8
|
-
]);
|
|
9
|
-
|
|
10
|
-
const guardDestinationPath = (key, step, context) => {
|
|
11
|
-
const fail = (message) => throwGuardError(key, message, context);
|
|
12
|
-
|
|
13
|
-
const destinationPath = step.destinationPath;
|
|
14
|
-
if (!destinationPath || typeof destinationPath !== "object" || Array.isArray(destinationPath)) {
|
|
15
|
-
fail("destinationPath must be an object");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (typeof destinationPath.jsonPath !== "string" || destinationPath.jsonPath.trim().length === 0) {
|
|
19
|
-
fail("destinationPath.jsonPath must be a non-empty string");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (step.func === null && !supportedStaticActions.has(destinationPath.action)) {
|
|
23
|
-
fail(`unsupported or missing destinationPath.action "${destinationPath.action}"`);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default guardDestinationPath;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const throwGuardError = (key, message, context = {}) => {
|
|
2
|
-
if (context.type === "multi") {
|
|
3
|
-
throw new Error(`Invalid multi instruction "${key}" at step ${context.stepIndex + 1}: ${message}`);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
throw new Error(`Invalid single instruction "${key}": ${message}`);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default throwGuardError;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import throwGuardError from "./error.js";
|
|
2
|
-
|
|
3
|
-
const supportedFuncs = new Set([
|
|
4
|
-
null,
|
|
5
|
-
"applyTemplate",
|
|
6
|
-
"fromCollection",
|
|
7
|
-
"rowOnColumn",
|
|
8
|
-
"columnOnRow"
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
const guardFunc = (key, step, context) => {
|
|
12
|
-
const fail = (message) => throwGuardError(key, message, context);
|
|
13
|
-
|
|
14
|
-
if (!step || typeof step !== "object" || Array.isArray(step)) {
|
|
15
|
-
fail("expected an instruction object");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!supportedFuncs.has(step.func)) {
|
|
19
|
-
fail(`unsupported or missing func "${step.func}"`);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default guardFunc;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import guardFunc from "./func.js";
|
|
2
|
-
import guardDestinationPath from "./destinationPath.js";
|
|
3
|
-
import guardTemplateKey from "./templateKey.js";
|
|
4
|
-
import guardSourcePath from "./sourcePath.js";
|
|
5
|
-
|
|
6
|
-
const guardSingleStep = (key, step, context = { type: "single" }) => {
|
|
7
|
-
guardFunc(key, step, context);
|
|
8
|
-
guardDestinationPath(key, step, context);
|
|
9
|
-
guardTemplateKey(key, step, context);
|
|
10
|
-
guardSourcePath(key, step, context);
|
|
11
|
-
return step;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { guardDestinationPath, guardFunc, guardSourcePath, guardTemplateKey };
|
|
15
|
-
export default guardSingleStep;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import throwGuardError from "./error.js";
|
|
2
|
-
|
|
3
|
-
const isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
4
|
-
|
|
5
|
-
const guardSourcePath = (key, step, context) => {
|
|
6
|
-
const fail = (message) => throwGuardError(key, message, context);
|
|
7
|
-
|
|
8
|
-
if (step.func === null) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (step.func === "applyTemplate" || step.func === "fromCollection") {
|
|
13
|
-
if (!isNonEmptyString(step.sourcePath)) {
|
|
14
|
-
fail("sourcePath must be a non-empty string");
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const sourcePath = step.sourcePath;
|
|
20
|
-
if (!sourcePath || typeof sourcePath !== "object" || Array.isArray(sourcePath)) {
|
|
21
|
-
fail("sourcePath must contain rows and columns paths");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!isNonEmptyString(sourcePath.rows) || !isNonEmptyString(sourcePath.columns)) {
|
|
25
|
-
fail("sourcePath.rows and sourcePath.columns must be non-empty strings");
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default guardSourcePath;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import spec from "declarative-spec";
|
|
2
|
-
import throwGuardError from "./error.js";
|
|
3
|
-
|
|
4
|
-
const isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
5
|
-
|
|
6
|
-
const guardTemplateKey = (key, step, context) => {
|
|
7
|
-
const fail = (message) => throwGuardError(key, message, context);
|
|
8
|
-
|
|
9
|
-
const requireTemplate = (templateKey, fieldName) => {
|
|
10
|
-
if (!isNonEmptyString(templateKey)) {
|
|
11
|
-
fail(`${fieldName} must be a non-empty string`);
|
|
12
|
-
}
|
|
13
|
-
if (spec[templateKey] === undefined) {
|
|
14
|
-
fail(`template was not found for ${fieldName} "${templateKey}"`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
if (step.func === "rowOnColumn" || step.func === "columnOnRow") {
|
|
19
|
-
const templateKey = step.templateKey;
|
|
20
|
-
if (!templateKey || typeof templateKey !== "object" || Array.isArray(templateKey)) {
|
|
21
|
-
fail("templateKey must contain rowKey and columnKey");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
requireTemplate(templateKey.rowKey, "templateKey.rowKey");
|
|
25
|
-
requireTemplate(templateKey.columnKey, "templateKey.columnKey");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
requireTemplate(step.templateKey, "templateKey");
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default guardTemplateKey;
|
package/src/v1/single/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import singleInstructions from "declarative-instructions-single";
|
|
2
|
-
import guardSingleStep from "./guard/index.js";
|
|
3
|
-
import runStep from "./runStep.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Executes one atomic instruction from `declarative-instructions-single`.
|
|
7
|
-
*/
|
|
8
|
-
const runSingle = (key, state, showLog = false) => {
|
|
9
|
-
const step = singleInstructions[key];
|
|
10
|
-
if (!step) {
|
|
11
|
-
throw new Error(`Single instruction not found: ${key}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return runStep(guardSingleStep(key, step), state, showLog);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { runStep };
|
|
18
|
-
export default runSingle;
|
package/src/v1/single/runStep.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./runStep/index.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|