json-renderers-run-instructions 1.9.1 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers-run-instructions",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "Reusable instruction execution and JSON-to-DOM mounting runtime for JSON renderers",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -22,9 +22,9 @@
22
22
  "json-transformer-funcs-row-on-column": "^1.2.1",
23
23
  "json-write-path": "^1.6.1",
24
24
  "jsonpathly": "^4.0.0",
25
- "spec-repo": "^1.17.1"
25
+ "spec-repo": "^1.17.2"
26
26
  },
27
27
  "devDependencies": {
28
- "spec-repo": "^1.17.1"
28
+ "spec-repo": "^1.17.2"
29
29
  }
30
- }
30
+ }
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./v8/index.js";
1
+ export * from "./v9/index.js";
2
2
 
3
- export { default } from "./v8/index.js";
3
+ export { default } from "./v9/index.js";
@@ -1,26 +1,43 @@
1
+ import { instructions as defaultInstructions } from "spec-repo";
1
2
  import runSingleInstructions from "json-instruction-single";
2
3
  import instructionsWithTargets from "./instructionsWithTargets/index.js";
3
4
 
4
- export const runOptions = ({ base, options = {}, optionDefs = {}, showLog = false } = {}) => {
5
+ const getInstructionList = (optDef, instructions = defaultInstructions) => {
6
+ if (!optDef) return [];
7
+ if (Array.isArray(optDef)) return optDef;
8
+ if (typeof optDef === "string") return instructions[optDef] ?? [];
9
+ return [];
10
+ };
11
+
12
+ export const runOptions = ({
13
+ base,
14
+ options = {},
15
+ optionDefs = {},
16
+ instructions = defaultInstructions,
17
+ showLog = false
18
+ } = {}) => {
5
19
  if (!base) return base;
6
20
  const context = { base };
7
21
 
8
22
  if (options.showSearch && optionDefs.search) {
9
- const targets = instructionsWithTargets(optionDefs.search, base);
23
+ const list = getInstructionList(optionDefs.search, instructions);
24
+ const targets = instructionsWithTargets(list, base);
10
25
  if (showLog) console.log("[runOptions:search]", targets);
11
26
  runSingleInstructions(targets, context, showLog);
12
27
  }
13
28
  if ((options.showSerial || options.serial) && optionDefs.serial) {
14
- const targets = instructionsWithTargets(optionDefs.serial, base);
29
+ const list = getInstructionList(optionDefs.serial, instructions);
30
+ const targets = instructionsWithTargets(list, base);
15
31
  if (showLog) console.log("[runOptions:serial]", targets);
16
32
  runSingleInstructions(targets, context, showLog);
17
33
  }
18
34
  if ((options.showOptions || options.options) && optionDefs.options) {
19
- const targets = instructionsWithTargets(optionDefs.options, base);
35
+ const list = getInstructionList(optionDefs.options, instructions);
36
+ const targets = instructionsWithTargets(list, base);
20
37
  if (showLog) console.log("[runOptions:options]", targets);
21
38
  runSingleInstructions(targets, context, showLog);
22
39
  }
23
40
  return base;
24
41
  };
25
42
 
26
- export default runOptions;
43
+ export default runOptions;
@@ -1,11 +1,12 @@
1
1
  import { query } from "jsonpathly";
2
2
 
3
3
  const instructionsWithTargets = (instructions = [], base) => {
4
- return instructions.filter(({ destinationPath }) => {
4
+ const list = Array.isArray(instructions) ? instructions : [];
5
+ return list.filter(({ destinationPath }) => {
5
6
  const jsonPath = destinationPath?.jsonPath;
6
7
  if (typeof jsonPath !== "string" || !jsonPath.trim()) return false;
7
8
  return query(base, jsonPath, { returnArray: true }).length > 0;
8
9
  });
9
10
  };
10
11
 
11
- export default instructionsWithTargets;
12
+ export default instructionsWithTargets;