@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.
- package/bin/cli.js +8 -11
- package/bin/cliV1.js +18 -0
- package/bin/v2/commands/init.js +20 -0
- package/bin/v2/commands/template/.vscode/launch.json +12 -0
- package/bin/v2/commands/template/Config/Schemas/LedgerNames.json +50 -0
- package/bin/v2/commands/template/Data/BillsTable.json +165 -0
- package/bin/v2/commands/template/Data/ItemsTable.json +200 -0
- package/bin/v2/commands/template/Data/LedgerNames.json +6 -0
- package/bin/v2/commands/template/Data/StockItems.json +45 -0
- package/bin/v2/commands/template/app.js +4 -0
- package/bin/v2/commands/template/package-lock.json +21 -0
- package/bin/v2/commands/template/package.json +13 -0
- package/bin/v2/commands/template/read.js +8 -0
- package/bin/v2/commands/template/write.js +8 -0
- package/bin/v2/commands/test.js +36 -0
- package/bin/v2/start.js +23 -0
- package/keshavsoft-kschema-cli-1.2.2.tgz +0 -0
- package/package.json +1 -1
- package/src/template/v1/Config/Schemas/BillsTable.json +165 -0
- package/src/template/v1/Config/Schemas/ItemsTable.json +200 -0
- package/src/template/v1/Config/Schemas/StockItems.json +45 -0
- package/src/template/v1/Config/api.json +8 -0
- package/src/template/v1/Config/schema.json +8 -0
- package/src/template/v1/Config/ui.json +8 -0
- package/src/template/v1/config.json +4 -0
- package/template/v1/Config/Schemas/BillsTable.json +165 -0
- package/template/v1/Config/Schemas/ItemsTable.json +200 -0
- package/template/v1/Config/Schemas/LedgerNames.json +45 -0
- package/template/v1/Config/Schemas/StockItems.json +45 -0
- package/template/v1/Config/api.json +8 -0
- package/template/v1/Config/schema.json +8 -0
- package/template/v1/Config/ui.json +8 -0
- package/template/v1/config.json +4 -0
- package/template/v2/Config/Schemas/BillsTable.json +165 -0
- package/template/v2/Config/Schemas/ItemsTable.json +200 -0
- package/template/v2/Config/Schemas/LedgerNames.json +50 -0
- package/template/v2/Config/Schemas/StockItems.json +45 -0
- package/template/v2/Config/api.json +8 -0
- package/template/v2/Config/schema.json +8 -0
- package/template/v2/Config/ui.json +8 -0
- package/template/v2/Data/BillsTable.json +1 -0
- package/template/v2/Data/ItemsTable.json +1 -0
- package/template/v2/Data/LedgerNames.json +6 -0
- package/template/v2/Data/StockItems.json +1 -0
- package/template/v2/config.json +4 -0
- package/template/v2/delete.js +8 -0
- package/template/v2/package.json +15 -0
- package/template/v2/read.js +8 -0
- package/template/v2/write.js +8 -0
- package/index.js +0 -1
- package/src/core/configStore.js +0 -10
- package/src/utils/pathBuilder.js +0 -3
- package/src/v1/data/deleteData.js +0 -16
- package/src/v1/data/getData.js +0 -13
- package/src/v1/data/index.js +0 -4
- package/src/v1/data/insertData.js +0 -16
- package/src/v1/data/updateData.js +0 -20
- package/src/v1/index.js +0 -3
- package/src/v2/config/getSchema.js +0 -12
- package/src/v2/data/deleteData.js +0 -16
- package/src/v2/data/getData.js +0 -13
- package/src/v2/data/index.js +0 -4
- package/src/v2/data/insertData copy.js +0 -46
- package/src/v2/data/insertData.js +0 -52
- package/src/v2/data/updateData.js +0 -20
- package/src/v2/index.js +0 -3
- package/src/v3/config/getSchema.js +0 -12
- package/src/v3/data/deleteData.js +0 -16
- package/src/v3/data/getData.js +0 -13
- package/src/v3/data/index.js +0 -4
- package/src/v3/data/insertData.js +0 -27
- package/src/v3/data/updateData.js +0 -20
- package/src/v3/helpers/fileHelper.js +0 -11
- package/src/v3/helpers/pkHelper.js +0 -18
- package/src/v3/helpers/validateHelper.js +0 -20
- package/src/v3/index.js +0 -3
- package/src/v4/config/getSchema.js +0 -12
- package/src/v4/data/deleteData.js +0 -16
- package/src/v4/data/getData.js +0 -13
- package/src/v4/data/index.js +0 -4
- package/src/v4/data/insertData.js +0 -47
- package/src/v4/data/updateData.js +0 -20
- package/src/v4/helpers/fileHelper.js +0 -11
- package/src/v4/helpers/pkHelper.js +0 -18
- package/src/v4/helpers/recordHelper.js +0 -9
- package/src/v4/helpers/validateHelper.js +0 -15
- package/src/v4/index.js +0 -3
- package/src/v5/config/getSchema.js +0 -12
- package/src/v5/data/deleteData.js +0 -16
- package/src/v5/data/getData.js +0 -13
- package/src/v5/data/index.js +0 -8
- package/src/v5/data/insertData.js +0 -56
- package/src/v5/data/insertDataStrict.js +0 -63
- package/src/v5/data/updateData.js +0 -20
- package/src/v5/helpers/fileHelper.js +0 -11
- package/src/v5/helpers/pkHelper.js +0 -18
- package/src/v5/helpers/recordHelper.js +0 -9
- package/src/v5/helpers/validateHelper.js +0 -15
- package/src/v5/index.js +0 -3
- package/src/v6/config/getSchema.js +0 -12
- package/src/v6/data/deleteData.js +0 -16
- package/src/v6/data/getData.js +0 -13
- package/src/v6/data/index.js +0 -8
- package/src/v6/data/insertData.js +0 -56
- package/src/v6/data/insertDataStrict.js +0 -76
- package/src/v6/data/updateData.js +0 -20
- package/src/v6/helpers/fileHelper.js +0 -11
- package/src/v6/helpers/pkHelper.js +0 -18
- package/src/v6/helpers/recordHelper.js +0 -9
- package/src/v6/helpers/validateHelper.js +0 -15
- package/src/v6/index.js +0 -21
- package/src/v7/config/getSchema.js +0 -12
- package/src/v7/data/deleteData.js +0 -16
- package/src/v7/data/filterByColumns.js +0 -19
- package/src/v7/data/filterByPk.js +0 -16
- package/src/v7/data/findByColumns.js +0 -21
- package/src/v7/data/findByPk.js +0 -16
- package/src/v7/data/getData.js +0 -13
- package/src/v7/data/index.js +0 -11
- package/src/v7/data/insertData.js +0 -55
- package/src/v7/data/insertDataStrict.js +0 -73
- package/src/v7/data/updateData.js +0 -20
- package/src/v7/helpers/fileHelper.js +0 -16
- package/src/v7/helpers/pkHelper.js +0 -21
- package/src/v7/helpers/recordHelper.js +0 -15
- package/src/v7/helpers/validateHelper.js +0 -27
- package/src/v7/index.js +0 -27
- package/src/v8/config/getSchema.js +0 -12
- package/src/v8/data/deleteByColumnsData.js +0 -20
- package/src/v8/data/deleteData.js +0 -22
- package/src/v8/data/filterByColumns.js +0 -19
- package/src/v8/data/filterByPk.js +0 -16
- package/src/v8/data/findByColumns.js +0 -21
- package/src/v8/data/findByPk.js +0 -16
- package/src/v8/data/getData.js +0 -13
- package/src/v8/data/index.js +0 -12
- package/src/v8/data/insertData.js +0 -55
- package/src/v8/data/insertDataStrict.js +0 -73
- package/src/v8/data/updateData.js +0 -20
- package/src/v8/helpers/fileHelper.js +0 -16
- package/src/v8/helpers/pkHelper.js +0 -21
- package/src/v8/helpers/recordHelper.js +0 -15
- package/src/v8/helpers/validateHelper.js +0 -27
- package/src/v8/index.js +0 -43
- /package/{template → bin/v2/commands/template}/Config/Schemas/BillsTable.json +0 -0
- /package/{template → bin/v2/commands/template}/Config/Schemas/ItemsTable.json +0 -0
- /package/{template → bin/v2/commands/template}/Config/Schemas/StockItems.json +0 -0
- /package/{template → bin/v2/commands/template}/Config/api.json +0 -0
- /package/{template → bin/v2/commands/template}/Config/schema.json +0 -0
- /package/{template → bin/v2/commands/template}/Config/ui.json +0 -0
- /package/{template → bin/v2/commands/template}/config.json +0 -0
- /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 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -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 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";
|
package/src/core/configStore.js
DELETED
package/src/utils/pathBuilder.js
DELETED
|
@@ -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
|
-
};
|
package/src/v1/data/getData.js
DELETED
|
@@ -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
|
-
};
|
package/src/v1/data/index.js
DELETED
|
@@ -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,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
|
-
};
|
package/src/v2/data/getData.js
DELETED
|
@@ -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
|
-
};
|
package/src/v2/data/index.js
DELETED
|
@@ -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,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
|
-
};
|
package/src/v3/data/getData.js
DELETED
|
@@ -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
|
-
};
|
package/src/v3/data/index.js
DELETED
|
@@ -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,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
|
-
};
|