@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
package/src/data-diff.ts DELETED
@@ -1,117 +0,0 @@
1
- import { Cid } from '@atproto/lex-data'
2
- import { BlockMap } from './block-map.js'
3
- import { CidSet } from './cid-set.js'
4
- import { MST, NodeEntry, mstDiff } from './mst/index.js'
5
-
6
- export class DataDiff {
7
- adds: Record<string, DataAdd> = {}
8
- updates: Record<string, DataUpdate> = {}
9
- deletes: Record<string, DataDelete> = {}
10
-
11
- newMstBlocks: BlockMap = new BlockMap()
12
- newLeafCids: CidSet = new CidSet()
13
- removedCids: CidSet = new CidSet()
14
-
15
- static async of(curr: MST, prev: MST | null): Promise<DataDiff> {
16
- return mstDiff(curr, prev)
17
- }
18
-
19
- async nodeAdd(node: NodeEntry) {
20
- if (node.isLeaf()) {
21
- this.leafAdd(node.key, node.value)
22
- } else {
23
- const data = await node.serialize()
24
- this.treeAdd(data.cid, data.bytes)
25
- }
26
- }
27
-
28
- async nodeDelete(node: NodeEntry) {
29
- if (node.isLeaf()) {
30
- const key = node.key
31
- const cid = node.value
32
- this.deletes[key] = { key, cid }
33
- this.removedCids.add(cid)
34
- } else {
35
- const cid = await node.getPointer()
36
- this.treeDelete(cid)
37
- }
38
- }
39
-
40
- leafAdd(key: string, cid: Cid) {
41
- this.adds[key] = { key, cid }
42
- if (this.removedCids.has(cid)) {
43
- this.removedCids.delete(cid)
44
- } else {
45
- this.newLeafCids.add(cid)
46
- }
47
- }
48
-
49
- leafUpdate(key: string, prev: Cid, cid: Cid) {
50
- if (prev.equals(cid)) return
51
- this.updates[key] = { key, prev, cid }
52
- this.removedCids.add(prev)
53
- this.newLeafCids.add(cid)
54
- }
55
-
56
- leafDelete(key: string, cid: Cid) {
57
- this.deletes[key] = { key, cid }
58
- if (this.newLeafCids.has(cid)) {
59
- this.newLeafCids.delete(cid)
60
- } else {
61
- this.removedCids.add(cid)
62
- }
63
- }
64
-
65
- treeAdd(cid: Cid, bytes: Uint8Array) {
66
- if (this.removedCids.has(cid)) {
67
- this.removedCids.delete(cid)
68
- } else {
69
- this.newMstBlocks.set(cid, bytes)
70
- }
71
- }
72
-
73
- treeDelete(cid: Cid) {
74
- if (this.newMstBlocks.has(cid)) {
75
- this.newMstBlocks.delete(cid)
76
- } else {
77
- this.removedCids.add(cid)
78
- }
79
- }
80
-
81
- addList(): DataAdd[] {
82
- return Object.values(this.adds)
83
- }
84
-
85
- updateList(): DataUpdate[] {
86
- return Object.values(this.updates)
87
- }
88
-
89
- deleteList(): DataDelete[] {
90
- return Object.values(this.deletes)
91
- }
92
-
93
- updatedKeys(): string[] {
94
- const keys = [
95
- ...Object.keys(this.adds),
96
- ...Object.keys(this.updates),
97
- ...Object.keys(this.deletes),
98
- ]
99
- return [...new Set(keys)]
100
- }
101
- }
102
-
103
- export type DataAdd = {
104
- key: string
105
- cid: Cid
106
- }
107
-
108
- export type DataUpdate = {
109
- key: string
110
- prev: Cid
111
- cid: Cid
112
- }
113
-
114
- export type DataDelete = {
115
- key: string
116
- cid: Cid
117
- }
package/src/error.ts DELETED
@@ -1,43 +0,0 @@
1
- import { Cid } from '@atproto/lex-data'
2
-
3
- export class MissingBlockError extends Error {
4
- constructor(
5
- public cid: Cid,
6
- def?: string,
7
- ) {
8
- let msg = `block not found: ${cid.toString()}`
9
- if (def) {
10
- msg += `, expected type: ${def}`
11
- }
12
- super(msg)
13
- }
14
- }
15
-
16
- export class MissingBlocksError extends Error {
17
- constructor(
18
- public context: string,
19
- public cids: Cid[],
20
- ) {
21
- const cidStr = cids.map((c) => c.toString())
22
- super(`missing ${context} blocks: ${cidStr}`)
23
- }
24
- }
25
-
26
- export class MissingCommitBlocksError extends Error {
27
- constructor(
28
- public commit: Cid,
29
- public cids: Cid[],
30
- ) {
31
- const cidStr = cids.map((c) => c.toString())
32
- super(`missing blocks for commit ${commit.toString()}: ${cidStr}`)
33
- }
34
- }
35
-
36
- export class UnexpectedObjectError extends Error {
37
- constructor(
38
- public cid: Cid,
39
- public def: string,
40
- ) {
41
- super(`unexpected object at ${cid.toString()}, expected: ${def}`)
42
- }
43
- }
package/src/index.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from './block-map.js'
2
- export * from './cid-set.js'
3
- export * from './repo.js'
4
- export * from './mst/index.js'
5
- export * from './parse.js'
6
- export * from './storage/index.js'
7
- export * from './sync/index.js'
8
- export * from './types.js'
9
- export * from './data-diff.js'
10
- export * from './car.js'
11
- export * from './util.js'
package/src/logger.ts DELETED
@@ -1,7 +0,0 @@
1
- // @TODO remove dependency on @atproto/common and subsystemLogger
2
- import { subsystemLogger } from '@atproto/common'
3
-
4
- export const logger: ReturnType<typeof subsystemLogger> =
5
- subsystemLogger('repo')
6
-
7
- export default logger
package/src/mst/diff.ts DELETED
@@ -1,114 +0,0 @@
1
- import { DataDiff } from '../data-diff.js'
2
- import { MST } from './mst.js'
3
- import { MstWalker } from './walker.js'
4
-
5
- export const nullDiff = async (tree: MST): Promise<DataDiff> => {
6
- const diff = new DataDiff()
7
- for await (const entry of tree.walk()) {
8
- await diff.nodeAdd(entry)
9
- }
10
- return diff
11
- }
12
-
13
- export const mstDiff = async (
14
- curr: MST,
15
- prev: MST | null,
16
- ): Promise<DataDiff> => {
17
- await curr.getPointer()
18
- if (prev === null) {
19
- return nullDiff(curr)
20
- }
21
-
22
- await prev.getPointer()
23
- const diff = new DataDiff()
24
-
25
- const leftWalker = new MstWalker(prev)
26
- const rightWalker = new MstWalker(curr)
27
- while (!leftWalker.status.done || !rightWalker.status.done) {
28
- // if one walker is finished, continue walking the other & logging all nodes
29
- if (leftWalker.status.done && !rightWalker.status.done) {
30
- await diff.nodeAdd(rightWalker.status.curr)
31
- await rightWalker.advance()
32
- continue
33
- } else if (!leftWalker.status.done && rightWalker.status.done) {
34
- await diff.nodeDelete(leftWalker.status.curr)
35
- await leftWalker.advance()
36
- continue
37
- }
38
- if (leftWalker.status.done || rightWalker.status.done) break
39
- const left = leftWalker.status.curr
40
- const right = rightWalker.status.curr
41
- if (left === null || right === null) break
42
-
43
- // if both pointers are leaves, record an update & advance both or record the lowest key and advance that pointer
44
- if (left.isLeaf() && right.isLeaf()) {
45
- if (left.key === right.key) {
46
- if (!left.value.equals(right.value)) {
47
- diff.leafUpdate(left.key, left.value, right.value)
48
- }
49
- await leftWalker.advance()
50
- await rightWalker.advance()
51
- } else if (left.key < right.key) {
52
- diff.leafDelete(left.key, left.value)
53
- await leftWalker.advance()
54
- } else {
55
- diff.leafAdd(right.key, right.value)
56
- await rightWalker.advance()
57
- }
58
- continue
59
- }
60
-
61
- // next, ensure that we're on the same layer
62
- // if one walker is at a higher layer than the other, we need to do one of two things
63
- // if the higher walker is pointed at a tree, step into that tree to try to catch up with the lower
64
- // if the higher walker is pointed at a leaf, then advance the lower walker to try to catch up the higher
65
- if (leftWalker.layer() > rightWalker.layer()) {
66
- if (left.isLeaf()) {
67
- await diff.nodeAdd(right)
68
- await rightWalker.advance()
69
- } else {
70
- await diff.nodeDelete(left)
71
- await leftWalker.stepInto()
72
- }
73
- continue
74
- } else if (leftWalker.layer() < rightWalker.layer()) {
75
- if (right.isLeaf()) {
76
- await diff.nodeDelete(left)
77
- await leftWalker.advance()
78
- } else {
79
- await diff.nodeAdd(right)
80
- await rightWalker.stepInto()
81
- }
82
- continue
83
- }
84
-
85
- // if we're on the same level, and both pointers are trees, do a comparison
86
- // if they're the same, step over. if they're different, step in to find the subdiff
87
- if (left.isTree() && right.isTree()) {
88
- if (left.pointer.equals(right.pointer)) {
89
- await leftWalker.stepOver()
90
- await rightWalker.stepOver()
91
- } else {
92
- await diff.nodeAdd(right)
93
- await diff.nodeDelete(left)
94
- await leftWalker.stepInto()
95
- await rightWalker.stepInto()
96
- }
97
- continue
98
- }
99
-
100
- // finally, if one pointer is a tree and the other is a leaf, simply step into the tree
101
- if (left.isLeaf() && right.isTree()) {
102
- await diff.nodeAdd(right)
103
- await rightWalker.stepInto()
104
- continue
105
- } else if (left.isTree() && right.isLeaf()) {
106
- await diff.nodeDelete(left)
107
- await leftWalker.stepInto()
108
- continue
109
- }
110
-
111
- throw new Error('Unidentifiable case in diff walk')
112
- }
113
- return diff
114
- }
package/src/mst/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './mst.js'
2
- export * from './diff.js'
3
- export * from './walker.js'
4
- export * as mstUtil from './util.js'