@rljson/db 0.0.3 → 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.
package/dist/db.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import { Io } from '@rljson/io';
2
+ import { Json } from '@rljson/json';
3
+ import { Insert, InsertHistoryRow, InsertHistoryTimeId, Ref, Rljson, Route } from '@rljson/rljson';
4
+ import { Controller, ControllerRefs } from './controller/controller.ts';
2
5
  import { Core } from './core.ts';
6
+ import { Join } from './join/join.ts';
7
+ import { ColumnSelection } from './join/selection/column-selection.ts';
8
+ import { Notify } from './notify.ts';
3
9
  /**
4
10
  * Access Rljson data
5
11
  */
@@ -15,8 +21,150 @@ export declare class Db {
15
21
  */
16
22
  readonly core: Core;
17
23
  /**
18
- * Example
19
- * @returns A new Db instance for test purposes
24
+ * Notification system to register callbacks on data changes
20
25
  */
21
- static example: () => Promise<Db>;
26
+ readonly notify: Notify;
27
+ private _cache;
28
+ /**
29
+ * Get data from a route with optional filtering
30
+ * @param route - The route to get data from
31
+ * @param where - Optional filter to apply to the data
32
+ * @returns An array of Rljson objects matching the route and filter
33
+ * @throws {Error} If the route is not valid or if any controller cannot be created
34
+ */
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>;
37
+ /**
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
51
+ */
52
+ private _getBaseDataForColumnSelection;
53
+ /**
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
58
+ */
59
+ insert(insert: Insert<any>, options?: {
60
+ skipNotification?: boolean;
61
+ }): Promise<InsertHistoryRow<any>>;
62
+ /**
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
66
+ * @param runFns - A record of controller run functions, keyed by table name
67
+ * @returns The result of the Insert
68
+ * @throws {Error} If the route is not valid or if any controller cannot be created
69
+ */
70
+ private _insert;
71
+ /**
72
+ * Registers a callback to be called when an Insert is made on the given route
73
+ * @param route - The route to register the callback on
74
+ * @param callback - The callback to be called when an Insert is made
75
+ */
76
+ registerObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
77
+ /**
78
+ * Unregisters a callback from the given route
79
+ * @param route - The route to unregister the callback from
80
+ * @param callback - The callback to be unregistered
81
+ */
82
+ unregisterObserver(route: Route, callback: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
83
+ /**
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
86
+ * @returns A record of controller run functions, keyed by table name
87
+ * @throws {Error} If the route is not valid or if any controller cannot be created
88
+ */
89
+ private _resolveInsert;
90
+ /**
91
+ * Returns the keys of child refs in a value based on a route
92
+ * @param value - The value to check
93
+ * @returns An array of keys of child refs in the value
94
+ */
95
+ private _childKeys;
96
+ /**
97
+ * Get a controller for a specific table
98
+ * @param tableKey - The key of the table to get the controller for
99
+ * @param refs - Optional references required by some controllers
100
+ * @returns A controller for the specified table
101
+ * @throws {Error} If the table does not exist or if the table type is not supported
102
+ */
103
+ getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<any, string>>;
104
+ private _indexedControllers;
105
+ /**
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
110
+ */
111
+ private _writeInsertHistory;
112
+ /**
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
116
+ */
117
+ getInsertHistory(table: string, options?: {
118
+ sorted?: boolean;
119
+ ascending?: boolean;
120
+ }): Promise<Rljson>;
121
+ /**
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
127
+ */
128
+ getInsertHistoryRowsByRef(table: string, ref: string): Promise<InsertHistoryRow<any>[]>;
129
+ /**
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
135
+ */
136
+ getInsertHistoryRowByTimeId(table: string, timeId: InsertHistoryTimeId): Promise<InsertHistoryRow<any>>;
137
+ /**
138
+ * Get all timeIds for a specific ref in a table
139
+ * @param table - The table to get the timeIds from
140
+ * @param ref - The reference to get the timeIds for
141
+ * @returns An array of timeIds
142
+ * @throws {Error} If the Inserts table does not exist
143
+ */
144
+ getTimeIdsForRef(table: string, ref: Ref): Promise<InsertHistoryTimeId[]>;
145
+ /**
146
+ * Get the ref for a specific timeId in a table
147
+ * @param table - The table to get the ref from
148
+ * @param timeId - The timeId to get the ref for
149
+ * @returns The ref or null if it 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
164
+ */
165
+ isolatePropertyFromComponents(rljson: Rljson, propertyKey: string): Rljson;
166
+ /**
167
+ * Get the current cache of the Db instance
168
+ */
169
+ get cache(): Map<string, Rljson>;
22
170
  }