@fireproof/vendor 2.0.2 → 3.0.0
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/package.json +6 -60
- package/src/p-limit/index.d.ts +81 -0
- package/src/p-limit/index.js +104 -0
- package/src/p-limit/license +9 -0
- package/src/p-limit/readme.md +129 -0
- package/src/@web3-storage/pail/LICENSE.md +0 -232
- package/src/@web3-storage/pail/README.md +0 -84
- package/src/@web3-storage/pail/cli.js +0 -218
- package/src/@web3-storage/pail/dist/src/api.d.ts +0 -61
- package/src/@web3-storage/pail/dist/src/api.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/api.js +0 -1
- package/src/@web3-storage/pail/dist/src/batch/api.d.ts +0 -31
- package/src/@web3-storage/pail/dist/src/batch/api.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/batch/api.js +0 -1
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts +0 -23
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/batch/index.js +0 -241
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts +0 -3
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.js +0 -12
- package/src/@web3-storage/pail/dist/src/block.d.ts +0 -35
- package/src/@web3-storage/pail/dist/src/block.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/block.js +0 -66
- package/src/@web3-storage/pail/dist/src/clock/api.d.ts +0 -10
- package/src/@web3-storage/pail/dist/src/clock/api.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/clock/api.js +0 -1
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts +0 -48
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/clock/index.js +0 -178
- package/src/@web3-storage/pail/dist/src/crdt/api.d.ts +0 -26
- package/src/@web3-storage/pail/dist/src/crdt/api.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/api.js +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/api.d.ts +0 -11
- package/src/@web3-storage/pail/dist/src/crdt/batch/api.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/api.js +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts +0 -5
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.js +0 -140
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts +0 -9
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/crdt/index.js +0 -344
- package/src/@web3-storage/pail/dist/src/diff.d.ts +0 -13
- package/src/@web3-storage/pail/dist/src/diff.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/diff.js +0 -151
- package/src/@web3-storage/pail/dist/src/index.d.ts +0 -10
- package/src/@web3-storage/pail/dist/src/index.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/index.js +0 -356
- package/src/@web3-storage/pail/dist/src/merge.d.ts +0 -5
- package/src/@web3-storage/pail/dist/src/merge.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/merge.js +0 -42
- package/src/@web3-storage/pail/dist/src/shard.d.ts +0 -43
- package/src/@web3-storage/pail/dist/src/shard.d.ts.map +0 -1
- package/src/@web3-storage/pail/dist/src/shard.js +0 -166
- package/src/@web3-storage/pail/dist/tsconfig.tsbuildinfo +0 -1
- package/src/@web3-storage/pail/src/api.ts +0 -92
- package/src/@web3-storage/pail/src/batch/api.js +0 -1
- package/src/@web3-storage/pail/src/batch/api.ts +0 -59
- package/src/@web3-storage/pail/src/batch/index.js +0 -258
- package/src/@web3-storage/pail/src/batch/shard.js +0 -13
- package/src/@web3-storage/pail/src/block.js +0 -75
- package/src/@web3-storage/pail/src/clock/api.js +0 -1
- package/src/@web3-storage/pail/src/clock/api.ts +0 -12
- package/src/@web3-storage/pail/src/clock/index.js +0 -182
- package/src/@web3-storage/pail/src/crdt/api.js +0 -1
- package/src/@web3-storage/pail/src/crdt/api.ts +0 -33
- package/src/@web3-storage/pail/src/crdt/batch/api.js +0 -1
- package/src/@web3-storage/pail/src/crdt/batch/api.ts +0 -30
- package/src/@web3-storage/pail/src/crdt/batch/index.js +0 -155
- package/src/@web3-storage/pail/src/crdt/index.js +0 -354
- package/src/@web3-storage/pail/src/diff.js +0 -151
- package/src/@web3-storage/pail/src/index.js +0 -406
- package/src/@web3-storage/pail/src/merge.js +0 -43
- package/src/@web3-storage/pail/src/shard.js +0 -180
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shard.d.ts","sourceRoot":"","sources":["../../../src/batch/shard.js"],"names":[],"mappings":"AAQO,8BAHI,GAAG,CAAC,gBAAgB,GAClB,GAAG,CAAC,YAAY,CAM3B;qBAXmB,UAAU"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
import * as API from './api.js';
|
|
3
|
-
import { configure } from '../shard.js';
|
|
4
|
-
/**
|
|
5
|
-
* @param {API.BatcherShardInit} [init]
|
|
6
|
-
* @returns {API.BatcherShard}
|
|
7
|
-
*/
|
|
8
|
-
export const create = init => ({
|
|
9
|
-
base: init?.base,
|
|
10
|
-
entries: [...(init?.entries ?? [])],
|
|
11
|
-
...configure(init)
|
|
12
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/** @implements {API.BlockFetcher} */
|
|
2
|
-
export class MemoryBlockstore implements API.BlockFetcher {
|
|
3
|
-
/**
|
|
4
|
-
* @param {Array<import('multiformats').Block>} [blocks]
|
|
5
|
-
*/
|
|
6
|
-
constructor(blocks?: Array<import("multiformats").Block>);
|
|
7
|
-
get<T = unknown, C extends number = number, A extends number = number, V extends API.Version = 1>(link: API.Link<T, C, A, V>): Promise<API.Block<T, C, A, V> | undefined>;
|
|
8
|
-
/**
|
|
9
|
-
* @param {API.UnknownLink} cid
|
|
10
|
-
* @param {Uint8Array} bytes
|
|
11
|
-
*/
|
|
12
|
-
put(cid: API.UnknownLink, bytes: Uint8Array): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* @param {API.UnknownLink} cid
|
|
15
|
-
* @param {Uint8Array} bytes
|
|
16
|
-
*/
|
|
17
|
-
putSync(cid: API.UnknownLink, bytes: Uint8Array): void;
|
|
18
|
-
/** @param {API.UnknownLink} cid */
|
|
19
|
-
delete(cid: API.UnknownLink): Promise<void>;
|
|
20
|
-
/** @param {API.UnknownLink} cid */
|
|
21
|
-
deleteSync(cid: API.UnknownLink): void;
|
|
22
|
-
entries(): Generator<{
|
|
23
|
-
cid: API.Link<any, number, number, API.Version>;
|
|
24
|
-
bytes: Uint8Array<ArrayBufferLike>;
|
|
25
|
-
}, void, unknown>;
|
|
26
|
-
#private;
|
|
27
|
-
}
|
|
28
|
-
export class MultiBlockFetcher {
|
|
29
|
-
/** @param {API.BlockFetcher[]} fetchers */
|
|
30
|
-
constructor(...fetchers: API.BlockFetcher[]);
|
|
31
|
-
get<T = unknown, C extends number = number, A extends number = number, V extends API.Version = 1>(link: API.Link<T, C, A, V>): Promise<API.Block<T, C, A, V> | undefined>;
|
|
32
|
-
#private;
|
|
33
|
-
}
|
|
34
|
-
import * as API from './api.js';
|
|
35
|
-
//# sourceMappingURL=block.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/block.js"],"names":[],"mappings":"AAIA,qCAAqC;AACrC,yCADiB,GAAG,CAAC,YAAY;IAK/B;;OAEG;IACH,qBAFW,KAAK,CAAC,OAAO,cAAc,EAAE,KAAK,CAAC,EAM7C;;IASD;;;OAGG;IACH,SAHW,GAAG,CAAC,WAAW,SACf,UAAU,iBAIpB;IAED;;;OAGG;IACH,aAHW,GAAG,CAAC,WAAW,SACf,UAAU,QAIpB;IAED,mCAAmC;IACnC,YADY,GAAG,CAAC,WAAW,iBAG1B;IAED,mCAAmC;IACnC,gBADY,GAAG,CAAC,WAAW,QAG1B;IAED;;;sBAIC;;CACF;AAED;IAIE,2CAA2C;IAC3C,yBADY,GAAG,CAAC,YAAY,EAAE,EAG7B;;;CASF;qBAzEoB,UAAU"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
import * as API from './api.js';
|
|
3
|
-
import { parse } from 'multiformats/link';
|
|
4
|
-
/** @implements {API.BlockFetcher} */
|
|
5
|
-
export class MemoryBlockstore {
|
|
6
|
-
/** @type {Map<string, Uint8Array>} */
|
|
7
|
-
#blocks = new Map();
|
|
8
|
-
/**
|
|
9
|
-
* @param {Array<import('multiformats').Block>} [blocks]
|
|
10
|
-
*/
|
|
11
|
-
constructor(blocks) {
|
|
12
|
-
if (blocks) {
|
|
13
|
-
this.#blocks = new Map(blocks.map(b => [b.cid.toString(), b.bytes]));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/** @type {API.BlockFetcher['get']} */
|
|
17
|
-
async get(cid) {
|
|
18
|
-
const bytes = this.#blocks.get(cid.toString());
|
|
19
|
-
if (!bytes)
|
|
20
|
-
return;
|
|
21
|
-
return { cid, bytes };
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @param {API.UnknownLink} cid
|
|
25
|
-
* @param {Uint8Array} bytes
|
|
26
|
-
*/
|
|
27
|
-
async put(cid, bytes) {
|
|
28
|
-
this.#blocks.set(cid.toString(), bytes);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @param {API.UnknownLink} cid
|
|
32
|
-
* @param {Uint8Array} bytes
|
|
33
|
-
*/
|
|
34
|
-
putSync(cid, bytes) {
|
|
35
|
-
this.#blocks.set(cid.toString(), bytes);
|
|
36
|
-
}
|
|
37
|
-
/** @param {API.UnknownLink} cid */
|
|
38
|
-
async delete(cid) {
|
|
39
|
-
this.#blocks.delete(cid.toString());
|
|
40
|
-
}
|
|
41
|
-
/** @param {API.UnknownLink} cid */
|
|
42
|
-
deleteSync(cid) {
|
|
43
|
-
this.#blocks.delete(cid.toString());
|
|
44
|
-
}
|
|
45
|
-
*entries() {
|
|
46
|
-
for (const [str, bytes] of this.#blocks) {
|
|
47
|
-
yield { cid: parse(str), bytes };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class MultiBlockFetcher {
|
|
52
|
-
/** @type {API.BlockFetcher[]} */
|
|
53
|
-
#fetchers;
|
|
54
|
-
/** @param {API.BlockFetcher[]} fetchers */
|
|
55
|
-
constructor(...fetchers) {
|
|
56
|
-
this.#fetchers = fetchers;
|
|
57
|
-
}
|
|
58
|
-
/** @type {API.BlockFetcher['get']} */
|
|
59
|
-
async get(link) {
|
|
60
|
-
for (const f of this.#fetchers) {
|
|
61
|
-
const v = await f.get(link);
|
|
62
|
-
if (v)
|
|
63
|
-
return v;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Link, BlockView } from 'multiformats';
|
|
2
|
-
export { BlockFetcher } from '../api.js';
|
|
3
|
-
export type EventLink<T> = Link<EventView<T>>;
|
|
4
|
-
export interface EventView<T> {
|
|
5
|
-
parents: EventLink<T>[];
|
|
6
|
-
data: T;
|
|
7
|
-
}
|
|
8
|
-
export interface EventBlockView<T> extends BlockView<EventView<T>> {
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/clock/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7C,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;CACR;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export function advance<T>(blocks: API.BlockFetcher, head: API.EventLink<T>[], event: API.EventLink<T>): Promise<API.EventLink<T>[]>;
|
|
2
|
-
/**
|
|
3
|
-
* @template T
|
|
4
|
-
* @extends {Block<API.EventView<T>, typeof cbor.code, typeof sha256.code, 1>}
|
|
5
|
-
* @implements {API.EventBlockView<T>}
|
|
6
|
-
*/
|
|
7
|
-
export class EventBlock<T> extends Block<API.EventView<T>, 113, 18, 1> implements API.EventBlockView<T> {
|
|
8
|
-
/**
|
|
9
|
-
* @template T
|
|
10
|
-
* @param {T} data
|
|
11
|
-
* @param {API.EventLink<T>[]} [parents]
|
|
12
|
-
*/
|
|
13
|
-
static create<T_1>(data: T_1, parents?: API.EventLink<T_1>[]): Promise<API.EventBlockView<T_1>>;
|
|
14
|
-
/**
|
|
15
|
-
* @param {object} config
|
|
16
|
-
* @param {API.EventLink<T>} config.cid
|
|
17
|
-
* @param {Event} config.value
|
|
18
|
-
* @param {Uint8Array} config.bytes
|
|
19
|
-
* @param {string} config.prefix
|
|
20
|
-
*/
|
|
21
|
-
constructor({ cid, value, bytes, prefix }: {
|
|
22
|
-
cid: API.EventLink<T>;
|
|
23
|
-
value: Event;
|
|
24
|
-
bytes: Uint8Array;
|
|
25
|
-
prefix: string;
|
|
26
|
-
});
|
|
27
|
-
prefix: string;
|
|
28
|
-
}
|
|
29
|
-
/** @template T */
|
|
30
|
-
export class EventFetcher<T> {
|
|
31
|
-
/** @param {API.BlockFetcher} blocks */
|
|
32
|
-
constructor(blocks: API.BlockFetcher);
|
|
33
|
-
/** @private */
|
|
34
|
-
private _blocks;
|
|
35
|
-
/**
|
|
36
|
-
* @param {API.EventLink<T>} link
|
|
37
|
-
* @returns {Promise<API.EventBlockView<T>>}
|
|
38
|
-
*/
|
|
39
|
-
get(link: API.EventLink<T>): Promise<API.EventBlockView<T>>;
|
|
40
|
-
}
|
|
41
|
-
export function encodeEventBlock<T>(value: API.EventView<T>): Promise<API.EventBlockView<T>>;
|
|
42
|
-
export function decodeEventBlock<T>(bytes: Uint8Array): Promise<API.EventBlockView<T>>;
|
|
43
|
-
export function vis<T>(blocks: API.BlockFetcher, head: API.EventLink<T>[], options?: {
|
|
44
|
-
renderNodeLabel?: ((b: API.EventBlockView<T>) => string) | undefined;
|
|
45
|
-
}): AsyncGenerator<string, void, unknown>;
|
|
46
|
-
import * as API from './api.js';
|
|
47
|
-
import { Block } from 'multiformats/block';
|
|
48
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clock/index.js"],"names":[],"mappings":"AAcO,wBALM,CAAC,UACH,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAClB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,+BA4B1B;AAED;;;;GAIG;AACH,wBAJa,CAAC,yDAEE,GAAG,CAAC,cAAc,CAAC,CAAC;IAgBlC;;;;OAIG;IACH,yBAHW,GAAC,YACD,GAAG,CAAC,SAAS,CAAC,GAAC,CAAC,EAAE,oCAI5B;IApBD;;;;;;OAMG;IACH,2CALG;QAAiC,GAAG,EAA5B,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QACF,KAAK,EAAnB,KAAK;QACc,KAAK,EAAxB,UAAU;QACK,MAAM,EAArB,MAAM;KAChB,EAKA;IADC,eAAoB;CAWvB;AAED,kBAAkB;AAClB,0BADc,CAAC;IAEb,uCAAuC;IACvC,oBADY,GAAG,CAAC,YAAY,EAI3B;IAFC,eAAe;IACf,gBAAqB;IAGvB;;;OAGG;IACH,UAHW,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GACd,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAM1C;CACF;AAOM,iCAJM,CAAC,SACH,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GACd,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAO1C;AAOM,iCAJM,CAAC,SACH,UAAU,GACR,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAM1C;AAoCM,oBANM,CAAC,UACH,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAE1B;IAAuD,eAAe,QAA1D,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,MAAM;CAA2B,yCAiCzE;qBA9KoB,UAAU;sBAJO,oBAAoB"}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { Block, encode, decode } from 'multiformats/block';
|
|
2
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
3
|
-
import * as cbor from '@ipld/dag-cbor';
|
|
4
|
-
// eslint-disable-next-line no-unused-vars
|
|
5
|
-
import * as API from './api.js';
|
|
6
|
-
/**
|
|
7
|
-
* Advance the clock by adding an event.
|
|
8
|
-
*
|
|
9
|
-
* @template T
|
|
10
|
-
* @param {API.BlockFetcher} blocks Block storage.
|
|
11
|
-
* @param {API.EventLink<T>[]} head The head of the clock.
|
|
12
|
-
* @param {API.EventLink<T>} event The event to add.
|
|
13
|
-
*/
|
|
14
|
-
export const advance = async (blocks, head, event) => {
|
|
15
|
-
const events = new EventFetcher(blocks);
|
|
16
|
-
const headmap = new Map(head.map(cid => [cid.toString(), cid]));
|
|
17
|
-
if (headmap.has(event.toString()))
|
|
18
|
-
return head;
|
|
19
|
-
// does event contain the clock?
|
|
20
|
-
let changed = false;
|
|
21
|
-
for (const cid of head) {
|
|
22
|
-
if (await contains(events, event, cid)) {
|
|
23
|
-
headmap.delete(cid.toString());
|
|
24
|
-
headmap.set(event.toString(), event);
|
|
25
|
-
changed = true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (changed) {
|
|
29
|
-
return [...headmap.values()];
|
|
30
|
-
}
|
|
31
|
-
// does clock contain the event?
|
|
32
|
-
for (const p of head) {
|
|
33
|
-
if (await contains(events, p, event)) {
|
|
34
|
-
return head;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return head.concat(event);
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* @template T
|
|
41
|
-
* @extends {Block<API.EventView<T>, typeof cbor.code, typeof sha256.code, 1>}
|
|
42
|
-
* @implements {API.EventBlockView<T>}
|
|
43
|
-
*/
|
|
44
|
-
export class EventBlock extends Block {
|
|
45
|
-
/**
|
|
46
|
-
* @param {object} config
|
|
47
|
-
* @param {API.EventLink<T>} config.cid
|
|
48
|
-
* @param {Event} config.value
|
|
49
|
-
* @param {Uint8Array} config.bytes
|
|
50
|
-
* @param {string} config.prefix
|
|
51
|
-
*/
|
|
52
|
-
constructor({ cid, value, bytes, prefix }) {
|
|
53
|
-
// @ts-expect-error
|
|
54
|
-
super({ cid, value, bytes });
|
|
55
|
-
this.prefix = prefix;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @template T
|
|
59
|
-
* @param {T} data
|
|
60
|
-
* @param {API.EventLink<T>[]} [parents]
|
|
61
|
-
*/
|
|
62
|
-
static create(data, parents) {
|
|
63
|
-
return encodeEventBlock({ data, parents: parents ?? [] });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** @template T */
|
|
67
|
-
export class EventFetcher {
|
|
68
|
-
/** @param {API.BlockFetcher} blocks */
|
|
69
|
-
constructor(blocks) {
|
|
70
|
-
/** @private */
|
|
71
|
-
this._blocks = blocks;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @param {API.EventLink<T>} link
|
|
75
|
-
* @returns {Promise<API.EventBlockView<T>>}
|
|
76
|
-
*/
|
|
77
|
-
async get(link) {
|
|
78
|
-
const block = await this._blocks.get(link);
|
|
79
|
-
if (!block)
|
|
80
|
-
throw new Error(`missing block: ${link}`);
|
|
81
|
-
return decodeEventBlock(block.bytes);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @template T
|
|
86
|
-
* @param {API.EventView<T>} value
|
|
87
|
-
* @returns {Promise<API.EventBlockView<T>>}
|
|
88
|
-
*/
|
|
89
|
-
export const encodeEventBlock = async (value) => {
|
|
90
|
-
// TODO: sort parents
|
|
91
|
-
const { cid, bytes } = await encode({ value, codec: cbor, hasher: sha256 });
|
|
92
|
-
// @ts-expect-error
|
|
93
|
-
return new Block({ cid, value, bytes });
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* @template T
|
|
97
|
-
* @param {Uint8Array} bytes
|
|
98
|
-
* @returns {Promise<API.EventBlockView<T>>}
|
|
99
|
-
*/
|
|
100
|
-
export const decodeEventBlock = async (bytes) => {
|
|
101
|
-
const { cid, value } = await decode({ bytes, codec: cbor, hasher: sha256 });
|
|
102
|
-
// @ts-expect-error
|
|
103
|
-
return new Block({ cid, value, bytes });
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Returns true if event "a" contains event "b". Breadth first search.
|
|
107
|
-
* @template T
|
|
108
|
-
* @param {EventFetcher<T>} events
|
|
109
|
-
* @param {API.EventLink<T>} a
|
|
110
|
-
* @param {API.EventLink<T>} b
|
|
111
|
-
*/
|
|
112
|
-
const contains = async (events, a, b) => {
|
|
113
|
-
if (a.toString() === b.toString())
|
|
114
|
-
return true;
|
|
115
|
-
const [{ value: aevent }, { value: bevent }] = await Promise.all([events.get(a), events.get(b)]);
|
|
116
|
-
const links = [...aevent.parents];
|
|
117
|
-
const seen = new Set();
|
|
118
|
-
while (links.length) {
|
|
119
|
-
const link = links.shift();
|
|
120
|
-
if (!link)
|
|
121
|
-
break;
|
|
122
|
-
if (link.toString() === b.toString())
|
|
123
|
-
return true;
|
|
124
|
-
// if any of b's parents are this link, then b cannot exist in any of the
|
|
125
|
-
// tree below, since that would create a cycle.
|
|
126
|
-
if (bevent.parents.some(p => link.toString() === p.toString()))
|
|
127
|
-
continue;
|
|
128
|
-
if (seen.has(link.toString()))
|
|
129
|
-
continue;
|
|
130
|
-
seen.add(link.toString());
|
|
131
|
-
const { value: event } = await events.get(link);
|
|
132
|
-
links.push(...event.parents);
|
|
133
|
-
}
|
|
134
|
-
return false;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* @template T
|
|
138
|
-
* @param {API.BlockFetcher} blocks Block storage.
|
|
139
|
-
* @param {API.EventLink<T>[]} head
|
|
140
|
-
* @param {object} [options]
|
|
141
|
-
* @param {(b: API.EventBlockView<T>) => string} [options.renderNodeLabel]
|
|
142
|
-
*/
|
|
143
|
-
export const vis = async function* (blocks, head, options = {}) {
|
|
144
|
-
const renderNodeLabel = options.renderNodeLabel ?? (b => shortLink(b.cid));
|
|
145
|
-
const events = new EventFetcher(blocks);
|
|
146
|
-
yield 'digraph clock {';
|
|
147
|
-
yield ' node [shape=point fontname="Courier"]; head;';
|
|
148
|
-
const hevents = await Promise.all(head.map(link => events.get(link)));
|
|
149
|
-
/** @type {import('multiformats').Link<API.EventView<any>>[]} */
|
|
150
|
-
const links = [];
|
|
151
|
-
const nodes = new Set();
|
|
152
|
-
for (const e of hevents) {
|
|
153
|
-
nodes.add(e.cid.toString());
|
|
154
|
-
yield ` node [shape=oval fontname="Courier"]; ${e.cid} [label="${renderNodeLabel(e)}"];`;
|
|
155
|
-
yield ` head -> ${e.cid};`;
|
|
156
|
-
for (const p of e.value.parents) {
|
|
157
|
-
yield ` ${e.cid} -> ${p};`;
|
|
158
|
-
}
|
|
159
|
-
links.push(...e.value.parents);
|
|
160
|
-
}
|
|
161
|
-
while (links.length) {
|
|
162
|
-
const link = links.shift();
|
|
163
|
-
if (!link)
|
|
164
|
-
break;
|
|
165
|
-
if (nodes.has(link.toString()))
|
|
166
|
-
continue;
|
|
167
|
-
nodes.add(link.toString());
|
|
168
|
-
const block = await events.get(link);
|
|
169
|
-
yield ` node [shape=oval]; ${link} [label="${renderNodeLabel(block)}" fontname="Courier"];`;
|
|
170
|
-
for (const p of block.value.parents) {
|
|
171
|
-
yield ` ${link} -> ${p};`;
|
|
172
|
-
}
|
|
173
|
-
links.push(...block.value.parents);
|
|
174
|
-
}
|
|
175
|
-
yield '}';
|
|
176
|
-
};
|
|
177
|
-
/** @param {import('multiformats').UnknownLink} l */
|
|
178
|
-
const shortLink = l => `${String(l).slice(0, 4)}..${String(l).slice(-4)}`;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ShardDiff, ShardLink, UnknownLink } from '../api.js';
|
|
2
|
-
import { EventLink, EventBlockView } from '../clock/api.js';
|
|
3
|
-
export { BlockFetcher, UnknownLink, ShardBlockView, ShardDiff, ShardLink, EntriesOptions } from '../api.js';
|
|
4
|
-
export { EventBlockView, EventLink } from '../clock/api.js';
|
|
5
|
-
export interface Result extends ShardDiff {
|
|
6
|
-
root: ShardLink;
|
|
7
|
-
head: EventLink<Operation>[];
|
|
8
|
-
event?: EventBlockView<Operation>;
|
|
9
|
-
}
|
|
10
|
-
export type Operation = (PutOperation | DeleteOperation | BatchOperation) & {
|
|
11
|
-
root: ShardLink;
|
|
12
|
-
};
|
|
13
|
-
export interface PutOperation {
|
|
14
|
-
type: 'put';
|
|
15
|
-
key: string;
|
|
16
|
-
value: UnknownLink;
|
|
17
|
-
}
|
|
18
|
-
export interface DeleteOperation {
|
|
19
|
-
type: 'del';
|
|
20
|
-
key: string;
|
|
21
|
-
}
|
|
22
|
-
export interface BatchOperation {
|
|
23
|
-
type: 'batch';
|
|
24
|
-
ops: Array<PutOperation | DeleteOperation>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/crdt/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE3D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC3G,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3D,MAAM,WAAW,MAAO,SAAQ,SAAS;IACvC,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,CAAA;IAC5B,KAAK,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;CAClC;AAED,MAAM,MAAM,SAAS,GAAG,CACpB,YAAY,GACZ,eAAe,GACf,cAAc,CACjB,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAEvB,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,WAAW,CAAA;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,KAAK,CAAC,YAAY,GAAC,eAAe,CAAC,CAAA;CACzC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Batcher, BatcherShardEntry, ShardBlockView, BlockFetcher, ShardLink, UnknownLink } from '../../batch/api.js';
|
|
2
|
-
import { Operation, BatchOperation, EventLink, Result } from '../api.js';
|
|
3
|
-
export { Batcher, BatcherShardEntry, ShardBlockView, BlockFetcher, ShardLink, UnknownLink, Operation, BatchOperation, EventLink, Result };
|
|
4
|
-
export interface CRDTBatcher extends Batcher {
|
|
5
|
-
/**
|
|
6
|
-
* Encode all altered shards in the batch and return the new root CID, new
|
|
7
|
-
* clock head, the new clock event and the difference blocks.
|
|
8
|
-
*/
|
|
9
|
-
commit(): Promise<Result>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/crdt/batch/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,SAAS,EACT,WAAW,EACZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAExE,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,cAAc,EACd,SAAS,EACT,MAAM,EACP,CAAA;AAED,MAAM,WAAW,WAAY,SAAQ,OAAO;IAC1C;;;OAGG;IACH,MAAM,IAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { BatchCommittedError };
|
|
2
|
-
export function create(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[]): Promise<API.CRDTBatcher>;
|
|
3
|
-
import { BatchCommittedError } from '../../batch/index.js';
|
|
4
|
-
import * as API from './api.js';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/crdt/batch/index.js"],"names":[],"mappings":";AA0JO,+BAJI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAC5B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAEmC;oCArJpC,sBAAsB;qBAJrC,UAAU"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
import * as API from './api.js';
|
|
3
|
-
import * as Shard from '../../shard.js';
|
|
4
|
-
import { ShardFetcher, ShardBlock } from '../../shard.js';
|
|
5
|
-
import * as Batch from '../../batch/index.js';
|
|
6
|
-
import { BatchCommittedError } from '../../batch/index.js';
|
|
7
|
-
import * as CRDT from '../index.js';
|
|
8
|
-
import * as Clock from '../../clock/index.js';
|
|
9
|
-
import { EventBlock } from '../../clock/index.js';
|
|
10
|
-
import { MemoryBlockstore, MultiBlockFetcher } from '../../block.js';
|
|
11
|
-
export { BatchCommittedError };
|
|
12
|
-
/** @implements {API.CRDTBatcher} */
|
|
13
|
-
class Batcher {
|
|
14
|
-
#committed = false;
|
|
15
|
-
/**
|
|
16
|
-
* @param {object} init
|
|
17
|
-
* @param {API.BlockFetcher} init.blocks Block storage.
|
|
18
|
-
* @param {API.EventLink<API.Operation>[]} init.head Merkle clock head.
|
|
19
|
-
* @param {API.BatcherShardEntry[]} init.entries The entries in this shard.
|
|
20
|
-
* @param {string} init.prefix Key prefix.
|
|
21
|
-
* @param {number} init.version Shard compatibility version.
|
|
22
|
-
* @param {string} init.keyChars Characters allowed in keys, referring to a known character set.
|
|
23
|
-
* @param {number} init.maxKeySize Max key size in bytes.
|
|
24
|
-
* @param {API.ShardBlockView} init.base Original shard this batcher is based on.
|
|
25
|
-
* @param {API.ShardBlockView[]} init.additions Additions to include in the committed batch.
|
|
26
|
-
* @param {API.ShardBlockView[]} init.removals Removals to include in the committed batch.
|
|
27
|
-
*/
|
|
28
|
-
constructor({ blocks, head, entries, prefix, version, keyChars, maxKeySize, base, additions, removals }) {
|
|
29
|
-
this.blocks = blocks;
|
|
30
|
-
this.head = head;
|
|
31
|
-
this.prefix = prefix;
|
|
32
|
-
this.entries = [...entries];
|
|
33
|
-
this.base = base;
|
|
34
|
-
this.version = version;
|
|
35
|
-
this.keyChars = keyChars;
|
|
36
|
-
this.maxKeySize = maxKeySize;
|
|
37
|
-
this.additions = additions;
|
|
38
|
-
this.removals = removals;
|
|
39
|
-
/** @type {API.BatchOperation['ops']} */
|
|
40
|
-
this.ops = [];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* @param {string} key The key of the value to put.
|
|
44
|
-
* @param {API.UnknownLink} value The value to put.
|
|
45
|
-
* @returns {Promise<void>}
|
|
46
|
-
*/
|
|
47
|
-
async put(key, value) {
|
|
48
|
-
if (this.#committed)
|
|
49
|
-
throw new BatchCommittedError();
|
|
50
|
-
await Batch.put(this.blocks, this, key, value);
|
|
51
|
-
this.ops.push({ type: 'put', key, value });
|
|
52
|
-
}
|
|
53
|
-
async commit() {
|
|
54
|
-
if (this.#committed)
|
|
55
|
-
throw new BatchCommittedError();
|
|
56
|
-
this.#committed = true;
|
|
57
|
-
const res = await Batch.commit(this);
|
|
58
|
-
/** @type {API.Operation} */
|
|
59
|
-
const data = { type: 'batch', ops: this.ops, root: res.root };
|
|
60
|
-
const event = await EventBlock.create(data, this.head);
|
|
61
|
-
const mblocks = new MemoryBlockstore();
|
|
62
|
-
const blocks = new MultiBlockFetcher(mblocks, this.blocks);
|
|
63
|
-
mblocks.putSync(event.cid, event.bytes);
|
|
64
|
-
const head = await Clock.advance(blocks, this.head, event.cid);
|
|
65
|
-
/** @type {Map<string, API.ShardBlockView>} */
|
|
66
|
-
const additions = new Map();
|
|
67
|
-
/** @type {Map<string, API.ShardBlockView>} */
|
|
68
|
-
const removals = new Map();
|
|
69
|
-
for (const a of this.additions) {
|
|
70
|
-
additions.set(a.cid.toString(), a);
|
|
71
|
-
}
|
|
72
|
-
for (const r of this.removals) {
|
|
73
|
-
removals.set(r.cid.toString(), r);
|
|
74
|
-
}
|
|
75
|
-
for (const a of res.additions) {
|
|
76
|
-
if (removals.has(a.cid.toString())) {
|
|
77
|
-
removals.delete(a.cid.toString());
|
|
78
|
-
}
|
|
79
|
-
additions.set(a.cid.toString(), a);
|
|
80
|
-
}
|
|
81
|
-
for (const r of res.removals) {
|
|
82
|
-
if (additions.has(r.cid.toString())) {
|
|
83
|
-
additions.delete(r.cid.toString());
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
removals.set(r.cid.toString(), r);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
head,
|
|
91
|
-
event,
|
|
92
|
-
root: res.root,
|
|
93
|
-
additions: [...additions.values()],
|
|
94
|
-
removals: [...removals.values()]
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @param {object} init
|
|
99
|
-
* @param {API.BlockFetcher} init.blocks Block storage.
|
|
100
|
-
* @param {API.EventLink<API.Operation>[]} init.head Merkle clock head.
|
|
101
|
-
*/
|
|
102
|
-
static async create({ blocks, head }) {
|
|
103
|
-
const mblocks = new MemoryBlockstore();
|
|
104
|
-
blocks = new MultiBlockFetcher(mblocks, blocks);
|
|
105
|
-
if (!head.length) {
|
|
106
|
-
const base = await ShardBlock.create();
|
|
107
|
-
mblocks.putSync(base.cid, base.bytes);
|
|
108
|
-
return new Batcher({
|
|
109
|
-
blocks,
|
|
110
|
-
head,
|
|
111
|
-
entries: [],
|
|
112
|
-
base,
|
|
113
|
-
additions: [base],
|
|
114
|
-
removals: [],
|
|
115
|
-
...Shard.configure(base.value)
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
const { root, additions, removals } = await CRDT.root(blocks, head);
|
|
119
|
-
for (const a of additions) {
|
|
120
|
-
mblocks.putSync(a.cid, a.bytes);
|
|
121
|
-
}
|
|
122
|
-
const shards = new ShardFetcher(blocks);
|
|
123
|
-
const base = await shards.get(root);
|
|
124
|
-
return new Batcher({
|
|
125
|
-
blocks,
|
|
126
|
-
head,
|
|
127
|
-
entries: base.value.entries,
|
|
128
|
-
base,
|
|
129
|
-
additions,
|
|
130
|
-
removals,
|
|
131
|
-
...Shard.configure(base.value)
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @param {API.BlockFetcher} blocks Bucket block storage.
|
|
137
|
-
* @param {API.EventLink<API.Operation>[]} head Merkle clock head.
|
|
138
|
-
* @returns {Promise<API.CRDTBatcher>}
|
|
139
|
-
*/
|
|
140
|
-
export const create = (blocks, head) => Batcher.create({ blocks, head });
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function put(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[], key: string, value: API.UnknownLink): Promise<API.Result>;
|
|
2
|
-
export function del(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[], key: string, options?: object): Promise<API.Result>;
|
|
3
|
-
export function root(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[]): Promise<{
|
|
4
|
-
root: API.ShardLink;
|
|
5
|
-
} & API.ShardDiff>;
|
|
6
|
-
export function get(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[], key: string): Promise<import("multiformats").Link<unknown, number, number, import("multiformats").Version> | undefined>;
|
|
7
|
-
export function entries(blocks: API.BlockFetcher, head: API.EventLink<API.Operation>[], options?: API.EntriesOptions): AsyncGenerator<import("../api.js").ShardValueEntry, void, any>;
|
|
8
|
-
import * as API from './api.js';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crdt/index.js"],"names":[],"mappings":"AAmBO,4BANI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAC9B,MAAM,SACN,GAAG,CAAC,WAAW,GACb,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAoG/B;AAYM,4BANI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAC9B,MAAM,YACN,MAAM,GACJ,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAI/B;AAYM,6BAJI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAC5B,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC,SAAS,CAAA;CAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAsE5D;AAOM,4BAJI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAC9B,MAAM,6GAShB;AAOM,gCAJI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,YAC9B,GAAG,CAAC,cAAc,kEAS5B;qBA9OoB,UAAU"}
|