@atproto/repo 0.1.0 → 0.3.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.
Files changed (49) hide show
  1. package/dist/block-map.d.ts +2 -0
  2. package/dist/data-diff.d.ts +12 -10
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +12388 -4431
  5. package/dist/index.js.map +4 -4
  6. package/dist/mst/mst.d.ts +19 -16
  7. package/dist/readable-repo.d.ts +4 -3
  8. package/dist/repo.d.ts +3 -2
  9. package/dist/storage/index.d.ts +0 -1
  10. package/dist/storage/memory-blockstore.d.ts +6 -10
  11. package/dist/storage/types.d.ts +29 -0
  12. package/dist/sync/consumer.d.ts +13 -16
  13. package/dist/sync/provider.d.ts +2 -6
  14. package/dist/types.d.ts +236 -48
  15. package/dist/util.d.ts +9 -7
  16. package/jest.bench.config.js +2 -1
  17. package/package.json +12 -7
  18. package/src/block-map.ts +8 -0
  19. package/src/data-diff.ts +47 -49
  20. package/src/index.ts +1 -1
  21. package/src/mst/diff.ts +14 -36
  22. package/src/mst/mst.ts +15 -14
  23. package/src/readable-repo.ts +5 -5
  24. package/src/repo.ts +50 -40
  25. package/src/storage/index.ts +0 -1
  26. package/src/storage/memory-blockstore.ts +19 -59
  27. package/src/storage/types.ts +30 -0
  28. package/src/sync/consumer.ts +170 -113
  29. package/src/sync/provider.ts +6 -44
  30. package/src/types.ts +49 -25
  31. package/src/util.ts +57 -91
  32. package/tests/_util.ts +38 -67
  33. package/tests/mst.test.ts +4 -1
  34. package/tests/{sync/narrow.test.ts → proofs.test.ts} +14 -21
  35. package/tests/repo.test.ts +5 -4
  36. package/tests/sync.test.ts +97 -0
  37. package/tests/util.test.ts +21 -0
  38. package/tsconfig.build.tsbuildinfo +1 -1
  39. package/tsconfig.json +1 -1
  40. package/dist/blockstore/index.d.ts +0 -2
  41. package/dist/blockstore/ipld-store.d.ts +0 -27
  42. package/dist/blockstore/memory-blockstore.d.ts +0 -13
  43. package/dist/storage/repo-storage.d.ts +0 -18
  44. package/dist/sync.d.ts +0 -9
  45. package/dist/verify.d.ts +0 -27
  46. package/src/storage/repo-storage.ts +0 -42
  47. package/src/verify.ts +0 -227
  48. package/tests/sync/checkout.test.ts +0 -57
  49. package/tests/sync/diff.test.ts +0 -87
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';
@@ -13,32 +12,32 @@ declare const nodeData: z.ZodObject<{
13
12
  v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
14
13
  t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
15
14
  }, "strip", z.ZodTypeAny, {
15
+ t: CID | null;
16
16
  p: number;
17
17
  k: Uint8Array;
18
18
  v: CID;
19
- 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
26
  l: CID | null;
28
27
  e: {
28
+ t: CID | null;
29
29
  p: number;
30
30
  k: Uint8Array;
31
31
  v: CID;
32
- t: CID | null;
33
32
  }[];
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: {
@@ -51,39 +50,39 @@ export declare const nodeDataDef: {
51
50
  v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
52
51
  t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
53
52
  }, "strip", z.ZodTypeAny, {
53
+ t: CID | null;
54
54
  p: number;
55
55
  k: Uint8Array;
56
56
  v: CID;
57
- 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
64
  l: CID | null;
66
65
  e: {
66
+ t: CID | null;
67
67
  p: number;
68
68
  k: Uint8Array;
69
69
  v: CID;
70
- t: CID | null;
71
70
  }[];
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 implements DataStore {
85
+ export declare class MST {
87
86
  storage: ReadableBlockstore;
88
87
  entries: NodeEntry[] | null;
89
88
  layer: number | null;
@@ -96,6 +95,10 @@ export declare class MST implements DataStore {
96
95
  newTree(entries: NodeEntry[]): Promise<MST>;
97
96
  getEntries(): Promise<NodeEntry[]>;
98
97
  getPointer(): Promise<CID>;
98
+ serialize(): Promise<{
99
+ cid: CID;
100
+ bytes: Uint8Array;
101
+ }>;
99
102
  getLayer(): Promise<number>;
100
103
  attemptGetLayer(): Promise<number | null>;
101
104
  getUnstoredBlocks(): Promise<{
@@ -1,15 +1,16 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import { Commit, DataStore, RepoContents } from './types';
2
+ import { RepoContents, Commit } from './types';
3
3
  import { ReadableBlockstore } from './storage';
4
+ import { MST } from './mst';
4
5
  declare type Params = {
5
6
  storage: ReadableBlockstore;
6
- data: DataStore;
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: DataStore;
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, DataStore, RecordCreateOp, RecordWriteOp, CommitData } from './types';
3
+ import { Commit, CommitData, RecordCreateOp, RecordWriteOp } 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: DataStore;
9
+ data: MST;
9
10
  commit: Commit;
10
11
  cid: CID;
11
12
  };
@@ -1,5 +1,4 @@
1
1
  export * from './readable-blockstore';
2
- export * from './repo-storage';
3
2
  export * from './memory-blockstore';
4
3
  export * from './sync-storage';
5
4
  export * from './types';
@@ -1,12 +1,13 @@
1
1
  import { CID } from 'multiformats/cid';
2
2
  import { CommitData } from '../types';
3
3
  import BlockMap from '../block-map';
4
- import RepoStorage from './repo-storage';
5
- export declare class MemoryBlockstore extends RepoStorage {
4
+ import ReadableBlockstore from './readable-blockstore';
5
+ import { RepoStorage } from './types';
6
+ export declare class MemoryBlockstore extends ReadableBlockstore implements RepoStorage {
6
7
  blocks: BlockMap;
7
- head: CID | null;
8
+ root: CID | null;
8
9
  constructor(blocks?: BlockMap);
9
- getHead(): Promise<CID | null>;
10
+ getRoot(): Promise<CID | null>;
10
11
  getBytes(cid: CID): Promise<Uint8Array | null>;
11
12
  has(cid: CID): Promise<boolean>;
12
13
  getBlocks(cids: CID[]): Promise<{
@@ -15,13 +16,8 @@ export declare class MemoryBlockstore extends RepoStorage {
15
16
  }>;
16
17
  putBlock(cid: CID, block: Uint8Array): Promise<void>;
17
18
  putMany(blocks: BlockMap): Promise<void>;
18
- indexCommits(commits: CommitData[]): Promise<void>;
19
- updateHead(cid: CID, _prev: CID | null): Promise<void>;
19
+ updateRoot(cid: CID): Promise<void>;
20
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
21
  sizeInBytes(): Promise<number>;
26
22
  destroy(): Promise<void>;
27
23
  }
@@ -1,6 +1,34 @@
1
1
  /// <reference types="node" />
2
2
  import stream from 'stream';
3
3
  import { CID } from 'multiformats/cid';
4
+ import { RepoRecord } from '@atproto/lexicon';
5
+ import { check } from '@atproto/common';
6
+ import BlockMap from '../block-map';
7
+ import { CommitData } from '../types';
8
+ export interface RepoStorage {
9
+ getRoot(): Promise<CID | null>;
10
+ putBlock(cid: CID, block: Uint8Array, rev: string): Promise<void>;
11
+ putMany(blocks: BlockMap, rev: string): Promise<void>;
12
+ updateRoot(cid: CID): Promise<void>;
13
+ applyCommit(commit: CommitData): any;
14
+ getBytes(cid: CID): Promise<Uint8Array | null>;
15
+ has(cid: CID): Promise<boolean>;
16
+ getBlocks(cids: CID[]): Promise<{
17
+ blocks: BlockMap;
18
+ missing: CID[];
19
+ }>;
20
+ attemptRead<T>(cid: CID, def: check.Def<T>): Promise<{
21
+ obj: T;
22
+ bytes: Uint8Array;
23
+ } | null>;
24
+ readObjAndBytes<T>(cid: CID, def: check.Def<T>): Promise<{
25
+ obj: T;
26
+ bytes: Uint8Array;
27
+ }>;
28
+ readObj<T>(cid: CID, def: check.Def<T>): Promise<T>;
29
+ attemptReadRecord(cid: CID): Promise<RepoRecord | null>;
30
+ readRecord(cid: CID): Promise<RepoRecord>;
31
+ }
4
32
  export interface BlobStore {
5
33
  putTemp(bytes: Uint8Array | stream.Readable): Promise<string>;
6
34
  makePermanent(key: string, cid: CID): Promise<void>;
@@ -9,6 +37,7 @@ export interface BlobStore {
9
37
  unquarantine(cid: CID): Promise<void>;
10
38
  getBytes(cid: CID): Promise<Uint8Array>;
11
39
  getStream(cid: CID): Promise<stream.Readable>;
40
+ hasStored(cid: CID): Promise<boolean>;
12
41
  delete(cid: CID): Promise<void>;
13
42
  }
14
43
  export declare class BlobNotFoundError extends Error {
@@ -1,18 +1,15 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import { RepoStorage } from '../storage';
3
- import Repo from '../repo';
4
- import * as verify from '../verify';
5
- import { RepoContents, WriteLog } from '../types';
6
- export declare const loadCheckout: (storage: RepoStorage, repoCar: Uint8Array, did: string, signingKey: string) => Promise<{
7
- root: CID;
8
- contents: RepoContents;
2
+ import ReadableRepo from '../readable-repo';
3
+ import { RecordClaim, VerifiedDiff, VerifiedRepo } from '../types';
4
+ import BlockMap from '../block-map';
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) => Promise<VerifiedRepo>;
7
+ export declare const verifyDiffCar: (repo: ReadableRepo | null, carBytes: Uint8Array, did?: string, signingKey?: string) => Promise<VerifiedDiff>;
8
+ export declare const verifyDiff: (repo: ReadableRepo | null, updateBlocks: BlockMap, updateRoot: CID, did?: string, signingKey?: string) => Promise<VerifiedDiff>;
9
+ export declare const verifyProofs: (proofs: Uint8Array, claims: RecordClaim[], did: string, didKey: string) => Promise<{
10
+ verified: RecordClaim[];
11
+ unverified: RecordClaim[];
9
12
  }>;
10
- export declare const loadFullRepo: (storage: RepoStorage, repoCar: Uint8Array, did: string, signingKey: string) => Promise<{
11
- root: CID;
12
- writeLog: WriteLog;
13
- }>;
14
- export declare const loadDiff: (repo: Repo, diffCar: Uint8Array, did: string, signingKey: string) => Promise<{
15
- root: CID;
16
- writeLog: WriteLog;
17
- }>;
18
- export declare const persistUpdates: (storage: RepoStorage, updateStorage: RepoStorage, updates: verify.VerifiedUpdate[]) => Promise<WriteLog>;
13
+ export declare const verifyRecords: (proofs: Uint8Array, did: string, signingKey: string) => Promise<RecordClaim[]>;
14
+ export declare class RepoVerificationError extends Error {
15
+ }
@@ -1,9 +1,5 @@
1
1
  import { RecordPath } from '../types';
2
- import { BlockWriter } from '@ipld/car/writer';
3
2
  import { CID } from 'multiformats/cid';
4
3
  import { RepoStorage } from '../storage';
5
- export declare const getCheckout: (storage: RepoStorage, commitCid: CID) => Promise<Uint8Array>;
6
- export declare const getDiff: (storage: RepoStorage, latest: CID, earliest: CID | null) => Promise<Uint8Array>;
7
- export declare const getFullRepo: (storage: RepoStorage, cid: CID) => Promise<Uint8Array>;
8
- export declare const writeCommitsToCarStream: (storage: RepoStorage, car: BlockWriter, latest: CID, earliest: CID | null) => Promise<void>;
9
- export declare const getRecords: (storage: RepoStorage, commitCid: CID, paths: RecordPath[]) => Promise<Uint8Array>;
4
+ export declare const getFullRepo: (storage: RepoStorage, commitCid: CID) => AsyncIterable<Uint8Array>;
5
+ export declare const getRecords: (storage: RepoStorage, commitCid: CID, paths: RecordPath[]) => AsyncIterable<Uint8Array>;
package/dist/types.d.ts CHANGED
@@ -1,67 +1,208 @@
1
1
  import { z } from 'zod';
2
- import { BlockWriter } from '@ipld/car/writer';
3
2
  import { CID } from 'multiformats';
4
3
  import BlockMap from './block-map';
5
4
  import { RepoRecord } from '@atproto/lexicon';
5
+ import CidSet from './cid-set';
6
6
  declare const unsignedCommit: z.ZodObject<{
7
7
  did: z.ZodString;
8
- version: z.ZodNumber;
9
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
8
+ version: z.ZodLiteral<3>;
10
9
  data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
10
+ rev: z.ZodString;
11
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
11
12
  }, "strip", z.ZodTypeAny, {
12
- data: CID;
13
13
  did: string;
14
- version: number;
15
- prev: CID | null;
14
+ data: CID;
15
+ version: 3;
16
+ rev: string;
17
+ prev?: CID | null | undefined;
16
18
  }, {
19
+ did: string;
20
+ version: 3;
21
+ rev: string;
17
22
  data?: any;
18
23
  prev?: any;
19
- did: string;
20
- version: number;
21
24
  }>;
22
25
  export declare type UnsignedCommit = z.infer<typeof unsignedCommit> & {
23
26
  sig?: never;
24
27
  };
25
28
  declare const commit: z.ZodObject<{
26
29
  did: z.ZodString;
27
- version: z.ZodNumber;
28
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
30
+ version: z.ZodLiteral<3>;
29
31
  data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
32
+ rev: z.ZodString;
33
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
30
34
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
31
35
  }, "strip", z.ZodTypeAny, {
36
+ did: string;
32
37
  data: CID;
38
+ version: 3;
39
+ rev: string;
40
+ sig: Uint8Array;
41
+ prev?: CID | null | undefined;
42
+ }, {
43
+ did: string;
44
+ version: 3;
45
+ rev: string;
46
+ sig: Uint8Array;
47
+ data?: any;
48
+ prev?: any;
49
+ }>;
50
+ export declare type Commit = z.infer<typeof commit>;
51
+ declare const legacyV2Commit: z.ZodObject<{
52
+ did: z.ZodString;
53
+ version: z.ZodLiteral<2>;
54
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
55
+ rev: z.ZodOptional<z.ZodString>;
56
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
57
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
58
+ }, "strip", z.ZodTypeAny, {
33
59
  did: string;
34
- version: number;
60
+ data: CID;
61
+ version: 2;
35
62
  prev: CID | null;
36
63
  sig: Uint8Array;
64
+ rev?: string | undefined;
37
65
  }, {
66
+ did: string;
67
+ version: 2;
68
+ sig: Uint8Array;
38
69
  data?: any;
70
+ rev?: string | undefined;
39
71
  prev?: any;
72
+ }>;
73
+ export declare type LegacyV2Commit = z.infer<typeof legacyV2Commit>;
74
+ declare const versionedCommit: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
75
+ did: z.ZodString;
76
+ version: z.ZodLiteral<3>;
77
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
78
+ rev: z.ZodString;
79
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
80
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
81
+ }, "strip", z.ZodTypeAny, {
40
82
  did: string;
41
- version: number;
83
+ data: CID;
84
+ version: 3;
85
+ rev: string;
42
86
  sig: Uint8Array;
43
- }>;
44
- export declare type Commit = z.infer<typeof commit>;
87
+ prev?: CID | null | undefined;
88
+ }, {
89
+ did: string;
90
+ version: 3;
91
+ rev: string;
92
+ sig: Uint8Array;
93
+ data?: any;
94
+ prev?: any;
95
+ }>, z.ZodObject<{
96
+ did: z.ZodString;
97
+ version: z.ZodLiteral<2>;
98
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
99
+ rev: z.ZodOptional<z.ZodString>;
100
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
101
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
102
+ }, "strip", z.ZodTypeAny, {
103
+ did: string;
104
+ data: CID;
105
+ version: 2;
106
+ prev: CID | null;
107
+ sig: Uint8Array;
108
+ rev?: string | undefined;
109
+ }, {
110
+ did: string;
111
+ version: 2;
112
+ sig: Uint8Array;
113
+ data?: any;
114
+ rev?: string | undefined;
115
+ prev?: any;
116
+ }>]>;
117
+ export declare type VersionedCommit = z.infer<typeof versionedCommit>;
45
118
  export declare const schema: {
46
119
  commit: z.ZodObject<{
47
120
  did: z.ZodString;
48
- version: z.ZodNumber;
49
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
121
+ version: z.ZodLiteral<3>;
50
122
  data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
123
+ rev: z.ZodString;
124
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
51
125
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
52
126
  }, "strip", z.ZodTypeAny, {
127
+ did: string;
53
128
  data: CID;
129
+ version: 3;
130
+ rev: string;
131
+ sig: Uint8Array;
132
+ prev?: CID | null | undefined;
133
+ }, {
134
+ did: string;
135
+ version: 3;
136
+ rev: string;
137
+ sig: Uint8Array;
138
+ data?: any;
139
+ prev?: any;
140
+ }>;
141
+ legacyV2Commit: z.ZodObject<{
142
+ did: z.ZodString;
143
+ version: z.ZodLiteral<2>;
144
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
145
+ rev: z.ZodOptional<z.ZodString>;
146
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
147
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
148
+ }, "strip", z.ZodTypeAny, {
54
149
  did: string;
55
- version: number;
150
+ data: CID;
151
+ version: 2;
56
152
  prev: CID | null;
57
153
  sig: Uint8Array;
154
+ rev?: string | undefined;
155
+ }, {
156
+ did: string;
157
+ version: 2;
158
+ sig: Uint8Array;
159
+ data?: any;
160
+ rev?: string | undefined;
161
+ prev?: any;
162
+ }>;
163
+ versionedCommit: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
164
+ did: z.ZodString;
165
+ version: z.ZodLiteral<3>;
166
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
167
+ rev: z.ZodString;
168
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
169
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
170
+ }, "strip", z.ZodTypeAny, {
171
+ did: string;
172
+ data: CID;
173
+ version: 3;
174
+ rev: string;
175
+ sig: Uint8Array;
176
+ prev?: CID | null | undefined;
58
177
  }, {
178
+ did: string;
179
+ version: 3;
180
+ rev: string;
181
+ sig: Uint8Array;
59
182
  data?: any;
60
183
  prev?: any;
184
+ }>, z.ZodObject<{
185
+ did: z.ZodString;
186
+ version: z.ZodLiteral<2>;
187
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
188
+ rev: z.ZodOptional<z.ZodString>;
189
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
190
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
191
+ }, "strip", z.ZodTypeAny, {
61
192
  did: string;
62
- version: number;
193
+ data: CID;
194
+ version: 2;
195
+ prev: CID | null;
63
196
  sig: Uint8Array;
64
- }>;
197
+ rev?: string | undefined;
198
+ }, {
199
+ did: string;
200
+ version: 2;
201
+ sig: Uint8Array;
202
+ data?: any;
203
+ rev?: string | undefined;
204
+ prev?: any;
205
+ }>]>;
65
206
  cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
66
207
  bytes: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
67
208
  string: z.ZodString;
@@ -74,23 +215,72 @@ export declare const def: {
74
215
  name: string;
75
216
  schema: z.ZodObject<{
76
217
  did: z.ZodString;
77
- version: z.ZodNumber;
78
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
218
+ version: z.ZodLiteral<3>;
79
219
  data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
220
+ rev: z.ZodString;
221
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
80
222
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
81
223
  }, "strip", z.ZodTypeAny, {
224
+ did: string;
82
225
  data: CID;
226
+ version: 3;
227
+ rev: string;
228
+ sig: Uint8Array;
229
+ prev?: CID | null | undefined;
230
+ }, {
83
231
  did: string;
84
- version: number;
85
- prev: CID | null;
232
+ version: 3;
233
+ rev: string;
86
234
  sig: Uint8Array;
235
+ data?: any;
236
+ prev?: any;
237
+ }>;
238
+ };
239
+ versionedCommit: {
240
+ name: string;
241
+ schema: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
242
+ did: z.ZodString;
243
+ version: z.ZodLiteral<3>;
244
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
245
+ rev: z.ZodString;
246
+ prev: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>>;
247
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
248
+ }, "strip", z.ZodTypeAny, {
249
+ did: string;
250
+ data: CID;
251
+ version: 3;
252
+ rev: string;
253
+ sig: Uint8Array;
254
+ prev?: CID | null | undefined;
87
255
  }, {
256
+ did: string;
257
+ version: 3;
258
+ rev: string;
259
+ sig: Uint8Array;
88
260
  data?: any;
89
261
  prev?: any;
262
+ }>, z.ZodObject<{
263
+ did: z.ZodString;
264
+ version: z.ZodLiteral<2>;
265
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
266
+ rev: z.ZodOptional<z.ZodString>;
267
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
268
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
269
+ }, "strip", z.ZodTypeAny, {
90
270
  did: string;
91
- version: number;
271
+ data: CID;
272
+ version: 2;
273
+ prev: CID | null;
92
274
  sig: Uint8Array;
93
- }>;
275
+ rev?: string | undefined;
276
+ }, {
277
+ did: string;
278
+ version: 2;
279
+ sig: Uint8Array;
280
+ data?: any;
281
+ rev?: string | undefined;
282
+ prev?: any;
283
+ }>]>;
94
284
  };
95
285
  cid: import("@atproto/common-web/src/check").Def<CID>;
96
286
  bytes: import("@atproto/common-web/src/check").Def<Uint8Array>;
@@ -133,18 +323,26 @@ export declare type RecordDeleteDescript = RecordDeleteOp & {
133
323
  };
134
324
  export declare type RecordWriteDescript = RecordCreateDescript | RecordUpdateDescript | RecordDeleteDescript;
135
325
  export declare type WriteLog = RecordWriteDescript[][];
136
- export declare type CommitBlockData = {
137
- commit: CID;
138
- blocks: BlockMap;
139
- };
140
- export declare type CommitData = CommitBlockData & {
326
+ export declare type CommitData = {
327
+ cid: CID;
328
+ rev: string;
329
+ since: string | null;
141
330
  prev: CID | null;
331
+ newBlocks: BlockMap;
332
+ removedCids: CidSet;
142
333
  };
143
334
  export declare type RepoUpdate = CommitData & {
144
335
  ops: RecordWriteOp[];
145
336
  };
146
337
  export declare type CollectionContents = Record<string, RepoRecord>;
147
338
  export declare type RepoContents = Record<string, CollectionContents>;
339
+ export declare type RepoRecordWithCid = {
340
+ cid: CID;
341
+ value: RepoRecord;
342
+ };
343
+ export declare type CollectionContentsWithCids = Record<string, RepoRecordWithCid>;
344
+ export declare type RepoContentsWithCids = Record<string, CollectionContentsWithCids>;
345
+ export declare type DatastoreContents = Record<string, CID>;
148
346
  export declare type RecordPath = {
149
347
  collection: string;
150
348
  rkey: string;
@@ -154,22 +352,12 @@ export declare type RecordClaim = {
154
352
  rkey: string;
155
353
  record: RepoRecord | null;
156
354
  };
157
- export declare type DataValue = {
158
- key: string;
159
- value: CID;
160
- };
161
- export interface DataStore {
162
- add(key: string, value: CID): Promise<DataStore>;
163
- update(key: string, value: CID): Promise<DataStore>;
164
- delete(key: string): Promise<DataStore>;
165
- get(key: string): Promise<CID | null>;
166
- list(count?: number, after?: string, before?: string): Promise<DataValue[]>;
167
- listWithPrefix(prefix: string, count?: number): Promise<DataValue[]>;
168
- getUnstoredBlocks(): Promise<{
169
- root: CID;
170
- blocks: BlockMap;
171
- }>;
172
- writeToCarStream(car: BlockWriter): Promise<void>;
173
- cidsForPath(key: string): Promise<CID[]>;
174
- }
355
+ export declare type VerifiedDiff = {
356
+ writes: RecordWriteDescript[];
357
+ commit: CommitData;
358
+ };
359
+ export declare type VerifiedRepo = {
360
+ creates: RecordCreateDescript[];
361
+ commit: CommitData;
362
+ };
175
363
  export {};
package/dist/util.d.ts CHANGED
@@ -1,15 +1,18 @@
1
+ /// <reference types="node" />
1
2
  import { CID } from 'multiformats/cid';
2
3
  import { BlockWriter } from '@ipld/car/writer';
3
4
  import { Block as CarBlock } from '@ipld/car/api';
4
5
  import { LexValue, RepoRecord } from '@atproto/lexicon';
5
6
  import DataDiff from './data-diff';
6
- import { RepoStorage } from './storage';
7
- import { Commit, RecordPath, RecordWriteDescript, UnsignedCommit, WriteLog } from './types';
7
+ import { Commit, LegacyV2Commit, RecordCreateDescript, RecordPath, RecordWriteDescript, UnsignedCommit } from './types';
8
8
  import BlockMap from './block-map';
9
9
  import { Keypair } from '@atproto/crypto';
10
+ import { Readable } from 'stream';
10
11
  export declare function verifyIncomingCarBlocks(car: AsyncIterable<CarBlock>): AsyncIterable<CarBlock>;
11
- export declare const writeCar: (root: CID | null, fn: (car: BlockWriter) => Promise<void>) => Promise<Uint8Array>;
12
- export declare const blocksToCar: (root: CID | null, blocks: BlockMap) => Promise<Uint8Array>;
12
+ export declare function writeCarStream(root: CID | null, fn: (car: BlockWriter) => Promise<void>): Readable;
13
+ export declare function writeCar(root: CID | null, fn: (car: BlockWriter) => Promise<void>): AsyncIterable<Uint8Array>;
14
+ export declare const blocksToCarStream: (root: CID | null, blocks: BlockMap) => AsyncIterable<Uint8Array>;
15
+ export declare const blocksToCarFile: (root: CID | null, blocks: BlockMap) => Promise<Uint8Array>;
13
16
  export declare const readCar: (bytes: Uint8Array) => Promise<{
14
17
  roots: CID[];
15
18
  blocks: BlockMap;
@@ -18,10 +21,8 @@ export declare const readCarWithRoot: (bytes: Uint8Array) => Promise<{
18
21
  root: CID;
19
22
  blocks: BlockMap;
20
23
  }>;
21
- export declare const getWriteLog: (storage: RepoStorage, latest: CID, earliest: CID | null) => Promise<WriteLog>;
22
24
  export declare const diffToWriteDescripts: (diff: DataDiff, blocks: BlockMap) => Promise<RecordWriteDescript[]>;
23
- export declare const collapseWriteLog: (log: WriteLog) => RecordWriteDescript[];
24
- export declare const collapseDiffs: (diffs: DataDiff[]) => DataDiff;
25
+ export declare const ensureCreates: (descripts: RecordWriteDescript[]) => RecordCreateDescript[];
25
26
  export declare const parseDataKey: (key: string) => RecordPath;
26
27
  export declare const formatDataKey: (collection: string, rkey: string) => string;
27
28
  export declare const metaEqual: (a: Commit, b: Commit) => boolean;
@@ -30,3 +31,4 @@ export declare const verifyCommitSig: (commit: Commit, didKey: string) => Promis
30
31
  export declare const cborToLex: (val: Uint8Array) => LexValue;
31
32
  export declare const cborToLexRecord: (val: Uint8Array) => RepoRecord;
32
33
  export declare const cidForRecord: (val: LexValue) => Promise<CID>;
34
+ export declare const ensureV3Commit: (commit: LegacyV2Commit | Commit) => Commit;