@gscdump/lakehouse 7.11.0 → 7.11.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/README.md CHANGED
@@ -206,6 +206,8 @@ The caller owns the target and excludes concurrent writers through settlement.
206
206
 
207
207
  Supply the saved metadata location, SHA-256, table UUID, head snapshot ID, and complete snapshot ID inventory.
208
208
  The operation checks the target, saved metadata bytes, and identity before registration.
209
+ Metadata can use plain JSON or gzip. The byte limit applies to stored and expanded bytes.
210
+ The SHA-256 always authenticates the stored object bytes before decompression.
209
211
  It registers with `overwrite: false` and verifies the returned identity.
210
212
  Existing tables produce `target-exists`, including tables with matching saved identities.
211
213
  Malformed bytes or mismatched identities produce `backup-invalid` before registration.
@@ -10,7 +10,7 @@ export interface RestoreIcebergTableOptions {
10
10
  snapshotIds: readonly string[];
11
11
  /** The caller excludes writers and owns the target through settlement. */
12
12
  confirmAuthority: () => Promise<boolean>;
13
- /** Defaults to 16 MiB. The maximum is 64 MiB. */
13
+ /** Bounds stored and expanded metadata. Defaults to 16 MiB. The maximum is 64 MiB. */
14
14
  maxMetadataBytes?: number;
15
15
  cache?: CatalogCache;
16
16
  }
@@ -16,6 +16,35 @@ function matchesBackup(loaded, options) {
16
16
  const head = rawHead == null || String(rawHead) === "-1" ? null : String(rawHead);
17
17
  return loaded.metadataLocation === options.metadataLocation && metadata["table-uuid"] === options.tableUuid && head === options.headSnapshotId && ids.length === expected.size && new Set(ids).size === expected.size && ids.every((id) => expected.has(id));
18
18
  }
19
+ async function expandMetadata(bytes, maxBytes) {
20
+ if (bytes[0] !== 31 || bytes[1] !== 139) return bytes;
21
+ const reader = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip")).getReader();
22
+ try {
23
+ const chunks = [];
24
+ let total = 0;
25
+ for (;;) {
26
+ const chunk = await reader.read();
27
+ if (chunk.done) break;
28
+ total += chunk.value.byteLength;
29
+ if (total > maxBytes) {
30
+ await reader.cancel();
31
+ return null;
32
+ }
33
+ chunks.push(chunk.value);
34
+ }
35
+ const expanded = new Uint8Array(total);
36
+ let offset = 0;
37
+ for (const chunk of chunks) {
38
+ expanded.set(chunk, offset);
39
+ offset += chunk.byteLength;
40
+ }
41
+ return expanded;
42
+ } catch {
43
+ return null;
44
+ } finally {
45
+ reader.releaseLock();
46
+ }
47
+ }
19
48
  async function restoreIcebergTable(conn, table, options) {
20
49
  if (!validOptions(table, options)) return {
21
50
  _tag: "Err",
@@ -51,9 +80,14 @@ async function restoreIcebergTable(conn, table, options) {
51
80
  _tag: "Err",
52
81
  reason: "backup-invalid"
53
82
  };
83
+ const expanded = await expandMetadata(bytes, maxBytes);
84
+ if (!expanded) return {
85
+ _tag: "Err",
86
+ reason: "backup-invalid"
87
+ };
54
88
  let metadata;
55
89
  try {
56
- metadata = parseIcebergJson(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
90
+ metadata = parseIcebergJson(new TextDecoder("utf-8", { fatal: true }).decode(expanded));
57
91
  } catch {
58
92
  return {
59
93
  _tag: "Err",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/lakehouse",
3
3
  "type": "module",
4
- "version": "7.11.0",
4
+ "version": "7.11.1",
5
5
  "description": "Dataset-agnostic Iceberg lakehouse layer + dataset registry for R2 Data Catalog producers (ADR-0021).",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",