@atproto/repo 0.0.1 → 0.1.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/bench/mst.bench.ts +7 -4
- package/bench/repo.bench.ts +25 -16
- package/dist/block-map.d.ts +25 -0
- package/dist/data-diff.d.ts +36 -0
- package/dist/error.d.ts +20 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +11605 -10399
- package/dist/index.js.map +4 -4
- package/dist/mst/diff.d.ts +4 -33
- package/dist/mst/mst.d.ts +68 -25
- package/dist/mst/util.d.ts +13 -5
- package/dist/parse.d.ts +16 -0
- package/dist/readable-repo.d.ts +22 -0
- package/dist/repo.d.ts +14 -30
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/memory-blockstore.d.ts +28 -0
- package/dist/storage/readable-blockstore.d.ts +24 -0
- package/dist/storage/repo-storage.d.ts +18 -0
- package/dist/storage/sync-storage.d.ts +15 -0
- package/dist/storage/types.d.ts +3 -0
- package/dist/sync/consumer.d.ts +18 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/provider.d.ts +9 -0
- package/dist/types.d.ts +124 -317
- package/dist/util.d.ts +31 -12
- package/dist/verify.d.ts +26 -4
- package/package.json +4 -2
- package/src/block-map.ts +95 -0
- package/src/cid-set.ts +1 -2
- package/src/data-diff.ts +121 -0
- package/src/error.ts +31 -0
- package/src/index.ts +3 -1
- package/src/mst/diff.ts +120 -90
- package/src/mst/mst.ts +185 -184
- package/src/mst/util.ts +54 -31
- package/src/parse.ts +44 -0
- package/src/readable-repo.ts +75 -0
- package/src/repo.ts +119 -249
- package/src/storage/index.ts +4 -0
- package/src/storage/memory-blockstore.ts +114 -0
- package/src/storage/readable-blockstore.ts +56 -0
- package/src/storage/repo-storage.ts +42 -0
- package/src/storage/sync-storage.ts +35 -0
- package/src/storage/types.ts +3 -0
- package/src/sync/consumer.ts +137 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/provider.ts +91 -0
- package/src/types.ts +101 -62
- package/src/util.ts +237 -56
- package/src/verify.ts +207 -42
- package/tests/_util.ts +132 -97
- package/tests/mst.test.ts +269 -122
- package/tests/repo.test.ts +48 -50
- package/tests/sync/checkout.test.ts +57 -0
- package/tests/sync/diff.test.ts +87 -0
- package/tests/sync/narrow.test.ts +145 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +2 -1
- package/src/blockstore/index.ts +0 -2
- package/src/blockstore/ipld-store.ts +0 -103
- package/src/blockstore/memory-blockstore.ts +0 -49
- package/src/sync.ts +0 -38
- package/tests/sync.test.ts +0 -129
package/bench/mst.bench.ts
CHANGED
|
@@ -24,14 +24,14 @@ describe('MST Benchmarks', () => {
|
|
|
24
24
|
const size = 500000
|
|
25
25
|
|
|
26
26
|
beforeAll(async () => {
|
|
27
|
-
mapping = await util.
|
|
27
|
+
mapping = await util.generateBulkDataKeys(size)
|
|
28
28
|
shuffled = util.shuffle(Object.entries(mapping))
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
// const fanouts: Fanout[] = [8, 16, 32]
|
|
32
32
|
const fanouts: Fanout[] = [16, 32]
|
|
33
33
|
it('benchmarks various fanouts', async () => {
|
|
34
|
-
|
|
34
|
+
const benches: BenchmarkData[] = []
|
|
35
35
|
for (const fanout of fanouts) {
|
|
36
36
|
const blockstore = new MemoryBlockstore()
|
|
37
37
|
let mst = await MST.create(blockstore, [], { fanout })
|
|
@@ -44,11 +44,11 @@ describe('MST Benchmarks', () => {
|
|
|
44
44
|
|
|
45
45
|
const doneAdding = Date.now()
|
|
46
46
|
|
|
47
|
-
const root = await
|
|
47
|
+
const root = await util.saveMst(blockstore, mst)
|
|
48
48
|
|
|
49
49
|
const doneSaving = Date.now()
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
const reloaded = await MST.load(blockstore, root, { fanout })
|
|
52
52
|
const widthTracker = new NodeWidths()
|
|
53
53
|
for await (const entry of reloaded.walk()) {
|
|
54
54
|
await widthTracker.trackEntry(entry)
|
|
@@ -64,6 +64,9 @@ describe('MST Benchmarks', () => {
|
|
|
64
64
|
for (const entry of path) {
|
|
65
65
|
if (entry.isTree()) {
|
|
66
66
|
const bytes = await blockstore.getBytes(entry.pointer)
|
|
67
|
+
if (!bytes) {
|
|
68
|
+
throw new Error(`Bytes not found: ${entry.pointer}`)
|
|
69
|
+
}
|
|
67
70
|
proofSize += bytes.byteLength
|
|
68
71
|
}
|
|
69
72
|
}
|
package/bench/repo.bench.ts
CHANGED
|
@@ -1,37 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { TID } from '@atproto/common'
|
|
2
|
+
import * as crypto from '@atproto/crypto'
|
|
3
|
+
import { Secp256k1Keypair } from '@atproto/crypto'
|
|
4
|
+
import { MemoryBlockstore, Repo, WriteOpAction } from '../src'
|
|
3
5
|
import * as util from '../tests/_util'
|
|
4
6
|
|
|
5
7
|
describe('Repo Benchmarks', () => {
|
|
6
|
-
const verifier = new auth.Verifier()
|
|
7
8
|
const size = 10000
|
|
8
9
|
|
|
9
10
|
let blockstore: MemoryBlockstore
|
|
10
|
-
let
|
|
11
|
+
let keypair: crypto.Keypair
|
|
11
12
|
let repo: Repo
|
|
12
13
|
|
|
13
14
|
beforeAll(async () => {
|
|
14
15
|
blockstore = new MemoryBlockstore()
|
|
15
|
-
|
|
16
|
-
await
|
|
17
|
-
repo = await Repo.create(blockstore, await authStore.did(), authStore)
|
|
16
|
+
keypair = await Secp256k1Keypair.create()
|
|
17
|
+
repo = await Repo.create(blockstore, await keypair.did(), keypair)
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
it('calculates size', async () => {
|
|
21
|
-
const posts = repo.getCollection('app.bsky.post')
|
|
22
21
|
for (let i = 0; i < size; i++) {
|
|
23
22
|
if (i % 500 === 0) {
|
|
24
23
|
console.log(i)
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
|
|
26
|
+
await repo.applyCommit(
|
|
27
|
+
{
|
|
28
|
+
action: WriteOpAction.Create,
|
|
29
|
+
collection: 'app.bsky.post',
|
|
30
|
+
rkey: TID.nextStr(),
|
|
31
|
+
value: {
|
|
32
|
+
$type: 'app.bsky.post',
|
|
33
|
+
text: util.randomStr(150),
|
|
34
|
+
reply: {
|
|
35
|
+
root: 'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
|
|
36
|
+
parent:
|
|
37
|
+
'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
|
|
38
|
+
},
|
|
39
|
+
createdAt: new Date().toISOString(),
|
|
40
|
+
},
|
|
32
41
|
},
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
keypair,
|
|
43
|
+
)
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
console.log('SIZE: ', await blockstore.sizeInBytes())
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LexValue } from '@atproto/lexicon';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
export declare class BlockMap {
|
|
4
|
+
private map;
|
|
5
|
+
add(value: LexValue): Promise<CID>;
|
|
6
|
+
set(cid: CID, bytes: Uint8Array): void;
|
|
7
|
+
get(cid: CID): Uint8Array | undefined;
|
|
8
|
+
getMany(cids: CID[]): {
|
|
9
|
+
blocks: BlockMap;
|
|
10
|
+
missing: CID[];
|
|
11
|
+
};
|
|
12
|
+
has(cid: CID): boolean;
|
|
13
|
+
clear(): void;
|
|
14
|
+
forEach(cb: (bytes: Uint8Array, cid: CID) => void): void;
|
|
15
|
+
entries(): Entry[];
|
|
16
|
+
addMap(toAdd: BlockMap): void;
|
|
17
|
+
get size(): number;
|
|
18
|
+
get byteSize(): number;
|
|
19
|
+
equals(other: BlockMap): boolean;
|
|
20
|
+
}
|
|
21
|
+
declare type Entry = {
|
|
22
|
+
cid: CID;
|
|
23
|
+
bytes: Uint8Array;
|
|
24
|
+
};
|
|
25
|
+
export default BlockMap;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CID } from 'multiformats';
|
|
2
|
+
import CidSet from './cid-set';
|
|
3
|
+
import { DataStore } from './types';
|
|
4
|
+
export declare class DataDiff {
|
|
5
|
+
adds: Record<string, DataAdd>;
|
|
6
|
+
updates: Record<string, DataUpdate>;
|
|
7
|
+
deletes: Record<string, DataDelete>;
|
|
8
|
+
newCids: CidSet;
|
|
9
|
+
removedCids: CidSet;
|
|
10
|
+
static of(curr: DataStore, prev: DataStore | null): Promise<DataDiff>;
|
|
11
|
+
recordAdd(key: string, cid: CID): void;
|
|
12
|
+
recordUpdate(key: string, prev: CID, cid: CID): void;
|
|
13
|
+
recordDelete(key: string, cid: CID): void;
|
|
14
|
+
recordNewCid(cid: CID): void;
|
|
15
|
+
recordRemovedCid(cid: CID): void;
|
|
16
|
+
addDiff(diff: DataDiff): void;
|
|
17
|
+
addList(): DataAdd[];
|
|
18
|
+
updateList(): DataUpdate[];
|
|
19
|
+
deleteList(): DataDelete[];
|
|
20
|
+
newCidList(): CID[];
|
|
21
|
+
updatedKeys(): string[];
|
|
22
|
+
}
|
|
23
|
+
export declare type DataAdd = {
|
|
24
|
+
key: string;
|
|
25
|
+
cid: CID;
|
|
26
|
+
};
|
|
27
|
+
export declare type DataUpdate = {
|
|
28
|
+
key: string;
|
|
29
|
+
prev: CID;
|
|
30
|
+
cid: CID;
|
|
31
|
+
};
|
|
32
|
+
export declare type DataDelete = {
|
|
33
|
+
key: string;
|
|
34
|
+
cid: CID;
|
|
35
|
+
};
|
|
36
|
+
export default DataDiff;
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
export declare class MissingBlockError extends Error {
|
|
3
|
+
cid: CID;
|
|
4
|
+
constructor(cid: CID, def?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class MissingBlocksError extends Error {
|
|
7
|
+
context: string;
|
|
8
|
+
cids: CID[];
|
|
9
|
+
constructor(context: string, cids: CID[]);
|
|
10
|
+
}
|
|
11
|
+
export declare class MissingCommitBlocksError extends Error {
|
|
12
|
+
commit: CID;
|
|
13
|
+
cids: CID[];
|
|
14
|
+
constructor(commit: CID, cids: CID[]);
|
|
15
|
+
}
|
|
16
|
+
export declare class UnexpectedObjectError extends Error {
|
|
17
|
+
cid: CID;
|
|
18
|
+
def: string;
|
|
19
|
+
constructor(cid: CID, def: string);
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './block-map';
|
|
2
|
+
export * from './cid-set';
|
|
2
3
|
export * from './repo';
|
|
3
4
|
export * from './mst';
|
|
4
5
|
export * from './storage';
|
|
6
|
+
export * from './sync';
|
|
5
7
|
export * from './types';
|
|
6
8
|
export * from './verify';
|
|
7
9
|
export * from './util';
|