@atproto/repo 0.2.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 (79) hide show
  1. package/dist/data-diff.d.ts +11 -9
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +404 -1655
  4. package/dist/index.js.map +4 -4
  5. package/dist/mst/mst.d.ts +10 -6
  6. package/dist/readable-repo.d.ts +1 -1
  7. package/dist/repo.d.ts +1 -4
  8. package/dist/storage/index.d.ts +0 -1
  9. package/dist/storage/memory-blockstore.d.ts +7 -12
  10. package/dist/storage/types.d.ts +28 -0
  11. package/dist/sync/consumer.d.ts +13 -17
  12. package/dist/sync/provider.d.ts +1 -5
  13. package/dist/types.d.ts +228 -39
  14. package/dist/util.d.ts +3 -5
  15. package/package.json +2 -2
  16. package/src/data-diff.ts +46 -44
  17. package/src/index.ts +0 -1
  18. package/src/mst/diff.ts +14 -36
  19. package/src/mst/mst.ts +14 -4
  20. package/src/readable-repo.ts +3 -3
  21. package/src/repo.ts +49 -70
  22. package/src/storage/index.ts +0 -1
  23. package/src/storage/memory-blockstore.ts +18 -77
  24. package/src/storage/types.ts +29 -0
  25. package/src/sync/consumer.ts +170 -116
  26. package/src/sync/provider.ts +2 -40
  27. package/src/types.ts +49 -23
  28. package/src/util.ts +24 -79
  29. package/tests/_util.ts +38 -67
  30. package/tests/mst.test.ts +4 -1
  31. package/tests/{sync/narrow.test.ts → proofs.test.ts} +9 -20
  32. package/tests/repo.test.ts +5 -4
  33. package/tests/sync.test.ts +97 -0
  34. package/tsconfig.build.tsbuildinfo +1 -1
  35. package/dist/src/block-map.d.ts +0 -23
  36. package/dist/src/blockstore/index.d.ts +0 -2
  37. package/dist/src/blockstore/ipld-store.d.ts +0 -27
  38. package/dist/src/blockstore/memory-blockstore.d.ts +0 -13
  39. package/dist/src/blockstore/persistent-blockstore.d.ts +0 -12
  40. package/dist/src/cid-set.d.ts +0 -14
  41. package/dist/src/collection.d.ts +0 -22
  42. package/dist/src/data-diff.d.ts +0 -34
  43. package/dist/src/error.d.ts +0 -21
  44. package/dist/src/index.d.ts +0 -7
  45. package/dist/src/logger.d.ts +0 -2
  46. package/dist/src/mst/diff.d.ts +0 -33
  47. package/dist/src/mst/index.d.ts +0 -4
  48. package/dist/src/mst/mst.d.ts +0 -106
  49. package/dist/src/mst/util.d.ts +0 -9
  50. package/dist/src/mst/walker.d.ts +0 -22
  51. package/dist/src/parse.d.ts +0 -11
  52. package/dist/src/readable-repo.d.ts +0 -25
  53. package/dist/src/repo.d.ts +0 -39
  54. package/dist/src/storage/error.d.ts +0 -22
  55. package/dist/src/storage/index.d.ts +0 -1
  56. package/dist/src/storage/memory-blobstore.d.ts +0 -1
  57. package/dist/src/storage/memory-blockstore.d.ts +0 -28
  58. package/dist/src/storage/readable-blockstore.d.ts +0 -21
  59. package/dist/src/storage/repo-storage.d.ts +0 -18
  60. package/dist/src/storage/sync-storage.d.ts +0 -15
  61. package/dist/src/storage/types.d.ts +0 -12
  62. package/dist/src/storage/util.d.ts +0 -17
  63. package/dist/src/structure.d.ts +0 -39
  64. package/dist/src/sync/consumer.d.ts +0 -19
  65. package/dist/src/sync/index.d.ts +0 -2
  66. package/dist/src/sync/producer.d.ts +0 -13
  67. package/dist/src/sync/provider.d.ts +0 -11
  68. package/dist/src/sync.d.ts +0 -9
  69. package/dist/src/types.d.ts +0 -368
  70. package/dist/src/util.d.ts +0 -13
  71. package/dist/src/verify.d.ts +0 -5
  72. package/dist/storage/repo-storage.d.ts +0 -19
  73. package/dist/tsconfig.build.tsbuildinfo +0 -1
  74. package/dist/verify.d.ts +0 -32
  75. package/src/storage/repo-storage.ts +0 -43
  76. package/src/verify.ts +0 -268
  77. package/tests/rebase.test.ts +0 -37
  78. package/tests/sync/checkout.test.ts +0 -75
  79. package/tests/sync/diff.test.ts +0 -92
package/dist/mst/mst.d.ts CHANGED
@@ -12,10 +12,10 @@ declare const nodeData: z.ZodObject<{
12
12
  v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
13
13
  t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
14
14
  }, "strip", z.ZodTypeAny, {
15
+ t: CID | null;
15
16
  p: number;
16
17
  k: Uint8Array;
17
18
  v: CID;
18
- t: CID | null;
19
19
  }, {
20
20
  p: number;
21
21
  k: Uint8Array;
@@ -23,13 +23,13 @@ declare const nodeData: z.ZodObject<{
23
23
  t?: any;
24
24
  }>, "many">;
25
25
  }, "strip", z.ZodTypeAny, {
26
+ l: CID | null;
26
27
  e: {
28
+ t: CID | null;
27
29
  p: number;
28
30
  k: Uint8Array;
29
31
  v: CID;
30
- t: CID | null;
31
32
  }[];
32
- l: CID | null;
33
33
  }, {
34
34
  e: {
35
35
  p: number;
@@ -50,10 +50,10 @@ export declare const nodeDataDef: {
50
50
  v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
51
51
  t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
52
52
  }, "strip", z.ZodTypeAny, {
53
+ t: CID | null;
53
54
  p: number;
54
55
  k: Uint8Array;
55
56
  v: CID;
56
- t: CID | null;
57
57
  }, {
58
58
  p: number;
59
59
  k: Uint8Array;
@@ -61,13 +61,13 @@ export declare const nodeDataDef: {
61
61
  t?: any;
62
62
  }>, "many">;
63
63
  }, "strip", z.ZodTypeAny, {
64
+ l: CID | null;
64
65
  e: {
66
+ t: CID | null;
65
67
  p: number;
66
68
  k: Uint8Array;
67
69
  v: CID;
68
- t: CID | null;
69
70
  }[];
70
- l: CID | null;
71
71
  }, {
72
72
  e: {
73
73
  p: number;
@@ -95,6 +95,10 @@ export declare class MST {
95
95
  newTree(entries: NodeEntry[]): Promise<MST>;
96
96
  getEntries(): Promise<NodeEntry[]>;
97
97
  getPointer(): Promise<CID>;
98
+ serialize(): Promise<{
99
+ cid: CID;
100
+ bytes: Uint8Array;
101
+ }>;
98
102
  getLayer(): Promise<number>;
99
103
  attemptGetLayer(): Promise<number | null>;
100
104
  getUnstoredBlocks(): Promise<{
@@ -1,5 +1,5 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import { Commit, RepoContents } from './types';
2
+ import { RepoContents, Commit } from './types';
3
3
  import { ReadableBlockstore } from './storage';
4
4
  import { MST } from './mst';
5
5
  declare type Params = {
package/dist/repo.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CID } from 'multiformats/cid';
2
2
  import * as crypto from '@atproto/crypto';
3
- import { Commit, RecordCreateOp, RecordWriteOp, CommitData, RebaseData } from './types';
3
+ import { Commit, CommitData, RecordCreateOp, RecordWriteOp } from './types';
4
4
  import { RepoStorage } from './storage';
5
5
  import { MST } from './mst';
6
6
  import { ReadableRepo } from './readable-repo';
@@ -20,8 +20,5 @@ export declare class Repo extends ReadableRepo {
20
20
  formatCommit(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<CommitData>;
21
21
  applyCommit(commitData: CommitData): Promise<Repo>;
22
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>;
26
23
  }
27
24
  export default Repo;
@@ -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
- import { CommitData, RebaseData } from '../types';
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,14 +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
- applyRebase(rebase: RebaseData): Promise<void>;
26
21
  sizeInBytes(): Promise<number>;
27
22
  destroy(): Promise<void>;
28
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>;
@@ -1,19 +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
- repo: Repo;
14
- }>;
15
- export declare const loadDiff: (repo: Repo, diffCar: Uint8Array, did: string, signingKey: string) => Promise<{
16
- root: CID;
17
- writeLog: WriteLog;
18
- }>;
19
- 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) => AsyncIterable<Uint8Array>;
6
- export declare const getCommits: (storage: RepoStorage, latest: CID, earliest: CID | null) => AsyncIterable<Uint8Array>;
7
- export declare const getFullRepo: (storage: RepoStorage, cid: CID) => AsyncIterable<Uint8Array>;
8
- export declare const writeCommitsToCarStream: (storage: RepoStorage, car: BlockWriter, latest: CID, earliest: CID | null) => Promise<void>;
4
+ export declare const getFullRepo: (storage: RepoStorage, commitCid: CID) => AsyncIterable<Uint8Array>;
9
5
  export declare const getRecords: (storage: RepoStorage, commitCid: CID, paths: RecordPath[]) => AsyncIterable<Uint8Array>;
package/dist/types.d.ts CHANGED
@@ -2,65 +2,207 @@ import { z } from 'zod';
2
2
  import { CID } from 'multiformats';
3
3
  import BlockMap from './block-map';
4
4
  import { RepoRecord } from '@atproto/lexicon';
5
+ import CidSet from './cid-set';
5
6
  declare const unsignedCommit: z.ZodObject<{
6
7
  did: z.ZodString;
7
- version: z.ZodNumber;
8
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
8
+ version: z.ZodLiteral<3>;
9
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>>>;
10
12
  }, "strip", z.ZodTypeAny, {
11
13
  did: string;
12
14
  data: CID;
13
- version: number;
14
- prev: CID | null;
15
+ version: 3;
16
+ rev: string;
17
+ prev?: CID | null | undefined;
15
18
  }, {
16
19
  did: string;
17
- version: number;
18
- prev?: any;
20
+ version: 3;
21
+ rev: string;
19
22
  data?: any;
23
+ prev?: any;
20
24
  }>;
21
25
  export declare type UnsignedCommit = z.infer<typeof unsignedCommit> & {
22
26
  sig?: never;
23
27
  };
24
28
  declare const commit: z.ZodObject<{
25
29
  did: z.ZodString;
26
- version: z.ZodNumber;
27
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
30
+ version: z.ZodLiteral<3>;
28
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>>>;
29
34
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
30
35
  }, "strip", z.ZodTypeAny, {
31
36
  did: string;
32
37
  data: CID;
33
- version: number;
34
- prev: CID | null;
38
+ version: 3;
39
+ rev: string;
35
40
  sig: Uint8Array;
41
+ prev?: CID | null | undefined;
36
42
  }, {
37
43
  did: string;
38
- version: number;
44
+ version: 3;
45
+ rev: string;
39
46
  sig: Uint8Array;
40
- prev?: any;
41
47
  data?: any;
48
+ prev?: any;
42
49
  }>;
43
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, {
59
+ did: string;
60
+ data: CID;
61
+ version: 2;
62
+ prev: CID | null;
63
+ sig: Uint8Array;
64
+ rev?: string | undefined;
65
+ }, {
66
+ did: string;
67
+ version: 2;
68
+ sig: Uint8Array;
69
+ data?: any;
70
+ rev?: string | undefined;
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, {
82
+ did: string;
83
+ data: CID;
84
+ version: 3;
85
+ rev: string;
86
+ sig: Uint8Array;
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>;
44
118
  export declare const schema: {
45
119
  commit: z.ZodObject<{
46
120
  did: z.ZodString;
47
- version: z.ZodNumber;
48
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
121
+ version: z.ZodLiteral<3>;
49
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>>>;
50
125
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
51
126
  }, "strip", z.ZodTypeAny, {
52
127
  did: string;
53
128
  data: CID;
54
- version: number;
55
- prev: CID | null;
129
+ version: 3;
130
+ rev: string;
56
131
  sig: Uint8Array;
132
+ prev?: CID | null | undefined;
57
133
  }, {
58
134
  did: string;
59
- version: number;
135
+ version: 3;
136
+ rev: string;
60
137
  sig: Uint8Array;
138
+ data?: any;
61
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, {
149
+ did: string;
150
+ data: CID;
151
+ version: 2;
152
+ prev: CID | null;
153
+ sig: Uint8Array;
154
+ rev?: string | undefined;
155
+ }, {
156
+ did: string;
157
+ version: 2;
158
+ sig: Uint8Array;
62
159
  data?: any;
160
+ rev?: string | undefined;
161
+ prev?: any;
63
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;
177
+ }, {
178
+ did: string;
179
+ version: 3;
180
+ rev: string;
181
+ sig: Uint8Array;
182
+ data?: any;
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, {
192
+ did: string;
193
+ data: CID;
194
+ version: 2;
195
+ prev: CID | null;
196
+ sig: Uint8Array;
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
+ }>]>;
64
206
  cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
65
207
  bytes: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
66
208
  string: z.ZodString;
@@ -73,24 +215,73 @@ export declare const def: {
73
215
  name: string;
74
216
  schema: z.ZodObject<{
75
217
  did: z.ZodString;
76
- version: z.ZodNumber;
77
- prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
218
+ version: z.ZodLiteral<3>;
78
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>>>;
79
222
  sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
80
223
  }, "strip", z.ZodTypeAny, {
81
224
  did: string;
82
225
  data: CID;
83
- version: number;
84
- prev: CID | null;
226
+ version: 3;
227
+ rev: string;
85
228
  sig: Uint8Array;
229
+ prev?: CID | null | undefined;
86
230
  }, {
87
231
  did: string;
88
- version: number;
232
+ version: 3;
233
+ rev: string;
89
234
  sig: Uint8Array;
90
- prev?: any;
91
235
  data?: any;
236
+ prev?: any;
92
237
  }>;
93
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;
255
+ }, {
256
+ did: string;
257
+ version: 3;
258
+ rev: string;
259
+ sig: Uint8Array;
260
+ data?: any;
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, {
270
+ did: string;
271
+ data: CID;
272
+ version: 2;
273
+ prev: CID | null;
274
+ sig: Uint8Array;
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
+ }>]>;
284
+ };
94
285
  cid: import("@atproto/common-web/src/check").Def<CID>;
95
286
  bytes: import("@atproto/common-web/src/check").Def<Uint8Array>;
96
287
  string: import("@atproto/common-web/src/check").Def<string>;
@@ -132,23 +323,13 @@ export declare type RecordDeleteDescript = RecordDeleteOp & {
132
323
  };
133
324
  export declare type RecordWriteDescript = RecordCreateDescript | RecordUpdateDescript | RecordDeleteDescript;
134
325
  export declare type WriteLog = RecordWriteDescript[][];
135
- export declare type CommitBlockData = {
136
- commit: CID;
137
- blocks: BlockMap;
138
- };
139
- export declare type CommitData = CommitBlockData & {
140
- prev: CID | null;
141
- };
142
- export declare type RebaseData = {
143
- commit: CID;
144
- rebased: CID;
145
- blocks: BlockMap;
146
- preservedCids: CID[];
147
- };
148
- export declare type CommitCidData = {
149
- commit: CID;
326
+ export declare type CommitData = {
327
+ cid: CID;
328
+ rev: string;
329
+ since: string | null;
150
330
  prev: CID | null;
151
- cids: CID[];
331
+ newBlocks: BlockMap;
332
+ removedCids: CidSet;
152
333
  };
153
334
  export declare type RepoUpdate = CommitData & {
154
335
  ops: RecordWriteOp[];
@@ -171,4 +352,12 @@ export declare type RecordClaim = {
171
352
  rkey: string;
172
353
  record: RepoRecord | null;
173
354
  };
355
+ export declare type VerifiedDiff = {
356
+ writes: RecordWriteDescript[];
357
+ commit: CommitData;
358
+ };
359
+ export declare type VerifiedRepo = {
360
+ creates: RecordCreateDescript[];
361
+ commit: CommitData;
362
+ };
174
363
  export {};
package/dist/util.d.ts CHANGED
@@ -4,8 +4,7 @@ import { BlockWriter } from '@ipld/car/writer';
4
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 { RepoStorage } from './storage';
8
- import { Commit, RecordPath, RecordWriteDescript, UnsignedCommit, WriteLog } from './types';
7
+ import { Commit, LegacyV2Commit, RecordCreateDescript, RecordPath, RecordWriteDescript, UnsignedCommit } from './types';
9
8
  import BlockMap from './block-map';
10
9
  import { Keypair } from '@atproto/crypto';
11
10
  import { Readable } from 'stream';
@@ -22,10 +21,8 @@ export declare const readCarWithRoot: (bytes: Uint8Array) => Promise<{
22
21
  root: CID;
23
22
  blocks: BlockMap;
24
23
  }>;
25
- export declare const getWriteLog: (storage: RepoStorage, latest: CID, earliest: CID | null) => Promise<WriteLog>;
26
24
  export declare const diffToWriteDescripts: (diff: DataDiff, blocks: BlockMap) => Promise<RecordWriteDescript[]>;
27
- export declare const collapseWriteLog: (log: WriteLog) => RecordWriteDescript[];
28
- export declare const collapseDiffs: (diffs: DataDiff[]) => DataDiff;
25
+ export declare const ensureCreates: (descripts: RecordWriteDescript[]) => RecordCreateDescript[];
29
26
  export declare const parseDataKey: (key: string) => RecordPath;
30
27
  export declare const formatDataKey: (collection: string, rkey: string) => string;
31
28
  export declare const metaEqual: (a: Commit, b: Commit) => boolean;
@@ -34,3 +31,4 @@ export declare const verifyCommitSig: (commit: Commit, didKey: string) => Promis
34
31
  export declare const cborToLex: (val: Uint8Array) => LexValue;
35
32
  export declare const cborToLexRecord: (val: Uint8Array) => RepoRecord;
36
33
  export declare const cidForRecord: (val: LexValue) => Promise<CID>;
34
+ export declare const ensureV3Commit: (commit: LegacyV2Commit | Commit) => Commit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/repo",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "@atproto/crypto": "*",
32
32
  "@atproto/identity": "*",
33
33
  "@atproto/lexicon": "*",
34
- "@atproto/nsid": "*",
34
+ "@atproto/syntax": "*",
35
35
  "@ipld/car": "^3.2.3",
36
36
  "@ipld/dag-cbor": "^7.0.0",
37
37
  "multiformats": "^9.6.4",