json-renderers-run-instructions 1.9.6 → 1.14.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 (41) hide show
  1. package/package.json +5 -4
  2. package/src/index.js +3 -3
  3. package/src/v10/index.js +218 -0
  4. package/src/v10/registerGlobal/index.js +16 -0
  5. package/src/v10/registerGlobal/meta.js +6 -0
  6. package/src/v10/runOptions/index.js +70 -0
  7. package/src/v10/runOptions/instructionsWithTargets/index.js +31 -0
  8. package/src/v10-2/index.js +202 -0
  9. package/src/v10-2/runOptions/index.js +52 -0
  10. package/src/v10-2/runOptions/instructionsWithTargets/index.js +31 -0
  11. package/src/v10-old/index.js +195 -0
  12. package/src/v10-old/runOptions/index.js +117 -0
  13. package/src/v10-old/runOptions/instructionsWithTargets/index.js +31 -0
  14. package/src/v11/index.js +219 -0
  15. package/src/v11/registerGlobal/index.js +16 -0
  16. package/src/v11/registerGlobal/meta.js +6 -0
  17. package/src/v11/runOptions/index.js +70 -0
  18. package/src/v11/runOptions/instructionsWithTargets/index.js +31 -0
  19. package/src/v12/index.js +178 -0
  20. package/src/v12/registerGlobal/index.js +16 -0
  21. package/src/v12/registerGlobal/meta.js +6 -0
  22. package/src/v12/runOptions/index.js +66 -0
  23. package/src/v12/transformers/columnOnRow.js +33 -0
  24. package/src/v12/transformers/index.js +21 -0
  25. package/src/v13/index.js +49 -0
  26. package/src/v13/registerGlobal/index.js +16 -0
  27. package/src/v13/registerGlobal/meta.js +6 -0
  28. package/src/v13/runOptions/index.js +66 -0
  29. package/src/v13/transformers/columnOnRow.js +33 -0
  30. package/src/v13/transformers/index.js +21 -0
  31. package/src/v13/types/columnOnRow.js +34 -0
  32. package/src/v13/types/helpers/guards.js +38 -0
  33. package/src/v13/types/helpers/resolveSource.js +27 -0
  34. package/src/v13/types/helpers/writeResult.js +19 -0
  35. package/src/v13/types/index.js +33 -0
  36. package/src/v13/types/rowOnColumn.js +22 -0
  37. package/src/v13/types/single.js +28 -0
  38. package/src/v14/index.js +48 -0
  39. package/src/v14/registerGlobal/index.js +16 -0
  40. package/src/v14/registerGlobal/meta.js +6 -0
  41. package/src/v14/runOptions/index.js +77 -0
@@ -0,0 +1,22 @@
1
+ import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
2
+ import writeResult from "./helpers/writeResult.js";
3
+
4
+ const runRowOnColumn = ({ instruction, context, spec, showLog = false }) => {
5
+ const columnSpec = spec[instruction?.templateKey?.columnKey];
6
+ const rowSpec = spec[instruction?.templateKey?.rowKey];
7
+
8
+ const columns = context.data?.columns ?? context.columns ?? [];
9
+ const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows ?? []);
10
+
11
+ const result = rowOnColumnFunc({
12
+ columns,
13
+ data: rows,
14
+ columnSpec,
15
+ rowSpec
16
+ });
17
+
18
+ writeResult(context, instruction.destinationPath, result, showLog);
19
+ return result;
20
+ };
21
+
22
+ export default runRowOnColumn;
@@ -0,0 +1,28 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+ import resolveSource from "./helpers/resolveSource.js";
4
+ import writeResult from "./helpers/writeResult.js";
5
+
6
+ const transformers = {
7
+ applyTemplate,
8
+ fromCollection
9
+ };
10
+
11
+ const runSingle = ({ instruction, context, spec, showLog = false }) => {
12
+ const template = instruction.templateKey ? spec[instruction.templateKey] : null;
13
+ const source = resolveSource(instruction.sourcePath, context);
14
+
15
+ let result;
16
+ if (instruction.func === null || instruction.func === undefined) {
17
+ result = structuredClone(template);
18
+ } else {
19
+ const fn = transformers[instruction.func];
20
+ if (!fn) throw new Error(`Unknown function: ${instruction.func}`);
21
+ result = fn(source, template);
22
+ }
23
+
24
+ writeResult(context, instruction.destinationPath, result, showLog);
25
+ return result;
26
+ };
27
+
28
+ export default runSingle;
@@ -0,0 +1,48 @@
1
+ import { spec, definitions } from "spec-repo";
2
+ import runInstructions from "json-renderers-run-instructions-steps";
3
+
4
+ import runOptions from "./runOptions/index.js";
5
+ import registerGlobal from "./registerGlobal/index.js";
6
+
7
+ const startFunc = ({
8
+ instructionMainKey,
9
+ instructionSubKey,
10
+ data,
11
+ options,
12
+ showLog = false
13
+ } = {}) => {
14
+ const definition = definitions[instructionMainKey]?.[instructionSubKey];
15
+ if (!definition) {
16
+ throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
17
+ }
18
+
19
+ // The Canvas
20
+ const base = structuredClone(spec[definition.baseFromSpec]);
21
+
22
+ // Task 1: Execute blueprint instructions (Array-based, from dedicated steps package)
23
+ runInstructions({
24
+ instructions: definition.instructions ?? [],
25
+ base,
26
+ data,
27
+ showLog
28
+ });
29
+
30
+ // Task 2: Apply feature options (Key-Value switch-based)
31
+ const optionDefs = (definition.options && typeof definition.options === "object")
32
+ ? definition.options
33
+ : (definitions[instructionMainKey]?.options ?? {});
34
+
35
+ runOptions({
36
+ options,
37
+ optionDefs,
38
+ base,
39
+ data,
40
+ showLog
41
+ });
42
+
43
+ return base;
44
+ };
45
+
46
+ export default startFunc;
47
+
48
+ 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,6 @@
1
+ export const meta = {
2
+ name: "json-renderers-run-instructions",
3
+ version: "1.14.1"
4
+ };
5
+
6
+ export default meta;
@@ -0,0 +1,77 @@
1
+ import { spec, instructions } from "spec-repo";
2
+ import writePath from "json-write-path";
3
+ import { query } from "jsonpathly";
4
+
5
+ const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
6
+
7
+ const getFeatureOptions = (options, featureKey) => {
8
+ if (!isObject(options)) return null;
9
+ if (options[featureKey] !== undefined) return options[featureKey];
10
+ const prefixed = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
11
+ if (options[prefixed] !== undefined) return options[prefixed];
12
+ return null;
13
+ };
14
+
15
+ const applyOption = (instructionKey, base) => {
16
+ const list = instructions[instructionKey];
17
+ if (!list) return;
18
+
19
+ for (const step of list) {
20
+ if (step.skipIf && query(base, step.skipIf, { returnArray: true }).length > 0) continue;
21
+ const template = spec[step.templateKey];
22
+ try {
23
+ writePath({ base }, step.destinationPath, template);
24
+ } catch {
25
+ // Optional target node not in base (e.g. footer on table without footer)
26
+ }
27
+ }
28
+ };
29
+
30
+ /**
31
+ * Task 2: Applies key-value feature options (search, serial, actions) to base.
32
+ */
33
+ const runOptions = ({
34
+ options = {},
35
+ optionDefs = {},
36
+ base,
37
+ showLog = false
38
+ } = {}) => {
39
+ if (!base || !isObject(options) || !isObject(optionDefs)) {
40
+ return base;
41
+ }
42
+
43
+ for (const [featureKey, featureSwitches] of Object.entries(optionDefs)) {
44
+ if (!isObject(featureSwitches)) continue;
45
+
46
+ const userFeature = getFeatureOptions(options, featureKey);
47
+ if (!userFeature) continue;
48
+
49
+ const isBool = typeof userFeature === "boolean" && userFeature === true;
50
+ const isObj = isObject(userFeature);
51
+ if (!isBool && !isObj) continue;
52
+
53
+ const hasActiveSwitch = Object.entries(featureSwitches).some(
54
+ ([switchKey]) => switchKey !== "initialize" && (isBool || userFeature[switchKey] === true)
55
+ );
56
+ if (!hasActiveSwitch) continue;
57
+
58
+ // 1. Run initialize option if present (e.g. "searchFrame")
59
+ if (featureSwitches.initialize) {
60
+ applyOption(featureSwitches.initialize, base);
61
+ }
62
+
63
+ // 2. Run enabled switch options (e.g. "searchLabel", "searchInput")
64
+ for (const [switchKey, instructionKey] of Object.entries(featureSwitches)) {
65
+ if (switchKey === "initialize") continue;
66
+
67
+ const isEnabled = isBool || userFeature[switchKey] === true;
68
+ if (isEnabled) {
69
+ applyOption(instructionKey, base);
70
+ }
71
+ }
72
+ }
73
+
74
+ return base;
75
+ };
76
+
77
+ export default runOptions;