@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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* insertDataStrict - Strict Orchestration Flow
|
|
3
|
-
*
|
|
4
|
-
* 1. Load config & schema
|
|
5
|
-
* 2. Resolve primary key + file path
|
|
6
|
-
* 3. Reject manual primary key input
|
|
7
|
-
* 4. Reject extra fields (only schema fields allowed)
|
|
8
|
-
* 5. Read existing data
|
|
9
|
-
* 6. Normalize record (keep only schema fields)
|
|
10
|
-
* 7. Validate (required + unique on schema columns)
|
|
11
|
-
* 8. Attach primary key (auto increment)
|
|
12
|
-
* 9. Push + persist to file
|
|
13
|
-
* 10. Return inserted record
|
|
14
|
-
*
|
|
15
|
-
* Notes:
|
|
16
|
-
* - Only schema-defined fields are allowed
|
|
17
|
-
* - Any extra field will throw an error
|
|
18
|
-
* - Primary key is system-generated only
|
|
19
|
-
*/
|
|
20
|
-
import { getConfig } from "../../core/configStore.js";
|
|
21
|
-
import { buildDataPath } from "../../utils/pathBuilder.js";
|
|
22
|
-
import { getSchema } from "../config/getSchema.js";
|
|
23
|
-
|
|
24
|
-
import { getPrimaryKey, attachPrimaryKey } from "../helpers/pkHelper.js";
|
|
25
|
-
import { readData, writeData } from "../helpers/fileHelper.js";
|
|
26
|
-
import { validateRecord } from "../helpers/validateHelper.js";
|
|
27
|
-
import { normalizeRecord } from "../helpers/recordHelper.js";
|
|
28
|
-
|
|
29
|
-
export const insertDataStrict = ({ table, record }) => {
|
|
30
|
-
try {
|
|
31
|
-
const config = getConfig();
|
|
32
|
-
const schema = getSchema(table);
|
|
33
|
-
|
|
34
|
-
const pk = getPrimaryKey(schema.columns);
|
|
35
|
-
const path = buildDataPath(config, table);
|
|
36
|
-
|
|
37
|
-
const schemaFields = schema.columns.map(c => c.field);
|
|
38
|
-
|
|
39
|
-
if (pk in record) {
|
|
40
|
-
throw new Error(`Primary key '${pk}' should not be provided`);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const extraFields = Object.keys(record).filter(
|
|
44
|
-
key => !schemaFields.includes(key)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
if (extraFields.length) {
|
|
48
|
-
throw new Error(`Invalid fields: ${extraFields.join(", ")}`);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const data = readData(path);
|
|
52
|
-
|
|
53
|
-
const cleanRecord = normalizeRecord(record, schema.columns);
|
|
54
|
-
|
|
55
|
-
validateRecord(cleanRecord, schema.columns, data);
|
|
56
|
-
|
|
57
|
-
const newRecord = attachPrimaryKey(cleanRecord, pk, data);
|
|
58
|
-
|
|
59
|
-
data.push(newRecord);
|
|
60
|
-
|
|
61
|
-
writeData(path, data);
|
|
62
|
-
|
|
63
|
-
return pk;
|
|
64
|
-
} catch (err) {
|
|
65
|
-
return {
|
|
66
|
-
success: false,
|
|
67
|
-
error: {
|
|
68
|
-
message: err.message,
|
|
69
|
-
code: "VALIDATION_ERROR"
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
@@ -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,16 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
export const readData = (path) => {
|
|
4
|
-
if (!fs.existsSync(path)) return [];
|
|
5
|
-
return JSON.parse(fs.readFileSync(path, "utf-8"));
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const writeData = (path, data) => {
|
|
9
|
-
fs.writeFileSync(path, JSON.stringify(data, null, 2));
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const applyFilter = (data, filter) => {
|
|
13
|
-
return data.filter(row =>
|
|
14
|
-
Object.keys(filter).every(key => row[key] === filter[key])
|
|
15
|
-
);
|
|
16
|
-
};
|
|
@@ -1,21 +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
|
-
let maxId = 0;
|
|
11
|
-
|
|
12
|
-
for (const row of data) {
|
|
13
|
-
const val = Number(row[pk]) || 0;
|
|
14
|
-
if (val > maxId) maxId = val;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
...record,
|
|
19
|
-
[pk]: maxId + 1
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,15 +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
|
-
};
|
|
10
|
-
|
|
11
|
-
export const applyFilter = (data, filter) => {
|
|
12
|
-
return data.filter(row =>
|
|
13
|
-
Object.keys(filter).every(key => row[key] === filter[key])
|
|
14
|
-
);
|
|
15
|
-
};
|
|
@@ -1,27 +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 === null || 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
|
-
};
|
|
16
|
-
|
|
17
|
-
export const validateFilterKeys = (filter, columns) => {
|
|
18
|
-
const validColumns = columns.map(col => col.field);
|
|
19
|
-
|
|
20
|
-
const invalidKeys = Object.keys(filter).filter(
|
|
21
|
-
key => !validColumns.includes(key)
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (invalidKeys.length > 0) {
|
|
25
|
-
throw new Error(`Invalid columns: ${invalidKeys.join(", ")}`);
|
|
26
|
-
};
|
|
27
|
-
};
|
package/src/v8/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { loadConfig, getConfig } from "../core/configStore.js";
|
|
2
|
-
import {
|
|
3
|
-
insertData,
|
|
4
|
-
getData,
|
|
5
|
-
updateData,
|
|
6
|
-
deleteData,
|
|
7
|
-
insertDataStrict,
|
|
8
|
-
findByPkData,
|
|
9
|
-
filterByPkData,
|
|
10
|
-
filterByColumnsData,
|
|
11
|
-
deleteByColumnsData
|
|
12
|
-
} from "./data/index.js";
|
|
13
|
-
// Core entry point for kschema operations
|
|
14
|
-
// Exposes config + table-level data APIs
|
|
15
|
-
|
|
16
|
-
export const kschema = {
|
|
17
|
-
loadConfig, // Initialize configuration (must be called first)
|
|
18
|
-
getConfig, // Access current config
|
|
19
|
-
|
|
20
|
-
// Table-scoped operations
|
|
21
|
-
table: (tableName) => ({
|
|
22
|
-
|
|
23
|
-
// Create
|
|
24
|
-
insert: (record) => insertData({ table: tableName, record }),
|
|
25
|
-
insertStrict: (record) => insertDataStrict({ table: tableName, record }),
|
|
26
|
-
|
|
27
|
-
// Read
|
|
28
|
-
get: () => getData({ table: tableName }),
|
|
29
|
-
findByPk: (id) => findByPkData({ table: tableName, id }),
|
|
30
|
-
|
|
31
|
-
// Filter
|
|
32
|
-
filterByPk: (id) => filterByPkData({ table: tableName, id }),
|
|
33
|
-
filterByColumns: (filter) => filterByColumnsData({ table: tableName, filter }),
|
|
34
|
-
|
|
35
|
-
// Update
|
|
36
|
-
update: (record) => updateData({ table: tableName, record }),
|
|
37
|
-
|
|
38
|
-
// Delete
|
|
39
|
-
delete: (id) => deleteData({ table: tableName, id }), // delete single by primary key
|
|
40
|
-
deleteByPk: (id) => deleteData({ table: tableName, id }), // alias for delete
|
|
41
|
-
deleteByColumns: (filter) => deleteByColumnsData({ table: tableName, filter }) // bulk delete by condition
|
|
42
|
-
})
|
|
43
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|