@atproto/repo 0.10.2 → 0.10.3
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 +16 -0
- package/package.json +22 -17
- package/jest.config.cjs +0 -24
- package/src/block-map.ts +0 -131
- package/src/car.ts +0 -357
- package/src/cid-set.ts +0 -55
- package/src/data-diff.ts +0 -117
- package/src/error.ts +0 -43
- package/src/index.ts +0 -11
- package/src/logger.ts +0 -7
- package/src/mst/diff.ts +0 -114
- package/src/mst/index.ts +0 -4
- package/src/mst/mst.ts +0 -892
- package/src/mst/util.ts +0 -160
- package/src/mst/walker.ts +0 -118
- package/src/parse.ts +0 -44
- package/src/readable-repo.ts +0 -86
- package/src/repo.ts +0 -236
- package/src/storage/index.ts +0 -4
- package/src/storage/memory-blockstore.ts +0 -76
- package/src/storage/readable-blockstore.ts +0 -55
- package/src/storage/sync-storage.ts +0 -35
- package/src/storage/types.ts +0 -47
- package/src/sync/consumer.ts +0 -207
- package/src/sync/index.ts +0 -2
- package/src/sync/provider.ts +0 -67
- package/src/types.ts +0 -227
- package/src/util.ts +0 -146
- package/tests/_keys.ts +0 -156
- package/tests/_util.ts +0 -265
- package/tests/car-file-fixtures.json +0 -28
- package/tests/car.test.ts +0 -125
- package/tests/commit-data.test.ts +0 -94
- package/tests/commit-proof-fixtures.json +0 -118
- package/tests/commit-proofs.test.ts +0 -63
- package/tests/covering-proofs.test.ts +0 -256
- package/tests/mst.test.ts +0 -450
- package/tests/proofs.test.ts +0 -155
- package/tests/repo.test.ts +0 -106
- package/tests/sync.test.ts +0 -95
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -7
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { parseCid } from '@atproto/lex-data'
|
|
2
|
-
import { BlockMap } from '../src/index.js'
|
|
3
|
-
import { MST } from '../src/mst/index.js'
|
|
4
|
-
import { MemoryBlockstore } from '../src/storage/index.js'
|
|
5
|
-
import * as k from './_keys.js'
|
|
6
|
-
|
|
7
|
-
// @NOTE these tests are the exact same as the tests in commit-proof-fixtures.json but in code from
|
|
8
|
-
// kept around currently because they are a bit easier to understand/work with
|
|
9
|
-
// we should delete in the future once the fixtures are pulled into our test suite
|
|
10
|
-
|
|
11
|
-
describe('covering proofs', () => {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* * *
|
|
15
|
-
* _________|________ ____|____
|
|
16
|
-
* | | | | | | | |
|
|
17
|
-
* * b __*__ f * -> __*__ d __*__
|
|
18
|
-
* | | | | | | | | | |
|
|
19
|
-
* a c e g * b * * f *
|
|
20
|
-
* | | | |
|
|
21
|
-
* a c e g
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
it('two deep split ', async () => {
|
|
27
|
-
const storage = new MemoryBlockstore()
|
|
28
|
-
const cid = parseCid(
|
|
29
|
-
'bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454',
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
let mst = await MST.create(storage)
|
|
33
|
-
mst = await mst.add(k.A0, cid)
|
|
34
|
-
mst = await mst.add(k.B1, cid)
|
|
35
|
-
mst = await mst.add(k.C0, cid)
|
|
36
|
-
mst = await mst.add(k.E0, cid)
|
|
37
|
-
mst = await mst.add(k.F1, cid)
|
|
38
|
-
mst = await mst.add(k.G0, cid)
|
|
39
|
-
|
|
40
|
-
const rootBeforeCommit = await mst.getPointer()
|
|
41
|
-
|
|
42
|
-
mst = await mst.add(k.D2, cid)
|
|
43
|
-
const proof = await mst.getCoveringProof(k.D2)
|
|
44
|
-
|
|
45
|
-
const proofStorage = new MemoryBlockstore(proof)
|
|
46
|
-
let proofMst = await MST.load(proofStorage, await mst.getPointer())
|
|
47
|
-
proofMst = await proofMst.delete(k.D2)
|
|
48
|
-
const rootAfterInvert = await proofMst.getPointer()
|
|
49
|
-
expect(rootAfterInvert.equals(rootBeforeCommit)).toBe(true)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* * *
|
|
55
|
-
* _____|_____ ____|____
|
|
56
|
-
* | | | | | | |
|
|
57
|
-
* a b d e -> * c *
|
|
58
|
-
* | |
|
|
59
|
-
* __*__ __*__
|
|
60
|
-
* | | | |
|
|
61
|
-
* a b d e
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*/
|
|
66
|
-
it('two deep leafless splits ', async () => {
|
|
67
|
-
const storage = new MemoryBlockstore()
|
|
68
|
-
const cid = parseCid(
|
|
69
|
-
'bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454',
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
let mst = await MST.create(storage)
|
|
73
|
-
mst = await mst.add(k.A0, cid)
|
|
74
|
-
mst = await mst.add(k.B0, cid)
|
|
75
|
-
mst = await mst.add(k.D0, cid)
|
|
76
|
-
mst = await mst.add(k.E0, cid)
|
|
77
|
-
|
|
78
|
-
const rootBeforeCommit = await mst.getPointer()
|
|
79
|
-
|
|
80
|
-
mst = await mst.add(k.C2, cid)
|
|
81
|
-
const proof = await mst.getCoveringProof(k.C2)
|
|
82
|
-
|
|
83
|
-
const proofStorage = new MemoryBlockstore(proof)
|
|
84
|
-
let proofMst = await MST.load(proofStorage, await mst.getPointer())
|
|
85
|
-
proofMst = await proofMst.delete(k.C2)
|
|
86
|
-
const rootAfterInvert = await proofMst.getPointer()
|
|
87
|
-
expect(rootAfterInvert.equals(rootBeforeCommit)).toBe(true)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* * *
|
|
93
|
-
* ____|____ ____|____
|
|
94
|
-
* | b | | | | |
|
|
95
|
-
* * * -> * b * d
|
|
96
|
-
* | | | |
|
|
97
|
-
* a c a c
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*/
|
|
104
|
-
it('add on edge with neighbor two layers down', async () => {
|
|
105
|
-
const storage = new MemoryBlockstore()
|
|
106
|
-
const cid = parseCid(
|
|
107
|
-
'bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454',
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
let mst = await MST.create(storage)
|
|
111
|
-
mst = await mst.add(k.A0, cid)
|
|
112
|
-
mst = await mst.add(k.B2, cid)
|
|
113
|
-
mst = await mst.add(k.C0, cid)
|
|
114
|
-
|
|
115
|
-
const rootBeforeCommit = await mst.getPointer()
|
|
116
|
-
|
|
117
|
-
mst = await mst.add(k.D2, cid)
|
|
118
|
-
const proof = await mst.getCoveringProof(k.D2)
|
|
119
|
-
|
|
120
|
-
const proofStorage = new MemoryBlockstore(proof)
|
|
121
|
-
let proofMst = await MST.load(proofStorage, await mst.getPointer())
|
|
122
|
-
proofMst = await proofMst.delete(k.D2)
|
|
123
|
-
const rootAfterInvert = await proofMst.getPointer()
|
|
124
|
-
expect(rootAfterInvert.equals(rootBeforeCommit)).toBe(true)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
*
|
|
129
|
-
* * *
|
|
130
|
-
* _____|_____ _____|_____
|
|
131
|
-
* | | | | | | |
|
|
132
|
-
* * b d * -> * c *
|
|
133
|
-
* | | | |
|
|
134
|
-
* a e a e
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
it('merge and split in multi op commit', async () => {
|
|
142
|
-
const storage = new MemoryBlockstore()
|
|
143
|
-
const cid = parseCid(
|
|
144
|
-
'bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454',
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
let mst = await MST.create(storage)
|
|
148
|
-
mst = await mst.add(k.A0, cid)
|
|
149
|
-
mst = await mst.add(k.B2, cid)
|
|
150
|
-
mst = await mst.add(k.D2, cid)
|
|
151
|
-
mst = await mst.add(k.E0, cid)
|
|
152
|
-
|
|
153
|
-
const rootBeforeCommit = await mst.getPointer()
|
|
154
|
-
|
|
155
|
-
mst = await mst.delete(k.B2)
|
|
156
|
-
mst = await mst.delete(k.D2)
|
|
157
|
-
mst = await mst.add(k.C2, cid)
|
|
158
|
-
|
|
159
|
-
const proofs = await Promise.all([
|
|
160
|
-
mst.getCoveringProof(k.B2),
|
|
161
|
-
mst.getCoveringProof(k.D2),
|
|
162
|
-
mst.getCoveringProof(k.C2),
|
|
163
|
-
])
|
|
164
|
-
const proof = proofs.reduce((acc, cur) => acc.addMap(cur), new BlockMap())
|
|
165
|
-
const proofStorage = new MemoryBlockstore(proof)
|
|
166
|
-
|
|
167
|
-
const addB = async (mst: MST) => mst.add(k.B2, cid)
|
|
168
|
-
const addD = async (mst: MST) => mst.add(k.D2, cid)
|
|
169
|
-
const delC = async (mst: MST) => mst.delete(k.C2)
|
|
170
|
-
|
|
171
|
-
const testOrder = async (fns: ((mst: MST) => Promise<MST>)[]) => {
|
|
172
|
-
let proofMst = await MST.load(proofStorage, await mst.getPointer())
|
|
173
|
-
for (const fn of fns) {
|
|
174
|
-
proofMst = await fn(proofMst)
|
|
175
|
-
}
|
|
176
|
-
const rootAfterInvert = await proofMst.getPointer()
|
|
177
|
-
expect(rootAfterInvert.equals(rootBeforeCommit)).toBe(true)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// test that the operations work in any order
|
|
181
|
-
await testOrder([addB, addD, delC])
|
|
182
|
-
await testOrder([addB, delC, addD])
|
|
183
|
-
await testOrder([addD, addB, delC])
|
|
184
|
-
await testOrder([addD, delC, addB])
|
|
185
|
-
await testOrder([delC, addB, addD])
|
|
186
|
-
await testOrder([delC, addD, addB])
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
// This complex multi op commit includes:
|
|
190
|
-
// - a two deep split
|
|
191
|
-
// - a two deep merge
|
|
192
|
-
// - an addition that requires knowledge of a leaf two deeper
|
|
193
|
-
/**
|
|
194
|
-
*
|
|
195
|
-
* * *
|
|
196
|
-
* _____|_____ ______|_______
|
|
197
|
-
* | | | | | | | | | | |
|
|
198
|
-
* * c * e * -> a * e * g *
|
|
199
|
-
* | | _|_ | | |
|
|
200
|
-
* * * | | _*_ * *
|
|
201
|
-
* b d f h | | | |
|
|
202
|
-
* b d f h
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*/
|
|
207
|
-
it('complex multi-op commit', async () => {
|
|
208
|
-
const storage = new MemoryBlockstore()
|
|
209
|
-
const cid = parseCid(
|
|
210
|
-
'bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454',
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
let mst = await MST.create(storage)
|
|
214
|
-
mst = await mst.add(k.B0, cid)
|
|
215
|
-
mst = await mst.add(k.C2, cid)
|
|
216
|
-
mst = await mst.add(k.D0, cid)
|
|
217
|
-
mst = await mst.add(k.E2, cid)
|
|
218
|
-
mst = await mst.add(k.F0, cid)
|
|
219
|
-
mst = await mst.add(k.H0, cid)
|
|
220
|
-
|
|
221
|
-
const rootBeforeCommit = await mst.getPointer()
|
|
222
|
-
|
|
223
|
-
mst = await mst.add(k.A2, cid)
|
|
224
|
-
mst = await mst.add(k.G2, cid)
|
|
225
|
-
mst = await mst.delete(k.C2)
|
|
226
|
-
|
|
227
|
-
const proofs = await Promise.all([
|
|
228
|
-
mst.getCoveringProof(k.A2),
|
|
229
|
-
mst.getCoveringProof(k.G2),
|
|
230
|
-
mst.getCoveringProof(k.C2),
|
|
231
|
-
])
|
|
232
|
-
const proof = proofs.reduce((acc, cur) => acc.addMap(cur), new BlockMap())
|
|
233
|
-
const proofStorage = new MemoryBlockstore(proof)
|
|
234
|
-
|
|
235
|
-
const delA = async (mst: MST) => mst.delete(k.A2)
|
|
236
|
-
const delG = async (mst: MST) => mst.delete(k.G2)
|
|
237
|
-
const addC = async (mst: MST) => mst.add(k.C2, cid)
|
|
238
|
-
|
|
239
|
-
const testOrder = async (fns: ((mst: MST) => Promise<MST>)[]) => {
|
|
240
|
-
let proofMst = await MST.load(proofStorage, await mst.getPointer())
|
|
241
|
-
for (const fn of fns) {
|
|
242
|
-
proofMst = await fn(proofMst)
|
|
243
|
-
}
|
|
244
|
-
const rootAfterInvert = await proofMst.getPointer()
|
|
245
|
-
expect(rootAfterInvert.equals(rootBeforeCommit)).toBe(true)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// test that the operations work in any order
|
|
249
|
-
await testOrder([delA, delG, addC])
|
|
250
|
-
await testOrder([delA, addC, delG])
|
|
251
|
-
await testOrder([delG, delA, addC])
|
|
252
|
-
await testOrder([delG, addC, delA])
|
|
253
|
-
await testOrder([addC, delA, delG])
|
|
254
|
-
await testOrder([addC, delG, delA])
|
|
255
|
-
})
|
|
256
|
-
})
|