@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +22 -17
  3. package/jest.config.cjs +0 -24
  4. package/src/block-map.ts +0 -131
  5. package/src/car.ts +0 -357
  6. package/src/cid-set.ts +0 -55
  7. package/src/data-diff.ts +0 -117
  8. package/src/error.ts +0 -43
  9. package/src/index.ts +0 -11
  10. package/src/logger.ts +0 -7
  11. package/src/mst/diff.ts +0 -114
  12. package/src/mst/index.ts +0 -4
  13. package/src/mst/mst.ts +0 -892
  14. package/src/mst/util.ts +0 -160
  15. package/src/mst/walker.ts +0 -118
  16. package/src/parse.ts +0 -44
  17. package/src/readable-repo.ts +0 -86
  18. package/src/repo.ts +0 -236
  19. package/src/storage/index.ts +0 -4
  20. package/src/storage/memory-blockstore.ts +0 -76
  21. package/src/storage/readable-blockstore.ts +0 -55
  22. package/src/storage/sync-storage.ts +0 -35
  23. package/src/storage/types.ts +0 -47
  24. package/src/sync/consumer.ts +0 -207
  25. package/src/sync/index.ts +0 -2
  26. package/src/sync/provider.ts +0 -67
  27. package/src/types.ts +0 -227
  28. package/src/util.ts +0 -146
  29. package/tests/_keys.ts +0 -156
  30. package/tests/_util.ts +0 -265
  31. package/tests/car-file-fixtures.json +0 -28
  32. package/tests/car.test.ts +0 -125
  33. package/tests/commit-data.test.ts +0 -94
  34. package/tests/commit-proof-fixtures.json +0 -118
  35. package/tests/commit-proofs.test.ts +0 -63
  36. package/tests/covering-proofs.test.ts +0 -256
  37. package/tests/mst.test.ts +0 -450
  38. package/tests/proofs.test.ts +0 -155
  39. package/tests/repo.test.ts +0 -106
  40. package/tests/sync.test.ts +0 -95
  41. package/tsconfig.build.json +0 -8
  42. package/tsconfig.build.tsbuildinfo +0 -1
  43. package/tsconfig.json +0 -7
  44. package/tsconfig.tests.json +0 -7
@@ -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
- })
@@ -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
- })
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/node.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- },
7
- "include": ["./src"],
8
- }
@@ -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
@@ -1,7 +0,0 @@
1
- {
2
- "include": [],
3
- "references": [
4
- { "path": "./tsconfig.build.json" },
5
- { "path": "./tsconfig.tests.json" },
6
- ],
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/tests.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- },
6
- "include": ["./tests"],
7
- }