json-renderers-run-instructions 1.20.1 → 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.
- package/package.json +13 -16
- package/src/index.js +2 -2
- package/src/v18/README.md +21 -21
- package/src/v18/instructions/executeBuildInstruction.js +53 -53
- package/src/v18/instructions/executeWriteBundle.js +21 -21
- package/src/v18/instructions/index.js +35 -35
- package/src/v18/instructions/resolveSource.js +24 -24
- package/src/v18/instructions/writeResult.js +29 -29
- package/src/v19/data/definitions.json +149 -149
- package/src/v19/data/instructions.json +650 -650
- package/src/v19/data/spec.json +1605 -1605
- package/src/v19/index.js +54 -54
- package/src/v19/instructions/executeBuildInstruction.js +53 -53
- package/src/v19/instructions/executeWriteBundle.js +21 -21
- package/src/v19/instructions/index.js +35 -35
- package/src/v19/instructions/resolveSource.js +24 -24
- package/src/v19/instructions/writeResult.js +29 -29
- package/src/v19/registerGlobal/index.js +16 -16
- package/src/v19/registerGlobal/meta.js +6 -6
- package/src/v19/runOptions/index.js +78 -78
- package/src/v20/index.js +54 -54
- package/src/v20/instructions/executeBuildInstruction.js +53 -53
- package/src/v20/instructions/executeWriteBundle.js +21 -21
- package/src/v20/instructions/index.js +35 -35
- package/src/v20/instructions/resolveSource.js +24 -24
- package/src/v20/instructions/writeResult.js +29 -29
- package/src/v20/registerGlobal/index.js +16 -16
- package/src/v20/registerGlobal/meta.js +6 -6
- package/src/v20/runOptions/index.js +36 -36
- package/src/v20/runOptions/normalizeOptions.js +28 -28
- package/src/v20/runOptions/resolveFeatureKeys.js +43 -43
- package/src/v21/index.js +46 -0
- package/src/v21/registerGlobal/index.js +16 -0
- package/src/v21/registerGlobal/meta.js +6 -0
- package/src/v21/runOptions/index.js +28 -0
- package/src/v21/runOptions/normalizeOptions.js +28 -0
- package/src/v21/runOptions/resolveFeatureKeys.js +55 -0
- package/src/v22/index.js +46 -0
- package/src/v22/registerGlobal/index.js +16 -0
- package/src/v22/registerGlobal/meta.js +6 -0
- package/src/v22/runOptions/index.js +59 -0
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { isObject } from "./normalizeOptions.js";
|
|
2
|
-
|
|
3
|
-
const toKebabCase = value => value.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`);
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Translates one `[featureKey, request]` entry into ordered instruction keys present in `instructions`.
|
|
7
|
-
*/
|
|
8
|
-
const resolveFeatureKeys = ({ featureKey, request, instructions = {}, instructionKeys = [] } = {}) => {
|
|
9
|
-
const rootKey = `set-${featureKey}`;
|
|
10
|
-
const prefix = `${featureKey}-`;
|
|
11
|
-
const keys = [];
|
|
12
|
-
|
|
13
|
-
if (request === true) {
|
|
14
|
-
if (instructions[rootKey] !== undefined) {
|
|
15
|
-
keys.push(rootKey);
|
|
16
|
-
}
|
|
17
|
-
for (const key of instructionKeys) {
|
|
18
|
-
if (key.startsWith(prefix)) {
|
|
19
|
-
keys.push(key);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return keys;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!isObject(request)) return keys;
|
|
26
|
-
|
|
27
|
-
const switchKeys = Object.entries(request)
|
|
28
|
-
.filter(([, enabled]) => enabled === true)
|
|
29
|
-
.map(([switchKey]) => `${prefix}${toKebabCase(switchKey)}`)
|
|
30
|
-
.filter(key => instructions[key] !== undefined);
|
|
31
|
-
|
|
32
|
-
if (switchKeys.length === 0) return keys;
|
|
33
|
-
|
|
34
|
-
if (instructions[rootKey] !== undefined) {
|
|
35
|
-
keys.push(rootKey);
|
|
36
|
-
}
|
|
37
|
-
keys.push(...switchKeys);
|
|
38
|
-
|
|
39
|
-
return keys;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export { resolveFeatureKeys };
|
|
43
|
-
export default resolveFeatureKeys;
|
|
1
|
+
import { isObject } from "./normalizeOptions.js";
|
|
2
|
+
|
|
3
|
+
const toKebabCase = value => value.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Translates one `[featureKey, request]` entry into ordered instruction keys present in `instructions`.
|
|
7
|
+
*/
|
|
8
|
+
const resolveFeatureKeys = ({ featureKey, request, instructions = {}, instructionKeys = [] } = {}) => {
|
|
9
|
+
const rootKey = `set-${featureKey}`;
|
|
10
|
+
const prefix = `${featureKey}-`;
|
|
11
|
+
const keys = [];
|
|
12
|
+
|
|
13
|
+
if (request === true) {
|
|
14
|
+
if (instructions[rootKey] !== undefined) {
|
|
15
|
+
keys.push(rootKey);
|
|
16
|
+
}
|
|
17
|
+
for (const key of instructionKeys) {
|
|
18
|
+
if (key.startsWith(prefix)) {
|
|
19
|
+
keys.push(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return keys;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!isObject(request)) return keys;
|
|
26
|
+
|
|
27
|
+
const switchKeys = Object.entries(request)
|
|
28
|
+
.filter(([, enabled]) => enabled === true)
|
|
29
|
+
.map(([switchKey]) => `${prefix}${toKebabCase(switchKey)}`)
|
|
30
|
+
.filter(key => instructions[key] !== undefined);
|
|
31
|
+
|
|
32
|
+
if (switchKeys.length === 0) return keys;
|
|
33
|
+
|
|
34
|
+
if (instructions[rootKey] !== undefined) {
|
|
35
|
+
keys.push(rootKey);
|
|
36
|
+
}
|
|
37
|
+
keys.push(...switchKeys);
|
|
38
|
+
|
|
39
|
+
return keys;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { resolveFeatureKeys };
|
|
43
|
+
export default resolveFeatureKeys;
|
package/src/v21/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import definitions from "declarative-definitions";
|
|
2
|
+
import spec from "declarative-spec";
|
|
3
|
+
import runInstructions from "json-renderers-run-instructions-steps";
|
|
4
|
+
|
|
5
|
+
import resolveOptionSteps from "./runOptions/index.js";
|
|
6
|
+
import registerGlobal from "./registerGlobal/index.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a component definition, clones its spec canvas, attaches optional feature steps,
|
|
10
|
+
* and delegates execution to `json-renderers-run-instructions-steps` (v13).
|
|
11
|
+
*/
|
|
12
|
+
const startFunc = ({
|
|
13
|
+
instructionMainKey,
|
|
14
|
+
instructionSubKey,
|
|
15
|
+
data,
|
|
16
|
+
options,
|
|
17
|
+
showLog = false
|
|
18
|
+
} = {}) => {
|
|
19
|
+
const definition = definitions[instructionMainKey]?.[instructionSubKey];
|
|
20
|
+
if (!definition) {
|
|
21
|
+
throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const baseTemplate = spec[definition.baseFromSpec];
|
|
25
|
+
if (baseTemplate === undefined) {
|
|
26
|
+
throw new Error(`Base spec not found: ${definition.baseFromSpec}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const base = structuredClone(baseTemplate);
|
|
30
|
+
const baseSteps = definition["instructions-type"] ?? [];
|
|
31
|
+
const optionSteps = options ? resolveOptionSteps({ options }) : [];
|
|
32
|
+
const instructions = [...baseSteps, ...optionSteps];
|
|
33
|
+
|
|
34
|
+
if (showLog) console.log("[v21] instructions : ", instructions);
|
|
35
|
+
|
|
36
|
+
return runInstructions({
|
|
37
|
+
instructions,
|
|
38
|
+
base,
|
|
39
|
+
data,
|
|
40
|
+
showLog
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default startFunc;
|
|
45
|
+
|
|
46
|
+
registerGlobal(startFunc);
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import normalizeOptions, { isObject } from "./normalizeOptions.js";
|
|
2
|
+
import resolveFeatureKeys from "./resolveFeatureKeys.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts caller `options` into ordered, deduplicated `{ type, key }` step descriptors.
|
|
6
|
+
*/
|
|
7
|
+
const resolveOptionSteps = ({ options = {} } = {}) => {
|
|
8
|
+
if (!isObject(options)) return [];
|
|
9
|
+
|
|
10
|
+
const sequence = [];
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
|
|
13
|
+
for (const [featureKey, request] of normalizeOptions(options)) {
|
|
14
|
+
const descriptors = resolveFeatureKeys({ featureKey, request });
|
|
15
|
+
|
|
16
|
+
for (const descriptor of descriptors) {
|
|
17
|
+
const seenId = `${descriptor.type}:${descriptor.key}`;
|
|
18
|
+
if (seen.has(seenId)) continue;
|
|
19
|
+
seen.add(seenId);
|
|
20
|
+
sequence.push(descriptor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return sequence;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { resolveOptionSteps };
|
|
28
|
+
export default resolveOptionSteps;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import singleInstructions from "declarative-instructions-single";
|
|
2
|
+
import multiInstructions from "declarative-instructions-multi";
|
|
3
|
+
import { isObject } from "./normalizeOptions.js";
|
|
4
|
+
|
|
5
|
+
const toKebabCase = value => value.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`);
|
|
6
|
+
|
|
7
|
+
const findTypedDescriptor = (key) => {
|
|
8
|
+
if (singleInstructions[key] !== undefined) return { type: "single", key };
|
|
9
|
+
if (multiInstructions[key] !== undefined) return { type: "multi", key };
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Translates one `[featureKey, request]` entry into ordered `{ type, key }` descriptors
|
|
15
|
+
* resolved across `declarative-instructions-single` and `declarative-instructions-multi`.
|
|
16
|
+
*/
|
|
17
|
+
const resolveFeatureKeys = ({ featureKey, request } = {}) => {
|
|
18
|
+
const rootKey = `set-${featureKey}`;
|
|
19
|
+
const prefix = `${featureKey}-`;
|
|
20
|
+
const descriptors = [];
|
|
21
|
+
|
|
22
|
+
if (request === true) {
|
|
23
|
+
const rootStep = findTypedDescriptor(rootKey);
|
|
24
|
+
if (rootStep) descriptors.push(rootStep);
|
|
25
|
+
|
|
26
|
+
const allKeys = new Set([
|
|
27
|
+
...Object.keys(singleInstructions),
|
|
28
|
+
...Object.keys(multiInstructions)
|
|
29
|
+
]);
|
|
30
|
+
for (const key of allKeys) {
|
|
31
|
+
if (!key.startsWith(prefix)) continue;
|
|
32
|
+
const step = findTypedDescriptor(key);
|
|
33
|
+
if (step) descriptors.push(step);
|
|
34
|
+
}
|
|
35
|
+
return descriptors;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!isObject(request)) return descriptors;
|
|
39
|
+
|
|
40
|
+
const switchSteps = Object.entries(request)
|
|
41
|
+
.filter(([, enabled]) => enabled === true)
|
|
42
|
+
.map(([switchKey]) => findTypedDescriptor(`${prefix}${toKebabCase(switchKey)}`))
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
|
|
45
|
+
if (switchSteps.length === 0) return descriptors;
|
|
46
|
+
|
|
47
|
+
const rootStep = findTypedDescriptor(rootKey);
|
|
48
|
+
if (rootStep) descriptors.push(rootStep);
|
|
49
|
+
descriptors.push(...switchSteps);
|
|
50
|
+
|
|
51
|
+
return descriptors;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { resolveFeatureKeys };
|
|
55
|
+
export default resolveFeatureKeys;
|
package/src/v22/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import definitions from "declarative-definitions";
|
|
2
|
+
import spec from "declarative-spec";
|
|
3
|
+
import runInstructions from "json-renderers-run-instructions-steps";
|
|
4
|
+
|
|
5
|
+
import resolveOptionSteps from "./runOptions/index.js";
|
|
6
|
+
import registerGlobal from "./registerGlobal/index.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a component definition, clones its spec canvas, attaches optional feature steps,
|
|
10
|
+
* and delegates execution to `json-renderers-run-instructions-steps` (v14).
|
|
11
|
+
*/
|
|
12
|
+
const startFunc = ({
|
|
13
|
+
instructionMainKey,
|
|
14
|
+
instructionSubKey,
|
|
15
|
+
data,
|
|
16
|
+
options,
|
|
17
|
+
showLog = false
|
|
18
|
+
} = {}) => {
|
|
19
|
+
const definition = definitions[instructionMainKey]?.[instructionSubKey];
|
|
20
|
+
if (!definition) {
|
|
21
|
+
throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const baseTemplate = spec[definition.baseFromSpec];
|
|
25
|
+
if (baseTemplate === undefined) {
|
|
26
|
+
throw new Error(`Base spec not found: ${definition.baseFromSpec}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const base = structuredClone(baseTemplate);
|
|
30
|
+
const baseSteps = definition["instructions-type"] ?? [];
|
|
31
|
+
const optionSteps = options ? resolveOptionSteps({ options }) : [];
|
|
32
|
+
const instructions = [...baseSteps, ...optionSteps];
|
|
33
|
+
|
|
34
|
+
if (showLog) console.log("[v22] instructions : ", instructions);
|
|
35
|
+
|
|
36
|
+
return runInstructions({
|
|
37
|
+
instructions,
|
|
38
|
+
base,
|
|
39
|
+
data,
|
|
40
|
+
showLog
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default startFunc;
|
|
45
|
+
|
|
46
|
+
registerGlobal(startFunc);
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import singleInstructions from "declarative-instructions-single";
|
|
2
|
+
import multiInstructions from "declarative-instructions-multi";
|
|
3
|
+
|
|
4
|
+
const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
|
|
6
|
+
const allInstructionKeys = Array.from(new Set([
|
|
7
|
+
...Object.keys(singleInstructions),
|
|
8
|
+
...Object.keys(multiInstructions)
|
|
9
|
+
]));
|
|
10
|
+
|
|
11
|
+
const findDescriptor = (key) => {
|
|
12
|
+
if (singleInstructions[key] !== undefined) return { type: "single", key };
|
|
13
|
+
if (multiInstructions[key] !== undefined) return { type: "multi", key };
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const collectSteps = ({ node, prefix, sequence, seen }) => {
|
|
18
|
+
const pushStep = (descriptor) => {
|
|
19
|
+
if (!descriptor) return;
|
|
20
|
+
const id = `${descriptor.type}:${descriptor.key}`;
|
|
21
|
+
if (seen.has(id)) return;
|
|
22
|
+
seen.add(id);
|
|
23
|
+
sequence.push(descriptor);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
for (const [key, value] of Object.entries(node)) {
|
|
27
|
+
if (value === false || value === null || value === undefined) continue;
|
|
28
|
+
|
|
29
|
+
const nextPrefix = `${prefix}-${key}`;
|
|
30
|
+
pushStep(findDescriptor(nextPrefix));
|
|
31
|
+
|
|
32
|
+
if (isObject(value)) {
|
|
33
|
+
collectSteps({ node: value, prefix: nextPrefix, sequence, seen });
|
|
34
|
+
} else if (value === true) {
|
|
35
|
+
const branchPrefix = `${nextPrefix}-`;
|
|
36
|
+
for (const candidateKey of allInstructionKeys) {
|
|
37
|
+
if (candidateKey.startsWith(branchPrefix)) {
|
|
38
|
+
pushStep(findDescriptor(candidateKey));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Walks caller `options` recursively using the strict `options-...` tree path discipline,
|
|
47
|
+
* attaching matching single/multi descriptors and skipping missing nodes.
|
|
48
|
+
*/
|
|
49
|
+
const resolveOptionSteps = ({ options = {} } = {}) => {
|
|
50
|
+
if (!isObject(options)) return [];
|
|
51
|
+
|
|
52
|
+
const sequence = [];
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
collectSteps({ node: options, prefix: "options", sequence, seen });
|
|
55
|
+
return sequence;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { resolveOptionSteps };
|
|
59
|
+
export default resolveOptionSteps;
|