json-instruction-single 0.0.0-stage → 1.2.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/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # json-instruction-single
2
+
3
+ Executes one-dimensional instructions. It validates the instruction, resolves sourcePath, resolves templateKey when present, dispatches the named function, and writes the result to destinationPath.
4
+
5
+ ## Role in the architecture
6
+
7
+ Consumes the shared guard package and executes single instructions.
8
+
9
+ ## Instruction fields
10
+
11
+ - `sourcePath`: object containing `fileName` and `filePath`; the path identifies the input in the registry.
12
+ - `destinationPath`: object containing `fileName` and `filePath`; the path identifies where the result is written.
13
+ - `func`: registered function name.
14
+ - `templateKey`: optional template name used by template-based functions.
15
+ - `narration`: optional human-readable description for logs.
16
+
17
+ ## Usage notes
18
+
19
+ This repository is one package in a multi-package workspace. Keep versioned implementation under `src/vN/` and expose the current version through `src/index.js`. Install the declared dependencies before running the package. The packages are separate repositories in the intended publishing model; placing them together in this ZIP does not publish them to npm or create GitHub repositories.
20
+
21
+ ## Documentation
22
+
23
+ Open [`docs/index.html`](docs/index.html) for the architecture overview and examples.
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
- {
2
- "name": "json-instruction-single",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
1
+ {
2
+ "name": "json-instruction-single",
3
+ "version": "1.2.2",
4
+ "type": "module",
5
+ "main": "src/index.js",
6
+ "exports": {
7
+ ".": "./src/index.js"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "README.md"
12
+ ],
13
+ "dependencies": {
14
+ "json-instruction-guards": "^1.0.0",
15
+ "json-source-path": "^1.2.1",
16
+ "json-write-path": "^1.2.1",
17
+ "json-transformer-funcs-primitive": "^1.9.3",
18
+ "json-transformer-funcs-one-dimension": "^1.6.1"
19
+ }
6
20
  }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./v2/index.js";
2
+ export { default } from "./v2/index.js";
@@ -0,0 +1,24 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+ import writePath from "json-write-path";
4
+ import resolvePath from "json-source-path";
5
+ import validateInstruction from "json-instruction-guards";
6
+
7
+ const defaultFunctions = { applyTemplate, fromCollection };
8
+
9
+ export const runSingleInstruction = (instruction, registry, options = {}) => {
10
+ const { functions = defaultFunctions, showLog = false, returnLog = [] } = options;
11
+ const check = validateInstruction(instruction);
12
+ if (!check.valid) { if (showLog) console.warn("Invalid instruction:", check.errors); return { valid: false, errors: check.errors, registry }; }
13
+ if (typeof functions[instruction.func] !== "function") return { valid: false, errors: [`Unknown function: ${instruction.func}`], registry };
14
+ const source = instruction.sourcePath === null ? null : resolvePath(registry, instruction.sourcePath);
15
+ const template = instruction.templateKey ? registry.spec?.[instruction.templateKey] : undefined;
16
+ const result = source === null && instruction.templateKey ? template : functions[instruction.func](source, template);
17
+ writePath(registry, instruction.destinationPath, result);
18
+ if (showLog) returnLog.push({ instruction: instruction.narration || instruction.func, valid: true });
19
+ return { valid: true, result, registry };
20
+ };
21
+
22
+ export const runSingleInstructions = (instructions = [], registry, options = {}) => instructions.map(instruction => runSingleInstruction(instruction, registry, options));
23
+
24
+ export default runSingleInstructions;
@@ -0,0 +1,46 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import fromCollection from "json-transformer-funcs-one-dimension";
3
+
4
+ import writePath from "json-write-path";
5
+ import resolvePath from "json-source-path";
6
+
7
+ import spec from "./spec.json" with {type: "json"};
8
+
9
+ const functions = { applyTemplate, fromCollection };
10
+
11
+ const getSource = (instruction, registry) => {
12
+ if (instruction?.sourcePath === null) {
13
+ // Runs ONLY if value is exactly null
14
+ return null;
15
+ };
16
+
17
+ const source = resolvePath(registry, instruction.sourcePath);
18
+
19
+ return source;
20
+ };
21
+
22
+ const runSingleInstruction = (instruction, registry, showLog, returnLog) => {
23
+ const localSpec = spec;
24
+ const templateKey = instruction.templateKey;
25
+ let localSpecKey = localSpec[templateKey];
26
+ let result;
27
+
28
+ const source = getSource(instruction, registry);
29
+ // console.log("source : ", source);
30
+
31
+ if (source === null) {
32
+ result = localSpecKey;
33
+ } else {
34
+ result = functions[instruction.func](source, localSpecKey);
35
+ };
36
+
37
+ writePath(registry, instruction.destinationPath, result);
38
+ };
39
+
40
+ const startFunc = (instructions, registry, showLog, returnLog) => {
41
+ instructions.forEach(instruction => {
42
+ runSingleInstruction(instruction, registry, showLog, returnLog);
43
+ });
44
+ };
45
+
46
+ export default startFunc;
@@ -0,0 +1,148 @@
1
+ {
2
+ "buildBodyTr": {
3
+ "tagName": "tr",
4
+ "attributes": {
5
+ "class": "align-middle"
6
+ },
7
+ "children": []
8
+ },
9
+ "buildColGroup": {
10
+ "tagName": "col",
11
+ "attributes": {
12
+ "width": "${width}"
13
+ }
14
+ },
15
+ "buildHeader": {
16
+ "tagName": "th",
17
+ "textContent": "${columnName}",
18
+ "attributes": {
19
+ "class": "py-3 px-3 fw-semibold text-uppercase small"
20
+ }
21
+ },
22
+ "buildFooter": {
23
+ "tagName": "td",
24
+ "children": [
25
+ {
26
+ "tagName": "input",
27
+ "attributes": {
28
+ "type": "text",
29
+ "placeholder": "enter ${columnName}",
30
+ "name": "${columnName}",
31
+ "id": "${columnName}",
32
+ "list": "${columnName}",
33
+ "class": "form-control"
34
+ }
35
+ }
36
+ ]
37
+ },
38
+ "buildBodyCell": {
39
+ "tagName": "td",
40
+ "textContent": "${rowValue}",
41
+ "attributes": {
42
+ "class": "py-3 px-3 text-secondary"
43
+ }
44
+ },
45
+ "button": {
46
+ "tagName": "button",
47
+ "textContent": "${columnName}",
48
+ "attributes": {
49
+ "class": "btn btn-primary btn-sm"
50
+ }
51
+ },
52
+ "buttonCell": {
53
+ "tagName": "td",
54
+ "attributes": {
55
+ "class": "py-2 px-3 text-center"
56
+ },
57
+ "children": [
58
+ {
59
+ "tagName": "button",
60
+ "textContent": "${agg:count}",
61
+ "attributes": {
62
+ "class": "btn btn-primary btn-sm"
63
+ }
64
+ }
65
+ ]
66
+ },
67
+ "optionsButtonCell": {
68
+ "tagName": "td",
69
+ "attributes": {
70
+ "class": "py-2 px-3 text-center"
71
+ },
72
+ "children": [
73
+ {
74
+ "tagName": "button",
75
+ "textContent": "show",
76
+ "attributes": {
77
+ "class": "btn btn-primary btn-sm ks-btn-show"
78
+ }
79
+ }
80
+ ]
81
+ },
82
+ "buildOption": {
83
+ "tagName": "option",
84
+ "textContent": "${rowValue}",
85
+ "attributes": {
86
+ "value": "${rowValue}"
87
+ }
88
+ },
89
+ "buildSelect": {
90
+ "tagName": "select",
91
+ "attributes": {
92
+ "id": "LedgerName"
93
+ },
94
+ "children": []
95
+ },
96
+ "buildDataList": {
97
+ "tagName": "datalist",
98
+ "attributes": {
99
+ "data-name": "${columnName}"
100
+ },
101
+ "children": []
102
+ },
103
+ "emptyCell": {
104
+ "tagName": "td",
105
+ "children": []
106
+ },
107
+ "headerSerialCell": {
108
+ "tagName": "th",
109
+ "textContent": "#",
110
+ "attributes": {
111
+ "class": "py-3 px-3 fw-semibold text-uppercase small"
112
+ }
113
+ },
114
+ "colGroupForSerial": {
115
+ "tagName": "col",
116
+ "attributes": {
117
+ "width": "50px"
118
+ }
119
+ },
120
+ "colGroupForOption": {
121
+ "tagName": "col",
122
+ "attributes": {
123
+ "width": "100px"
124
+ }
125
+ },
126
+ "headerForOption": {
127
+ "tagName": "th",
128
+ "textContent": "options",
129
+ "attributes": {
130
+ "class": "py-3 px-3 fw-semibold text-uppercase small"
131
+ }
132
+ },
133
+ "tdWithButtonSaveWarning": {
134
+ "tagName": "td",
135
+ "attributes": {
136
+ "class": "py-2 px-3 text-center"
137
+ },
138
+ "children": [
139
+ {
140
+ "tagName": "button",
141
+ "textContent": "save",
142
+ "attributes": {
143
+ "class": "btn btn-warning btn-sm ks-btn-save"
144
+ }
145
+ }
146
+ ]
147
+ }
148
+ }