@rljson/db 0.0.7 → 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 CHANGED
@@ -1,11 +1,25 @@
1
1
  import { Io } from '@rljson/io';
2
- import { Json } from '@rljson/json';
3
- import { Insert, InsertHistoryRow, InsertHistoryTimeId, Ref, Rljson, Route, TableKey } from '@rljson/rljson';
4
- import { Controller, ControllerRefs } from './controller/controller.ts';
2
+ import { Json, JsonValue } from '@rljson/json';
3
+ import { Edit, EditHistory, InsertHistoryRow, InsertHistoryTimeId, MultiEdit, Ref, Rljson, Route, SliceId, TableType } from '@rljson/rljson';
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
+ export type Cell = {
10
+ route: Route;
11
+ value: JsonValue | JsonValue[] | null;
12
+ row: JsonValue | JsonValue[] | null;
13
+ path: Array<Array<string | number>>;
14
+ };
15
+ export type Container = {
16
+ rljson: Rljson;
17
+ tree: Json;
18
+ cell: Cell[];
19
+ };
20
+ export type ContainerWithControllers = Container & {
21
+ controllers: Record<string, Controller<any, any, any>>;
22
+ };
9
23
  /**
10
24
  * Access Rljson data
11
25
  */
@@ -29,10 +43,12 @@ export declare class Db {
29
43
  * Get data from a route with optional filtering
30
44
  * @param route - The route to get data from
31
45
  * @param where - Optional filter to apply to the data
46
+ * @param filter - Optional filter to apply to child entries in related tables
47
+ * @param sliceIds - Optional slice IDs to filter the data
32
48
  * @returns An array of Rljson objects matching the route and filter
33
49
  * @throws {Error} If the route is not valid or if any controller cannot be created
34
50
  */
35
- get(route: Route, where: string | Json): Promise<Rljson>;
51
+ get(route: Route, where: string | Json, filter?: ControllerChildProperty[], sliceIds?: SliceId[]): Promise<ContainerWithControllers>;
36
52
  /**
37
53
  * Resolves the route and returns corresponding data for any segment of the route,
38
54
  * matching recursive filters and where clauses
@@ -41,13 +57,10 @@ export declare class Db {
41
57
  * @param where - The recursive filtering key/value pairs to apply to the data
42
58
  * @param controllers - The controllers to use for fetching data
43
59
  * @param filter - Optional filter to apply to the data at the current route segment
60
+ * @param sliceIds - Optional slice IDs to filter the data at the current route segment
44
61
  * @returns - An Rljson object matching the route and filters
45
62
  */
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>;
63
+ _get(route: Route, where: string | Json, controllers: Record<string, Controller<any, any, any>>, filter?: ControllerChildProperty[], sliceIds?: SliceId[], routeAccumulator?: Route): Promise<Container>;
51
64
  /**
52
65
  * Get the reference (hash) of a route segment, considering default refs and insertHistory refs
53
66
  * @param segment - The route segment to get the reference for
@@ -59,27 +72,14 @@ export declare class Db {
59
72
  * @param rljson - The Rljson to join data for
60
73
  */
61
74
  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
74
- */
75
- private _getBaseDataForColumnSelection;
75
+ private _resolveSliceIds;
76
76
  /**
77
77
  * Runs an Insert by executing the appropriate controller(s) based on the Insert's route
78
78
  * @param Insert - The Insert to run
79
79
  * @returns The result of the Insert as an InsertHistoryRow
80
80
  * @throws {Error} If the Insert is not valid or if any controller cannot be created
81
81
  */
82
- insert(insert: Insert<any>, options?: {
82
+ insert(route: Route, tree: Json, options?: {
83
83
  skipNotification?: boolean;
84
84
  skipHistory?: boolean;
85
85
  }): Promise<InsertHistoryRow<any>[]>;
@@ -97,26 +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: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
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: (InsertHistoryRow: InsertHistoryRow<any>) => void): void;
107
- /**
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
110
- * @returns A record of controller run functions, keyed by table name
111
- * @throws {Error} If the route is not valid or if any controller cannot be created
112
- */
113
- private _resolveInsert;
114
- /**
115
- * Returns the keys of child refs in a value based on a route
116
- * @param value - The value to check
117
- * @returns An array of keys of child refs in the value
118
- */
119
- private _childKeys;
106
+ unregisterObserver(route: Route, callback: NotifyCallback<any>): void;
120
107
  /**
121
108
  * Get a controller for a specific table
122
109
  * @param tableKey - The key of the table to get the controller for
@@ -124,8 +111,8 @@ export declare class Db {
124
111
  * @returns A controller for the specified table
125
112
  * @throws {Error} If the table does not exist or if the table type is not supported
126
113
  */
127
- getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<any, string>>;
128
- private _indexedControllers;
114
+ getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<TableType, any, string>>;
115
+ indexedControllers(route: Route): Promise<Record<string, Controller<any, any, any>>>;
129
116
  /**
130
117
  * Adds an InsertHistory row to the InsertHistory table of a table
131
118
  * @param table - The table the Insert was made on
@@ -133,6 +120,48 @@ export declare class Db {
133
120
  * @throws {Error} If the InsertHistory table does not exist
134
121
  */
135
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[]>;
136
165
  /**
137
166
  * Get the InsertHistory of a table
138
167
  * @param table - The table to get the InsertHistory for
@@ -190,5 +219,5 @@ export declare class Db {
190
219
  /**
191
220
  * Get the current cache of the Db instance
192
221
  */
193
- get cache(): Map<string, Rljson>;
222
+ get cache(): Map<string, Container>;
194
223
  }