@atcute/car 3.0.4 → 3.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/README.md +22 -7
- package/dist/v3/atproto-repo.d.ts +1 -0
- package/dist/v3/atproto-repo.js +2 -0
- package/dist/v3/atproto-repo.js.map +1 -0
- package/dist/v3/index.js.map +1 -0
- package/dist/v3/reader.d.ts +1 -0
- package/dist/v3/reader.js +2 -0
- package/dist/v3/reader.js.map +1 -0
- package/dist/v4/car-reader/index.d.ts +3 -0
- package/dist/v4/car-reader/index.js +4 -0
- package/dist/v4/car-reader/index.js.map +1 -0
- package/dist/v4/car-reader/stream-car-reader.d.ts +11 -0
- package/dist/v4/car-reader/stream-car-reader.js +178 -0
- package/dist/v4/car-reader/stream-car-reader.js.map +1 -0
- package/dist/v4/car-reader/sync-car-reader.d.ts +10 -0
- package/dist/{utilities → v4/car-reader}/sync-car-reader.js +63 -31
- package/dist/v4/car-reader/sync-car-reader.js.map +1 -0
- package/dist/{utilities/car.js → v4/car-reader/types.js} +1 -1
- package/dist/v4/car-reader/types.js.map +1 -0
- package/dist/v4/index.d.ts +2 -0
- package/dist/v4/index.js +3 -0
- package/dist/v4/index.js.map +1 -0
- package/dist/v4/repo-reader/index.d.ts +5 -0
- package/dist/v4/repo-reader/index.js +6 -0
- package/dist/v4/repo-reader/index.js.map +1 -0
- package/dist/v4/repo-reader/mst.d.ts +47 -0
- package/dist/v4/repo-reader/mst.js +62 -0
- package/dist/v4/repo-reader/mst.js.map +1 -0
- package/dist/v4/repo-reader/stream-repo-reader.d.ts +24 -0
- package/dist/v4/repo-reader/stream-repo-reader.js +137 -0
- package/dist/v4/repo-reader/stream-repo-reader.js.map +1 -0
- package/dist/v4/repo-reader/sync-blockmap.d.ts +29 -0
- package/dist/v4/repo-reader/sync-blockmap.js +58 -0
- package/dist/v4/repo-reader/sync-blockmap.js.map +1 -0
- package/dist/v4/repo-reader/sync-repo-reader.d.ts +2 -0
- package/dist/v4/repo-reader/sync-repo-reader.js +20 -0
- package/dist/v4/repo-reader/sync-repo-reader.js.map +1 -0
- package/dist/v4/repo-reader/types.d.ts +20 -0
- package/dist/v4/repo-reader/types.js +37 -0
- package/dist/v4/repo-reader/types.js.map +1 -0
- package/dist/v4/utils.d.ts +3 -0
- package/dist/v4/utils.js +6 -0
- package/dist/v4/utils.js.map +1 -0
- package/lib/v3/atproto-repo.ts +15 -0
- package/lib/v3/reader.ts +9 -0
- package/lib/v4/car-reader/index.ts +4 -0
- package/lib/v4/car-reader/stream-car-reader.ts +240 -0
- package/lib/{utilities → v4/car-reader}/sync-car-reader.ts +90 -40
- package/lib/v4/index.ts +2 -0
- package/lib/v4/repo-reader/index.ts +6 -0
- package/lib/v4/repo-reader/mst.ts +110 -0
- package/lib/v4/repo-reader/stream-repo-reader.ts +204 -0
- package/lib/v4/repo-reader/sync-blockmap.ts +85 -0
- package/lib/v4/repo-reader/sync-repo-reader.ts +27 -0
- package/lib/v4/repo-reader/types.ts +32 -0
- package/lib/v4/utils.ts +7 -0
- package/package.json +12 -7
- package/dist/atproto-repo.d.ts +0 -104
- package/dist/atproto-repo.js +0 -171
- package/dist/atproto-repo.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/reader.d.ts +0 -4
- package/dist/reader.js +0 -7
- package/dist/reader.js.map +0 -1
- package/dist/utilities/car.js.map +0 -1
- package/dist/utilities/sync-byte-reader.d.ts +0 -7
- package/dist/utilities/sync-byte-reader.js +0 -28
- package/dist/utilities/sync-byte-reader.js.map +0 -1
- package/dist/utilities/sync-car-reader.d.ts +0 -7
- package/dist/utilities/sync-car-reader.js.map +0 -1
- package/lib/atproto-repo.ts +0 -248
- package/lib/reader.ts +0 -10
- package/lib/utilities/sync-byte-reader.ts +0 -39
- /package/dist/{index.d.ts → v3/index.d.ts} +0 -0
- /package/dist/{index.js → v3/index.js} +0 -0
- /package/dist/{utilities/car.d.ts → v4/car-reader/types.d.ts} +0 -0
- /package/lib/{index.ts → v3/index.ts} +0 -0
- /package/lib/{utilities/car.ts → v4/car-reader/types.ts} +0 -0
package/dist/atproto-repo.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import * as CBOR from '@atcute/cbor';
|
|
2
|
-
import * as CID from '@atcute/cid';
|
|
3
|
-
import { type CarEntry } from './reader.js';
|
|
4
|
-
export type BlockMap = Map<string, CarEntry>;
|
|
5
|
-
export declare class RepoEntry {
|
|
6
|
-
/** The collection this record belongs to */
|
|
7
|
-
readonly collection: string;
|
|
8
|
-
/** Record key */
|
|
9
|
-
readonly rkey: string;
|
|
10
|
-
/** CID of this record */
|
|
11
|
-
readonly cid: CID.CidLink;
|
|
12
|
-
private blockmap;
|
|
13
|
-
constructor(
|
|
14
|
-
/** The collection this record belongs to */
|
|
15
|
-
collection: string,
|
|
16
|
-
/** Record key */
|
|
17
|
-
rkey: string,
|
|
18
|
-
/** CID of this record */
|
|
19
|
-
cid: CID.CidLink, blockmap: BlockMap);
|
|
20
|
-
/**
|
|
21
|
-
* returns the associated CarEntry for this record
|
|
22
|
-
*/
|
|
23
|
-
get carEntry(): CarEntry;
|
|
24
|
-
/**
|
|
25
|
-
* returns the raw contents of this record
|
|
26
|
-
*/
|
|
27
|
-
get bytes(): Uint8Array;
|
|
28
|
-
/**
|
|
29
|
-
* returns the decoded contents of this record
|
|
30
|
-
*/
|
|
31
|
-
get record(): unknown;
|
|
32
|
-
}
|
|
33
|
-
export declare function iterateAtpRepo(buf: Uint8Array): Generator<RepoEntry>;
|
|
34
|
-
/**
|
|
35
|
-
* collects entries from a CAR archive into a mapping of CID string -> actual bytes
|
|
36
|
-
* @param iterator a generator that yields objects with a `cid` and `bytes` property
|
|
37
|
-
* @returns a mapping of CID string -> actual bytes
|
|
38
|
-
*/
|
|
39
|
-
export declare function collectBlock(iterator: Generator<CarEntry>): BlockMap;
|
|
40
|
-
/**
|
|
41
|
-
* reads a block from the blockmap and validates it against the provided validation function
|
|
42
|
-
* @param map a mapping of CID string -> actual bytes
|
|
43
|
-
* @param link a CID link to read
|
|
44
|
-
* @param validate a validation function to validate the decoded data
|
|
45
|
-
* @returns the decoded and validated data
|
|
46
|
-
*/
|
|
47
|
-
export declare function readBlock<T>(map: BlockMap, link: CID.CidLink, validate: (value: unknown) => value is T): T;
|
|
48
|
-
/** node entry object */
|
|
49
|
-
export interface NodeEntry {
|
|
50
|
-
key: string;
|
|
51
|
-
cid: CID.CidLink;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* walks the entries of a Merkle Sorted Tree (MST) in a depth-first manner
|
|
55
|
-
* @param map a mapping of CID string -> actual bytes
|
|
56
|
-
* @param pointer a CID link to the root of the MST
|
|
57
|
-
* @returns a generator that yields the entries of the MST
|
|
58
|
-
*/
|
|
59
|
-
export declare function walkMstEntries(map: BlockMap, pointer: CID.CidLink): Generator<NodeEntry>;
|
|
60
|
-
/** commit object */
|
|
61
|
-
export interface Commit {
|
|
62
|
-
version: 3;
|
|
63
|
-
did: string;
|
|
64
|
-
data: CID.CidLink;
|
|
65
|
-
rev: string;
|
|
66
|
-
prev: CID.CidLink | null;
|
|
67
|
-
sig: CBOR.Bytes;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* checks if a value is a valid commit object
|
|
71
|
-
* @param value the value to check
|
|
72
|
-
* @returns true if the value is a valid commit object, false otherwise
|
|
73
|
-
*/
|
|
74
|
-
export declare const isCommit: (value: unknown) => value is Commit;
|
|
75
|
-
/** mst tree entry object */
|
|
76
|
-
export interface TreeEntry {
|
|
77
|
-
/** count of bytes shared with previous TreeEntry in this Node (if any) */
|
|
78
|
-
p: number;
|
|
79
|
-
/** remainder of key for this TreeEntry, after "prefixlen" have been removed */
|
|
80
|
-
k: CBOR.Bytes;
|
|
81
|
-
/** link to a sub-tree Node at a lower level which has keys sorting after this TreeEntry's key (to the "right"), but before the next TreeEntry's key in this Node (if any) */
|
|
82
|
-
v: CID.CidLink;
|
|
83
|
-
/** next subtree (to the right of leaf) */
|
|
84
|
-
t: CID.CidLink | null;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* checks if a value is a valid mst tree entry object
|
|
88
|
-
* @param value the value to check
|
|
89
|
-
* @returns true if the value is a valid mst tree entry object, false otherwise
|
|
90
|
-
*/
|
|
91
|
-
export declare const isTreeEntry: (value: unknown) => value is TreeEntry;
|
|
92
|
-
/** mst node object */
|
|
93
|
-
export interface MstNode {
|
|
94
|
-
/** link to sub-tree Node on a lower level and with all keys sorting before keys at this node */
|
|
95
|
-
l: CID.CidLink | null;
|
|
96
|
-
/** ordered list of TreeEntry objects */
|
|
97
|
-
e: TreeEntry[];
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* checks if a value is a valid mst node object
|
|
101
|
-
* @param value the value to check
|
|
102
|
-
* @returns true if the value is a valid mst node object, false otherwise
|
|
103
|
-
*/
|
|
104
|
-
export declare const isMstNode: (value: unknown) => value is MstNode;
|
package/dist/atproto-repo.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import * as CBOR from '@atcute/cbor';
|
|
2
|
-
import * as CID from '@atcute/cid';
|
|
3
|
-
import { readCar } from './reader.js';
|
|
4
|
-
const decoder = new TextDecoder();
|
|
5
|
-
export class RepoEntry {
|
|
6
|
-
collection;
|
|
7
|
-
rkey;
|
|
8
|
-
cid;
|
|
9
|
-
blockmap;
|
|
10
|
-
constructor(
|
|
11
|
-
/** The collection this record belongs to */
|
|
12
|
-
collection,
|
|
13
|
-
/** Record key */
|
|
14
|
-
rkey,
|
|
15
|
-
/** CID of this record */
|
|
16
|
-
cid, blockmap) {
|
|
17
|
-
this.collection = collection;
|
|
18
|
-
this.rkey = rkey;
|
|
19
|
-
this.cid = cid;
|
|
20
|
-
this.blockmap = blockmap;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* returns the associated CarEntry for this record
|
|
24
|
-
*/
|
|
25
|
-
get carEntry() {
|
|
26
|
-
const cid = this.cid.$link;
|
|
27
|
-
const entry = this.blockmap.get(cid);
|
|
28
|
-
assert(entry != null, `cid not found in blockmap; cid=${cid}`);
|
|
29
|
-
return entry;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* returns the raw contents of this record
|
|
33
|
-
*/
|
|
34
|
-
get bytes() {
|
|
35
|
-
return this.carEntry.bytes;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* returns the decoded contents of this record
|
|
39
|
-
*/
|
|
40
|
-
get record() {
|
|
41
|
-
return CBOR.decode(this.bytes);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function* iterateAtpRepo(buf) {
|
|
45
|
-
const { header, iterate } = readCar(buf);
|
|
46
|
-
const roots = header.data.roots;
|
|
47
|
-
assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
|
|
48
|
-
const blockmap = collectBlock(iterate());
|
|
49
|
-
assert(blockmap.size > 0, `expected at least 1 block in the archive; got=${blockmap.size}`);
|
|
50
|
-
const commit = readBlock(blockmap, roots[0], isCommit);
|
|
51
|
-
for (const { key, cid } of walkMstEntries(blockmap, commit.data)) {
|
|
52
|
-
const [collection, rkey] = key.split('/');
|
|
53
|
-
yield new RepoEntry(collection, rkey, cid, blockmap);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* collects entries from a CAR archive into a mapping of CID string -> actual bytes
|
|
58
|
-
* @param iterator a generator that yields objects with a `cid` and `bytes` property
|
|
59
|
-
* @returns a mapping of CID string -> actual bytes
|
|
60
|
-
*/
|
|
61
|
-
export function collectBlock(iterator) {
|
|
62
|
-
const blockmap = new Map();
|
|
63
|
-
for (const entry of iterator) {
|
|
64
|
-
blockmap.set(CID.toString(entry.cid), entry);
|
|
65
|
-
}
|
|
66
|
-
return blockmap;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* reads a block from the blockmap and validates it against the provided validation function
|
|
70
|
-
* @param map a mapping of CID string -> actual bytes
|
|
71
|
-
* @param link a CID link to read
|
|
72
|
-
* @param validate a validation function to validate the decoded data
|
|
73
|
-
* @returns the decoded and validated data
|
|
74
|
-
*/
|
|
75
|
-
export function readBlock(map, link, validate) {
|
|
76
|
-
const cid = link.$link;
|
|
77
|
-
const entry = map.get(cid);
|
|
78
|
-
assert(entry != null, `cid not found in blockmap; cid=${cid}`);
|
|
79
|
-
const data = CBOR.decode(entry.bytes);
|
|
80
|
-
assert(validate(data), `validation failed for cid=${cid}`);
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* walks the entries of a Merkle Sorted Tree (MST) in a depth-first manner
|
|
85
|
-
* @param map a mapping of CID string -> actual bytes
|
|
86
|
-
* @param pointer a CID link to the root of the MST
|
|
87
|
-
* @returns a generator that yields the entries of the MST
|
|
88
|
-
*/
|
|
89
|
-
export function* walkMstEntries(map, pointer) {
|
|
90
|
-
const data = readBlock(map, pointer, isMstNode);
|
|
91
|
-
const entries = data.e;
|
|
92
|
-
let lastKey = '';
|
|
93
|
-
if (data.l !== null) {
|
|
94
|
-
yield* walkMstEntries(map, data.l);
|
|
95
|
-
}
|
|
96
|
-
for (let i = 0, il = entries.length; i < il; i++) {
|
|
97
|
-
const entry = entries[i];
|
|
98
|
-
const key_str = decoder.decode(CBOR.fromBytes(entry.k));
|
|
99
|
-
const key = lastKey.slice(0, entry.p) + key_str;
|
|
100
|
-
lastKey = key;
|
|
101
|
-
yield { key: key, cid: entry.v };
|
|
102
|
-
if (entry.t !== null) {
|
|
103
|
-
yield* walkMstEntries(map, entry.t);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function assert(condition, message) {
|
|
108
|
-
if (!condition) {
|
|
109
|
-
throw new Error(message);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const isCidLink = (value) => {
|
|
113
|
-
if (value instanceof CID.CidLinkWrapper) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
if (value === null || typeof value !== 'object') {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
return '$link' in value && typeof value.$link === 'string';
|
|
120
|
-
};
|
|
121
|
-
const isBytes = (value) => {
|
|
122
|
-
if (value instanceof CBOR.BytesWrapper) {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
if (value === null || typeof value !== 'object') {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return '$bytes' in value && typeof value.$bytes === 'string';
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* checks if a value is a valid commit object
|
|
132
|
-
* @param value the value to check
|
|
133
|
-
* @returns true if the value is a valid commit object, false otherwise
|
|
134
|
-
*/
|
|
135
|
-
export const isCommit = (value) => {
|
|
136
|
-
if (value === null || typeof value !== 'object') {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
const obj = value;
|
|
140
|
-
return (obj.version === 3 &&
|
|
141
|
-
typeof obj.did === 'string' &&
|
|
142
|
-
isCidLink(obj.data) &&
|
|
143
|
-
typeof obj.rev === 'string' &&
|
|
144
|
-
(obj.prev === null || isCidLink(obj.prev)) &&
|
|
145
|
-
isBytes(obj.sig));
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* checks if a value is a valid mst tree entry object
|
|
149
|
-
* @param value the value to check
|
|
150
|
-
* @returns true if the value is a valid mst tree entry object, false otherwise
|
|
151
|
-
*/
|
|
152
|
-
export const isTreeEntry = (value) => {
|
|
153
|
-
if (value === null || typeof value !== 'object') {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
const obj = value;
|
|
157
|
-
return (typeof obj.p === 'number' && isBytes(obj.k) && isCidLink(obj.v) && (obj.t === null || isCidLink(obj.t)));
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* checks if a value is a valid mst node object
|
|
161
|
-
* @param value the value to check
|
|
162
|
-
* @returns true if the value is a valid mst node object, false otherwise
|
|
163
|
-
*/
|
|
164
|
-
export const isMstNode = (value) => {
|
|
165
|
-
if (value === null || typeof value !== 'object') {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
const obj = value;
|
|
169
|
-
return (obj.l === null || isCidLink(obj.l)) && Array.isArray(obj.e) && obj.e.every(isTreeEntry);
|
|
170
|
-
};
|
|
171
|
-
//# sourceMappingURL=atproto-repo.js.map
|
package/dist/atproto-repo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-repo.js","sourceRoot":"","sources":["../lib/atproto-repo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAC;AAErD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAIlC,MAAM,OAAO,SAAS;IAGJ;IAEA;IAEA;IACR;IAPT;IACC,4CAA4C;IAC5B,UAAkB;IAClC,iBAAiB;IACD,IAAY;IAC5B,yBAAyB;IACT,GAAgB,EACxB,QAAkB;QALV,eAAU,GAAV,UAAU,CAAQ;QAElB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,QAAG,GAAH,GAAG,CAAa;QACxB,aAAQ,GAAR,QAAQ,CAAU;IACxB,CAAC;IAEJ;;OAEG;IACH,IAAI,QAAQ;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAE3B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,kCAAkC,GAAG,EAAE,CAAC,CAAC;QAE/D,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;Q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IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjG,CAAC,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
package/dist/reader.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type SyncCarReader } from './utilities/sync-car-reader.js';
|
|
2
|
-
export type { CarEntry, CarHeader, CarV1Header } from './utilities/car.js';
|
|
3
|
-
export type { SyncCarReader } from './utilities/sync-car-reader.js';
|
|
4
|
-
export declare const readCar: (buffer: Uint8Array) => SyncCarReader;
|
package/dist/reader.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createUint8Reader } from './utilities/sync-byte-reader.js';
|
|
2
|
-
import { createCarReader } from './utilities/sync-car-reader.js';
|
|
3
|
-
export const readCar = (buffer) => {
|
|
4
|
-
const reader = createUint8Reader(buffer);
|
|
5
|
-
return createCarReader(reader);
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=reader.js.map
|
package/dist/reader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reader.js","sourceRoot":"","sources":["../lib/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAsB,MAAM,gCAAgC,CAAC;AAKrF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAkB,EAAiB,EAAE;IAC5D,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"car.js","sourceRoot":"","sources":["../../lib/utilities/car.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAOnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAwB,EAAE;IACrE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAoB,CAAC;IAChD,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,YAAY,IAAI,CAAC,cAAc,CAAC,CAAC;AAC5G,CAAC,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const createUint8Reader = (buf) => {
|
|
2
|
-
let pos = 0;
|
|
3
|
-
return {
|
|
4
|
-
get pos() {
|
|
5
|
-
return pos;
|
|
6
|
-
},
|
|
7
|
-
seek(size) {
|
|
8
|
-
if (size > buf.length - pos) {
|
|
9
|
-
throw new RangeError('unexpected end of data');
|
|
10
|
-
}
|
|
11
|
-
pos += size;
|
|
12
|
-
},
|
|
13
|
-
upto(size) {
|
|
14
|
-
return buf.subarray(pos, pos + size);
|
|
15
|
-
},
|
|
16
|
-
exactly(size, seek) {
|
|
17
|
-
if (size > buf.length - pos) {
|
|
18
|
-
throw new RangeError('unexpected end of data');
|
|
19
|
-
}
|
|
20
|
-
const slice = buf.subarray(pos, pos + size);
|
|
21
|
-
if (seek) {
|
|
22
|
-
pos += size;
|
|
23
|
-
}
|
|
24
|
-
return slice;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=sync-byte-reader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-byte-reader.js","sourceRoot":"","sources":["../../lib/utilities/sync-byte-reader.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAe,EAAkB,EAAE;IACpE,IAAI,GAAG,GAAG,CAAC,CAAC;IAEZ,OAAO;QACN,IAAI,GAAG;YACN,OAAO,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,CAAC,IAAI;YACR,IAAI,IAAI,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;gBAC7B,MAAM,IAAI,UAAU,CAAC,wBAAwB,CAAC,CAAC;YAChD,CAAC;YAED,GAAG,IAAI,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,IAAI;YACR,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,IAAI;YACjB,IAAI,IAAI,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;gBAC7B,MAAM,IAAI,UAAU,CAAC,wBAAwB,CAAC,CAAC;YAChD,CAAC;YAED,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACV,GAAG,IAAI,IAAI,CAAC;YACb,CAAC;YAED,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type CarEntry, type CarHeader } from './car.js';
|
|
2
|
-
import type { SyncByteReader } from './sync-byte-reader.js';
|
|
3
|
-
export interface SyncCarReader {
|
|
4
|
-
header: CarHeader;
|
|
5
|
-
iterate(): Generator<CarEntry>;
|
|
6
|
-
}
|
|
7
|
-
export declare const createCarReader: (reader: SyncByteReader) => SyncCarReader;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-car-reader.js","sourceRoot":"","sources":["../../lib/utilities/sync-car-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAiC,MAAM,UAAU,CAAC;AAQxE,MAAM,UAAU,GAAG,CAAC,MAAsB,EAAE,IAAY,EAAU,EAAE;IACnE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,UAAU,CAAC,wBAAwB,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElB,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,MAAsB,EAAa,EAAE;IACxD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC;IAC/B,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;IAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;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MAAM,QAAQ,GAAG,QAAQ,CAAC;gBAE1B,MAAM;oBACL,GAAG;oBACH,KAAK;oBAEL,UAAU;oBACV,QAAQ;oBACR,QAAQ;oBACR,MAAM;oBACN,UAAU;oBACV,QAAQ;iBACR,CAAC;YACH,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC,CAAC"}
|
package/lib/atproto-repo.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import * as CBOR from '@atcute/cbor';
|
|
2
|
-
import * as CID from '@atcute/cid';
|
|
3
|
-
|
|
4
|
-
import { readCar, type CarEntry } from './reader.js';
|
|
5
|
-
|
|
6
|
-
const decoder = new TextDecoder();
|
|
7
|
-
|
|
8
|
-
export type BlockMap = Map<string, CarEntry>;
|
|
9
|
-
|
|
10
|
-
export class RepoEntry {
|
|
11
|
-
constructor(
|
|
12
|
-
/** The collection this record belongs to */
|
|
13
|
-
public readonly collection: string,
|
|
14
|
-
/** Record key */
|
|
15
|
-
public readonly rkey: string,
|
|
16
|
-
/** CID of this record */
|
|
17
|
-
public readonly cid: CID.CidLink,
|
|
18
|
-
private blockmap: BlockMap,
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* returns the associated CarEntry for this record
|
|
23
|
-
*/
|
|
24
|
-
get carEntry(): CarEntry {
|
|
25
|
-
const cid = this.cid.$link;
|
|
26
|
-
|
|
27
|
-
const entry = this.blockmap.get(cid);
|
|
28
|
-
assert(entry != null, `cid not found in blockmap; cid=${cid}`);
|
|
29
|
-
|
|
30
|
-
return entry;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* returns the raw contents of this record
|
|
35
|
-
*/
|
|
36
|
-
get bytes(): Uint8Array {
|
|
37
|
-
return this.carEntry.bytes;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* returns the decoded contents of this record
|
|
42
|
-
*/
|
|
43
|
-
get record(): unknown {
|
|
44
|
-
return CBOR.decode(this.bytes);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function* iterateAtpRepo(buf: Uint8Array): Generator<RepoEntry> {
|
|
49
|
-
const { header, iterate } = readCar(buf);
|
|
50
|
-
const roots = header.data.roots;
|
|
51
|
-
|
|
52
|
-
assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
|
|
53
|
-
|
|
54
|
-
const blockmap = collectBlock(iterate());
|
|
55
|
-
assert(blockmap.size > 0, `expected at least 1 block in the archive; got=${blockmap.size}`);
|
|
56
|
-
|
|
57
|
-
const commit = readBlock(blockmap, roots[0], isCommit);
|
|
58
|
-
for (const { key, cid } of walkMstEntries(blockmap, commit.data)) {
|
|
59
|
-
const [collection, rkey] = key.split('/');
|
|
60
|
-
|
|
61
|
-
yield new RepoEntry(collection, rkey, cid, blockmap);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* collects entries from a CAR archive into a mapping of CID string -> actual bytes
|
|
67
|
-
* @param iterator a generator that yields objects with a `cid` and `bytes` property
|
|
68
|
-
* @returns a mapping of CID string -> actual bytes
|
|
69
|
-
*/
|
|
70
|
-
export function collectBlock(iterator: Generator<CarEntry>): BlockMap {
|
|
71
|
-
const blockmap: BlockMap = new Map();
|
|
72
|
-
for (const entry of iterator) {
|
|
73
|
-
blockmap.set(CID.toString(entry.cid), entry);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return blockmap;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* reads a block from the blockmap and validates it against the provided validation function
|
|
81
|
-
* @param map a mapping of CID string -> actual bytes
|
|
82
|
-
* @param link a CID link to read
|
|
83
|
-
* @param validate a validation function to validate the decoded data
|
|
84
|
-
* @returns the decoded and validated data
|
|
85
|
-
*/
|
|
86
|
-
export function readBlock<T>(map: BlockMap, link: CID.CidLink, validate: (value: unknown) => value is T): T {
|
|
87
|
-
const cid = link.$link;
|
|
88
|
-
|
|
89
|
-
const entry = map.get(cid);
|
|
90
|
-
assert(entry != null, `cid not found in blockmap; cid=${cid}`);
|
|
91
|
-
|
|
92
|
-
const data = CBOR.decode(entry.bytes);
|
|
93
|
-
assert(validate(data), `validation failed for cid=${cid}`);
|
|
94
|
-
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** node entry object */
|
|
99
|
-
export interface NodeEntry {
|
|
100
|
-
key: string;
|
|
101
|
-
cid: CID.CidLink;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* walks the entries of a Merkle Sorted Tree (MST) in a depth-first manner
|
|
106
|
-
* @param map a mapping of CID string -> actual bytes
|
|
107
|
-
* @param pointer a CID link to the root of the MST
|
|
108
|
-
* @returns a generator that yields the entries of the MST
|
|
109
|
-
*/
|
|
110
|
-
export function* walkMstEntries(map: BlockMap, pointer: CID.CidLink): Generator<NodeEntry> {
|
|
111
|
-
const data = readBlock(map, pointer, isMstNode);
|
|
112
|
-
const entries = data.e;
|
|
113
|
-
|
|
114
|
-
let lastKey = '';
|
|
115
|
-
|
|
116
|
-
if (data.l !== null) {
|
|
117
|
-
yield* walkMstEntries(map, data.l);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
for (let i = 0, il = entries.length; i < il; i++) {
|
|
121
|
-
const entry = entries[i];
|
|
122
|
-
|
|
123
|
-
const key_str = decoder.decode(CBOR.fromBytes(entry.k));
|
|
124
|
-
const key = lastKey.slice(0, entry.p) + key_str;
|
|
125
|
-
|
|
126
|
-
lastKey = key;
|
|
127
|
-
|
|
128
|
-
yield { key: key, cid: entry.v };
|
|
129
|
-
|
|
130
|
-
if (entry.t !== null) {
|
|
131
|
-
yield* walkMstEntries(map, entry.t);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function assert(condition: boolean, message: string): asserts condition {
|
|
137
|
-
if (!condition) {
|
|
138
|
-
throw new Error(message);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const isCidLink = (value: unknown): value is CID.CidLink => {
|
|
143
|
-
if (value instanceof CID.CidLinkWrapper) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (value === null || typeof value !== 'object') {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return '$link' in value && typeof value.$link === 'string';
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const isBytes = (value: unknown): value is CBOR.Bytes => {
|
|
155
|
-
if (value instanceof CBOR.BytesWrapper) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (value === null || typeof value !== 'object') {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return '$bytes' in value && typeof value.$bytes === 'string';
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/** commit object */
|
|
167
|
-
export interface Commit {
|
|
168
|
-
version: 3;
|
|
169
|
-
did: string;
|
|
170
|
-
data: CID.CidLink;
|
|
171
|
-
rev: string;
|
|
172
|
-
prev: CID.CidLink | null;
|
|
173
|
-
sig: CBOR.Bytes;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* checks if a value is a valid commit object
|
|
178
|
-
* @param value the value to check
|
|
179
|
-
* @returns true if the value is a valid commit object, false otherwise
|
|
180
|
-
*/
|
|
181
|
-
export const isCommit = (value: unknown): value is Commit => {
|
|
182
|
-
if (value === null || typeof value !== 'object') {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const obj = value as Record<string, unknown>;
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
obj.version === 3 &&
|
|
190
|
-
typeof obj.did === 'string' &&
|
|
191
|
-
isCidLink(obj.data) &&
|
|
192
|
-
typeof obj.rev === 'string' &&
|
|
193
|
-
(obj.prev === null || isCidLink(obj.prev)) &&
|
|
194
|
-
isBytes(obj.sig)
|
|
195
|
-
);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/** mst tree entry object */
|
|
199
|
-
export interface TreeEntry {
|
|
200
|
-
/** count of bytes shared with previous TreeEntry in this Node (if any) */
|
|
201
|
-
p: number;
|
|
202
|
-
/** remainder of key for this TreeEntry, after "prefixlen" have been removed */
|
|
203
|
-
k: CBOR.Bytes;
|
|
204
|
-
/** link to a sub-tree Node at a lower level which has keys sorting after this TreeEntry's key (to the "right"), but before the next TreeEntry's key in this Node (if any) */
|
|
205
|
-
v: CID.CidLink;
|
|
206
|
-
/** next subtree (to the right of leaf) */
|
|
207
|
-
t: CID.CidLink | null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* checks if a value is a valid mst tree entry object
|
|
212
|
-
* @param value the value to check
|
|
213
|
-
* @returns true if the value is a valid mst tree entry object, false otherwise
|
|
214
|
-
*/
|
|
215
|
-
export const isTreeEntry = (value: unknown): value is TreeEntry => {
|
|
216
|
-
if (value === null || typeof value !== 'object') {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const obj = value as Record<string, unknown>;
|
|
221
|
-
|
|
222
|
-
return (
|
|
223
|
-
typeof obj.p === 'number' && isBytes(obj.k) && isCidLink(obj.v) && (obj.t === null || isCidLink(obj.t))
|
|
224
|
-
);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/** mst node object */
|
|
228
|
-
export interface MstNode {
|
|
229
|
-
/** link to sub-tree Node on a lower level and with all keys sorting before keys at this node */
|
|
230
|
-
l: CID.CidLink | null;
|
|
231
|
-
/** ordered list of TreeEntry objects */
|
|
232
|
-
e: TreeEntry[];
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* checks if a value is a valid mst node object
|
|
237
|
-
* @param value the value to check
|
|
238
|
-
* @returns true if the value is a valid mst node object, false otherwise
|
|
239
|
-
*/
|
|
240
|
-
export const isMstNode = (value: unknown): value is MstNode => {
|
|
241
|
-
if (value === null || typeof value !== 'object') {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const obj = value as Record<string, unknown>;
|
|
246
|
-
|
|
247
|
-
return (obj.l === null || isCidLink(obj.l)) && Array.isArray(obj.e) && obj.e.every(isTreeEntry);
|
|
248
|
-
};
|
package/lib/reader.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createUint8Reader } from './utilities/sync-byte-reader.js';
|
|
2
|
-
import { createCarReader, type SyncCarReader } from './utilities/sync-car-reader.js';
|
|
3
|
-
|
|
4
|
-
export type { CarEntry, CarHeader, CarV1Header } from './utilities/car.js';
|
|
5
|
-
export type { SyncCarReader } from './utilities/sync-car-reader.js';
|
|
6
|
-
|
|
7
|
-
export const readCar = (buffer: Uint8Array): SyncCarReader => {
|
|
8
|
-
const reader = createUint8Reader(buffer);
|
|
9
|
-
return createCarReader(reader);
|
|
10
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export interface SyncByteReader {
|
|
2
|
-
readonly pos: number;
|
|
3
|
-
upto(size: number): Uint8Array;
|
|
4
|
-
exactly(size: number, seek: boolean): Uint8Array;
|
|
5
|
-
seek(size: number): void;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const createUint8Reader = (buf: Uint8Array): SyncByteReader => {
|
|
9
|
-
let pos = 0;
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
get pos() {
|
|
13
|
-
return pos;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
seek(size) {
|
|
17
|
-
if (size > buf.length - pos) {
|
|
18
|
-
throw new RangeError('unexpected end of data');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
pos += size;
|
|
22
|
-
},
|
|
23
|
-
upto(size) {
|
|
24
|
-
return buf.subarray(pos, pos + size);
|
|
25
|
-
},
|
|
26
|
-
exactly(size, seek) {
|
|
27
|
-
if (size > buf.length - pos) {
|
|
28
|
-
throw new RangeError('unexpected end of data');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const slice = buf.subarray(pos, pos + size);
|
|
32
|
-
if (seek) {
|
|
33
|
-
pos += size;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return slice;
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|