capitalsix-data-table 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # DataTable
2
2
 
3
- A lightweight, framework-agnostic in-memory data table with fully typed CRUD operations. Use it anywhere you need to manage a collection of objects: plain TypeScript, Node.js, React state handlers, Svelte stores, etc.
3
+ A lightweight, framework-agnostic in-memory data table with fully typed CRUD operations. Use it anywhere you need to manage a collection of objects: plain TypeScript, Node.js, React state handlers, etc.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - **Typed rows** — generic over any object type `T`
8
8
  - **Insert** with optional duplicate-key guard
9
- - **Update** by predicate — via mutation function or replacement object
9
+ - **Update** by predicate — via mutation function, replacement object, or keyed update array
10
10
  - **Upsert** — insert new rows or update existing ones in a single call
11
11
  - **Delete** by predicate, returns deleted rows
12
12
  - **Sort** in-place with a custom comparator
@@ -94,6 +94,8 @@ table.insertRows([{ id: 1, name: 'Alice again', age: 99 }], 'id');
94
94
 
95
95
  Updates all rows matching `predicate` and returns them (already reflecting the changes).
96
96
 
97
+ When `update` is an object or array, `primaryKey` is required.
98
+
97
99
  **Mutation-function style** — receives each matched row and mutates it directly:
98
100
 
99
101
  ```ts
@@ -113,6 +115,20 @@ table.updateRows(
113
115
  );
114
116
  ```
115
117
 
118
+ **Keyed-array style** — for each matched row, finds the update item with the same `primaryKey` and merges it:
119
+
120
+ ```ts
121
+ table.updateRows(
122
+ u => u.id >= 2,
123
+ [
124
+ { id: 2, name: 'Bob Updated', age: 26 },
125
+ { id: 3, name: 'Carol Updated', age: 29 },
126
+ ],
127
+ 'id',
128
+ );
129
+ // matched rows without a corresponding key in the update array are left unchanged
130
+ ```
131
+
116
132
  ---
117
133
 
118
134
  ### `upsertRows(rows: T[], primaryKey: keyof T): DataTableUpsertResult<T>`
package/dist/index.cjs CHANGED
@@ -52,6 +52,13 @@ var DataTable = class {
52
52
  updateFunction = update;
53
53
  } else if (primaryKey === void 0) {
54
54
  throw new Error("Primary key must be provided when update is an object.");
55
+ } else if (Array.isArray(update)) {
56
+ updateFunction = (updateRow) => {
57
+ const target = update.find((r) => r[primaryKey] === updateRow[primaryKey]);
58
+ if (target) {
59
+ Object.assign(updateRow, target);
60
+ }
61
+ };
55
62
  } else {
56
63
  updateFunction = (updateRow) => {
57
64
  Object.assign(updateRow, { ...update, [primaryKey]: updateRow[primaryKey] });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/DataTable.ts"],"sourcesContent":["export { DataTable, type IDataTable } from './DataTable';\n","/**\r\n * Minimal initializer contract for replacing all rows in the table.\r\n */\r\nexport interface IDataTableInitial<T extends object> {\r\n /**\r\n * Replaces all current rows with the provided rows.\r\n */\r\n setRows: (rows: T[]) => void;\r\n}\r\n\r\n/**\r\n * Result of an upsert operation.\r\n * `inserted` contains rows that did not exist yet.\r\n * `updated` contains rows that matched an existing primary key.\r\n */\r\nexport interface DataTableUpsertResult<T extends object> {\r\n inserted: T[];\r\n updated: T[];\r\n}\r\n\r\n/**\r\n * Table-like CRUD and query operations for in-memory rows.\r\n */\r\nexport interface IDataTable<T extends object> {\r\n /**\r\n * Returns all rows, or only rows matching the predicate when provided.\r\n */\r\n getRows: (predicate?: (row: T) => boolean) => T[];\r\n\r\n /**\r\n * Appends rows to the table.\r\n * When `primaryKey` is provided, the method validates that no incoming key\r\n * already exists in the current table.\r\n */\r\n insertRows: (rows: T[], primaryKey?: keyof T) => void;\r\n\r\n /**\r\n * Updates all rows that match `predicate`.\r\n *\r\n * - When `update` is a function, the function mutates each matched row.\r\n * - When `update` is an object, `primaryKey` is required and preserved on each row.\r\n *\r\n * Returns the matched rows by reference (already reflecting any applied mutations).\r\n */\r\n updateRows: (\r\n predicate: (row: T) => boolean,\r\n update: T | ((updateRow: T) => void),\r\n primaryKey?: keyof T) => T[];\r\n\r\n /**\r\n * Upserts rows by `primaryKey`.\r\n *\r\n * - If a matching key exists, the existing row is updated in place.\r\n * - If no matching key exists, the row is inserted.\r\n *\r\n * Returns a `DataTableUpsertResult` where:\r\n * - `updated` contains the incoming rows that matched existing keys.\r\n * - `inserted` contains the incoming rows that were newly added.\r\n */\r\n upsertRows: (rows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;\r\n\r\n /**\r\n * Deletes matching rows and returns the deleted rows.\r\n */\r\n deleteRows: (predicate: (row: T) => boolean) => T[];\r\n \r\n /**\r\n * Sorts rows in place with the provided compare function.\r\n */\r\n sortRows: (compareFn: (a: T, b: T) => number) => void;\r\n}\r\n\r\n/**\r\n * Generic in-memory data table with mutable row operations.\r\n */\r\nexport class DataTable<T extends object> implements IDataTable<T>, IDataTableInitial<T> {\r\n private rows: T[] = [];\r\n\r\n public constructor(initialRows: T[] = []) {\r\n this.rows = initialRows;\r\n }\r\n\r\n public getRows = (predicate?: (row: T) => boolean): T[] => {\r\n return predicate ? this.rows.filter(predicate) : this.rows;\r\n };\r\n\r\n public setRows = (newRows: T[]): void => {\r\n this.rows.length = 0;\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public insertRows = (newRows: T[], primaryKey?: keyof T): void => {\r\n if (primaryKey) {\r\n // Reject insert when any incoming row key already exists in the current table.\r\n if (this.rows.some(row => newRows.findIndex(r => r[primaryKey] === row[primaryKey]) !== -1))\r\n {\r\n throw new Error(\r\n `Duplicate primary key value found in existing rows for key: ${String(primaryKey)}`);\r\n }\r\n }\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public updateRows = (\r\n predicate: (row: T) => boolean,\r\n update: T | ((updateRow: T) => void),\r\n primaryKey?: keyof T): T[] => {\r\n // Keep references to matched rows; these objects are mutated in place below.\r\n const updatedRows: T[] = this.rows.filter(predicate);\r\n\r\n let updateFunction: (updateRow: T) => void;\r\n if (typeof update === 'function') {\r\n updateFunction = update as (updateRow: T) => void;\r\n } else if (primaryKey === undefined) {\r\n throw new Error('Primary key must be provided when update is an object.');\r\n } else {\r\n // Preserve the original primary key when doing object-style updates.\r\n updateFunction = (updateRow: T): void => {\r\n Object.assign(updateRow, { ...update, [primaryKey!]: updateRow[primaryKey!] });\r\n };\r\n }\r\n\r\n for (let i = 0; i < this.rows.length; i++) {\r\n if (predicate(this.rows[i])) {\r\n updateFunction(this.rows[i]);\r\n }\r\n }\r\n\r\n return updatedRows;\r\n };\r\n\r\n public upsertRows = (newRows: T[], primaryKey: keyof T): DataTableUpsertResult<T> => {\r\n const result: DataTableUpsertResult<T> = { inserted: [], updated: [] };\r\n // Index existing rows by primary key for efficient upsert lookup.\r\n const existingRowsMap = new Map(this.rows.map(row => [ row[primaryKey], row ]));\r\n for (const newRow of newRows) {\r\n const key = newRow[primaryKey];\r\n if (existingRowsMap.has(key)) {\r\n Object.assign(existingRowsMap.get(key)!, newRow);\r\n result.updated.push(newRow);\r\n } else {\r\n this.rows.push(newRow);\r\n result.inserted.push(newRow);\r\n }\r\n }\r\n return result;\r\n };\r\n\r\n public deleteRows = (predicate: (row: T) => boolean): T[] => {\r\n const deletedRows = this.rows.filter(predicate);\r\n\r\n // Iterate backwards to safely remove items from the same array.\r\n for (let i = this.rows.length - 1; i >= 0; i--) {\r\n if (predicate(this.rows[i])) {\r\n this.rows.splice(i, 1);\r\n }\r\n }\r\n\r\n return deletedRows;\r\n };\r\n\r\n public sortRows = (compareFn: (a: T, b: T) => number): void => {\r\n this.rows.sort(compareFn);\r\n };\r\n}\r\n\r\nexport default DataTable;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2EO,IAAM,YAAN,MAAiF;AAAA,EAG/E,YAAY,cAAmB,CAAC,GAAG;AAF1C,SAAQ,OAAY,CAAC;AAMrB,SAAO,UAAU,CAAC,cAAyC;AACzD,aAAO,YAAY,KAAK,KAAK,OAAO,SAAS,IAAI,KAAK;AAAA,IACxD;AAEA,SAAO,UAAU,CAAC,YAAuB;AACvC,WAAK,KAAK,SAAS;AACnB,WAAK,KAAK,KAAK,GA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C,iBAAO,QAAQ,KAAK,MAAM;AAAA,QAC5B,OAAO;AACL,eAAK,KAAK,KAAK,MAAM;AACrB,iBAAO,SAAS,KAAK,MAAM;AAAA,QAC7B;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,SAAO,aAAa,CAAC,cAAwC;AAC3D,YAAM,cAAc,KAAK,KAAK,OAAO,SAAS;AAG9C,eAAS,IAAI,KAAK,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK;AAC9C,YAAI,UAAU,KAAK,KAAK,CAAC,CAAC,GAAG;AAC3B,eAAK,KAAK,OAAO,GAAG,CAAC;AAAA,QACvB;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAEA,SAAO,WAAW,CAAC,cAA4C;AAC7D,WAAK,KAAK,KAAK,SAAS;AAAA,IAC1B;AApFE,SAAK,OAAO;AAAA,EACd;AAoFF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/DataTable.ts"],"sourcesContent":["export { DataTable, type IDataTable } from './DataTable';\n","/**\r\n * Minimal initializer contract for replacing all rows in the table.\r\n */\r\nexport interface IDataTableInitial<T extends object> {\r\n /**\r\n * Replaces all current rows with the provided rows.\r\n */\r\n setRows: (rows: T[]) => void;\r\n}\r\n\r\n/**\r\n * Result of an upsert operation.\r\n * `inserted` contains rows that did not exist yet.\r\n * `updated` contains rows that matched an existing primary key.\r\n */\r\nexport interface IDataTableUpsertResult<T extends object> {\r\n inserted: T[];\r\n updated: T[];\r\n}\r\n\r\n/**\r\n * Table-like CRUD and query operations for in-memory rows.\r\n */\r\nexport interface IDataTable<T extends object> {\r\n /**\r\n * Returns all rows, or only rows matching the predicate when provided.\r\n */\r\n getRows: (predicate?: (row: T) => boolean) => T[];\r\n\r\n /**\r\n * Appends rows to the table.\r\n * When `primaryKey` is provided, the method validates that no incoming key\r\n * already exists in the current table.\r\n */\r\n insertRows: (rows: T[], primaryKey?: keyof T) => void;\r\n\r\n /**\r\n * Updates all rows that match `predicate`.\r\n *\r\n * - When `update` is a function, the function mutates each matched row.\r\n * - When `update` is an object, `primaryKey` is required and preserved on each row.\r\n *\r\n * Returns the matched rows by reference (already reflecting any applied mutations).\r\n */\r\n updateRows: (\r\n predicate: (row: T) => boolean,\r\n update: T | T[] | ((updateRow: T) => void),\r\n primaryKey?: keyof T) => T[];\r\n\r\n /**\r\n * Upserts rows by `primaryKey`.\r\n *\r\n * - If a matching key exists, the existing row is updated in place.\r\n * - If no matching key exists, the row is inserted.\r\n *\r\n * Returns a `IDataTableUpsertResult` where:\r\n * - `updated` contains the incoming rows that matched existing keys.\r\n * - `inserted` contains the incoming rows that were newly added.\r\n */\r\n upsertRows: (rows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;\r\n\r\n /**\r\n * Deletes matching rows and returns the deleted rows.\r\n */\r\n deleteRows: (predicate: (row: T) => boolean) => T[];\r\n \r\n /**\r\n * Sorts rows in place with the provided compare function.\r\n */\r\n sortRows: (compareFn: (a: T, b: T) => number) => void;\r\n}\r\n\r\n/**\r\n * Generic in-memory data table with mutable row operations.\r\n */\r\nexport class DataTable<T extends object> implements IDataTable<T>, IDataTableInitial<T> {\r\n private rows: T[] = [];\r\n\r\n public constructor(initialRows: T[] = []) {\r\n this.rows = initialRows;\r\n }\r\n\r\n public getRows = (predicate?: (row: T) => boolean): T[] => {\r\n return predicate ? this.rows.filter(predicate) : this.rows;\r\n };\r\n\r\n public setRows = (newRows: T[]): void => {\r\n this.rows.length = 0;\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public insertRows = (newRows: T[], primaryKey?: keyof T): void => {\r\n if (primaryKey) {\r\n // Reject insert when any incoming row key already exists in the current table.\r\n if (this.rows.some(row => newRows.findIndex(r => r[primaryKey] === row[primaryKey]) !== -1))\r\n {\r\n throw new Error(\r\n `Duplicate primary key value found in existing rows for key: ${String(primaryKey)}`);\r\n }\r\n }\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public updateRows = (\r\n predicate: (row: T) => boolean,\r\n update: T | T[] |((updateRow: T) => void),\r\n primaryKey?: keyof T): T[] => {\r\n // Keep references to matched rows; these objects are mutated in place below.\r\n const updatedRows: T[] = this.rows.filter(predicate);\r\n\r\n let updateFunction: (updateRow: T) => void;\r\n if (typeof update === 'function') {\r\n updateFunction = update as (updateRow: T) => void;\r\n } else if (primaryKey === undefined) {\r\n throw new Error('Primary key must be provided when update is an object.');\r\n } else if (Array.isArray(update)) {\r\n updateFunction = (updateRow: T): void => {\r\n const target = update.find(r => r[primaryKey!] === updateRow[primaryKey!]);\r\n if (target) {\r\n Object.assign(updateRow, target);\r\n }\r\n };\r\n } else {\r\n // Preserve the original primary key when doing object-style updates.\r\n updateFunction = (updateRow: T): void => {\r\n Object.assign(updateRow, { ...update, [primaryKey!]: updateRow[primaryKey!] });\r\n };\r\n }\r\n\r\n for (let i = 0; i < this.rows.length; i++) {\r\n if (predicate(this.rows[i])) {\r\n updateFunction(this.rows[i]);\r\n }\r\n }\r\n\r\n return updatedRows;\r\n };\r\n\r\n public upsertRows = (newRows: T[], primaryKey: keyof T): IDataTableUpsertResult<T> => {\r\n const result: IDataTableUpsertResult<T> = { inserted: [], updated: [] };\r\n // Index existing rows by primary key for efficient upsert lookup.\r\n const existingRowsMap = new Map(this.rows.map(row => [ row[primaryKey], row ]));\r\n for (const newRow of newRows) {\r\n const key = newRow[primaryKey];\r\n if (existingRowsMap.has(key)) {\r\n Object.assign(existingRowsMap.get(key)!, newRow);\r\n result.updated.push(newRow);\r\n } else {\r\n this.rows.push(newRow);\r\n result.inserted.push(newRow);\r\n }\r\n }\r\n return result;\r\n };\r\n\r\n public deleteRows = (predicate: (row: T) => boolean): T[] => {\r\n const deletedRows = this.rows.filter(predicate);\r\n\r\n // Iterate backwards to safely remove items from the same array.\r\n for (let i = this.rows.length - 1; i >= 0; i--) {\r\n if (predicate(this.rows[i])) {\r\n this.rows.splice(i, 1);\r\n }\r\n }\r\n\r\n return deletedRows;\r\n };\r\n\r\n public sortRows = (compareFn: (a: T, b: T) => number): void => {\r\n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exist yet.
13
13
  * `updated` contains rows that matched an existing primary key.
14
14
  */
15
- interface DataTableUpsertResult<T extends object> {
15
+ interface IDataTableUpsertResult<T extends object> {
16
16
  inserted: T[];
17
17
  updated: T[];
18
18
  }
@@ -38,18 +38,18 @@ interface IDataTable<T extends object> {
38
38
  *
39
39
  * Returns the matched rows by reference (already reflecting any applied mutations).
40
40
  */
41
- updateRows: (predicate: (row: T) => boolean, update: T | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
41
+ updateRows: (predicate: (row: T) => boolean, update: T | T[] | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
42
42
  /**
43
43
  * Upserts rows by `primaryKey`.
44
44
  *
45
45
  * - If a matching key exists, the existing row is updated in place.
46
46
  * - If no matching key exists, the row is inserted.
47
47
  *
48
- * Returns a `DataTableUpsertResult` where:
48
+ * Returns a `IDataTableUpsertResult` where:
49
49
  * - `updated` contains the incoming rows that matched existing keys.
50
50
  * - `inserted` contains the incoming rows that were newly added.
51
51
  */
52
- upsertRows: (rows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;
52
+ upsertRows: (rows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;
53
53
  /**
54
54
  * Deletes matching rows and returns the deleted rows.
55
55
  */
@@ -68,8 +68,8 @@ declare class DataTable<T extends object> implements IDataTable<T>, IDataTableIn
68
68
  getRows: (predicate?: (row: T) => boolean) => T[];
69
69
  setRows: (newRows: T[]) => void;
70
70
  insertRows: (newRows: T[], primaryKey?: keyof T) => void;
71
- updateRows: (predicate: (row: T) => boolean, update: T | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
72
- upsertRows: (newRows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;
71
+ updateRows: (predicate: (row: T) => boolean, update: T | T[] | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
72
+ upsertRows: (newRows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;
73
73
  deleteRows: (predicate: (row: T) => boolean) => T[];
74
74
  sortRows: (compareFn: (a: T, b: T) => number) => void;
75
75
  }
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ interface IDataTableInitial<T extends object> {
12
12
  * `inserted` contains rows that did not exist yet.
13
13
  * `updated` contains rows that matched an existing primary key.
14
14
  */
15
- interface DataTableUpsertResult<T extends object> {
15
+ interface IDataTableUpsertResult<T extends object> {
16
16
  inserted: T[];
17
17
  updated: T[];
18
18
  }
@@ -38,18 +38,18 @@ interface IDataTable<T extends object> {
38
38
  *
39
39
  * Returns the matched rows by reference (already reflecting any applied mutations).
40
40
  */
41
- updateRows: (predicate: (row: T) => boolean, update: T | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
41
+ updateRows: (predicate: (row: T) => boolean, update: T | T[] | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
42
42
  /**
43
43
  * Upserts rows by `primaryKey`.
44
44
  *
45
45
  * - If a matching key exists, the existing row is updated in place.
46
46
  * - If no matching key exists, the row is inserted.
47
47
  *
48
- * Returns a `DataTableUpsertResult` where:
48
+ * Returns a `IDataTableUpsertResult` where:
49
49
  * - `updated` contains the incoming rows that matched existing keys.
50
50
  * - `inserted` contains the incoming rows that were newly added.
51
51
  */
52
- upsertRows: (rows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;
52
+ upsertRows: (rows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;
53
53
  /**
54
54
  * Deletes matching rows and returns the deleted rows.
55
55
  */
@@ -68,8 +68,8 @@ declare class DataTable<T extends object> implements IDataTable<T>, IDataTableIn
68
68
  getRows: (predicate?: (row: T) => boolean) => T[];
69
69
  setRows: (newRows: T[]) => void;
70
70
  insertRows: (newRows: T[], primaryKey?: keyof T) => void;
71
- updateRows: (predicate: (row: T) => boolean, update: T | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
72
- upsertRows: (newRows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;
71
+ updateRows: (predicate: (row: T) => boolean, update: T | T[] | ((updateRow: T) => void), primaryKey?: keyof T) => T[];
72
+ upsertRows: (newRows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;
73
73
  deleteRows: (predicate: (row: T) => boolean) => T[];
74
74
  sortRows: (compareFn: (a: T, b: T) => number) => void;
75
75
  }
package/dist/index.js CHANGED
@@ -26,6 +26,13 @@ var DataTable = class {
26
26
  updateFunction = update;
27
27
  } else if (primaryKey === void 0) {
28
28
  throw new Error("Primary key must be provided when update is an object.");
29
+ } else if (Array.isArray(update)) {
30
+ updateFunction = (updateRow) => {
31
+ const target = update.find((r) => r[primaryKey] === updateRow[primaryKey]);
32
+ if (target) {
33
+ Object.assign(updateRow, target);
34
+ }
35
+ };
29
36
  } else {
30
37
  updateFunction = (updateRow) => {
31
38
  Object.assign(updateRow, { ...update, [primaryKey]: updateRow[primaryKey] });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/DataTable.ts"],"sourcesContent":["/**\r\n * Minimal initializer contract for replacing all rows in the table.\r\n */\r\nexport interface IDataTableInitial<T extends object> {\r\n /**\r\n * Replaces all current rows with the provided rows.\r\n */\r\n setRows: (rows: T[]) => void;\r\n}\r\n\r\n/**\r\n * Result of an upsert operation.\r\n * `inserted` contains rows that did not exist yet.\r\n * `updated` contains rows that matched an existing primary key.\r\n */\r\nexport interface DataTableUpsertResult<T extends object> {\r\n inserted: T[];\r\n updated: T[];\r\n}\r\n\r\n/**\r\n * Table-like CRUD and query operations for in-memory rows.\r\n */\r\nexport interface IDataTable<T extends object> {\r\n /**\r\n * Returns all rows, or only rows matching the predicate when provided.\r\n */\r\n getRows: (predicate?: (row: T) => boolean) => T[];\r\n\r\n /**\r\n * Appends rows to the table.\r\n * When `primaryKey` is provided, the method validates that no incoming key\r\n * already exists in the current table.\r\n */\r\n insertRows: (rows: T[], primaryKey?: keyof T) => void;\r\n\r\n /**\r\n * Updates all rows that match `predicate`.\r\n *\r\n * - When `update` is a function, the function mutates each matched row.\r\n * - When `update` is an object, `primaryKey` is required and preserved on each row.\r\n *\r\n * Returns the matched rows by reference (already reflecting any applied mutations).\r\n */\r\n updateRows: (\r\n predicate: (row: T) => boolean,\r\n update: T | ((updateRow: T) => void),\r\n primaryKey?: keyof T) => T[];\r\n\r\n /**\r\n * Upserts rows by `primaryKey`.\r\n *\r\n * - If a matching key exists, the existing row is updated in place.\r\n * - If no matching key exists, the row is inserted.\r\n *\r\n * Returns a `DataTableUpsertResult` where:\r\n * - `updated` contains the incoming rows that matched existing keys.\r\n * - `inserted` contains the incoming rows that were newly added.\r\n */\r\n upsertRows: (rows: T[], primaryKey: keyof T) => DataTableUpsertResult<T>;\r\n\r\n /**\r\n * Deletes matching rows and returns the deleted rows.\r\n */\r\n deleteRows: (predicate: (row: T) => boolean) => T[];\r\n \r\n /**\r\n * Sorts rows in place with the provided compare function.\r\n */\r\n sortRows: (compareFn: (a: T, b: T) => number) => void;\r\n}\r\n\r\n/**\r\n * Generic in-memory data table with mutable row operations.\r\n */\r\nexport class DataTable<T extends object> implements IDataTable<T>, IDataTableInitial<T> {\r\n private rows: T[] = [];\r\n\r\n public constructor(initialRows: T[] = []) {\r\n this.rows = initialRows;\r\n }\r\n\r\n public getRows = (predicate?: (row: T) => boolean): T[] => {\r\n return predicate ? this.rows.filter(predicate) : this.rows;\r\n };\r\n\r\n public setRows = (newRows: T[]): void => {\r\n this.rows.length = 0;\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public insertRows = (newRows: T[], primaryKey?: keyof T): void => {\r\n if (primaryKey) {\r\n // Reject insert when any incoming row key already exists in the current table.\r\n if (this.rows.some(row => newRows.findIndex(r => r[primaryKey] === row[primaryKey]) !== -1))\r\n {\r\n throw new Error(\r\n `Duplicate primary key value found in existing rows for key: ${String(primaryKey)}`);\r\n }\r\n }\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public updateRows = (\r\n predicate: (row: T) => boolean,\r\n update: T | ((updateRow: T) => void),\r\n primaryKey?: keyof T): T[] => {\r\n // Keep references to matched rows; these objects are mutated in place below.\r\n const updatedRows: T[] = this.rows.filter(predicate);\r\n\r\n let updateFunction: (updateRow: T) => void;\r\n if (typeof update === 'function') {\r\n updateFunction = update as (updateRow: T) => void;\r\n } else if (primaryKey === undefined) {\r\n throw new Error('Primary key must be provided when update is an object.');\r\n } else {\r\n // Preserve the original primary key when doing object-style updates.\r\n updateFunction = (updateRow: T): void => {\r\n Object.assign(updateRow, { ...update, [primaryKey!]: updateRow[primaryKey!] });\r\n };\r\n }\r\n\r\n for (let i = 0; i < this.rows.length; i++) {\r\n if (predicate(this.rows[i])) {\r\n updateFunction(this.rows[i]);\r\n }\r\n }\r\n\r\n return updatedRows;\r\n };\r\n\r\n public upsertRows = (newRows: T[], primaryKey: keyof T): DataTableUpsertResult<T> => {\r\n const result: DataTableUpsertResult<T> = { inserted: [], updated: [] };\r\n // Index existing rows by primary key for efficient upsert lookup.\r\n const existingRowsMap = new Map(this.rows.map(row => [ row[primaryKey], row ]));\r\n for (const newRow of newRows) {\r\n const key = newRow[primaryKey];\r\n if (existingRowsMap.has(key)) {\r\n Object.assign(existingRowsMap.get(key)!, newRow);\r\n result.updated.push(newRow);\r\n } else {\r\n this.rows.push(newRow);\r\n result.inserted.push(newRow);\r\n }\r\n }\r\n return result;\r\n };\r\n\r\n public deleteRows = (predicate: (row: T) => boolean): T[] => {\r\n const deletedRows = this.rows.filter(predicate);\r\n\r\n // Iterate backwards to safely remove items from the same array.\r\n for (let i = this.rows.length - 1; i >= 0; i--) {\r\n if (predicate(this.rows[i])) {\r\n this.rows.splice(i, 1);\r\n }\r\n }\r\n\r\n return deletedRows;\r\n };\r\n\r\n public sortRows = (compareFn: (a: T, b: T) => number): void => {\r\n this.rows.sort(compareFn);\r\n };\r\n}\r\n\r\nexport default DataTable;\r\n"],"mappings":";AA2EO,IAAM,YAAN,MAAiF;AAAA,EAG/E,YAAY,cAAmB,CAAC,GAAG;AAF1C,SAAQ,OAAY,CAAC;AAMrB,SAAO,UAAU,CAAC,cAAyC;AACzD,aAAO,YA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AAS;AAC5B,cAAM,MAAM,OAAO,UAAU;AAC7B,YAAI,gBAAgB,IAAI,GAAG,GAAG;AAC5B,iBAAO,OAAO,gBAAgB,IAAI,GAAG,GAAI,MAAM;AAC/C,iBAAO,QAAQ,KAAK,MAAM;AAAA,QAC5B,OAAO;AACL,eAAK,KAAK,KAAK,MAAM;AACrB,iBAAO,SAAS,KAAK,MAAM;AAAA,QAC7B;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,SAAO,aAAa,CAAC,cAAwC;AAC3D,YAAM,cAAc,KAAK,KAAK,OAAO,SAAS;AAG9C,eAAS,IAAI,KAAK,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK;AAC9C,YAAI,UAAU,KAAK,KAAK,CAAC,CAAC,GAAG;AAC3B,eAAK,KAAK,OAAO,GAAG,CAAC;AAAA,QACvB;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAEA,SAAO,WAAW,CAAC,cAA4C;AAC7D,WAAK,KAAK,KAAK,SAAS;AAAA,IAC1B;AApFE,SAAK,OAAO;AAAA,EACd;AAoFF;","names":[]}
1
+ {"version":3,"sources":["../src/DataTable.ts"],"sourcesContent":["/**\r\n * Minimal initializer contract for replacing all rows in the table.\r\n */\r\nexport interface IDataTableInitial<T extends object> {\r\n /**\r\n * Replaces all current rows with the provided rows.\r\n */\r\n setRows: (rows: T[]) => void;\r\n}\r\n\r\n/**\r\n * Result of an upsert operation.\r\n * `inserted` contains rows that did not exist yet.\r\n * `updated` contains rows that matched an existing primary key.\r\n */\r\nexport interface IDataTableUpsertResult<T extends object> {\r\n inserted: T[];\r\n updated: T[];\r\n}\r\n\r\n/**\r\n * Table-like CRUD and query operations for in-memory rows.\r\n */\r\nexport interface IDataTable<T extends object> {\r\n /**\r\n * Returns all rows, or only rows matching the predicate when provided.\r\n */\r\n getRows: (predicate?: (row: T) => boolean) => T[];\r\n\r\n /**\r\n * Appends rows to the table.\r\n * When `primaryKey` is provided, the method validates that no incoming key\r\n * already exists in the current table.\r\n */\r\n insertRows: (rows: T[], primaryKey?: keyof T) => void;\r\n\r\n /**\r\n * Updates all rows that match `predicate`.\r\n *\r\n * - When `update` is a function, the function mutates each matched row.\r\n * - When `update` is an object, `primaryKey` is required and preserved on each row.\r\n *\r\n * Returns the matched rows by reference (already reflecting any applied mutations).\r\n */\r\n updateRows: (\r\n predicate: (row: T) => boolean,\r\n update: T | T[] | ((updateRow: T) => void),\r\n primaryKey?: keyof T) => T[];\r\n\r\n /**\r\n * Upserts rows by `primaryKey`.\r\n *\r\n * - If a matching key exists, the existing row is updated in place.\r\n * - If no matching key exists, the row is inserted.\r\n *\r\n * Returns a `IDataTableUpsertResult` where:\r\n * - `updated` contains the incoming rows that matched existing keys.\r\n * - `inserted` contains the incoming rows that were newly added.\r\n */\r\n upsertRows: (rows: T[], primaryKey: keyof T) => IDataTableUpsertResult<T>;\r\n\r\n /**\r\n * Deletes matching rows and returns the deleted rows.\r\n */\r\n deleteRows: (predicate: (row: T) => boolean) => T[];\r\n \r\n /**\r\n * Sorts rows in place with the provided compare function.\r\n */\r\n sortRows: (compareFn: (a: T, b: T) => number) => void;\r\n}\r\n\r\n/**\r\n * Generic in-memory data table with mutable row operations.\r\n */\r\nexport class DataTable<T extends object> implements IDataTable<T>, IDataTableInitial<T> {\r\n private rows: T[] = [];\r\n\r\n public constructor(initialRows: T[] = []) {\r\n this.rows = initialRows;\r\n }\r\n\r\n public getRows = (predicate?: (row: T) => boolean): T[] => {\r\n return predicate ? this.rows.filter(predicate) : this.rows;\r\n };\r\n\r\n public setRows = (newRows: T[]): void => {\r\n this.rows.length = 0;\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public insertRows = (newRows: T[], primaryKey?: keyof T): void => {\r\n if (primaryKey) {\r\n // Reject insert when any incoming row key already exists in the current table.\r\n if (this.rows.some(row => newRows.findIndex(r => r[primaryKey] === row[primaryKey]) !== -1))\r\n {\r\n throw new Error(\r\n `Duplicate primary key value found in existing rows for key: ${String(primaryKey)}`);\r\n }\r\n }\r\n this.rows.push(...newRows);\r\n };\r\n\r\n public updateRows = (\r\n predicate: (row: T) => boolean,\r\n update: T | T[] |((updateRow: T) => void),\r\n primaryKey?: keyof T): T[] => {\r\n // Keep references to matched rows; these objects are mutated in place below.\r\n const updatedRows: T[] = this.rows.filter(predicate);\r\n\r\n let updateFunction: (updateRow: T) => void;\r\n if (typeof update === 'function') {\r\n updateFunction = update as (updateRow: T) => void;\r\n } else if (primaryKey === undefined) {\r\n throw new Error('Primary key must be provided when update is an object.');\r\n } else if (Array.isArray(update)) {\r\n updateFunction = (updateRow: T): void => {\r\n const target = update.find(r => r[primaryKey!] === updateRow[primaryKey!]);\r\n if (target) {\r\n Object.assign(updateRow, target);\r\n }\r\n };\r\n } else {\r\n // Preserve the original primary key when doing object-style updates.\r\n updateFunction = (updateRow: T): void => {\r\n Object.assign(updateRow, { ...update, [primaryKey!]: updateRow[primaryKey!] });\r\n };\r\n }\r\n\r\n for (let i = 0; i < this.rows.length; i++) {\r\n if (predicate(this.rows[i])) {\r\n updateFunction(this.rows[i]);\r\n }\r\n }\r\n\r\n return updatedRows;\r\n };\r\n\r\n public upsertRows = (newRows: T[], primaryKey: keyof T): IDataTableUpsertResult<T> => {\r\n const result: IDataTableUpsertResult<T> = { inserted: [], updated: [] };\r\n // Index existing rows by primary key for efficient upsert lookup.\r\n const existingRowsMap = new Map(this.rows.map(row => [ row[primaryKey], row ]));\r\n for (const newRow of newRows) {\r\n const key = newRow[primaryKey];\r\n if (existingRowsMap.has(key)) {\r\n Object.assign(existingRowsMap.get(key)!, newRow);\r\n result.updated.push(newRow);\r\n } else {\r\n this.rows.push(newRow);\r\n result.inserted.push(newRow);\r\n }\r\n }\r\n return result;\r\n };\r\n\r\n public deleteRows = (predicate: (row: T) => boolean): T[] => {\r\n const deletedRows = this.rows.filter(predicate);\r\n\r\n // Iterate backwards to safely remove items from the same array.\r\n for (let i = this.rows.length - 1; i >= 0; i--) {\r\n if (predicate(this.rows[i])) {\r\n this.rows.splice(i, 1);\r\n }\r\n }\r\n\r\n return deletedRows;\r\n };\r\n\r\n public sortRows = (compareFn: (a: T, b: T) => number): void => {\r\n this.rows.sort(compareFn);\r\n };\r\n}\r\n\r\nexport default DataTable;\r\n"],"mappings":";AA2EO,IAAM,YAAN,MAAiF;AAAA,EAG/E,YAAY,cAAmB,CAAC,GAAG;AAF1C,SAAQ,OAAY,CAAC;AAMrB,SAAO,UAAU,CAAC,cAAyC;AACzD,aAAO,YAAY,KAAK,KAAK,OAAO,SAAS,IAAI,KAAK;AAAA,IACxD;AAEA,SAAO,UAAU,CAAC,YAAuB;AACvC,WAAK,KAAK,SAAS;AACnB,WAAK,KAAK,KAAK,GAAG,OAAO;AAAA,IAC3B;AAEA,SAAO,aAAa,CAAC,SAAc,eAA+B;AAChE,UAAI,YAAY;AAEd,YAAI,KAAK,KAAK,KAAK,SAAO,QAAQ,UAAU,OAAK,EAAE,UAAU,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,GAC1F;AACE,gBAAM,IAAI;AAAA,YACR,+DAA+D,OAAO,UAAU,CAAC;AAAA,UAAE;AAAA,QACvF;AAAA,MACF;AACA,WAAK,KAAK,KAAK,GAAG,OAAO;AAAA,IAC3B;AAEA,SAAO,aAAa,CAClB,WACA,QACA,eAA8B;AAE9B,YAAM,cAAmB,KAAK,KAAK,OAAO,SAAS;AAEnD,UAAI;AACJ,UAAI,OAAO,WAAW,YAAY;AAChC,yBAAiB;AAAA,MACnB,WAAW,eAAe,QAAW;AACnC,cAAM,IAAI,MAAM,wDAAwD;AAAA,MAC1E,WAAW,MAAM,QAAQ,MAAM,GAAG;AAChC,yBAAiB,CAAC,cAAuB;AACvC,gBAAM,SAAS,OAAO,KAAK,OAAK,EAAE,UAAW,MAAM,UAAU,UAAW,CAAC;AACzE,cAAI,QAAQ;AACV,mBAAO,OAAO,WAAW,MAAM;AAAA,UACjC;AAAA,QACF;AAAA,MACF,OAAO;AAEL,yBAAiB,CAAC,cAAuB;AACvC,iB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2
  "name": "capitalsix-data-table",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A lightweight, framework-agnostic in-memory data table with typed CRUD operations: insert, update, upsert, delete, sort, and query rows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,12 +24,13 @@
24
24
  "url": "https://capitalsix.nl"
25
25
  },
26
26
  "repository": {
27
- "url": "https://github.com/capital-six/data-table"
27
+ "url": "https://github.com/capital-six/capitalsix-data-table"
28
28
  },
29
29
  "keywords": [
30
30
  "react",
31
- "global",
32
- "state",
31
+ "data",
32
+ "table",
33
+ "crud",
33
34
  "typescript"
34
35
  ],
35
36
  "ignore": [
@@ -45,24 +46,14 @@
45
46
  "typecheck": "tsc --noEmit",
46
47
  "prepack": "npmignore --auto"
47
48
  },
48
- "peerDependencies": {
49
- "react": "^18.3.1",
50
- "react-dom": "^18.3.1"
51
- },
52
49
  "devDependencies": {
53
50
  "@testing-library/jest-dom": "^6.4.8",
54
- "@testing-library/react": "^16.0.1",
55
51
  "@types/node": "^22.10.2",
56
- "@types/react": "^18.3.1",
57
- "@types/react-dom": "^18.3.1",
58
- "@vitejs/plugin-react": "^5.0.0",
59
52
  "jsdom": "^25.0.1",
53
+ "npmignore": "^0.3.5",
60
54
  "tsup": "^8.3.5",
61
55
  "typescript": "^5.7.3",
62
56
  "vite": "^6.0.5",
63
57
  "vitest": "^2.1.8"
64
- },
65
- "dependencies": {
66
- "npmignore": "^0.3.5"
67
58
  }
68
59
  }