@atproto/repo 0.0.1

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 (54) hide show
  1. package/README.md +3 -0
  2. package/babel.config.js +1 -0
  3. package/bench/mst.bench.ts +162 -0
  4. package/bench/repo.bench.ts +39 -0
  5. package/build.js +22 -0
  6. package/dist/blockstore/index.d.ts +2 -0
  7. package/dist/blockstore/ipld-store.d.ts +27 -0
  8. package/dist/blockstore/memory-blockstore.d.ts +13 -0
  9. package/dist/cid-set.d.ts +14 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.js +17731 -0
  12. package/dist/index.js.map +7 -0
  13. package/dist/logger.d.ts +2 -0
  14. package/dist/mst/diff.d.ts +33 -0
  15. package/dist/mst/index.d.ts +4 -0
  16. package/dist/mst/mst.d.ts +106 -0
  17. package/dist/mst/util.d.ts +9 -0
  18. package/dist/mst/walker.d.ts +22 -0
  19. package/dist/repo.d.ts +39 -0
  20. package/dist/storage/index.d.ts +1 -0
  21. package/dist/storage/types.d.ts +12 -0
  22. package/dist/sync.d.ts +9 -0
  23. package/dist/types.d.ts +368 -0
  24. package/dist/util.d.ts +13 -0
  25. package/dist/verify.d.ts +5 -0
  26. package/jest.bench.config.js +7 -0
  27. package/jest.config.js +6 -0
  28. package/package.json +34 -0
  29. package/src/blockstore/index.ts +2 -0
  30. package/src/blockstore/ipld-store.ts +103 -0
  31. package/src/blockstore/memory-blockstore.ts +49 -0
  32. package/src/cid-set.ts +50 -0
  33. package/src/index.ts +7 -0
  34. package/src/logger.ts +5 -0
  35. package/src/mst/diff.ts +106 -0
  36. package/src/mst/index.ts +4 -0
  37. package/src/mst/mst.ts +796 -0
  38. package/src/mst/util.ts +122 -0
  39. package/src/mst/walker.ts +120 -0
  40. package/src/repo.ts +312 -0
  41. package/src/storage/index.ts +1 -0
  42. package/src/storage/types.ts +12 -0
  43. package/src/sync.ts +38 -0
  44. package/src/types.ts +101 -0
  45. package/src/util.ts +88 -0
  46. package/src/verify.ts +62 -0
  47. package/tests/_util.ts +254 -0
  48. package/tests/mst.test.ts +280 -0
  49. package/tests/repo.test.ts +107 -0
  50. package/tests/sync.test.ts +129 -0
  51. package/tsconfig.build.json +4 -0
  52. package/tsconfig.build.tsbuildinfo +1 -0
  53. package/tsconfig.json +14 -0
  54. package/update-pkg.js +14 -0
@@ -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;
package/dist/repo.d.ts ADDED
@@ -0,0 +1,39 @@
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';
6
+ declare type Params = {
7
+ blockstore: IpldStore;
8
+ data: DataStore;
9
+ commit: Commit;
10
+ root: RepoRoot;
11
+ meta: RepoMeta;
12
+ cid: CID;
13
+ stagedWrites: RecordWriteOp[];
14
+ };
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[];
23
+ 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>;
38
+ }
39
+ export default Repo;
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import stream from 'stream';
3
+ import { CID } from 'multiformats/cid';
4
+ export interface BlobStore {
5
+ putTemp(bytes: Uint8Array | stream.Readable): Promise<string>;
6
+ makePermanent(key: string, cid: CID): Promise<void>;
7
+ putPermanent(cid: CID, bytes: Uint8Array | stream.Readable): Promise<void>;
8
+ getBytes(cid: CID): Promise<Uint8Array>;
9
+ getStream(cid: CID): Promise<stream.Readable>;
10
+ }
11
+ export declare class BlobNotFoundError extends Error {
12
+ }
package/dist/sync.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as auth from '@atproto/auth';
2
+ import { IpldStore } from './blockstore';
3
+ import { DataDiff } from './mst';
4
+ import Repo from './repo';
5
+ export declare const loadRepoFromCar: (carBytes: Uint8Array, blockstore: IpldStore, verifier: auth.Verifier) => Promise<Repo>;
6
+ export declare const loadDiff: (repo: Repo, diffCar: Uint8Array, verifier: auth.Verifier) => Promise<{
7
+ repo: Repo;
8
+ diff: DataDiff;
9
+ }>;
@@ -0,0 +1,368 @@
1
+ import { z } from 'zod';
2
+ import { BlockWriter } from '@ipld/car/writer';
3
+ import { CID } from 'multiformats';
4
+ import { DataDiff } from './mst';
5
+ declare const repoMeta: z.ZodObject<{
6
+ did: z.ZodString;
7
+ version: z.ZodNumber;
8
+ datastore: z.ZodString;
9
+ }, "strip", z.ZodTypeAny, {
10
+ version: number;
11
+ did: string;
12
+ datastore: string;
13
+ }, {
14
+ version: number;
15
+ did: string;
16
+ datastore: string;
17
+ }>;
18
+ export declare type RepoMeta = z.infer<typeof repoMeta>;
19
+ declare const repoRoot: z.ZodObject<{
20
+ meta: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
21
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
22
+ auth_token: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
23
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ data: CID;
26
+ meta: CID;
27
+ prev: CID | null;
28
+ auth_token: CID | null;
29
+ }, {
30
+ data?: any;
31
+ meta?: any;
32
+ prev?: any;
33
+ auth_token?: any;
34
+ }>;
35
+ export declare type RepoRoot = z.infer<typeof repoRoot>;
36
+ declare const commit: z.ZodObject<{
37
+ root: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
38
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ root: CID;
41
+ sig: Uint8Array;
42
+ }, {
43
+ root?: any;
44
+ sig: Uint8Array;
45
+ }>;
46
+ export declare type Commit = z.infer<typeof commit>;
47
+ export declare const cidCreateOp: z.ZodObject<{
48
+ action: z.ZodLiteral<"create">;
49
+ collection: z.ZodString;
50
+ rkey: z.ZodString;
51
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ collection: string;
54
+ action: "create";
55
+ rkey: string;
56
+ cid: CID;
57
+ }, {
58
+ cid?: any;
59
+ collection: string;
60
+ action: "create";
61
+ rkey: string;
62
+ }>;
63
+ export declare type CidCreateOp = z.infer<typeof cidCreateOp>;
64
+ export declare const cidUpdateOp: z.ZodObject<{
65
+ action: z.ZodLiteral<"update">;
66
+ collection: z.ZodString;
67
+ rkey: z.ZodString;
68
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ collection: string;
71
+ action: "update";
72
+ rkey: string;
73
+ cid: CID;
74
+ }, {
75
+ cid?: any;
76
+ collection: string;
77
+ action: "update";
78
+ rkey: string;
79
+ }>;
80
+ export declare type CidUpdateOp = z.infer<typeof cidUpdateOp>;
81
+ export declare const deleteOp: z.ZodObject<{
82
+ action: z.ZodLiteral<"delete">;
83
+ collection: z.ZodString;
84
+ rkey: z.ZodString;
85
+ }, "strip", z.ZodTypeAny, {
86
+ collection: string;
87
+ action: "delete";
88
+ rkey: string;
89
+ }, {
90
+ collection: string;
91
+ action: "delete";
92
+ rkey: string;
93
+ }>;
94
+ export declare type DeleteOp = z.infer<typeof deleteOp>;
95
+ export declare const cidWriteOp: z.ZodUnion<[z.ZodObject<{
96
+ action: z.ZodLiteral<"create">;
97
+ collection: z.ZodString;
98
+ rkey: z.ZodString;
99
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
100
+ }, "strip", z.ZodTypeAny, {
101
+ collection: string;
102
+ action: "create";
103
+ rkey: string;
104
+ cid: CID;
105
+ }, {
106
+ cid?: any;
107
+ collection: string;
108
+ action: "create";
109
+ rkey: string;
110
+ }>, z.ZodObject<{
111
+ action: z.ZodLiteral<"update">;
112
+ collection: z.ZodString;
113
+ rkey: z.ZodString;
114
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
115
+ }, "strip", z.ZodTypeAny, {
116
+ collection: string;
117
+ action: "update";
118
+ rkey: string;
119
+ cid: CID;
120
+ }, {
121
+ cid?: any;
122
+ collection: string;
123
+ action: "update";
124
+ rkey: string;
125
+ }>, z.ZodObject<{
126
+ action: z.ZodLiteral<"delete">;
127
+ collection: z.ZodString;
128
+ rkey: z.ZodString;
129
+ }, "strip", z.ZodTypeAny, {
130
+ collection: string;
131
+ action: "delete";
132
+ rkey: string;
133
+ }, {
134
+ collection: string;
135
+ action: "delete";
136
+ rkey: string;
137
+ }>]>;
138
+ export declare type CidWriteOp = z.infer<typeof cidWriteOp>;
139
+ export declare const recordCreateOp: z.ZodObject<{
140
+ action: z.ZodLiteral<"create">;
141
+ collection: z.ZodString;
142
+ rkey: z.ZodString;
143
+ value: z.ZodAny;
144
+ }, "strip", z.ZodTypeAny, {
145
+ value?: any;
146
+ collection: string;
147
+ action: "create";
148
+ rkey: string;
149
+ }, {
150
+ value?: any;
151
+ collection: string;
152
+ action: "create";
153
+ rkey: string;
154
+ }>;
155
+ export declare type RecordCreateOp = z.infer<typeof recordCreateOp>;
156
+ export declare const recordUpdateOp: z.ZodObject<{
157
+ action: z.ZodLiteral<"update">;
158
+ collection: z.ZodString;
159
+ rkey: z.ZodString;
160
+ value: z.ZodAny;
161
+ }, "strip", z.ZodTypeAny, {
162
+ value?: any;
163
+ collection: string;
164
+ action: "update";
165
+ rkey: string;
166
+ }, {
167
+ value?: any;
168
+ collection: string;
169
+ action: "update";
170
+ rkey: string;
171
+ }>;
172
+ export declare type RecordUpdateOp = z.infer<typeof recordUpdateOp>;
173
+ export declare const recordWriteOp: z.ZodUnion<[z.ZodObject<{
174
+ action: z.ZodLiteral<"create">;
175
+ collection: z.ZodString;
176
+ rkey: z.ZodString;
177
+ value: z.ZodAny;
178
+ }, "strip", z.ZodTypeAny, {
179
+ value?: any;
180
+ collection: string;
181
+ action: "create";
182
+ rkey: string;
183
+ }, {
184
+ value?: any;
185
+ collection: string;
186
+ action: "create";
187
+ rkey: string;
188
+ }>, z.ZodObject<{
189
+ action: z.ZodLiteral<"update">;
190
+ collection: z.ZodString;
191
+ rkey: z.ZodString;
192
+ value: z.ZodAny;
193
+ }, "strip", z.ZodTypeAny, {
194
+ value?: any;
195
+ collection: string;
196
+ action: "update";
197
+ rkey: string;
198
+ }, {
199
+ value?: any;
200
+ collection: string;
201
+ action: "update";
202
+ rkey: string;
203
+ }>, z.ZodObject<{
204
+ action: z.ZodLiteral<"delete">;
205
+ collection: z.ZodString;
206
+ rkey: z.ZodString;
207
+ }, "strip", z.ZodTypeAny, {
208
+ collection: string;
209
+ action: "delete";
210
+ rkey: string;
211
+ }, {
212
+ collection: string;
213
+ action: "delete";
214
+ rkey: string;
215
+ }>]>;
216
+ export declare type RecordWriteOp = z.infer<typeof recordWriteOp>;
217
+ export declare const def: {
218
+ repoMeta: z.ZodObject<{
219
+ did: z.ZodString;
220
+ version: z.ZodNumber;
221
+ datastore: z.ZodString;
222
+ }, "strip", z.ZodTypeAny, {
223
+ version: number;
224
+ did: string;
225
+ datastore: string;
226
+ }, {
227
+ version: number;
228
+ did: string;
229
+ datastore: string;
230
+ }>;
231
+ repoRoot: z.ZodObject<{
232
+ meta: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
233
+ prev: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
234
+ auth_token: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
235
+ data: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
236
+ }, "strip", z.ZodTypeAny, {
237
+ data: CID;
238
+ meta: CID;
239
+ prev: CID | null;
240
+ auth_token: CID | null;
241
+ }, {
242
+ data?: any;
243
+ meta?: any;
244
+ prev?: any;
245
+ auth_token?: any;
246
+ }>;
247
+ commit: z.ZodObject<{
248
+ root: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
249
+ sig: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
250
+ }, "strip", z.ZodTypeAny, {
251
+ root: CID;
252
+ sig: Uint8Array;
253
+ }, {
254
+ root?: any;
255
+ sig: Uint8Array;
256
+ }>;
257
+ cidWriteOp: z.ZodUnion<[z.ZodObject<{
258
+ action: z.ZodLiteral<"create">;
259
+ collection: z.ZodString;
260
+ rkey: z.ZodString;
261
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
262
+ }, "strip", z.ZodTypeAny, {
263
+ collection: string;
264
+ action: "create";
265
+ rkey: string;
266
+ cid: CID;
267
+ }, {
268
+ cid?: any;
269
+ collection: string;
270
+ action: "create";
271
+ rkey: string;
272
+ }>, z.ZodObject<{
273
+ action: z.ZodLiteral<"update">;
274
+ collection: z.ZodString;
275
+ rkey: z.ZodString;
276
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
277
+ }, "strip", z.ZodTypeAny, {
278
+ collection: string;
279
+ action: "update";
280
+ rkey: string;
281
+ cid: CID;
282
+ }, {
283
+ cid?: any;
284
+ collection: string;
285
+ action: "update";
286
+ rkey: string;
287
+ }>, z.ZodObject<{
288
+ action: z.ZodLiteral<"delete">;
289
+ collection: z.ZodString;
290
+ rkey: z.ZodString;
291
+ }, "strip", z.ZodTypeAny, {
292
+ collection: string;
293
+ action: "delete";
294
+ rkey: string;
295
+ }, {
296
+ collection: string;
297
+ action: "delete";
298
+ rkey: string;
299
+ }>]>;
300
+ recordWriteOp: z.ZodUnion<[z.ZodObject<{
301
+ action: z.ZodLiteral<"create">;
302
+ collection: z.ZodString;
303
+ rkey: z.ZodString;
304
+ value: z.ZodAny;
305
+ }, "strip", z.ZodTypeAny, {
306
+ value?: any;
307
+ collection: string;
308
+ action: "create";
309
+ rkey: string;
310
+ }, {
311
+ value?: any;
312
+ collection: string;
313
+ action: "create";
314
+ rkey: string;
315
+ }>, z.ZodObject<{
316
+ action: z.ZodLiteral<"update">;
317
+ collection: z.ZodString;
318
+ rkey: z.ZodString;
319
+ value: z.ZodAny;
320
+ }, "strip", z.ZodTypeAny, {
321
+ value?: any;
322
+ collection: string;
323
+ action: "update";
324
+ rkey: string;
325
+ }, {
326
+ value?: any;
327
+ collection: string;
328
+ action: "update";
329
+ rkey: string;
330
+ }>, z.ZodObject<{
331
+ action: z.ZodLiteral<"delete">;
332
+ collection: z.ZodString;
333
+ rkey: z.ZodString;
334
+ }, "strip", z.ZodTypeAny, {
335
+ collection: string;
336
+ action: "delete";
337
+ rkey: string;
338
+ }, {
339
+ collection: string;
340
+ action: "delete";
341
+ rkey: string;
342
+ }>]>;
343
+ string: z.ZodString;
344
+ cid: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
345
+ strToCid: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, CID, string>;
346
+ bytes: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
347
+ strToInt: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, number, string>;
348
+ strToBool: z.ZodEffects<z.ZodString, boolean, string>;
349
+ };
350
+ export interface CarStreamable {
351
+ writeToCarStream(car: BlockWriter): Promise<void>;
352
+ }
353
+ export declare type DataValue = {
354
+ key: string;
355
+ value: CID;
356
+ };
357
+ export interface DataStore {
358
+ add(key: string, value: CID): Promise<DataStore>;
359
+ update(key: string, value: CID): Promise<DataStore>;
360
+ delete(key: string): Promise<DataStore>;
361
+ get(key: string): Promise<CID | null>;
362
+ list(count: number, after?: string, before?: string): Promise<DataValue[]>;
363
+ listWithPrefix(prefix: string, count?: number): Promise<DataValue[]>;
364
+ diff(other: DataStore): Promise<DataDiff>;
365
+ stage(): Promise<CID>;
366
+ writeToCarStream(car: BlockWriter): Promise<void>;
367
+ }
368
+ export {};
package/dist/util.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { CID } from 'multiformats/cid';
2
+ import * as auth from '@atproto/auth';
3
+ import { DataDiff } from './mst';
4
+ import { IpldStore } from './blockstore';
5
+ import { DataStore, RecordWriteOp } from './types';
6
+ export declare const ucanForOperation: (prevData: DataStore, newData: DataStore, rootDid: string, authStore: auth.AuthStore) => Promise<string>;
7
+ export declare const getCommitPath: (blockstore: IpldStore, earliest: CID | null, latest: CID) => Promise<CID[] | null>;
8
+ export declare const getWriteOpLog: (blockstore: IpldStore, earliest: CID | null, latest: CID) => Promise<RecordWriteOp[][]>;
9
+ export declare const diffToWriteOps: (blockstore: IpldStore, diff: DataDiff) => Promise<RecordWriteOp[]>;
10
+ export declare const parseRecordKey: (key: string) => {
11
+ collection: string;
12
+ rkey: string;
13
+ };
@@ -0,0 +1,5 @@
1
+ import { CID } from 'multiformats/cid';
2
+ import * as auth from '@atproto/auth';
3
+ import { IpldStore } from './blockstore';
4
+ import { DataDiff } from './mst';
5
+ export declare const verifyUpdates: (blockstore: IpldStore, earliest: CID | null, latest: CID, verifier: auth.Verifier) => Promise<DataDiff>;
@@ -0,0 +1,7 @@
1
+ const base = require('./jest.config')
2
+
3
+ module.exports = {
4
+ ...base,
5
+ testRegex: '(/bench/.*.bench)',
6
+ testTimeout: 3000000,
7
+ }
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ const base = require('../../jest.config.base.js')
2
+
3
+ module.exports = {
4
+ ...base,
5
+ displayName: 'Repo',
6
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@atproto/repo",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "license": "MIT",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "test:profile": "node --inspect ../../node_modules/.bin/jest",
9
+ "bench": "jest --config jest.bench.config.js",
10
+ "bench:profile": "node --inspect ../../node_modules/.bin/jest --config jest.bench.config.js",
11
+ "prettier": "prettier --check src/",
12
+ "prettier:fix": "prettier --write src/",
13
+ "lint": "eslint . --ext .ts,.tsx",
14
+ "lint:fix": "yarn lint --fix",
15
+ "verify": "run-p prettier lint",
16
+ "verify:fix": "yarn prettier:fix && yarn lint:fix",
17
+ "build": "node ./build.js",
18
+ "postbuild": "tsc --build tsconfig.build.json",
19
+ "update-main-to-dist": "node ./update-pkg.js --update-main-to-dist",
20
+ "update-main-to-src": "node ./update-pkg.js --update-main-to-src",
21
+ "prepublish": "npm run update-main-to-dist",
22
+ "postpublish": "npm run update-main-to-src"
23
+ },
24
+ "dependencies": {
25
+ "@atproto/auth": "*",
26
+ "@atproto/common": "*",
27
+ "@atproto/nsid": "*",
28
+ "@ipld/car": "^3.2.3",
29
+ "@ipld/dag-cbor": "^7.0.0",
30
+ "multiformats": "^9.6.4",
31
+ "uint8arrays": "3.0.0",
32
+ "zod": "^3.14.2"
33
+ }
34
+ }