@keshavsoft/kschema-cli 1.1.1 → 1.3.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 (198) hide show
  1. package/CHANGELOG.md +16 -30
  2. package/README.md +21 -78
  3. package/bin/cli.js +11 -10
  4. package/bin/v2/commands/init.js +20 -0
  5. package/bin/v2/commands/template/.vscode/launch.json +12 -0
  6. package/bin/v2/commands/template/Config/Schemas/LedgerNames.json +50 -0
  7. package/bin/v2/commands/template/Data/BillsTable.json +165 -0
  8. package/bin/v2/commands/template/Data/ItemsTable.json +200 -0
  9. package/bin/v2/commands/template/Data/LedgerNames.json +6 -0
  10. package/bin/v2/commands/template/Data/StockItems.json +45 -0
  11. package/bin/v2/commands/template/app.js +4 -0
  12. package/bin/v2/commands/template/package-lock.json +21 -0
  13. package/bin/v2/commands/template/package.json +13 -0
  14. package/bin/v2/commands/template/read.js +8 -0
  15. package/bin/v2/commands/template/write.js +8 -0
  16. package/bin/v2/commands/test.js +36 -0
  17. package/bin/v2/start.js +23 -0
  18. package/bin/v3/commands/init.js +30 -0
  19. package/bin/v3/commands/template/basic/.vscode/launch.json +12 -0
  20. package/bin/v3/commands/template/basic/Config/Schemas/BillsTable.json +165 -0
  21. package/bin/v3/commands/template/basic/Config/Schemas/ItemsTable.json +200 -0
  22. package/bin/v3/commands/template/basic/Config/Schemas/LedgerNames.json +50 -0
  23. package/bin/v3/commands/template/basic/Config/Schemas/StockItems.json +45 -0
  24. package/bin/v3/commands/template/basic/Config/api.json +8 -0
  25. package/bin/v3/commands/template/basic/Config/schema.json +8 -0
  26. package/bin/v3/commands/template/basic/Config/ui.json +8 -0
  27. package/bin/v3/commands/template/basic/Data/BillsTable.json +165 -0
  28. package/bin/v3/commands/template/basic/Data/ItemsTable.json +200 -0
  29. package/bin/v3/commands/template/basic/Data/LedgerNames.json +6 -0
  30. package/bin/v3/commands/template/basic/Data/StockItems.json +45 -0
  31. package/bin/v3/commands/template/basic/app.js +4 -0
  32. package/bin/v3/commands/template/basic/config.json +4 -0
  33. package/bin/v3/commands/template/basic/package-lock.json +21 -0
  34. package/bin/v3/commands/template/basic/package.json +13 -0
  35. package/bin/v3/commands/template/basic/read.js +8 -0
  36. package/bin/v3/commands/template/basic/write.js +8 -0
  37. package/bin/v3/commands/template/express/.env +8 -0
  38. package/bin/v3/commands/template/express/.env.local +7 -0
  39. package/bin/v3/commands/template/express/.vscode/launch.json +12 -0
  40. package/bin/v3/commands/template/express/Config/Schemas/BillsTable.json +166 -0
  41. package/bin/v3/commands/template/express/Config/Schemas/ItemsTable.json +206 -0
  42. package/bin/v3/commands/template/express/Config/Schemas/LedgerNames.json +50 -0
  43. package/bin/v3/commands/template/express/Config/Schemas/StockItems.json +45 -0
  44. package/bin/v3/commands/template/express/Config/api.json +8 -0
  45. package/bin/v3/commands/template/express/Config/schema.json +8 -0
  46. package/bin/v3/commands/template/express/Config/ui.json +8 -0
  47. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/build.js +6 -0
  48. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/config.js +12 -0
  49. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/main.js +29 -0
  50. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/publish.js +22 -0
  51. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/repo.js +20 -0
  52. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/schema.js +16 -0
  53. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/utils.js +26 -0
  54. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/Builder/version.js +25 -0
  55. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/buildAndCopy.js +166 -0
  56. package/bin/v3/commands/template/express/ForFrontEnd/NonSecured/latestVersion.js +38 -0
  57. package/bin/v3/commands/template/express/ForFrontEnd/Secured/buildProtected.js +108 -0
  58. package/bin/v3/commands/template/express/ForFrontEnd/Secured/latestVersion.js +38 -0
  59. package/bin/v3/commands/template/express/app.js +33 -0
  60. package/bin/v3/commands/template/express/config.json +4 -0
  61. package/bin/v3/commands/template/express/package.json +18 -0
  62. package/bin/v3/commands/test.js +36 -0
  63. package/bin/v3/start.js +27 -0
  64. package/package.json +2 -1
  65. package/src/template/v1/Config/Schemas/BillsTable.json +165 -0
  66. package/src/template/v1/Config/Schemas/ItemsTable.json +200 -0
  67. package/src/template/v1/Config/Schemas/StockItems.json +45 -0
  68. package/src/template/v1/Config/api.json +8 -0
  69. package/src/template/v1/Config/schema.json +8 -0
  70. package/src/template/v1/Config/ui.json +8 -0
  71. package/src/template/v1/config.json +4 -0
  72. package/template/v1/Config/Schemas/BillsTable.json +165 -0
  73. package/template/v1/Config/Schemas/ItemsTable.json +200 -0
  74. package/template/v1/Config/Schemas/LedgerNames.json +45 -0
  75. package/template/v1/Config/Schemas/StockItems.json +45 -0
  76. package/template/v1/Config/api.json +8 -0
  77. package/template/v1/Config/schema.json +8 -0
  78. package/template/v1/Config/ui.json +8 -0
  79. package/template/v1/config.json +4 -0
  80. package/template/v2/Config/Schemas/BillsTable.json +165 -0
  81. package/template/v2/Config/Schemas/ItemsTable.json +200 -0
  82. package/template/v2/Config/Schemas/LedgerNames.json +50 -0
  83. package/template/v2/Config/Schemas/StockItems.json +45 -0
  84. package/template/v2/Config/api.json +8 -0
  85. package/template/v2/Config/schema.json +8 -0
  86. package/template/v2/Config/ui.json +8 -0
  87. package/template/v2/Data/BillsTable.json +1 -0
  88. package/template/v2/Data/ItemsTable.json +1 -0
  89. package/template/v2/Data/LedgerNames.json +6 -0
  90. package/template/v2/Data/StockItems.json +1 -0
  91. package/template/v2/config.json +4 -0
  92. package/template/v2/delete.js +8 -0
  93. package/template/v2/package.json +15 -0
  94. package/template/v2/read.js +8 -0
  95. package/template/v2/write.js +8 -0
  96. package/index.js +0 -1
  97. package/src/core/configStore.js +0 -10
  98. package/src/utils/pathBuilder.js +0 -3
  99. package/src/v1/data/deleteData.js +0 -16
  100. package/src/v1/data/getData.js +0 -13
  101. package/src/v1/data/index.js +0 -4
  102. package/src/v1/data/insertData.js +0 -16
  103. package/src/v1/data/updateData.js +0 -20
  104. package/src/v1/index.js +0 -3
  105. package/src/v2/config/getSchema.js +0 -12
  106. package/src/v2/data/deleteData.js +0 -16
  107. package/src/v2/data/getData.js +0 -13
  108. package/src/v2/data/index.js +0 -4
  109. package/src/v2/data/insertData copy.js +0 -46
  110. package/src/v2/data/insertData.js +0 -52
  111. package/src/v2/data/updateData.js +0 -20
  112. package/src/v2/index.js +0 -3
  113. package/src/v3/config/getSchema.js +0 -12
  114. package/src/v3/data/deleteData.js +0 -16
  115. package/src/v3/data/getData.js +0 -13
  116. package/src/v3/data/index.js +0 -4
  117. package/src/v3/data/insertData.js +0 -27
  118. package/src/v3/data/updateData.js +0 -20
  119. package/src/v3/helpers/fileHelper.js +0 -11
  120. package/src/v3/helpers/pkHelper.js +0 -18
  121. package/src/v3/helpers/validateHelper.js +0 -20
  122. package/src/v3/index.js +0 -3
  123. package/src/v4/config/getSchema.js +0 -12
  124. package/src/v4/data/deleteData.js +0 -16
  125. package/src/v4/data/getData.js +0 -13
  126. package/src/v4/data/index.js +0 -4
  127. package/src/v4/data/insertData.js +0 -47
  128. package/src/v4/data/updateData.js +0 -20
  129. package/src/v4/helpers/fileHelper.js +0 -11
  130. package/src/v4/helpers/pkHelper.js +0 -18
  131. package/src/v4/helpers/recordHelper.js +0 -9
  132. package/src/v4/helpers/validateHelper.js +0 -15
  133. package/src/v4/index.js +0 -3
  134. package/src/v5/config/getSchema.js +0 -12
  135. package/src/v5/data/deleteData.js +0 -16
  136. package/src/v5/data/getData.js +0 -13
  137. package/src/v5/data/index.js +0 -8
  138. package/src/v5/data/insertData.js +0 -56
  139. package/src/v5/data/insertDataStrict.js +0 -63
  140. package/src/v5/data/updateData.js +0 -20
  141. package/src/v5/helpers/fileHelper.js +0 -11
  142. package/src/v5/helpers/pkHelper.js +0 -18
  143. package/src/v5/helpers/recordHelper.js +0 -9
  144. package/src/v5/helpers/validateHelper.js +0 -15
  145. package/src/v5/index.js +0 -3
  146. package/src/v6/config/getSchema.js +0 -12
  147. package/src/v6/data/deleteData.js +0 -16
  148. package/src/v6/data/getData.js +0 -13
  149. package/src/v6/data/index.js +0 -8
  150. package/src/v6/data/insertData.js +0 -56
  151. package/src/v6/data/insertDataStrict.js +0 -76
  152. package/src/v6/data/updateData.js +0 -20
  153. package/src/v6/helpers/fileHelper.js +0 -11
  154. package/src/v6/helpers/pkHelper.js +0 -18
  155. package/src/v6/helpers/recordHelper.js +0 -9
  156. package/src/v6/helpers/validateHelper.js +0 -15
  157. package/src/v6/index.js +0 -21
  158. package/src/v7/config/getSchema.js +0 -12
  159. package/src/v7/data/deleteData.js +0 -16
  160. package/src/v7/data/filterByColumns.js +0 -19
  161. package/src/v7/data/filterByPk.js +0 -16
  162. package/src/v7/data/findByColumns.js +0 -21
  163. package/src/v7/data/findByPk.js +0 -16
  164. package/src/v7/data/getData.js +0 -13
  165. package/src/v7/data/index.js +0 -11
  166. package/src/v7/data/insertData.js +0 -55
  167. package/src/v7/data/insertDataStrict.js +0 -73
  168. package/src/v7/data/updateData.js +0 -20
  169. package/src/v7/helpers/fileHelper.js +0 -16
  170. package/src/v7/helpers/pkHelper.js +0 -21
  171. package/src/v7/helpers/recordHelper.js +0 -15
  172. package/src/v7/helpers/validateHelper.js +0 -27
  173. package/src/v7/index.js +0 -27
  174. package/src/v8/config/getSchema.js +0 -12
  175. package/src/v8/data/deleteByColumnsData.js +0 -20
  176. package/src/v8/data/deleteData.js +0 -22
  177. package/src/v8/data/filterByColumns.js +0 -19
  178. package/src/v8/data/filterByPk.js +0 -16
  179. package/src/v8/data/findByColumns.js +0 -21
  180. package/src/v8/data/findByPk.js +0 -16
  181. package/src/v8/data/getData.js +0 -13
  182. package/src/v8/data/index.js +0 -12
  183. package/src/v8/data/insertData.js +0 -55
  184. package/src/v8/data/insertDataStrict.js +0 -73
  185. package/src/v8/data/updateData.js +0 -20
  186. package/src/v8/helpers/fileHelper.js +0 -16
  187. package/src/v8/helpers/pkHelper.js +0 -21
  188. package/src/v8/helpers/recordHelper.js +0 -15
  189. package/src/v8/helpers/validateHelper.js +0 -27
  190. package/src/v8/index.js +0 -43
  191. /package/{template → bin/v2/commands/template}/Config/Schemas/BillsTable.json +0 -0
  192. /package/{template → bin/v2/commands/template}/Config/Schemas/ItemsTable.json +0 -0
  193. /package/{template → bin/v2/commands/template}/Config/Schemas/StockItems.json +0 -0
  194. /package/{template → bin/v2/commands/template}/Config/api.json +0 -0
  195. /package/{template → bin/v2/commands/template}/Config/schema.json +0 -0
  196. /package/{template → bin/v2/commands/template}/Config/ui.json +0 -0
  197. /package/{template → bin/v2/commands/template}/config.json +0 -0
  198. /package/{template → src/template/v1}/Config/Schemas/LedgerNames.json +0 -0
@@ -1,16 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const deleteData = ({ table, key, value }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const newData = data.filter(item => item[key] !== value);
12
-
13
- fs.writeFileSync(path, JSON.stringify(newData, null, 2));
14
-
15
- return true;
16
- };
@@ -1,13 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const getData = ({ table }) => {
6
- const cfg = getConfig();
7
-
8
- const path = buildDataPath(cfg, table);
9
-
10
- const data = fs.readFileSync(path, "utf-8");
11
-
12
- return JSON.parse(data);
13
- };
@@ -1,4 +0,0 @@
1
- export { getData } from "./getData.js";
2
- export { insertData } from "./insertData.js";
3
- export { updateData } from "./updateData.js";
4
- export { deleteData } from "./deleteData.js";
@@ -1,46 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- // 🔹 helpers
6
-
7
- const getPrimaryKey = (columns) => {
8
- const pk = columns.find(c => c.unique)?.field;
9
- if (!pk) throw new Error("Primary key not defined");
10
- return pk;
11
- };
12
-
13
- const readData = (path) => {
14
- return JSON.parse(fs.readFileSync(path));
15
- };
16
-
17
- const writeData = (path, data) => {
18
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
19
- };
20
-
21
- const attachPrimaryKey = (record, pk) => {
22
- return {
23
- ...record,
24
- [pk]: Date.now()
25
- };
26
- };
27
-
28
- // 🔹 main
29
-
30
- export const insertData = ({ table, record }) => {
31
- const config = getConfig();
32
- const schema = config[table];
33
-
34
- const pk = getPrimaryKey(schema.columns);
35
- const path = buildDataPath(config, table);
36
-
37
- const data = readData(path);
38
-
39
- const newRecord = attachPrimaryKey(record, pk);
40
-
41
- data.push(newRecord);
42
-
43
- writeData(path, data);
44
-
45
- return newRecord;
46
- };
@@ -1,52 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
- import { getSchema } from "../config/getSchema.js";
5
- // 🔹 helpers
6
-
7
- const getPrimaryKey = (columns) => {
8
- const pk = columns.find(c => c.unique)?.field;
9
- if (!pk) throw new Error("Primary key not defined");
10
- return pk;
11
- };
12
-
13
- const readData = (path) => {
14
- if (!fs.existsSync(path)) return [];
15
- return JSON.parse(fs.readFileSync(path));
16
- };
17
-
18
- const writeData = (path, data) => {
19
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
20
- };
21
-
22
- const attachPrimaryKey = (record, pk, data) => {
23
- if (data.length === 0) {
24
- return { ...record, [pk]: 1 };
25
- }
26
-
27
- const maxId = Math.max(...data.map(row => row[pk] || 0));
28
-
29
- return {
30
- ...record,
31
- [pk]: maxId + 1
32
- };
33
- };
34
- // 🔹 main
35
-
36
- export const insertData = ({ table, record }) => {
37
- const config = getConfig();
38
- const schema = getSchema(table);
39
-
40
- const pk = getPrimaryKey(schema.columns);
41
- const path = buildDataPath(config, table);
42
-
43
- const data = readData(path);
44
-
45
- const newRecord = attachPrimaryKey(record, pk, data);
46
-
47
- data.push(newRecord);
48
-
49
- writeData(path, data);
50
-
51
- return newRecord;
52
- };
@@ -1,20 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const updateData = ({ table, key, value, updates }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const index = data.findIndex(item => item[key] === value);
12
-
13
- if (index === -1) throw new Error("Record not found");
14
-
15
- data[index] = { ...data[index], ...updates };
16
-
17
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
18
-
19
- return data[index];
20
- };
package/src/v2/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { loadConfig, getConfig } from "../core/configStore.js";
2
-
3
- export * from "./data/index.js";
@@ -1,12 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
-
4
- export const getSchema = (table) => {
5
- const config = getConfig();
6
-
7
- const schemaPath = `${config.SchemaPath}/${table}.json`;
8
-
9
- const schema = fs.readFileSync(schemaPath, "utf-8");
10
-
11
- return JSON.parse(schema);
12
- };
@@ -1,16 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const deleteData = ({ table, key, value }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const newData = data.filter(item => item[key] !== value);
12
-
13
- fs.writeFileSync(path, JSON.stringify(newData, null, 2));
14
-
15
- return true;
16
- };
@@ -1,13 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const getData = ({ table }) => {
6
- const cfg = getConfig();
7
-
8
- const path = buildDataPath(cfg, table);
9
-
10
- const data = fs.readFileSync(path, "utf-8");
11
-
12
- return JSON.parse(data);
13
- };
@@ -1,4 +0,0 @@
1
- export { getData } from "./getData.js";
2
- export { insertData } from "./insertData.js";
3
- export { updateData } from "./updateData.js";
4
- export { deleteData } from "./deleteData.js";
@@ -1,27 +0,0 @@
1
- import { getConfig } from "../../core/configStore.js";
2
- import { buildDataPath } from "../../utils/pathBuilder.js";
3
- import { getSchema } from "../config/getSchema.js";
4
-
5
- import { getPrimaryKey, attachPrimaryKey } from "../helpers/pkHelper.js";
6
- import { readData, writeData } from "../helpers/fileHelper.js";
7
- import { validateRecord } from "../helpers/validateHelper.js";
8
-
9
- export const insertData = ({ table, record }) => {
10
- const config = getConfig();
11
- const schema = getSchema(table);
12
-
13
- const pk = getPrimaryKey(schema.columns);
14
- const path = buildDataPath(config, table);
15
-
16
- const data = readData(path);
17
-
18
- validateRecord(record, schema.columns, data);
19
-
20
- const newRecord = attachPrimaryKey(record, pk, data);
21
-
22
- data.push(newRecord);
23
-
24
- writeData(path, data);
25
-
26
- return newRecord;
27
- };
@@ -1,20 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const updateData = ({ table, key, value, updates }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const index = data.findIndex(item => item[key] === value);
12
-
13
- if (index === -1) throw new Error("Record not found");
14
-
15
- data[index] = { ...data[index], ...updates };
16
-
17
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
18
-
19
- return data[index];
20
- };
@@ -1,11 +0,0 @@
1
- // v3/helpers/fileHelper.js
2
- import fs from "fs";
3
-
4
- export const readData = (path) => {
5
- if (!fs.existsSync(path)) return [];
6
- return JSON.parse(fs.readFileSync(path, "utf-8"));
7
- };
8
-
9
- export const writeData = (path, data) => {
10
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
11
- };
@@ -1,18 +0,0 @@
1
- // v3/helpers/pkHelper.js
2
-
3
- export const getPrimaryKey = (columns) => {
4
- const pkColumn = columns.find(c => c.primary);
5
- if (!pkColumn) throw new Error("Primary key not defined");
6
- return pkColumn.field;
7
- };
8
-
9
- export const attachPrimaryKey = (record, pk, data) => {
10
- const maxId = data.length
11
- ? Math.max(...data.map(row => row[pk] || 0))
12
- : 0;
13
-
14
- return {
15
- ...record,
16
- [pk]: maxId + 1
17
- };
18
- };
@@ -1,20 +0,0 @@
1
- // v3/helpers/validateHelper.js
2
-
3
- export const validateRecord = (record, columns, data) => {
4
- columns.forEach(col => {
5
- const value = record[col.field];
6
-
7
- // required
8
- if (col.required && value === undefined) {
9
- throw new Error(`${col.field} is required`);
10
- }
11
-
12
- // unique
13
- if (col.unique) {
14
- const exists = data.some(row => row[col.field] === value);
15
- if (exists) {
16
- throw new Error(`${col.field} must be unique`);
17
- }
18
- }
19
- });
20
- };
package/src/v3/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { loadConfig, getConfig } from "../core/configStore.js";
2
-
3
- export * from "./data/index.js";
@@ -1,12 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
-
4
- export const getSchema = (table) => {
5
- const config = getConfig();
6
-
7
- const schemaPath = `${config.SchemaPath}/${table}.json`;
8
-
9
- const schema = fs.readFileSync(schemaPath, "utf-8");
10
-
11
- return JSON.parse(schema);
12
- };
@@ -1,16 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const deleteData = ({ table, key, value }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const newData = data.filter(item => item[key] !== value);
12
-
13
- fs.writeFileSync(path, JSON.stringify(newData, null, 2));
14
-
15
- return true;
16
- };
@@ -1,13 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const getData = ({ table }) => {
6
- const cfg = getConfig();
7
-
8
- const path = buildDataPath(cfg, table);
9
-
10
- const data = fs.readFileSync(path, "utf-8");
11
-
12
- return JSON.parse(data);
13
- };
@@ -1,4 +0,0 @@
1
- export { getData } from "./getData.js";
2
- export { insertData } from "./insertData.js";
3
- export { updateData } from "./updateData.js";
4
- export { deleteData } from "./deleteData.js";
@@ -1,47 +0,0 @@
1
- /**
2
- * insertData - Orchestration Flow
3
- *
4
- * 1. Load config & schema
5
- * 2. Resolve primary key + file path
6
- * 3. Read existing data
7
- * 4. Prepare record (allow extra fields, validate only schema fields)
8
- * 5. Validate (required + unique only on schema columns)
9
- * 6. Attach primary key (auto increment)
10
- * 7. Push + persist to file
11
- * 8. Return inserted record
12
- *
13
- * Notes:
14
- * - Extra fields are NOT validated but are stored
15
- * - Schema drives validation, not storage
16
- */
17
- import { getConfig } from "../../core/configStore.js";
18
- import { buildDataPath } from "../../utils/pathBuilder.js";
19
- import { getSchema } from "../config/getSchema.js";
20
-
21
- import { getPrimaryKey, attachPrimaryKey } from "../helpers/pkHelper.js";
22
- import { readData, writeData } from "../helpers/fileHelper.js";
23
- import { validateRecord } from "../helpers/validateHelper.js";
24
- import { normalizeRecord } from "../helpers/recordHelper.js";
25
-
26
- export const insertData = ({ table, record }) => {
27
- const config = getConfig();
28
- const schema = getSchema(table);
29
-
30
- const pk = getPrimaryKey(schema.columns);
31
- const path = buildDataPath(config, table);
32
-
33
- const data = readData(path);
34
-
35
- // const cleanRecord = normalizeRecord(record, schema.columns);
36
- const cleanRecord = { ...record };
37
-
38
- validateRecord(cleanRecord, schema.columns, data);
39
-
40
- const newRecord = attachPrimaryKey(cleanRecord, pk, data);
41
-
42
- data.push(newRecord);
43
-
44
- writeData(path, data);
45
-
46
- return newRecord;
47
- };
@@ -1,20 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const updateData = ({ table, key, value, updates }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const index = data.findIndex(item => item[key] === value);
12
-
13
- if (index === -1) throw new Error("Record not found");
14
-
15
- data[index] = { ...data[index], ...updates };
16
-
17
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
18
-
19
- return data[index];
20
- };
@@ -1,11 +0,0 @@
1
- // v3/helpers/fileHelper.js
2
- import fs from "fs";
3
-
4
- export const readData = (path) => {
5
- if (!fs.existsSync(path)) return [];
6
- return JSON.parse(fs.readFileSync(path, "utf-8"));
7
- };
8
-
9
- export const writeData = (path, data) => {
10
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
11
- };
@@ -1,18 +0,0 @@
1
- // v3/helpers/pkHelper.js
2
-
3
- export const getPrimaryKey = (columns) => {
4
- const pkColumn = columns.find(c => c.primary);
5
- if (!pkColumn) throw new Error("Primary key not defined");
6
- return pkColumn.field;
7
- };
8
-
9
- export const attachPrimaryKey = (record, pk, data) => {
10
- const maxId = data.length
11
- ? Math.max(...data.map(row => row[pk] || 0))
12
- : 0;
13
-
14
- return {
15
- ...record,
16
- [pk]: maxId + 1
17
- };
18
- };
@@ -1,9 +0,0 @@
1
- export const normalizeRecord = (record, columns) => {
2
- const clean = {};
3
- columns.forEach(col => {
4
- if (record[col.field] !== undefined) {
5
- clean[col.field] = record[col.field];
6
- }
7
- });
8
- return clean;
9
- };
@@ -1,15 +0,0 @@
1
- export const validateRecord = (record, columns, data) => {
2
- columns.forEach(col => {
3
- const value = record[col.field];
4
-
5
- if (col.required && (value === undefined || value === "")) {
6
- throw new Error(`${col.field} is required`);
7
- }
8
-
9
- if (value === undefined) return;
10
-
11
- if (col.unique && data.some(r => r[col.field] === value)) {
12
- throw new Error(`${col.field} must be unique`);
13
- }
14
- });
15
- };
package/src/v4/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { loadConfig, getConfig } from "../core/configStore.js";
2
-
3
- export * from "./data/index.js";
@@ -1,12 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
-
4
- export const getSchema = (table) => {
5
- const config = getConfig();
6
-
7
- const schemaPath = `${config.SchemaPath}/${table}.json`;
8
-
9
- const schema = fs.readFileSync(schemaPath, "utf-8");
10
-
11
- return JSON.parse(schema);
12
- };
@@ -1,16 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const deleteData = ({ table, key, value }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- const newData = data.filter(item => item[key] !== value);
12
-
13
- fs.writeFileSync(path, JSON.stringify(newData, null, 2));
14
-
15
- return true;
16
- };
@@ -1,13 +0,0 @@
1
- import fs from "fs";
2
- import { getConfig } from "../../core/configStore.js";
3
- import { buildDataPath } from "../../utils/pathBuilder.js";
4
-
5
- export const getData = ({ table }) => {
6
- const cfg = getConfig();
7
-
8
- const path = buildDataPath(cfg, table);
9
-
10
- const data = fs.readFileSync(path, "utf-8");
11
-
12
- return JSON.parse(data);
13
- };
@@ -1,8 +0,0 @@
1
- export { getData } from "./getData.js";
2
- export { insertData } from "./insertData.js";
3
- export { insertDataStrict } from "./insertDataStrict.js";
4
-
5
- export { updateData } from "./updateData.js";
6
- export { deleteData } from "./deleteData.js";
7
-
8
-
@@ -1,56 +0,0 @@
1
- /**
2
- * insertData - Orchestration Flow
3
- *
4
- * 1. Load config & schema
5
- * 2. Resolve primary key + file path
6
- * 3. Read existing data
7
- * 4. Prepare record (allow extra fields, validate only schema fields)
8
- * 5. Validate (required + unique only on schema columns)
9
- * 6. Attach primary key (auto increment)
10
- * 7. Push + persist to file
11
- * 8. Return inserted record
12
- *
13
- * Notes:
14
- * - Extra fields are NOT validated but are stored
15
- * - Schema drives validation, not storage
16
- */
17
- import { getConfig } from "../../core/configStore.js";
18
- import { buildDataPath } from "../../utils/pathBuilder.js";
19
- import { getSchema } from "../config/getSchema.js";
20
-
21
- import { getPrimaryKey, attachPrimaryKey } from "../helpers/pkHelper.js";
22
- import { readData, writeData } from "../helpers/fileHelper.js";
23
- import { validateRecord } from "../helpers/validateHelper.js";
24
- import { normalizeRecord } from "../helpers/recordHelper.js";
25
-
26
- /**
27
- * Inserts a record into the data store
28
- *
29
- * @param {Object} params
30
- * @param {string} params.table - Table name
31
- * @param {Object} params.record - Record data to insert
32
- *
33
- * @returns {Object} Inserted record with primary key
34
- */
35
- export const insertData = ({ table, record }) => {
36
- const config = getConfig();
37
- const schema = getSchema(table);
38
-
39
- const pk = getPrimaryKey(schema.columns);
40
- const path = buildDataPath(config, table);
41
-
42
- const data = readData(path);
43
-
44
- // const cleanRecord = normalizeRecord(record, schema.columns);
45
- const cleanRecord = { ...record };
46
-
47
- validateRecord(cleanRecord, schema.columns, data);
48
-
49
- const newRecord = attachPrimaryKey(cleanRecord, pk, data);
50
-
51
- data.push(newRecord);
52
-
53
- writeData(path, data);
54
-
55
- return newRecord;
56
- };