@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.
@@ -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 edit protocol for the table
10
+ * Creates a table and an insertHistory for the table
11
11
  * @param tableCfg TableCfg of table to create
12
12
  */
13
- createEditable(tableCfg: TableCfg): Promise<void>;
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 edit protocol table for a given table
20
+ * Creates an insertHistory table for a given table
21
21
  * @param tableCfg TableCfg of table
22
22
  */
23
- createEditProtocol(tableCfg: TableCfg): Promise<void>;
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 | null>;
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 { Edit, EditProtocolRow, EditProtocolTimeId, Ref, Rljson, Route } from '@rljson/rljson';
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
- * Recursively fetches data from the given route using the provided controllers
35
- * @param route - The route to fetch data from
36
- * @param where - The filter to apply to the root table
37
- * @param controllers - A record of controllers keyed by table name
38
- * @returns An array of Rljson objects matching the route and filter
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 _get;
75
+ private _getBaseDataForColumnSelection;
41
76
  /**
42
- * Runs an edit by executing the appropriate controller(s) based on the edit's route
43
- * @param edit - The edit to run
44
- * @returns The result of the edit as an EditProtocolRow
45
- * @throws {Error} If the edit is not valid or if any controller cannot be created
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
- run(edit: Edit<any>, options?: {
82
+ insert(insert: Insert<any>, options?: {
48
83
  skipNotification?: boolean;
49
- }): Promise<EditProtocolRow<any>>;
84
+ skipHistory?: boolean;
85
+ }): Promise<InsertHistoryRow<any>[]>;
50
86
  /**
51
- * Recursively runs controllers based on the route of the edit
52
- * @param edit - The edit to run
53
- * @param route - The route of the edit
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 edit
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 _run;
94
+ private _insert;
59
95
  /**
60
- * Registers a callback to be called when an edit is made on the given route
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 edit is made
98
+ * @param callback - The callback to be called when an Insert is made
63
99
  */
64
- registerObserver(route: Route, callback: (EditProtocolRow: EditProtocolRow<any>) => void): void;
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: (EditProtocolRow: EditProtocolRow<any>) => void): void;
106
+ unregisterObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
71
107
  /**
72
- * Resolves an edit by returning the run functions of all controllers involved in the edit's route
73
- * @param edit - The edit to resolve
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 _resolveRuns;
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 edit protocol row to the edits table of a table
96
- * @param table - The table the edit was made on
97
- * @param editProtocolRow - The edit protocol row to add
98
- * @throws {Error} If the edits table does not exist
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 _writeProtocol;
135
+ private _writeInsertHistory;
101
136
  /**
102
- * Get the edit protocol of a table
103
- * @param table - The table to get the edit protocol for
104
- * @throws {Error} If the edits table does not exist
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
- getProtocol(table: string, options?: {
141
+ getInsertHistory(table: string, options?: {
107
142
  sorted?: boolean;
108
143
  ascending?: boolean;
109
144
  }): Promise<Rljson>;
110
145
  /**
111
- * Get a specific edit protocol row from a table
112
- * @param table - The table to get the edit protocol row from
113
- * @param ref - The reference of the edit protocol row to get
114
- * @returns The edit protocol row or null if it does not exist
115
- * @throws {Error} If the edits table does not exist
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
- getProtocolRowsByRef(table: string, ref: string): Promise<EditProtocolRow<any>[] | null>;
152
+ getInsertHistoryRowsByRef(table: string, ref: string): Promise<InsertHistoryRow<any>[]>;
118
153
  /**
119
- * Get a specific edit protocol row from a table by its timeId
120
- * @param table - The table to get the edit protocol row from
121
- * @param timeId - The timeId of the edit protocol row to get
122
- * @returns The edit protocol row or null if it does not exist
123
- * @throws {Error} If the edits table does not exist
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
- getProtocolRowByTimeId(table: string, timeId: EditProtocolTimeId): Promise<EditProtocolRow<any> | null>;
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 edits table does not exist
166
+ * @throws {Error} If the Inserts table does not exist
132
167
  */
133
- getTimeIdsForRef(table: string, ref: Ref): Promise<EditProtocolTimeId[]>;
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 edits table does not exist
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
- getRefOfTimeId(table: string, timeId: EditProtocolTimeId): Promise<Ref | null>;
189
+ isolatePropertyFromComponents(rljson: Rljson, propertyKey: string): Rljson;
142
190
  /**
143
- * Example
144
- * @returns A new Db instance for test purposes
191
+ * Get the current cache of the Db instance
145
192
  */
146
- static example: () => Promise<Db>;
193
+ get cache(): Map<string, Rljson>;
147
194
  }