@atproto/repo 0.2.0 → 0.3.1

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 (88) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1 -1
  4. package/build.js +0 -8
  5. package/dist/data-diff.d.ts +11 -9
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1620 -2953
  8. package/dist/index.js.map +4 -4
  9. package/dist/logger.d.ts +2 -1
  10. package/dist/mst/mst.d.ts +10 -6
  11. package/dist/readable-repo.d.ts +1 -1
  12. package/dist/repo.d.ts +1 -4
  13. package/dist/storage/index.d.ts +0 -1
  14. package/dist/storage/memory-blockstore.d.ts +7 -12
  15. package/dist/storage/types.d.ts +28 -0
  16. package/dist/sync/consumer.d.ts +13 -17
  17. package/dist/sync/provider.d.ts +1 -5
  18. package/dist/types.d.ts +228 -39
  19. package/dist/util.d.ts +3 -5
  20. package/package.json +17 -24
  21. package/src/data-diff.ts +46 -44
  22. package/src/index.ts +0 -1
  23. package/src/logger.ts +2 -1
  24. package/src/mst/diff.ts +14 -36
  25. package/src/mst/mst.ts +14 -4
  26. package/src/readable-repo.ts +3 -3
  27. package/src/repo.ts +49 -70
  28. package/src/storage/index.ts +0 -1
  29. package/src/storage/memory-blockstore.ts +18 -77
  30. package/src/storage/types.ts +29 -0
  31. package/src/sync/consumer.ts +170 -116
  32. package/src/sync/provider.ts +2 -40
  33. package/src/types.ts +51 -24
  34. package/src/util.ts +24 -79
  35. package/tests/_util.ts +38 -67
  36. package/tests/mst.test.ts +4 -1
  37. package/tests/{sync/narrow.test.ts → proofs.test.ts} +9 -20
  38. package/tests/repo.test.ts +5 -4
  39. package/tests/sync.test.ts +97 -0
  40. package/tsconfig.build.json +1 -1
  41. package/tsconfig.json +3 -3
  42. package/dist/src/block-map.d.ts +0 -23
  43. package/dist/src/blockstore/index.d.ts +0 -2
  44. package/dist/src/blockstore/ipld-store.d.ts +0 -27
  45. package/dist/src/blockstore/memory-blockstore.d.ts +0 -13
  46. package/dist/src/blockstore/persistent-blockstore.d.ts +0 -12
  47. package/dist/src/cid-set.d.ts +0 -14
  48. package/dist/src/collection.d.ts +0 -22
  49. package/dist/src/data-diff.d.ts +0 -34
  50. package/dist/src/error.d.ts +0 -21
  51. package/dist/src/index.d.ts +0 -7
  52. package/dist/src/logger.d.ts +0 -2
  53. package/dist/src/mst/diff.d.ts +0 -33
  54. package/dist/src/mst/index.d.ts +0 -4
  55. package/dist/src/mst/mst.d.ts +0 -106
  56. package/dist/src/mst/util.d.ts +0 -9
  57. package/dist/src/mst/walker.d.ts +0 -22
  58. package/dist/src/parse.d.ts +0 -11
  59. package/dist/src/readable-repo.d.ts +0 -25
  60. package/dist/src/repo.d.ts +0 -39
  61. package/dist/src/storage/error.d.ts +0 -22
  62. package/dist/src/storage/index.d.ts +0 -1
  63. package/dist/src/storage/memory-blobstore.d.ts +0 -1
  64. package/dist/src/storage/memory-blockstore.d.ts +0 -28
  65. package/dist/src/storage/readable-blockstore.d.ts +0 -21
  66. package/dist/src/storage/repo-storage.d.ts +0 -18
  67. package/dist/src/storage/sync-storage.d.ts +0 -15
  68. package/dist/src/storage/types.d.ts +0 -12
  69. package/dist/src/storage/util.d.ts +0 -17
  70. package/dist/src/structure.d.ts +0 -39
  71. package/dist/src/sync/consumer.d.ts +0 -19
  72. package/dist/src/sync/index.d.ts +0 -2
  73. package/dist/src/sync/producer.d.ts +0 -13
  74. package/dist/src/sync/provider.d.ts +0 -11
  75. package/dist/src/sync.d.ts +0 -9
  76. package/dist/src/types.d.ts +0 -368
  77. package/dist/src/util.d.ts +0 -13
  78. package/dist/src/verify.d.ts +0 -5
  79. package/dist/storage/repo-storage.d.ts +0 -19
  80. package/dist/tsconfig.build.tsbuildinfo +0 -1
  81. package/dist/verify.d.ts +0 -32
  82. package/src/storage/repo-storage.ts +0 -43
  83. package/src/verify.ts +0 -268
  84. package/tests/rebase.test.ts +0 -37
  85. package/tests/sync/checkout.test.ts +0 -75
  86. package/tests/sync/diff.test.ts +0 -92
  87. package/tsconfig.build.tsbuildinfo +0 -1
  88. package/update-pkg.js +0 -14
package/tests/_util.ts CHANGED
@@ -7,15 +7,15 @@ import { RepoStorage } from '../src/storage'
7
7
  import { MST } from '../src/mst'
8
8
  import {
9
9
  BlockMap,
10
- collapseWriteLog,
11
10
  CollectionContents,
12
11
  RecordWriteOp,
13
12
  RepoContents,
14
13
  RecordPath,
15
- WriteLog,
16
14
  WriteOpAction,
17
15
  RecordClaim,
18
16
  Commit,
17
+ DataDiff,
18
+ CommitData,
19
19
  } from '../src'
20
20
  import { Keypair, randomBytes } from '@atproto/crypto'
21
21
 
@@ -109,7 +109,7 @@ export const fillRepo = async (
109
109
  }
110
110
  }
111
111
 
112
- export const editRepo = async (
112
+ export const formatEdit = async (
113
113
  repo: Repo,
114
114
  prevData: RepoContents,
115
115
  keypair: crypto.Keypair,
@@ -118,91 +118,58 @@ export const editRepo = async (
118
118
  updates?: number
119
119
  deletes?: number
120
120
  },
121
- ): Promise<{ repo: Repo; data: RepoContents }> => {
121
+ ): Promise<{ commit: CommitData; data: RepoContents }> => {
122
122
  const { adds = 0, updates = 0, deletes = 0 } = params
123
123
  const repoData: RepoContents = {}
124
+ const writes: RecordWriteOp[] = []
124
125
  for (const collName of testCollections) {
125
- const collData = prevData[collName]
126
+ const collData = { ...(prevData[collName] ?? {}) }
126
127
  const shuffled = shuffle(Object.entries(collData))
127
128
 
128
129
  for (let i = 0; i < adds; i++) {
129
130
  const object = generateObject()
130
131
  const rkey = TID.nextStr()
131
132
  collData[rkey] = object
132
- repo = await repo.applyWrites(
133
- {
134
- action: WriteOpAction.Create,
135
- collection: collName,
136
- rkey,
137
- record: object,
138
- },
139
- keypair,
140
- )
133
+ writes.push({
134
+ action: WriteOpAction.Create,
135
+ collection: collName,
136
+ rkey,
137
+ record: object,
138
+ })
141
139
  }
142
140
 
143
141
  const toUpdate = shuffled.slice(0, updates)
144
142
  for (let i = 0; i < toUpdate.length; i++) {
145
143
  const object = generateObject()
146
144
  const rkey = toUpdate[i][0]
147
- repo = await repo.applyWrites(
148
- {
149
- action: WriteOpAction.Update,
150
- collection: collName,
151
- rkey,
152
- record: object,
153
- },
154
- keypair,
155
- )
156
145
  collData[rkey] = object
146
+ writes.push({
147
+ action: WriteOpAction.Update,
148
+ collection: collName,
149
+ rkey,
150
+ record: object,
151
+ })
157
152
  }
158
153
 
159
154
  const toDelete = shuffled.slice(updates, deletes)
160
155
  for (let i = 0; i < toDelete.length; i++) {
161
156
  const rkey = toDelete[i][0]
162
- repo = await repo.applyWrites(
163
- {
164
- action: WriteOpAction.Delete,
165
- collection: collName,
166
- rkey,
167
- },
168
- keypair,
169
- )
170
157
  delete collData[rkey]
158
+ writes.push({
159
+ action: WriteOpAction.Delete,
160
+ collection: collName,
161
+ rkey,
162
+ })
171
163
  }
172
164
  repoData[collName] = collData
173
165
  }
166
+ const commit = await repo.formatCommit(writes, keypair)
174
167
  return {
175
- repo,
168
+ commit,
176
169
  data: repoData,
177
170
  }
178
171
  }
179
172
 
180
- export const verifyRepoDiff = async (
181
- writeLog: WriteLog,
182
- before: RepoContents,
183
- after: RepoContents,
184
- ): Promise<void> => {
185
- const getVal = (op: RecordWriteOp, data: RepoContents) => {
186
- return (data[op.collection] || {})[op.rkey]
187
- }
188
- const ops = await collapseWriteLog(writeLog)
189
-
190
- for (const op of ops) {
191
- if (op.action === WriteOpAction.Create) {
192
- expect(getVal(op, before)).toBeUndefined()
193
- expect(getVal(op, after)).toEqual(op.record)
194
- } else if (op.action === WriteOpAction.Update) {
195
- expect(getVal(op, before)).toBeDefined()
196
- expect(getVal(op, after)).toEqual(op.record)
197
- } else if (op.action === WriteOpAction.Delete) {
198
- expect(getVal(op, before)).toBeDefined()
199
- expect(getVal(op, after)).toBeUndefined()
200
- } else {
201
- throw new Error('unexpected op type')
202
- }
203
- }
204
- }
205
-
206
173
  export const contentsToClaims = (contents: RepoContents): RecordClaim[] => {
207
174
  const claims: RecordClaim[] = []
208
175
  for (const coll of Object.keys(contents)) {
@@ -233,23 +200,27 @@ export const addBadCommit = async (
233
200
  keypair: Keypair,
234
201
  ): Promise<Repo> => {
235
202
  const obj = generateObject()
236
- const blocks = new BlockMap()
237
- const cid = await blocks.add(obj)
203
+ const newBlocks = new BlockMap()
204
+ const cid = await newBlocks.add(obj)
238
205
  const updatedData = await repo.data.add(`com.example.test/${TID.next()}`, cid)
239
- const unstoredData = await updatedData.getUnstoredBlocks()
240
- blocks.addMap(unstoredData.blocks)
206
+ const dataCid = await updatedData.getPointer()
207
+ const diff = await DataDiff.of(updatedData, repo.data)
208
+ newBlocks.addMap(diff.newMstBlocks)
241
209
  // we generate a bad sig by signing some other data
210
+ const rev = TID.nextStr(repo.commit.rev)
242
211
  const commit: Commit = {
243
212
  ...repo.commit,
244
- prev: repo.cid,
245
- data: unstoredData.root,
213
+ rev,
214
+ data: dataCid,
246
215
  sig: await keypair.sign(randomBytes(256)),
247
216
  }
248
- const commitCid = await blocks.add(commit)
217
+ const commitCid = await newBlocks.add(commit)
249
218
  await repo.storage.applyCommit({
250
- commit: commitCid,
219
+ cid: commitCid,
220
+ rev,
251
221
  prev: repo.cid,
252
- blocks: blocks,
222
+ newBlocks,
223
+ removedCids: diff.removedCids,
253
224
  })
254
225
  return await Repo.load(repo.storage, commitCid)
255
226
  }
package/tests/mst.test.ts CHANGED
@@ -150,7 +150,10 @@ describe('Merkle Search Tree', () => {
150
150
  } else {
151
151
  cid = entry.value
152
152
  }
153
- const found = (await blockstore.has(cid)) || diff.newCids.has(cid)
153
+ const found =
154
+ (await blockstore.has(cid)) ||
155
+ diff.newMstBlocks.has(cid) ||
156
+ diff.newLeafCids.has(cid)
154
157
  expect(found).toBeTruthy()
155
158
  }
156
159
  })
@@ -1,13 +1,12 @@
1
1
  import { TID, streamToBuffer } from '@atproto/common'
2
2
  import * as crypto from '@atproto/crypto'
3
- import { RecordClaim, Repo, RepoContents } from '../../src'
4
- import { MemoryBlockstore } from '../../src/storage'
5
- import * as verify from '../../src/verify'
6
- import * as sync from '../../src/sync'
3
+ import { RecordClaim, Repo, RepoContents } from '../src'
4
+ import { MemoryBlockstore } from '../src/storage'
5
+ import * as sync from '../src/sync'
7
6
 
8
- import * as util from '../_util'
7
+ import * as util from './_util'
9
8
 
10
- describe('Narrow Sync', () => {
9
+ describe('Repo Proofs', () => {
11
10
  let storage: MemoryBlockstore
12
11
  let repo: Repo
13
12
  let keypair: crypto.Keypair
@@ -29,7 +28,7 @@ describe('Narrow Sync', () => {
29
28
  }
30
29
 
31
30
  const doVerify = (proofs: Uint8Array, claims: RecordClaim[]) => {
32
- return verify.verifyProofs(proofs, claims, repoDid, keypair.did())
31
+ return sync.verifyProofs(proofs, claims, repoDid, keypair.did())
33
32
  }
34
33
 
35
34
  it('verifies valid records', async () => {
@@ -112,7 +111,7 @@ describe('Narrow Sync', () => {
112
111
  possible[8],
113
112
  ]
114
113
  const proofs = await getProofs(claims)
115
- const records = await verify.verifyRecords(proofs, repoDid, keypair.did())
114
+ const records = await sync.verifyRecords(proofs, repoDid, keypair.did())
116
115
  for (const record of records) {
117
116
  const foundClaim = claims.find(
118
117
  (claim) =>
@@ -127,23 +126,13 @@ describe('Narrow Sync', () => {
127
126
  }
128
127
  })
129
128
 
130
- it('verifyRecords throws on a bad signature', async () => {
131
- const badRepo = await util.addBadCommit(repo, keypair)
132
- const claims = util.contentsToClaims(repoData)
133
- const proofs = await streamToBuffer(
134
- sync.getRecords(storage, badRepo.cid, claims),
135
- )
136
- const fn = verify.verifyRecords(proofs, repoDid, keypair.did())
137
- await expect(fn).rejects.toThrow(verify.RepoVerificationError)
138
- })
139
-
140
129
  it('verifyProofs throws on a bad signature', async () => {
141
130
  const badRepo = await util.addBadCommit(repo, keypair)
142
131
  const claims = util.contentsToClaims(repoData)
143
132
  const proofs = await streamToBuffer(
144
133
  sync.getRecords(storage, badRepo.cid, claims),
145
134
  )
146
- const fn = verify.verifyProofs(proofs, claims, repoDid, keypair.did())
147
- await expect(fn).rejects.toThrow(verify.RepoVerificationError)
135
+ const fn = sync.verifyProofs(proofs, claims, repoDid, keypair.did())
136
+ await expect(fn).rejects.toThrow(sync.RepoVerificationError)
148
137
  })
149
138
  })
@@ -22,7 +22,7 @@ describe('Repo', () => {
22
22
 
23
23
  it('has proper metadata', async () => {
24
24
  expect(repo.did).toEqual(keypair.did())
25
- expect(repo.version).toBe(2)
25
+ expect(repo.version).toBe(3)
26
26
  })
27
27
 
28
28
  it('does basic operations', async () => {
@@ -75,12 +75,13 @@ describe('Repo', () => {
75
75
  })
76
76
 
77
77
  it('edits and deletes content', async () => {
78
- const edited = await util.editRepo(repo, repoData, keypair, {
78
+ const edit = await util.formatEdit(repo, repoData, keypair, {
79
79
  adds: 20,
80
80
  updates: 20,
81
81
  deletes: 20,
82
82
  })
83
- repo = edited.repo
83
+ repo = await repo.applyCommit(edit.commit)
84
+ repoData = edit.data
84
85
  const contents = await repo.getContents()
85
86
  expect(contents).toEqual(repoData)
86
87
  })
@@ -100,6 +101,6 @@ describe('Repo', () => {
100
101
  const contents = await reloadedRepo.getContents()
101
102
  expect(contents).toEqual(repoData)
102
103
  expect(repo.did).toEqual(keypair.did())
103
- expect(repo.version).toBe(2)
104
+ expect(repo.version).toBe(3)
104
105
  })
105
106
  })
@@ -0,0 +1,97 @@
1
+ import * as crypto from '@atproto/crypto'
2
+ import {
3
+ CidSet,
4
+ Repo,
5
+ RepoContents,
6
+ RepoVerificationError,
7
+ readCarWithRoot,
8
+ } from '../src'
9
+ import { MemoryBlockstore } from '../src/storage'
10
+ import * as sync from '../src/sync'
11
+
12
+ import * as util from './_util'
13
+ import { streamToBuffer } from '@atproto/common'
14
+ import { CarReader } from '@ipld/car/reader'
15
+
16
+ describe('Repo Sync', () => {
17
+ let storage: MemoryBlockstore
18
+ let repo: Repo
19
+ let keypair: crypto.Keypair
20
+ let repoData: RepoContents
21
+
22
+ const repoDid = 'did:example:test'
23
+
24
+ beforeAll(async () => {
25
+ storage = new MemoryBlockstore()
26
+ keypair = await crypto.Secp256k1Keypair.create()
27
+ repo = await Repo.create(storage, repoDid, keypair)
28
+ const filled = await util.fillRepo(repo, keypair, 20)
29
+ repo = filled.repo
30
+ repoData = filled.data
31
+ })
32
+
33
+ it('sync a full repo', async () => {
34
+ const carBytes = await streamToBuffer(sync.getFullRepo(storage, repo.cid))
35
+ const car = await readCarWithRoot(carBytes)
36
+ const verified = await sync.verifyRepo(
37
+ car.blocks,
38
+ car.root,
39
+ repoDid,
40
+ keypair.did(),
41
+ )
42
+ const syncStorage = new MemoryBlockstore()
43
+ await syncStorage.applyCommit(verified.commit)
44
+ const loadedRepo = await Repo.load(syncStorage, car.root)
45
+ const contents = await loadedRepo.getContents()
46
+ expect(contents).toEqual(repoData)
47
+ const contentsFromOps: RepoContents = {}
48
+ for (const write of verified.creates) {
49
+ contentsFromOps[write.collection] ??= {}
50
+ contentsFromOps[write.collection][write.rkey] = write.record
51
+ }
52
+ expect(contentsFromOps).toEqual(repoData)
53
+ })
54
+
55
+ it('does not sync duplicate blocks', async () => {
56
+ const carBytes = await streamToBuffer(sync.getFullRepo(storage, repo.cid))
57
+ const car = await CarReader.fromBytes(carBytes)
58
+ const cids = new CidSet()
59
+ for await (const block of car.blocks()) {
60
+ if (cids.has(block.cid)) {
61
+ throw new Error(`duplicate block: :${block.cid.toString()}`)
62
+ }
63
+ cids.add(block.cid)
64
+ }
65
+ })
66
+
67
+ it('syncs a repo that is behind', async () => {
68
+ // add more to providers's repo & have consumer catch up
69
+ const edit = await util.formatEdit(repo, repoData, keypair, {
70
+ adds: 10,
71
+ updates: 10,
72
+ deletes: 10,
73
+ })
74
+ const verified = await sync.verifyDiff(
75
+ repo,
76
+ edit.commit.newBlocks,
77
+ edit.commit.cid,
78
+ repoDid,
79
+ keypair.did(),
80
+ )
81
+ await storage.applyCommit(verified.commit)
82
+ repo = await Repo.load(storage, verified.commit.cid)
83
+ const contents = await repo.getContents()
84
+ expect(contents).toEqual(edit.data)
85
+ })
86
+
87
+ it('throws on a bad signature', async () => {
88
+ const badRepo = await util.addBadCommit(repo, keypair)
89
+ const carBytes = await streamToBuffer(
90
+ sync.getFullRepo(storage, badRepo.cid),
91
+ )
92
+ const car = await readCarWithRoot(carBytes)
93
+ await expect(
94
+ sync.verifyRepo(car.blocks, car.root, repoDid, keypair.did()),
95
+ ).rejects.toThrow(RepoVerificationError)
96
+ })
97
+ })
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "exclude": ["**/*.spec.ts", "**/*.test.ts"]
4
- }
4
+ }
package/tsconfig.json CHANGED
@@ -5,11 +5,11 @@
5
5
  "outDir": "./dist", // Your outDir,
6
6
  "emitDeclarationOnly": true
7
7
  },
8
- "include": ["./src","__tests__/**/**.ts"],
8
+ "include": ["./src", "__tests__/**/**.ts"],
9
9
  "references": [
10
10
  { "path": "../common/tsconfig.build.json" },
11
11
  { "path": "../crypto/tsconfig.build.json" },
12
12
  { "path": "../identity/tsconfig.build.json" },
13
- { "path": "../nsid/tsconfig.build.json" },
13
+ { "path": "../nsid/tsconfig.build.json" }
14
14
  ]
15
- }
15
+ }
@@ -1,23 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export * from './ipld-store';
2
- export * from './memory-blockstore';
@@ -1,27 +0,0 @@
1
- import { CID } from 'multiformats/cid';
2
- import { BlockWriter } from '@ipld/car/writer';
3
- import { check } from '@atproto/common';
4
- import { BlockReader } from '@ipld/car/api';
5
- import CidSet from '../cid-set';
6
- export declare abstract class IpldStore {
7
- staged: Map<string, Uint8Array>;
8
- constructor();
9
- abstract getSavedBytes(cid: CID): Promise<Uint8Array | null>;
10
- abstract hasSavedBlock(cid: CID): Promise<boolean>;
11
- abstract saveStaged(): Promise<void>;
12
- abstract destroySaved(): Promise<void>;
13
- stageBytes(k: CID, v: Uint8Array): Promise<void>;
14
- stage(value: unknown): Promise<CID>;
15
- getBytes(cid: CID): Promise<Uint8Array>;
16
- get<T>(cid: CID, schema: check.Def<T>): Promise<T>;
17
- getUnchecked(cid: CID): Promise<unknown>;
18
- has(cid: CID): Promise<boolean>;
19
- isMissing(cid: CID): Promise<boolean>;
20
- checkMissing(cids: CidSet): Promise<CidSet>;
21
- clearStaged(): Promise<void>;
22
- destroy(): Promise<void>;
23
- addToCar(car: BlockWriter, cid: CID): Promise<void>;
24
- stageCar(buf: Uint8Array): Promise<CID>;
25
- stageCarBlocks(car: BlockReader): Promise<void>;
26
- }
27
- export default IpldStore;
@@ -1,13 +0,0 @@
1
- import { CID } from 'multiformats/cid';
2
- import IpldStore from './ipld-store';
3
- export declare class MemoryBlockstore extends IpldStore {
4
- blocks: Map<string, Uint8Array>;
5
- constructor();
6
- getSavedBytes(cid: CID): Promise<Uint8Array | null>;
7
- hasSavedBlock(cid: CID): Promise<boolean>;
8
- saveStaged(): Promise<void>;
9
- sizeInBytes(): Promise<number>;
10
- destroySaved(): Promise<void>;
11
- getContents(): Promise<Record<string, unknown>>;
12
- }
13
- export default MemoryBlockstore;
@@ -1,12 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,22 +0,0 @@
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;
@@ -1,34 +0,0 @@
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;
@@ -1,21 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
1
- export * from './blockstore';
2
- export * from './repo';
3
- export * from './mst';
4
- export * from './storage';
5
- export * from './types';
6
- export * from './verify';
7
- export * from './util';
@@ -1,2 +0,0 @@
1
- export declare const logger: import("pino").default.Logger<import("pino").default.LoggerOptions>;
2
- export default logger;
@@ -1,33 +0,0 @@
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
- };
@@ -1,4 +0,0 @@
1
- export * from './mst';
2
- export * from './diff';
3
- export * from './walker';
4
- export * as mstUtil from './util';