json-instruction-single 1.5.3 → 1.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-instruction-single",
3
- "version": "1.5.3",
3
+ "version": "1.6.1",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "dependencies": {
14
14
  "json-source-path": "^1.2.1",
15
- "json-transformer-funcs-one-dimension": "^1.6.1",
15
+ "json-transformer-funcs-one-dimension": "^1.8.2",
16
16
  "json-transformer-funcs-primitive": "^1.9.3",
17
17
  "json-write-path": "^1.3.2",
18
18
  "spec-repo": "^1.4.2"
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./v5/index.js";
2
- export { default } from "./v5/index.js";
1
+ export * from "./v6/index.js";
2
+ export { default, runSingleInstruction, getResult } from "./v6/index.js";
@@ -0,0 +1,38 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+
4
+ import resolvePath from "json-source-path";
5
+
6
+ import fallbackSpec from "spec-repo";
7
+
8
+ const functions = { applyTemplate, fromCollection };
9
+
10
+ const getSource = (instruction, registry, showLog) => {
11
+ if (instruction?.sourcePath === null) {
12
+ return null;
13
+ };
14
+
15
+ return resolvePath(registry, instruction.sourcePath);
16
+ };
17
+
18
+ const startFunc = (instruction, registry, showLog) => {
19
+ const localSpec = registry?.spec ?? fallbackSpec;
20
+ const localTemplateKey = instruction.templateKey;
21
+ const localFunc = instruction?.func;
22
+
23
+ const template = localSpec[localTemplateKey];
24
+
25
+ const source = getSource(instruction, registry, showLog);
26
+
27
+ const localFuncResult = localFunc === null
28
+ ? template
29
+ : functions[instruction.func](source, template);
30
+
31
+ const result = source === null
32
+ ? template
33
+ : localFuncResult;
34
+
35
+ return result;
36
+ };
37
+
38
+ export default startFunc;
@@ -0,0 +1,10 @@
1
+ import runSingleInstruction, { getResult } from "./runSingleInstruction.js";
2
+
3
+ const startFunc = (instructions, registry, showLog, returnLog) => {
4
+ instructions.forEach(instruction => {
5
+ runSingleInstruction(instruction, registry, showLog, returnLog);
6
+ });
7
+ };
8
+
9
+ export { runSingleInstruction, getResult };
10
+ export default startFunc;
@@ -0,0 +1,12 @@
1
+ import writePath from "json-write-path";
2
+
3
+ import getResult from "./getResult.js";
4
+
5
+ const startFunc = (instruction, registry, showLog) => {
6
+ const result = getResult(instruction, registry, showLog);
7
+
8
+ writePath(registry, instruction.destinationPath, result);
9
+ };
10
+
11
+ export { getResult };
12
+ export default startFunc;