@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
package/tests/repo.test.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { TID } from '@atproto/common-web'
|
|
2
|
-
import * as crypto from '@atproto/crypto'
|
|
3
|
-
import { Secp256k1Keypair } from '@atproto/crypto'
|
|
4
|
-
import { RepoContents, WriteOpAction, verifyCommitSig } from '../src/index.js'
|
|
5
|
-
import { Repo } from '../src/repo.js'
|
|
6
|
-
import { MemoryBlockstore } from '../src/storage/index.js'
|
|
7
|
-
import * as util from './_util.js'
|
|
8
|
-
|
|
9
|
-
describe('Repo', () => {
|
|
10
|
-
const collName = 'com.example.posts'
|
|
11
|
-
|
|
12
|
-
let storage: MemoryBlockstore
|
|
13
|
-
let keypair: crypto.Keypair
|
|
14
|
-
let repo: Repo
|
|
15
|
-
let repoData: RepoContents
|
|
16
|
-
|
|
17
|
-
it('creates repo', async () => {
|
|
18
|
-
storage = new MemoryBlockstore()
|
|
19
|
-
keypair = await Secp256k1Keypair.create()
|
|
20
|
-
repo = await Repo.create(storage, keypair.did(), keypair)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('has proper metadata', async () => {
|
|
24
|
-
expect(repo.did).toEqual(keypair.did())
|
|
25
|
-
expect(repo.version).toBe(3)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('does basic operations', async () => {
|
|
29
|
-
const rkey = TID.nextStr()
|
|
30
|
-
const record = util.generateObject()
|
|
31
|
-
repo = await repo.applyWrites(
|
|
32
|
-
{
|
|
33
|
-
action: WriteOpAction.Create,
|
|
34
|
-
collection: collName,
|
|
35
|
-
rkey,
|
|
36
|
-
record,
|
|
37
|
-
},
|
|
38
|
-
keypair,
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
let got = await repo.getRecord(collName, rkey)
|
|
42
|
-
expect(got).toEqual(record)
|
|
43
|
-
|
|
44
|
-
const updatedRecord = util.generateObject()
|
|
45
|
-
repo = await repo.applyWrites(
|
|
46
|
-
{
|
|
47
|
-
action: WriteOpAction.Update,
|
|
48
|
-
collection: collName,
|
|
49
|
-
rkey,
|
|
50
|
-
record: updatedRecord,
|
|
51
|
-
},
|
|
52
|
-
keypair,
|
|
53
|
-
)
|
|
54
|
-
got = await repo.getRecord(collName, rkey)
|
|
55
|
-
expect(got).toEqual(updatedRecord)
|
|
56
|
-
|
|
57
|
-
repo = await repo.applyWrites(
|
|
58
|
-
{
|
|
59
|
-
action: WriteOpAction.Delete,
|
|
60
|
-
collection: collName,
|
|
61
|
-
rkey: rkey,
|
|
62
|
-
},
|
|
63
|
-
keypair,
|
|
64
|
-
)
|
|
65
|
-
got = await repo.getRecord(collName, rkey)
|
|
66
|
-
expect(got).toBeNull()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('adds content collections', async () => {
|
|
70
|
-
const filled = await util.fillRepo(repo, keypair, 100)
|
|
71
|
-
repo = filled.repo
|
|
72
|
-
repoData = filled.data
|
|
73
|
-
const contents = await repo.getContents()
|
|
74
|
-
expect(contents).toEqual(repoData)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('edits and deletes content', async () => {
|
|
78
|
-
const edit = await util.formatEdit(repo, repoData, keypair, {
|
|
79
|
-
adds: 20,
|
|
80
|
-
updates: 20,
|
|
81
|
-
deletes: 20,
|
|
82
|
-
})
|
|
83
|
-
repo = await repo.applyCommit(edit.commit)
|
|
84
|
-
repoData = edit.data
|
|
85
|
-
const contents = await repo.getContents()
|
|
86
|
-
expect(contents).toEqual(repoData)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('has a valid signature to commit', async () => {
|
|
90
|
-
const verified = await verifyCommitSig(repo.commit, keypair.did())
|
|
91
|
-
expect(verified).toBeTruthy()
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('sets correct DID', async () => {
|
|
95
|
-
expect(repo.did).toEqual(keypair.did())
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('loads from blockstore', async () => {
|
|
99
|
-
const reloadedRepo = await Repo.load(storage, repo.cid)
|
|
100
|
-
|
|
101
|
-
const contents = await reloadedRepo.getContents()
|
|
102
|
-
expect(contents).toEqual(repoData)
|
|
103
|
-
expect(repo.did).toEqual(keypair.did())
|
|
104
|
-
expect(repo.version).toBe(3)
|
|
105
|
-
})
|
|
106
|
-
})
|
package/tests/sync.test.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import * as crypto from '@atproto/crypto'
|
|
2
|
-
import {
|
|
3
|
-
CidSet,
|
|
4
|
-
Repo,
|
|
5
|
-
RepoContents,
|
|
6
|
-
RepoVerificationError,
|
|
7
|
-
getAndParseRecord,
|
|
8
|
-
readCar,
|
|
9
|
-
readCarWithRoot,
|
|
10
|
-
} from '../src/index.js'
|
|
11
|
-
import { MemoryBlockstore } from '../src/storage/index.js'
|
|
12
|
-
import * as sync from '../src/sync/index.js'
|
|
13
|
-
import * as util from './_util.js'
|
|
14
|
-
|
|
15
|
-
describe('Repo Sync', () => {
|
|
16
|
-
let storage: MemoryBlockstore
|
|
17
|
-
let repo: Repo
|
|
18
|
-
let keypair: crypto.Keypair
|
|
19
|
-
let repoData: RepoContents
|
|
20
|
-
|
|
21
|
-
const repoDid = 'did:example:test'
|
|
22
|
-
|
|
23
|
-
beforeAll(async () => {
|
|
24
|
-
storage = new MemoryBlockstore()
|
|
25
|
-
keypair = await crypto.Secp256k1Keypair.create()
|
|
26
|
-
repo = await Repo.create(storage, repoDid, keypair)
|
|
27
|
-
const filled = await util.fillRepo(repo, keypair, 20)
|
|
28
|
-
repo = filled.repo
|
|
29
|
-
repoData = filled.data
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('sync a full repo', async () => {
|
|
33
|
-
const carBytes = await util.toBuffer(sync.getFullRepo(storage, repo.cid))
|
|
34
|
-
const car = await readCarWithRoot(carBytes)
|
|
35
|
-
const verified = await sync.verifyRepo(
|
|
36
|
-
car.blocks,
|
|
37
|
-
car.root,
|
|
38
|
-
repoDid,
|
|
39
|
-
keypair.did(),
|
|
40
|
-
)
|
|
41
|
-
const syncStorage = new MemoryBlockstore()
|
|
42
|
-
await syncStorage.applyCommit(verified.commit)
|
|
43
|
-
const loadedRepo = await Repo.load(syncStorage, car.root)
|
|
44
|
-
const contents = await loadedRepo.getContents()
|
|
45
|
-
expect(contents).toEqual(repoData)
|
|
46
|
-
const contentsFromOps: RepoContents = {}
|
|
47
|
-
for (const write of verified.creates) {
|
|
48
|
-
contentsFromOps[write.collection] ??= {}
|
|
49
|
-
const parsed = await getAndParseRecord(car.blocks, write.cid)
|
|
50
|
-
contentsFromOps[write.collection][write.rkey] = parsed.record
|
|
51
|
-
}
|
|
52
|
-
expect(contentsFromOps).toEqual(repoData)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('does not sync duplicate blocks', async () => {
|
|
56
|
-
const carBytes = await util.toBuffer(sync.getFullRepo(storage, repo.cid))
|
|
57
|
-
const car = await readCar(carBytes)
|
|
58
|
-
const cids = new CidSet()
|
|
59
|
-
car.blocks.forEach((_, cid) => {
|
|
60
|
-
if (cids.has(cid)) {
|
|
61
|
-
throw new Error(`duplicate block: :${cid.toString()}`)
|
|
62
|
-
}
|
|
63
|
-
cids.add(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 util.toBuffer(sync.getFullRepo(storage, badRepo.cid))
|
|
90
|
-
const car = await readCarWithRoot(carBytes)
|
|
91
|
-
await expect(
|
|
92
|
-
sync.verifyRepo(car.blocks, car.root, repoDid, keypair.did()),
|
|
93
|
-
).rejects.toThrow(RepoVerificationError)
|
|
94
|
-
})
|
|
95
|
-
})
|
package/tsconfig.build.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"7.0.0-dev.20260614.1","root":["./src/block-map.ts","./src/car.ts","./src/cid-set.ts","./src/data-diff.ts","./src/error.ts","./src/index.ts","./src/logger.ts","./src/parse.ts","./src/readable-repo.ts","./src/repo.ts","./src/types.ts","./src/util.ts","./src/mst/diff.ts","./src/mst/index.ts","./src/mst/mst.ts","./src/mst/util.ts","./src/mst/walker.ts","./src/storage/index.ts","./src/storage/memory-blockstore.ts","./src/storage/readable-blockstore.ts","./src/storage/sync-storage.ts","./src/storage/types.ts","./src/sync/consumer.ts","./src/sync/index.ts","./src/sync/provider.ts"]}
|
package/tsconfig.json
DELETED