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.cjs +48 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1415,6 +1415,33 @@ function listTagsFromRepo(parsedRepo) {
|
|
|
1415
1415
|
const { repo } = parsedRepo;
|
|
1416
1416
|
return listRefs((i) => repo.tags(i), repo.tagsLength());
|
|
1417
1417
|
}
|
|
1418
|
+
var snapshotIndexCache = /* @__PURE__ */ new WeakMap();
|
|
1419
|
+
function snapshotIndexById(parsedRepo) {
|
|
1420
|
+
let index = snapshotIndexCache.get(parsedRepo);
|
|
1421
|
+
if (!index) {
|
|
1422
|
+
index = /* @__PURE__ */ new Map();
|
|
1423
|
+
for (let i = 0; i < parsedRepo.snapshotsLength; i++) {
|
|
1424
|
+
index.set(bytesKey(getSnapshotIdByIndex(parsedRepo, i)), i);
|
|
1425
|
+
}
|
|
1426
|
+
snapshotIndexCache.set(parsedRepo, index);
|
|
1427
|
+
}
|
|
1428
|
+
return index;
|
|
1429
|
+
}
|
|
1430
|
+
function bytesKey(bytes) {
|
|
1431
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1432
|
+
}
|
|
1433
|
+
function resolveSnapshotParent(parsedRepo, snapshotId) {
|
|
1434
|
+
const index = snapshotIndexById(parsedRepo).get(bytesKey(snapshotId));
|
|
1435
|
+
if (index === void 0) return void 0;
|
|
1436
|
+
const parentOffset = parsedRepo.repo.snapshots(index).parentOffset();
|
|
1437
|
+
if (parentOffset === -1) return null;
|
|
1438
|
+
if (parentOffset < 0 || parentOffset >= parsedRepo.snapshotsLength) {
|
|
1439
|
+
throw new Error(
|
|
1440
|
+
`Invalid parent offset ${parentOffset} for snapshot at index ${index}, snapshots array has ${parsedRepo.snapshotsLength} entries`
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
return getSnapshotIdByIndex(parsedRepo, parentOffset);
|
|
1444
|
+
}
|
|
1418
1445
|
|
|
1419
1446
|
// src/cache/lru.ts
|
|
1420
1447
|
var LRUCache = class {
|
|
@@ -4067,18 +4094,37 @@ var Repository = class _Repository {
|
|
|
4067
4094
|
*/
|
|
4068
4095
|
async *walkHistory(session, options) {
|
|
4069
4096
|
let current = session;
|
|
4097
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4070
4098
|
while (current) {
|
|
4099
|
+
const id = encodeObjectId12(current.getSnapshotId());
|
|
4100
|
+
if (seen.has(id)) {
|
|
4101
|
+
throw new Error(`Cycle in snapshot history at ${id}`);
|
|
4102
|
+
}
|
|
4103
|
+
seen.add(id);
|
|
4071
4104
|
yield {
|
|
4072
|
-
id
|
|
4105
|
+
id,
|
|
4073
4106
|
message: current.getMessage(),
|
|
4074
4107
|
flushedAt: current.getFlushedAt(),
|
|
4075
4108
|
metadata: current.getSnapshotMetadata()
|
|
4076
4109
|
};
|
|
4077
|
-
const parentId = current.getParentSnapshotId();
|
|
4110
|
+
const parentId = current.getParentSnapshotId() ?? await this.resolveParentFromRepoInfo(current, options);
|
|
4078
4111
|
if (!parentId) break;
|
|
4079
4112
|
current = await this.checkoutSnapshot(parentId, options);
|
|
4080
4113
|
}
|
|
4081
4114
|
}
|
|
4115
|
+
/** v2 snapshots record ancestry only in the repo file. */
|
|
4116
|
+
async resolveParentFromRepoInfo(session, options) {
|
|
4117
|
+
const repoInfo = await this.loadRepoInfo(options);
|
|
4118
|
+
if (!repoInfo) return null;
|
|
4119
|
+
const snapshotId = session.getSnapshotId();
|
|
4120
|
+
const parent = resolveSnapshotParent(repoInfo, snapshotId);
|
|
4121
|
+
if (parent === void 0) {
|
|
4122
|
+
throw new Error(
|
|
4123
|
+
`Snapshot ${encodeObjectId12(snapshotId)} not found in repo info`
|
|
4124
|
+
);
|
|
4125
|
+
}
|
|
4126
|
+
return parent;
|
|
4127
|
+
}
|
|
4082
4128
|
/**
|
|
4083
4129
|
* Get the storage backend.
|
|
4084
4130
|
*/
|