@atproto/repo 0.3.6 → 0.3.7

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/dist/index.js CHANGED
@@ -8866,30 +8866,292 @@ var require_dist = __commonJS({
8866
8866
  }
8867
8867
  });
8868
8868
 
8869
- // ../../node_modules/.pnpm/node-gyp-build-optional-packages@5.0.3/node_modules/node-gyp-build-optional-packages/index.js
8869
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/process.js
8870
+ var require_process = __commonJS({
8871
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/process.js"(exports, module2) {
8872
+ "use strict";
8873
+ var isLinux = () => process.platform === "linux";
8874
+ var report = null;
8875
+ var getReport = () => {
8876
+ if (!report) {
8877
+ report = isLinux() && process.report ? process.report.getReport() : {};
8878
+ }
8879
+ return report;
8880
+ };
8881
+ module2.exports = { isLinux, getReport };
8882
+ }
8883
+ });
8884
+
8885
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/filesystem.js
8886
+ var require_filesystem = __commonJS({
8887
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/filesystem.js"(exports, module2) {
8888
+ "use strict";
8889
+ var fs3 = require("fs");
8890
+ var LDD_PATH = "/usr/bin/ldd";
8891
+ var readFileSync = (path) => fs3.readFileSync(path, "utf-8");
8892
+ var readFile = (path) => new Promise((resolve, reject) => {
8893
+ fs3.readFile(path, "utf-8", (err, data) => {
8894
+ if (err) {
8895
+ reject(err);
8896
+ } else {
8897
+ resolve(data);
8898
+ }
8899
+ });
8900
+ });
8901
+ module2.exports = {
8902
+ LDD_PATH,
8903
+ readFileSync,
8904
+ readFile
8905
+ };
8906
+ }
8907
+ });
8908
+
8909
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/detect-libc.js
8910
+ var require_detect_libc = __commonJS({
8911
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/detect-libc.js"(exports, module2) {
8912
+ "use strict";
8913
+ var childProcess = require("child_process");
8914
+ var { isLinux, getReport } = require_process();
8915
+ var { LDD_PATH, readFile, readFileSync } = require_filesystem();
8916
+ var cachedFamilyFilesystem;
8917
+ var cachedVersionFilesystem;
8918
+ var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
8919
+ var commandOut = "";
8920
+ var safeCommand = () => {
8921
+ if (!commandOut) {
8922
+ return new Promise((resolve) => {
8923
+ childProcess.exec(command, (err, out) => {
8924
+ commandOut = err ? " " : out;
8925
+ resolve(commandOut);
8926
+ });
8927
+ });
8928
+ }
8929
+ return commandOut;
8930
+ };
8931
+ var safeCommandSync = () => {
8932
+ if (!commandOut) {
8933
+ try {
8934
+ commandOut = childProcess.execSync(command, { encoding: "utf8" });
8935
+ } catch (_err) {
8936
+ commandOut = " ";
8937
+ }
8938
+ }
8939
+ return commandOut;
8940
+ };
8941
+ var GLIBC = "glibc";
8942
+ var RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/;
8943
+ var MUSL = "musl";
8944
+ var GLIBC_ON_LDD = GLIBC.toUpperCase();
8945
+ var MUSL_ON_LDD = MUSL.toLowerCase();
8946
+ var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
8947
+ var familyFromReport = () => {
8948
+ const report = getReport();
8949
+ if (report.header && report.header.glibcVersionRuntime) {
8950
+ return GLIBC;
8951
+ }
8952
+ if (Array.isArray(report.sharedObjects)) {
8953
+ if (report.sharedObjects.some(isFileMusl)) {
8954
+ return MUSL;
8955
+ }
8956
+ }
8957
+ return null;
8958
+ };
8959
+ var familyFromCommand = (out) => {
8960
+ const [getconf, ldd1] = out.split(/[\r\n]+/);
8961
+ if (getconf && getconf.includes(GLIBC)) {
8962
+ return GLIBC;
8963
+ }
8964
+ if (ldd1 && ldd1.includes(MUSL)) {
8965
+ return MUSL;
8966
+ }
8967
+ return null;
8968
+ };
8969
+ var getFamilyFromLddContent = (content) => {
8970
+ if (content.includes(MUSL_ON_LDD)) {
8971
+ return MUSL;
8972
+ }
8973
+ if (content.includes(GLIBC_ON_LDD)) {
8974
+ return GLIBC;
8975
+ }
8976
+ return null;
8977
+ };
8978
+ var familyFromFilesystem = async () => {
8979
+ if (cachedFamilyFilesystem !== void 0) {
8980
+ return cachedFamilyFilesystem;
8981
+ }
8982
+ cachedFamilyFilesystem = null;
8983
+ try {
8984
+ const lddContent = await readFile(LDD_PATH);
8985
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
8986
+ } catch (e) {
8987
+ }
8988
+ return cachedFamilyFilesystem;
8989
+ };
8990
+ var familyFromFilesystemSync = () => {
8991
+ if (cachedFamilyFilesystem !== void 0) {
8992
+ return cachedFamilyFilesystem;
8993
+ }
8994
+ cachedFamilyFilesystem = null;
8995
+ try {
8996
+ const lddContent = readFileSync(LDD_PATH);
8997
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
8998
+ } catch (e) {
8999
+ }
9000
+ return cachedFamilyFilesystem;
9001
+ };
9002
+ var family = async () => {
9003
+ let family2 = null;
9004
+ if (isLinux()) {
9005
+ family2 = await familyFromFilesystem();
9006
+ if (!family2) {
9007
+ family2 = familyFromReport();
9008
+ }
9009
+ if (!family2) {
9010
+ const out = await safeCommand();
9011
+ family2 = familyFromCommand(out);
9012
+ }
9013
+ }
9014
+ return family2;
9015
+ };
9016
+ var familySync = () => {
9017
+ let family2 = null;
9018
+ if (isLinux()) {
9019
+ family2 = familyFromFilesystemSync();
9020
+ if (!family2) {
9021
+ family2 = familyFromReport();
9022
+ }
9023
+ if (!family2) {
9024
+ const out = safeCommandSync();
9025
+ family2 = familyFromCommand(out);
9026
+ }
9027
+ }
9028
+ return family2;
9029
+ };
9030
+ var isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
9031
+ var isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
9032
+ var versionFromFilesystem = async () => {
9033
+ if (cachedVersionFilesystem !== void 0) {
9034
+ return cachedVersionFilesystem;
9035
+ }
9036
+ cachedVersionFilesystem = null;
9037
+ try {
9038
+ const lddContent = await readFile(LDD_PATH);
9039
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
9040
+ if (versionMatch) {
9041
+ cachedVersionFilesystem = versionMatch[1];
9042
+ }
9043
+ } catch (e) {
9044
+ }
9045
+ return cachedVersionFilesystem;
9046
+ };
9047
+ var versionFromFilesystemSync = () => {
9048
+ if (cachedVersionFilesystem !== void 0) {
9049
+ return cachedVersionFilesystem;
9050
+ }
9051
+ cachedVersionFilesystem = null;
9052
+ try {
9053
+ const lddContent = readFileSync(LDD_PATH);
9054
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
9055
+ if (versionMatch) {
9056
+ cachedVersionFilesystem = versionMatch[1];
9057
+ }
9058
+ } catch (e) {
9059
+ }
9060
+ return cachedVersionFilesystem;
9061
+ };
9062
+ var versionFromReport = () => {
9063
+ const report = getReport();
9064
+ if (report.header && report.header.glibcVersionRuntime) {
9065
+ return report.header.glibcVersionRuntime;
9066
+ }
9067
+ return null;
9068
+ };
9069
+ var versionSuffix = (s) => s.trim().split(/\s+/)[1];
9070
+ var versionFromCommand = (out) => {
9071
+ const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
9072
+ if (getconf && getconf.includes(GLIBC)) {
9073
+ return versionSuffix(getconf);
9074
+ }
9075
+ if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
9076
+ return versionSuffix(ldd2);
9077
+ }
9078
+ return null;
9079
+ };
9080
+ var version2 = async () => {
9081
+ let version3 = null;
9082
+ if (isLinux()) {
9083
+ version3 = await versionFromFilesystem();
9084
+ if (!version3) {
9085
+ version3 = versionFromReport();
9086
+ }
9087
+ if (!version3) {
9088
+ const out = await safeCommand();
9089
+ version3 = versionFromCommand(out);
9090
+ }
9091
+ }
9092
+ return version3;
9093
+ };
9094
+ var versionSync = () => {
9095
+ let version3 = null;
9096
+ if (isLinux()) {
9097
+ version3 = versionFromFilesystemSync();
9098
+ if (!version3) {
9099
+ version3 = versionFromReport();
9100
+ }
9101
+ if (!version3) {
9102
+ const out = safeCommandSync();
9103
+ version3 = versionFromCommand(out);
9104
+ }
9105
+ }
9106
+ return version3;
9107
+ };
9108
+ module2.exports = {
9109
+ GLIBC,
9110
+ MUSL,
9111
+ family,
9112
+ familySync,
9113
+ isNonGlibcLinux,
9114
+ isNonGlibcLinuxSync,
9115
+ version: version2,
9116
+ versionSync
9117
+ };
9118
+ }
9119
+ });
9120
+
9121
+ // ../../node_modules/.pnpm/node-gyp-build-optional-packages@5.1.1/node_modules/node-gyp-build-optional-packages/index.js
8870
9122
  var require_node_gyp_build_optional_packages = __commonJS({
8871
- "../../node_modules/.pnpm/node-gyp-build-optional-packages@5.0.3/node_modules/node-gyp-build-optional-packages/index.js"(exports, module2) {
9123
+ "../../node_modules/.pnpm/node-gyp-build-optional-packages@5.1.1/node_modules/node-gyp-build-optional-packages/index.js"(exports, module2) {
8872
9124
  var fs3 = require("fs");
8873
9125
  var path = require("path");
8874
- var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
9126
+ var url = require("url");
8875
9127
  var vars = process.config && process.config.variables || {};
8876
9128
  var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
8877
- var abi = process.versions.modules;
9129
+ var versions = process.versions;
9130
+ var abi = versions.modules;
9131
+ if (versions.deno || process.isBun) {
9132
+ abi = "unsupported";
9133
+ }
8878
9134
  var runtime = isElectron() ? "electron" : "node";
8879
9135
  var arch = process.arch;
8880
9136
  var platform = process.platform;
8881
- var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
9137
+ var libc = process.env.LIBC || (isMusl(platform) ? "musl" : "glibc");
8882
9138
  var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
8883
- var uv = (process.versions.uv || "").split(".")[0];
9139
+ var uv = (versions.uv || "").split(".")[0];
8884
9140
  module2.exports = load;
8885
9141
  function load(dir) {
8886
- return runtimeRequire(load.path(dir));
9142
+ if (typeof __webpack_require__ === "function")
9143
+ return __non_webpack_require__(load.path(dir));
9144
+ else
9145
+ return require(load.path(dir));
8887
9146
  }
8888
9147
  load.path = function(dir) {
8889
9148
  dir = path.resolve(dir || ".");
8890
- var packageName;
9149
+ var packageName = "";
8891
9150
  try {
8892
- packageName = runtimeRequire(path.join(dir, "package.json")).name;
9151
+ if (typeof __webpack_require__ === "function")
9152
+ packageName = __non_webpack_require__(path.join(dir, "package.json")).name;
9153
+ else
9154
+ packageName = require(path.join(dir, "package.json")).name;
8893
9155
  var varName = packageName.toUpperCase().replace(/-/g, "_") + "_PREBUILD";
8894
9156
  if (process.env[varName])
8895
9157
  dir = process.env[varName];
@@ -8911,7 +9173,7 @@ var require_node_gyp_build_optional_packages = __commonJS({
8911
9173
  return nearby;
8912
9174
  var platformPackage = (packageName[0] == "@" ? "" : "@" + packageName + "/") + packageName + "-" + platform + "-" + arch;
8913
9175
  try {
8914
- var prebuildPackage = path.dirname(require("module").createRequire(path.join(dir, "package.json")).resolve(platformPackage));
9176
+ var prebuildPackage = path.dirname(require("module").createRequire(url.pathToFileURL(path.join(dir, "package.json"))).resolve(platformPackage));
8915
9177
  return resolveFile(prebuildPackage);
8916
9178
  } catch (error) {
8917
9179
  }
@@ -8927,7 +9189,7 @@ var require_node_gyp_build_optional_packages = __commonJS({
8927
9189
  process.versions.electron ? "electron=" + process.versions.electron : "",
8928
9190
  typeof __webpack_require__ === "function" ? "webpack=true" : ""
8929
9191
  ].filter(Boolean).join(" ");
8930
- throw new Error("No native build was found for " + target2 + "\n loaded from: " + dir + " and package: " + platformPackage + "\n");
9192
+ throw new Error("No native build was found for " + target2 + "\n attempted loading from: " + dir + " and package: " + platformPackage + "\n");
8931
9193
  function resolve(dir2) {
8932
9194
  var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
8933
9195
  var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
@@ -9050,8 +9312,11 @@ var require_node_gyp_build_optional_packages = __commonJS({
9050
9312
  return true;
9051
9313
  return typeof window !== "undefined" && window.process && window.process.type === "renderer";
9052
9314
  }
9053
- function isAlpine(platform2) {
9054
- return platform2 === "linux" && fs3.existsSync("/etc/alpine-release");
9315
+ function isMusl(platform2) {
9316
+ if (platform2 !== "linux")
9317
+ return false;
9318
+ const { familySync, MUSL } = require_detect_libc();
9319
+ return familySync() === MUSL;
9055
9320
  }
9056
9321
  load.parseTags = parseTags;
9057
9322
  load.matchTags = matchTags;
@@ -9062,9 +9327,9 @@ var require_node_gyp_build_optional_packages = __commonJS({
9062
9327
  }
9063
9328
  });
9064
9329
 
9065
- // ../../node_modules/.pnpm/cbor-extract@2.1.1/node_modules/cbor-extract/index.js
9330
+ // ../../node_modules/.pnpm/cbor-extract@2.2.0/node_modules/cbor-extract/index.js
9066
9331
  var require_cbor_extract = __commonJS({
9067
- "../../node_modules/.pnpm/cbor-extract@2.1.1/node_modules/cbor-extract/index.js"(exports, module2) {
9332
+ "../../node_modules/.pnpm/cbor-extract@2.2.0/node_modules/cbor-extract/index.js"(exports, module2) {
9068
9333
  module2.exports = require_node_gyp_build_optional_packages()(__dirname);
9069
9334
  }
9070
9335
  });
@@ -10846,7 +11111,7 @@ var require_wait = __commonJS({
10846
11111
  "../../node_modules/.pnpm/thread-stream@2.4.0/node_modules/thread-stream/lib/wait.js"(exports, module2) {
10847
11112
  "use strict";
10848
11113
  var MAX_TIMEOUT = 1e3;
10849
- function wait(state, index, expected, timeout, done) {
11114
+ function wait2(state, index, expected, timeout, done) {
10850
11115
  const max = Date.now() + timeout;
10851
11116
  let current = Atomics.load(state, index);
10852
11117
  if (current === expected) {
@@ -10897,7 +11162,7 @@ var require_wait = __commonJS({
10897
11162
  };
10898
11163
  check2(1);
10899
11164
  }
10900
- module2.exports = { wait, waitDiff };
11165
+ module2.exports = { wait: wait2, waitDiff };
10901
11166
  }
10902
11167
  });
10903
11168
 
@@ -10923,7 +11188,7 @@ var require_thread_stream = __commonJS({
10923
11188
  var { Worker } = require("worker_threads");
10924
11189
  var { join } = require("path");
10925
11190
  var { pathToFileURL } = require("url");
10926
- var { wait } = require_wait();
11191
+ var { wait: wait2 } = require_wait();
10927
11192
  var {
10928
11193
  WRITE_INDEX,
10929
11194
  READ_INDEX
@@ -11148,7 +11413,7 @@ var require_thread_stream = __commonJS({
11148
11413
  return;
11149
11414
  }
11150
11415
  const writeIndex = Atomics.load(this[kImpl].state, WRITE_INDEX);
11151
- wait(this[kImpl].state, READ_INDEX, writeIndex, Infinity, (err, res) => {
11416
+ wait2(this[kImpl].state, READ_INDEX, writeIndex, Infinity, (err, res) => {
11152
11417
  if (err) {
11153
11418
  destroy(this, err);
11154
11419
  process.nextTick(cb, err);
@@ -13151,6 +13416,7 @@ __export(src_exports4, {
13151
13416
  WriteOpAction: () => WriteOpAction,
13152
13417
  blocksToCarFile: () => blocksToCarFile,
13153
13418
  blocksToCarStream: () => blocksToCarStream,
13419
+ carToBlocks: () => carToBlocks,
13154
13420
  cborToLex: () => cborToLex,
13155
13421
  cborToLexRecord: () => cborToLexRecord,
13156
13422
  cidForRecord: () => cidForRecord,
@@ -13159,6 +13425,8 @@ __export(src_exports4, {
13159
13425
  ensureCreates: () => ensureCreates,
13160
13426
  ensureV3Commit: () => ensureV3Commit,
13161
13427
  formatDataKey: () => formatDataKey,
13428
+ getAndParseByDef: () => getAndParseByDef,
13429
+ getAndParseRecord: () => getAndParseRecord,
13162
13430
  getFullRepo: () => getFullRepo,
13163
13431
  getRecords: () => getRecords,
13164
13432
  metaEqual: () => metaEqual,
@@ -13167,7 +13435,9 @@ __export(src_exports4, {
13167
13435
  nodeDataDef: () => nodeDataDef,
13168
13436
  nullDiff: () => nullDiff,
13169
13437
  parseDataKey: () => parseDataKey,
13438
+ parseObjByDef: () => parseObjByDef,
13170
13439
  readCar: () => readCar,
13440
+ readCarStream: () => readCarStream,
13171
13441
  readCarWithRoot: () => readCarWithRoot,
13172
13442
  schema: () => schema2,
13173
13443
  signCommit: () => signCommit,
@@ -22635,14 +22905,14 @@ var unsignedCommit = z.object({
22635
22905
  version: z.literal(3),
22636
22906
  data: schema.cid,
22637
22907
  rev: z.string(),
22638
- prev: schema.cid.nullable().optional()
22908
+ prev: schema.cid.nullable()
22639
22909
  });
22640
22910
  var commit = z.object({
22641
22911
  did: z.string(),
22642
22912
  version: z.literal(3),
22643
22913
  data: schema.cid,
22644
22914
  rev: z.string(),
22645
- prev: schema.cid.nullable().optional(),
22915
+ prev: schema.cid.nullable(),
22646
22916
  sig: schema.bytes
22647
22917
  });
22648
22918
  var legacyV2Commit = z.object({
@@ -23525,7 +23795,7 @@ function weierstrassPoints(opts) {
23525
23795
  const a = point.toAffine();
23526
23796
  return concatBytes2(Uint8Array.from([4]), Fp3.toBytes(a.x), Fp3.toBytes(a.y));
23527
23797
  });
23528
- const fromBytes = CURVE.fromBytes || ((bytes3) => {
23798
+ const fromBytes2 = CURVE.fromBytes || ((bytes3) => {
23529
23799
  const tail = bytes3.subarray(1);
23530
23800
  const x = Fp3.fromBytes(tail.subarray(0, Fp3.BYTES));
23531
23801
  const y = Fp3.fromBytes(tail.subarray(Fp3.BYTES, 2 * Fp3.BYTES));
@@ -23605,7 +23875,7 @@ function weierstrassPoints(opts) {
23605
23875
  return points.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
23606
23876
  }
23607
23877
  static fromHex(hex) {
23608
- const P = Point2.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
23878
+ const P = Point2.fromAffine(fromBytes2(ensureBytes("pointHex", hex)));
23609
23879
  P.assertValidity();
23610
23880
  return P;
23611
23881
  }
@@ -24801,9 +25071,12 @@ var UnexpectedObjectError = class extends Error {
24801
25071
  }
24802
25072
  };
24803
25073
 
25074
+ // src/util.ts
25075
+ var import_promises = require("node:timers/promises");
25076
+
24804
25077
  // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/reader.js
24805
25078
  var import_fs = __toESM(require("fs"), 1);
24806
- var import_util7 = require("util");
25079
+ var import_util8 = require("util");
24807
25080
 
24808
25081
  // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/decoder.js
24809
25082
  var import_varint2 = __toESM(require_varint(), 1);
@@ -25013,13 +25286,15 @@ function asyncIterableReader(asyncIterable) {
25013
25286
  return chunkReader(readChunk);
25014
25287
  }
25015
25288
 
25016
- // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/reader-browser.js
25017
- var CarReader = class {
25018
- constructor(version2, roots, blocks) {
25289
+ // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/reader.js
25290
+ var fsread = (0, import_util8.promisify)(import_fs.default.read);
25291
+
25292
+ // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/indexer.js
25293
+ var CarIndexer = class {
25294
+ constructor(version2, roots, iterator) {
25019
25295
  this._version = version2;
25020
25296
  this._roots = roots;
25021
- this._blocks = blocks;
25022
- this._keys = blocks.map((b) => b.cid.toString());
25297
+ this._iterator = iterator;
25023
25298
  }
25024
25299
  get version() {
25025
25300
  return this._version;
@@ -25027,73 +25302,120 @@ var CarReader = class {
25027
25302
  async getRoots() {
25028
25303
  return this._roots;
25029
25304
  }
25030
- async has(key) {
25031
- return this._keys.indexOf(key.toString()) > -1;
25032
- }
25033
- async get(key) {
25034
- const index = this._keys.indexOf(key.toString());
25035
- return index > -1 ? this._blocks[index] : void 0;
25036
- }
25037
- async *blocks() {
25038
- for (const block of this._blocks) {
25039
- yield block;
25040
- }
25041
- }
25042
- async *cids() {
25043
- for (const block of this._blocks) {
25044
- yield block.cid;
25045
- }
25305
+ [Symbol.asyncIterator]() {
25306
+ return this._iterator;
25046
25307
  }
25047
25308
  static async fromBytes(bytes3) {
25048
25309
  if (!(bytes3 instanceof Uint8Array)) {
25049
25310
  throw new TypeError("fromBytes() requires a Uint8Array");
25050
25311
  }
25051
- return decodeReaderComplete(bytesReader(bytes3));
25312
+ return decodeIndexerComplete(bytesReader(bytes3));
25052
25313
  }
25053
25314
  static async fromIterable(asyncIterable) {
25054
25315
  if (!asyncIterable || !(typeof asyncIterable[Symbol.asyncIterator] === "function")) {
25055
25316
  throw new TypeError("fromIterable() requires an async iterable");
25056
25317
  }
25057
- return decodeReaderComplete(asyncIterableReader(asyncIterable));
25318
+ return decodeIndexerComplete(asyncIterableReader(asyncIterable));
25058
25319
  }
25059
25320
  };
25060
- async function decodeReaderComplete(reader) {
25321
+ async function decodeIndexerComplete(reader) {
25061
25322
  const decoder2 = createDecoder(reader);
25062
25323
  const { version: version2, roots } = await decoder2.header();
25063
- const blocks = [];
25064
- for await (const block of decoder2.blocks()) {
25065
- blocks.push(block);
25066
- }
25067
- return new CarReader(version2, roots, blocks);
25324
+ return new CarIndexer(version2, roots, decoder2.blocksIndex());
25068
25325
  }
25069
25326
 
25070
- // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/reader.js
25071
- var fsread = (0, import_util7.promisify)(import_fs.default.read);
25072
- var CarReader2 = class extends CarReader {
25073
- static async readRaw(fd, blockIndex) {
25074
- const { cid: cid2, blockLength, blockOffset } = blockIndex;
25075
- const bytes3 = new Uint8Array(blockLength);
25076
- let read3;
25077
- if (typeof fd === "number") {
25078
- read3 = (await fsread(fd, bytes3, 0, blockLength, blockOffset)).bytesRead;
25079
- } else if (typeof fd === "object" && typeof fd.read === "function") {
25080
- read3 = (await fd.read(bytes3, 0, blockLength, blockOffset)).bytesRead;
25081
- } else {
25082
- throw new TypeError("Bad fd");
25327
+ // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/iterator.js
25328
+ var CarIteratorBase = class {
25329
+ constructor(version2, roots, iterable) {
25330
+ this._version = version2;
25331
+ this._roots = roots;
25332
+ this._iterable = iterable;
25333
+ this._decoded = false;
25334
+ }
25335
+ get version() {
25336
+ return this._version;
25337
+ }
25338
+ async getRoots() {
25339
+ return this._roots;
25340
+ }
25341
+ };
25342
+ var CarBlockIterator = class extends CarIteratorBase {
25343
+ [Symbol.asyncIterator]() {
25344
+ if (this._decoded) {
25345
+ throw new Error("Cannot decode more than once");
25346
+ }
25347
+ if (!this._iterable) {
25348
+ throw new Error("Block iterable not found");
25349
+ }
25350
+ this._decoded = true;
25351
+ return this._iterable[Symbol.asyncIterator]();
25352
+ }
25353
+ static async fromBytes(bytes3) {
25354
+ const { version: version2, roots, iterator } = await fromBytes(bytes3);
25355
+ return new CarBlockIterator(version2, roots, iterator);
25356
+ }
25357
+ static async fromIterable(asyncIterable) {
25358
+ const { version: version2, roots, iterator } = await fromIterable(asyncIterable);
25359
+ return new CarBlockIterator(version2, roots, iterator);
25360
+ }
25361
+ };
25362
+ var CarCIDIterator = class extends CarIteratorBase {
25363
+ [Symbol.asyncIterator]() {
25364
+ if (this._decoded) {
25365
+ throw new Error("Cannot decode more than once");
25083
25366
  }
25084
- if (read3 !== blockLength) {
25085
- throw new Error(`Failed to read entire block (${read3} instead of ${blockLength})`);
25367
+ if (!this._iterable) {
25368
+ throw new Error("Block iterable not found");
25086
25369
  }
25370
+ this._decoded = true;
25371
+ const iterable = this._iterable[Symbol.asyncIterator]();
25087
25372
  return {
25088
- cid: cid2,
25089
- bytes: bytes3
25373
+ async next() {
25374
+ const next = await iterable.next();
25375
+ if (next.done) {
25376
+ return next;
25377
+ }
25378
+ return {
25379
+ done: false,
25380
+ value: next.value.cid
25381
+ };
25382
+ }
25090
25383
  };
25091
25384
  }
25385
+ static async fromBytes(bytes3) {
25386
+ const { version: version2, roots, iterator } = await fromBytes(bytes3);
25387
+ return new CarCIDIterator(version2, roots, iterator);
25388
+ }
25389
+ static async fromIterable(asyncIterable) {
25390
+ const { version: version2, roots, iterator } = await fromIterable(asyncIterable);
25391
+ return new CarCIDIterator(version2, roots, iterator);
25392
+ }
25092
25393
  };
25394
+ async function fromBytes(bytes3) {
25395
+ if (!(bytes3 instanceof Uint8Array)) {
25396
+ throw new TypeError("fromBytes() requires a Uint8Array");
25397
+ }
25398
+ return decodeIterator(bytesReader(bytes3));
25399
+ }
25400
+ async function fromIterable(asyncIterable) {
25401
+ if (!asyncIterable || !(typeof asyncIterable[Symbol.asyncIterator] === "function")) {
25402
+ throw new TypeError("fromIterable() requires an async iterable");
25403
+ }
25404
+ return decodeIterator(asyncIterableReader(asyncIterable));
25405
+ }
25406
+ async function decodeIterator(reader) {
25407
+ const decoder2 = createDecoder(reader);
25408
+ const { version: version2, roots } = await decoder2.header();
25409
+ return {
25410
+ version: version2,
25411
+ roots,
25412
+ iterator: decoder2.blocks()
25413
+ };
25414
+ }
25093
25415
 
25094
25416
  // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/writer.js
25095
25417
  var import_fs2 = __toESM(require("fs"), 1);
25096
- var import_util8 = require("util");
25418
+ var import_util9 = require("util");
25097
25419
 
25098
25420
  // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/encoder.js
25099
25421
  var import_varint3 = __toESM(require_varint(), 1);
@@ -25308,8 +25630,8 @@ function toRoots(roots) {
25308
25630
  }
25309
25631
 
25310
25632
  // ../../node_modules/.pnpm/@ipld+car@3.2.3/node_modules/@ipld/car/esm/lib/writer.js
25311
- var fsread2 = (0, import_util8.promisify)(import_fs2.default.read);
25312
- var fswrite = (0, import_util8.promisify)(import_fs2.default.write);
25633
+ var fsread2 = (0, import_util9.promisify)(import_fs2.default.read);
25634
+ var fswrite = (0, import_util9.promisify)(import_fs2.default.write);
25313
25635
  var CarWriter2 = class extends CarWriter {
25314
25636
  static async updateRootsInFile(fd, roots) {
25315
25637
  const chunkSize = 256;
@@ -25374,18 +25696,26 @@ var blocksToCarFile = (root, blocks) => {
25374
25696
  const carStream = blocksToCarStream(root, blocks);
25375
25697
  return streamToBuffer(carStream);
25376
25698
  };
25377
- var readCar = async (bytes3) => {
25378
- const car = await CarReader2.fromBytes(bytes3);
25699
+ var carToBlocks = async (car) => {
25379
25700
  const roots = await car.getRoots();
25380
25701
  const blocks = new block_map_default();
25381
- for await (const block of verifyIncomingCarBlocks(car.blocks())) {
25702
+ for await (const block of verifyIncomingCarBlocks(car)) {
25382
25703
  blocks.set(block.cid, block.bytes);
25704
+ await (0, import_promises.setImmediate)();
25383
25705
  }
25384
25706
  return {
25385
25707
  roots,
25386
25708
  blocks
25387
25709
  };
25388
25710
  };
25711
+ var readCar = async (bytes3) => {
25712
+ const car = await CarBlockIterator.fromBytes(bytes3);
25713
+ return carToBlocks(car);
25714
+ };
25715
+ var readCarStream = async (stream) => {
25716
+ const car = await CarBlockIterator.fromIterable(stream);
25717
+ return carToBlocks(car);
25718
+ };
25389
25719
  var readCarWithRoot = async (bytes3) => {
25390
25720
  const { roots, blocks } = await readCar(bytes3);
25391
25721
  if (roots.length !== 1) {
@@ -25397,29 +25727,25 @@ var readCarWithRoot = async (bytes3) => {
25397
25727
  blocks
25398
25728
  };
25399
25729
  };
25400
- var diffToWriteDescripts = (diff, blocks) => {
25730
+ var diffToWriteDescripts = (diff) => {
25401
25731
  return Promise.all([
25402
25732
  ...diff.addList().map(async (add) => {
25403
25733
  const { collection, rkey } = parseDataKey(add.key);
25404
- const value = await getAndParseRecord(blocks, add.cid);
25405
25734
  return {
25406
25735
  action: "create" /* Create */,
25407
25736
  collection,
25408
25737
  rkey,
25409
- cid: add.cid,
25410
- record: value.record
25738
+ cid: add.cid
25411
25739
  };
25412
25740
  }),
25413
25741
  ...diff.updateList().map(async (upd) => {
25414
25742
  const { collection, rkey } = parseDataKey(upd.key);
25415
- const value = await getAndParseRecord(blocks, upd.cid);
25416
25743
  return {
25417
25744
  action: "update" /* Update */,
25418
25745
  collection,
25419
25746
  rkey,
25420
25747
  cid: upd.cid,
25421
- prev: upd.prev,
25422
- record: value.record
25748
+ prev: upd.prev
25423
25749
  };
25424
25750
  }),
25425
25751
  ...diff.deleteList().map((del) => {
@@ -26390,6 +26716,13 @@ var ReadableRepo = class {
26390
26716
  get version() {
26391
26717
  return this.commit.version;
26392
26718
  }
26719
+ async *walkRecords(from3) {
26720
+ for await (const leaf of this.data.walkLeavesFrom(from3 ?? "")) {
26721
+ const { collection, rkey } = parseDataKey(leaf.key);
26722
+ const record = await this.storage.readRecord(leaf.value);
26723
+ yield { collection, rkey, cid: leaf.value, record };
26724
+ }
26725
+ }
26393
26726
  async getRecord(collection, rkey) {
26394
26727
  const dataKey = collection + "/" + rkey;
26395
26728
  const cid2 = await this.data.get(dataKey);
@@ -26532,6 +26865,29 @@ var Repo = class extends ReadableRepo {
26532
26865
  const commit2 = await this.formatCommit(toWrite, keypair);
26533
26866
  return this.applyCommit(commit2);
26534
26867
  }
26868
+ async formatResignCommit(rev, keypair) {
26869
+ const commit2 = await signCommit({
26870
+ did: this.did,
26871
+ version: 3,
26872
+ rev,
26873
+ prev: null,
26874
+ data: this.commit.data
26875
+ }, keypair);
26876
+ const newBlocks = new block_map_default();
26877
+ const commitCid = await newBlocks.add(commit2);
26878
+ return {
26879
+ cid: commitCid,
26880
+ rev,
26881
+ since: null,
26882
+ prev: null,
26883
+ newBlocks,
26884
+ removedCids: new cid_set_default([this.cid])
26885
+ };
26886
+ }
26887
+ async resignCommit(rev, keypair) {
26888
+ const formatted = await this.formatResignCommit(rev, keypair);
26889
+ return this.applyCommit(formatted);
26890
+ }
26535
26891
  };
26536
26892
 
26537
26893
  // src/storage/readable-blockstore.ts
@@ -26575,6 +26931,7 @@ var MemoryBlockstore = class extends readable_blockstore_default {
26575
26931
  constructor(blocks) {
26576
26932
  super();
26577
26933
  this.root = null;
26934
+ this.rev = null;
26578
26935
  this.blocks = new block_map_default();
26579
26936
  if (blocks) {
26580
26937
  this.blocks.addMap(blocks);
@@ -26598,8 +26955,9 @@ var MemoryBlockstore = class extends readable_blockstore_default {
26598
26955
  async putMany(blocks) {
26599
26956
  this.blocks.addMap(blocks);
26600
26957
  }
26601
- async updateRoot(cid2) {
26958
+ async updateRoot(cid2, rev) {
26602
26959
  this.root = cid2;
26960
+ this.rev = rev;
26603
26961
  }
26604
26962
  async applyCommit(commit2) {
26605
26963
  this.root = commit2.cid;
@@ -26660,27 +27018,28 @@ var verifyRepoCar = async (carBytes, did2, signingKey) => {
26660
27018
  const car = await readCarWithRoot(carBytes);
26661
27019
  return verifyRepo(car.blocks, car.root, did2, signingKey);
26662
27020
  };
26663
- var verifyRepo = async (blocks, head, did2, signingKey) => {
26664
- const diff = await verifyDiff(null, blocks, head, did2, signingKey);
27021
+ var verifyRepo = async (blocks, head, did2, signingKey, opts) => {
27022
+ const diff = await verifyDiff(null, blocks, head, did2, signingKey, opts);
26665
27023
  const creates = ensureCreates(diff.writes);
26666
27024
  return {
26667
27025
  creates,
26668
27026
  commit: diff.commit
26669
27027
  };
26670
27028
  };
26671
- var verifyDiffCar = async (repo, carBytes, did2, signingKey) => {
27029
+ var verifyDiffCar = async (repo, carBytes, did2, signingKey, opts) => {
26672
27030
  const car = await readCarWithRoot(carBytes);
26673
- return verifyDiff(repo, car.blocks, car.root, did2, signingKey);
27031
+ return verifyDiff(repo, car.blocks, car.root, did2, signingKey, opts);
26674
27032
  };
26675
- var verifyDiff = async (repo, updateBlocks, updateRoot, did2, signingKey) => {
27033
+ var verifyDiff = async (repo, updateBlocks, updateRoot, did2, signingKey, opts) => {
27034
+ const { ensureLeaves = true } = opts ?? {};
26676
27035
  const stagedStorage = new MemoryBlockstore(updateBlocks);
26677
27036
  const updateStorage = repo ? new SyncStorage(stagedStorage, repo.storage) : stagedStorage;
26678
27037
  const updated = await verifyRepoRoot(updateStorage, updateRoot, did2, signingKey);
26679
27038
  const diff = await data_diff_default.of(updated.data, repo?.data ?? null);
26680
- const writes = await diffToWriteDescripts(diff, updateBlocks);
27039
+ const writes = await diffToWriteDescripts(diff);
26681
27040
  const newBlocks = diff.newMstBlocks;
26682
27041
  const leaves = updateBlocks.getMany(diff.newLeafCids.toList());
26683
- if (leaves.missing.length > 0) {
27042
+ if (leaves.missing.length > 0 && ensureLeaves) {
26684
27043
  throw new Error(`missing leaf blocks: ${leaves.missing}`);
26685
27044
  }
26686
27045
  newBlocks.addMap(leaves.blocks);
@@ -26826,6 +27185,7 @@ var getRecords = (storage, commitCid, paths) => {
26826
27185
  WriteOpAction,
26827
27186
  blocksToCarFile,
26828
27187
  blocksToCarStream,
27188
+ carToBlocks,
26829
27189
  cborToLex,
26830
27190
  cborToLexRecord,
26831
27191
  cidForRecord,
@@ -26834,6 +27194,8 @@ var getRecords = (storage, commitCid, paths) => {
26834
27194
  ensureCreates,
26835
27195
  ensureV3Commit,
26836
27196
  formatDataKey,
27197
+ getAndParseByDef,
27198
+ getAndParseRecord,
26837
27199
  getFullRepo,
26838
27200
  getRecords,
26839
27201
  metaEqual,
@@ -26842,7 +27204,9 @@ var getRecords = (storage, commitCid, paths) => {
26842
27204
  nodeDataDef,
26843
27205
  nullDiff,
26844
27206
  parseDataKey,
27207
+ parseObjByDef,
26845
27208
  readCar,
27209
+ readCarStream,
26846
27210
  readCarWithRoot,
26847
27211
  schema,
26848
27212
  signCommit,