@keshavsoft/kschema-cli 1.1.1 → 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.
Files changed (152) hide show
  1. package/bin/cli.js +8 -11
  2. package/bin/cliV1.js +18 -0
  3. package/bin/v2/commands/init.js +20 -0
  4. package/bin/v2/commands/template/.vscode/launch.json +12 -0
  5. package/bin/v2/commands/template/Config/Schemas/LedgerNames.json +50 -0
  6. package/bin/v2/commands/template/Data/BillsTable.json +165 -0
  7. package/bin/v2/commands/template/Data/ItemsTable.json +200 -0
  8. package/bin/v2/commands/template/Data/LedgerNames.json +6 -0
  9. package/bin/v2/commands/template/Data/StockItems.json +45 -0
  10. package/bin/v2/commands/template/app.js +4 -0
  11. package/bin/v2/commands/template/package-lock.json +21 -0
  12. package/bin/v2/commands/template/package.json +13 -0
  13. package/bin/v2/commands/template/read.js +8 -0
  14. package/bin/v2/commands/template/write.js +8 -0
  15. package/bin/v2/commands/test.js +36 -0
  16. package/bin/v2/start.js +23 -0
  17. package/keshavsoft-kschema-cli-1.2.2.tgz +0 -0
  18. package/package.json +1 -1
  19. package/src/template/v1/Config/Schemas/BillsTable.json +165 -0
  20. package/src/template/v1/Config/Schemas/ItemsTable.json +200 -0
  21. package/src/template/v1/Config/Schemas/StockItems.json +45 -0
  22. package/src/template/v1/Config/api.json +8 -0
  23. package/src/template/v1/Config/schema.json +8 -0
  24. package/src/template/v1/Config/ui.json +8 -0
  25. package/src/template/v1/config.json +4 -0
  26. package/template/v1/Config/Schemas/BillsTable.json +165 -0
  27. package/template/v1/Config/Schemas/ItemsTable.json +200 -0
  28. package/template/v1/Config/Schemas/LedgerNames.json +45 -0
  29. package/template/v1/Config/Schemas/StockItems.json +45 -0
  30. package/template/v1/Config/api.json +8 -0
  31. package/template/v1/Config/schema.json +8 -0
  32. package/template/v1/Config/ui.json +8 -0
  33. package/template/v1/config.json +4 -0
  34. package/template/v2/Config/Schemas/BillsTable.json +165 -0
  35. package/template/v2/Config/Schemas/ItemsTable.json +200 -0
  36. package/template/v2/Config/Schemas/LedgerNames.json +50 -0
  37. package/template/v2/Config/Schemas/StockItems.json +45 -0
  38. package/template/v2/Config/api.json +8 -0
  39. package/template/v2/Config/schema.json +8 -0
  40. package/template/v2/Config/ui.json +8 -0
  41. package/template/v2/Data/BillsTable.json +1 -0
  42. package/template/v2/Data/ItemsTable.json +1 -0
  43. package/template/v2/Data/LedgerNames.json +6 -0
  44. package/template/v2/Data/StockItems.json +1 -0
  45. package/template/v2/config.json +4 -0
  46. package/template/v2/delete.js +8 -0
  47. package/template/v2/package.json +15 -0
  48. package/template/v2/read.js +8 -0
  49. package/template/v2/write.js +8 -0
  50. package/index.js +0 -1
  51. package/src/core/configStore.js +0 -10
  52. package/src/utils/pathBuilder.js +0 -3
  53. package/src/v1/data/deleteData.js +0 -16
  54. package/src/v1/data/getData.js +0 -13
  55. package/src/v1/data/index.js +0 -4
  56. package/src/v1/data/insertData.js +0 -16
  57. package/src/v1/data/updateData.js +0 -20
  58. package/src/v1/index.js +0 -3
  59. package/src/v2/config/getSchema.js +0 -12
  60. package/src/v2/data/deleteData.js +0 -16
  61. package/src/v2/data/getData.js +0 -13
  62. package/src/v2/data/index.js +0 -4
  63. package/src/v2/data/insertData copy.js +0 -46
  64. package/src/v2/data/insertData.js +0 -52
  65. package/src/v2/data/updateData.js +0 -20
  66. package/src/v2/index.js +0 -3
  67. package/src/v3/config/getSchema.js +0 -12
  68. package/src/v3/data/deleteData.js +0 -16
  69. package/src/v3/data/getData.js +0 -13
  70. package/src/v3/data/index.js +0 -4
  71. package/src/v3/data/insertData.js +0 -27
  72. package/src/v3/data/updateData.js +0 -20
  73. package/src/v3/helpers/fileHelper.js +0 -11
  74. package/src/v3/helpers/pkHelper.js +0 -18
  75. package/src/v3/helpers/validateHelper.js +0 -20
  76. package/src/v3/index.js +0 -3
  77. package/src/v4/config/getSchema.js +0 -12
  78. package/src/v4/data/deleteData.js +0 -16
  79. package/src/v4/data/getData.js +0 -13
  80. package/src/v4/data/index.js +0 -4
  81. package/src/v4/data/insertData.js +0 -47
  82. package/src/v4/data/updateData.js +0 -20
  83. package/src/v4/helpers/fileHelper.js +0 -11
  84. package/src/v4/helpers/pkHelper.js +0 -18
  85. package/src/v4/helpers/recordHelper.js +0 -9
  86. package/src/v4/helpers/validateHelper.js +0 -15
  87. package/src/v4/index.js +0 -3
  88. package/src/v5/config/getSchema.js +0 -12
  89. package/src/v5/data/deleteData.js +0 -16
  90. package/src/v5/data/getData.js +0 -13
  91. package/src/v5/data/index.js +0 -8
  92. package/src/v5/data/insertData.js +0 -56
  93. package/src/v5/data/insertDataStrict.js +0 -63
  94. package/src/v5/data/updateData.js +0 -20
  95. package/src/v5/helpers/fileHelper.js +0 -11
  96. package/src/v5/helpers/pkHelper.js +0 -18
  97. package/src/v5/helpers/recordHelper.js +0 -9
  98. package/src/v5/helpers/validateHelper.js +0 -15
  99. package/src/v5/index.js +0 -3
  100. package/src/v6/config/getSchema.js +0 -12
  101. package/src/v6/data/deleteData.js +0 -16
  102. package/src/v6/data/getData.js +0 -13
  103. package/src/v6/data/index.js +0 -8
  104. package/src/v6/data/insertData.js +0 -56
  105. package/src/v6/data/insertDataStrict.js +0 -76
  106. package/src/v6/data/updateData.js +0 -20
  107. package/src/v6/helpers/fileHelper.js +0 -11
  108. package/src/v6/helpers/pkHelper.js +0 -18
  109. package/src/v6/helpers/recordHelper.js +0 -9
  110. package/src/v6/helpers/validateHelper.js +0 -15
  111. package/src/v6/index.js +0 -21
  112. package/src/v7/config/getSchema.js +0 -12
  113. package/src/v7/data/deleteData.js +0 -16
  114. package/src/v7/data/filterByColumns.js +0 -19
  115. package/src/v7/data/filterByPk.js +0 -16
  116. package/src/v7/data/findByColumns.js +0 -21
  117. package/src/v7/data/findByPk.js +0 -16
  118. package/src/v7/data/getData.js +0 -13
  119. package/src/v7/data/index.js +0 -11
  120. package/src/v7/data/insertData.js +0 -55
  121. package/src/v7/data/insertDataStrict.js +0 -73
  122. package/src/v7/data/updateData.js +0 -20
  123. package/src/v7/helpers/fileHelper.js +0 -16
  124. package/src/v7/helpers/pkHelper.js +0 -21
  125. package/src/v7/helpers/recordHelper.js +0 -15
  126. package/src/v7/helpers/validateHelper.js +0 -27
  127. package/src/v7/index.js +0 -27
  128. package/src/v8/config/getSchema.js +0 -12
  129. package/src/v8/data/deleteByColumnsData.js +0 -20
  130. package/src/v8/data/deleteData.js +0 -22
  131. package/src/v8/data/filterByColumns.js +0 -19
  132. package/src/v8/data/filterByPk.js +0 -16
  133. package/src/v8/data/findByColumns.js +0 -21
  134. package/src/v8/data/findByPk.js +0 -16
  135. package/src/v8/data/getData.js +0 -13
  136. package/src/v8/data/index.js +0 -12
  137. package/src/v8/data/insertData.js +0 -55
  138. package/src/v8/data/insertDataStrict.js +0 -73
  139. package/src/v8/data/updateData.js +0 -20
  140. package/src/v8/helpers/fileHelper.js +0 -16
  141. package/src/v8/helpers/pkHelper.js +0 -21
  142. package/src/v8/helpers/recordHelper.js +0 -15
  143. package/src/v8/helpers/validateHelper.js +0 -27
  144. package/src/v8/index.js +0 -43
  145. /package/{template → bin/v2/commands/template}/Config/Schemas/BillsTable.json +0 -0
  146. /package/{template → bin/v2/commands/template}/Config/Schemas/ItemsTable.json +0 -0
  147. /package/{template → bin/v2/commands/template}/Config/Schemas/StockItems.json +0 -0
  148. /package/{template → bin/v2/commands/template}/Config/api.json +0 -0
  149. /package/{template → bin/v2/commands/template}/Config/schema.json +0 -0
  150. /package/{template → bin/v2/commands/template}/Config/ui.json +0 -0
  151. /package/{template → bin/v2/commands/template}/config.json +0 -0
  152. /package/{template → src/template/v1}/Config/Schemas/LedgerNames.json +0 -0
@@ -0,0 +1,50 @@
1
+ {
2
+ "tableName": "LedgerNames",
3
+ "columns": [
4
+ {
5
+ "field": "LedgerName",
6
+ "title": "LedgerName",
7
+ "unique": true,
8
+ "type": "text",
9
+ "isInput": true,
10
+ "isAutoFocus": true,
11
+ "defaultvalue": "KeshavSoft",
12
+ "isConsider": true
13
+ },
14
+ {
15
+ "field": "LedgerParentName",
16
+ "title": "LedgerParentName",
17
+ "type": "text",
18
+ "isInput": true,
19
+ "isConsider": true
20
+ },
21
+ {
22
+ "field": "LedgerType",
23
+ "title": "LedgerType",
24
+ "type": "text",
25
+ "isInput": true,
26
+ "isConsider": true
27
+ },
28
+ {
29
+ "field": "pk",
30
+ "title": "pk",
31
+ "primary": true
32
+ }
33
+ ],
34
+ "data": [],
35
+ "Vertical": [],
36
+ "DataTableOptions": {
37
+ "Header": {
38
+ "autoFocus": "LedgerName"
39
+ }
40
+ },
41
+ "NonSecured": {
42
+ "SubRoutes": [
43
+ "ShowAll",
44
+ "Insert",
45
+ "Pipe"
46
+ ]
47
+ },
48
+ "PrimarykeyTableNames": [],
49
+ "PrimarykeyTables": []
50
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "tableName": "StockItems",
3
+ "columns": [
4
+ {
5
+ "field": "StockItemName",
6
+ "title": "StockItemName",
7
+ "unique": true,
8
+ "type": "text",
9
+ "isInput": true,
10
+ "isAutoFocus": true,
11
+ "defaultvalue": "KeshavSoft",
12
+ "isConsider": true
13
+ },
14
+ {
15
+ "field": "StockItemReservedName",
16
+ "title": "StockItemReservedName",
17
+ "type": "text",
18
+ "isInput": true,
19
+ "isConsider": true
20
+ },
21
+ {
22
+ "field": "StockItemType",
23
+ "title": "StockItemType",
24
+ "type": "text",
25
+ "isInput": true,
26
+ "isConsider": true
27
+ }
28
+ ],
29
+ "data": [],
30
+ "Vertical": [],
31
+ "DataTableOptions": {
32
+ "Header": {
33
+ "autoFocus": "StockItemName"
34
+ }
35
+ },
36
+ "NonSecured": {
37
+ "SubRoutes": [
38
+ "ShowAll",
39
+ "Pipe",
40
+ "Insert"
41
+ ]
42
+ },
43
+ "PrimarykeyTableNames": [],
44
+ "PrimarykeyTables": []
45
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Tables": [
3
+ "BillsTable",
4
+ "ItemsTable",
5
+ "LedgerNames",
6
+ "StockItems"
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Tables": [
3
+ "BillsTable",
4
+ "ItemsTable",
5
+ "LedgerNames",
6
+ "StockItems"
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Tables": [
3
+ "BillsTable",
4
+ "ItemsTable",
5
+ "LedgerNames",
6
+ "StockItems"
7
+ ]
8
+ }
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,6 @@
1
+ [
2
+ {
3
+ "LedgerName": "Keshav",
4
+ "pk": 1
5
+ }
6
+ ]
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,4 @@
1
+ {
2
+ "DataPath": "Data",
3
+ "SchemaPath": "Config/Schemas"
4
+ }
@@ -0,0 +1,8 @@
1
+ import configJson from "./config.json" with { type: "json" };
2
+ import { kschema } from "@keshavsoft/kschema";
3
+
4
+ kschema.loadConfig(configJson);
5
+
6
+ const isDeleted = kschema.table("LedgerNames").delete(1);
7
+
8
+ console.log("isDeleted : ", isDeleted);
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "KeshavSoft",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "author": "",
7
+ "type": "module",
8
+ "main": "read.js",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "dependencies": {
13
+ "@keshavsoft/kschema": "^1.7.4"
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ import configJson from "./config.json" with { type: "json" };
2
+ import { kschema } from "@keshavsoft/kschema";
3
+
4
+ kschema.loadConfig(configJson);
5
+
6
+ const data = kschema.table("LedgerNames").get();
7
+
8
+ console.log("get Data : ", data);
@@ -0,0 +1,8 @@
1
+ import configJson from "./config.json" with { type: "json" };
2
+ import { kschema } from "@keshavsoft/kschema";
3
+
4
+ kschema.loadConfig(configJson);
5
+
6
+ const insertedPk = kschema.table("LedgerNames").insert({ LedgerName: "Keshav" });
7
+
8
+ console.log("inserted Pk : ", insertedPk);
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./src/v8/index.js";
@@ -1,10 +0,0 @@
1
- let _config = null;
2
-
3
- export const loadConfig = (config) => {
4
- _config = config;
5
- };
6
-
7
- export const getConfig = () => {
8
- if (!_config) throw new Error("Config not loaded");
9
- return _config;
10
- };
@@ -1,3 +0,0 @@
1
- export const buildDataPath = (cfg, fileName) => {
2
- return `${cfg.DataPath}/${fileName}.json`;
3
- };
@@ -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,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 insertData = ({ table, record }) => {
6
- const cfg = getConfig();
7
- const path = buildDataPath(cfg, table);
8
-
9
- const data = JSON.parse(fs.readFileSync(path));
10
-
11
- data.push(record);
12
-
13
- fs.writeFileSync(path, JSON.stringify(data, null, 2));
14
-
15
- return record;
16
- };
@@ -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/v1/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,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
- };