@fireproof/core 0.3.22 → 0.4.1

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,3 +1,98 @@
1
+ /**
2
+ * Represents an DbIndex for a Fireproof database.
3
+ *
4
+ * @class DbIndex
5
+ * @classdesc An DbIndex can be used to order and filter the documents in a Fireproof database.
6
+ *
7
+ * @param {Database} database - The Fireproof database instance to DbIndex.
8
+ * @param {Function} mapFn - The map function to apply to each entry in the database.
9
+ *
10
+ */
11
+ declare class DbIndex {
12
+ static registerWithDatabase(inIndex: any, database: any): void;
13
+ static fromJSON(database: any, { code, clock, name }: {
14
+ code: any;
15
+ clock: any;
16
+ name: any;
17
+ }): DbIndex;
18
+ constructor(database: any, mapFn: any, clock: any, opts?: {});
19
+ database: any;
20
+ mapFnString: any;
21
+ mapFn: any;
22
+ name: any;
23
+ indexById: {
24
+ root: any;
25
+ cid: any;
26
+ };
27
+ indexByKey: {
28
+ root: any;
29
+ cid: any;
30
+ };
31
+ dbHead: any;
32
+ instanceId: string;
33
+ updateIndexPromise: Promise<void>;
34
+ makeName(): any;
35
+ toJSON(): {
36
+ name: any;
37
+ code: any;
38
+ clock: {
39
+ db: any;
40
+ byId: any;
41
+ byKey: any;
42
+ };
43
+ };
44
+ /**
45
+ * JSDoc for Query type.
46
+ * @typedef {Object} DbQuery
47
+ * @property {string[]} [range] - The range to query.
48
+ * @memberof DbIndex
49
+ */
50
+ /**
51
+ * Query object can have {range}
52
+ * @param {DbQuery} query - the query range to use
53
+ * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
54
+ * @memberof DbIndex
55
+ * @instance
56
+ */
57
+ query(query: {
58
+ /**
59
+ * - The range to query.
60
+ */
61
+ range?: string[];
62
+ }, update?: boolean): Promise<{
63
+ proof: {};
64
+ rows: Array<{
65
+ id: string;
66
+ key: string;
67
+ value: any;
68
+ }>;
69
+ }>;
70
+ /**
71
+ * Update the DbIndex with the latest changes
72
+ * @private
73
+ * @returns {Promise<void>}
74
+ */
75
+ private updateIndex;
76
+ innerUpdateIndex(inBlocks: any): Promise<void>;
77
+ }
78
+ /**
79
+ * JDoc for the result row type.
80
+ */
81
+ type ChangeEvent = {
82
+ /**
83
+ * - The key of the document.
84
+ */
85
+ key: string;
86
+ /**
87
+ * - The new value of the document.
88
+ */
89
+ value: any;
90
+ /**
91
+ * - Is the row deleted?
92
+ */
93
+ del?: boolean;
94
+ };
95
+
1
96
  /**
2
97
  * @class Fireproof
3
98
  * @classdesc Fireproof stores data in IndexedDB and provides a Merkle clock.
@@ -10,24 +105,14 @@
10
105
  * @param {object} [authCtx] - Optional authorization context object to use for any authentication checks.
11
106
  *
12
107
  */
13
- declare class Fireproof {
14
- /**
15
- * @function storage
16
- * @memberof Fireproof
17
- * Creates a new Fireproof instance with default storage settings
18
- * Most apps should use this and not worry about the details.
19
- * @static
20
- * @returns {Fireproof} - a new Fireproof instance
21
- */
22
- static storage: (name?: string) => Fireproof;
23
- constructor(blocks: any, clock: any, config: any, authCtx?: {});
108
+ declare class Database$1 {
109
+ constructor(blocks: any, clock: any, config?: {});
24
110
  listeners: Set<any>;
25
111
  name: any;
26
112
  instanceId: string;
27
113
  blocks: any;
28
114
  clock: any;
29
- config: any;
30
- authCtx: {};
115
+ config: {};
31
116
  indexes: Map<any, any>;
32
117
  /**
33
118
  * Renders the Fireproof instance as a JSON object.
@@ -49,6 +134,7 @@ declare class Fireproof {
49
134
  key: any;
50
135
  }): void;
51
136
  indexBlocks: any;
137
+ maybeSaveClock(): void;
52
138
  /**
53
139
  * Triggers a notification to all listeners
54
140
  * of the Fireproof instance so they can repaint UI, etc.
@@ -101,21 +187,46 @@ declare class Fireproof {
101
187
  get(key: string, opts?: any): Promise<{
102
188
  _id: string;
103
189
  }>;
190
+ /**
191
+ * @typedef {Object} Document
192
+ * @property {string} _id - The ID of the document (required)
193
+ * @property {string} [_proof] - The proof of the document (optional)
194
+ * @property {string} [_clock] - The clock of the document (optional)
195
+ * @property {any} [key: string] - Index signature notation to allow any other unknown fields
196
+ * * @property {Object.<string, any>} [otherProperties] - Any other unknown properties (optional)
197
+ */
104
198
  /**
105
199
  * Adds a new document to the database, or updates an existing document. Returns the ID of the document and the new clock head.
106
200
  *
107
- * @param {Object} doc - the document to be added
108
- * @param {string} doc._id - the document ID. If not provided, a random ID will be generated.
109
- * @param {CID[]} doc._clock - the document ID. If not provided, a random ID will be generated.
110
- * @param {Proof} doc._proof - CIDs referenced by the update
201
+ * @param {Document} doc - the document to be added
111
202
  * @returns {Promise<{ id: string, clock: CID[] }>} - The result of adding the document to the database
112
203
  * @memberof Fireproof
113
204
  * @instance
114
205
  */
115
206
  put({ _id, _proof, ...doc }: {
207
+ /**
208
+ * - The ID of the document (required)
209
+ */
116
210
  _id: string;
117
- _clock: CID[];
118
- _proof: Proof;
211
+ /**
212
+ * - The proof of the document (optional)
213
+ */
214
+ _proof?: string;
215
+ /**
216
+ * - The clock of the document (optional)
217
+ */
218
+ _clock?: string;
219
+ /**
220
+ * : string] - Index signature notation to allow any other unknown fields
221
+ * *
222
+ */
223
+ key?: any;
224
+ /**
225
+ * - Any other unknown properties (optional)
226
+ */
227
+ otherProperties?: {
228
+ [x: string]: any;
229
+ };
119
230
  }): Promise<{
120
231
  id: string;
121
232
  clock: CID[];
@@ -171,103 +282,6 @@ declare class Fireproof {
171
282
  setCarUploader(carUploaderFn: any): void;
172
283
  setRemoteBlockReader(remoteBlockReaderFn: any): void;
173
284
  }
174
- declare class Proof {
175
- }
176
-
177
- /**
178
- * Represents an DbIndex for a Fireproof database.
179
- *
180
- * @class DbIndex
181
- * @classdesc An DbIndex can be used to order and filter the documents in a Fireproof database.
182
- *
183
- * @param {Fireproof} database - The Fireproof database instance to DbIndex.
184
- * @param {Function} mapFn - The map function to apply to each entry in the database.
185
- *
186
- */
187
- declare class DbIndex {
188
- static registerWithDatabase(inIndex: any, database: any): void;
189
- static fromJSON(database: any, { code, clock, name }: {
190
- code: any;
191
- clock: any;
192
- name: any;
193
- }): DbIndex;
194
- constructor(database: any, mapFn: any, clock: any, opts?: {});
195
- database: any;
196
- mapFnString: any;
197
- mapFn: any;
198
- name: any;
199
- indexById: {
200
- root: any;
201
- cid: any;
202
- };
203
- indexByKey: {
204
- root: any;
205
- cid: any;
206
- };
207
- dbHead: any;
208
- instanceId: string;
209
- updateIndexPromise: Promise<void>;
210
- makeName(): any;
211
- toJSON(): {
212
- name: any;
213
- code: any;
214
- clock: {
215
- db: any;
216
- byId: any;
217
- byKey: any;
218
- };
219
- };
220
- /**
221
- * JSDoc for Query type.
222
- * @typedef {Object} DbQuery
223
- * @property {string[]} [range] - The range to query.
224
- * @memberof DbIndex
225
- */
226
- /**
227
- * Query object can have {range}
228
- * @param {DbQuery} query - the query range to use
229
- * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
230
- * @memberof DbIndex
231
- * @instance
232
- */
233
- query(query: {
234
- /**
235
- * - The range to query.
236
- */
237
- range?: string[];
238
- }, update?: boolean): Promise<{
239
- proof: {};
240
- rows: Array<{
241
- id: string;
242
- key: string;
243
- value: any;
244
- }>;
245
- }>;
246
- /**
247
- * Update the DbIndex with the latest changes
248
- * @private
249
- * @returns {Promise<void>}
250
- */
251
- private updateIndex;
252
- innerUpdateIndex(inBlocks: any): Promise<void>;
253
- }
254
- /**
255
- * JDoc for the result row type.
256
- */
257
- type ChangeEvent = {
258
- /**
259
- * - The key of the document.
260
- */
261
- key: string;
262
- /**
263
- * - The new value of the document.
264
- */
265
- value: any;
266
- /**
267
- * - Is the row deleted?
268
- */
269
- del?: boolean;
270
- };
271
285
 
272
286
  /**
273
287
  * A Fireproof database Listener allows you to react to events in the database.
@@ -275,18 +289,18 @@ type ChangeEvent = {
275
289
  * @class Listener
276
290
  * @classdesc An listener attaches to a Fireproof database and runs a routing function on each change, sending the results to subscribers.
277
291
  *
278
- * @param {import('./fireproof.js').Fireproof} database - The Fireproof database instance to index.
292
+ * @param {import('./database.js').Database} database - The Database database instance to index.
279
293
  * @param {Function} routingFn - The routing function to apply to each entry in the database.
280
294
  */
281
295
  declare class Listener {
282
296
  /**
283
- * @param {import('./fireproof.js').Fireproof} database
297
+ * @param {import('./database.js').Database} database
284
298
  * @param {(_: any, emit: any) => void} routingFn
285
299
  */
286
- constructor(database: Fireproof, routingFn: (_: any, emit: any) => void);
300
+ constructor(database: Database$1, routingFn?: (_: any, emit: any) => void);
287
301
  subcribers: Map<any, any>;
288
302
  doStopListening: any;
289
- database: Fireproof;
303
+ database: Database$1;
290
304
  /**
291
305
  * The map function to apply to each entry in the database.
292
306
  * @type {Function}
@@ -312,10 +326,19 @@ declare class Listener {
312
326
  onChanges(changes: ChangeEvent[]): void;
313
327
  }
314
328
 
315
- declare class Hydrator {
329
+ declare class Fireproof {
330
+ /**
331
+ * @function storage
332
+ * @memberof Fireproof
333
+ * Creates a new Fireproof instance with default storage settings
334
+ * Most apps should use this and not worry about the details.
335
+ * @static
336
+ * @returns {Database} - a new Fireproof instance
337
+ */
338
+ static storage: (name?: any, opts?: {}) => Database;
316
339
  static fromJSON(json: any, database: any): any;
317
340
  static snapshot(database: any, clock: any): any;
318
341
  static zoom(database: any, clock: any): Promise<any>;
319
342
  }
320
343
 
321
- export { Fireproof, Hydrator, DbIndex as Index, Listener };
344
+ export { Fireproof, DbIndex as Index, Listener };