@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
@@ -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
- };