@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,33 +1,4 @@
1
- import * as auth from '@atproto/auth';
2
- import { CID } from 'multiformats';
3
- import CidSet from '../cid-set';
4
- export declare class DataDiff {
5
- adds: Record<string, DataAdd>;
6
- updates: Record<string, DataUpdate>;
7
- deletes: Record<string, DataDelete>;
8
- newCids: CidSet;
9
- recordAdd(key: string, cid: CID): void;
10
- recordUpdate(key: string, prev: CID, cid: CID): void;
11
- recordDelete(key: string, cid: CID): void;
12
- recordNewCid(cid: CID): void;
13
- addDiff(diff: DataDiff): void;
14
- addList(): DataAdd[];
15
- updateList(): DataUpdate[];
16
- deleteList(): DataDelete[];
17
- newCidList(): CID[];
18
- updatedKeys(): string[];
19
- neededCapabilities(rootDid: string): auth.ucans.Capability[];
20
- }
21
- export declare type DataAdd = {
22
- key: string;
23
- cid: CID;
24
- };
25
- export declare type DataUpdate = {
26
- key: string;
27
- prev: CID;
28
- cid: CID;
29
- };
30
- export declare type DataDelete = {
31
- key: string;
32
- cid: CID;
33
- };
1
+ import { DataDiff } from '../data-diff';
2
+ import MST from './mst';
3
+ export declare const nullDiff: (tree: MST) => Promise<DataDiff>;
4
+ export declare const mstDiff: (curr: MST, prev: MST | null) => Promise<DataDiff>;
package/dist/mst/mst.d.ts CHANGED
@@ -1,74 +1,111 @@
1
1
  import z from 'zod';
2
2
  import { CID } from 'multiformats';
3
- import IpldStore from '../blockstore/ipld-store';
4
- import { DataDiff } from './diff';
5
- import { DataStore } from '../types';
3
+ import { ReadableBlockstore } from '../storage';
6
4
  import { BlockWriter } from '@ipld/car/api';
7
- export declare const nodeDataDef: z.ZodObject<{
5
+ import BlockMap from '../block-map';
6
+ import CidSet from '../cid-set';
7
+ declare const nodeData: z.ZodObject<{
8
8
  l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
9
9
  e: z.ZodArray<z.ZodObject<{
10
10
  p: z.ZodNumber;
11
- k: z.ZodString;
11
+ k: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
12
12
  v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
13
13
  t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
14
14
  }, "strip", z.ZodTypeAny, {
15
- t: CID | null;
16
15
  p: number;
17
- k: string;
16
+ k: Uint8Array;
18
17
  v: CID;
18
+ t: CID | null;
19
19
  }, {
20
- t?: any;
21
- v?: any;
22
20
  p: number;
23
- k: string;
21
+ k: Uint8Array;
22
+ v?: any;
23
+ t?: any;
24
24
  }>, "many">;
25
25
  }, "strip", z.ZodTypeAny, {
26
- l: CID | null;
27
26
  e: {
28
- t: CID | null;
29
27
  p: number;
30
- k: string;
28
+ k: Uint8Array;
31
29
  v: CID;
30
+ t: CID | null;
32
31
  }[];
32
+ l: CID | null;
33
33
  }, {
34
- l?: any;
35
34
  e: {
36
- t?: any;
37
- v?: any;
38
35
  p: number;
39
- k: string;
36
+ k: Uint8Array;
37
+ v?: any;
38
+ t?: any;
40
39
  }[];
40
+ l?: any;
41
41
  }>;
42
- export declare type NodeData = z.infer<typeof nodeDataDef>;
42
+ export declare type NodeData = z.infer<typeof nodeData>;
43
+ export declare const nodeDataDef: {
44
+ name: string;
45
+ schema: z.ZodObject<{
46
+ l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
47
+ e: z.ZodArray<z.ZodObject<{
48
+ p: z.ZodNumber;
49
+ k: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
50
+ v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
51
+ t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ p: number;
54
+ k: Uint8Array;
55
+ v: CID;
56
+ t: CID | null;
57
+ }, {
58
+ p: number;
59
+ k: Uint8Array;
60
+ v?: any;
61
+ t?: any;
62
+ }>, "many">;
63
+ }, "strip", z.ZodTypeAny, {
64
+ e: {
65
+ p: number;
66
+ k: Uint8Array;
67
+ v: CID;
68
+ t: CID | null;
69
+ }[];
70
+ l: CID | null;
71
+ }, {
72
+ e: {
73
+ p: number;
74
+ k: Uint8Array;
75
+ v?: any;
76
+ t?: any;
77
+ }[];
78
+ l?: any;
79
+ }>;
80
+ };
43
81
  export declare type NodeEntry = MST | Leaf;
44
- export declare type Fanout = 2 | 8 | 16 | 32 | 64;
45
82
  export declare type MstOpts = {
46
83
  layer: number;
47
- fanout: Fanout;
48
84
  };
49
- export declare class MST implements DataStore {
50
- blockstore: IpldStore;
51
- fanout: Fanout;
85
+ export declare class MST {
86
+ storage: ReadableBlockstore;
52
87
  entries: NodeEntry[] | null;
53
88
  layer: number | null;
54
89
  pointer: CID;
55
90
  outdatedPointer: boolean;
56
- constructor(blockstore: IpldStore, fanout: Fanout, pointer: CID, entries: NodeEntry[] | null, layer: number | null);
57
- static create(blockstore: IpldStore, entries?: NodeEntry[], opts?: Partial<MstOpts>): Promise<MST>;
58
- static fromData(blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>): Promise<MST>;
59
- static load(blockstore: IpldStore, cid: CID, opts?: Partial<MstOpts>): MST;
91
+ constructor(storage: ReadableBlockstore, pointer: CID, entries: NodeEntry[] | null, layer: number | null);
92
+ static create(storage: ReadableBlockstore, entries?: NodeEntry[], opts?: Partial<MstOpts>): Promise<MST>;
93
+ static fromData(storage: ReadableBlockstore, data: NodeData, opts?: Partial<MstOpts>): Promise<MST>;
94
+ static load(storage: ReadableBlockstore, cid: CID, opts?: Partial<MstOpts>): MST;
60
95
  newTree(entries: NodeEntry[]): Promise<MST>;
61
96
  getEntries(): Promise<NodeEntry[]>;
62
97
  getPointer(): Promise<CID>;
63
98
  getLayer(): Promise<number>;
64
99
  attemptGetLayer(): Promise<number | null>;
65
- stage(): Promise<CID>;
66
- stageRecurse(trimTop?: boolean): Promise<CID>;
100
+ getUnstoredBlocks(): Promise<{
101
+ root: CID;
102
+ blocks: BlockMap;
103
+ }>;
67
104
  add(key: string, value: CID, knownZeros?: number): Promise<MST>;
68
105
  get(key: string): Promise<CID | null>;
69
106
  update(key: string, value: CID): Promise<MST>;
70
107
  delete(key: string): Promise<MST>;
71
- diff(other: MST): Promise<DataDiff>;
108
+ deleteRecurse(key: string): Promise<MST>;
72
109
  updateEntry(index: number, entry: NodeEntry): Promise<MST>;
73
110
  removeEntry(index: number): Promise<MST>;
74
111
  append(entry: NodeEntry): Promise<MST>;
@@ -77,20 +114,25 @@ export declare class MST implements DataStore {
77
114
  slice(start?: number | undefined, end?: number | undefined): Promise<NodeEntry[]>;
78
115
  spliceIn(entry: NodeEntry, index: number): Promise<MST>;
79
116
  replaceWithSplit(index: number, left: MST | null, leaf: Leaf, right: MST | null): Promise<MST>;
117
+ trimTop(): Promise<MST>;
80
118
  splitAround(key: string): Promise<[MST | null, MST | null]>;
81
119
  appendMerge(toMerge: MST): Promise<MST>;
82
120
  createChild(): Promise<MST>;
83
121
  createParent(): Promise<MST>;
84
122
  findGtOrEqualLeafIndex(key: string): Promise<number>;
85
123
  walkLeavesFrom(key: string): AsyncIterable<Leaf>;
86
- list(count: number, after?: string, before?: string): Promise<Leaf[]>;
124
+ list(count?: number, after?: string, before?: string): Promise<Leaf[]>;
87
125
  listWithPrefix(prefix: string, count?: number): Promise<Leaf[]>;
88
126
  walk(): AsyncIterable<NodeEntry>;
89
127
  paths(): Promise<NodeEntry[][]>;
90
128
  allNodes(): Promise<NodeEntry[]>;
129
+ allCids(): Promise<CidSet>;
91
130
  leaves(): Promise<Leaf[]>;
92
131
  leafCount(): Promise<number>;
132
+ walkReachable(): AsyncIterable<NodeEntry>;
133
+ reachableLeaves(): Promise<Leaf[]>;
93
134
  writeToCarStream(car: BlockWriter): Promise<void>;
135
+ cidsForPath(key: string): Promise<CID[]>;
94
136
  isTree(): this is MST;
95
137
  isLeaf(): this is Leaf;
96
138
  equals(other: NodeEntry): Promise<boolean>;
@@ -1,9 +1,17 @@
1
1
  import { CID } from 'multiformats';
2
- import IpldStore from '../blockstore/ipld-store';
3
- import { NodeEntry, NodeData, MstOpts, Fanout } from './mst';
4
- export declare const leadingZerosOnHash: (key: string, fanout: Fanout) => Promise<number>;
5
- export declare const layerForEntries: (entries: NodeEntry[], fanout: Fanout) => Promise<number | null>;
6
- export declare const deserializeNodeData: (blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>) => Promise<NodeEntry[]>;
2
+ import { ReadableBlockstore } from '../storage';
3
+ import { NodeEntry, NodeData, MstOpts } from './mst';
4
+ export declare const leadingZerosOnHash: (key: string | Uint8Array) => Promise<number>;
5
+ export declare const layerForEntries: (entries: NodeEntry[]) => Promise<number | null>;
6
+ export declare const deserializeNodeData: (storage: ReadableBlockstore, data: NodeData, opts?: Partial<MstOpts>) => Promise<NodeEntry[]>;
7
7
  export declare const serializeNodeData: (entries: NodeEntry[]) => NodeData;
8
8
  export declare const countPrefixLen: (a: string, b: string) => number;
9
9
  export declare const cidForEntries: (entries: NodeEntry[]) => Promise<CID>;
10
+ export declare const isValidMstKey: (str: string) => boolean;
11
+ export declare const validCharsRegex: RegExp;
12
+ export declare const isValidChars: (str: string) => boolean;
13
+ export declare const ensureValidMstKey: (str: string) => void;
14
+ export declare class InvalidMstKeyError extends Error {
15
+ key: string;
16
+ constructor(key: string);
17
+ }
@@ -0,0 +1,16 @@
1
+ import { check } from '@atproto/common';
2
+ import { RepoRecord } from '@atproto/lexicon';
3
+ import { CID } from 'multiformats/cid';
4
+ import BlockMap from './block-map';
5
+ export declare const getAndParseRecord: (blocks: BlockMap, cid: CID) => Promise<{
6
+ record: RepoRecord;
7
+ bytes: Uint8Array;
8
+ }>;
9
+ export declare const getAndParseByDef: <T>(blocks: BlockMap, cid: CID, def: check.Def<T>) => Promise<{
10
+ obj: T;
11
+ bytes: Uint8Array;
12
+ }>;
13
+ export declare const parseObjByDef: <T>(bytes: Uint8Array, cid: CID, def: check.Def<T>) => {
14
+ obj: T;
15
+ bytes: Uint8Array;
16
+ };
@@ -0,0 +1,23 @@
1
+ import { CID } from 'multiformats/cid';
2
+ import { Commit, RepoContents } from './types';
3
+ import { ReadableBlockstore } from './storage';
4
+ import { MST } from './mst';
5
+ declare type Params = {
6
+ storage: ReadableBlockstore;
7
+ data: MST;
8
+ commit: Commit;
9
+ cid: CID;
10
+ };
11
+ export declare class ReadableRepo {
12
+ storage: ReadableBlockstore;
13
+ data: MST;
14
+ commit: Commit;
15
+ cid: CID;
16
+ constructor(params: Params);
17
+ static load(storage: ReadableBlockstore, commitCid: CID): Promise<ReadableRepo>;
18
+ get did(): string;
19
+ get version(): number;
20
+ getRecord(collection: string, rkey: string): Promise<unknown | null>;
21
+ getContents(): Promise<RepoContents>;
22
+ }
23
+ export default ReadableRepo;
package/dist/repo.d.ts CHANGED
@@ -1,39 +1,27 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import { BlockWriter } from '@ipld/car/writer';
3
- import { RepoRoot, Commit, DataStore, RepoMeta, RecordCreateOp, RecordWriteOp } from './types';
4
- import IpldStore from './blockstore/ipld-store';
5
- import * as auth from '@atproto/auth';
2
+ import * as crypto from '@atproto/crypto';
3
+ import { Commit, RecordCreateOp, RecordWriteOp, CommitData, RebaseData } from './types';
4
+ import { RepoStorage } from './storage';
5
+ import { MST } from './mst';
6
+ import { ReadableRepo } from './readable-repo';
6
7
  declare type Params = {
7
- blockstore: IpldStore;
8
- data: DataStore;
8
+ storage: RepoStorage;
9
+ data: MST;
9
10
  commit: Commit;
10
- root: RepoRoot;
11
- meta: RepoMeta;
12
11
  cid: CID;
13
- stagedWrites: RecordWriteOp[];
14
12
  };
15
- export declare class Repo {
16
- blockstore: IpldStore;
17
- data: DataStore;
18
- commit: Commit;
19
- root: RepoRoot;
20
- meta: RepoMeta;
21
- cid: CID;
22
- stagedWrites: RecordWriteOp[];
13
+ export declare class Repo extends ReadableRepo {
14
+ storage: RepoStorage;
23
15
  constructor(params: Params);
24
- static create(blockstore: IpldStore, did: string, authStore: auth.AuthStore, initialRecords?: RecordCreateOp[]): Promise<Repo>;
25
- static load(blockstore: IpldStore, cid: CID): Promise<Repo>;
26
- private updateRepo;
27
- get did(): string;
28
- getRecord(collection: string, rkey: string): Promise<unknown | null>;
29
- stageUpdate(write: RecordWriteOp | RecordWriteOp[]): Repo;
30
- createCommit(authStore: auth.AuthStore, performUpdate?: (prev: CID, curr: CID) => Promise<CID | null>): Promise<Repo>;
31
- revert(count: number): Promise<Repo>;
32
- getCarNoHistory(): Promise<Uint8Array>;
33
- getDiffCar(to: CID | null): Promise<Uint8Array>;
34
- getFullHistory(): Promise<Uint8Array>;
35
- private openCar;
36
- writeCheckoutToCarStream(car: BlockWriter): Promise<void>;
37
- writeCommitsToCarStream(car: BlockWriter, oldestCommit: CID | null, recentCommit: CID): Promise<void>;
16
+ static formatInitCommit(storage: RepoStorage, did: string, keypair: crypto.Keypair, initialWrites?: RecordCreateOp[]): Promise<CommitData>;
17
+ static createFromCommit(storage: RepoStorage, commit: CommitData): Promise<Repo>;
18
+ static create(storage: RepoStorage, did: string, keypair: crypto.Keypair, initialWrites?: RecordCreateOp[]): Promise<Repo>;
19
+ static load(storage: RepoStorage, cid?: CID): Promise<Repo>;
20
+ formatCommit(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<CommitData>;
21
+ applyCommit(commitData: CommitData): Promise<Repo>;
22
+ applyWrites(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<Repo>;
23
+ formatRebase(keypair: crypto.Keypair): Promise<RebaseData>;
24
+ applyRebase(rebase: RebaseData): Promise<Repo>;
25
+ rebase(keypair: crypto.Keypair): Promise<Repo>;
38
26
  }
39
27
  export default Repo;
@@ -0,0 +1,23 @@
1
+ import { CID } from 'multiformats/cid';
2
+ export declare class BlockMap {
3
+ private map;
4
+ add(value: unknown): Promise<CID>;
5
+ set(cid: CID, bytes: Uint8Array): void;
6
+ get(cid: CID): Uint8Array | undefined;
7
+ getMany(cids: CID[]): {
8
+ blocks: BlockMap;
9
+ missing: CID[];
10
+ };
11
+ has(cid: CID): boolean;
12
+ clear(): void;
13
+ forEach(cb: (bytes: Uint8Array, cid: CID) => void): void;
14
+ entries(): Entry[];
15
+ addMap(toAdd: BlockMap): void;
16
+ get size(): number;
17
+ equals(other: BlockMap): boolean;
18
+ }
19
+ declare type Entry = {
20
+ cid: CID;
21
+ bytes: Uint8Array;
22
+ };
23
+ export default BlockMap;
@@ -0,0 +1,12 @@
1
+ import level from 'level';
2
+ import { CID } from 'multiformats/cid';
3
+ import IpldStore from './ipld-store';
4
+ export declare class PersistentBlockstore extends IpldStore {
5
+ store: level.Level;
6
+ constructor(location?: string);
7
+ getBytes(cid: CID): Promise<Uint8Array>;
8
+ putBytes(cid: CID, bytes: Uint8Array): Promise<void>;
9
+ has(cid: CID): Promise<boolean>;
10
+ destroy(): Promise<void>;
11
+ }
12
+ export default PersistentBlockstore;
@@ -0,0 +1,14 @@
1
+ import { CID } from 'multiformats';
2
+ export declare class CidSet {
3
+ private set;
4
+ constructor(arr?: CID[]);
5
+ add(cid: CID): CidSet;
6
+ addSet(toMerge: CidSet): CidSet;
7
+ subtractSet(toSubtract: CidSet): CidSet;
8
+ delete(cid: CID): this;
9
+ has(cid: CID): boolean;
10
+ size(): number;
11
+ clear(): CidSet;
12
+ toList(): CID[];
13
+ }
14
+ export default CidSet;
@@ -0,0 +1,22 @@
1
+ import { NSID } from '@atproto/nsid';
2
+ import { CID } from 'multiformats/cid';
3
+ import Repo from './repo';
4
+ export declare class Collection {
5
+ repo: Repo;
6
+ nsid: NSID;
7
+ constructor(repo: Repo, nsid: NSID | string);
8
+ name(): string;
9
+ dataIdForRecord(key: string): string;
10
+ getRecord(key: string): Promise<unknown | null>;
11
+ listRecords(count?: number, after?: string, before?: string): Promise<{
12
+ key: string;
13
+ value: unknown;
14
+ }[]>;
15
+ createRecord(record: unknown, rkey?: string): Promise<{
16
+ rkey: string;
17
+ cid: CID;
18
+ }>;
19
+ updateRecord(rkey: string, record: unknown): Promise<CID>;
20
+ deleteRecord(rkey: string): Promise<void>;
21
+ }
22
+ export default Collection;
@@ -0,0 +1,34 @@
1
+ import { CID } from 'multiformats';
2
+ import CidSet from './cid-set';
3
+ import { DataStore } from './types';
4
+ export declare class DataDiff {
5
+ adds: Record<string, DataAdd>;
6
+ updates: Record<string, DataUpdate>;
7
+ deletes: Record<string, DataDelete>;
8
+ newCids: CidSet;
9
+ static of(curr: DataStore, prev: DataStore | null): Promise<DataDiff>;
10
+ recordAdd(key: string, cid: CID): void;
11
+ recordUpdate(key: string, prev: CID, cid: CID): void;
12
+ recordDelete(key: string, cid: CID): void;
13
+ recordNewCid(cid: CID): void;
14
+ addDiff(diff: DataDiff): void;
15
+ addList(): DataAdd[];
16
+ updateList(): DataUpdate[];
17
+ deleteList(): DataDelete[];
18
+ newCidList(): CID[];
19
+ updatedKeys(): string[];
20
+ }
21
+ export declare type DataAdd = {
22
+ key: string;
23
+ cid: CID;
24
+ };
25
+ export declare type DataUpdate = {
26
+ key: string;
27
+ prev: CID;
28
+ cid: CID;
29
+ };
30
+ export declare type DataDelete = {
31
+ key: string;
32
+ cid: CID;
33
+ };
34
+ export default DataDiff;
@@ -0,0 +1,21 @@
1
+ import { Def } from '@atproto/common/src/check';
2
+ import { CID } from 'multiformats/cid';
3
+ export declare class MissingBlockError extends Error {
4
+ cid: CID;
5
+ constructor(cid: CID, def?: Def<unknown>);
6
+ }
7
+ export declare class MissingBlocksError extends Error {
8
+ context: string;
9
+ cids: CID[];
10
+ constructor(context: string, cids: CID[]);
11
+ }
12
+ export declare class MissingCommitBlocksError extends Error {
13
+ commit: CID;
14
+ cids: CID[];
15
+ constructor(commit: CID, cids: CID[]);
16
+ }
17
+ export declare class UnexpectedObjectError extends Error {
18
+ cid: CID;
19
+ def: Def<unknown>;
20
+ constructor(cid: CID, def: Def<unknown>);
21
+ }
@@ -0,0 +1,7 @@
1
+ export * from './blockstore';
2
+ export * from './repo';
3
+ export * from './mst';
4
+ export * from './storage';
5
+ export * from './types';
6
+ export * from './verify';
7
+ export * from './util';
@@ -0,0 +1,2 @@
1
+ export declare const logger: import("pino").default.Logger<import("pino").default.LoggerOptions>;
2
+ export default logger;
@@ -0,0 +1,33 @@
1
+ import * as auth from '@atproto/auth';
2
+ import { CID } from 'multiformats';
3
+ import CidSet from '../cid-set';
4
+ export declare class DataDiff {
5
+ adds: Record<string, DataAdd>;
6
+ updates: Record<string, DataUpdate>;
7
+ deletes: Record<string, DataDelete>;
8
+ newCids: CidSet;
9
+ recordAdd(key: string, cid: CID): void;
10
+ recordUpdate(key: string, prev: CID, cid: CID): void;
11
+ recordDelete(key: string, cid: CID): void;
12
+ recordNewCid(cid: CID): void;
13
+ addDiff(diff: DataDiff): void;
14
+ addList(): DataAdd[];
15
+ updateList(): DataUpdate[];
16
+ deleteList(): DataDelete[];
17
+ newCidList(): CID[];
18
+ updatedKeys(): string[];
19
+ neededCapabilities(rootDid: string): auth.ucans.Capability[];
20
+ }
21
+ export declare type DataAdd = {
22
+ key: string;
23
+ cid: CID;
24
+ };
25
+ export declare type DataUpdate = {
26
+ key: string;
27
+ prev: CID;
28
+ cid: CID;
29
+ };
30
+ export declare type DataDelete = {
31
+ key: string;
32
+ cid: CID;
33
+ };
@@ -0,0 +1,4 @@
1
+ export * from './mst';
2
+ export * from './diff';
3
+ export * from './walker';
4
+ export * as mstUtil from './util';
@@ -0,0 +1,106 @@
1
+ import z from 'zod';
2
+ import { CID } from 'multiformats';
3
+ import IpldStore from '../blockstore/ipld-store';
4
+ import { DataDiff } from './diff';
5
+ import { DataStore } from '../types';
6
+ import { BlockWriter } from '@ipld/car/api';
7
+ export declare const nodeDataDef: z.ZodObject<{
8
+ l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
9
+ e: z.ZodArray<z.ZodObject<{
10
+ p: z.ZodNumber;
11
+ k: z.ZodString;
12
+ v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
13
+ t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ t: CID | null;
16
+ p: number;
17
+ k: string;
18
+ v: CID;
19
+ }, {
20
+ t?: any;
21
+ v?: any;
22
+ p: number;
23
+ k: string;
24
+ }>, "many">;
25
+ }, "strip", z.ZodTypeAny, {
26
+ l: CID | null;
27
+ e: {
28
+ t: CID | null;
29
+ p: number;
30
+ k: string;
31
+ v: CID;
32
+ }[];
33
+ }, {
34
+ l?: any;
35
+ e: {
36
+ t?: any;
37
+ v?: any;
38
+ p: number;
39
+ k: string;
40
+ }[];
41
+ }>;
42
+ export declare type NodeData = z.infer<typeof nodeDataDef>;
43
+ export declare type NodeEntry = MST | Leaf;
44
+ export declare type Fanout = 2 | 8 | 16 | 32 | 64;
45
+ export declare type MstOpts = {
46
+ layer: number;
47
+ fanout: Fanout;
48
+ };
49
+ export declare class MST implements DataStore {
50
+ blockstore: IpldStore;
51
+ fanout: Fanout;
52
+ entries: NodeEntry[] | null;
53
+ layer: number | null;
54
+ pointer: CID;
55
+ outdatedPointer: boolean;
56
+ constructor(blockstore: IpldStore, fanout: Fanout, pointer: CID, entries: NodeEntry[] | null, layer: number | null);
57
+ static create(blockstore: IpldStore, entries?: NodeEntry[], opts?: Partial<MstOpts>): Promise<MST>;
58
+ static fromData(blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>): Promise<MST>;
59
+ static load(blockstore: IpldStore, cid: CID, opts?: Partial<MstOpts>): MST;
60
+ newTree(entries: NodeEntry[]): Promise<MST>;
61
+ getEntries(): Promise<NodeEntry[]>;
62
+ getPointer(): Promise<CID>;
63
+ getLayer(): Promise<number>;
64
+ attemptGetLayer(): Promise<number | null>;
65
+ stage(): Promise<CID>;
66
+ stageRecurse(trimTop?: boolean): Promise<CID>;
67
+ add(key: string, value: CID, knownZeros?: number): Promise<MST>;
68
+ get(key: string): Promise<CID | null>;
69
+ update(key: string, value: CID): Promise<MST>;
70
+ delete(key: string): Promise<MST>;
71
+ diff(other: MST): Promise<DataDiff>;
72
+ updateEntry(index: number, entry: NodeEntry): Promise<MST>;
73
+ removeEntry(index: number): Promise<MST>;
74
+ append(entry: NodeEntry): Promise<MST>;
75
+ prepend(entry: NodeEntry): Promise<MST>;
76
+ atIndex(index: number): Promise<NodeEntry | null>;
77
+ slice(start?: number | undefined, end?: number | undefined): Promise<NodeEntry[]>;
78
+ spliceIn(entry: NodeEntry, index: number): Promise<MST>;
79
+ replaceWithSplit(index: number, left: MST | null, leaf: Leaf, right: MST | null): Promise<MST>;
80
+ splitAround(key: string): Promise<[MST | null, MST | null]>;
81
+ appendMerge(toMerge: MST): Promise<MST>;
82
+ createChild(): Promise<MST>;
83
+ createParent(): Promise<MST>;
84
+ findGtOrEqualLeafIndex(key: string): Promise<number>;
85
+ walkLeavesFrom(key: string): AsyncIterable<Leaf>;
86
+ list(count: number, after?: string, before?: string): Promise<Leaf[]>;
87
+ listWithPrefix(prefix: string, count?: number): Promise<Leaf[]>;
88
+ walk(): AsyncIterable<NodeEntry>;
89
+ paths(): Promise<NodeEntry[][]>;
90
+ allNodes(): Promise<NodeEntry[]>;
91
+ leaves(): Promise<Leaf[]>;
92
+ leafCount(): Promise<number>;
93
+ writeToCarStream(car: BlockWriter): Promise<void>;
94
+ isTree(): this is MST;
95
+ isLeaf(): this is Leaf;
96
+ equals(other: NodeEntry): Promise<boolean>;
97
+ }
98
+ export declare class Leaf {
99
+ key: string;
100
+ value: CID;
101
+ constructor(key: string, value: CID);
102
+ isTree(): this is MST;
103
+ isLeaf(): this is Leaf;
104
+ equals(entry: NodeEntry): boolean;
105
+ }
106
+ export default MST;
@@ -0,0 +1,9 @@
1
+ import { CID } from 'multiformats';
2
+ import IpldStore from '../blockstore/ipld-store';
3
+ import { NodeEntry, NodeData, MstOpts, Fanout } from './mst';
4
+ export declare const leadingZerosOnHash: (key: string, fanout: Fanout) => Promise<number>;
5
+ export declare const layerForEntries: (entries: NodeEntry[], fanout: Fanout) => Promise<number | null>;
6
+ export declare const deserializeNodeData: (blockstore: IpldStore, data: NodeData, opts?: Partial<MstOpts>) => Promise<NodeEntry[]>;
7
+ export declare const serializeNodeData: (entries: NodeEntry[]) => NodeData;
8
+ export declare const countPrefixLen: (a: string, b: string) => number;
9
+ export declare const cidForEntries: (entries: NodeEntry[]) => Promise<CID>;
@@ -0,0 +1,22 @@
1
+ import { MST, NodeEntry } from './mst';
2
+ declare type WalkerStatusDone = {
3
+ done: true;
4
+ };
5
+ declare type WalkerStatusProgress = {
6
+ done: false;
7
+ curr: NodeEntry;
8
+ walking: MST | null;
9
+ index: number;
10
+ };
11
+ declare type WalkerStatus = WalkerStatusDone | WalkerStatusProgress;
12
+ export declare class MstWalker {
13
+ root: MST;
14
+ stack: WalkerStatus[];
15
+ status: WalkerStatus;
16
+ constructor(root: MST);
17
+ layer(): number;
18
+ stepOver(): Promise<void>;
19
+ stepInto(): Promise<void>;
20
+ advance(): Promise<void>;
21
+ }
22
+ export default MstWalker;