@fireproof/core 0.3.2 → 0.3.3
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 +1 -1
- package/dist/src/blockstore.d.ts +115 -0
- package/dist/src/blockstore.d.ts.map +1 -0
- package/dist/src/clock.d.ts +98 -0
- package/dist/src/clock.d.ts.map +1 -0
- package/dist/src/crypto.d.ts +18 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/db-index.d.ts +116 -0
- package/dist/src/db-index.d.ts.map +1 -0
- package/dist/src/fireproof.d.ts +167 -0
- package/dist/src/fireproof.d.ts.map +1 -0
- package/dist/src/hydrator.d.ts +6 -0
- package/dist/src/hydrator.d.ts.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/listener.d.ts +36 -0
- package/dist/src/listener.d.ts.map +1 -0
- package/dist/src/prolly.d.ts +83 -0
- package/dist/src/prolly.d.ts.map +1 -0
- package/dist/src/sha1.d.ts +9 -0
- package/dist/src/sha1.d.ts.map +1 -0
- package/dist/src/valet.d.ts +34 -0
- package/dist/src/valet.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +33 -3
- package/src/blockstore.js +3 -2
- package/src/clock.js +4 -3
- package/src/crypto.js +1 -0
- package/src/db-index.js +10 -5
- package/src/fireproof.js +15 -10
- package/src/hydrator.js +3 -3
- package/src/index.js +6 -0
- package/src/listener.js +2 -1
- package/src/prolly.js +11 -24
- package/src/sha1.js +2 -1
- package/src/valet.js +7 -5
- package/hooks/use-fireproof.js +0 -135
- package/index.js +0 -6
- package/scripts/keygen.js +0 -3
- package/test/block.js +0 -65
- package/test/clock.test.js +0 -694
- package/test/db-index.test.js +0 -261
- package/test/fireproof.test.js +0 -493
- package/test/fulltext.test.js +0 -66
- package/test/helpers.js +0 -45
- package/test/hydrator.test.js +0 -81
- package/test/listener.test.js +0 -102
- package/test/prolly.test.js +0 -190
- package/test/proofs.test.js +0 -53
- package/test/reproduce-fixture-bug.test.js +0 -65
- package/test/valet.test.js +0 -59
package/README.md
CHANGED
@@ -18,7 +18,7 @@ Fireproof is alpha software, you should only use it if you are planning to contr
|
|
18
18
|
## Usage
|
19
19
|
|
20
20
|
```js
|
21
|
-
import Fireproof from 'fireproof';
|
21
|
+
import { Fireproof } from 'fireproof';
|
22
22
|
|
23
23
|
async function main() {
|
24
24
|
const database = Fireproof.storage('my-db');
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {Object} AnyBlock
|
3
|
+
* @property {import('./link').AnyLink} cid - The CID of the block
|
4
|
+
* @property {Uint8Array} bytes - The block's data
|
5
|
+
*
|
6
|
+
* @typedef {Object} Blockstore
|
7
|
+
* @property {function(import('./link').AnyLink): Promise<AnyBlock|undefined>} get - A function to retrieve a block by CID
|
8
|
+
* @property {function(import('./link').AnyLink, Uint8Array): Promise<void>} put - A function to store a block's data and CID
|
9
|
+
*
|
10
|
+
* A blockstore that caches writes to a transaction and only persists them when committed.
|
11
|
+
* @implements {Blockstore}
|
12
|
+
*/
|
13
|
+
export class TransactionBlockstore implements Blockstore {
|
14
|
+
constructor(name: any, encryptionKey: any);
|
15
|
+
/** @type {Map<string, Uint8Array>} */
|
16
|
+
committedBlocks: Map<string, Uint8Array>;
|
17
|
+
valet: any;
|
18
|
+
instanceId: string;
|
19
|
+
inflightTransactions: Set<any>;
|
20
|
+
/**
|
21
|
+
* Get a block from the store.
|
22
|
+
*
|
23
|
+
* @param {import('./link').AnyLink} cid
|
24
|
+
* @returns {Promise<AnyBlock | undefined>}
|
25
|
+
*/
|
26
|
+
get(cid: import('./link').AnyLink): Promise<AnyBlock | undefined>;
|
27
|
+
transactionsGet(key: any): Promise<any>;
|
28
|
+
committedGet(key: any): Promise<any>;
|
29
|
+
clearCommittedCache(): Promise<void>;
|
30
|
+
networkGet(key: any): Promise<any>;
|
31
|
+
/**
|
32
|
+
* Add a block to the store. Usually bound to a transaction by a closure.
|
33
|
+
* It sets the lastCid property to the CID of the block that was put.
|
34
|
+
* This is used by the transaction as the head of the car when written to the valet.
|
35
|
+
* We don't have to worry about which transaction we are when we are here because
|
36
|
+
* we are the transactionBlockstore.
|
37
|
+
*
|
38
|
+
* @param {import('./link').AnyLink} cid
|
39
|
+
* @param {Uint8Array} bytes
|
40
|
+
*/
|
41
|
+
put(cid: import('./link').AnyLink, bytes: Uint8Array): void;
|
42
|
+
/**
|
43
|
+
* Iterate over all blocks in the store.
|
44
|
+
*
|
45
|
+
* @yields {AnyBlock}
|
46
|
+
* @returns {AsyncGenerator<AnyBlock>}
|
47
|
+
*/
|
48
|
+
/**
|
49
|
+
* Begin a transaction. Ensures the uncommited blocks are empty at the begining.
|
50
|
+
* Returns the blocks to read and write during the transaction.
|
51
|
+
* @returns {InnerBlockstore}
|
52
|
+
* @memberof TransactionBlockstore
|
53
|
+
*/
|
54
|
+
begin(label?: string): InnerBlockstore;
|
55
|
+
/**
|
56
|
+
* Commit the transaction. Writes the blocks to the store.
|
57
|
+
* @returns {Promise<void>}
|
58
|
+
* @memberof TransactionBlockstore
|
59
|
+
*/
|
60
|
+
commit(innerBlockstore: any): Promise<void>;
|
61
|
+
doCommit: (innerBlockstore: any) => Promise<void>;
|
62
|
+
/**
|
63
|
+
* Retire the transaction. Clears the uncommited blocks.
|
64
|
+
* @returns {void}
|
65
|
+
* @memberof TransactionBlockstore
|
66
|
+
*/
|
67
|
+
retire(innerBlockstore: any): void;
|
68
|
+
}
|
69
|
+
export function doTransaction(label: string, blockstore: TransactionBlockstore, doFun: (innerBlockstore: Blockstore) => Promise<any>): Promise<any>;
|
70
|
+
/** @implements {BlockFetcher} */
|
71
|
+
export class InnerBlockstore implements BlockFetcher {
|
72
|
+
constructor(label: any, parentBlockstore: any);
|
73
|
+
/** @type {Map<string, Uint8Array>} */
|
74
|
+
blocks: Map<string, Uint8Array>;
|
75
|
+
lastCid: any;
|
76
|
+
label: string;
|
77
|
+
parentBlockstore: any;
|
78
|
+
/**
|
79
|
+
* @param {import('./link').AnyLink} cid
|
80
|
+
* @returns {Promise<AnyBlock | undefined>}
|
81
|
+
*/
|
82
|
+
get(cid: import('./link').AnyLink): Promise<AnyBlock | undefined>;
|
83
|
+
/**
|
84
|
+
* @param {import('./link').AnyLink} cid
|
85
|
+
* @param {Uint8Array} bytes
|
86
|
+
*/
|
87
|
+
put(cid: import('./link').AnyLink, bytes: Uint8Array): void;
|
88
|
+
entries(): Generator<{
|
89
|
+
cid: import("multiformats").Link<unknown, number, number, import("multiformats").Version>;
|
90
|
+
bytes: Uint8Array;
|
91
|
+
}, void, unknown>;
|
92
|
+
}
|
93
|
+
export type AnyBlock = {
|
94
|
+
/**
|
95
|
+
* - The CID of the block
|
96
|
+
*/
|
97
|
+
cid: import('./link').AnyLink;
|
98
|
+
/**
|
99
|
+
* - The block's data
|
100
|
+
*/
|
101
|
+
bytes: Uint8Array;
|
102
|
+
};
|
103
|
+
export type Blockstore = {
|
104
|
+
/**
|
105
|
+
* - A function to retrieve a block by CID
|
106
|
+
*/
|
107
|
+
get: (arg0: import('./link').AnyLink) => Promise<AnyBlock | undefined>;
|
108
|
+
/**
|
109
|
+
* - A function to store a block's data and CID
|
110
|
+
*
|
111
|
+
* A blockstore that caches writes to a transaction and only persists them when committed.
|
112
|
+
*/
|
113
|
+
put: (arg0: import('./link').AnyLink, arg1: Uint8Array) => Promise<void>;
|
114
|
+
};
|
115
|
+
//# sourceMappingURL=blockstore.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"blockstore.d.ts","sourceRoot":"","sources":["../../src/blockstore.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;GAWG;AACH;IASE,2CAEC;IAVD,sCAAsC;IACtC,iBADW,IAAI,MAAM,EAAE,UAAU,CAAC,CACP;IAE3B,WAAY;IAEZ,mBAAiE;IACjE,+BAAgC;IAMhC;;;;;OAKG;IACH,SAHW,OAAO,QAAQ,EAAE,OAAO,GACtB,QAAQ,QAAQ,GAAG,SAAS,CAAC,CAWzC;IAID,wCAMC;IAED,qCAOC;IAED,qCAEC;IAED,mCAcC;IAED;;;;;;;;;OASG;IACH,SAHW,OAAO,QAAQ,EAAE,OAAO,SACxB,UAAU,QAIpB;IAED;;;;;OAKG;IAWH;;;;;OAKG;IACH,uBAHa,eAAe,CAO3B;IAED;;;;OAIG;IACH,8BAHa,QAAQ,IAAI,CAAC,CAKzB;IAOD,kDAeC;IAED;;;;OAIG;IACH,8BAHa,IAAI,CAKhB;CACF;AAWM,qCANI,MAAM,cACN,qBAAqB,2BACH,UAAU,KAAK,QAAQ,GAAG,CAAC,GAC3C,QAAQ,GAAG,CAAC,CAgBxB;AAED,iCAAiC;AACjC,wCADiB,YAAY;IAQ3B,+CAGC;IATD,sCAAsC;IACtC,QADW,IAAI,MAAM,EAAE,UAAU,CAAC,CAChB;IAClB,aAAc;IACd,cAAU;IACV,sBAAuB;IAOvB;;;OAGG;IACH,SAHW,OAAO,QAAQ,EAAE,OAAO,GACtB,QAAQ,QAAQ,GAAG,SAAS,CAAC,CAYzC;IAED;;;OAGG;IACH,SAHW,OAAO,QAAQ,EAAE,OAAO,SACxB,UAAU,QAMpB;IAED;;;sBAIC;CACF;;;;;SAtOa,OAAO,QAAQ,EAAE,OAAO;;;;WACxB,UAAU;;;;;;gBAGD,OAAO,QAAQ,EAAE,OAAO,KAAG,QAAQ,QAAQ,GAAC,SAAS,CAAC;;;;;;gBACtD,OAAO,QAAQ,EAAE,OAAO,QAAE,UAAU,KAAG,QAAQ,IAAI,CAAC"}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
/**
|
2
|
+
* @template T
|
3
|
+
* @typedef {{ parents: EventLink<T>[], data: T }} EventView
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @template T
|
7
|
+
* @typedef {import('multiformats').BlockView<EventView<T>>} EventBlockView
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* @template T
|
11
|
+
* @typedef {import('multiformats').Link<EventView<T>>} EventLink
|
12
|
+
*/
|
13
|
+
/**
|
14
|
+
* Advance the clock by adding an event.
|
15
|
+
*
|
16
|
+
* @template T
|
17
|
+
* @param {import('./blockstore').BlockFetcher} blocks Block storage.
|
18
|
+
* @param {EventLink<T>[]} head The head of the clock.
|
19
|
+
* @param {EventLink<T>} event The event to add.
|
20
|
+
* @returns {Promise<EventLink<T>[]>} The new head of the clock.
|
21
|
+
*/
|
22
|
+
export function advance<T>(blocks: any, head: import("multiformats/dist/types/src").Link<EventView<T>, number, number, 1>[], event: import("multiformats/dist/types/src").Link<EventView<T>, number, number, 1>): Promise<import("multiformats/dist/types/src").Link<EventView<T>, number, number, 1>[]>;
|
23
|
+
/**
|
24
|
+
* @template T
|
25
|
+
* @param {EventView<T>} value
|
26
|
+
* @returns {Promise<EventBlockView<T>>}
|
27
|
+
*/
|
28
|
+
export function encodeEventBlock<T>(value: EventView<T>): Promise<import("multiformats/dist/types/src").BlockView<EventView<T>, number, number, 1>>;
|
29
|
+
/**
|
30
|
+
* @template T
|
31
|
+
* @param {Uint8Array} bytes
|
32
|
+
* @returns {Promise<EventBlockView<T>>}
|
33
|
+
*/
|
34
|
+
export function decodeEventBlock<T>(bytes: Uint8Array): Promise<import("multiformats/dist/types/src").BlockView<EventView<T>, number, number, 1>>;
|
35
|
+
/**
|
36
|
+
* @template T
|
37
|
+
* @param {import('./blockstore').BlockFetcher} blocks Block storage.
|
38
|
+
* @param {EventLink<T>[]} head
|
39
|
+
* @param {object} [options]
|
40
|
+
* @param {(b: EventBlockView<T>) => string} [options.renderNodeLabel]
|
41
|
+
*/
|
42
|
+
export function vis<T>(blocks: any, head: import("multiformats/dist/types/src").Link<EventView<T>, number, number, 1>[], options?: {
|
43
|
+
renderNodeLabel?: (b: import("multiformats/dist/types/src").BlockView<EventView<T>, number, number, 1>) => string;
|
44
|
+
}): AsyncGenerator<string, void, unknown>;
|
45
|
+
export function findEventsToSync(blocks: any, head: any): Promise<{
|
46
|
+
cids: any;
|
47
|
+
events: any;
|
48
|
+
}>;
|
49
|
+
export function findCommonAncestorWithSortedEvents(events: any, children: any): Promise<{
|
50
|
+
ancestor: import("multiformats/dist/types/src").Link<EventView<EventData>, number, number, 1>;
|
51
|
+
sorted: import("multiformats/dist/types/src").BlockView<EventView<EventData>, number, number, 1>[];
|
52
|
+
}>;
|
53
|
+
/**
|
54
|
+
* @template T
|
55
|
+
* @implements {EventBlockView<T>}
|
56
|
+
*/
|
57
|
+
export class EventBlock<T> extends Block<any, any, any, any> implements EventBlockView<T> {
|
58
|
+
/**
|
59
|
+
* @template T
|
60
|
+
* @param {T} data
|
61
|
+
* @param {EventLink<T>[]} [parents]
|
62
|
+
*/
|
63
|
+
static create<T_1>(data: T_1, parents?: import("multiformats/dist/types/src").Link<EventView<T_1>, number, number, 1>[]): Promise<import("multiformats/dist/types/src").BlockView<EventView<T_1>, number, number, 1>>;
|
64
|
+
/**
|
65
|
+
* @param {object} config
|
66
|
+
* @param {EventLink<T>} config.cid
|
67
|
+
* @param {Event} config.value
|
68
|
+
* @param {Uint8Array} config.bytes
|
69
|
+
*/
|
70
|
+
constructor({ cid, value, bytes }: {
|
71
|
+
cid: EventLink<T>;
|
72
|
+
value: Event;
|
73
|
+
bytes: Uint8Array;
|
74
|
+
});
|
75
|
+
}
|
76
|
+
/** @template T */
|
77
|
+
export class EventFetcher<T> {
|
78
|
+
/** @param {import('./blockstore').BlockFetcher} blocks */
|
79
|
+
constructor(blocks: any);
|
80
|
+
/** @private */
|
81
|
+
private _blocks;
|
82
|
+
_cids: any;
|
83
|
+
_cache: Map<any, any>;
|
84
|
+
/**
|
85
|
+
* @param {EventLink<T>} link
|
86
|
+
* @returns {Promise<EventBlockView<T>>}
|
87
|
+
*/
|
88
|
+
get(link: EventLink<T>): Promise<EventBlockView<T>>;
|
89
|
+
all(): Promise<any>;
|
90
|
+
}
|
91
|
+
export type EventView<T> = {
|
92
|
+
parents: EventLink<T>[];
|
93
|
+
data: T;
|
94
|
+
};
|
95
|
+
export type EventBlockView<T> = import('multiformats').BlockView<EventView<T>>;
|
96
|
+
export type EventLink<T> = import('multiformats').Link<EventView<T>>;
|
97
|
+
import { Block } from 'multiformats/block';
|
98
|
+
//# sourceMappingURL=clock.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/clock.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;;GAQG;AACH,ySAgCC;AA4DD;;;;GAIG;AACH,oJAKC;AAED;;;;GAIG;AACH,2CAHW,UAAU,6FAOpB;AA0BD;;;;;;GAMG;AACH;+GAFqC,MAAM;0CAgC1C;AAED;;;GAYC;AAKD;;;GAYC;AA7KD;;;GAGG;AACH,uFAF+B,CAAC;IAc9B;;;;OAIG;IACH,sNAEC;IAlBD;;;;;OAKG;IACH;QAJgC,GAAG,EAAxB,UAAU,CAAC,CAAC;QACE,KAAK,EAAnB,KAAK;QACc,KAAK,EAAxB,UAAU;OAKpB;CAUF;AAED,kBAAkB;AAClB;IACE,0DAA0D;IAC1D,yBAKC;IAJC,eAAe;IACf,gBAAqB;IACrB,WAA6B;IAC7B,sBAAuB;IAGzB;;;OAGG;IACH,UAHW,UAAU,CAAC,CAAC,GACV,QAAQ,eAAe,CAAC,CAAC,CAAC,CAYtC;IAED,oBAGC;CACF;2BAhHY;IAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE;gCAKpC,OAAO,cAAc,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;2BAK9C,OAAO,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;sBAjBhB,oBAAoB"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export function encrypt({ get, cids, hasher, key, cache, chunker, root }: {
|
2
|
+
get: any;
|
3
|
+
cids: any;
|
4
|
+
hasher: any;
|
5
|
+
key: any;
|
6
|
+
cache: any;
|
7
|
+
chunker: any;
|
8
|
+
root: any;
|
9
|
+
}): AsyncGenerator<any, void, unknown>;
|
10
|
+
export function decrypt({ root, get, key, cache, chunker, hasher }: {
|
11
|
+
root: any;
|
12
|
+
get: any;
|
13
|
+
key: any;
|
14
|
+
cache: any;
|
15
|
+
chunker: any;
|
16
|
+
hasher: any;
|
17
|
+
}): AsyncGenerator<any, void, undefined>;
|
18
|
+
//# sourceMappingURL=crypto.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto.js"],"names":[],"mappings":"AAaA;;;;;;;;uCAuBC;AAED;;;;;;;yCAsBC"}
|
@@ -0,0 +1,116 @@
|
|
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 {Fireproof} 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
|
+
export 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
|
+
/**
|
20
|
+
* The database instance to DbIndex.
|
21
|
+
* @type {Fireproof}
|
22
|
+
*/
|
23
|
+
database: Fireproof;
|
24
|
+
mapFnString: any;
|
25
|
+
mapFn: any;
|
26
|
+
name: any;
|
27
|
+
indexById: {
|
28
|
+
root: any;
|
29
|
+
cid: any;
|
30
|
+
};
|
31
|
+
indexByKey: {
|
32
|
+
root: any;
|
33
|
+
cid: any;
|
34
|
+
};
|
35
|
+
dbHead: any;
|
36
|
+
instanceId: string;
|
37
|
+
updateIndexPromise: Promise<void>;
|
38
|
+
makeName(): any;
|
39
|
+
toJSON(): {
|
40
|
+
name: any;
|
41
|
+
code: any;
|
42
|
+
clock: {
|
43
|
+
db: any;
|
44
|
+
byId: any;
|
45
|
+
byKey: any;
|
46
|
+
};
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* JSDoc for Query type.
|
50
|
+
* @typedef {Object} DbQuery
|
51
|
+
* @property {string[]} [range] - The range to query.
|
52
|
+
* @memberof DbIndex
|
53
|
+
*/
|
54
|
+
/**
|
55
|
+
* Query object can have {range}
|
56
|
+
* @param {DbQuery} query - the query range to use
|
57
|
+
* @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
|
58
|
+
* @memberof DbIndex
|
59
|
+
* @instance
|
60
|
+
*/
|
61
|
+
query(query: {
|
62
|
+
/**
|
63
|
+
* - The range to query.
|
64
|
+
*/
|
65
|
+
range?: string[];
|
66
|
+
}, update?: boolean): Promise<{
|
67
|
+
proof: {};
|
68
|
+
rows: Array<{
|
69
|
+
id: string;
|
70
|
+
key: string;
|
71
|
+
value: any;
|
72
|
+
}>;
|
73
|
+
}>;
|
74
|
+
/**
|
75
|
+
* Update the DbIndex with the latest changes
|
76
|
+
* @private
|
77
|
+
* @returns {Promise<void>}
|
78
|
+
*/
|
79
|
+
private updateIndex;
|
80
|
+
innerUpdateIndex(inBlocks: any): Promise<void>;
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* JDoc for the result row type.
|
84
|
+
*/
|
85
|
+
export type ChangeEvent = {
|
86
|
+
/**
|
87
|
+
* - The key of the document.
|
88
|
+
*/
|
89
|
+
key: string;
|
90
|
+
/**
|
91
|
+
* - The new value of the document.
|
92
|
+
*/
|
93
|
+
value: any;
|
94
|
+
/**
|
95
|
+
* - Is the row deleted?
|
96
|
+
*/
|
97
|
+
del?: boolean;
|
98
|
+
};
|
99
|
+
/**
|
100
|
+
* JDoc for the result row type.
|
101
|
+
*/
|
102
|
+
export type DbIndexEntry = {
|
103
|
+
/**
|
104
|
+
* - The key for the DbIndex entry.
|
105
|
+
*/
|
106
|
+
key: string[];
|
107
|
+
/**
|
108
|
+
* - The value of the document.
|
109
|
+
*/
|
110
|
+
value: any;
|
111
|
+
/**
|
112
|
+
* - Is the row deleted?
|
113
|
+
*/
|
114
|
+
del?: boolean;
|
115
|
+
};
|
116
|
+
//# sourceMappingURL=db-index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"db-index.d.ts","sourceRoot":"","sources":["../../src/db-index.js"],"names":[],"mappings":"AAoFA;;;;;;;;;GASG;AACH;IA0CE,+DAkBC;IAUD;;;;gBAGC;IAxED,8DAiCC;IA/BC;;;OAGG;IACH,oBAAwB;IAUtB,iBAAwB;IAExB,WAAkB;IAGpB,UAAwC;IACxC;;;MAA0C;IAC1C;;;MAA2C;IAC3C,YAAkB;IAMlB,mBAAqG;IACrG,kCAA8B;IAIhC,gBAIC;IAsBD;;;;;;;;MAMC;IAOD;;;;;OAKG;IAEH;;;;;;OAMG;IACH;;;;gBAXc,MAAM,EAAE;0BAOT,QAAQ;QAAC,KAAK,EAAE,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM;YAAC,EAAE,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,GAAG,CAAA;SAAC,CAAC,CAAA;KAAC,CAAC,CAoBpF;IAED;;;;OAIG;IAEH,oBAOC;IAED,+CA6CC;CACF;;;;;;;;SAzNa,MAAM;;;;;;;;UAEN,OAAO;;;;;;;;;SAOP,MAAM,EAAE;;;;;;;;UAER,OAAO"}
|
@@ -0,0 +1,167 @@
|
|
1
|
+
export function cidsToProof(cids: any): Promise<any[]>;
|
2
|
+
/**
|
3
|
+
* @class Fireproof
|
4
|
+
* @classdesc Fireproof stores data in IndexedDB and provides a Merkle clock.
|
5
|
+
* This is the main class for saving and loading JSON and other documents with the database. You can find additional examples and
|
6
|
+
* usage guides in the repository README.
|
7
|
+
*
|
8
|
+
* @param {import('./blockstore.js').TransactionBlockstore} blocks - The block storage instance to use documents and indexes
|
9
|
+
* @param {CID[]} clock - The Merkle clock head to use for the Fireproof instance.
|
10
|
+
* @param {object} [config] - Optional configuration options for the Fireproof instance.
|
11
|
+
* @param {object} [authCtx] - Optional authorization context object to use for any authentication checks.
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
export class Fireproof {
|
15
|
+
/**
|
16
|
+
* @function storage
|
17
|
+
* @memberof Fireproof
|
18
|
+
* Creates a new Fireproof instance with default storage settings
|
19
|
+
* Most apps should use this and not worry about the details.
|
20
|
+
* @static
|
21
|
+
* @returns {Fireproof} - a new Fireproof instance
|
22
|
+
*/
|
23
|
+
static storage: (name?: string) => Fireproof;
|
24
|
+
constructor(blocks: any, clock: any, config: any, authCtx?: {});
|
25
|
+
listeners: Set<any>;
|
26
|
+
name: any;
|
27
|
+
instanceId: string;
|
28
|
+
blocks: any;
|
29
|
+
clock: any;
|
30
|
+
config: any;
|
31
|
+
authCtx: {};
|
32
|
+
indexes: Map<any, any>;
|
33
|
+
/**
|
34
|
+
* Renders the Fireproof instance as a JSON object.
|
35
|
+
* @returns {Object} - The JSON representation of the Fireproof instance. Includes clock heads for the database and its indexes.
|
36
|
+
* @memberof Fireproof
|
37
|
+
* @instance
|
38
|
+
*/
|
39
|
+
toJSON(): any;
|
40
|
+
clockToJSON(): any;
|
41
|
+
hydrate({ clock, name, key }: {
|
42
|
+
clock: any;
|
43
|
+
name: any;
|
44
|
+
key: any;
|
45
|
+
}): void;
|
46
|
+
indexBlocks: any;
|
47
|
+
/**
|
48
|
+
* Triggers a notification to all listeners
|
49
|
+
* of the Fireproof instance so they can repaint UI, etc.
|
50
|
+
* @param {CID[] } clock
|
51
|
+
* Clock to use for the snapshot.
|
52
|
+
* @returns {Promise<void>}
|
53
|
+
* @memberof Fireproof
|
54
|
+
* @instance
|
55
|
+
*/
|
56
|
+
notifyReset(): Promise<void>;
|
57
|
+
notifyExternal(source?: string): Promise<void>;
|
58
|
+
/**
|
59
|
+
* Returns the changes made to the Fireproof instance since the specified event.
|
60
|
+
* @function changesSince
|
61
|
+
* @param {CID[]} [event] - The clock head to retrieve changes since. If null or undefined, retrieves all changes.
|
62
|
+
* @returns {Object<{rows : Object[], clock: CID[]}>} An object containing the rows and the head of the instance's clock.
|
63
|
+
* @memberof Fireproof
|
64
|
+
* @instance
|
65
|
+
*/
|
66
|
+
changesSince(event?: CID[]): any;
|
67
|
+
allDocuments(): Promise<{
|
68
|
+
rows: {
|
69
|
+
key: any;
|
70
|
+
value: any;
|
71
|
+
}[];
|
72
|
+
clock: any;
|
73
|
+
proof: any[];
|
74
|
+
}>;
|
75
|
+
/**
|
76
|
+
* Runs validation on the specified document using the Fireproof instance's configuration. Throws an error if the document is invalid.
|
77
|
+
*
|
78
|
+
* @param {Object} doc - The document to validate.
|
79
|
+
* @returns {Promise<void>}
|
80
|
+
* @throws {Error} - Throws an error if the document is invalid.
|
81
|
+
* @memberof Fireproof
|
82
|
+
* @instance
|
83
|
+
*/
|
84
|
+
runValidation(doc: any): Promise<void>;
|
85
|
+
/**
|
86
|
+
* Retrieves the document with the specified ID from the database
|
87
|
+
*
|
88
|
+
* @param {string} key - the ID of the document to retrieve
|
89
|
+
* @param {Object} [opts] - options
|
90
|
+
* @returns {Promise<{_id: string}>} - the document with the specified ID
|
91
|
+
* @memberof Fireproof
|
92
|
+
* @instance
|
93
|
+
*/
|
94
|
+
get(key: string, opts?: any): Promise<{
|
95
|
+
_id: string;
|
96
|
+
}>;
|
97
|
+
/**
|
98
|
+
* Adds a new document to the database, or updates an existing document. Returns the ID of the document and the new clock head.
|
99
|
+
*
|
100
|
+
* @param {Object} doc - the document to be added
|
101
|
+
* @param {string} doc._id - the document ID. If not provided, a random ID will be generated.
|
102
|
+
* @param {CID[]} doc._clock - the document ID. If not provided, a random ID will be generated.
|
103
|
+
* @param {Proof} doc._proof - CIDs referenced by the update
|
104
|
+
* @returns {Promise<{ id: string, clock: CID[] }>} - The result of adding the document to the database
|
105
|
+
* @memberof Fireproof
|
106
|
+
* @instance
|
107
|
+
*/
|
108
|
+
put({ _id, _proof, ...doc }: {
|
109
|
+
_id: string;
|
110
|
+
_clock: CID[];
|
111
|
+
_proof: Proof;
|
112
|
+
}): Promise<{
|
113
|
+
id: string;
|
114
|
+
clock: CID[];
|
115
|
+
}>;
|
116
|
+
/**
|
117
|
+
* Deletes a document from the database
|
118
|
+
* @param {string | any} docOrId - the document ID
|
119
|
+
* @returns {Promise<{ id: string, clock: CID[] }>} - The result of deleting the document from the database
|
120
|
+
* @memberof Fireproof
|
121
|
+
* @instance
|
122
|
+
*/
|
123
|
+
del(docOrId: string | any): Promise<{
|
124
|
+
id: string;
|
125
|
+
clock: CID[];
|
126
|
+
}>;
|
127
|
+
/**
|
128
|
+
* Updates the underlying storage with the specified event.
|
129
|
+
* @private
|
130
|
+
* @param {{del?: true, key : string, value?: any}} decodedEvent - the event to add
|
131
|
+
* @returns {Promise<{ proof:{}, id: string, clock: CID[] }>} - The result of adding the event to storage
|
132
|
+
*/
|
133
|
+
private putToProllyTree;
|
134
|
+
vis(): AsyncGenerator<any, {
|
135
|
+
cids: any;
|
136
|
+
result: any;
|
137
|
+
vis?: undefined;
|
138
|
+
} | {
|
139
|
+
vis: string;
|
140
|
+
cids: any;
|
141
|
+
result?: undefined;
|
142
|
+
}, unknown>;
|
143
|
+
visTree(): Promise<{
|
144
|
+
cids: any;
|
145
|
+
result: any;
|
146
|
+
vis?: undefined;
|
147
|
+
} | {
|
148
|
+
vis: string;
|
149
|
+
cids: any;
|
150
|
+
result?: undefined;
|
151
|
+
}>;
|
152
|
+
visClock(): Promise<{
|
153
|
+
vis: string;
|
154
|
+
}>;
|
155
|
+
/**
|
156
|
+
* Registers a Listener to be called when the Fireproof instance's clock is updated.
|
157
|
+
* Recieves live changes from the database after they are committed.
|
158
|
+
* @param {Function} listener - The listener to be called when the clock is updated.
|
159
|
+
* @returns {Function} - A function that can be called to unregister the listener.
|
160
|
+
* @memberof Fireproof
|
161
|
+
*/
|
162
|
+
registerListener(listener: Function): Function;
|
163
|
+
notifyListeners(changes: any): Promise<void>;
|
164
|
+
setCarUploader(carUploaderFn: any): void;
|
165
|
+
setRemoteBlockReader(remoteBlockReaderFn: any): void;
|
166
|
+
}
|
167
|
+
//# sourceMappingURL=fireproof.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"fireproof.d.ts","sourceRoot":"","sources":["../../src/fireproof.js"],"names":[],"mappings":"AAkUA,uDAIC;AA3TD;;;;;;;;;;;GAWG;AACH;IAGE;;;;;;;OAOG;IACH,mCAFa,SAAS,CAOrB;IAED,gEAQC;IAzBD,oBAAqB;IAkBnB,UAAoC;IACpC,mBAAiF;IACjF,YAAoB;IACpB,WAAkB;IAClB,YAAoB;IACpB,YAAsB;IACtB,uBAAwB;IAG1B;;;;;OAKG;IACH,cAQC;IAED,mBAEC;IAED;;;;aAKC;IADC,iBAAuB;IAGzB;;;;;;;;OAQG;IACH,eAJa,QAAQ,IAAI,CAAC,CAMzB;IAGD,+CAEC;IAED;;;;;;;OAOG;IACH,qBALW,KAAK,OAiCf;IAED;;;;;;;OAQC;IAED;;;;;;;;OAQG;IACH,yBALa,QAAQ,IAAI,CAAC,CAYzB;IAED;;;;;;;;OAQG;IACH,SANW,MAAM,eAEJ,QAAQ;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAC,CAsBlC;IAED;;;;;;;;;;OAUG;IACH;QAPuB,GAAG,EAAf,MAAM;QACK,MAAM,EAAjB,KAAK;QACM,MAAM;;YACD,MAAM;eAAS,KAAK;OAQ9C;IAED;;;;;;OAMG;IACH,aALW,MAAM,GAAG,GAAG;YACI,MAAM;eAAS,KAAK;OAiB9C;IAED;;;;;OAKG;IACH,wBA6BC;IAYD;;;;;;;;gBAEC;IAED;;;;;;;;OAEC;IAED;;OAEC;IAED;;;;;;OAMG;IACH,+CAKC;IAED,6CAKC;IAED,yCAIC;IAED,qDAGC;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"hydrator.d.ts","sourceRoot":"","sources":["../../src/hydrator.js"],"names":[],"mappings":"AAMA;IACE,+CAgBC;IAED,gDAgBC;IAED,qDASC;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"0BAA0B,aAAa;iCACN,YAAY;yBACpB,YAAY;yBACZ,YAAY"}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/**
|
2
|
+
* A Fireproof database Listener allows you to react to events in the database.
|
3
|
+
*
|
4
|
+
* @class Listener
|
5
|
+
* @classdesc An listener attaches to a Fireproof database and runs a routing function on each change, sending the results to subscribers.
|
6
|
+
*
|
7
|
+
* @param {Fireproof} database - The Fireproof database instance to index.
|
8
|
+
* @param {Function} routingFn - The routing function to apply to each entry in the database.
|
9
|
+
*/
|
10
|
+
export class Listener {
|
11
|
+
constructor(database: any, routingFn: any);
|
12
|
+
subcribers: Map<any, any>;
|
13
|
+
doStopListening: any;
|
14
|
+
/** routingFn
|
15
|
+
* The database instance to index.
|
16
|
+
* @type {Fireproof}
|
17
|
+
*/
|
18
|
+
database: Fireproof;
|
19
|
+
/**
|
20
|
+
* The map function to apply to each entry in the database.
|
21
|
+
* @type {Function}
|
22
|
+
*/
|
23
|
+
routingFn: Function;
|
24
|
+
dbHead: any;
|
25
|
+
/**
|
26
|
+
* Subscribe to a topic emitted by the event function.
|
27
|
+
* @param {string} topic - The topic to subscribe to.
|
28
|
+
* @param {Function} subscriber - The function to call when the topic is emitted.
|
29
|
+
* @returns {Function} A function to unsubscribe from the topic.
|
30
|
+
* @memberof Listener
|
31
|
+
* @instance
|
32
|
+
*/
|
33
|
+
on(topic: string, subscriber: Function, since: any): Function;
|
34
|
+
onChanges(changes: any): void;
|
35
|
+
}
|
36
|
+
//# sourceMappingURL=listener.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/listener.js"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAGH;IAIE,2CAiBC;IApBD,0BAAsB;IACtB,qBAAsB;IAGpB;;;OAGG;IACH,oBAAwB;IAExB;;;OAGG;IACH,oBAIG;IACH,YAAkB;IAGpB;;;;;;;OAOG;IACH,UANW,MAAM,8CAmBhB;IAED,8BAaC;CACF"}
|