@rljson/db 0.0.5 → 0.0.7
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/cars-example.d.ts +5 -1
- package/dist/core.d.ts +6 -5
- package/dist/db.d.ts +102 -55
- package/dist/db.js +2552 -368
- package/dist/notify.d.ts +4 -4
- package/package.json +21 -19
package/dist/cars-example.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Json, JsonH } from '@rljson/json';
|
|
1
|
+
import { Json, JsonH, JsonValueH } from '@rljson/json';
|
|
2
2
|
import { CakesTable, ComponentsTable, LayersTable, Rljson, SliceIdsTable, TablesCfgTable } from '@rljson/rljson';
|
|
3
3
|
export interface CarsExample extends Rljson {
|
|
4
4
|
carSliceId: SliceIdsTable;
|
|
@@ -22,6 +22,10 @@ export interface CarGeneral extends JsonH {
|
|
|
22
22
|
brand: string;
|
|
23
23
|
type: string;
|
|
24
24
|
doors: number;
|
|
25
|
+
energyConsumption: number;
|
|
26
|
+
units: JsonValueH;
|
|
27
|
+
serviceIntervals: number[];
|
|
28
|
+
isElectric: boolean;
|
|
25
29
|
}
|
|
26
30
|
export interface CarDimension extends JsonH {
|
|
27
31
|
height: number;
|
package/dist/core.d.ts
CHANGED
|
@@ -7,20 +7,20 @@ export declare class Core {
|
|
|
7
7
|
constructor(_io: Io);
|
|
8
8
|
static example: () => Promise<Core>;
|
|
9
9
|
/**
|
|
10
|
-
* Creates a table and an
|
|
10
|
+
* Creates a table and an insertHistory for the table
|
|
11
11
|
* @param tableCfg TableCfg of table to create
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
createTableWithInsertHistory(tableCfg: TableCfg): Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a table
|
|
16
16
|
* @param tableCfg TableCfg of table to create
|
|
17
17
|
*/
|
|
18
18
|
createTable(tableCfg: TableCfg): Promise<void>;
|
|
19
19
|
/**
|
|
20
|
-
* Creates an
|
|
20
|
+
* Creates an insertHistory table for a given table
|
|
21
21
|
* @param tableCfg TableCfg of table
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
createInsertHistory(tableCfg: TableCfg): Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Returns a dump of the database
|
|
26
26
|
*/
|
|
@@ -39,7 +39,8 @@ export declare class Core {
|
|
|
39
39
|
import(data: Rljson): Promise<void>;
|
|
40
40
|
tables(): Promise<Rljson>;
|
|
41
41
|
hasTable(table: string): Promise<boolean>;
|
|
42
|
-
contentType(table: string): Promise<ContentType
|
|
42
|
+
contentType(table: string): Promise<ContentType>;
|
|
43
|
+
tableCfg(table: string): Promise<TableCfg>;
|
|
43
44
|
/** Reads a specific row from a database table */
|
|
44
45
|
readRow(table: string, rowHash: string): Promise<Rljson>;
|
|
45
46
|
readRows(table: string, where: {
|
package/dist/db.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Io } from '@rljson/io';
|
|
2
2
|
import { Json } from '@rljson/json';
|
|
3
|
-
import {
|
|
3
|
+
import { Insert, InsertHistoryRow, InsertHistoryTimeId, Ref, Rljson, Route, TableKey } from '@rljson/rljson';
|
|
4
4
|
import { Controller, ControllerRefs } from './controller/controller.ts';
|
|
5
5
|
import { Core } from './core.ts';
|
|
6
|
+
import { Join } from './join/join.ts';
|
|
7
|
+
import { ColumnSelection } from './join/selection/column-selection.ts';
|
|
6
8
|
import { Notify } from './notify.ts';
|
|
7
9
|
/**
|
|
8
10
|
* Access Rljson data
|
|
@@ -22,6 +24,7 @@ export declare class Db {
|
|
|
22
24
|
* Notification system to register callbacks on data changes
|
|
23
25
|
*/
|
|
24
26
|
readonly notify: Notify;
|
|
27
|
+
private _cache;
|
|
25
28
|
/**
|
|
26
29
|
* Get data from a route with optional filtering
|
|
27
30
|
* @param route - The route to get data from
|
|
@@ -29,55 +32,87 @@ export declare class Db {
|
|
|
29
32
|
* @returns An array of Rljson objects matching the route and filter
|
|
30
33
|
* @throws {Error} If the route is not valid or if any controller cannot be created
|
|
31
34
|
*/
|
|
32
|
-
get(route: Route, where: string | Json): Promise<Rljson
|
|
35
|
+
get(route: Route, where: string | Json): Promise<Rljson>;
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
37
|
+
* Resolves the route and returns corresponding data for any segment of the route,
|
|
38
|
+
* matching recursive filters and where clauses
|
|
39
|
+
*
|
|
40
|
+
* @param route - The route to get data from
|
|
41
|
+
* @param where - The recursive filtering key/value pairs to apply to the data
|
|
42
|
+
* @param controllers - The controllers to use for fetching data
|
|
43
|
+
* @param filter - Optional filter to apply to the data at the current route segment
|
|
44
|
+
* @returns - An Rljson object matching the route and filters
|
|
45
|
+
*/
|
|
46
|
+
_get(route: Route, where: string | Json, controllers: Record<string, Controller<any, any>>, filter?: Array<{
|
|
47
|
+
tableKey: TableKey;
|
|
48
|
+
columnKey?: string;
|
|
49
|
+
ref: Ref;
|
|
50
|
+
}>): Promise<Rljson>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the reference (hash) of a route segment, considering default refs and insertHistory refs
|
|
53
|
+
* @param segment - The route segment to get the reference for
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
private _getReferenceOfRouteSegment;
|
|
57
|
+
/**
|
|
58
|
+
* Joins data from layers in an Rljson into a single dataset
|
|
59
|
+
* @param rljson - The Rljson to join data for
|
|
60
|
+
*/
|
|
61
|
+
join(columnSelection: ColumnSelection, cakeKey: string, cakeRef: Ref): Promise<Join>;
|
|
62
|
+
private _resolveComponentProperties;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve a component's columns, including referenced components
|
|
65
|
+
*
|
|
66
|
+
* @param baseRoute - The base route for the component
|
|
67
|
+
* @param componentKey - The component's table key
|
|
68
|
+
* @returns - The resolved column configurations, column infos, and object map
|
|
69
|
+
*/
|
|
70
|
+
private _resolveComponent;
|
|
71
|
+
/**
|
|
72
|
+
* Fetches data for the given ColumnSelection
|
|
73
|
+
* @param columnSelection - The ColumnSelection to fetch data for
|
|
39
74
|
*/
|
|
40
|
-
private
|
|
75
|
+
private _getBaseDataForColumnSelection;
|
|
41
76
|
/**
|
|
42
|
-
* Runs an
|
|
43
|
-
* @param
|
|
44
|
-
* @returns The result of the
|
|
45
|
-
* @throws {Error} If the
|
|
77
|
+
* Runs an Insert by executing the appropriate controller(s) based on the Insert's route
|
|
78
|
+
* @param Insert - The Insert to run
|
|
79
|
+
* @returns The result of the Insert as an InsertHistoryRow
|
|
80
|
+
* @throws {Error} If the Insert is not valid or if any controller cannot be created
|
|
46
81
|
*/
|
|
47
|
-
|
|
82
|
+
insert(insert: Insert<any>, options?: {
|
|
48
83
|
skipNotification?: boolean;
|
|
49
|
-
|
|
84
|
+
skipHistory?: boolean;
|
|
85
|
+
}): Promise<InsertHistoryRow<any>[]>;
|
|
50
86
|
/**
|
|
51
|
-
* Recursively runs controllers based on the route of the
|
|
52
|
-
* @param
|
|
53
|
-
* @param route - The route of the
|
|
87
|
+
* Recursively runs controllers based on the route of the Insert
|
|
88
|
+
* @param insert - The Insert to run
|
|
89
|
+
* @param route - The route of the Insert
|
|
54
90
|
* @param runFns - A record of controller run functions, keyed by table name
|
|
55
|
-
* @returns The result of the
|
|
91
|
+
* @returns The result of the Insert
|
|
56
92
|
* @throws {Error} If the route is not valid or if any controller cannot be created
|
|
57
93
|
*/
|
|
58
|
-
private
|
|
94
|
+
private _insert;
|
|
59
95
|
/**
|
|
60
|
-
* Registers a callback to be called when an
|
|
96
|
+
* Registers a callback to be called when an Insert is made on the given route
|
|
61
97
|
* @param route - The route to register the callback on
|
|
62
|
-
* @param callback - The callback to be called when an
|
|
98
|
+
* @param callback - The callback to be called when an Insert is made
|
|
63
99
|
*/
|
|
64
|
-
registerObserver(route: Route, callback: (
|
|
100
|
+
registerObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
|
|
65
101
|
/**
|
|
66
102
|
* Unregisters a callback from the given route
|
|
67
103
|
* @param route - The route to unregister the callback from
|
|
68
104
|
* @param callback - The callback to be unregistered
|
|
69
105
|
*/
|
|
70
|
-
unregisterObserver(route: Route, callback: (
|
|
106
|
+
unregisterObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
|
|
71
107
|
/**
|
|
72
|
-
* Resolves an
|
|
73
|
-
* @param
|
|
108
|
+
* Resolves an Insert by returning the run functions of all controllers involved in the Insert's route
|
|
109
|
+
* @param Insert - The Insert to resolve
|
|
74
110
|
* @returns A record of controller run functions, keyed by table name
|
|
75
111
|
* @throws {Error} If the route is not valid or if any controller cannot be created
|
|
76
112
|
*/
|
|
77
|
-
private
|
|
113
|
+
private _resolveInsert;
|
|
78
114
|
/**
|
|
79
115
|
* Returns the keys of child refs in a value based on a route
|
|
80
|
-
* @param route - The route to check
|
|
81
116
|
* @param value - The value to check
|
|
82
117
|
* @returns An array of keys of child refs in the value
|
|
83
118
|
*/
|
|
@@ -92,56 +127,68 @@ export declare class Db {
|
|
|
92
127
|
getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<any, string>>;
|
|
93
128
|
private _indexedControllers;
|
|
94
129
|
/**
|
|
95
|
-
* Adds an
|
|
96
|
-
* @param table - The table the
|
|
97
|
-
* @param
|
|
98
|
-
* @throws {Error} If the
|
|
130
|
+
* Adds an InsertHistory row to the InsertHistory table of a table
|
|
131
|
+
* @param table - The table the Insert was made on
|
|
132
|
+
* @param InsertHistoryRow - The InsertHistory row to add
|
|
133
|
+
* @throws {Error} If the InsertHistory table does not exist
|
|
99
134
|
*/
|
|
100
|
-
private
|
|
135
|
+
private _writeInsertHistory;
|
|
101
136
|
/**
|
|
102
|
-
* Get the
|
|
103
|
-
* @param table - The table to get the
|
|
104
|
-
* @throws {Error} If the
|
|
137
|
+
* Get the InsertHistory of a table
|
|
138
|
+
* @param table - The table to get the InsertHistory for
|
|
139
|
+
* @throws {Error} If the InsertHistory table does not exist
|
|
105
140
|
*/
|
|
106
|
-
|
|
141
|
+
getInsertHistory(table: string, options?: {
|
|
107
142
|
sorted?: boolean;
|
|
108
143
|
ascending?: boolean;
|
|
109
144
|
}): Promise<Rljson>;
|
|
110
145
|
/**
|
|
111
|
-
* Get a specific
|
|
112
|
-
* @param table - The table to get the
|
|
113
|
-
* @param ref - The reference of the
|
|
114
|
-
* @returns The
|
|
115
|
-
* @throws {Error} If the
|
|
146
|
+
* Get a specific InsertHistory row from a table
|
|
147
|
+
* @param table - The table to get the InsertHistory row from
|
|
148
|
+
* @param ref - The reference of the InsertHistory row to get
|
|
149
|
+
* @returns The InsertHistory row or null if it does not exist
|
|
150
|
+
* @throws {Error} If the Inserts table does not exist
|
|
116
151
|
*/
|
|
117
|
-
|
|
152
|
+
getInsertHistoryRowsByRef(table: string, ref: string): Promise<InsertHistoryRow<any>[]>;
|
|
118
153
|
/**
|
|
119
|
-
* Get a specific
|
|
120
|
-
* @param table - The table to get the
|
|
121
|
-
* @param timeId - The timeId of the
|
|
122
|
-
* @returns The
|
|
123
|
-
* @throws {Error} If the
|
|
154
|
+
* Get a specific InsertHistory row from a table by its timeId
|
|
155
|
+
* @param table - The table to get the InsertHistory row from
|
|
156
|
+
* @param timeId - The timeId of the InsertHistory row to get
|
|
157
|
+
* @returns The InsertHistory row or null if it does not exist
|
|
158
|
+
* @throws {Error} If the Inserts table does not exist
|
|
124
159
|
*/
|
|
125
|
-
|
|
160
|
+
getInsertHistoryRowByTimeId(table: string, timeId: InsertHistoryTimeId): Promise<InsertHistoryRow<any>>;
|
|
126
161
|
/**
|
|
127
162
|
* Get all timeIds for a specific ref in a table
|
|
128
163
|
* @param table - The table to get the timeIds from
|
|
129
164
|
* @param ref - The reference to get the timeIds for
|
|
130
165
|
* @returns An array of timeIds
|
|
131
|
-
* @throws {Error} If the
|
|
166
|
+
* @throws {Error} If the Inserts table does not exist
|
|
132
167
|
*/
|
|
133
|
-
getTimeIdsForRef(table: string, ref: Ref): Promise<
|
|
168
|
+
getTimeIdsForRef(table: string, ref: Ref): Promise<InsertHistoryTimeId[]>;
|
|
134
169
|
/**
|
|
135
170
|
* Get the ref for a specific timeId in a table
|
|
136
171
|
* @param table - The table to get the ref from
|
|
137
172
|
* @param timeId - The timeId to get the ref for
|
|
138
173
|
* @returns The ref or null if it does not exist
|
|
139
|
-
* @throws {Error} If the
|
|
174
|
+
* @throws {Error} If the Inserts table does not exist
|
|
175
|
+
*/
|
|
176
|
+
getRefOfTimeId(table: string, timeId: InsertHistoryTimeId): Promise<Ref | null>;
|
|
177
|
+
/**
|
|
178
|
+
* Isolates the property key from the last segment of a route if it is a property of a component
|
|
179
|
+
* @param route - The route to extract property key from
|
|
180
|
+
* @returns A route with extracted property key
|
|
181
|
+
*/
|
|
182
|
+
isolatePropertyKeyFromRoute(route: Route): Promise<Route>;
|
|
183
|
+
/**
|
|
184
|
+
* Isolates a property from all components in an Rljson
|
|
185
|
+
* @param rljson - The Rljson to isolate the property from
|
|
186
|
+
* @param propertyKey - The property key to isolate
|
|
187
|
+
* @returns A new Rljson with only the isolated property
|
|
140
188
|
*/
|
|
141
|
-
|
|
189
|
+
isolatePropertyFromComponents(rljson: Rljson, propertyKey: string): Rljson;
|
|
142
190
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @returns A new Db instance for test purposes
|
|
191
|
+
* Get the current cache of the Db instance
|
|
145
192
|
*/
|
|
146
|
-
|
|
193
|
+
get cache(): Map<string, Rljson>;
|
|
147
194
|
}
|