@atproto/repo 0.0.1 → 0.2.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.
- package/bench/mst.bench.ts +7 -4
- package/bench/repo.bench.ts +25 -16
- package/dist/block-map.d.ts +27 -0
- package/dist/data-diff.d.ts +36 -0
- package/dist/error.d.ts +20 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +22870 -12456
- package/dist/index.js.map +4 -4
- package/dist/mst/diff.d.ts +4 -33
- package/dist/mst/mst.d.ts +73 -31
- package/dist/mst/util.d.ts +13 -5
- package/dist/parse.d.ts +16 -0
- package/dist/readable-repo.d.ts +23 -0
- package/dist/repo.d.ts +19 -31
- package/dist/src/block-map.d.ts +23 -0
- package/dist/src/blockstore/persistent-blockstore.d.ts +12 -0
- package/dist/src/cid-set.d.ts +14 -0
- package/dist/src/collection.d.ts +22 -0
- package/dist/src/data-diff.d.ts +34 -0
- package/dist/src/error.d.ts +21 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/mst/diff.d.ts +33 -0
- package/dist/src/mst/index.d.ts +4 -0
- package/dist/src/mst/mst.d.ts +106 -0
- package/dist/src/mst/util.d.ts +9 -0
- package/dist/src/mst/walker.d.ts +22 -0
- package/dist/src/parse.d.ts +11 -0
- package/dist/src/readable-repo.d.ts +25 -0
- package/dist/src/repo.d.ts +39 -0
- package/dist/src/storage/error.d.ts +22 -0
- package/dist/src/storage/index.d.ts +1 -0
- package/dist/src/storage/memory-blobstore.d.ts +1 -0
- package/dist/src/storage/memory-blockstore.d.ts +28 -0
- package/dist/src/storage/readable-blockstore.d.ts +21 -0
- package/dist/src/storage/repo-storage.d.ts +18 -0
- package/dist/src/storage/sync-storage.d.ts +15 -0
- package/dist/src/storage/types.d.ts +12 -0
- package/dist/src/storage/util.d.ts +17 -0
- package/dist/src/structure.d.ts +39 -0
- package/dist/src/sync/consumer.d.ts +19 -0
- package/dist/src/sync/index.d.ts +2 -0
- package/dist/src/sync/producer.d.ts +13 -0
- package/dist/src/sync/provider.d.ts +11 -0
- package/dist/src/types.d.ts +368 -0
- package/dist/src/util.d.ts +13 -0
- package/dist/src/verify.d.ts +5 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/memory-blockstore.d.ts +29 -0
- package/dist/storage/readable-blockstore.d.ts +24 -0
- package/dist/storage/repo-storage.d.ts +19 -0
- package/dist/storage/sync-storage.d.ts +15 -0
- package/dist/storage/types.d.ts +4 -0
- package/dist/sync/consumer.d.ts +19 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/provider.d.ts +9 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types.d.ts +137 -331
- package/dist/util.d.ts +35 -12
- package/dist/verify.d.ts +31 -4
- package/jest.bench.config.js +2 -1
- package/package.json +13 -6
- package/src/block-map.ts +103 -0
- package/src/cid-set.ts +1 -2
- package/src/data-diff.ts +117 -0
- package/src/error.ts +31 -0
- package/src/index.ts +4 -1
- package/src/mst/diff.ts +120 -90
- package/src/mst/mst.ts +179 -187
- package/src/mst/util.ts +54 -31
- package/src/parse.ts +44 -0
- package/src/readable-repo.ts +75 -0
- package/src/repo.ts +145 -244
- package/src/storage/index.ts +4 -0
- package/src/storage/memory-blockstore.ts +133 -0
- package/src/storage/readable-blockstore.ts +56 -0
- package/src/storage/repo-storage.ts +43 -0
- package/src/storage/sync-storage.ts +35 -0
- package/src/storage/types.ts +4 -0
- package/src/sync/consumer.ts +140 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/provider.ts +91 -0
- package/src/types.ts +110 -73
- package/src/util.ts +258 -56
- package/src/verify.ts +248 -42
- package/tests/_util.ts +132 -97
- package/tests/mst.test.ts +269 -122
- package/tests/rebase.test.ts +37 -0
- package/tests/repo.test.ts +48 -50
- package/tests/sync/checkout.test.ts +75 -0
- package/tests/sync/diff.test.ts +92 -0
- package/tests/sync/narrow.test.ts +149 -0
- package/tests/util.test.ts +21 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +2 -1
- package/src/blockstore/index.ts +0 -2
- package/src/blockstore/ipld-store.ts +0 -103
- package/src/blockstore/memory-blockstore.ts +0 -49
- package/src/sync.ts +0 -38
- package/tests/sync.test.ts +0 -129
- /package/dist/{blockstore → src/blockstore}/index.d.ts +0 -0
- /package/dist/{blockstore → src/blockstore}/ipld-store.d.ts +0 -0
- /package/dist/{blockstore → src/blockstore}/memory-blockstore.d.ts +0 -0
- /package/dist/{sync.d.ts → src/sync.d.ts} +0 -0
package/tests/sync.test.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import * as auth from '@atproto/auth'
|
|
2
|
-
import { TID } from '@atproto/common'
|
|
3
|
-
import { Repo, RepoRoot, verifyUpdates, ucanForOperation } from '../src'
|
|
4
|
-
import { MemoryBlockstore } from '../src/blockstore'
|
|
5
|
-
import * as sync from '../src/sync'
|
|
6
|
-
|
|
7
|
-
import * as util from './_util'
|
|
8
|
-
|
|
9
|
-
describe('Sync', () => {
|
|
10
|
-
const verifier = new auth.Verifier()
|
|
11
|
-
|
|
12
|
-
let aliceBlockstore: MemoryBlockstore, bobBlockstore: MemoryBlockstore
|
|
13
|
-
let aliceRepo: Repo
|
|
14
|
-
let aliceAuth: auth.AuthStore
|
|
15
|
-
let repoData: util.RepoData
|
|
16
|
-
|
|
17
|
-
beforeAll(async () => {
|
|
18
|
-
aliceBlockstore = new MemoryBlockstore()
|
|
19
|
-
aliceAuth = await verifier.createTempAuthStore()
|
|
20
|
-
await aliceAuth.claimFull()
|
|
21
|
-
aliceRepo = await Repo.create(
|
|
22
|
-
aliceBlockstore,
|
|
23
|
-
await aliceAuth.did(),
|
|
24
|
-
aliceAuth,
|
|
25
|
-
)
|
|
26
|
-
bobBlockstore = new MemoryBlockstore()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('syncs an empty repo', async () => {
|
|
30
|
-
const car = await aliceRepo.getFullHistory()
|
|
31
|
-
const repoBob = await sync.loadRepoFromCar(car, bobBlockstore, verifier)
|
|
32
|
-
const data = await repoBob.data.list(10)
|
|
33
|
-
expect(data.length).toBe(0)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
let bobRepo: Repo
|
|
37
|
-
|
|
38
|
-
it('syncs a repo that is starting from scratch', async () => {
|
|
39
|
-
const filled = await util.fillRepo(aliceRepo, aliceAuth, 100)
|
|
40
|
-
aliceRepo = filled.repo
|
|
41
|
-
repoData = filled.data
|
|
42
|
-
await aliceRepo.getFullHistory()
|
|
43
|
-
|
|
44
|
-
const car = await aliceRepo.getFullHistory()
|
|
45
|
-
bobRepo = await sync.loadRepoFromCar(car, bobBlockstore, verifier)
|
|
46
|
-
const diff = await verifyUpdates(bobBlockstore, null, bobRepo.cid, verifier)
|
|
47
|
-
await util.checkRepo(bobRepo, repoData)
|
|
48
|
-
await util.checkRepoDiff(diff, {}, repoData)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('syncs a repo that is behind', async () => {
|
|
52
|
-
// add more to alice's repo & have bob catch up
|
|
53
|
-
const beforeData = JSON.parse(JSON.stringify(repoData))
|
|
54
|
-
const edited = await util.editRepo(aliceRepo, repoData, aliceAuth, {
|
|
55
|
-
adds: 20,
|
|
56
|
-
updates: 20,
|
|
57
|
-
deletes: 20,
|
|
58
|
-
})
|
|
59
|
-
aliceRepo = edited.repo
|
|
60
|
-
repoData = edited.data
|
|
61
|
-
const diffCar = await aliceRepo.getDiffCar(bobRepo.cid)
|
|
62
|
-
const loaded = await sync.loadDiff(bobRepo, diffCar, verifier)
|
|
63
|
-
await util.checkRepo(loaded.repo, repoData)
|
|
64
|
-
await util.checkRepoDiff(loaded.diff, beforeData, repoData)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('throws an error on invalid UCANs', async () => {
|
|
68
|
-
const obj = util.generateObject()
|
|
69
|
-
const cid = await aliceBlockstore.stage(obj)
|
|
70
|
-
const updatedData = await aliceRepo.data.add(
|
|
71
|
-
`com.example.test/${TID.next()}`,
|
|
72
|
-
cid,
|
|
73
|
-
)
|
|
74
|
-
// we create an unrelated token for bob & try to permission alice's repo commit with it
|
|
75
|
-
const bobAuth = await verifier.createTempAuthStore()
|
|
76
|
-
const badUcan = await bobAuth.claimFull()
|
|
77
|
-
const auth_token = await aliceBlockstore.stage(auth.encodeUcan(badUcan))
|
|
78
|
-
const dataCid = await updatedData.stage()
|
|
79
|
-
const root: RepoRoot = {
|
|
80
|
-
meta: aliceRepo.root.meta,
|
|
81
|
-
prev: aliceRepo.cid,
|
|
82
|
-
auth_token,
|
|
83
|
-
data: dataCid,
|
|
84
|
-
}
|
|
85
|
-
const rootCid = await aliceBlockstore.stage(root)
|
|
86
|
-
const commit = {
|
|
87
|
-
root: rootCid,
|
|
88
|
-
sig: await aliceAuth.sign(rootCid.bytes),
|
|
89
|
-
}
|
|
90
|
-
const commitCid = await aliceBlockstore.stage(commit)
|
|
91
|
-
const badAliceRepo = await Repo.load(aliceBlockstore, commitCid)
|
|
92
|
-
const diffCar = await badAliceRepo.getDiffCar(bobRepo.cid)
|
|
93
|
-
await expect(sync.loadDiff(bobRepo, diffCar, verifier)).rejects.toThrow()
|
|
94
|
-
// await aliceBlockstore.clearStaged()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('throws on a bad signature', async () => {
|
|
98
|
-
const obj = util.generateObject()
|
|
99
|
-
const cid = await aliceBlockstore.stage(obj)
|
|
100
|
-
const updatedData = await aliceRepo.data.add(
|
|
101
|
-
`com.example.test/${TID.next()}`,
|
|
102
|
-
cid,
|
|
103
|
-
)
|
|
104
|
-
const authToken = await ucanForOperation(
|
|
105
|
-
aliceRepo.data,
|
|
106
|
-
updatedData,
|
|
107
|
-
aliceRepo.did,
|
|
108
|
-
aliceAuth,
|
|
109
|
-
)
|
|
110
|
-
const authCid = await aliceBlockstore.stage(authToken)
|
|
111
|
-
const dataCid = await updatedData.stage()
|
|
112
|
-
const root: RepoRoot = {
|
|
113
|
-
meta: aliceRepo.root.meta,
|
|
114
|
-
prev: aliceRepo.cid,
|
|
115
|
-
auth_token: authCid,
|
|
116
|
-
data: dataCid,
|
|
117
|
-
}
|
|
118
|
-
const rootCid = await aliceBlockstore.stage(root)
|
|
119
|
-
// we generated a bad sig by signing the data cid instead of root cid
|
|
120
|
-
const commit = {
|
|
121
|
-
root: rootCid,
|
|
122
|
-
sig: await aliceAuth.sign(dataCid.bytes),
|
|
123
|
-
}
|
|
124
|
-
const commitCid = await aliceBlockstore.stage(commit)
|
|
125
|
-
const badAliceRepo = await Repo.load(aliceBlockstore, commitCid)
|
|
126
|
-
const diffCar = await badAliceRepo.getDiffCar(bobRepo.cid)
|
|
127
|
-
await expect(sync.loadDiff(bobRepo, diffCar, verifier)).rejects.toThrow()
|
|
128
|
-
})
|
|
129
|
-
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|