@rljson/db 0.0.3 → 0.0.5

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,9 @@
1
1
  import { Io } from '@rljson/io';
2
+ import { Json } from '@rljson/json';
3
+ import { Edit, EditProtocolRow, EditProtocolTimeId, Ref, Rljson, Route } from '@rljson/rljson';
4
+ import { Controller, ControllerRefs } from './controller/controller.ts';
2
5
  import { Core } from './core.ts';
6
+ import { Notify } from './notify.ts';
3
7
  /**
4
8
  * Access Rljson data
5
9
  */
@@ -14,6 +18,127 @@ export declare class Db {
14
18
  * Core functionalities like importing data, setting and getting tables
15
19
  */
16
20
  readonly core: Core;
21
+ /**
22
+ * Notification system to register callbacks on data changes
23
+ */
24
+ readonly notify: Notify;
25
+ /**
26
+ * Get data from a route with optional filtering
27
+ * @param route - The route to get data from
28
+ * @param where - Optional filter to apply to the data
29
+ * @returns An array of Rljson objects matching the route and filter
30
+ * @throws {Error} If the route is not valid or if any controller cannot be created
31
+ */
32
+ get(route: Route, where: string | Json): Promise<Rljson[]>;
33
+ /**
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
39
+ */
40
+ private _get;
41
+ /**
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
46
+ */
47
+ run(edit: Edit<any>, options?: {
48
+ skipNotification?: boolean;
49
+ }): Promise<EditProtocolRow<any>>;
50
+ /**
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
54
+ * @param runFns - A record of controller run functions, keyed by table name
55
+ * @returns The result of the edit
56
+ * @throws {Error} If the route is not valid or if any controller cannot be created
57
+ */
58
+ private _run;
59
+ /**
60
+ * Registers a callback to be called when an edit is made on the given route
61
+ * @param route - The route to register the callback on
62
+ * @param callback - The callback to be called when an edit is made
63
+ */
64
+ registerObserver(route: Route, callback: (EditProtocolRow: EditProtocolRow<any>) => void): void;
65
+ /**
66
+ * Unregisters a callback from the given route
67
+ * @param route - The route to unregister the callback from
68
+ * @param callback - The callback to be unregistered
69
+ */
70
+ unregisterObserver(route: Route, callback: (EditProtocolRow: EditProtocolRow<any>) => void): void;
71
+ /**
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
74
+ * @returns A record of controller run functions, keyed by table name
75
+ * @throws {Error} If the route is not valid or if any controller cannot be created
76
+ */
77
+ private _resolveRuns;
78
+ /**
79
+ * Returns the keys of child refs in a value based on a route
80
+ * @param route - The route to check
81
+ * @param value - The value to check
82
+ * @returns An array of keys of child refs in the value
83
+ */
84
+ private _childKeys;
85
+ /**
86
+ * Get a controller for a specific table
87
+ * @param tableKey - The key of the table to get the controller for
88
+ * @param refs - Optional references required by some controllers
89
+ * @returns A controller for the specified table
90
+ * @throws {Error} If the table does not exist or if the table type is not supported
91
+ */
92
+ getController(tableKey: string, refs?: ControllerRefs): Promise<Controller<any, string>>;
93
+ private _indexedControllers;
94
+ /**
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
99
+ */
100
+ private _writeProtocol;
101
+ /**
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
105
+ */
106
+ getProtocol(table: string, options?: {
107
+ sorted?: boolean;
108
+ ascending?: boolean;
109
+ }): Promise<Rljson>;
110
+ /**
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
116
+ */
117
+ getProtocolRowsByRef(table: string, ref: string): Promise<EditProtocolRow<any>[] | null>;
118
+ /**
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
124
+ */
125
+ getProtocolRowByTimeId(table: string, timeId: EditProtocolTimeId): Promise<EditProtocolRow<any> | null>;
126
+ /**
127
+ * Get all timeIds for a specific ref in a table
128
+ * @param table - The table to get the timeIds from
129
+ * @param ref - The reference to get the timeIds for
130
+ * @returns An array of timeIds
131
+ * @throws {Error} If the edits table does not exist
132
+ */
133
+ getTimeIdsForRef(table: string, ref: Ref): Promise<EditProtocolTimeId[]>;
134
+ /**
135
+ * Get the ref for a specific timeId in a table
136
+ * @param table - The table to get the ref from
137
+ * @param timeId - The timeId to get the ref for
138
+ * @returns The ref or null if it does not exist
139
+ * @throws {Error} If the edits table does not exist
140
+ */
141
+ getRefOfTimeId(table: string, timeId: EditProtocolTimeId): Promise<Ref | null>;
17
142
  /**
18
143
  * Example
19
144
  * @returns A new Db instance for test purposes