@rljson/db 0.0.5 → 0.0.6

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 } 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,63 @@ 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>;
36
+ _get(route: Route, where: string | Json, controllers: Record<string, Controller<any, any>>, segmentLevel?: number): Promise<Rljson>;
33
37
  /**
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
38
+ * Get the reference (hash) of a route segment, considering default refs and insertHistory refs
39
+ * @param segment - The route segment to get the reference for
40
+ * @returns
41
+ */
42
+ private _getReferenceOfRouteSegment;
43
+ /**
44
+ * Joins data from layers in an Rljson into a single dataset
45
+ * @param rljson - The Rljson to join data for
46
+ */
47
+ join(columnSelection: ColumnSelection, cakeKey: string, cakeRef: Ref): Promise<Join>;
48
+ /**
49
+ * Fetches data for the given ColumnSelection
50
+ * @param columnSelection - The ColumnSelection to fetch data for
39
51
  */
40
- private _get;
52
+ private _getBaseDataForColumnSelection;
41
53
  /**
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
54
+ * Runs an Insert by executing the appropriate controller(s) based on the Insert's route
55
+ * @param Insert - The Insert to run
56
+ * @returns The result of the Insert as an InsertHistoryRow
57
+ * @throws {Error} If the Insert is not valid or if any controller cannot be created
46
58
  */
47
- run(edit: Edit<any>, options?: {
59
+ insert(insert: Insert<any>, options?: {
48
60
  skipNotification?: boolean;
49
- }): Promise<EditProtocolRow<any>>;
61
+ }): Promise<InsertHistoryRow<any>>;
50
62
  /**
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
63
+ * Recursively runs controllers based on the route of the Insert
64
+ * @param insert - The Insert to run
65
+ * @param route - The route of the Insert
54
66
  * @param runFns - A record of controller run functions, keyed by table name
55
- * @returns The result of the edit
67
+ * @returns The result of the Insert
56
68
  * @throws {Error} If the route is not valid or if any controller cannot be created
57
69
  */
58
- private _run;
70
+ private _insert;
59
71
  /**
60
- * Registers a callback to be called when an edit is made on the given route
72
+ * Registers a callback to be called when an Insert is made on the given route
61
73
  * @param route - The route to register the callback on
62
- * @param callback - The callback to be called when an edit is made
74
+ * @param callback - The callback to be called when an Insert is made
63
75
  */
64
- registerObserver(route: Route, callback: (EditProtocolRow: EditProtocolRow<any>) => void): void;
76
+ registerObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
65
77
  /**
66
78
  * Unregisters a callback from the given route
67
79
  * @param route - The route to unregister the callback from
68
80
  * @param callback - The callback to be unregistered
69
81
  */
70
- unregisterObserver(route: Route, callback: (EditProtocolRow: EditProtocolRow<any>) => void): void;
82
+ unregisterObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
71
83
  /**
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
84
+ * Resolves an Insert by returning the run functions of all controllers involved in the Insert's route
85
+ * @param Insert - The Insert to resolve
74
86
  * @returns A record of controller run functions, keyed by table name
75
87
  * @throws {Error} If the route is not valid or if any controller cannot be created
76
88
  */
77
- private _resolveRuns;
89
+ private _resolveInsert;
78
90
  /**
79
91
  * Returns the keys of child refs in a value based on a route
80
- * @param route - The route to check
81
92
  * @param value - The value to check
82
93
  * @returns An array of keys of child refs in the value
83
94
  */
@@ -92,56 +103,68 @@ export declare class Db {
92
103
  getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<any, string>>;
93
104
  private _indexedControllers;
94
105
  /**
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
106
+ * Adds an InsertHistory row to the InsertHistory table of a table
107
+ * @param table - The table the Insert was made on
108
+ * @param InsertHistoryRow - The InsertHistory row to add
109
+ * @throws {Error} If the InsertHistory table does not exist
99
110
  */
100
- private _writeProtocol;
111
+ private _writeInsertHistory;
101
112
  /**
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
113
+ * Get the InsertHistory of a table
114
+ * @param table - The table to get the InsertHistory for
115
+ * @throws {Error} If the InsertHistory table does not exist
105
116
  */
106
- getProtocol(table: string, options?: {
117
+ getInsertHistory(table: string, options?: {
107
118
  sorted?: boolean;
108
119
  ascending?: boolean;
109
120
  }): Promise<Rljson>;
110
121
  /**
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
122
+ * Get a specific InsertHistory row from a table
123
+ * @param table - The table to get the InsertHistory row from
124
+ * @param ref - The reference of the InsertHistory row to get
125
+ * @returns The InsertHistory row or null if it does not exist
126
+ * @throws {Error} If the Inserts table does not exist
116
127
  */
117
- getProtocolRowsByRef(table: string, ref: string): Promise<EditProtocolRow<any>[] | null>;
128
+ getInsertHistoryRowsByRef(table: string, ref: string): Promise<InsertHistoryRow<any>[]>;
118
129
  /**
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
130
+ * Get a specific InsertHistory row from a table by its timeId
131
+ * @param table - The table to get the InsertHistory row from
132
+ * @param timeId - The timeId of the InsertHistory row to get
133
+ * @returns The InsertHistory row or null if it does not exist
134
+ * @throws {Error} If the Inserts table does not exist
124
135
  */
125
- getProtocolRowByTimeId(table: string, timeId: EditProtocolTimeId): Promise<EditProtocolRow<any> | null>;
136
+ getInsertHistoryRowByTimeId(table: string, timeId: InsertHistoryTimeId): Promise<InsertHistoryRow<any>>;
126
137
  /**
127
138
  * Get all timeIds for a specific ref in a table
128
139
  * @param table - The table to get the timeIds from
129
140
  * @param ref - The reference to get the timeIds for
130
141
  * @returns An array of timeIds
131
- * @throws {Error} If the edits table does not exist
142
+ * @throws {Error} If the Inserts table does not exist
132
143
  */
133
- getTimeIdsForRef(table: string, ref: Ref): Promise<EditProtocolTimeId[]>;
144
+ getTimeIdsForRef(table: string, ref: Ref): Promise<InsertHistoryTimeId[]>;
134
145
  /**
135
146
  * Get the ref for a specific timeId in a table
136
147
  * @param table - The table to get the ref from
137
148
  * @param timeId - The timeId to get the ref for
138
149
  * @returns The ref or null if it does not exist
139
- * @throws {Error} If the edits table does not exist
150
+ * @throws {Error} If the Inserts table does not exist
151
+ */
152
+ getRefOfTimeId(table: string, timeId: InsertHistoryTimeId): Promise<Ref | null>;
153
+ /**
154
+ * Isolates the property key from the last segment of a route if it is a property of a component
155
+ * @param route - The route to extract property key from
156
+ * @returns A route with extracted property key
157
+ */
158
+ isolatePropertyKeyFromRoute(route: Route): Promise<Route>;
159
+ /**
160
+ * Isolates a property from all components in an Rljson
161
+ * @param rljson - The Rljson to isolate the property from
162
+ * @param propertyKey - The property key to isolate
163
+ * @returns A new Rljson with only the isolated property
140
164
  */
141
- getRefOfTimeId(table: string, timeId: EditProtocolTimeId): Promise<Ref | null>;
165
+ isolatePropertyFromComponents(rljson: Rljson, propertyKey: string): Rljson;
142
166
  /**
143
- * Example
144
- * @returns A new Db instance for test purposes
167
+ * Get the current cache of the Db instance
145
168
  */
146
- static example: () => Promise<Db>;
169
+ get cache(): Map<string, Rljson>;
147
170
  }