json-renderers-run-instructions 1.20.3 → 1.22.2

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 (41) hide show
  1. package/package.json +12 -12
  2. package/src/index.js +2 -2
  3. package/src/v18/README.md +21 -21
  4. package/src/v18/instructions/executeBuildInstruction.js +53 -53
  5. package/src/v18/instructions/executeWriteBundle.js +21 -21
  6. package/src/v18/instructions/index.js +35 -35
  7. package/src/v18/instructions/resolveSource.js +24 -24
  8. package/src/v18/instructions/writeResult.js +29 -29
  9. package/src/v19/data/definitions.json +149 -149
  10. package/src/v19/data/instructions.json +650 -650
  11. package/src/v19/data/spec.json +1605 -1605
  12. package/src/v19/index.js +54 -54
  13. package/src/v19/instructions/executeBuildInstruction.js +53 -53
  14. package/src/v19/instructions/executeWriteBundle.js +21 -21
  15. package/src/v19/instructions/index.js +35 -35
  16. package/src/v19/instructions/resolveSource.js +24 -24
  17. package/src/v19/instructions/writeResult.js +29 -29
  18. package/src/v19/registerGlobal/index.js +16 -16
  19. package/src/v19/registerGlobal/meta.js +6 -6
  20. package/src/v19/runOptions/index.js +78 -78
  21. package/src/v20/index.js +54 -54
  22. package/src/v20/instructions/executeBuildInstruction.js +53 -53
  23. package/src/v20/instructions/executeWriteBundle.js +21 -21
  24. package/src/v20/instructions/index.js +35 -35
  25. package/src/v20/instructions/resolveSource.js +24 -24
  26. package/src/v20/instructions/writeResult.js +29 -29
  27. package/src/v20/registerGlobal/index.js +16 -16
  28. package/src/v20/registerGlobal/meta.js +6 -6
  29. package/src/v20/runOptions/index.js +36 -36
  30. package/src/v20/runOptions/normalizeOptions.js +28 -28
  31. package/src/v20/runOptions/resolveFeatureKeys.js +43 -43
  32. package/src/v21/index.js +46 -0
  33. package/src/v21/registerGlobal/index.js +16 -0
  34. package/src/v21/registerGlobal/meta.js +6 -0
  35. package/src/v21/runOptions/index.js +28 -0
  36. package/src/v21/runOptions/normalizeOptions.js +28 -0
  37. package/src/v21/runOptions/resolveFeatureKeys.js +55 -0
  38. package/src/v22/index.js +46 -0
  39. package/src/v22/registerGlobal/index.js +16 -0
  40. package/src/v22/registerGlobal/meta.js +6 -0
  41. package/src/v22/runOptions/index.js +59 -0
package/src/v20/index.js CHANGED
@@ -1,54 +1,54 @@
1
- import definitions from "declarative-definitions";
2
- import instructions from "declarative-instructions";
3
- import spec from "declarative-spec";
4
-
5
- import resolveOptionSteps from "./runOptions/index.js";
6
- import runInstructionSequence from "./instructions/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
- // Start with the component's base JSON spec.
22
- const baseTemplate = spec[definition.baseFromSpec];
23
- if (baseTemplate === undefined) {
24
- throw new Error(`Base spec not found: ${definition.baseFromSpec}`);
25
- }
26
-
27
- const base = structuredClone(baseTemplate);
28
-
29
- // Resolve external options directly into instruction keys defined in declarative-instructions.
30
- const optionsArray = resolveOptionSteps({ options, instructions });
31
- if (showLog) console.log("optionsArray : ", optionsArray);
32
-
33
- const instructionSequence = [
34
- ...(definition.instructions ?? []).map(key => ({
35
- key,
36
- instructionKey: key
37
- })),
38
- ...optionsArray
39
- ];
40
- if (showLog) console.log("instructionSequence : ", instructionSequence);
41
-
42
- return runInstructionSequence({
43
- sequence: instructionSequence,
44
- base,
45
- data,
46
- instructions,
47
- spec,
48
- showLog
49
- });
50
- };
51
-
52
- export default startFunc;
53
-
54
- registerGlobal(startFunc);
1
+ import definitions from "declarative-definitions";
2
+ import instructions from "declarative-instructions";
3
+ import spec from "declarative-spec";
4
+
5
+ import resolveOptionSteps from "./runOptions/index.js";
6
+ import runInstructionSequence from "./instructions/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
+ // Start with the component's base JSON spec.
22
+ const baseTemplate = spec[definition.baseFromSpec];
23
+ if (baseTemplate === undefined) {
24
+ throw new Error(`Base spec not found: ${definition.baseFromSpec}`);
25
+ }
26
+
27
+ const base = structuredClone(baseTemplate);
28
+
29
+ // Resolve external options directly into instruction keys defined in declarative-instructions.
30
+ const optionsArray = resolveOptionSteps({ options, instructions });
31
+ if (showLog) console.log("optionsArray : ", optionsArray);
32
+
33
+ const instructionSequence = [
34
+ ...(definition.instructions ?? []).map(key => ({
35
+ key,
36
+ instructionKey: key
37
+ })),
38
+ ...optionsArray
39
+ ];
40
+ if (showLog) console.log("instructionSequence : ", instructionSequence);
41
+
42
+ return runInstructionSequence({
43
+ sequence: instructionSequence,
44
+ base,
45
+ data,
46
+ instructions,
47
+ spec,
48
+ showLog
49
+ });
50
+ };
51
+
52
+ export default startFunc;
53
+
54
+ registerGlobal(startFunc);
@@ -1,53 +1,53 @@
1
- import applyTemplate from "json-transformer-funcs-primitive";
2
- import fromCollection from "json-transformer-funcs-one-dimension";
3
- import { columnOnRow, rowOnColumn } from "json-transformer-funcs-two-dimensions";
4
-
5
- import resolveSource from "./resolveSource.js";
6
- import writeResult from "./writeResult.js";
7
-
8
- const getTemplate = (spec, key) => {
9
- const template = spec[key];
10
- if (template === undefined) {
11
- throw new Error(`Instruction spec not found: ${key}`);
12
- }
13
- return template;
14
- };
15
-
16
- const executeBuildInstruction = ({ key, instruction, state, spec, showLog = false }) => {
17
- const templateKey = instruction.templateKey;
18
- let result;
19
-
20
- switch (instruction.type) {
21
- case "single": {
22
- const source = resolveSource(instruction.sourcePath, state);
23
- const template = getTemplate(spec, templateKey);
24
- result = instruction.func === "fromCollection"
25
- ? fromCollection(source ?? [], template)
26
- : applyTemplate(source, template, showLog);
27
- break;
28
- }
29
- case "rowOnColumn":
30
- result = rowOnColumn({
31
- columns: state.data?.columns,
32
- data: state.data,
33
- columnSpec: getTemplate(spec, templateKey.columnKey),
34
- rowSpec: getTemplate(spec, templateKey.rowKey)
35
- });
36
- break;
37
- case "columnOnRow":
38
- result = columnOnRow({
39
- columns: state.data?.columns,
40
- data: state.data,
41
- columnSpec: getTemplate(spec, templateKey.columnKey),
42
- rowSpec: getTemplate(spec, templateKey.rowKey)
43
- });
44
- break;
45
- default:
46
- throw new Error(`Unsupported instruction type for ${key}: ${instruction.type}`);
47
- }
48
-
49
- writeResult(state, instruction.destinationPath, result, showLog);
50
- if (showLog) console.log(instruction.narration ?? `Ran instruction: ${key}`);
51
- };
52
-
53
- export default executeBuildInstruction;
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+ import { columnOnRow, rowOnColumn } from "json-transformer-funcs-two-dimensions";
4
+
5
+ import resolveSource from "./resolveSource.js";
6
+ import writeResult from "./writeResult.js";
7
+
8
+ const getTemplate = (spec, key) => {
9
+ const template = spec[key];
10
+ if (template === undefined) {
11
+ throw new Error(`Instruction spec not found: ${key}`);
12
+ }
13
+ return template;
14
+ };
15
+
16
+ const executeBuildInstruction = ({ key, instruction, state, spec, showLog = false }) => {
17
+ const templateKey = instruction.templateKey;
18
+ let result;
19
+
20
+ switch (instruction.type) {
21
+ case "single": {
22
+ const source = resolveSource(instruction.sourcePath, state);
23
+ const template = getTemplate(spec, templateKey);
24
+ result = instruction.func === "fromCollection"
25
+ ? fromCollection(source ?? [], template)
26
+ : applyTemplate(source, template, showLog);
27
+ break;
28
+ }
29
+ case "rowOnColumn":
30
+ result = rowOnColumn({
31
+ columns: state.data?.columns,
32
+ data: state.data,
33
+ columnSpec: getTemplate(spec, templateKey.columnKey),
34
+ rowSpec: getTemplate(spec, templateKey.rowKey)
35
+ });
36
+ break;
37
+ case "columnOnRow":
38
+ result = columnOnRow({
39
+ columns: state.data?.columns,
40
+ data: state.data,
41
+ columnSpec: getTemplate(spec, templateKey.columnKey),
42
+ rowSpec: getTemplate(spec, templateKey.rowKey)
43
+ });
44
+ break;
45
+ default:
46
+ throw new Error(`Unsupported instruction type for ${key}: ${instruction.type}`);
47
+ }
48
+
49
+ writeResult(state, instruction.destinationPath, result, showLog);
50
+ if (showLog) console.log(instruction.narration ?? `Ran instruction: ${key}`);
51
+ };
52
+
53
+ export default executeBuildInstruction;
@@ -1,21 +1,21 @@
1
- import { query } from "jsonpathly";
2
- import writePath from "json-write-path";
3
-
4
- import { hasDestination } from "./writeResult.js";
5
-
6
- const executeWriteBundle = ({ key, steps, state, spec, showLog = false }) => {
7
- for (const step of steps) {
8
- if (step.skipIf && query(state.base, step.skipIf, { returnArray: true }).length > 0) continue;
9
- if (!hasDestination(state, step.destinationPath)) continue;
10
-
11
- const template = spec[step.templateKey];
12
- if (template === undefined) {
13
- throw new Error(`Instruction spec not found: ${step.templateKey} (from ${key})`);
14
- }
15
-
16
- writePath(state, step.destinationPath, structuredClone(template), showLog);
17
- if (showLog) console.log(step.narration ?? `Ran instruction: ${key}`);
18
- }
19
- };
20
-
21
- export default executeWriteBundle;
1
+ import { query } from "jsonpathly";
2
+ import writePath from "json-write-path";
3
+
4
+ import { hasDestination } from "./writeResult.js";
5
+
6
+ const executeWriteBundle = ({ key, steps, state, spec, showLog = false }) => {
7
+ for (const step of steps) {
8
+ if (step.skipIf && query(state.base, step.skipIf, { returnArray: true }).length > 0) continue;
9
+ if (!hasDestination(state, step.destinationPath)) continue;
10
+
11
+ const template = spec[step.templateKey];
12
+ if (template === undefined) {
13
+ throw new Error(`Instruction spec not found: ${step.templateKey} (from ${key})`);
14
+ }
15
+
16
+ writePath(state, step.destinationPath, structuredClone(template), showLog);
17
+ if (showLog) console.log(step.narration ?? `Ran instruction: ${key}`);
18
+ }
19
+ };
20
+
21
+ export default executeWriteBundle;
@@ -1,35 +1,35 @@
1
- import executeBuildInstruction from "./executeBuildInstruction.js";
2
- import executeWriteBundle from "./executeWriteBundle.js";
3
-
4
- const runInstructionSequence = ({
5
- sequence = [],
6
- base,
7
- data,
8
- instructions,
9
- spec,
10
- showLog = false
11
- } = {}) => {
12
- const state = { base, data };
13
-
14
- for (const step of sequence) {
15
- const instructionKey = typeof step === "string" ? step : step.instructionKey;
16
- const instruction = instructions[instructionKey];
17
-
18
- if (!instruction) {
19
- throw new Error(`Instruction not found: ${instructionKey}`);
20
- }
21
-
22
- if (showLog) console.log(`[v20] ${step.key ?? instructionKey}`);
23
-
24
- if (Array.isArray(instruction)) {
25
- executeWriteBundle({ key: instructionKey, steps: instruction, state, spec, showLog });
26
- continue;
27
- }
28
-
29
- executeBuildInstruction({ key: instructionKey, instruction, state, spec, showLog });
30
- }
31
-
32
- return state.base;
33
- };
34
-
35
- export default runInstructionSequence;
1
+ import executeBuildInstruction from "./executeBuildInstruction.js";
2
+ import executeWriteBundle from "./executeWriteBundle.js";
3
+
4
+ const runInstructionSequence = ({
5
+ sequence = [],
6
+ base,
7
+ data,
8
+ instructions,
9
+ spec,
10
+ showLog = false
11
+ } = {}) => {
12
+ const state = { base, data };
13
+
14
+ for (const step of sequence) {
15
+ const instructionKey = typeof step === "string" ? step : step.instructionKey;
16
+ const instruction = instructions[instructionKey];
17
+
18
+ if (!instruction) {
19
+ throw new Error(`Instruction not found: ${instructionKey}`);
20
+ }
21
+
22
+ if (showLog) console.log(`[v20] ${step.key ?? instructionKey}`);
23
+
24
+ if (Array.isArray(instruction)) {
25
+ executeWriteBundle({ key: instructionKey, steps: instruction, state, spec, showLog });
26
+ continue;
27
+ }
28
+
29
+ executeBuildInstruction({ key: instructionKey, instruction, state, spec, showLog });
30
+ }
31
+
32
+ return state.base;
33
+ };
34
+
35
+ export default runInstructionSequence;
@@ -1,24 +1,24 @@
1
- import { query } from "jsonpathly";
2
-
3
- const resolveSource = (sourcePath, state) => {
4
- if (!sourcePath) return null;
5
-
6
- const root = state[sourcePath.fileName];
7
- if (root === undefined) {
8
- throw new Error(`Instruction source not found: ${sourcePath.fileName}`);
9
- }
10
-
11
- if (sourcePath.jsonPath) {
12
- const matches = query(root, sourcePath.jsonPath, { returnArray: true });
13
- if (matches.length === 0) return Array.isArray(root) ? root : [];
14
- return matches.length === 1 ? matches[0] : matches;
15
- }
16
-
17
- if (Array.isArray(sourcePath.filePath) && sourcePath.filePath.length > 0) {
18
- return sourcePath.filePath.reduce((value, key) => value?.[key], root);
19
- }
20
-
21
- return root;
22
- };
23
-
24
- export default resolveSource;
1
+ import { query } from "jsonpathly";
2
+
3
+ const resolveSource = (sourcePath, state) => {
4
+ if (!sourcePath) return null;
5
+
6
+ const root = state[sourcePath.fileName];
7
+ if (root === undefined) {
8
+ throw new Error(`Instruction source not found: ${sourcePath.fileName}`);
9
+ }
10
+
11
+ if (sourcePath.jsonPath) {
12
+ const matches = query(root, sourcePath.jsonPath, { returnArray: true });
13
+ if (matches.length === 0) return Array.isArray(root) ? root : [];
14
+ return matches.length === 1 ? matches[0] : matches;
15
+ }
16
+
17
+ if (Array.isArray(sourcePath.filePath) && sourcePath.filePath.length > 0) {
18
+ return sourcePath.filePath.reduce((value, key) => value?.[key], root);
19
+ }
20
+
21
+ return root;
22
+ };
23
+
24
+ export default resolveSource;
@@ -1,29 +1,29 @@
1
- import writePath from "json-write-path";
2
- import { query } from "jsonpathly";
3
-
4
- const hasDestination = (state, destinationPath) => {
5
- if (!destinationPath?.jsonPath) return true;
6
-
7
- const root = state[destinationPath.fileName];
8
- return root !== undefined && query(root, destinationPath.jsonPath, { returnArray: true }).length > 0;
9
- };
10
-
11
- const writeResult = (state, destinationPath, result, showLog = false) => {
12
- if (!destinationPath) return;
13
- if (!hasDestination(state, destinationPath)) return;
14
-
15
- if (!Array.isArray(destinationPath.filePath) || destinationPath.filePath.length === 0) {
16
- const target = state[destinationPath.fileName];
17
- if (Array.isArray(target)) {
18
- target.push(...(Array.isArray(result) ? result : [result]));
19
- } else {
20
- state[destinationPath.fileName] = result;
21
- }
22
- return;
23
- }
24
-
25
- writePath(state, destinationPath, result, showLog);
26
- };
27
-
28
- export { hasDestination };
29
- export default writeResult;
1
+ import writePath from "json-write-path";
2
+ import { query } from "jsonpathly";
3
+
4
+ const hasDestination = (state, destinationPath) => {
5
+ if (!destinationPath?.jsonPath) return true;
6
+
7
+ const root = state[destinationPath.fileName];
8
+ return root !== undefined && query(root, destinationPath.jsonPath, { returnArray: true }).length > 0;
9
+ };
10
+
11
+ const writeResult = (state, destinationPath, result, showLog = false) => {
12
+ if (!destinationPath) return;
13
+ if (!hasDestination(state, destinationPath)) return;
14
+
15
+ if (!Array.isArray(destinationPath.filePath) || destinationPath.filePath.length === 0) {
16
+ const target = state[destinationPath.fileName];
17
+ if (Array.isArray(target)) {
18
+ target.push(...(Array.isArray(result) ? result : [result]));
19
+ } else {
20
+ state[destinationPath.fileName] = result;
21
+ }
22
+ return;
23
+ }
24
+
25
+ writePath(state, destinationPath, result, showLog);
26
+ };
27
+
28
+ export { hasDestination };
29
+ export default writeResult;
@@ -1,16 +1,16 @@
1
- import meta from "./meta.js";
2
-
3
- const registerGlobal = (renderFunc) => {
4
- if (typeof globalThis === "undefined" || !renderFunc) return;
5
-
6
- globalThis.ks ??= {};
7
- globalThis.ks.jsonRenderers ??= {};
8
- globalThis.ks.jsonRenderers.runInstructions ??= {};
9
-
10
- globalThis.ks.jsonRenderers.runInstructions.render = {
11
- meta,
12
- renderFunc
13
- };
14
- };
15
-
16
- export default registerGlobal;
1
+ import meta from "./meta.js";
2
+
3
+ const registerGlobal = (renderFunc) => {
4
+ if (typeof globalThis === "undefined" || !renderFunc) return;
5
+
6
+ globalThis.ks ??= {};
7
+ globalThis.ks.jsonRenderers ??= {};
8
+ globalThis.ks.jsonRenderers.runInstructions ??= {};
9
+
10
+ globalThis.ks.jsonRenderers.runInstructions.render = {
11
+ meta,
12
+ renderFunc
13
+ };
14
+ };
15
+
16
+ export default registerGlobal;
@@ -1,6 +1,6 @@
1
- export const meta = {
2
- name: "json-renderers-run-instructions",
3
- version: "1.20.1"
4
- };
5
-
6
- export default meta;
1
+ export const meta = {
2
+ name: "json-renderers-run-instructions",
3
+ version: "1.20.1"
4
+ };
5
+
6
+ export default meta;
@@ -1,36 +1,36 @@
1
- import normalizeOptions, { isObject } from "./normalizeOptions.js";
2
- import resolveFeatureKeys from "./resolveFeatureKeys.js";
3
-
4
- /**
5
- * Converts caller `options` into ordered, deduplicated instruction steps.
6
- */
7
- const resolveOptionSteps = ({ options = {}, instructions = {} } = {}) => {
8
- if (!isObject(options) || !isObject(instructions)) return [];
9
-
10
- const instructionKeys = Object.keys(instructions);
11
- const sequence = [];
12
- const seen = new Set();
13
-
14
- for (const [featureKey, request] of normalizeOptions(options)) {
15
- const featureKeys = resolveFeatureKeys({
16
- featureKey,
17
- request,
18
- instructions,
19
- instructionKeys
20
- });
21
-
22
- for (const instructionKey of featureKeys) {
23
- if (seen.has(instructionKey)) continue;
24
- seen.add(instructionKey);
25
- sequence.push({
26
- key: instructionKey,
27
- instructionKey
28
- });
29
- }
30
- }
31
-
32
- return sequence;
33
- };
34
-
35
- export { resolveOptionSteps };
36
- export default resolveOptionSteps;
1
+ import normalizeOptions, { isObject } from "./normalizeOptions.js";
2
+ import resolveFeatureKeys from "./resolveFeatureKeys.js";
3
+
4
+ /**
5
+ * Converts caller `options` into ordered, deduplicated instruction steps.
6
+ */
7
+ const resolveOptionSteps = ({ options = {}, instructions = {} } = {}) => {
8
+ if (!isObject(options) || !isObject(instructions)) return [];
9
+
10
+ const instructionKeys = Object.keys(instructions);
11
+ const sequence = [];
12
+ const seen = new Set();
13
+
14
+ for (const [featureKey, request] of normalizeOptions(options)) {
15
+ const featureKeys = resolveFeatureKeys({
16
+ featureKey,
17
+ request,
18
+ instructions,
19
+ instructionKeys
20
+ });
21
+
22
+ for (const instructionKey of featureKeys) {
23
+ if (seen.has(instructionKey)) continue;
24
+ seen.add(instructionKey);
25
+ sequence.push({
26
+ key: instructionKey,
27
+ instructionKey
28
+ });
29
+ }
30
+ }
31
+
32
+ return sequence;
33
+ };
34
+
35
+ export { resolveOptionSteps };
36
+ export default resolveOptionSteps;
@@ -1,28 +1,28 @@
1
- const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
-
3
- /**
4
- * Normalizes modern grouped options and legacy `show*` shorthand flags
5
- * into `[featureKey, request]` pairs, preferring explicit modern keys.
6
- */
7
- const normalizeOptions = (options = {}) => {
8
- if (!isObject(options)) return [];
9
-
10
- const features = new Map();
11
-
12
- for (const [rawKey, rawValue] of Object.entries(options)) {
13
- if (rawKey.startsWith("show") && rawKey.length > 4) {
14
- const featureKey = rawKey.charAt(4).toLowerCase() + rawKey.slice(5);
15
- if (options[featureKey] === undefined) {
16
- features.set(featureKey, rawValue);
17
- }
18
- continue;
19
- }
20
-
21
- features.set(rawKey, rawValue);
22
- }
23
-
24
- return Array.from(features.entries());
25
- };
26
-
27
- export { isObject, normalizeOptions };
28
- export default normalizeOptions;
1
+ const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
+
3
+ /**
4
+ * Normalizes modern grouped options and legacy `show*` shorthand flags
5
+ * into `[featureKey, request]` pairs, preferring explicit modern keys.
6
+ */
7
+ const normalizeOptions = (options = {}) => {
8
+ if (!isObject(options)) return [];
9
+
10
+ const features = new Map();
11
+
12
+ for (const [rawKey, rawValue] of Object.entries(options)) {
13
+ if (rawKey.startsWith("show") && rawKey.length > 4) {
14
+ const featureKey = rawKey.charAt(4).toLowerCase() + rawKey.slice(5);
15
+ if (options[featureKey] === undefined) {
16
+ features.set(featureKey, rawValue);
17
+ }
18
+ continue;
19
+ }
20
+
21
+ features.set(rawKey, rawValue);
22
+ }
23
+
24
+ return Array.from(features.entries());
25
+ };
26
+
27
+ export { isObject, normalizeOptions };
28
+ export default normalizeOptions;