@rljson/db 0.0.8 → 0.0.9
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/dist/db.d.ts +48 -6
- package/dist/db.js +131 -10
- package/dist/notify.d.ts +1 -2
- package/package.json +10 -10
package/dist/db.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Io } from '@rljson/io';
|
|
2
2
|
import { Json, JsonValue } from '@rljson/json';
|
|
3
|
-
import { InsertHistoryRow, InsertHistoryTimeId, Ref, Rljson, Route, SliceId, TableType } from '@rljson/rljson';
|
|
3
|
+
import { Edit, EditHistory, InsertHistoryRow, InsertHistoryTimeId, MultiEdit, Ref, Rljson, Route, SliceId, TableType } from '@rljson/rljson';
|
|
4
4
|
import { Controller, ControllerChildProperty, ControllerRefs } from './controller/controller.ts';
|
|
5
5
|
import { Core } from './core.ts';
|
|
6
6
|
import { Join } from './join/join.ts';
|
|
7
7
|
import { ColumnSelection } from './join/selection/column-selection.ts';
|
|
8
|
-
import { Notify } from './notify.ts';
|
|
8
|
+
import { Notify, NotifyCallback } from './notify.ts';
|
|
9
9
|
export type Cell = {
|
|
10
10
|
route: Route;
|
|
11
|
-
value: JsonValue[] | null;
|
|
12
|
-
row: JsonValue[] | null;
|
|
11
|
+
value: JsonValue | JsonValue[] | null;
|
|
12
|
+
row: JsonValue | JsonValue[] | null;
|
|
13
13
|
path: Array<Array<string | number>>;
|
|
14
14
|
};
|
|
15
15
|
export type Container = {
|
|
@@ -97,13 +97,13 @@ export declare class Db {
|
|
|
97
97
|
* @param route - The route to register the callback on
|
|
98
98
|
* @param callback - The callback to be called when an Insert is made
|
|
99
99
|
*/
|
|
100
|
-
registerObserver(route: Route, callback:
|
|
100
|
+
registerObserver(route: Route, callback: NotifyCallback<any>): void;
|
|
101
101
|
/**
|
|
102
102
|
* Unregisters a callback from the given route
|
|
103
103
|
* @param route - The route to unregister the callback from
|
|
104
104
|
* @param callback - The callback to be unregistered
|
|
105
105
|
*/
|
|
106
|
-
unregisterObserver(route: Route, callback:
|
|
106
|
+
unregisterObserver(route: Route, callback: NotifyCallback<any>): void;
|
|
107
107
|
/**
|
|
108
108
|
* Get a controller for a specific table
|
|
109
109
|
* @param tableKey - The key of the table to get the controller for
|
|
@@ -120,6 +120,48 @@ export declare class Db {
|
|
|
120
120
|
* @throws {Error} If the InsertHistory table does not exist
|
|
121
121
|
*/
|
|
122
122
|
private _writeInsertHistory;
|
|
123
|
+
/**
|
|
124
|
+
* Add a head revision for a cake
|
|
125
|
+
* @param cakeKey - The cake table key
|
|
126
|
+
* @param cakeRef - The cake reference
|
|
127
|
+
*/
|
|
128
|
+
addHeadRevision(cakeKey: string, cakeRef: Ref): Promise<InsertHistoryRow<string>[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Add a multiEdit
|
|
131
|
+
* @param cakeKey - The cake table key
|
|
132
|
+
* @param multiEdit - The multiEdit to add
|
|
133
|
+
*/
|
|
134
|
+
addMultiEdit(cakeKey: string, multiEdit: MultiEdit): Promise<InsertHistoryRow<any>[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Get multiEdits
|
|
137
|
+
* @param cakeKey - The cake table key
|
|
138
|
+
* @param where - The where clause to filter multiEdits
|
|
139
|
+
*/
|
|
140
|
+
getMultiEdits(cakeKey: string, where: string | Json): Promise<MultiEdit[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Add an edit
|
|
143
|
+
* @param cakeKey - The cake table key
|
|
144
|
+
* @param edit - The edit to add
|
|
145
|
+
*/
|
|
146
|
+
addEdit(cakeKey: string, edit: Edit): Promise<InsertHistoryRow<any>[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Get edits
|
|
149
|
+
* @param cakeKey - The cake table key
|
|
150
|
+
* @param where - The where clause to filter edits
|
|
151
|
+
*/
|
|
152
|
+
getEdits(cakeKey: string, where: string | Json): Promise<Edit[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Add an edit history entry
|
|
155
|
+
* @param cakeKey - The cake table key
|
|
156
|
+
* @param editHistory - The edit history entry to add
|
|
157
|
+
*/
|
|
158
|
+
addEditHistory(cakeKey: string, editHistory: EditHistory): Promise<InsertHistoryRow<any>[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get edit history entries
|
|
161
|
+
* @param cakeKey - The cake table key
|
|
162
|
+
* @param where - The where clause to filter edit history entries
|
|
163
|
+
*/
|
|
164
|
+
getEditHistories(cakeKey: string, where: string | Json): Promise<EditHistory[]>;
|
|
123
165
|
/**
|
|
124
166
|
* Get the InsertHistory of a table
|
|
125
167
|
* @param table - The table to get the InsertHistory for
|
package/dist/db.js
CHANGED
|
@@ -217,7 +217,8 @@ class ComponentController extends BaseController {
|
|
|
217
217
|
"components",
|
|
218
218
|
"edits",
|
|
219
219
|
"editHistory",
|
|
220
|
-
"multiEdits"
|
|
220
|
+
"multiEdits",
|
|
221
|
+
"head"
|
|
221
222
|
];
|
|
222
223
|
_resolvedColumns = null;
|
|
223
224
|
_refTableKeyToColumnKeyMap = null;
|
|
@@ -888,6 +889,7 @@ const createController = async (type, core, tableKey, refs) => {
|
|
|
888
889
|
case "edits":
|
|
889
890
|
case "editHistory":
|
|
890
891
|
case "multiEdits":
|
|
892
|
+
case "head":
|
|
891
893
|
ctrl = new ComponentController(core, tableKey, refs);
|
|
892
894
|
break;
|
|
893
895
|
case "cakes":
|
|
@@ -2564,9 +2566,12 @@ class Notify {
|
|
|
2564
2566
|
notify(route, insertHistoryRow) {
|
|
2565
2567
|
const callbacks = this._callbacks.get(route.flat);
|
|
2566
2568
|
if (callbacks) {
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2569
|
+
Promise.all(callbacks.map((cb) => cb(insertHistoryRow))).catch((err) => {
|
|
2570
|
+
console.error(
|
|
2571
|
+
`Error notifying callbacks for route ${route.flat}:`,
|
|
2572
|
+
err
|
|
2573
|
+
);
|
|
2574
|
+
});
|
|
2570
2575
|
}
|
|
2571
2576
|
}
|
|
2572
2577
|
// ...........................................................................
|
|
@@ -3278,9 +3283,13 @@ class Db {
|
|
|
3278
3283
|
);
|
|
3279
3284
|
}
|
|
3280
3285
|
}
|
|
3281
|
-
if ([
|
|
3282
|
-
|
|
3283
|
-
|
|
3286
|
+
if ([
|
|
3287
|
+
"components",
|
|
3288
|
+
"edits",
|
|
3289
|
+
"multiEdits",
|
|
3290
|
+
"editHistory",
|
|
3291
|
+
"head"
|
|
3292
|
+
].includes(nodeType)) {
|
|
3284
3293
|
const runFn = runFns[nodeTableKey];
|
|
3285
3294
|
const components = nodeTree._data;
|
|
3286
3295
|
for (const component of components) {
|
|
@@ -3313,9 +3322,13 @@ class Db {
|
|
|
3313
3322
|
}
|
|
3314
3323
|
} else {
|
|
3315
3324
|
const runFn = runFns[nodeTableKey];
|
|
3316
|
-
if ([
|
|
3317
|
-
|
|
3318
|
-
|
|
3325
|
+
if ([
|
|
3326
|
+
"components",
|
|
3327
|
+
"edits",
|
|
3328
|
+
"multiEdits",
|
|
3329
|
+
"editHistory",
|
|
3330
|
+
"head"
|
|
3331
|
+
].includes(nodeType)) {
|
|
3319
3332
|
const components = rmhsh(
|
|
3320
3333
|
tree[nodeTableKey]
|
|
3321
3334
|
);
|
|
@@ -3435,6 +3448,114 @@ class Db {
|
|
|
3435
3448
|
});
|
|
3436
3449
|
}
|
|
3437
3450
|
// ...........................................................................
|
|
3451
|
+
/**
|
|
3452
|
+
* Add a head revision for a cake
|
|
3453
|
+
* @param cakeKey - The cake table key
|
|
3454
|
+
* @param cakeRef - The cake reference
|
|
3455
|
+
*/
|
|
3456
|
+
async addHeadRevision(cakeKey, cakeRef) {
|
|
3457
|
+
const cakeHeadKey = cakeKey + "Heads";
|
|
3458
|
+
const cakeHeadController = await this.getController(cakeHeadKey);
|
|
3459
|
+
return await cakeHeadController.insert("add", {
|
|
3460
|
+
cakeRef,
|
|
3461
|
+
timeId: timeId(),
|
|
3462
|
+
_hash: ""
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
// ...........................................................................
|
|
3466
|
+
/**
|
|
3467
|
+
* Add a multiEdit
|
|
3468
|
+
* @param cakeKey - The cake table key
|
|
3469
|
+
* @param multiEdit - The multiEdit to add
|
|
3470
|
+
*/
|
|
3471
|
+
async addMultiEdit(cakeKey, multiEdit) {
|
|
3472
|
+
return this.insert(
|
|
3473
|
+
Route.fromFlat(cakeKey + "MultiEdits"),
|
|
3474
|
+
{
|
|
3475
|
+
[cakeKey + "MultiEdits"]: {
|
|
3476
|
+
_data: [multiEdit],
|
|
3477
|
+
_type: "multiEdits"
|
|
3478
|
+
}
|
|
3479
|
+
},
|
|
3480
|
+
{ skipHistory: true }
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3483
|
+
// ...........................................................................
|
|
3484
|
+
/**
|
|
3485
|
+
* Get multiEdits
|
|
3486
|
+
* @param cakeKey - The cake table key
|
|
3487
|
+
* @param where - The where clause to filter multiEdits
|
|
3488
|
+
*/
|
|
3489
|
+
async getMultiEdits(cakeKey, where) {
|
|
3490
|
+
const multiEditController = await this.getController(
|
|
3491
|
+
cakeKey + "MultiEdits"
|
|
3492
|
+
);
|
|
3493
|
+
const { [cakeKey + "MultiEdits"]: result } = await multiEditController.get(
|
|
3494
|
+
where
|
|
3495
|
+
);
|
|
3496
|
+
return result._data;
|
|
3497
|
+
}
|
|
3498
|
+
// ...........................................................................
|
|
3499
|
+
/**
|
|
3500
|
+
* Add an edit
|
|
3501
|
+
* @param cakeKey - The cake table key
|
|
3502
|
+
* @param edit - The edit to add
|
|
3503
|
+
*/
|
|
3504
|
+
async addEdit(cakeKey, edit) {
|
|
3505
|
+
return this.insert(
|
|
3506
|
+
Route.fromFlat(cakeKey + "Edits"),
|
|
3507
|
+
{
|
|
3508
|
+
[cakeKey + "Edits"]: {
|
|
3509
|
+
_data: [edit],
|
|
3510
|
+
_type: "edits"
|
|
3511
|
+
}
|
|
3512
|
+
},
|
|
3513
|
+
{ skipHistory: true }
|
|
3514
|
+
);
|
|
3515
|
+
}
|
|
3516
|
+
// ...........................................................................
|
|
3517
|
+
/**
|
|
3518
|
+
* Get edits
|
|
3519
|
+
* @param cakeKey - The cake table key
|
|
3520
|
+
* @param where - The where clause to filter edits
|
|
3521
|
+
*/
|
|
3522
|
+
async getEdits(cakeKey, where) {
|
|
3523
|
+
const editController = await this.getController(cakeKey + "Edits");
|
|
3524
|
+
const { [cakeKey + "Edits"]: result } = await editController.get(where);
|
|
3525
|
+
return result._data;
|
|
3526
|
+
}
|
|
3527
|
+
// ...........................................................................
|
|
3528
|
+
/**
|
|
3529
|
+
* Add an edit history entry
|
|
3530
|
+
* @param cakeKey - The cake table key
|
|
3531
|
+
* @param editHistory - The edit history entry to add
|
|
3532
|
+
*/
|
|
3533
|
+
async addEditHistory(cakeKey, editHistory) {
|
|
3534
|
+
return this.insert(
|
|
3535
|
+
Route.fromFlat(cakeKey + "EditHistory"),
|
|
3536
|
+
{
|
|
3537
|
+
[cakeKey + "EditHistory"]: {
|
|
3538
|
+
_data: [editHistory],
|
|
3539
|
+
_type: "editHistory"
|
|
3540
|
+
}
|
|
3541
|
+
},
|
|
3542
|
+
{ skipHistory: true }
|
|
3543
|
+
);
|
|
3544
|
+
}
|
|
3545
|
+
// ...........................................................................
|
|
3546
|
+
/**
|
|
3547
|
+
* Get edit history entries
|
|
3548
|
+
* @param cakeKey - The cake table key
|
|
3549
|
+
* @param where - The where clause to filter edit history entries
|
|
3550
|
+
*/
|
|
3551
|
+
async getEditHistories(cakeKey, where) {
|
|
3552
|
+
const editHistoryController = await this.getController(
|
|
3553
|
+
cakeKey + "EditHistory"
|
|
3554
|
+
);
|
|
3555
|
+
const { [cakeKey + "EditHistory"]: result } = await editHistoryController.get(where);
|
|
3556
|
+
return result._data;
|
|
3557
|
+
}
|
|
3558
|
+
// ...........................................................................
|
|
3438
3559
|
/**
|
|
3439
3560
|
* Get the InsertHistory of a table
|
|
3440
3561
|
* @param table - The table to get the InsertHistory for
|
package/dist/notify.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InsertHistoryRow, Route } from '@rljson/rljson';
|
|
2
|
-
type NotifyCallback<N extends string> = (InsertHistoryRow: InsertHistoryRow<N>) =>
|
|
2
|
+
export type NotifyCallback<N extends string> = (InsertHistoryRow: InsertHistoryRow<N>) => Promise<any>;
|
|
3
3
|
/**
|
|
4
4
|
* Notification system to manage callbacks for specific routes and notify them with edit protocol rows.
|
|
5
5
|
*/
|
|
@@ -36,4 +36,3 @@ export declare class Notify {
|
|
|
36
36
|
*/
|
|
37
37
|
getCallBacksForRoute(route: Route): NotifyCallback<any>[];
|
|
38
38
|
}
|
|
39
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A high level interface to read and write RLJSON data from and into a database",
|
|
5
5
|
"homepage": "https://github.com/rljson/db",
|
|
6
6
|
"bugs": "https://github.com/rljson/db/issues",
|
|
@@ -21,30 +21,30 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^24.10.1",
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^8.48.
|
|
25
|
-
"@typescript-eslint/parser": "^8.48.
|
|
26
|
-
"@vitest/coverage-v8": "^4.0.
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
25
|
+
"@typescript-eslint/parser": "^8.48.1",
|
|
26
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
27
27
|
"cross-env": "^10.1.0",
|
|
28
28
|
"eslint": "^9.39.1",
|
|
29
|
-
"eslint-plugin-jsdoc": "^61.
|
|
29
|
+
"eslint-plugin-jsdoc": "^61.5.0",
|
|
30
30
|
"eslint-plugin-tsdoc": "^0.5.0",
|
|
31
31
|
"globals": "^16.5.0",
|
|
32
32
|
"jsdoc": "^4.0.5",
|
|
33
33
|
"read-pkg": "^10.0.0",
|
|
34
34
|
"typescript": "~5.9.3",
|
|
35
|
-
"typescript-eslint": "^8.48.
|
|
36
|
-
"vite": "^7.2.
|
|
35
|
+
"typescript-eslint": "^8.48.1",
|
|
36
|
+
"vite": "^7.2.7",
|
|
37
37
|
"vite-node": "^5.2.0",
|
|
38
38
|
"vite-plugin-dts": "^4.5.4",
|
|
39
39
|
"vite-tsconfig-paths": "^5.1.4",
|
|
40
|
-
"vitest": "^4.0.
|
|
40
|
+
"vitest": "^4.0.15",
|
|
41
41
|
"vitest-dom": "^0.1.1"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@rljson/hash": "^0.0.17",
|
|
45
|
-
"@rljson/io": "^0.0.
|
|
45
|
+
"@rljson/io": "^0.0.61",
|
|
46
46
|
"@rljson/json": "^0.0.23",
|
|
47
|
-
"@rljson/rljson": "^0.0.
|
|
47
|
+
"@rljson/rljson": "^0.0.73",
|
|
48
48
|
"@rljson/validate": "^0.0.11",
|
|
49
49
|
"filtrex": "^3.1.0",
|
|
50
50
|
"object-traversal": "^1.0.1",
|