@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
@@ -24,14 +24,14 @@ describe('MST Benchmarks', () => {
24
24
  const size = 500000
25
25
 
26
26
  beforeAll(async () => {
27
- mapping = await util.generateBulkTidMapping(size)
27
+ mapping = await util.generateBulkDataKeys(size)
28
28
  shuffled = util.shuffle(Object.entries(mapping))
29
29
  })
30
30
 
31
31
  // const fanouts: Fanout[] = [8, 16, 32]
32
32
  const fanouts: Fanout[] = [16, 32]
33
33
  it('benchmarks various fanouts', async () => {
34
- let benches: BenchmarkData[] = []
34
+ const benches: BenchmarkData[] = []
35
35
  for (const fanout of fanouts) {
36
36
  const blockstore = new MemoryBlockstore()
37
37
  let mst = await MST.create(blockstore, [], { fanout })
@@ -44,11 +44,11 @@ describe('MST Benchmarks', () => {
44
44
 
45
45
  const doneAdding = Date.now()
46
46
 
47
- const root = await mst.save()
47
+ const root = await util.saveMst(blockstore, mst)
48
48
 
49
49
  const doneSaving = Date.now()
50
50
 
51
- let reloaded = await MST.load(blockstore, root, { fanout })
51
+ const reloaded = await MST.load(blockstore, root, { fanout })
52
52
  const widthTracker = new NodeWidths()
53
53
  for await (const entry of reloaded.walk()) {
54
54
  await widthTracker.trackEntry(entry)
@@ -64,6 +64,9 @@ describe('MST Benchmarks', () => {
64
64
  for (const entry of path) {
65
65
  if (entry.isTree()) {
66
66
  const bytes = await blockstore.getBytes(entry.pointer)
67
+ if (!bytes) {
68
+ throw new Error(`Bytes not found: ${entry.pointer}`)
69
+ }
67
70
  proofSize += bytes.byteLength
68
71
  }
69
72
  }
@@ -1,37 +1,46 @@
1
- import * as auth from '@atproto/auth'
2
- import { MemoryBlockstore, Repo } from '../src'
1
+ import { TID } from '@atproto/common'
2
+ import * as crypto from '@atproto/crypto'
3
+ import { Secp256k1Keypair } from '@atproto/crypto'
4
+ import { MemoryBlockstore, Repo, WriteOpAction } from '../src'
3
5
  import * as util from '../tests/_util'
4
6
 
5
7
  describe('Repo Benchmarks', () => {
6
- const verifier = new auth.Verifier()
7
8
  const size = 10000
8
9
 
9
10
  let blockstore: MemoryBlockstore
10
- let authStore: auth.AuthStore
11
+ let keypair: crypto.Keypair
11
12
  let repo: Repo
12
13
 
13
14
  beforeAll(async () => {
14
15
  blockstore = new MemoryBlockstore()
15
- authStore = await verifier.createTempAuthStore()
16
- await authStore.claimFull()
17
- repo = await Repo.create(blockstore, await authStore.did(), authStore)
16
+ keypair = await Secp256k1Keypair.create()
17
+ repo = await Repo.create(blockstore, await keypair.did(), keypair)
18
18
  })
19
19
 
20
20
  it('calculates size', async () => {
21
- const posts = repo.getCollection('app.bsky.post')
22
21
  for (let i = 0; i < size; i++) {
23
22
  if (i % 500 === 0) {
24
23
  console.log(i)
25
24
  }
26
- await posts.createRecord({
27
- $type: 'app.bsky.post',
28
- text: util.randomStr(150),
29
- reply: {
30
- root: 'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
31
- parent: 'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
25
+
26
+ await repo.applyCommit(
27
+ {
28
+ action: WriteOpAction.Create,
29
+ collection: 'app.bsky.post',
30
+ rkey: TID.nextStr(),
31
+ value: {
32
+ $type: 'app.bsky.post',
33
+ text: util.randomStr(150),
34
+ reply: {
35
+ root: 'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
36
+ parent:
37
+ 'at://did:plc:1234abdefeoi23/app.bsky.post/12345678912345',
38
+ },
39
+ createdAt: new Date().toISOString(),
40
+ },
32
41
  },
33
- createdAt: new Date().toISOString(),
34
- })
42
+ keypair,
43
+ )
35
44
  }
36
45
 
37
46
  console.log('SIZE: ', await blockstore.sizeInBytes())
@@ -0,0 +1,27 @@
1
+ import { LexValue } from '@atproto/lexicon';
2
+ import { CID } from 'multiformats/cid';
3
+ export declare class BlockMap {
4
+ private map;
5
+ add(value: LexValue): Promise<CID>;
6
+ set(cid: CID, bytes: Uint8Array): void;
7
+ get(cid: CID): Uint8Array | undefined;
8
+ delete(cid: CID): void;
9
+ getMany(cids: CID[]): {
10
+ blocks: BlockMap;
11
+ missing: CID[];
12
+ };
13
+ has(cid: CID): boolean;
14
+ clear(): void;
15
+ forEach(cb: (bytes: Uint8Array, cid: CID) => void): void;
16
+ entries(): Entry[];
17
+ cids(): CID[];
18
+ addMap(toAdd: BlockMap): void;
19
+ get size(): number;
20
+ get byteSize(): number;
21
+ equals(other: BlockMap): boolean;
22
+ }
23
+ declare type Entry = {
24
+ cid: CID;
25
+ bytes: Uint8Array;
26
+ };
27
+ export default BlockMap;
@@ -0,0 +1,36 @@
1
+ import { CID } from 'multiformats';
2
+ import CidSet from './cid-set';
3
+ import { MST } from './mst';
4
+ export declare class DataDiff {
5
+ adds: Record<string, DataAdd>;
6
+ updates: Record<string, DataUpdate>;
7
+ deletes: Record<string, DataDelete>;
8
+ newCids: CidSet;
9
+ removedCids: CidSet;
10
+ static of(curr: MST, prev: MST | null): Promise<DataDiff>;
11
+ recordAdd(key: string, cid: CID): void;
12
+ recordUpdate(key: string, prev: CID, cid: CID): void;
13
+ recordDelete(key: string, cid: CID): void;
14
+ recordNewCid(cid: CID): void;
15
+ recordRemovedCid(cid: CID): void;
16
+ addDiff(diff: DataDiff): void;
17
+ addList(): DataAdd[];
18
+ updateList(): DataUpdate[];
19
+ deleteList(): DataDelete[];
20
+ newCidList(): CID[];
21
+ updatedKeys(): string[];
22
+ }
23
+ export declare type DataAdd = {
24
+ key: string;
25
+ cid: CID;
26
+ };
27
+ export declare type DataUpdate = {
28
+ key: string;
29
+ prev: CID;
30
+ cid: CID;
31
+ };
32
+ export declare type DataDelete = {
33
+ key: string;
34
+ cid: CID;
35
+ };
36
+ export default DataDiff;
@@ -0,0 +1,20 @@
1
+ import { CID } from 'multiformats/cid';
2
+ export declare class MissingBlockError extends Error {
3
+ cid: CID;
4
+ constructor(cid: CID, def?: string);
5
+ }
6
+ export declare class MissingBlocksError extends Error {
7
+ context: string;
8
+ cids: CID[];
9
+ constructor(context: string, cids: CID[]);
10
+ }
11
+ export declare class MissingCommitBlocksError extends Error {
12
+ commit: CID;
13
+ cids: CID[];
14
+ constructor(commit: CID, cids: CID[]);
15
+ }
16
+ export declare class UnexpectedObjectError extends Error {
17
+ cid: CID;
18
+ def: string;
19
+ constructor(cid: CID, def: string);
20
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- export * from './blockstore';
1
+ export * from './block-map';
2
+ export * from './cid-set';
2
3
  export * from './repo';
3
4
  export * from './mst';
4
5
  export * from './storage';
6
+ export * from './sync';
5
7
  export * from './types';
6
8
  export * from './verify';
9
+ export * from './data-diff';
7
10
  export * from './util';