@atcute/car 1.0.0 → 1.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 CHANGED
@@ -3,7 +3,7 @@
3
3
  read AT Protocol's CAR (content-addressable archive) repositories
4
4
 
5
5
  ```ts
6
- for (const { collection, rkey, record } of iterateAtpCar(buf)) {
6
+ for (const { collection, rkey, record } of iterateAtpRepo(buf)) {
7
7
  // ...
8
8
  }
9
9
  ```
@@ -1,6 +1,14 @@
1
- export interface RepoEntry {
2
- collection: string;
3
- rkey: string;
4
- record: unknown;
1
+ import * as CBOR from '@atcute/cbor';
2
+ export declare class RepoEntry {
3
+ readonly collection: string;
4
+ readonly rkey: string;
5
+ readonly cid: CBOR.CIDLink;
6
+ private blockmap;
7
+ constructor(collection: string, rkey: string, cid: CBOR.CIDLink, blockmap: BlockMap);
8
+ get record(): unknown;
5
9
  }
6
- export declare function iterateAtpCar(buf: Uint8Array): Generator<RepoEntry>;
10
+ export declare function iterateAtpRepo(buf: Uint8Array): Generator<RepoEntry>;
11
+ /** @deprecated Use `iterateAtpRepo` instead */
12
+ export declare const iterateAtpCar: typeof iterateAtpRepo;
13
+ type BlockMap = Map<string, Uint8Array>;
14
+ export {};
@@ -2,20 +2,38 @@ import * as CBOR from '@atcute/cbor';
2
2
  import * as CID from '@atcute/cid';
3
3
  import { fromUint8Array } from './reader.js';
4
4
  const decoder = new TextDecoder();
5
- export function* iterateAtpCar(buf) {
5
+ export class RepoEntry {
6
+ collection;
7
+ rkey;
8
+ cid;
9
+ blockmap;
10
+ constructor(collection, rkey, cid, blockmap) {
11
+ this.collection = collection;
12
+ this.rkey = rkey;
13
+ this.cid = cid;
14
+ this.blockmap = blockmap;
15
+ }
16
+ get record() {
17
+ return readObject(this.blockmap, this.cid);
18
+ }
19
+ }
20
+ export function* iterateAtpRepo(buf) {
6
21
  const { roots, iterate } = fromUint8Array(new Uint8Array(buf));
7
22
  assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
23
+ // Collect all archive entries into a mapping of CID string -> actual bytes
8
24
  const blockmap = new Map();
9
25
  for (const entry of iterate()) {
10
26
  blockmap.set(CID.format(entry.cid), entry.bytes);
11
27
  }
28
+ // Read the head, then walk through the MST tree from there.
12
29
  const commit = readObject(blockmap, roots[0]);
13
30
  for (const { key, cid } of walkEntries(blockmap, commit.data)) {
14
31
  const [collection, rkey] = key.split('/');
15
- const record = readObject(blockmap, cid);
16
- yield { collection, rkey, record };
32
+ yield new RepoEntry(collection, rkey, cid, blockmap);
17
33
  }
18
34
  }
35
+ /** @deprecated Use `iterateAtpRepo` instead */
36
+ export const iterateAtpCar = iterateAtpRepo;
19
37
  function readObject(map, link) {
20
38
  const cid = link.$link;
21
39
  const bytes = map.get(cid);
@@ -1 +1 @@
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,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAQlC,MAAM,SAAS,CAAC,CAAC,aAAa,CAAC,GAAe;IAC7C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,gDAAgD,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAE3F,MAAM,QAAQ,GAAa,IAAI,GAAG,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,EAAE,CAAC;QAC/B,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CA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CAAC;AAED,SAAS,MAAM,CAAC,SAAkB,EAAE,OAAe;IAClD,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { iterateAtpCar, type RepoEntry } from './atproto-repo.js';
2
- export { fromUint8Array } from './reader.js';
1
+ export { iterateAtpCar, iterateAtpRepo, type RepoEntry } from './atproto-repo.js';
2
+ export { fromUint8Array, readCar } from './reader.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { iterateAtpCar } from './atproto-repo.js';
2
- export { fromUint8Array } from './reader.js';
1
+ export { iterateAtpCar, iterateAtpRepo } from './atproto-repo.js';
2
+ export { fromUint8Array, readCar } from './reader.js';
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAkB,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/reader.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ export declare const readCar: (buffer: Uint8Array) => {
2
+ roots: import("@atcute/cbor").CIDLink[];
3
+ iterate(): Generator<{
4
+ cid: import("@atcute/cid").CID;
5
+ bytes: Uint8Array;
6
+ }>;
7
+ };
8
+ /** @deprecated Use `readCar` instead */
1
9
  export declare const fromUint8Array: (buffer: Uint8Array) => {
2
10
  roots: import("@atcute/cbor").CIDLink[];
3
11
  iterate(): Generator<{
package/dist/reader.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { createUint8Reader } from './utilities/byte-reader.js';
2
2
  import { createCarReader } from './utilities/sync-car-reader.js';
3
- export const fromUint8Array = (buffer) => {
3
+ export const readCar = (buffer) => {
4
4
  const reader = createUint8Reader(buffer);
5
5
  return createCarReader(reader);
6
6
  };
7
+ /** @deprecated Use `readCar` instead */
8
+ export const fromUint8Array = readCar;
7
9
  //# sourceMappingURL=reader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reader.js","sourceRoot":"","sources":["../lib/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAkB,EAAE,EAAE;IACpD,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC"}
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../lib/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAkB,EAAE,EAAE;IAC7C,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@atcute/car",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "read AT Protocol's CAR (content-addressable archive) repositories",
6
6
  "license": "MIT",
7
7
  "repository": {