@atproto/repo 0.3.6 → 0.3.8
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/CHANGELOG.md +14 -0
- package/LICENSE.txt +1 -1
- package/dist/block-map.d.ts +1 -1
- package/dist/data-diff.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +455 -91
- package/dist/index.js.map +3 -3
- package/dist/mst/mst.d.ts +3 -3
- package/dist/mst/walker.d.ts +3 -3
- package/dist/readable-repo.d.ts +8 -1
- package/dist/repo.d.ts +12 -1
- package/dist/storage/memory-blockstore.d.ts +2 -1
- package/dist/storage/types.d.ts +3 -1
- package/dist/sync/consumer.d.ts +9 -3
- package/dist/sync/provider.d.ts +2 -2
- package/dist/types.d.ts +50 -39
- package/dist/util.d.ts +11 -3
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/readable-repo.ts +14 -0
- package/src/repo.ts +29 -0
- package/src/storage/memory-blockstore.ts +3 -1
- package/src/storage/types.ts +3 -1
- package/src/sync/consumer.ts +8 -4
- package/src/sync/provider.ts +2 -2
- package/src/types.ts +17 -5
- package/src/util.ts +20 -12
- package/tests/sync.test.ts +3 -1
package/dist/mst/mst.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ declare const nodeData: z.ZodObject<{
|
|
|
39
39
|
}[];
|
|
40
40
|
l?: any;
|
|
41
41
|
}>;
|
|
42
|
-
export
|
|
42
|
+
export type NodeData = z.infer<typeof nodeData>;
|
|
43
43
|
export declare const nodeDataDef: {
|
|
44
44
|
name: string;
|
|
45
45
|
schema: z.ZodObject<{
|
|
@@ -78,8 +78,8 @@ export declare const nodeDataDef: {
|
|
|
78
78
|
l?: any;
|
|
79
79
|
}>;
|
|
80
80
|
};
|
|
81
|
-
export
|
|
82
|
-
export
|
|
81
|
+
export type NodeEntry = MST | Leaf;
|
|
82
|
+
export type MstOpts = {
|
|
83
83
|
layer: number;
|
|
84
84
|
};
|
|
85
85
|
export declare class MST {
|
package/dist/mst/walker.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { MST, NodeEntry } from './mst';
|
|
2
|
-
|
|
2
|
+
type WalkerStatusDone = {
|
|
3
3
|
done: true;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type WalkerStatusProgress = {
|
|
6
6
|
done: false;
|
|
7
7
|
curr: NodeEntry;
|
|
8
8
|
walking: MST | null;
|
|
9
9
|
index: number;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type WalkerStatus = WalkerStatusDone | WalkerStatusProgress;
|
|
12
12
|
export declare class MstWalker {
|
|
13
13
|
root: MST;
|
|
14
14
|
stack: WalkerStatus[];
|
package/dist/readable-repo.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { CID } from 'multiformats/cid';
|
|
|
2
2
|
import { RepoContents, Commit } from './types';
|
|
3
3
|
import { ReadableBlockstore } from './storage';
|
|
4
4
|
import { MST } from './mst';
|
|
5
|
-
|
|
5
|
+
import { RepoRecord } from '@atproto/lexicon';
|
|
6
|
+
type Params = {
|
|
6
7
|
storage: ReadableBlockstore;
|
|
7
8
|
data: MST;
|
|
8
9
|
commit: Commit;
|
|
@@ -17,6 +18,12 @@ export declare class ReadableRepo {
|
|
|
17
18
|
static load(storage: ReadableBlockstore, commitCid: CID): Promise<ReadableRepo>;
|
|
18
19
|
get did(): string;
|
|
19
20
|
get version(): number;
|
|
21
|
+
walkRecords(from?: string): AsyncIterable<{
|
|
22
|
+
collection: string;
|
|
23
|
+
rkey: string;
|
|
24
|
+
cid: CID;
|
|
25
|
+
record: RepoRecord;
|
|
26
|
+
}>;
|
|
20
27
|
getRecord(collection: string, rkey: string): Promise<unknown | null>;
|
|
21
28
|
getContents(): Promise<RepoContents>;
|
|
22
29
|
}
|
package/dist/repo.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import * as crypto from '@atproto/crypto';
|
|
|
3
3
|
import { Commit, CommitData, RecordCreateOp, RecordWriteOp } from './types';
|
|
4
4
|
import { RepoStorage } from './storage';
|
|
5
5
|
import { MST } from './mst';
|
|
6
|
+
import BlockMap from './block-map';
|
|
6
7
|
import { ReadableRepo } from './readable-repo';
|
|
7
|
-
|
|
8
|
+
import CidSet from './cid-set';
|
|
9
|
+
type Params = {
|
|
8
10
|
storage: RepoStorage;
|
|
9
11
|
data: MST;
|
|
10
12
|
commit: Commit;
|
|
@@ -20,5 +22,14 @@ export declare class Repo extends ReadableRepo {
|
|
|
20
22
|
formatCommit(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<CommitData>;
|
|
21
23
|
applyCommit(commitData: CommitData): Promise<Repo>;
|
|
22
24
|
applyWrites(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<Repo>;
|
|
25
|
+
formatResignCommit(rev: string, keypair: crypto.Keypair): Promise<{
|
|
26
|
+
cid: CID;
|
|
27
|
+
rev: string;
|
|
28
|
+
since: null;
|
|
29
|
+
prev: null;
|
|
30
|
+
newBlocks: BlockMap;
|
|
31
|
+
removedCids: CidSet;
|
|
32
|
+
}>;
|
|
33
|
+
resignCommit(rev: string, keypair: crypto.Keypair): Promise<Repo>;
|
|
23
34
|
}
|
|
24
35
|
export default Repo;
|
|
@@ -6,6 +6,7 @@ import { RepoStorage } from './types';
|
|
|
6
6
|
export declare class MemoryBlockstore extends ReadableBlockstore implements RepoStorage {
|
|
7
7
|
blocks: BlockMap;
|
|
8
8
|
root: CID | null;
|
|
9
|
+
rev: string | null;
|
|
9
10
|
constructor(blocks?: BlockMap);
|
|
10
11
|
getRoot(): Promise<CID | null>;
|
|
11
12
|
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
@@ -16,7 +17,7 @@ export declare class MemoryBlockstore extends ReadableBlockstore implements Repo
|
|
|
16
17
|
}>;
|
|
17
18
|
putBlock(cid: CID, block: Uint8Array): Promise<void>;
|
|
18
19
|
putMany(blocks: BlockMap): Promise<void>;
|
|
19
|
-
updateRoot(cid: CID): Promise<void>;
|
|
20
|
+
updateRoot(cid: CID, rev: string): Promise<void>;
|
|
20
21
|
applyCommit(commit: CommitData): Promise<void>;
|
|
21
22
|
sizeInBytes(): Promise<number>;
|
|
22
23
|
destroy(): Promise<void>;
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface RepoStorage {
|
|
|
9
9
|
getRoot(): Promise<CID | null>;
|
|
10
10
|
putBlock(cid: CID, block: Uint8Array, rev: string): Promise<void>;
|
|
11
11
|
putMany(blocks: BlockMap, rev: string): Promise<void>;
|
|
12
|
-
updateRoot(cid: CID): Promise<void>;
|
|
12
|
+
updateRoot(cid: CID, rev: string): Promise<void>;
|
|
13
13
|
applyCommit(commit: CommitData): any;
|
|
14
14
|
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
15
15
|
has(cid: CID): Promise<boolean>;
|
|
@@ -37,8 +37,10 @@ export interface BlobStore {
|
|
|
37
37
|
unquarantine(cid: CID): Promise<void>;
|
|
38
38
|
getBytes(cid: CID): Promise<Uint8Array>;
|
|
39
39
|
getStream(cid: CID): Promise<stream.Readable>;
|
|
40
|
+
hasTemp(key: string): Promise<boolean>;
|
|
40
41
|
hasStored(cid: CID): Promise<boolean>;
|
|
41
42
|
delete(cid: CID): Promise<void>;
|
|
43
|
+
deleteMany(cid: CID[]): Promise<void>;
|
|
42
44
|
}
|
|
43
45
|
export declare class BlobNotFoundError extends Error {
|
|
44
46
|
}
|
package/dist/sync/consumer.d.ts
CHANGED
|
@@ -3,9 +3,15 @@ import ReadableRepo from '../readable-repo';
|
|
|
3
3
|
import { RecordClaim, VerifiedDiff, VerifiedRepo } from '../types';
|
|
4
4
|
import BlockMap from '../block-map';
|
|
5
5
|
export declare const verifyRepoCar: (carBytes: Uint8Array, did?: string, signingKey?: string) => Promise<VerifiedRepo>;
|
|
6
|
-
export declare const verifyRepo: (blocks: BlockMap, head: CID, did?: string, signingKey?: string
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export declare const verifyRepo: (blocks: BlockMap, head: CID, did?: string, signingKey?: string, opts?: {
|
|
7
|
+
ensureLeaves?: boolean;
|
|
8
|
+
}) => Promise<VerifiedRepo>;
|
|
9
|
+
export declare const verifyDiffCar: (repo: ReadableRepo | null, carBytes: Uint8Array, did?: string, signingKey?: string, opts?: {
|
|
10
|
+
ensureLeaves?: boolean;
|
|
11
|
+
}) => Promise<VerifiedDiff>;
|
|
12
|
+
export declare const verifyDiff: (repo: ReadableRepo | null, updateBlocks: BlockMap, updateRoot: CID, did?: string, signingKey?: string, opts?: {
|
|
13
|
+
ensureLeaves?: boolean;
|
|
14
|
+
}) => Promise<VerifiedDiff>;
|
|
9
15
|
export declare const verifyProofs: (proofs: Uint8Array, claims: RecordClaim[], did: string, didKey: string) => Promise<{
|
|
10
16
|
verified: RecordClaim[];
|
|
11
17
|
unverified: RecordClaim[];
|
package/dist/sync/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RecordPath } from '../types';
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
|
-
import { RepoStorage } from '../storage';
|
|
3
|
+
import { ReadableBlockstore, RepoStorage } from '../storage';
|
|
4
4
|
export declare const getFullRepo: (storage: RepoStorage, commitCid: CID) => AsyncIterable<Uint8Array>;
|
|
5
|
-
export declare const getRecords: (storage:
|
|
5
|
+
export declare const getRecords: (storage: ReadableBlockstore, commitCid: CID, paths: RecordPath[]) => AsyncIterable<Uint8Array>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { CID } from 'multiformats';
|
|
3
|
+
import * as car from '@ipld/car/api';
|
|
3
4
|
import BlockMap from './block-map';
|
|
4
5
|
import { RepoRecord } from '@atproto/lexicon';
|
|
5
6
|
import CidSet from './cid-set';
|
|
@@ -8,13 +9,13 @@ declare const unsignedCommit: z.ZodObject<{
|
|
|
8
9
|
version: z.ZodLiteral<3>;
|
|
9
10
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
10
11
|
rev: z.ZodString;
|
|
11
|
-
prev: z.
|
|
12
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
12
13
|
}, "strip", z.ZodTypeAny, {
|
|
13
14
|
did: string;
|
|
14
15
|
data: CID;
|
|
15
16
|
version: 3;
|
|
16
17
|
rev: string;
|
|
17
|
-
prev
|
|
18
|
+
prev: CID | null;
|
|
18
19
|
}, {
|
|
19
20
|
did: string;
|
|
20
21
|
version: 3;
|
|
@@ -22,7 +23,7 @@ declare const unsignedCommit: z.ZodObject<{
|
|
|
22
23
|
data?: any;
|
|
23
24
|
prev?: any;
|
|
24
25
|
}>;
|
|
25
|
-
export
|
|
26
|
+
export type UnsignedCommit = z.infer<typeof unsignedCommit> & {
|
|
26
27
|
sig?: never;
|
|
27
28
|
};
|
|
28
29
|
declare const commit: z.ZodObject<{
|
|
@@ -30,15 +31,15 @@ declare const commit: z.ZodObject<{
|
|
|
30
31
|
version: z.ZodLiteral<3>;
|
|
31
32
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
32
33
|
rev: z.ZodString;
|
|
33
|
-
prev: z.
|
|
34
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
34
35
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
35
36
|
}, "strip", z.ZodTypeAny, {
|
|
36
37
|
did: string;
|
|
37
38
|
data: CID;
|
|
38
39
|
version: 3;
|
|
39
40
|
rev: string;
|
|
41
|
+
prev: CID | null;
|
|
40
42
|
sig: Uint8Array;
|
|
41
|
-
prev?: CID | null | undefined;
|
|
42
43
|
}, {
|
|
43
44
|
did: string;
|
|
44
45
|
version: 3;
|
|
@@ -47,7 +48,7 @@ declare const commit: z.ZodObject<{
|
|
|
47
48
|
data?: any;
|
|
48
49
|
prev?: any;
|
|
49
50
|
}>;
|
|
50
|
-
export
|
|
51
|
+
export type Commit = z.infer<typeof commit>;
|
|
51
52
|
declare const legacyV2Commit: z.ZodObject<{
|
|
52
53
|
did: z.ZodString;
|
|
53
54
|
version: z.ZodLiteral<2>;
|
|
@@ -70,21 +71,21 @@ declare const legacyV2Commit: z.ZodObject<{
|
|
|
70
71
|
rev?: string | undefined;
|
|
71
72
|
prev?: any;
|
|
72
73
|
}>;
|
|
73
|
-
export
|
|
74
|
+
export type LegacyV2Commit = z.infer<typeof legacyV2Commit>;
|
|
74
75
|
declare const versionedCommit: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
|
|
75
76
|
did: z.ZodString;
|
|
76
77
|
version: z.ZodLiteral<3>;
|
|
77
78
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
78
79
|
rev: z.ZodString;
|
|
79
|
-
prev: z.
|
|
80
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
80
81
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
81
82
|
}, "strip", z.ZodTypeAny, {
|
|
82
83
|
did: string;
|
|
83
84
|
data: CID;
|
|
84
85
|
version: 3;
|
|
85
86
|
rev: string;
|
|
87
|
+
prev: CID | null;
|
|
86
88
|
sig: Uint8Array;
|
|
87
|
-
prev?: CID | null | undefined;
|
|
88
89
|
}, {
|
|
89
90
|
did: string;
|
|
90
91
|
version: 3;
|
|
@@ -114,22 +115,22 @@ declare const versionedCommit: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
|
|
|
114
115
|
rev?: string | undefined;
|
|
115
116
|
prev?: any;
|
|
116
117
|
}>]>;
|
|
117
|
-
export
|
|
118
|
+
export type VersionedCommit = z.infer<typeof versionedCommit>;
|
|
118
119
|
export declare const schema: {
|
|
119
120
|
commit: z.ZodObject<{
|
|
120
121
|
did: z.ZodString;
|
|
121
122
|
version: z.ZodLiteral<3>;
|
|
122
123
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
123
124
|
rev: z.ZodString;
|
|
124
|
-
prev: z.
|
|
125
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
125
126
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
126
127
|
}, "strip", z.ZodTypeAny, {
|
|
127
128
|
did: string;
|
|
128
129
|
data: CID;
|
|
129
130
|
version: 3;
|
|
130
131
|
rev: string;
|
|
132
|
+
prev: CID | null;
|
|
131
133
|
sig: Uint8Array;
|
|
132
|
-
prev?: CID | null | undefined;
|
|
133
134
|
}, {
|
|
134
135
|
did: string;
|
|
135
136
|
version: 3;
|
|
@@ -165,15 +166,15 @@ export declare const schema: {
|
|
|
165
166
|
version: z.ZodLiteral<3>;
|
|
166
167
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
167
168
|
rev: z.ZodString;
|
|
168
|
-
prev: z.
|
|
169
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
169
170
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
170
171
|
}, "strip", z.ZodTypeAny, {
|
|
171
172
|
did: string;
|
|
172
173
|
data: CID;
|
|
173
174
|
version: 3;
|
|
174
175
|
rev: string;
|
|
176
|
+
prev: CID | null;
|
|
175
177
|
sig: Uint8Array;
|
|
176
|
-
prev?: CID | null | undefined;
|
|
177
178
|
}, {
|
|
178
179
|
did: string;
|
|
179
180
|
version: 3;
|
|
@@ -218,15 +219,15 @@ export declare const def: {
|
|
|
218
219
|
version: z.ZodLiteral<3>;
|
|
219
220
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
220
221
|
rev: z.ZodString;
|
|
221
|
-
prev: z.
|
|
222
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
222
223
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
223
224
|
}, "strip", z.ZodTypeAny, {
|
|
224
225
|
did: string;
|
|
225
226
|
data: CID;
|
|
226
227
|
version: 3;
|
|
227
228
|
rev: string;
|
|
229
|
+
prev: CID | null;
|
|
228
230
|
sig: Uint8Array;
|
|
229
|
-
prev?: CID | null | undefined;
|
|
230
231
|
}, {
|
|
231
232
|
did: string;
|
|
232
233
|
version: 3;
|
|
@@ -243,15 +244,15 @@ export declare const def: {
|
|
|
243
244
|
version: z.ZodLiteral<3>;
|
|
244
245
|
data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
245
246
|
rev: z.ZodString;
|
|
246
|
-
prev: z.
|
|
247
|
+
prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
247
248
|
sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
248
249
|
}, "strip", z.ZodTypeAny, {
|
|
249
250
|
did: string;
|
|
250
251
|
data: CID;
|
|
251
252
|
version: 3;
|
|
252
253
|
rev: string;
|
|
254
|
+
prev: CID | null;
|
|
253
255
|
sig: Uint8Array;
|
|
254
|
-
prev?: CID | null | undefined;
|
|
255
256
|
}, {
|
|
256
257
|
did: string;
|
|
257
258
|
version: 3;
|
|
@@ -293,37 +294,46 @@ export declare enum WriteOpAction {
|
|
|
293
294
|
Update = "update",
|
|
294
295
|
Delete = "delete"
|
|
295
296
|
}
|
|
296
|
-
export
|
|
297
|
+
export type RecordCreateOp = {
|
|
297
298
|
action: WriteOpAction.Create;
|
|
298
299
|
collection: string;
|
|
299
300
|
rkey: string;
|
|
300
301
|
record: RepoRecord;
|
|
301
302
|
};
|
|
302
|
-
export
|
|
303
|
+
export type RecordUpdateOp = {
|
|
303
304
|
action: WriteOpAction.Update;
|
|
304
305
|
collection: string;
|
|
305
306
|
rkey: string;
|
|
306
307
|
record: RepoRecord;
|
|
307
308
|
};
|
|
308
|
-
export
|
|
309
|
+
export type RecordDeleteOp = {
|
|
309
310
|
action: WriteOpAction.Delete;
|
|
310
311
|
collection: string;
|
|
311
312
|
rkey: string;
|
|
312
313
|
};
|
|
313
|
-
export
|
|
314
|
-
export
|
|
314
|
+
export type RecordWriteOp = RecordCreateOp | RecordUpdateOp | RecordDeleteOp;
|
|
315
|
+
export type RecordCreateDescript = {
|
|
316
|
+
action: WriteOpAction.Create;
|
|
317
|
+
collection: string;
|
|
318
|
+
rkey: string;
|
|
315
319
|
cid: CID;
|
|
316
320
|
};
|
|
317
|
-
export
|
|
321
|
+
export type RecordUpdateDescript = {
|
|
322
|
+
action: WriteOpAction.Update;
|
|
323
|
+
collection: string;
|
|
324
|
+
rkey: string;
|
|
318
325
|
prev: CID;
|
|
319
326
|
cid: CID;
|
|
320
327
|
};
|
|
321
|
-
export
|
|
328
|
+
export type RecordDeleteDescript = {
|
|
329
|
+
action: WriteOpAction.Delete;
|
|
330
|
+
collection: string;
|
|
331
|
+
rkey: string;
|
|
322
332
|
cid: CID;
|
|
323
333
|
};
|
|
324
|
-
export
|
|
325
|
-
export
|
|
326
|
-
export
|
|
334
|
+
export type RecordWriteDescript = RecordCreateDescript | RecordUpdateDescript | RecordDeleteDescript;
|
|
335
|
+
export type WriteLog = RecordWriteDescript[][];
|
|
336
|
+
export type CommitData = {
|
|
327
337
|
cid: CID;
|
|
328
338
|
rev: string;
|
|
329
339
|
since: string | null;
|
|
@@ -331,33 +341,34 @@ export declare type CommitData = {
|
|
|
331
341
|
newBlocks: BlockMap;
|
|
332
342
|
removedCids: CidSet;
|
|
333
343
|
};
|
|
334
|
-
export
|
|
344
|
+
export type RepoUpdate = CommitData & {
|
|
335
345
|
ops: RecordWriteOp[];
|
|
336
346
|
};
|
|
337
|
-
export
|
|
338
|
-
export
|
|
339
|
-
export
|
|
347
|
+
export type CollectionContents = Record<string, RepoRecord>;
|
|
348
|
+
export type RepoContents = Record<string, CollectionContents>;
|
|
349
|
+
export type RepoRecordWithCid = {
|
|
340
350
|
cid: CID;
|
|
341
351
|
value: RepoRecord;
|
|
342
352
|
};
|
|
343
|
-
export
|
|
344
|
-
export
|
|
345
|
-
export
|
|
346
|
-
export
|
|
353
|
+
export type CollectionContentsWithCids = Record<string, RepoRecordWithCid>;
|
|
354
|
+
export type RepoContentsWithCids = Record<string, CollectionContentsWithCids>;
|
|
355
|
+
export type DatastoreContents = Record<string, CID>;
|
|
356
|
+
export type RecordPath = {
|
|
347
357
|
collection: string;
|
|
348
358
|
rkey: string;
|
|
349
359
|
};
|
|
350
|
-
export
|
|
360
|
+
export type RecordClaim = {
|
|
351
361
|
collection: string;
|
|
352
362
|
rkey: string;
|
|
353
363
|
record: RepoRecord | null;
|
|
354
364
|
};
|
|
355
|
-
export
|
|
365
|
+
export type VerifiedDiff = {
|
|
356
366
|
writes: RecordWriteDescript[];
|
|
357
367
|
commit: CommitData;
|
|
358
368
|
};
|
|
359
|
-
export
|
|
369
|
+
export type VerifiedRepo = {
|
|
360
370
|
creates: RecordCreateDescript[];
|
|
361
371
|
commit: CommitData;
|
|
362
372
|
};
|
|
373
|
+
export type CarBlock = car.Block;
|
|
363
374
|
export {};
|
package/dist/util.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
|
+
import { CarBlockIterator } from '@ipld/car';
|
|
3
4
|
import { BlockWriter } from '@ipld/car/writer';
|
|
4
|
-
import { Block as CarBlock } from '@ipld/car/api';
|
|
5
5
|
import { LexValue, RepoRecord } from '@atproto/lexicon';
|
|
6
6
|
import DataDiff from './data-diff';
|
|
7
|
-
import { Commit, LegacyV2Commit, RecordCreateDescript, RecordPath, RecordWriteDescript, UnsignedCommit } from './types';
|
|
7
|
+
import { CarBlock, Commit, LegacyV2Commit, RecordCreateDescript, RecordPath, RecordWriteDescript, UnsignedCommit } from './types';
|
|
8
8
|
import BlockMap from './block-map';
|
|
9
9
|
import { Keypair } from '@atproto/crypto';
|
|
10
10
|
import { Readable } from 'stream';
|
|
@@ -13,15 +13,23 @@ export declare function writeCarStream(root: CID | null, fn: (car: BlockWriter)
|
|
|
13
13
|
export declare function writeCar(root: CID | null, fn: (car: BlockWriter) => Promise<void>): AsyncIterable<Uint8Array>;
|
|
14
14
|
export declare const blocksToCarStream: (root: CID | null, blocks: BlockMap) => AsyncIterable<Uint8Array>;
|
|
15
15
|
export declare const blocksToCarFile: (root: CID | null, blocks: BlockMap) => Promise<Uint8Array>;
|
|
16
|
+
export declare const carToBlocks: (car: CarBlockIterator) => Promise<{
|
|
17
|
+
roots: CID[];
|
|
18
|
+
blocks: BlockMap;
|
|
19
|
+
}>;
|
|
16
20
|
export declare const readCar: (bytes: Uint8Array) => Promise<{
|
|
17
21
|
roots: CID[];
|
|
18
22
|
blocks: BlockMap;
|
|
19
23
|
}>;
|
|
24
|
+
export declare const readCarStream: (stream: AsyncIterable<Uint8Array>) => Promise<{
|
|
25
|
+
roots: CID[];
|
|
26
|
+
blocks: BlockMap;
|
|
27
|
+
}>;
|
|
20
28
|
export declare const readCarWithRoot: (bytes: Uint8Array) => Promise<{
|
|
21
29
|
root: CID;
|
|
22
30
|
blocks: BlockMap;
|
|
23
31
|
}>;
|
|
24
|
-
export declare const diffToWriteDescripts: (diff: DataDiff
|
|
32
|
+
export declare const diffToWriteDescripts: (diff: DataDiff) => Promise<RecordWriteDescript[]>;
|
|
25
33
|
export declare const ensureCreates: (descripts: RecordWriteDescript[]) => RecordCreateDescript[];
|
|
26
34
|
export declare const parseDataKey: (key: string) => RecordPath;
|
|
27
35
|
export declare const formatDataKey: (collection: string, rkey: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/repo",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "atproto repo and MST implementation",
|
|
6
6
|
"keywords": [
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@atproto/common-web": "^0.2.3",
|
|
25
25
|
"@atproto/crypto": "^0.3.0",
|
|
26
26
|
"@atproto/identity": "^0.3.2",
|
|
27
|
-
"@atproto/lexicon": "^0.3.
|
|
28
|
-
"@atproto/syntax": "^0.
|
|
27
|
+
"@atproto/lexicon": "^0.3.2",
|
|
28
|
+
"@atproto/syntax": "^0.2.0"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "jest",
|
package/src/index.ts
CHANGED
package/src/readable-repo.ts
CHANGED
|
@@ -6,6 +6,7 @@ import log from './logger'
|
|
|
6
6
|
import * as util from './util'
|
|
7
7
|
import * as parse from './parse'
|
|
8
8
|
import { MissingBlocksError } from './error'
|
|
9
|
+
import { RepoRecord } from '@atproto/lexicon'
|
|
9
10
|
|
|
10
11
|
type Params = {
|
|
11
12
|
storage: ReadableBlockstore
|
|
@@ -47,6 +48,19 @@ export class ReadableRepo {
|
|
|
47
48
|
return this.commit.version
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
async *walkRecords(from?: string): AsyncIterable<{
|
|
52
|
+
collection: string
|
|
53
|
+
rkey: string
|
|
54
|
+
cid: CID
|
|
55
|
+
record: RepoRecord
|
|
56
|
+
}> {
|
|
57
|
+
for await (const leaf of this.data.walkLeavesFrom(from ?? '')) {
|
|
58
|
+
const { collection, rkey } = util.parseDataKey(leaf.key)
|
|
59
|
+
const record = await this.storage.readRecord(leaf.value)
|
|
60
|
+
yield { collection, rkey, cid: leaf.value, record }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
async getRecord(collection: string, rkey: string): Promise<unknown | null> {
|
|
51
65
|
const dataKey = collection + '/' + rkey
|
|
52
66
|
const cid = await this.data.get(dataKey)
|
package/src/repo.ts
CHANGED
|
@@ -16,6 +16,7 @@ import log from './logger'
|
|
|
16
16
|
import BlockMap from './block-map'
|
|
17
17
|
import { ReadableRepo } from './readable-repo'
|
|
18
18
|
import * as util from './util'
|
|
19
|
+
import CidSet from './cid-set'
|
|
19
20
|
|
|
20
21
|
type Params = {
|
|
21
22
|
storage: RepoStorage
|
|
@@ -187,6 +188,34 @@ export class Repo extends ReadableRepo {
|
|
|
187
188
|
const commit = await this.formatCommit(toWrite, keypair)
|
|
188
189
|
return this.applyCommit(commit)
|
|
189
190
|
}
|
|
191
|
+
|
|
192
|
+
async formatResignCommit(rev: string, keypair: crypto.Keypair) {
|
|
193
|
+
const commit = await util.signCommit(
|
|
194
|
+
{
|
|
195
|
+
did: this.did,
|
|
196
|
+
version: 3,
|
|
197
|
+
rev,
|
|
198
|
+
prev: null, // added for backwards compatibility with v2
|
|
199
|
+
data: this.commit.data,
|
|
200
|
+
},
|
|
201
|
+
keypair,
|
|
202
|
+
)
|
|
203
|
+
const newBlocks = new BlockMap()
|
|
204
|
+
const commitCid = await newBlocks.add(commit)
|
|
205
|
+
return {
|
|
206
|
+
cid: commitCid,
|
|
207
|
+
rev,
|
|
208
|
+
since: null,
|
|
209
|
+
prev: null,
|
|
210
|
+
newBlocks,
|
|
211
|
+
removedCids: new CidSet([this.cid]),
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async resignCommit(rev: string, keypair: crypto.Keypair) {
|
|
216
|
+
const formatted = await this.formatResignCommit(rev, keypair)
|
|
217
|
+
return this.applyCommit(formatted)
|
|
218
|
+
}
|
|
190
219
|
}
|
|
191
220
|
|
|
192
221
|
export default Repo
|
|
@@ -10,6 +10,7 @@ export class MemoryBlockstore
|
|
|
10
10
|
{
|
|
11
11
|
blocks: BlockMap
|
|
12
12
|
root: CID | null = null
|
|
13
|
+
rev: string | null = null
|
|
13
14
|
|
|
14
15
|
constructor(blocks?: BlockMap) {
|
|
15
16
|
super()
|
|
@@ -43,8 +44,9 @@ export class MemoryBlockstore
|
|
|
43
44
|
this.blocks.addMap(blocks)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
async updateRoot(cid: CID): Promise<void> {
|
|
47
|
+
async updateRoot(cid: CID, rev: string): Promise<void> {
|
|
47
48
|
this.root = cid
|
|
49
|
+
this.rev = rev
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
async applyCommit(commit: CommitData): Promise<void> {
|
package/src/storage/types.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface RepoStorage {
|
|
|
10
10
|
getRoot(): Promise<CID | null>
|
|
11
11
|
putBlock(cid: CID, block: Uint8Array, rev: string): Promise<void>
|
|
12
12
|
putMany(blocks: BlockMap, rev: string): Promise<void>
|
|
13
|
-
updateRoot(cid: CID): Promise<void>
|
|
13
|
+
updateRoot(cid: CID, rev: string): Promise<void>
|
|
14
14
|
applyCommit(commit: CommitData)
|
|
15
15
|
|
|
16
16
|
// Readable
|
|
@@ -38,8 +38,10 @@ export interface BlobStore {
|
|
|
38
38
|
unquarantine(cid: CID): Promise<void>
|
|
39
39
|
getBytes(cid: CID): Promise<Uint8Array>
|
|
40
40
|
getStream(cid: CID): Promise<stream.Readable>
|
|
41
|
+
hasTemp(key: string): Promise<boolean>
|
|
41
42
|
hasStored(cid: CID): Promise<boolean>
|
|
42
43
|
delete(cid: CID): Promise<void>
|
|
44
|
+
deleteMany(cid: CID[]): Promise<void>
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export class BlobNotFoundError extends Error {}
|
package/src/sync/consumer.ts
CHANGED
|
@@ -23,8 +23,9 @@ export const verifyRepo = async (
|
|
|
23
23
|
head: CID,
|
|
24
24
|
did?: string,
|
|
25
25
|
signingKey?: string,
|
|
26
|
+
opts?: { ensureLeaves?: boolean },
|
|
26
27
|
): Promise<VerifiedRepo> => {
|
|
27
|
-
const diff = await verifyDiff(null, blocks, head, did, signingKey)
|
|
28
|
+
const diff = await verifyDiff(null, blocks, head, did, signingKey, opts)
|
|
28
29
|
const creates = util.ensureCreates(diff.writes)
|
|
29
30
|
return {
|
|
30
31
|
creates,
|
|
@@ -37,9 +38,10 @@ export const verifyDiffCar = async (
|
|
|
37
38
|
carBytes: Uint8Array,
|
|
38
39
|
did?: string,
|
|
39
40
|
signingKey?: string,
|
|
41
|
+
opts?: { ensureLeaves?: boolean },
|
|
40
42
|
): Promise<VerifiedDiff> => {
|
|
41
43
|
const car = await util.readCarWithRoot(carBytes)
|
|
42
|
-
return verifyDiff(repo, car.blocks, car.root, did, signingKey)
|
|
44
|
+
return verifyDiff(repo, car.blocks, car.root, did, signingKey, opts)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export const verifyDiff = async (
|
|
@@ -48,7 +50,9 @@ export const verifyDiff = async (
|
|
|
48
50
|
updateRoot: CID,
|
|
49
51
|
did?: string,
|
|
50
52
|
signingKey?: string,
|
|
53
|
+
opts?: { ensureLeaves?: boolean },
|
|
51
54
|
): Promise<VerifiedDiff> => {
|
|
55
|
+
const { ensureLeaves = true } = opts ?? {}
|
|
52
56
|
const stagedStorage = new MemoryBlockstore(updateBlocks)
|
|
53
57
|
const updateStorage = repo
|
|
54
58
|
? new SyncStorage(stagedStorage, repo.storage)
|
|
@@ -60,10 +64,10 @@ export const verifyDiff = async (
|
|
|
60
64
|
signingKey,
|
|
61
65
|
)
|
|
62
66
|
const diff = await DataDiff.of(updated.data, repo?.data ?? null)
|
|
63
|
-
const writes = await util.diffToWriteDescripts(diff
|
|
67
|
+
const writes = await util.diffToWriteDescripts(diff)
|
|
64
68
|
const newBlocks = diff.newMstBlocks
|
|
65
69
|
const leaves = updateBlocks.getMany(diff.newLeafCids.toList())
|
|
66
|
-
if (leaves.missing.length > 0) {
|
|
70
|
+
if (leaves.missing.length > 0 && ensureLeaves) {
|
|
67
71
|
throw new Error(`missing leaf blocks: ${leaves.missing}`)
|
|
68
72
|
}
|
|
69
73
|
newBlocks.addMap(leaves.blocks)
|
package/src/sync/provider.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BlockWriter } from '@ipld/car/writer'
|
|
|
3
3
|
import { CID } from 'multiformats/cid'
|
|
4
4
|
import CidSet from '../cid-set'
|
|
5
5
|
import { MissingBlocksError } from '../error'
|
|
6
|
-
import { RepoStorage } from '../storage'
|
|
6
|
+
import { ReadableBlockstore, RepoStorage } from '../storage'
|
|
7
7
|
import * as util from '../util'
|
|
8
8
|
import { MST } from '../mst'
|
|
9
9
|
|
|
@@ -26,7 +26,7 @@ export const getFullRepo = (
|
|
|
26
26
|
// -------------
|
|
27
27
|
|
|
28
28
|
export const getRecords = (
|
|
29
|
-
storage:
|
|
29
|
+
storage: ReadableBlockstore,
|
|
30
30
|
commitCid: CID,
|
|
31
31
|
paths: RecordPath[],
|
|
32
32
|
): AsyncIterable<Uint8Array> => {
|