@atproto/repo 0.0.1 → 0.1.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.
- package/bench/mst.bench.ts +7 -4
- package/bench/repo.bench.ts +25 -16
- package/dist/block-map.d.ts +25 -0
- package/dist/data-diff.d.ts +36 -0
- package/dist/error.d.ts +20 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +11605 -10399
- package/dist/index.js.map +4 -4
- package/dist/mst/diff.d.ts +4 -33
- package/dist/mst/mst.d.ts +68 -25
- package/dist/mst/util.d.ts +13 -5
- package/dist/parse.d.ts +16 -0
- package/dist/readable-repo.d.ts +22 -0
- package/dist/repo.d.ts +14 -30
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/memory-blockstore.d.ts +28 -0
- package/dist/storage/readable-blockstore.d.ts +24 -0
- package/dist/storage/repo-storage.d.ts +18 -0
- package/dist/storage/sync-storage.d.ts +15 -0
- package/dist/storage/types.d.ts +3 -0
- package/dist/sync/consumer.d.ts +18 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/provider.d.ts +9 -0
- package/dist/types.d.ts +124 -317
- package/dist/util.d.ts +31 -12
- package/dist/verify.d.ts +26 -4
- package/package.json +4 -2
- package/src/block-map.ts +95 -0
- package/src/cid-set.ts +1 -2
- package/src/data-diff.ts +121 -0
- package/src/error.ts +31 -0
- package/src/index.ts +3 -1
- package/src/mst/diff.ts +120 -90
- package/src/mst/mst.ts +185 -184
- package/src/mst/util.ts +54 -31
- package/src/parse.ts +44 -0
- package/src/readable-repo.ts +75 -0
- package/src/repo.ts +119 -249
- package/src/storage/index.ts +4 -0
- package/src/storage/memory-blockstore.ts +114 -0
- package/src/storage/readable-blockstore.ts +56 -0
- package/src/storage/repo-storage.ts +42 -0
- package/src/storage/sync-storage.ts +35 -0
- package/src/storage/types.ts +3 -0
- package/src/sync/consumer.ts +137 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/provider.ts +91 -0
- package/src/types.ts +101 -62
- package/src/util.ts +237 -56
- package/src/verify.ts +207 -42
- package/tests/_util.ts +132 -97
- package/tests/mst.test.ts +269 -122
- package/tests/repo.test.ts +48 -50
- package/tests/sync/checkout.test.ts +57 -0
- package/tests/sync/diff.test.ts +87 -0
- package/tests/sync/narrow.test.ts +145 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +2 -1
- package/src/blockstore/index.ts +0 -2
- package/src/blockstore/ipld-store.ts +0 -103
- package/src/blockstore/memory-blockstore.ts +0 -49
- package/src/sync.ts +0 -38
- package/tests/sync.test.ts +0 -129
package/dist/mst/diff.d.ts
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export declare
|
|
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,112 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import { CID } from 'multiformats';
|
|
3
|
-
import
|
|
4
|
-
import { DataDiff } from './diff';
|
|
3
|
+
import { ReadableBlockstore } from '../storage';
|
|
5
4
|
import { DataStore } from '../types';
|
|
6
5
|
import { BlockWriter } from '@ipld/car/api';
|
|
7
|
-
|
|
6
|
+
import BlockMap from '../block-map';
|
|
7
|
+
import CidSet from '../cid-set';
|
|
8
|
+
declare const nodeData: z.ZodObject<{
|
|
8
9
|
l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
9
10
|
e: z.ZodArray<z.ZodObject<{
|
|
10
11
|
p: z.ZodNumber;
|
|
11
|
-
k: z.
|
|
12
|
+
k: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
12
13
|
v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
13
14
|
t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
14
15
|
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
t: CID | null;
|
|
16
16
|
p: number;
|
|
17
|
-
k:
|
|
17
|
+
k: Uint8Array;
|
|
18
18
|
v: CID;
|
|
19
|
+
t: CID | null;
|
|
19
20
|
}, {
|
|
20
|
-
t?: any;
|
|
21
21
|
v?: any;
|
|
22
|
+
t?: any;
|
|
22
23
|
p: number;
|
|
23
|
-
k:
|
|
24
|
+
k: Uint8Array;
|
|
24
25
|
}>, "many">;
|
|
25
26
|
}, "strip", z.ZodTypeAny, {
|
|
26
27
|
l: CID | null;
|
|
27
28
|
e: {
|
|
28
|
-
t: CID | null;
|
|
29
29
|
p: number;
|
|
30
|
-
k:
|
|
30
|
+
k: Uint8Array;
|
|
31
31
|
v: CID;
|
|
32
|
+
t: CID | null;
|
|
32
33
|
}[];
|
|
33
34
|
}, {
|
|
34
35
|
l?: any;
|
|
35
36
|
e: {
|
|
36
|
-
t?: any;
|
|
37
37
|
v?: any;
|
|
38
|
+
t?: any;
|
|
38
39
|
p: number;
|
|
39
|
-
k:
|
|
40
|
+
k: Uint8Array;
|
|
40
41
|
}[];
|
|
41
42
|
}>;
|
|
42
|
-
export declare type NodeData = z.infer<typeof
|
|
43
|
+
export declare type NodeData = z.infer<typeof nodeData>;
|
|
44
|
+
export declare const nodeDataDef: {
|
|
45
|
+
name: string;
|
|
46
|
+
schema: z.ZodObject<{
|
|
47
|
+
l: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
48
|
+
e: z.ZodArray<z.ZodObject<{
|
|
49
|
+
p: z.ZodNumber;
|
|
50
|
+
k: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
|
|
51
|
+
v: z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>;
|
|
52
|
+
t: z.ZodNullable<z.ZodEffects<z.ZodEffects<z.ZodAny, any, any>, CID, any>>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
p: number;
|
|
55
|
+
k: Uint8Array;
|
|
56
|
+
v: CID;
|
|
57
|
+
t: CID | null;
|
|
58
|
+
}, {
|
|
59
|
+
v?: any;
|
|
60
|
+
t?: any;
|
|
61
|
+
p: number;
|
|
62
|
+
k: Uint8Array;
|
|
63
|
+
}>, "many">;
|
|
64
|
+
}, "strip", z.ZodTypeAny, {
|
|
65
|
+
l: CID | null;
|
|
66
|
+
e: {
|
|
67
|
+
p: number;
|
|
68
|
+
k: Uint8Array;
|
|
69
|
+
v: CID;
|
|
70
|
+
t: CID | null;
|
|
71
|
+
}[];
|
|
72
|
+
}, {
|
|
73
|
+
l?: any;
|
|
74
|
+
e: {
|
|
75
|
+
v?: any;
|
|
76
|
+
t?: any;
|
|
77
|
+
p: number;
|
|
78
|
+
k: Uint8Array;
|
|
79
|
+
}[];
|
|
80
|
+
}>;
|
|
81
|
+
};
|
|
43
82
|
export declare type NodeEntry = MST | Leaf;
|
|
44
|
-
export declare type Fanout = 2 | 8 | 16 | 32 | 64;
|
|
45
83
|
export declare type MstOpts = {
|
|
46
84
|
layer: number;
|
|
47
|
-
fanout: Fanout;
|
|
48
85
|
};
|
|
49
86
|
export declare class MST implements DataStore {
|
|
50
|
-
|
|
51
|
-
fanout: Fanout;
|
|
87
|
+
storage: ReadableBlockstore;
|
|
52
88
|
entries: NodeEntry[] | null;
|
|
53
89
|
layer: number | null;
|
|
54
90
|
pointer: CID;
|
|
55
91
|
outdatedPointer: boolean;
|
|
56
|
-
constructor(
|
|
57
|
-
static create(
|
|
58
|
-
static fromData(
|
|
59
|
-
static load(
|
|
92
|
+
constructor(storage: ReadableBlockstore, pointer: CID, entries: NodeEntry[] | null, layer: number | null);
|
|
93
|
+
static create(storage: ReadableBlockstore, entries?: NodeEntry[], opts?: Partial<MstOpts>): Promise<MST>;
|
|
94
|
+
static fromData(storage: ReadableBlockstore, data: NodeData, opts?: Partial<MstOpts>): Promise<MST>;
|
|
95
|
+
static load(storage: ReadableBlockstore, cid: CID, opts?: Partial<MstOpts>): MST;
|
|
60
96
|
newTree(entries: NodeEntry[]): Promise<MST>;
|
|
61
97
|
getEntries(): Promise<NodeEntry[]>;
|
|
62
98
|
getPointer(): Promise<CID>;
|
|
63
99
|
getLayer(): Promise<number>;
|
|
64
100
|
attemptGetLayer(): Promise<number | null>;
|
|
65
|
-
|
|
66
|
-
|
|
101
|
+
getUnstoredBlocks(): Promise<{
|
|
102
|
+
root: CID;
|
|
103
|
+
blocks: BlockMap;
|
|
104
|
+
}>;
|
|
67
105
|
add(key: string, value: CID, knownZeros?: number): Promise<MST>;
|
|
68
106
|
get(key: string): Promise<CID | null>;
|
|
69
107
|
update(key: string, value: CID): Promise<MST>;
|
|
70
108
|
delete(key: string): Promise<MST>;
|
|
71
|
-
|
|
109
|
+
deleteRecurse(key: string): Promise<MST>;
|
|
72
110
|
updateEntry(index: number, entry: NodeEntry): Promise<MST>;
|
|
73
111
|
removeEntry(index: number): Promise<MST>;
|
|
74
112
|
append(entry: NodeEntry): Promise<MST>;
|
|
@@ -77,20 +115,25 @@ export declare class MST implements DataStore {
|
|
|
77
115
|
slice(start?: number | undefined, end?: number | undefined): Promise<NodeEntry[]>;
|
|
78
116
|
spliceIn(entry: NodeEntry, index: number): Promise<MST>;
|
|
79
117
|
replaceWithSplit(index: number, left: MST | null, leaf: Leaf, right: MST | null): Promise<MST>;
|
|
118
|
+
trimTop(): Promise<MST>;
|
|
80
119
|
splitAround(key: string): Promise<[MST | null, MST | null]>;
|
|
81
120
|
appendMerge(toMerge: MST): Promise<MST>;
|
|
82
121
|
createChild(): Promise<MST>;
|
|
83
122
|
createParent(): Promise<MST>;
|
|
84
123
|
findGtOrEqualLeafIndex(key: string): Promise<number>;
|
|
85
124
|
walkLeavesFrom(key: string): AsyncIterable<Leaf>;
|
|
86
|
-
list(count
|
|
125
|
+
list(count?: number, after?: string, before?: string): Promise<Leaf[]>;
|
|
87
126
|
listWithPrefix(prefix: string, count?: number): Promise<Leaf[]>;
|
|
88
127
|
walk(): AsyncIterable<NodeEntry>;
|
|
89
128
|
paths(): Promise<NodeEntry[][]>;
|
|
90
129
|
allNodes(): Promise<NodeEntry[]>;
|
|
130
|
+
allCids(): Promise<CidSet>;
|
|
91
131
|
leaves(): Promise<Leaf[]>;
|
|
92
132
|
leafCount(): Promise<number>;
|
|
133
|
+
walkReachable(): AsyncIterable<NodeEntry>;
|
|
134
|
+
reachableLeaves(): Promise<Leaf[]>;
|
|
93
135
|
writeToCarStream(car: BlockWriter): Promise<void>;
|
|
136
|
+
cidsForPath(key: string): Promise<CID[]>;
|
|
94
137
|
isTree(): this is MST;
|
|
95
138
|
isLeaf(): this is Leaf;
|
|
96
139
|
equals(other: NodeEntry): Promise<boolean>;
|
package/dist/mst/util.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { CID } from 'multiformats';
|
|
2
|
-
import
|
|
3
|
-
import { NodeEntry, NodeData, MstOpts
|
|
4
|
-
export declare const leadingZerosOnHash: (key: string
|
|
5
|
-
export declare const layerForEntries: (entries: NodeEntry[]
|
|
6
|
-
export declare const deserializeNodeData: (
|
|
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
|
+
}
|
package/dist/parse.d.ts
ADDED
|
@@ -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,22 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { Commit, DataStore, RepoContents } from './types';
|
|
3
|
+
import { ReadableBlockstore } from './storage';
|
|
4
|
+
declare type Params = {
|
|
5
|
+
storage: ReadableBlockstore;
|
|
6
|
+
data: DataStore;
|
|
7
|
+
commit: Commit;
|
|
8
|
+
cid: CID;
|
|
9
|
+
};
|
|
10
|
+
export declare class ReadableRepo {
|
|
11
|
+
storage: ReadableBlockstore;
|
|
12
|
+
data: DataStore;
|
|
13
|
+
commit: Commit;
|
|
14
|
+
cid: CID;
|
|
15
|
+
constructor(params: Params);
|
|
16
|
+
static load(storage: ReadableBlockstore, commitCid: CID): Promise<ReadableRepo>;
|
|
17
|
+
get did(): string;
|
|
18
|
+
get version(): number;
|
|
19
|
+
getRecord(collection: string, rkey: string): Promise<unknown | null>;
|
|
20
|
+
getContents(): Promise<RepoContents>;
|
|
21
|
+
}
|
|
22
|
+
export default ReadableRepo;
|
package/dist/repo.d.ts
CHANGED
|
@@ -1,39 +1,23 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import * as crypto from '@atproto/crypto';
|
|
3
|
+
import { Commit, DataStore, RecordCreateOp, RecordWriteOp, CommitData } from './types';
|
|
4
|
+
import { RepoStorage } from './storage';
|
|
5
|
+
import { ReadableRepo } from './readable-repo';
|
|
6
6
|
declare type Params = {
|
|
7
|
-
|
|
7
|
+
storage: RepoStorage;
|
|
8
8
|
data: DataStore;
|
|
9
9
|
commit: Commit;
|
|
10
|
-
root: RepoRoot;
|
|
11
|
-
meta: RepoMeta;
|
|
12
10
|
cid: CID;
|
|
13
|
-
stagedWrites: RecordWriteOp[];
|
|
14
11
|
};
|
|
15
|
-
export declare class Repo {
|
|
16
|
-
|
|
17
|
-
data: DataStore;
|
|
18
|
-
commit: Commit;
|
|
19
|
-
root: RepoRoot;
|
|
20
|
-
meta: RepoMeta;
|
|
21
|
-
cid: CID;
|
|
22
|
-
stagedWrites: RecordWriteOp[];
|
|
12
|
+
export declare class Repo extends ReadableRepo {
|
|
13
|
+
storage: RepoStorage;
|
|
23
14
|
constructor(params: Params);
|
|
24
|
-
static
|
|
25
|
-
static
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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>;
|
|
15
|
+
static formatInitCommit(storage: RepoStorage, did: string, keypair: crypto.Keypair, initialWrites?: RecordCreateOp[]): Promise<CommitData>;
|
|
16
|
+
static createFromCommit(storage: RepoStorage, commit: CommitData): Promise<Repo>;
|
|
17
|
+
static create(storage: RepoStorage, did: string, keypair: crypto.Keypair, initialWrites?: RecordCreateOp[]): Promise<Repo>;
|
|
18
|
+
static load(storage: RepoStorage, cid?: CID): Promise<Repo>;
|
|
19
|
+
formatCommit(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<CommitData>;
|
|
20
|
+
applyCommit(commitData: CommitData): Promise<Repo>;
|
|
21
|
+
applyWrites(toWrite: RecordWriteOp | RecordWriteOp[], keypair: crypto.Keypair): Promise<Repo>;
|
|
38
22
|
}
|
|
39
23
|
export default Repo;
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { CommitData } from '../types';
|
|
3
|
+
import BlockMap from '../block-map';
|
|
4
|
+
import RepoStorage from './repo-storage';
|
|
5
|
+
export declare class MemoryBlockstore extends RepoStorage {
|
|
6
|
+
blocks: BlockMap;
|
|
7
|
+
head: CID | null;
|
|
8
|
+
constructor(blocks?: BlockMap);
|
|
9
|
+
getHead(): Promise<CID | null>;
|
|
10
|
+
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
11
|
+
has(cid: CID): Promise<boolean>;
|
|
12
|
+
getBlocks(cids: CID[]): Promise<{
|
|
13
|
+
blocks: BlockMap;
|
|
14
|
+
missing: CID[];
|
|
15
|
+
}>;
|
|
16
|
+
putBlock(cid: CID, block: Uint8Array): Promise<void>;
|
|
17
|
+
putMany(blocks: BlockMap): Promise<void>;
|
|
18
|
+
indexCommits(commits: CommitData[]): Promise<void>;
|
|
19
|
+
updateHead(cid: CID, _prev: CID | null): Promise<void>;
|
|
20
|
+
applyCommit(commit: CommitData): Promise<void>;
|
|
21
|
+
getCommitPath(latest: CID, earliest: CID | null): Promise<CID[] | null>;
|
|
22
|
+
getBlocksForCommits(commits: CID[]): Promise<{
|
|
23
|
+
[commit: string]: BlockMap;
|
|
24
|
+
}>;
|
|
25
|
+
sizeInBytes(): Promise<number>;
|
|
26
|
+
destroy(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export default MemoryBlockstore;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 abstract class ReadableBlockstore {
|
|
6
|
+
abstract getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
7
|
+
abstract has(cid: CID): Promise<boolean>;
|
|
8
|
+
abstract getBlocks(cids: CID[]): Promise<{
|
|
9
|
+
blocks: BlockMap;
|
|
10
|
+
missing: CID[];
|
|
11
|
+
}>;
|
|
12
|
+
attemptRead<T>(cid: CID, def: check.Def<T>): Promise<{
|
|
13
|
+
obj: T;
|
|
14
|
+
bytes: Uint8Array;
|
|
15
|
+
} | null>;
|
|
16
|
+
readObjAndBytes<T>(cid: CID, def: check.Def<T>): Promise<{
|
|
17
|
+
obj: T;
|
|
18
|
+
bytes: Uint8Array;
|
|
19
|
+
}>;
|
|
20
|
+
readObj<T>(cid: CID, def: check.Def<T>): Promise<T>;
|
|
21
|
+
attemptReadRecord(cid: CID): Promise<RepoRecord | null>;
|
|
22
|
+
readRecord(cid: CID): Promise<RepoRecord>;
|
|
23
|
+
}
|
|
24
|
+
export default ReadableBlockstore;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import BlockMap from '../block-map';
|
|
3
|
+
import { CommitBlockData, CommitData } from '../types';
|
|
4
|
+
import ReadableBlockstore from './readable-blockstore';
|
|
5
|
+
export declare abstract class RepoStorage extends ReadableBlockstore {
|
|
6
|
+
abstract getHead(forUpdate?: boolean): Promise<CID | null>;
|
|
7
|
+
abstract getCommitPath(latest: CID, earliest: CID | null): Promise<CID[] | null>;
|
|
8
|
+
abstract getBlocksForCommits(commits: CID[]): Promise<{
|
|
9
|
+
[commit: string]: BlockMap;
|
|
10
|
+
}>;
|
|
11
|
+
abstract putBlock(cid: CID, block: Uint8Array): Promise<void>;
|
|
12
|
+
abstract putMany(blocks: BlockMap): Promise<void>;
|
|
13
|
+
abstract updateHead(cid: CID, prev: CID | null): Promise<void>;
|
|
14
|
+
abstract indexCommits(commit: CommitData[]): Promise<void>;
|
|
15
|
+
applyCommit(commit: CommitData): Promise<void>;
|
|
16
|
+
getCommits(latest: CID, earliest: CID | null): Promise<CommitBlockData[] | null>;
|
|
17
|
+
}
|
|
18
|
+
export default RepoStorage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import BlockMap from '../block-map';
|
|
3
|
+
import ReadableBlockstore from './readable-blockstore';
|
|
4
|
+
export declare class SyncStorage extends ReadableBlockstore {
|
|
5
|
+
staged: ReadableBlockstore;
|
|
6
|
+
saved: ReadableBlockstore;
|
|
7
|
+
constructor(staged: ReadableBlockstore, saved: ReadableBlockstore);
|
|
8
|
+
getBytes(cid: CID): Promise<Uint8Array | null>;
|
|
9
|
+
getBlocks(cids: CID[]): Promise<{
|
|
10
|
+
blocks: BlockMap;
|
|
11
|
+
missing: CID[];
|
|
12
|
+
}>;
|
|
13
|
+
has(cid: CID): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export default SyncStorage;
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -5,8 +5,11 @@ export interface BlobStore {
|
|
|
5
5
|
putTemp(bytes: Uint8Array | stream.Readable): Promise<string>;
|
|
6
6
|
makePermanent(key: string, cid: CID): Promise<void>;
|
|
7
7
|
putPermanent(cid: CID, bytes: Uint8Array | stream.Readable): Promise<void>;
|
|
8
|
+
quarantine(cid: CID): Promise<void>;
|
|
9
|
+
unquarantine(cid: CID): Promise<void>;
|
|
8
10
|
getBytes(cid: CID): Promise<Uint8Array>;
|
|
9
11
|
getStream(cid: CID): Promise<stream.Readable>;
|
|
12
|
+
delete(cid: CID): Promise<void>;
|
|
10
13
|
}
|
|
11
14
|
export declare class BlobNotFoundError extends Error {
|
|
12
15
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { RepoStorage } from '../storage';
|
|
3
|
+
import Repo from '../repo';
|
|
4
|
+
import * as verify from '../verify';
|
|
5
|
+
import { RepoContents, WriteLog } from '../types';
|
|
6
|
+
export declare const loadCheckout: (storage: RepoStorage, repoCar: Uint8Array, did: string, signingKey: string) => Promise<{
|
|
7
|
+
root: CID;
|
|
8
|
+
contents: RepoContents;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const loadFullRepo: (storage: RepoStorage, repoCar: Uint8Array, did: string, signingKey: string) => Promise<{
|
|
11
|
+
root: CID;
|
|
12
|
+
writeLog: WriteLog;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const loadDiff: (repo: Repo, diffCar: Uint8Array, did: string, signingKey: string) => Promise<{
|
|
15
|
+
root: CID;
|
|
16
|
+
writeLog: WriteLog;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const persistUpdates: (storage: RepoStorage, updateStorage: RepoStorage, updates: verify.VerifiedUpdate[]) => Promise<WriteLog>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RecordPath } from '../types';
|
|
2
|
+
import { BlockWriter } from '@ipld/car/writer';
|
|
3
|
+
import { CID } from 'multiformats/cid';
|
|
4
|
+
import { RepoStorage } from '../storage';
|
|
5
|
+
export declare const getCheckout: (storage: RepoStorage, commitCid: CID) => Promise<Uint8Array>;
|
|
6
|
+
export declare const getDiff: (storage: RepoStorage, latest: CID, earliest: CID | null) => Promise<Uint8Array>;
|
|
7
|
+
export declare const getFullRepo: (storage: RepoStorage, cid: CID) => Promise<Uint8Array>;
|
|
8
|
+
export declare const writeCommitsToCarStream: (storage: RepoStorage, car: BlockWriter, latest: CID, earliest: CID | null) => Promise<void>;
|
|
9
|
+
export declare const getRecords: (storage: RepoStorage, commitCid: CID, paths: RecordPath[]) => Promise<Uint8Array>;
|