@atproto/repo 0.1.0 → 0.2.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/dist/block-map.d.ts +2 -0
- package/dist/data-diff.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12090 -2882
- package/dist/index.js.map +4 -4
- package/dist/mst/mst.d.ts +13 -14
- package/dist/readable-repo.d.ts +4 -3
- package/dist/repo.d.ts +6 -2
- package/dist/src/block-map.d.ts +23 -0
- package/dist/src/blockstore/persistent-blockstore.d.ts +12 -0
- package/dist/src/cid-set.d.ts +14 -0
- package/dist/src/collection.d.ts +22 -0
- package/dist/src/data-diff.d.ts +34 -0
- package/dist/src/error.d.ts +21 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/mst/diff.d.ts +33 -0
- package/dist/src/mst/index.d.ts +4 -0
- package/dist/src/mst/mst.d.ts +106 -0
- package/dist/src/mst/util.d.ts +9 -0
- package/dist/src/mst/walker.d.ts +22 -0
- package/dist/src/parse.d.ts +11 -0
- package/dist/src/readable-repo.d.ts +25 -0
- package/dist/src/repo.d.ts +39 -0
- package/dist/src/storage/error.d.ts +22 -0
- package/dist/src/storage/index.d.ts +1 -0
- package/dist/src/storage/memory-blobstore.d.ts +1 -0
- package/dist/src/storage/memory-blockstore.d.ts +28 -0
- package/dist/src/storage/readable-blockstore.d.ts +21 -0
- package/dist/src/storage/repo-storage.d.ts +18 -0
- package/dist/src/storage/sync-storage.d.ts +15 -0
- package/dist/src/storage/types.d.ts +12 -0
- package/dist/src/storage/util.d.ts +17 -0
- package/dist/src/structure.d.ts +39 -0
- package/dist/src/sync/consumer.d.ts +19 -0
- package/dist/src/sync/index.d.ts +2 -0
- package/dist/src/sync/producer.d.ts +13 -0
- package/dist/src/sync/provider.d.ts +11 -0
- package/dist/src/types.d.ts +368 -0
- package/dist/src/util.d.ts +13 -0
- package/dist/src/verify.d.ts +5 -0
- package/dist/storage/memory-blockstore.d.ts +2 -1
- package/dist/storage/repo-storage.d.ts +2 -1
- package/dist/storage/types.d.ts +1 -0
- package/dist/sync/consumer.d.ts +1 -0
- package/dist/sync/provider.d.ts +4 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types.d.ts +30 -31
- package/dist/util.d.ts +6 -2
- package/dist/verify.d.ts +6 -1
- package/jest.bench.config.js +2 -1
- package/package.json +11 -6
- package/src/block-map.ts +8 -0
- package/src/data-diff.ts +2 -6
- package/src/index.ts +1 -0
- package/src/mst/mst.ts +1 -10
- package/src/readable-repo.ts +3 -3
- package/src/repo.ts +33 -2
- package/src/storage/memory-blockstore.ts +20 -1
- package/src/storage/repo-storage.ts +2 -1
- package/src/storage/types.ts +1 -0
- package/src/sync/consumer.ts +4 -1
- package/src/sync/provider.ts +11 -11
- package/src/types.ts +19 -21
- package/src/util.ts +34 -13
- package/src/verify.ts +52 -11
- package/tests/rebase.test.ts +37 -0
- package/tests/sync/checkout.test.ts +21 -3
- package/tests/sync/diff.test.ts +9 -4
- package/tests/sync/narrow.test.ts +8 -4
- package/tests/util.test.ts +21 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +1 -1
- /package/dist/{blockstore → src/blockstore}/index.d.ts +0 -0
- /package/dist/{blockstore → src/blockstore}/ipld-store.d.ts +0 -0
- /package/dist/{blockstore → src/blockstore}/memory-blockstore.d.ts +0 -0
- /package/dist/{sync.d.ts → src/sync.d.ts} +0 -0
package/dist/mst/mst.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import { CID } from 'multiformats';
|
|
3
3
|
import { ReadableBlockstore } from '../storage';
|
|
4
|
-
import { DataStore } from '../types';
|
|
5
4
|
import { BlockWriter } from '@ipld/car/api';
|
|
6
5
|
import BlockMap from '../block-map';
|
|
7
6
|
import CidSet from '../cid-set';
|
|
@@ -18,27 +17,27 @@ declare const nodeData: z.ZodObject<{
|
|
|
18
17
|
v: CID;
|
|
19
18
|
t: CID | null;
|
|
20
19
|
}, {
|
|
21
|
-
v?: any;
|
|
22
|
-
t?: any;
|
|
23
20
|
p: number;
|
|
24
21
|
k: Uint8Array;
|
|
22
|
+
v?: any;
|
|
23
|
+
t?: any;
|
|
25
24
|
}>, "many">;
|
|
26
25
|
}, "strip", z.ZodTypeAny, {
|
|
27
|
-
l: CID | null;
|
|
28
26
|
e: {
|
|
29
27
|
p: number;
|
|
30
28
|
k: Uint8Array;
|
|
31
29
|
v: CID;
|
|
32
30
|
t: CID | null;
|
|
33
31
|
}[];
|
|
32
|
+
l: CID | null;
|
|
34
33
|
}, {
|
|
35
|
-
l?: any;
|
|
36
34
|
e: {
|
|
37
|
-
v?: any;
|
|
38
|
-
t?: any;
|
|
39
35
|
p: number;
|
|
40
36
|
k: Uint8Array;
|
|
37
|
+
v?: any;
|
|
38
|
+
t?: any;
|
|
41
39
|
}[];
|
|
40
|
+
l?: any;
|
|
42
41
|
}>;
|
|
43
42
|
export declare type NodeData = z.infer<typeof nodeData>;
|
|
44
43
|
export declare const nodeDataDef: {
|
|
@@ -56,34 +55,34 @@ export declare const nodeDataDef: {
|
|
|
56
55
|
v: CID;
|
|
57
56
|
t: CID | null;
|
|
58
57
|
}, {
|
|
59
|
-
v?: any;
|
|
60
|
-
t?: any;
|
|
61
58
|
p: number;
|
|
62
59
|
k: Uint8Array;
|
|
60
|
+
v?: any;
|
|
61
|
+
t?: any;
|
|
63
62
|
}>, "many">;
|
|
64
63
|
}, "strip", z.ZodTypeAny, {
|
|
65
|
-
l: CID | null;
|
|
66
64
|
e: {
|
|
67
65
|
p: number;
|
|
68
66
|
k: Uint8Array;
|
|
69
67
|
v: CID;
|
|
70
68
|
t: CID | null;
|
|
71
69
|
}[];
|
|
70
|
+
l: CID | null;
|
|
72
71
|
}, {
|
|
73
|
-
l?: any;
|
|
74
72
|
e: {
|
|
75
|
-
v?: any;
|
|
76
|
-
t?: any;
|
|
77
73
|
p: number;
|
|
78
74
|
k: Uint8Array;
|
|
75
|
+
v?: any;
|
|
76
|
+
t?: any;
|
|
79
77
|
}[];
|
|
78
|
+
l?: any;
|
|
80
79
|
}>;
|
|
81
80
|
};
|
|
82
81
|
export declare type NodeEntry = MST | Leaf;
|
|
83
82
|
export declare type MstOpts = {
|
|
84
83
|
layer: number;
|
|
85
84
|
};
|
|
86
|
-
export declare class MST
|
|
85
|
+
export declare class MST {
|
|
87
86
|
storage: ReadableBlockstore;
|
|
88
87
|
entries: NodeEntry[] | null;
|
|
89
88
|
layer: number | null;
|
package/dist/readable-repo.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import { Commit,
|
|
2
|
+
import { Commit, RepoContents } from './types';
|
|
3
3
|
import { ReadableBlockstore } from './storage';
|
|
4
|
+
import { MST } from './mst';
|
|
4
5
|
declare type Params = {
|
|
5
6
|
storage: ReadableBlockstore;
|
|
6
|
-
data:
|
|
7
|
+
data: MST;
|
|
7
8
|
commit: Commit;
|
|
8
9
|
cid: CID;
|
|
9
10
|
};
|
|
10
11
|
export declare class ReadableRepo {
|
|
11
12
|
storage: ReadableBlockstore;
|
|
12
|
-
data:
|
|
13
|
+
data: MST;
|
|
13
14
|
commit: Commit;
|
|
14
15
|
cid: CID;
|
|
15
16
|
constructor(params: Params);
|
package/dist/repo.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
2
|
import * as crypto from '@atproto/crypto';
|
|
3
|
-
import { Commit,
|
|
3
|
+
import { Commit, RecordCreateOp, RecordWriteOp, CommitData, RebaseData } from './types';
|
|
4
4
|
import { RepoStorage } from './storage';
|
|
5
|
+
import { MST } from './mst';
|
|
5
6
|
import { ReadableRepo } from './readable-repo';
|
|
6
7
|
declare type Params = {
|
|
7
8
|
storage: RepoStorage;
|
|
8
|
-
data:
|
|
9
|
+
data: MST;
|
|
9
10
|
commit: Commit;
|
|
10
11
|
cid: CID;
|
|
11
12
|
};
|
|
@@ -19,5 +20,8 @@ export declare class Repo extends ReadableRepo {
|
|
|
19
20
|
formatCommit(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<CommitData>;
|
|
20
21
|
applyCommit(commitData: CommitData): Promise<Repo>;
|
|
21
22
|
applyWrites(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<Repo>;
|
|
23
|
+
formatRebase(keypair: crypto.Keypair): Promise<RebaseData>;
|
|
24
|
+
applyRebase(rebase: RebaseData): Promise<Repo>;
|
|
25
|
+
rebase(keypair: crypto.Keypair): Promise<Repo>;
|
|
22
26
|
}
|
|
23
27
|
export default Repo;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
export declare class BlockMap {
|
|
3
|
+
private map;
|
|
4
|
+
add(value: unknown): Promise<CID>;
|
|
5
|
+
set(cid: CID, bytes: Uint8Array): void;
|
|
6
|
+
get(cid: CID): Uint8Array | undefined;
|
|
7
|
+
getMany(cids: CID[]): {
|
|
8
|
+
blocks: BlockMap;
|
|
9
|
+
missing: CID[];
|
|
10
|
+
};
|
|
11
|
+
has(cid: CID): boolean;
|
|
12
|
+
clear(): void;
|
|
13
|
+
forEach(cb: (bytes: Uint8Array, cid: CID) => void): void;
|
|
14
|
+
entries(): Entry[];
|
|
15
|
+
addMap(toAdd: BlockMap): void;
|
|
16
|
+
get size(): number;
|
|
17
|
+
equals(other: BlockMap): boolean;
|
|
18
|
+
}
|
|
19
|
+
declare type Entry = {
|
|
20
|
+
cid: CID;
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
};
|
|
23
|
+
export default BlockMap;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import level from 'level';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
import IpldStore from './ipld-store';
|
|
4
|
+
export declare class PersistentBlockstore extends IpldStore {
|
|
5
|
+
store: level.Level;
|
|
6
|
+
constructor(location?: string);
|
|
7
|
+
getBytes(cid: CID): Promise<Uint8Array>;
|
|
8
|
+
putBytes(cid: CID, bytes: Uint8Array): Promise<void>;
|
|
9
|
+
has(cid: CID): Promise<boolean>;
|
|
10
|
+
destroy(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export default PersistentBlockstore;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CID } from 'multiformats';
|
|
2
|
+
export declare class CidSet {
|
|
3
|
+
private set;
|
|
4
|
+
constructor(arr?: CID[]);
|
|
5
|
+
add(cid: CID): CidSet;
|
|
6
|
+
addSet(toMerge: CidSet): CidSet;
|
|
7
|
+
subtractSet(toSubtract: CidSet): CidSet;
|
|
8
|
+
delete(cid: CID): this;
|
|
9
|
+
has(cid: CID): boolean;
|
|
10
|
+
size(): number;
|
|
11
|
+
clear(): CidSet;
|
|
12
|
+
toList(): CID[];
|
|
13
|
+
}
|
|
14
|
+
export default CidSet;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NSID } from '@atproto/nsid';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
import Repo from './repo';
|
|
4
|
+
export declare class Collection {
|
|
5
|
+
repo: Repo;
|
|
6
|
+
nsid: NSID;
|
|
7
|
+
constructor(repo: Repo, nsid: NSID | string);
|
|
8
|
+
name(): string;
|
|
9
|
+
dataIdForRecord(key: string): string;
|
|
10
|
+
getRecord(key: string): Promise<unknown | null>;
|
|
11
|
+
listRecords(count?: number, after?: string, before?: string): Promise<{
|
|
12
|
+
key: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
}[]>;
|
|
15
|
+
createRecord(record: unknown, rkey?: string): Promise<{
|
|
16
|
+
rkey: string;
|
|
17
|
+
cid: CID;
|
|
18
|
+
}>;
|
|
19
|
+
updateRecord(rkey: string, record: unknown): Promise<CID>;
|
|
20
|
+
deleteRecord(rkey: string): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export default Collection;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
static of(curr: DataStore, prev: DataStore | null): Promise<DataDiff>;
|
|
10
|
+
recordAdd(key: string, cid: CID): void;
|
|
11
|
+
recordUpdate(key: string, prev: CID, cid: CID): void;
|
|
12
|
+
recordDelete(key: string, cid: CID): void;
|
|
13
|
+
recordNewCid(cid: CID): void;
|
|
14
|
+
addDiff(diff: DataDiff): void;
|
|
15
|
+
addList(): DataAdd[];
|
|
16
|
+
updateList(): DataUpdate[];
|
|
17
|
+
deleteList(): DataDelete[];
|
|
18
|
+
newCidList(): CID[];
|
|
19
|
+
updatedKeys(): string[];
|
|
20
|
+
}
|
|
21
|
+
export declare type DataAdd = {
|
|
22
|
+
key: string;
|
|
23
|
+
cid: CID;
|
|
24
|
+
};
|
|
25
|
+
export declare type DataUpdate = {
|
|
26
|
+
key: string;
|
|
27
|
+
prev: CID;
|
|
28
|
+
cid: CID;
|
|
29
|
+
};
|
|
30
|
+
export declare type DataDelete = {
|
|
31
|
+
key: string;
|
|
32
|
+
cid: CID;
|
|
33
|
+
};
|
|
34
|
+
export default DataDiff;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Def } from '@atproto/common/src/check';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
export declare class MissingBlockError extends Error {
|
|
4
|
+
cid: CID;
|
|
5
|
+
constructor(cid: CID, def?: Def<unknown>);
|
|
6
|
+
}
|
|
7
|
+
export declare class MissingBlocksError extends Error {
|
|
8
|
+
context: string;
|
|
9
|
+
cids: CID[];
|
|
10
|
+
constructor(context: string, cids: CID[]);
|
|
11
|
+
}
|
|
12
|
+
export declare class MissingCommitBlocksError extends Error {
|
|
13
|
+
commit: CID;
|
|
14
|
+
cids: CID[];
|
|
15
|
+
constructor(commit: CID, cids: CID[]);
|
|
16
|
+
}
|
|
17
|
+
export declare class UnexpectedObjectError extends Error {
|
|
18
|
+
cid: CID;
|
|
19
|
+
def: Def<unknown>;
|
|
20
|
+
constructor(cid: CID, def: Def<unknown>);
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as auth from '@atproto/auth';
|
|
2
|
+
import { CID } from 'multiformats';
|
|
3
|
+
import CidSet from '../cid-set';
|
|
4
|
+
export declare class DataDiff {
|
|
5
|
+
adds: Record<string, DataAdd>;
|
|
6
|
+
updates: Record<string, DataUpdate>;
|
|
7
|
+
deletes: Record<string, DataDelete>;
|
|
8
|
+
newCids: CidSet;
|
|
9
|
+
recordAdd(key: string, cid: CID): void;
|
|
10
|
+
recordUpdate(key: string, prev: CID, cid: CID): void;
|
|
11
|
+
recordDelete(key: string, cid: CID): void;
|
|
12
|
+
recordNewCid(cid: CID): void;
|
|
13
|
+
addDiff(diff: DataDiff): void;
|
|
14
|
+
addList(): DataAdd[];
|
|
15
|
+
updateList(): DataUpdate[];
|
|
16
|
+
deleteList(): DataDelete[];
|
|
17
|
+
newCidList(): CID[];
|
|
18
|
+
updatedKeys(): string[];
|
|
19
|
+
neededCapabilities(rootDid: string): auth.ucans.Capability[];
|
|
20
|
+
}
|
|
21
|
+
export declare type DataAdd = {
|
|
22
|
+
key: string;
|
|
23
|
+
cid: CID;
|
|
24
|
+
};
|
|
25
|
+
export declare type DataUpdate = {
|
|
26
|
+
key: string;
|
|
27
|
+
prev: CID;
|
|
28
|
+
cid: CID;
|
|
29
|
+
};
|
|
30
|
+
export declare type DataDelete = {
|
|
31
|
+
key: string;
|
|
32
|
+
cid: CID;
|
|
33
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { CID } from 'multiformats';
|
|
3
|
+
import IpldStore from '../blockstore/ipld-store';
|
|
4
|
+
import { DataDiff } from './diff';
|
|
5
|
+
import { DataStore } from '../types';
|
|
6
|
+
import { BlockWriter } from '@ipld/car/api';
|
|
7
|
+
export declare const nodeDataDef: z.ZodObject<{
|
|
8
|
+
l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
9
|
+
e: z.ZodArray<z.ZodObject<{
|
|
10
|
+
p: z.ZodNumber;
|
|
11
|
+
k: z.ZodString;
|
|
12
|
+
v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
13
|
+
t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
t: CID | null;
|
|
16
|
+
p: number;
|
|
17
|
+
k: string;
|
|
18
|
+
v: CID;
|
|
19
|
+
}, {
|
|
20
|
+
t?: any;
|
|
21
|
+
v?: any;
|
|
22
|
+
p: number;
|
|
23
|
+
k: string;
|
|
24
|
+
}>, "many">;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
l: CID | null;
|
|
27
|
+
e: {
|
|
28
|
+
t: CID | null;
|
|
29
|
+
p: number;
|
|
30
|
+
k: string;
|
|
31
|
+
v: CID;
|
|
32
|
+
}[];
|
|
33
|
+
}, {
|
|
34
|
+
l?: any;
|
|
35
|
+
e: {
|
|
36
|
+
t?: any;
|
|
37
|
+
v?: any;
|
|
38
|
+
p: number;
|
|
39
|
+
k: string;
|
|
40
|
+
}[];
|
|
41
|
+
}>;
|
|
42
|
+
export declare type NodeData = z.infer<typeof nodeDataDef>;
|
|
43
|
+
export declare type NodeEntry = MST | Leaf;
|
|
44
|
+
export declare type Fanout = 2 | 8 | 16 | 32 | 64;
|
|
45
|
+
export declare type MstOpts = {
|
|
46
|
+
layer: number;
|
|
47
|
+
fanout: Fanout;
|
|
48
|
+
};
|
|
49
|
+
export declare class MST implements DataStore {
|
|
50
|
+
blockstore: IpldStore;
|
|
51
|
+
fanout: Fanout;
|
|
52
|
+
entries: NodeEntry[] | null;
|
|
53
|
+
layer: number | null;
|
|
54
|
+
pointer: CID;
|
|
55
|
+
outdatedPointer: boolean;
|
|
56
|
+
constructor(blockstore: IpldStore, fanout: Fanout, pointer: CID, entries: NodeEntry[] | null, layer: number | null);
|
|
57
|
+
static create(blockstore: IpldStore, entries?: NodeEntry[], opts?: Partial<MstOpts>): Promise<MST>;
|
|
58
|
+
static fromData(blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>): Promise<MST>;
|
|
59
|
+
static load(blockstore: IpldStore, cid: CID, opts?: Partial<MstOpts>): MST;
|
|
60
|
+
newTree(entries: NodeEntry[]): Promise<MST>;
|
|
61
|
+
getEntries(): Promise<NodeEntry[]>;
|
|
62
|
+
getPointer(): Promise<CID>;
|
|
63
|
+
getLayer(): Promise<number>;
|
|
64
|
+
attemptGetLayer(): Promise<number | null>;
|
|
65
|
+
stage(): Promise<CID>;
|
|
66
|
+
stageRecurse(trimTop?: boolean): Promise<CID>;
|
|
67
|
+
add(key: string, value: CID, knownZeros?: number): Promise<MST>;
|
|
68
|
+
get(key: string): Promise<CID | null>;
|
|
69
|
+
update(key: string, value: CID): Promise<MST>;
|
|
70
|
+
delete(key: string): Promise<MST>;
|
|
71
|
+
diff(other: MST): Promise<DataDiff>;
|
|
72
|
+
updateEntry(index: number, entry: NodeEntry): Promise<MST>;
|
|
73
|
+
removeEntry(index: number): Promise<MST>;
|
|
74
|
+
append(entry: NodeEntry): Promise<MST>;
|
|
75
|
+
prepend(entry: NodeEntry): Promise<MST>;
|
|
76
|
+
atIndex(index: number): Promise<NodeEntry | null>;
|
|
77
|
+
slice(start?: number | undefined, end?: number | undefined): Promise<NodeEntry[]>;
|
|
78
|
+
spliceIn(entry: NodeEntry, index: number): Promise<MST>;
|
|
79
|
+
replaceWithSplit(index: number, left: MST | null, leaf: Leaf, right: MST | null): Promise<MST>;
|
|
80
|
+
splitAround(key: string): Promise<[MST | null, MST | null]>;
|
|
81
|
+
appendMerge(toMerge: MST): Promise<MST>;
|
|
82
|
+
createChild(): Promise<MST>;
|
|
83
|
+
createParent(): Promise<MST>;
|
|
84
|
+
findGtOrEqualLeafIndex(key: string): Promise<number>;
|
|
85
|
+
walkLeavesFrom(key: string): AsyncIterable<Leaf>;
|
|
86
|
+
list(count: number, after?: string, before?: string): Promise<Leaf[]>;
|
|
87
|
+
listWithPrefix(prefix: string, count?: number): Promise<Leaf[]>;
|
|
88
|
+
walk(): AsyncIterable<NodeEntry>;
|
|
89
|
+
paths(): Promise<NodeEntry[][]>;
|
|
90
|
+
allNodes(): Promise<NodeEntry[]>;
|
|
91
|
+
leaves(): Promise<Leaf[]>;
|
|
92
|
+
leafCount(): Promise<number>;
|
|
93
|
+
writeToCarStream(car: BlockWriter): Promise<void>;
|
|
94
|
+
isTree(): this is MST;
|
|
95
|
+
isLeaf(): this is Leaf;
|
|
96
|
+
equals(other: NodeEntry): Promise<boolean>;
|
|
97
|
+
}
|
|
98
|
+
export declare class Leaf {
|
|
99
|
+
key: string;
|
|
100
|
+
value: CID;
|
|
101
|
+
constructor(key: string, value: CID);
|
|
102
|
+
isTree(): this is MST;
|
|
103
|
+
isLeaf(): this is Leaf;
|
|
104
|
+
equals(entry: NodeEntry): boolean;
|
|
105
|
+
}
|
|
106
|
+
export default MST;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CID } from 'multiformats';
|
|
2
|
+
import IpldStore from '../blockstore/ipld-store';
|
|
3
|
+
import { NodeEntry, NodeData, MstOpts, Fanout } from './mst';
|
|
4
|
+
export declare const leadingZerosOnHash: (key: string, fanout: Fanout) => Promise<number>;
|
|
5
|
+
export declare const layerForEntries: (entries: NodeEntry[], fanout: Fanout) => Promise<number | null>;
|
|
6
|
+
export declare const deserializeNodeData: (blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>) => Promise<NodeEntry[]>;
|
|
7
|
+
export declare const serializeNodeData: (entries: NodeEntry[]) => NodeData;
|
|
8
|
+
export declare const countPrefixLen: (a: string, b: string) => number;
|
|
9
|
+
export declare const cidForEntries: (entries: NodeEntry[]) => Promise<CID>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MST, NodeEntry } from './mst';
|
|
2
|
+
declare type WalkerStatusDone = {
|
|
3
|
+
done: true;
|
|
4
|
+
};
|
|
5
|
+
declare type WalkerStatusProgress = {
|
|
6
|
+
done: false;
|
|
7
|
+
curr: NodeEntry;
|
|
8
|
+
walking: MST | null;
|
|
9
|
+
index: number;
|
|
10
|
+
};
|
|
11
|
+
declare type WalkerStatus = WalkerStatusDone | WalkerStatusProgress;
|
|
12
|
+
export declare class MstWalker {
|
|
13
|
+
root: MST;
|
|
14
|
+
stack: WalkerStatus[];
|
|
15
|
+
status: WalkerStatus;
|
|
16
|
+
constructor(root: MST);
|
|
17
|
+
layer(): number;
|
|
18
|
+
stepOver(): Promise<void>;
|
|
19
|
+
stepInto(): Promise<void>;
|
|
20
|
+
advance(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export default MstWalker;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { check } from '@atproto/common';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
import BlockMap from './block-map';
|
|
4
|
+
export declare const getAndParse: <T>(blocks: BlockMap, cid: CID, def: check.Def<T>) => Promise<{
|
|
5
|
+
obj: T;
|
|
6
|
+
bytes: Uint8Array;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const parseObj: <T>(bytes: Uint8Array, cid: CID, def: check.Def<T>) => {
|
|
9
|
+
obj: T;
|
|
10
|
+
bytes: Uint8Array;
|
|
11
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { RepoRoot, Commit, DataStore, RepoMeta, RepoContents } from './types';
|
|
3
|
+
import { ReadableBlockstore } from './storage';
|
|
4
|
+
declare type Params = {
|
|
5
|
+
storage: ReadableBlockstore;
|
|
6
|
+
data: DataStore;
|
|
7
|
+
commit: Commit;
|
|
8
|
+
root: RepoRoot;
|
|
9
|
+
meta: RepoMeta;
|
|
10
|
+
cid: CID;
|
|
11
|
+
};
|
|
12
|
+
export declare class ReadableRepo {
|
|
13
|
+
storage: ReadableBlockstore;
|
|
14
|
+
data: DataStore;
|
|
15
|
+
commit: Commit;
|
|
16
|
+
root: RepoRoot;
|
|
17
|
+
meta: RepoMeta;
|
|
18
|
+
cid: CID;
|
|
19
|
+
constructor(params: Params);
|
|
20
|
+
static load(storage: ReadableBlockstore, commitCid: CID): Promise<ReadableRepo>;
|
|
21
|
+
get did(): string;
|
|
22
|
+
getRecord(collection: string, rkey: string): Promise<unknown | null>;
|
|
23
|
+
getContents(): Promise<RepoContents>;
|
|
24
|
+
}
|
|
25
|
+
export default ReadableRepo;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { BlockWriter } from '@ipld/car/writer';
|
|
3
|
+
import { RepoRoot, Commit, DataStore, RepoMeta, RecordCreateOp, RecordWriteOp } from './types';
|
|
4
|
+
import IpldStore from './blockstore/ipld-store';
|
|
5
|
+
import * as auth from '@atproto/auth';
|
|
6
|
+
declare type Params = {
|
|
7
|
+
blockstore: IpldStore;
|
|
8
|
+
data: DataStore;
|
|
9
|
+
commit: Commit;
|
|
10
|
+
root: RepoRoot;
|
|
11
|
+
meta: RepoMeta;
|
|
12
|
+
cid: CID;
|
|
13
|
+
stagedWrites: RecordWriteOp[];
|
|
14
|
+
};
|
|
15
|
+
export declare class Repo {
|
|
16
|
+
blockstore: IpldStore;
|
|
17
|
+
data: DataStore;
|
|
18
|
+
commit: Commit;
|
|
19
|
+
root: RepoRoot;
|
|
20
|
+
meta: RepoMeta;
|
|
21
|
+
cid: CID;
|
|
22
|
+
stagedWrites: RecordWriteOp[];
|
|
23
|
+
constructor(params: Params);
|
|
24
|
+
static create(blockstore: IpldStore, did: string, authStore: auth.AuthStore, initialRecords?: RecordCreateOp[]): Promise<Repo>;
|
|
25
|
+
static load(blockstore: IpldStore, cid: CID): Promise<Repo>;
|
|
26
|
+
private updateRepo;
|
|
27
|
+
get did(): string;
|
|
28
|
+
getRecord(collection: string, rkey: string): Promise<unknown | null>;
|
|
29
|
+
stageUpdate(write: RecordWriteOp | RecordWriteOp[]): Repo;
|
|
30
|
+
createCommit(authStore: auth.AuthStore, performUpdate?: (prev: CID, curr: CID) => Promise<CID | null>): Promise<Repo>;
|
|
31
|
+
revert(count: number): Promise<Repo>;
|
|
32
|
+
getCarNoHistory(): Promise<Uint8Array>;
|
|
33
|
+
getDiffCar(to: CID | null): Promise<Uint8Array>;
|
|
34
|
+
getFullHistory(): Promise<Uint8Array>;
|
|
35
|
+
private openCar;
|
|
36
|
+
writeCheckoutToCarStream(car: BlockWriter): Promise<void>;
|
|
37
|
+
writeCommitsToCarStream(car: BlockWriter, oldestCommit: CID | null, recentCommit: CID): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export default Repo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Def } from '@atproto/common/src/check';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
export declare class MissingBlockError extends Error {
|
|
4
|
+
cid: CID;
|
|
5
|
+
def?: Def<unknown> | undefined;
|
|
6
|
+
constructor(cid: CID, def?: Def<unknown> | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare class MissingBlocksError extends Error {
|
|
9
|
+
context: string;
|
|
10
|
+
cids: CID[];
|
|
11
|
+
constructor(context: string, cids: CID[]);
|
|
12
|
+
}
|
|
13
|
+
export declare class MissingCommitBlocksError extends Error {
|
|
14
|
+
commit: CID;
|
|
15
|
+
cids: CID[];
|
|
16
|
+
constructor(commit: CID, cids: CID[]);
|
|
17
|
+
}
|
|
18
|
+
export declare class UnexpectedObjectError extends Error {
|
|
19
|
+
cid: CID;
|
|
20
|
+
def: Def<unknown>;
|
|
21
|
+
constructor(cid: CID, def: Def<unknown>);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const thing = 1;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { CommitData } from '../types';
|
|
3
|
+
import BlockMap from '../block-map';
|
|
4
|
+
import RepoStorage from './repo-storage';
|
|
5
|
+
export declare class MemoryBlockstore extends RepoStorage {
|
|
6
|
+
blocks: BlockMap;
|
|
7
|
+
head: CID | null;
|
|
8
|
+
constructor(blocks?: BlockMap);
|
|
9
|
+
getHead(): Promise<CID | null>;
|
|
10
|
+
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
11
|
+
has(cid: CID): Promise<boolean>;
|
|
12
|
+
getBlocks(cids: CID[]): Promise<{
|
|
13
|
+
blocks: BlockMap;
|
|
14
|
+
missing: CID[];
|
|
15
|
+
}>;
|
|
16
|
+
putBlock(cid: CID, block: Uint8Array): Promise<void>;
|
|
17
|
+
putMany(blocks: BlockMap): Promise<void>;
|
|
18
|
+
indexCommits(commits: CommitData[]): Promise<void>;
|
|
19
|
+
updateHead(cid: CID, _prev: CID | null): Promise<void>;
|
|
20
|
+
applyCommit(commit: CommitData): Promise<void>;
|
|
21
|
+
getCommitPath(latest: CID, earliest: CID | null): Promise<CID[] | null>;
|
|
22
|
+
getBlocksForCommits(commits: CID[]): Promise<{
|
|
23
|
+
[commit: string]: BlockMap;
|
|
24
|
+
}>;
|
|
25
|
+
sizeInBytes(): Promise<number>;
|
|
26
|
+
destroy(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export default MemoryBlockstore;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { check } from '@atproto/common';
|
|
2
|
+
import { CID } from 'multiformats/cid';
|
|
3
|
+
import BlockMap from '../block-map';
|
|
4
|
+
export declare abstract class ReadableBlockstore {
|
|
5
|
+
abstract getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
6
|
+
abstract has(cid: CID): Promise<boolean>;
|
|
7
|
+
abstract getBlocks(cids: CID[]): Promise<{
|
|
8
|
+
blocks: BlockMap;
|
|
9
|
+
missing: CID[];
|
|
10
|
+
}>;
|
|
11
|
+
attemptRead<T>(cid: CID, def: check.Def<T>): Promise<{
|
|
12
|
+
obj: T;
|
|
13
|
+
bytes: Uint8Array;
|
|
14
|
+
} | null>;
|
|
15
|
+
readObjAndBytes<T>(cid: CID, def: check.Def<T>): Promise<{
|
|
16
|
+
obj: T;
|
|
17
|
+
bytes: Uint8Array;
|
|
18
|
+
}>;
|
|
19
|
+
readObj<T>(cid: CID, def: check.Def<T>): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
export default ReadableBlockstore;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import BlockMap from '../block-map';
|
|
3
|
+
import { CommitBlockData, CommitData } from '../types';
|
|
4
|
+
import ReadableBlockstore from './readable-blockstore';
|
|
5
|
+
export declare abstract class RepoStorage extends ReadableBlockstore {
|
|
6
|
+
abstract getHead(forUpdate?: boolean): Promise<CID | null>;
|
|
7
|
+
abstract getCommitPath(latest: CID, earliest: CID | null): Promise<CID[] | null>;
|
|
8
|
+
abstract getBlocksForCommits(commits: CID[]): Promise<{
|
|
9
|
+
[commit: string]: BlockMap;
|
|
10
|
+
}>;
|
|
11
|
+
abstract putBlock(cid: CID, block: Uint8Array): Promise<void>;
|
|
12
|
+
abstract putMany(blocks: BlockMap): Promise<void>;
|
|
13
|
+
abstract updateHead(cid: CID, prev: CID | null): Promise<void>;
|
|
14
|
+
abstract indexCommits(commit: CommitData[]): Promise<void>;
|
|
15
|
+
applyCommit(commit: CommitData): Promise<void>;
|
|
16
|
+
getCommits(latest: CID, earliest: CID | null): Promise<CommitBlockData[] | null>;
|
|
17
|
+
}
|
|
18
|
+
export default RepoStorage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import BlockMap from '../block-map';
|
|
3
|
+
import ReadableBlockstore from './readable-blockstore';
|
|
4
|
+
export declare class SyncStorage extends ReadableBlockstore {
|
|
5
|
+
staged: ReadableBlockstore;
|
|
6
|
+
saved: ReadableBlockstore;
|
|
7
|
+
constructor(staged: ReadableBlockstore, saved: ReadableBlockstore);
|
|
8
|
+
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
9
|
+
getBlocks(cids: CID[]): Promise<{
|
|
10
|
+
blocks: BlockMap;
|
|
11
|
+
missing: CID[];
|
|
12
|
+
}>;
|
|
13
|
+
has(cid: CID): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export default SyncStorage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import stream from 'stream';
|
|
3
|
+
import { CID } from 'multiformats/cid';
|
|
4
|
+
export interface BlobStore {
|
|
5
|
+
putTemp(bytes: Uint8Array | stream.Readable): Promise<string>;
|
|
6
|
+
makePermanent(key: string, cid: CID): Promise<void>;
|
|
7
|
+
putPermanent(cid: CID, bytes: Uint8Array | stream.Readable): Promise<void>;
|
|
8
|
+
getBytes(cid: CID): Promise<Uint8Array>;
|
|
9
|
+
getStream(cid: CID): Promise<stream.Readable>;
|
|
10
|
+
}
|
|
11
|
+
export declare class BlobNotFoundError extends Error {
|
|
12
|
+
}
|