@fireproof/core 0.6.5 → 0.7.0-alpha.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.
- package/README.md +2 -2
- package/dist/{src/blockstore.js → blockstore.js} +7 -3
- package/dist/{src/database.js → database.js} +74 -48
- package/dist/{src/db-index.js → db-index.js} +2 -1
- package/dist/fireproof.js +81 -0
- package/dist/{src/loader.js → loader.js} +2 -3
- package/dist/{src/prolly.js → prolly.js} +1 -0
- package/dist/src/fireproof.d.ts +135 -134
- package/dist/src/fireproof.js +18168 -11485
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +18169 -11485
- package/dist/src/fireproof.mjs.map +1 -1
- package/dist/{src/storage → storage}/filesystem.js +2 -2
- package/dist/{src/sync.js → sync.js} +1 -1
- package/dist/valet.js +200 -0
- package/package.json +4 -5
- package/src/blockstore.js +6 -3
- package/src/database.js +80 -52
- package/src/db-index.js +2 -1
- package/src/fireproof.js +30 -31
- package/src/import.js +34 -0
- package/src/loader.js +26 -0
- package/src/prolly.js +2 -0
- package/src/storage/base.js +371 -0
- package/src/storage/browser.js +67 -0
- package/src/storage/filesystem.js +70 -0
- package/src/storage/rest.js +60 -0
- package/src/storage/ucan.js +0 -0
- package/src/sync.js +1 -1
- package/src/valet.js +57 -359
- package/dist/hooks/use-fireproof.js +0 -150
- package/dist/src/crypto-poly.js +0 -4
- package/dist/src/link.js +0 -1
- package/dist/src/valet.js +0 -476
- package/hooks/use-fireproof.js +0 -173
- package/src/listener.js +0 -119
- package/src/utils.js +0 -16
- /package/dist/{src/clock.js → clock.js} +0 -0
- /package/dist/{src/crypto.js → crypto.js} +0 -0
- /package/dist/{src/import.js → import.js} +0 -0
- /package/dist/{src/listener.js → listener.js} +0 -0
- /package/dist/{src/sha1.js → sha1.js} +0 -0
- /package/dist/{src/storage → storage}/base.js +0 -0
- /package/dist/{src/storage → storage}/browser.js +0 -0
- /package/dist/{src/storage → storage}/rest.js +0 -0
- /package/dist/{src/storage → storage}/ucan.js +0 -0
- /package/dist/{src/utils.js → utils.js} +0 -0
package/dist/src/fireproof.d.ts
CHANGED
@@ -1,67 +1,73 @@
|
|
1
1
|
import * as multiformats from 'multiformats';
|
2
2
|
import { Link, CID } from 'multiformats';
|
3
|
-
import * as
|
3
|
+
import * as multiformats_link from 'multiformats/link';
|
4
|
+
import * as _ipld_car_dist_src_api_js from '@ipld/car/dist/src/api.js';
|
5
|
+
import * as idb from 'idb';
|
4
6
|
|
5
7
|
type AnyLink = Link<unknown, number, number, 1|0>
|
6
8
|
|
7
|
-
declare class
|
8
|
-
constructor(name:
|
9
|
-
|
10
|
-
name: any;
|
11
|
-
uploadQueue: any;
|
12
|
-
alreadyEnqueued: Set<any>;
|
9
|
+
declare class Base {
|
10
|
+
constructor(name: any, config?: {});
|
11
|
+
valetRootCarCid: any;
|
13
12
|
keyMaterial: any;
|
14
13
|
keyId: string;
|
15
|
-
valetRoot: any;
|
16
|
-
valetRootCid: any;
|
17
|
-
valetRootCarCid: any;
|
18
|
-
valetCidBlocks: VMemoryBlockstore;
|
19
14
|
instanceId: string;
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
getKeyMaterial(): any;
|
15
|
+
name: any;
|
16
|
+
config: {};
|
17
|
+
ready: Promise<{}>;
|
18
|
+
setCarCidMapCarCid(carCid: any): void;
|
19
|
+
valetCarCidMap: Map<any, any>;
|
26
20
|
setKeyMaterial(km: any): void;
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
withDB: (dbWorkFun: any) => Promise<any>;
|
36
|
-
/**
|
37
|
-
* Iterate over all blocks in the store.
|
38
|
-
*
|
39
|
-
* @yields {{cid: string, value: Uint8Array}}
|
40
|
-
* @returns {AsyncGenerator<any, any, any>}
|
41
|
-
*/
|
42
|
-
cids(): AsyncGenerator<any, any, any>;
|
43
|
-
setRootCarCid(cid: any): void;
|
21
|
+
saveCar(carCid: any, value: any, cids: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
|
22
|
+
applyHeaders(headers: any): void;
|
23
|
+
headers: any;
|
24
|
+
getHeaders(): Promise<{}>;
|
25
|
+
loadHeader(branch?: string): void;
|
26
|
+
saveHeader(header: any): Promise<void>;
|
27
|
+
prepareHeader(header: any, json?: boolean): any;
|
28
|
+
writeHeader(branch: any, header: any): void;
|
44
29
|
getCarCIDForCID(cid: any): Promise<{
|
45
30
|
result: any;
|
46
31
|
}>;
|
47
|
-
|
32
|
+
readCar(carCid: any): Promise<Uint8Array>;
|
33
|
+
getLoaderBlock(dataCID: any): Promise<{
|
34
|
+
block: any;
|
35
|
+
reader: {
|
36
|
+
entries: () => Generator<any, void, unknown>;
|
37
|
+
root: any;
|
38
|
+
gat: (dataCID: any) => Promise<any>;
|
39
|
+
get: (dataCID: any) => Promise<any>;
|
40
|
+
} | {
|
41
|
+
entries: any;
|
42
|
+
root: any;
|
43
|
+
gat: (dataCID: any) => Promise<_ipld_car_dist_src_api_js.Block>;
|
44
|
+
get: (dataCID: any) => Promise<Uint8Array>;
|
45
|
+
};
|
46
|
+
carCid: any;
|
47
|
+
}>;
|
48
|
+
/** Private - internal **/
|
49
|
+
getCidCarMap(): Promise<Map<any, any>>;
|
50
|
+
mapForIPLDHashmapCarCid(carCid: any): Promise<Map<any, any>>;
|
51
|
+
getWriteableCarReader(carCid: any): Promise<{
|
52
|
+
blocks: VMemoryBlockstore;
|
48
53
|
root: any;
|
49
54
|
put: (cid: any, bytes: any) => Promise<void>;
|
50
55
|
get: (cid: any) => Promise<any>;
|
51
56
|
}>;
|
52
|
-
/**
|
53
|
-
*
|
54
|
-
* @param {string} carCid
|
55
|
-
* @param {*} value
|
56
|
-
*/
|
57
|
-
parkCar(carCid: string, value: any, cids: any): Promise<void>;
|
58
|
-
writeCars(cars: any): Promise<any>;
|
59
|
-
remoteBlockFunction: any;
|
60
57
|
getCarReader(carCid: any): Promise<{
|
58
|
+
entries: () => Generator<any, void, unknown>;
|
61
59
|
root: any;
|
60
|
+
gat: (dataCID: any) => Promise<any>;
|
62
61
|
get: (dataCID: any) => Promise<any>;
|
62
|
+
} | {
|
63
|
+
entries: any;
|
64
|
+
root: any;
|
65
|
+
gat: (dataCID: any) => Promise<_ipld_car_dist_src_api_js.Block>;
|
66
|
+
get: (dataCID: any) => Promise<Uint8Array>;
|
63
67
|
}>;
|
64
|
-
|
68
|
+
writeCars(cars: any): void;
|
69
|
+
updateCarCidMap(carCid: any, cids: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
|
70
|
+
persistCarMap(theCarMap: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
|
65
71
|
}
|
66
72
|
declare class VMemoryBlockstore {
|
67
73
|
/** @type {Map<string, Uint8Array>} */
|
@@ -72,16 +78,72 @@ declare class VMemoryBlockstore {
|
|
72
78
|
bytes: Uint8Array;
|
73
79
|
}>;
|
74
80
|
/**
|
75
|
-
* @param {
|
81
|
+
* @param {any} cid
|
76
82
|
* @param {Uint8Array} bytes
|
77
83
|
*/
|
78
|
-
put(cid:
|
84
|
+
put(cid: any, bytes: Uint8Array): Promise<void>;
|
79
85
|
entries(): Generator<{
|
80
|
-
cid:
|
86
|
+
cid: multiformats_link.Link<unknown, number, number, multiformats_link.Version>;
|
81
87
|
bytes: Uint8Array;
|
82
88
|
}, void, unknown>;
|
83
89
|
}
|
84
90
|
|
91
|
+
declare class Rest extends Base {
|
92
|
+
headerURL(branch?: string): string;
|
93
|
+
writeCars(cars: any): Promise<void>;
|
94
|
+
loadHeader(branch?: string): Promise<unknown>;
|
95
|
+
writeHeader(branch: any, header: any): Promise<void>;
|
96
|
+
}
|
97
|
+
|
98
|
+
declare class Filesystem extends Base {
|
99
|
+
writeCars(cars: any): Promise<void>;
|
100
|
+
readCar(carCid: any): Promise<any>;
|
101
|
+
loadHeader(branch?: string): any;
|
102
|
+
writeHeader(branch: any, header: any): Promise<void>;
|
103
|
+
headerFilename(branch?: string): any;
|
104
|
+
}
|
105
|
+
|
106
|
+
declare class Browser extends Base {
|
107
|
+
isBrowser: boolean;
|
108
|
+
withDB: (dbWorkFun: any) => Promise<any>;
|
109
|
+
idb: idb.IDBPDatabase<unknown>;
|
110
|
+
writeCars(cars: any): Promise<any>;
|
111
|
+
readCar(carCid: any): Promise<any>;
|
112
|
+
loadHeader(branch?: string): string;
|
113
|
+
writeHeader(branch: any, header: any): Promise<void>;
|
114
|
+
headerKey(branch?: string): string;
|
115
|
+
}
|
116
|
+
|
117
|
+
declare class Valet {
|
118
|
+
constructor(name?: string, config?: {});
|
119
|
+
idb: any;
|
120
|
+
name: any;
|
121
|
+
uploadQueue: any;
|
122
|
+
alreadyEnqueued: Set<any>;
|
123
|
+
instanceId: string;
|
124
|
+
primary: Browser | Filesystem | Rest;
|
125
|
+
secondary: Browser | Filesystem | Rest;
|
126
|
+
ready: Promise<{}[]>;
|
127
|
+
saveHeader(header: any): Promise<void>;
|
128
|
+
/**
|
129
|
+
* Group the blocks into a car and write it to the valet.
|
130
|
+
* @param {import('./blockstore.js').InnerBlockstore} innerBlockstore
|
131
|
+
* @param {Set<string>} cids
|
132
|
+
* @returns {Promise<void>}
|
133
|
+
* @memberof Valet
|
134
|
+
*/
|
135
|
+
writeTransaction(innerBlockstore: InnerBlockstore, cids: Set<string>): Promise<void>;
|
136
|
+
/**
|
137
|
+
* Iterate over all blocks in the store.
|
138
|
+
*
|
139
|
+
* @yields {{cid: string, value: Uint8Array}}
|
140
|
+
* @returns {AsyncGenerator<any, any, any>}
|
141
|
+
*/
|
142
|
+
cids(): AsyncGenerator<any, any, any>;
|
143
|
+
remoteBlockFunction: any;
|
144
|
+
getValetBlock(dataCID: any): Promise<any>;
|
145
|
+
}
|
146
|
+
|
85
147
|
/**
|
86
148
|
* @typedef {{ get: (link: import('../src/link').AnyLink) => Promise<AnyBlock | undefined> }} BlockFetcher
|
87
149
|
*/
|
@@ -97,7 +159,7 @@ declare class VMemoryBlockstore {
|
|
97
159
|
* A blockstore that caches writes to a transaction and only persists them when committed.
|
98
160
|
*/
|
99
161
|
declare class TransactionBlockstore {
|
100
|
-
constructor(name: any,
|
162
|
+
constructor(name: any, config: any);
|
101
163
|
/** @type {Map<string, Uint8Array>} */
|
102
164
|
committedBlocks: Map<string, Uint8Array>;
|
103
165
|
/** @type {Valet} */
|
@@ -105,6 +167,7 @@ declare class TransactionBlockstore {
|
|
105
167
|
instanceId: string;
|
106
168
|
inflightTransactions: Set<any>;
|
107
169
|
syncs: Set<any>;
|
170
|
+
ready: Promise<void> | Promise<{}[]>;
|
108
171
|
remoteBlockFunction: any;
|
109
172
|
/**
|
110
173
|
* Get a block from the store.
|
@@ -201,17 +264,18 @@ type AnyBlock = {
|
|
201
264
|
*
|
202
265
|
*/
|
203
266
|
declare class Database {
|
204
|
-
constructor(name: any,
|
267
|
+
constructor(name: any, config?: {});
|
205
268
|
listeners: Set<any>;
|
206
269
|
indexes: Map<any, any>;
|
207
270
|
rootCache: any;
|
208
271
|
eventsCache: Map<any, any>;
|
209
272
|
name: any;
|
273
|
+
clock: any[];
|
210
274
|
instanceId: string;
|
211
275
|
blocks: TransactionBlockstore;
|
212
276
|
indexBlocks: TransactionBlockstore;
|
213
|
-
clock: any;
|
214
277
|
config: {};
|
278
|
+
ready: Promise<void>;
|
215
279
|
/**
|
216
280
|
* Renders the Fireproof instance as a JSON object.
|
217
281
|
* @returns {Object} - The JSON representation of the Fireproof instance. Includes clock heads for the database and its indexes.
|
@@ -219,6 +283,15 @@ declare class Database {
|
|
219
283
|
* @instance
|
220
284
|
*/
|
221
285
|
toJSON(): any;
|
286
|
+
toHeader(): {
|
287
|
+
clock: string[];
|
288
|
+
name: any;
|
289
|
+
index: {
|
290
|
+
key: any;
|
291
|
+
car: any;
|
292
|
+
};
|
293
|
+
indexes: any[];
|
294
|
+
};
|
222
295
|
/**
|
223
296
|
* Returns the Merkle clock heads for the Fireproof instance.
|
224
297
|
* @returns {string[]} - The Merkle clock heads for the Fireproof instance.
|
@@ -226,13 +299,6 @@ declare class Database {
|
|
226
299
|
* @instance
|
227
300
|
*/
|
228
301
|
clockToJSON(clock?: any): string[];
|
229
|
-
hydrate({ clock, name, key, car, indexCar }: {
|
230
|
-
clock: any;
|
231
|
-
name: any;
|
232
|
-
key: any;
|
233
|
-
car: any;
|
234
|
-
indexCar: any;
|
235
|
-
}): void;
|
236
302
|
maybeSaveClock(): void;
|
237
303
|
index(name: any): any;
|
238
304
|
/**
|
@@ -266,16 +332,6 @@ declare class Database {
|
|
266
332
|
}>;
|
267
333
|
allCIDs(): Promise<any[]>;
|
268
334
|
allStoredCIDs(): Promise<any[]>;
|
269
|
-
/**
|
270
|
-
* Runs validation on the specified document using the Fireproof instance's configuration. Throws an error if the document is invalid.
|
271
|
-
*
|
272
|
-
* @param {Object} doc - The document to validate.
|
273
|
-
* @returns {Promise<void>}
|
274
|
-
* @throws {Error} - Throws an error if the document is invalid.
|
275
|
-
* @memberof Fireproof
|
276
|
-
* @instance
|
277
|
-
*/
|
278
|
-
runValidation(doc: any): Promise<void>;
|
279
335
|
/**
|
280
336
|
* Retrieves the document with the specified ID from the database
|
281
337
|
*
|
@@ -318,6 +374,16 @@ declare class Database {
|
|
318
374
|
id: string;
|
319
375
|
clock: CID[];
|
320
376
|
}>;
|
377
|
+
/**
|
378
|
+
* Runs validation on the specified document using the Fireproof instance's configuration. Throws an error if the document is invalid.
|
379
|
+
*
|
380
|
+
* @param {Object} doc - The document to validate.
|
381
|
+
* @returns {Promise<void>}
|
382
|
+
* @throws {Error} - Throws an error if the document is invalid.
|
383
|
+
* @memberof Fireproof
|
384
|
+
* @instance
|
385
|
+
*/
|
386
|
+
runValidation(doc: any): Promise<void>;
|
321
387
|
/**
|
322
388
|
* Updates the underlying storage with the specified event.
|
323
389
|
* @private
|
@@ -358,7 +424,6 @@ declare class Database {
|
|
358
424
|
*/
|
359
425
|
registerListener(listener: Function): Function;
|
360
426
|
notifyListeners(changes: any): Promise<void>;
|
361
|
-
setCarUploader(carUploaderFn: any): void;
|
362
427
|
setRemoteBlockReader(remoteBlockReaderFn: any): void;
|
363
428
|
}
|
364
429
|
|
@@ -461,69 +526,6 @@ declare class DbIndex {
|
|
461
526
|
private updateIndex;
|
462
527
|
innerUpdateIndex(inBlocks: any): Promise<any>;
|
463
528
|
}
|
464
|
-
/**
|
465
|
-
* JDoc for the result row type.
|
466
|
-
*/
|
467
|
-
type ChangeEvent = {
|
468
|
-
/**
|
469
|
-
* - The key of the document.
|
470
|
-
*/
|
471
|
-
key: string;
|
472
|
-
/**
|
473
|
-
* - The new value of the document.
|
474
|
-
*/
|
475
|
-
value: any;
|
476
|
-
/**
|
477
|
-
* - Is the row deleted?
|
478
|
-
*/
|
479
|
-
del?: boolean;
|
480
|
-
};
|
481
|
-
|
482
|
-
/**
|
483
|
-
* A Fireproof database Listener allows you to react to events in the database.
|
484
|
-
*
|
485
|
-
* @class Listener
|
486
|
-
* @classdesc An listener attaches to a Fireproof database and runs a routing function on each change, sending the results to subscribers.
|
487
|
-
*
|
488
|
-
* @param {import('./database.js').Database} database - The Database database instance to index.
|
489
|
-
* @param {Function} routingFn - The routing function to apply to each entry in the database.
|
490
|
-
*/
|
491
|
-
/**
|
492
|
-
* @deprecated since version 0.7.0
|
493
|
-
*/
|
494
|
-
declare class Listener {
|
495
|
-
/**
|
496
|
-
* @param {import('./database.js').Database} database
|
497
|
-
* @param {(_: any, emit: any) => void} routingFn
|
498
|
-
*/
|
499
|
-
constructor(database: Database, routingFn?: (_: any, emit: any) => void);
|
500
|
-
subcribers: Map<any, any>;
|
501
|
-
doStopListening: any;
|
502
|
-
database: Database;
|
503
|
-
/**
|
504
|
-
* The map function to apply to each entry in the database.
|
505
|
-
* @type {Function}
|
506
|
-
*/
|
507
|
-
routingFn: Function;
|
508
|
-
dbHead: any;
|
509
|
-
/**
|
510
|
-
* Subscribe to a topic emitted by the event function.
|
511
|
-
* @param {string} topic - The topic to subscribe to.
|
512
|
-
* @param {Function} subscriber - The function to call when the topic is emitted.
|
513
|
-
* @returns {Function} A function to unsubscribe from the topic.
|
514
|
-
* @memberof Listener
|
515
|
-
* @instance
|
516
|
-
* @param {any} [since] - clock to flush from on launch, pass null for all
|
517
|
-
*/
|
518
|
-
on(topic: string, subscriber: Function, since?: any): Function;
|
519
|
-
/**
|
520
|
-
* @typedef {import('./db-index').ChangeEvent} ChangeEvent
|
521
|
-
*/
|
522
|
-
/**
|
523
|
-
* @param {ChangeEvent[]} changes
|
524
|
-
*/
|
525
|
-
onChanges(changes: ChangeEvent[]): void;
|
526
|
-
}
|
527
529
|
|
528
530
|
/**
|
529
531
|
* @typedef {import('./database.js').Database} Database
|
@@ -570,10 +572,9 @@ declare class Fireproof {
|
|
570
572
|
* @returns {Database} - a new Fireproof instance
|
571
573
|
*/
|
572
574
|
static storage: (name?: any, opts?: {}) => Database;
|
573
|
-
static
|
574
|
-
static fromJSON(json: any, database: any): any;
|
575
|
+
static fromJSON(primary: any, secondary: any, database: any): any;
|
575
576
|
static snapshot(database: any, clock: any): any;
|
576
577
|
static zoom(database: any, clock: any): Promise<any>;
|
577
578
|
}
|
578
579
|
|
579
|
-
export { Database, Fireproof, DbIndex as Index,
|
580
|
+
export { Database, Fireproof, DbIndex as Index, Sync };
|