@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.
Files changed (104) hide show
  1. package/bench/mst.bench.ts +7 -4
  2. package/bench/repo.bench.ts +25 -16
  3. package/dist/block-map.d.ts +27 -0
  4. package/dist/data-diff.d.ts +36 -0
  5. package/dist/error.d.ts +20 -0
  6. package/dist/index.d.ts +4 -1
  7. package/dist/index.js +22870 -12456
  8. package/dist/index.js.map +4 -4
  9. package/dist/mst/diff.d.ts +4 -33
  10. package/dist/mst/mst.d.ts +73 -31
  11. package/dist/mst/util.d.ts +13 -5
  12. package/dist/parse.d.ts +16 -0
  13. package/dist/readable-repo.d.ts +23 -0
  14. package/dist/repo.d.ts +19 -31
  15. package/dist/src/block-map.d.ts +23 -0
  16. package/dist/src/blockstore/persistent-blockstore.d.ts +12 -0
  17. package/dist/src/cid-set.d.ts +14 -0
  18. package/dist/src/collection.d.ts +22 -0
  19. package/dist/src/data-diff.d.ts +34 -0
  20. package/dist/src/error.d.ts +21 -0
  21. package/dist/src/index.d.ts +7 -0
  22. package/dist/src/logger.d.ts +2 -0
  23. package/dist/src/mst/diff.d.ts +33 -0
  24. package/dist/src/mst/index.d.ts +4 -0
  25. package/dist/src/mst/mst.d.ts +106 -0
  26. package/dist/src/mst/util.d.ts +9 -0
  27. package/dist/src/mst/walker.d.ts +22 -0
  28. package/dist/src/parse.d.ts +11 -0
  29. package/dist/src/readable-repo.d.ts +25 -0
  30. package/dist/src/repo.d.ts +39 -0
  31. package/dist/src/storage/error.d.ts +22 -0
  32. package/dist/src/storage/index.d.ts +1 -0
  33. package/dist/src/storage/memory-blobstore.d.ts +1 -0
  34. package/dist/src/storage/memory-blockstore.d.ts +28 -0
  35. package/dist/src/storage/readable-blockstore.d.ts +21 -0
  36. package/dist/src/storage/repo-storage.d.ts +18 -0
  37. package/dist/src/storage/sync-storage.d.ts +15 -0
  38. package/dist/src/storage/types.d.ts +12 -0
  39. package/dist/src/storage/util.d.ts +17 -0
  40. package/dist/src/structure.d.ts +39 -0
  41. package/dist/src/sync/consumer.d.ts +19 -0
  42. package/dist/src/sync/index.d.ts +2 -0
  43. package/dist/src/sync/producer.d.ts +13 -0
  44. package/dist/src/sync/provider.d.ts +11 -0
  45. package/dist/src/types.d.ts +368 -0
  46. package/dist/src/util.d.ts +13 -0
  47. package/dist/src/verify.d.ts +5 -0
  48. package/dist/storage/index.d.ts +4 -0
  49. package/dist/storage/memory-blockstore.d.ts +29 -0
  50. package/dist/storage/readable-blockstore.d.ts +24 -0
  51. package/dist/storage/repo-storage.d.ts +19 -0
  52. package/dist/storage/sync-storage.d.ts +15 -0
  53. package/dist/storage/types.d.ts +4 -0
  54. package/dist/sync/consumer.d.ts +19 -0
  55. package/dist/sync/index.d.ts +2 -0
  56. package/dist/sync/provider.d.ts +9 -0
  57. package/dist/tsconfig.build.tsbuildinfo +1 -0
  58. package/dist/types.d.ts +137 -331
  59. package/dist/util.d.ts +35 -12
  60. package/dist/verify.d.ts +31 -4
  61. package/jest.bench.config.js +2 -1
  62. package/package.json +13 -6
  63. package/src/block-map.ts +103 -0
  64. package/src/cid-set.ts +1 -2
  65. package/src/data-diff.ts +117 -0
  66. package/src/error.ts +31 -0
  67. package/src/index.ts +4 -1
  68. package/src/mst/diff.ts +120 -90
  69. package/src/mst/mst.ts +179 -187
  70. package/src/mst/util.ts +54 -31
  71. package/src/parse.ts +44 -0
  72. package/src/readable-repo.ts +75 -0
  73. package/src/repo.ts +145 -244
  74. package/src/storage/index.ts +4 -0
  75. package/src/storage/memory-blockstore.ts +133 -0
  76. package/src/storage/readable-blockstore.ts +56 -0
  77. package/src/storage/repo-storage.ts +43 -0
  78. package/src/storage/sync-storage.ts +35 -0
  79. package/src/storage/types.ts +4 -0
  80. package/src/sync/consumer.ts +140 -0
  81. package/src/sync/index.ts +2 -0
  82. package/src/sync/provider.ts +91 -0
  83. package/src/types.ts +110 -73
  84. package/src/util.ts +258 -56
  85. package/src/verify.ts +248 -42
  86. package/tests/_util.ts +132 -97
  87. package/tests/mst.test.ts +269 -122
  88. package/tests/rebase.test.ts +37 -0
  89. package/tests/repo.test.ts +48 -50
  90. package/tests/sync/checkout.test.ts +75 -0
  91. package/tests/sync/diff.test.ts +92 -0
  92. package/tests/sync/narrow.test.ts +149 -0
  93. package/tests/util.test.ts +21 -0
  94. package/tsconfig.build.tsbuildinfo +1 -1
  95. package/tsconfig.json +2 -1
  96. package/src/blockstore/index.ts +0 -2
  97. package/src/blockstore/ipld-store.ts +0 -103
  98. package/src/blockstore/memory-blockstore.ts +0 -49
  99. package/src/sync.ts +0 -38
  100. package/tests/sync.test.ts +0 -129
  101. /package/dist/{blockstore → src/blockstore}/index.d.ts +0 -0
  102. /package/dist/{blockstore → src/blockstore}/ipld-store.d.ts +0 -0
  103. /package/dist/{blockstore → src/blockstore}/memory-blockstore.d.ts +0 -0
  104. /package/dist/{sync.d.ts → src/sync.d.ts} +0 -0
@@ -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