icechunk-js 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -895,6 +895,8 @@ declare class Repository {
895
895
  flushedAt: Date;
896
896
  metadata: Record<string, unknown>;
897
897
  }>;
898
+ /** v2 snapshots record ancestry only in the repo file. */
899
+ private resolveParentFromRepoInfo;
898
900
  /**
899
901
  * Get the storage backend.
900
902
  */
package/dist/index.d.ts CHANGED
@@ -895,6 +895,8 @@ declare class Repository {
895
895
  flushedAt: Date;
896
896
  metadata: Record<string, unknown>;
897
897
  }>;
898
+ /** v2 snapshots record ancestry only in the repo file. */
899
+ private resolveParentFromRepoInfo;
898
900
  /**
899
901
  * Get the storage backend.
900
902
  */
package/dist/index.js CHANGED
@@ -1362,6 +1362,33 @@ function listTagsFromRepo(parsedRepo) {
1362
1362
  const { repo } = parsedRepo;
1363
1363
  return listRefs((i) => repo.tags(i), repo.tagsLength());
1364
1364
  }
1365
+ var snapshotIndexCache = /* @__PURE__ */ new WeakMap();
1366
+ function snapshotIndexById(parsedRepo) {
1367
+ let index = snapshotIndexCache.get(parsedRepo);
1368
+ if (!index) {
1369
+ index = /* @__PURE__ */ new Map();
1370
+ for (let i = 0; i < parsedRepo.snapshotsLength; i++) {
1371
+ index.set(bytesKey(getSnapshotIdByIndex(parsedRepo, i)), i);
1372
+ }
1373
+ snapshotIndexCache.set(parsedRepo, index);
1374
+ }
1375
+ return index;
1376
+ }
1377
+ function bytesKey(bytes) {
1378
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
1379
+ }
1380
+ function resolveSnapshotParent(parsedRepo, snapshotId) {
1381
+ const index = snapshotIndexById(parsedRepo).get(bytesKey(snapshotId));
1382
+ if (index === void 0) return void 0;
1383
+ const parentOffset = parsedRepo.repo.snapshots(index).parentOffset();
1384
+ if (parentOffset === -1) return null;
1385
+ if (parentOffset < 0 || parentOffset >= parsedRepo.snapshotsLength) {
1386
+ throw new Error(
1387
+ `Invalid parent offset ${parentOffset} for snapshot at index ${index}, snapshots array has ${parsedRepo.snapshotsLength} entries`
1388
+ );
1389
+ }
1390
+ return getSnapshotIdByIndex(parsedRepo, parentOffset);
1391
+ }
1365
1392
 
1366
1393
  // src/cache/lru.ts
1367
1394
  var LRUCache = class {
@@ -4014,18 +4041,37 @@ var Repository = class _Repository {
4014
4041
  */
4015
4042
  async *walkHistory(session, options) {
4016
4043
  let current = session;
4044
+ const seen = /* @__PURE__ */ new Set();
4017
4045
  while (current) {
4046
+ const id = encodeObjectId12(current.getSnapshotId());
4047
+ if (seen.has(id)) {
4048
+ throw new Error(`Cycle in snapshot history at ${id}`);
4049
+ }
4050
+ seen.add(id);
4018
4051
  yield {
4019
- id: encodeObjectId12(current.getSnapshotId()),
4052
+ id,
4020
4053
  message: current.getMessage(),
4021
4054
  flushedAt: current.getFlushedAt(),
4022
4055
  metadata: current.getSnapshotMetadata()
4023
4056
  };
4024
- const parentId = current.getParentSnapshotId();
4057
+ const parentId = current.getParentSnapshotId() ?? await this.resolveParentFromRepoInfo(current, options);
4025
4058
  if (!parentId) break;
4026
4059
  current = await this.checkoutSnapshot(parentId, options);
4027
4060
  }
4028
4061
  }
4062
+ /** v2 snapshots record ancestry only in the repo file. */
4063
+ async resolveParentFromRepoInfo(session, options) {
4064
+ const repoInfo = await this.loadRepoInfo(options);
4065
+ if (!repoInfo) return null;
4066
+ const snapshotId = session.getSnapshotId();
4067
+ const parent = resolveSnapshotParent(repoInfo, snapshotId);
4068
+ if (parent === void 0) {
4069
+ throw new Error(
4070
+ `Snapshot ${encodeObjectId12(snapshotId)} not found in repo info`
4071
+ );
4072
+ }
4073
+ return parent;
4074
+ }
4029
4075
  /**
4030
4076
  * Get the storage backend.
4031
4077
  */