@query-farm/vgi 0.43.0 → 0.45.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 +5 -2
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
- package/dist/arrow/impl-flechette/build.d.ts +2 -2
- package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
- package/dist/arrow/index.d.ts +1 -1
- package/dist/attach-ticket.d.ts +18 -7
- package/dist/catalog/contents-codec.d.ts +7 -0
- package/dist/catalog/contents-digest.d.ts +2 -1
- package/dist/catalog/interface.d.ts +3 -0
- package/dist/catalog/publication-envelope.d.ts +1 -0
- package/dist/catalog/publication.d.ts +142 -0
- package/dist/catalog/s3-publication.d.ts +38 -0
- package/dist/client-entry.js +349 -114
- package/dist/client-entry.js.map +16 -14
- package/dist/codec/asd.d.ts +7 -1
- package/dist/codec/conform.d.ts +51 -0
- package/dist/errors.d.ts +5 -1
- package/dist/generated/vgi-client.d.ts +6 -14
- package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
- package/dist/generated/vgi-protocol-types.d.ts +26 -3
- package/dist/generated/vgi-service.d.ts +3 -3
- package/dist/index.core.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +955 -118
- package/dist/index.js.map +33 -28
- package/dist/protocol/dispatch.d.ts +1 -1
- package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
- package/dist/protocol/handlers/shared.d.ts +2 -1
- package/dist/protocol/serializers/shared.d.ts +2 -1
- package/dist/rpc-server.d.ts +2 -2
- package/dist/serve-entry.js +867 -165
- package/dist/serve-entry.js.map +26 -22
- package/dist/worker-cf-entry.js +825 -114
- package/dist/worker-cf-entry.js.map +31 -27
- package/package.json +3 -3
- package/src/arrow/impl-arrowjs/index.ts +1 -0
- package/src/arrow/impl-arrowjs/ipc.ts +23 -0
- package/src/arrow/impl-flechette/build.ts +4 -2
- package/src/arrow/impl-flechette/canonical.ts +7 -2
- package/src/arrow/impl-flechette/index.ts +1 -0
- package/src/arrow/impl-flechette/ipc.ts +19 -0
- package/src/arrow/index.ts +1 -1
- package/src/attach-ticket.ts +41 -13
- package/src/catalog/composite.ts +2 -1
- package/src/catalog/contents-codec.ts +77 -0
- package/src/catalog/contents-digest.ts +20 -17
- package/src/catalog/interface.ts +8 -4
- package/src/catalog/publication-envelope.ts +62 -0
- package/src/catalog/publication.ts +290 -0
- package/src/catalog/read-only.ts +8 -8
- package/src/catalog/s3-publication.ts +81 -0
- package/src/client/client.ts +15 -24
- package/src/codec/asd.ts +45 -3
- package/src/codec/conform.ts +194 -0
- package/src/errors.ts +27 -7
- package/src/functions/registry.ts +3 -2
- package/src/generated/vgi-client.ts +7 -16
- package/src/generated/vgi-protocol-schemas.ts +13 -6
- package/src/generated/vgi-protocol-types.ts +39 -5
- package/src/generated/vgi-service.ts +4 -3
- package/src/http/fetch.ts +1 -1
- package/src/index.core.ts +3 -1
- package/src/index.ts +5 -0
- package/src/protocol/dispatch.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +7 -4
- package/src/protocol/handlers/catalog/contents.ts +50 -35
- package/src/protocol/handlers/shared.ts +8 -2
- package/src/protocol/serializers/bind.ts +3 -1
- package/src/protocol/serializers/shared.ts +5 -2
- package/src/rpc-server.ts +7 -7
package/dist/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
2
25
|
var __returnValue = (v) => v;
|
|
3
26
|
function __exportSetter(name, newValue) {
|
|
4
27
|
this[name] = __returnValue.bind(null, newValue);
|
|
@@ -1706,7 +1729,26 @@ function deserializeBatch(bytes) {
|
|
|
1706
1729
|
}
|
|
1707
1730
|
return batches[0];
|
|
1708
1731
|
}
|
|
1732
|
+
function deserializeBatches(bytes) {
|
|
1733
|
+
return [...RecordBatchReader.from(bytes)];
|
|
1734
|
+
}
|
|
1735
|
+
function serializeBatches(batches, schema) {
|
|
1736
|
+
const writer = new RecordBatchStreamWriter;
|
|
1737
|
+
writer.reset(undefined, schema);
|
|
1738
|
+
for (const batch of batches)
|
|
1739
|
+
writer._writeRecordBatch(batch);
|
|
1740
|
+
writer.close();
|
|
1741
|
+
return writer.toUint8Array(true);
|
|
1742
|
+
}
|
|
1743
|
+
function serializeCollectionRows(schema, rows, maxBatchRows) {
|
|
1744
|
+
const batch = batchFromRows(rows, schema);
|
|
1745
|
+
const batches = [];
|
|
1746
|
+
for (let offset = 0;offset < batch.numRows; offset += maxBatchRows)
|
|
1747
|
+
batches.push(batch.slice(offset, offset + maxBatchRows));
|
|
1748
|
+
return serializeBatches(batches, schema);
|
|
1749
|
+
}
|
|
1709
1750
|
var init_ipc = __esm(() => {
|
|
1751
|
+
init_build();
|
|
1710
1752
|
init_empty();
|
|
1711
1753
|
});
|
|
1712
1754
|
|
|
@@ -1860,6 +1902,7 @@ __export(exports_impl_arrowjs, {
|
|
|
1860
1902
|
decodeDictValue: () => decodeDictValue,
|
|
1861
1903
|
denseUnion: () => denseUnion,
|
|
1862
1904
|
deserializeBatch: () => deserializeBatch,
|
|
1905
|
+
deserializeBatches: () => deserializeBatches,
|
|
1863
1906
|
deserializeSchema: () => deserializeSchema,
|
|
1864
1907
|
dictionary: () => dictionary,
|
|
1865
1908
|
duration: () => duration,
|
|
@@ -1889,6 +1932,8 @@ __export(exports_impl_arrowjs, {
|
|
|
1889
1932
|
safeNumber: () => safeNumber,
|
|
1890
1933
|
schema: () => schema,
|
|
1891
1934
|
serializeBatch: () => serializeBatch,
|
|
1935
|
+
serializeBatches: () => serializeBatches,
|
|
1936
|
+
serializeCollectionRows: () => serializeCollectionRows,
|
|
1892
1937
|
serializeSchema: () => serializeSchema,
|
|
1893
1938
|
sparseUnion: () => sparseUnion,
|
|
1894
1939
|
struct: () => struct,
|
|
@@ -2021,6 +2066,11 @@ var init_arrow = __esm(() => {
|
|
|
2021
2066
|
});
|
|
2022
2067
|
|
|
2023
2068
|
// src/functions/storage-cf-do.ts
|
|
2069
|
+
var exports_storage_cf_do = {};
|
|
2070
|
+
__export(exports_storage_cf_do, {
|
|
2071
|
+
FunctionStorageCfDo: () => FunctionStorageCfDo
|
|
2072
|
+
});
|
|
2073
|
+
|
|
2024
2074
|
class FunctionStorageCfDo {
|
|
2025
2075
|
_baseUrl;
|
|
2026
2076
|
_token;
|
|
@@ -2466,7 +2516,7 @@ function resolveStorageFromEnv() {
|
|
|
2466
2516
|
return new FunctionStorageSqlite;
|
|
2467
2517
|
}
|
|
2468
2518
|
if (backend === "cloudflare-do") {
|
|
2469
|
-
init_storage_cf_do();
|
|
2519
|
+
const { FunctionStorageCfDo } = (init_storage_cf_do(), __toCommonJS(exports_storage_cf_do));
|
|
2470
2520
|
return FunctionStorageCfDo.fromEnv();
|
|
2471
2521
|
}
|
|
2472
2522
|
throw new Error(`Unknown VGI_WORKER_SHARED_STORAGE backend: '${backend}'. Supported: 'memory', 'sqlite', 'cloudflare-do'.`);
|
|
@@ -2637,9 +2687,12 @@ var DEFAULT_MAX_WORKERS = 99999;
|
|
|
2637
2687
|
|
|
2638
2688
|
// src/errors.ts
|
|
2639
2689
|
class VgiError extends Error {
|
|
2640
|
-
|
|
2690
|
+
errorCode;
|
|
2691
|
+
constructor(message, code) {
|
|
2641
2692
|
super(message);
|
|
2642
2693
|
this.name = "VgiError";
|
|
2694
|
+
if (code !== undefined)
|
|
2695
|
+
this.errorCode = code;
|
|
2643
2696
|
}
|
|
2644
2697
|
}
|
|
2645
2698
|
|
|
@@ -2652,42 +2705,42 @@ class RowCountMismatchError extends VgiError {
|
|
|
2652
2705
|
|
|
2653
2706
|
class FunctionNotFoundError extends VgiError {
|
|
2654
2707
|
constructor(name, available) {
|
|
2655
|
-
super(`Unknown function '${name}'
|
|
2708
|
+
super(`Unknown function '${name}'`, "NOT_FOUND");
|
|
2656
2709
|
this.name = "FunctionNotFoundError";
|
|
2657
2710
|
}
|
|
2658
2711
|
}
|
|
2659
2712
|
|
|
2660
2713
|
class CatalogReadOnlyError extends VgiError {
|
|
2661
2714
|
constructor(operation) {
|
|
2662
|
-
super(`catalog is read-only: ${operation} is not supported
|
|
2715
|
+
super(`catalog is read-only: ${operation} is not supported`, "FAILED_PRECONDITION");
|
|
2663
2716
|
this.name = "CatalogReadOnlyError";
|
|
2664
2717
|
}
|
|
2665
2718
|
}
|
|
2666
2719
|
|
|
2667
2720
|
class CatalogNotFoundError extends VgiError {
|
|
2668
2721
|
constructor(entity, name) {
|
|
2669
|
-
super(`${entity} '${name}' not found
|
|
2722
|
+
super(`${entity} '${name}' not found`, "NOT_FOUND");
|
|
2670
2723
|
this.name = "CatalogNotFoundError";
|
|
2671
2724
|
}
|
|
2672
2725
|
}
|
|
2673
2726
|
|
|
2674
2727
|
class CatalogAlreadyExistsError extends VgiError {
|
|
2675
2728
|
constructor(entity, name) {
|
|
2676
|
-
super(`${entity} '${name}' already exists
|
|
2729
|
+
super(`${entity} '${name}' already exists`, "ALREADY_EXISTS");
|
|
2677
2730
|
this.name = "CatalogAlreadyExistsError";
|
|
2678
2731
|
}
|
|
2679
2732
|
}
|
|
2680
2733
|
|
|
2681
2734
|
class ArgumentValidationError extends VgiError {
|
|
2682
2735
|
constructor(message) {
|
|
2683
|
-
super(message);
|
|
2736
|
+
super(message, "INVALID_ARGUMENT");
|
|
2684
2737
|
this.name = "ArgumentValidationError";
|
|
2685
2738
|
}
|
|
2686
2739
|
}
|
|
2687
2740
|
|
|
2688
2741
|
class NoCatalogError extends VgiError {
|
|
2689
2742
|
constructor() {
|
|
2690
|
-
super("No catalog is configured for this worker");
|
|
2743
|
+
super("No catalog is configured for this worker", "UNIMPLEMENTED");
|
|
2691
2744
|
this.name = "NoCatalogError";
|
|
2692
2745
|
}
|
|
2693
2746
|
}
|
|
@@ -5381,6 +5434,139 @@ init_arrow();
|
|
|
5381
5434
|
|
|
5382
5435
|
// src/protocol/serializers/shared.ts
|
|
5383
5436
|
init_arrow();
|
|
5437
|
+
|
|
5438
|
+
// src/codec/conform.ts
|
|
5439
|
+
init_arrow();
|
|
5440
|
+
var OPTIONAL_ITEM_FIELDS = new Set(["argument_names"]);
|
|
5441
|
+
function children(type) {
|
|
5442
|
+
return type.children ?? [];
|
|
5443
|
+
}
|
|
5444
|
+
function mapValueType(type) {
|
|
5445
|
+
const entries = children(type)[0].type;
|
|
5446
|
+
return children(entries)[1].type;
|
|
5447
|
+
}
|
|
5448
|
+
function mapPairs(raw) {
|
|
5449
|
+
if (Array.isArray(raw))
|
|
5450
|
+
return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
|
|
5451
|
+
if (raw instanceof Map)
|
|
5452
|
+
return Array.from(raw.entries());
|
|
5453
|
+
if (typeof raw[Symbol.iterator] === "function")
|
|
5454
|
+
return Array.from(raw);
|
|
5455
|
+
return Object.entries(raw);
|
|
5456
|
+
}
|
|
5457
|
+
function zeroValue(type) {
|
|
5458
|
+
if (isDictionary(type))
|
|
5459
|
+
return zeroValue(type.dictionary);
|
|
5460
|
+
if (isUtf8(type))
|
|
5461
|
+
return "";
|
|
5462
|
+
if (isBinary(type))
|
|
5463
|
+
return new Uint8Array(0);
|
|
5464
|
+
if (isBool(type))
|
|
5465
|
+
return false;
|
|
5466
|
+
if (isInt(type))
|
|
5467
|
+
return type.bitWidth === 64 ? 0n : 0;
|
|
5468
|
+
if (isFloat(type))
|
|
5469
|
+
return 0;
|
|
5470
|
+
if (isList(type) || isMap(type))
|
|
5471
|
+
return [];
|
|
5472
|
+
if (isStruct(type)) {
|
|
5473
|
+
const out = {};
|
|
5474
|
+
for (const c of children(type))
|
|
5475
|
+
out[c.name] = c.nullable ? null : conformValue(c.type, undefined, false, c.name);
|
|
5476
|
+
return out;
|
|
5477
|
+
}
|
|
5478
|
+
return null;
|
|
5479
|
+
}
|
|
5480
|
+
var HAS_CONTAINER = new WeakMap;
|
|
5481
|
+
function hasContainer(type) {
|
|
5482
|
+
const cached = HAS_CONTAINER.get(type);
|
|
5483
|
+
if (cached !== undefined)
|
|
5484
|
+
return cached;
|
|
5485
|
+
let has = isList(type) || isMap(type);
|
|
5486
|
+
if (!has && isStruct(type))
|
|
5487
|
+
has = children(type).some((c) => hasContainer(c.type));
|
|
5488
|
+
HAS_CONTAINER.set(type, has);
|
|
5489
|
+
return has;
|
|
5490
|
+
}
|
|
5491
|
+
function conformValue(type, value, nullable, name) {
|
|
5492
|
+
if (value == null) {
|
|
5493
|
+
if (nullable)
|
|
5494
|
+
return value ?? null;
|
|
5495
|
+
if (isList(type) || isMap(type))
|
|
5496
|
+
return [];
|
|
5497
|
+
return value;
|
|
5498
|
+
}
|
|
5499
|
+
if (!hasContainer(type))
|
|
5500
|
+
return value;
|
|
5501
|
+
if (isList(type)) {
|
|
5502
|
+
const itemType = children(type)[0].type;
|
|
5503
|
+
const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
|
|
5504
|
+
const items = Array.isArray(value) ? value : Array.from(value);
|
|
5505
|
+
let changed = !Array.isArray(value);
|
|
5506
|
+
const out = items.map((item) => {
|
|
5507
|
+
const next = item == null && !itemsNullable ? zeroValue(itemType) : conformValue(itemType, item, true, name);
|
|
5508
|
+
if (next !== item)
|
|
5509
|
+
changed = true;
|
|
5510
|
+
return next;
|
|
5511
|
+
});
|
|
5512
|
+
return changed ? out : value;
|
|
5513
|
+
}
|
|
5514
|
+
if (isMap(type)) {
|
|
5515
|
+
const valueType = mapValueType(type);
|
|
5516
|
+
const pairs = mapPairs(value);
|
|
5517
|
+
let changed = false;
|
|
5518
|
+
const out = pairs.map(([k, v]) => {
|
|
5519
|
+
const next = v == null ? zeroValue(valueType) : conformValue(valueType, v, true, name);
|
|
5520
|
+
if (next !== v)
|
|
5521
|
+
changed = true;
|
|
5522
|
+
return [k, next];
|
|
5523
|
+
});
|
|
5524
|
+
return changed ? out : value;
|
|
5525
|
+
}
|
|
5526
|
+
if (isStruct(type)) {
|
|
5527
|
+
let out = null;
|
|
5528
|
+
for (const c of children(type)) {
|
|
5529
|
+
const v = value[c.name];
|
|
5530
|
+
const next = conformValue(c.type, v, c.nullable, c.name);
|
|
5531
|
+
if (next !== v) {
|
|
5532
|
+
(out ??= { ...value })[c.name] = next;
|
|
5533
|
+
}
|
|
5534
|
+
}
|
|
5535
|
+
return out ?? value;
|
|
5536
|
+
}
|
|
5537
|
+
return value;
|
|
5538
|
+
}
|
|
5539
|
+
function conformRecord(schema, obj) {
|
|
5540
|
+
let out = null;
|
|
5541
|
+
for (const f of schema.fields) {
|
|
5542
|
+
const v = obj[f.name];
|
|
5543
|
+
const next = conformValue(f.type, v, f.nullable, f.name);
|
|
5544
|
+
if (next !== v) {
|
|
5545
|
+
(out ??= { ...obj })[f.name] = next;
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
return out ?? obj;
|
|
5549
|
+
}
|
|
5550
|
+
function conformColumns(schema, columns) {
|
|
5551
|
+
let out = null;
|
|
5552
|
+
for (const f of schema.fields) {
|
|
5553
|
+
const col = columns[f.name];
|
|
5554
|
+
const rows = col ?? [undefined];
|
|
5555
|
+
let changed = col === undefined;
|
|
5556
|
+
const next = rows.map((v) => {
|
|
5557
|
+
const c = conformValue(f.type, v, f.nullable, f.name);
|
|
5558
|
+
if (c !== v)
|
|
5559
|
+
changed = true;
|
|
5560
|
+
return c;
|
|
5561
|
+
});
|
|
5562
|
+
if (changed) {
|
|
5563
|
+
(out ??= { ...columns })[f.name] = next;
|
|
5564
|
+
}
|
|
5565
|
+
}
|
|
5566
|
+
return out ?? columns;
|
|
5567
|
+
}
|
|
5568
|
+
|
|
5569
|
+
// src/protocol/serializers/shared.ts
|
|
5384
5570
|
function toUint8Array2(val) {
|
|
5385
5571
|
if (typeof val === "string")
|
|
5386
5572
|
return new TextEncoder().encode(val);
|
|
@@ -5392,8 +5578,9 @@ function toUint8Array2(val) {
|
|
|
5392
5578
|
}
|
|
5393
5579
|
function buildSingleRowBatch(schema, values) {
|
|
5394
5580
|
const cols = {};
|
|
5581
|
+
const row = conformRecord(schema, values);
|
|
5395
5582
|
for (const f of schema.fields) {
|
|
5396
|
-
let val =
|
|
5583
|
+
let val = row[f.name];
|
|
5397
5584
|
if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
|
|
5398
5585
|
val = BigInt(val);
|
|
5399
5586
|
}
|
|
@@ -5433,7 +5620,7 @@ function serializeBindRequest(req) {
|
|
|
5433
5620
|
return buildSingleRowBatch(BIND_REQUEST_SCHEMA, {
|
|
5434
5621
|
function_name: req.function_name,
|
|
5435
5622
|
arguments: serializeArguments(req.arguments),
|
|
5436
|
-
function_type: req.function_type,
|
|
5623
|
+
function_type: req.function_type == null ? req.function_type : String(req.function_type).toUpperCase(),
|
|
5437
5624
|
input_schema: req.input_schema ? serializeSchema(req.input_schema) : null,
|
|
5438
5625
|
settings: req.settings ? serializeBatch(req.settings) : null,
|
|
5439
5626
|
secrets: req.secrets ? serializeBatch(req.secrets) : null,
|
|
@@ -7035,7 +7222,7 @@ function schemaPathDisplay(path) {
|
|
|
7035
7222
|
// src/codec/asd.ts
|
|
7036
7223
|
init_arrow();
|
|
7037
7224
|
function encodeASD(schema, obj) {
|
|
7038
|
-
return serializeBatch(batchFromRows([sortMapsForSchema(schema, obj)], schema));
|
|
7225
|
+
return serializeBatch(batchFromRows([sortMapsForSchema(schema, conformRecord(schema, obj))], schema));
|
|
7039
7226
|
}
|
|
7040
7227
|
function compareCodePoints(a, b) {
|
|
7041
7228
|
const n = Math.min(a.length, b.length);
|
|
@@ -7052,7 +7239,7 @@ function compareCodePoints(a, b) {
|
|
|
7052
7239
|
}
|
|
7053
7240
|
return a.length - b.length;
|
|
7054
7241
|
}
|
|
7055
|
-
function
|
|
7242
|
+
function mapPairs2(raw) {
|
|
7056
7243
|
if (Array.isArray(raw))
|
|
7057
7244
|
return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
|
|
7058
7245
|
if (raw instanceof Map)
|
|
@@ -7087,7 +7274,7 @@ function sortMapsForType(type, value) {
|
|
|
7087
7274
|
if (isMap(type)) {
|
|
7088
7275
|
const entries = type.children[0].type;
|
|
7089
7276
|
const valueType = entries.children[1].type;
|
|
7090
|
-
return
|
|
7277
|
+
return mapPairs2(value).map(([k, v]) => [k, sortMapsForType(valueType, v)]).sort((x, y) => compareKeys(x[0], y[0]));
|
|
7091
7278
|
}
|
|
7092
7279
|
if (isList(type)) {
|
|
7093
7280
|
const child = type.children[0].type;
|
|
@@ -7168,7 +7355,7 @@ function normalizeValue(raw, type) {
|
|
|
7168
7355
|
return out;
|
|
7169
7356
|
}
|
|
7170
7357
|
if (isDictionary(type)) {
|
|
7171
|
-
return raw
|
|
7358
|
+
return normalizeValue(raw, type.dictionary);
|
|
7172
7359
|
}
|
|
7173
7360
|
if (isBinary(type)) {
|
|
7174
7361
|
return toUint8Array3(raw);
|
|
@@ -7197,9 +7384,44 @@ function toUint8Array3(val) {
|
|
|
7197
7384
|
}
|
|
7198
7385
|
return new Uint8Array(0);
|
|
7199
7386
|
}
|
|
7387
|
+
function encodeASDCollection(schema, records) {
|
|
7388
|
+
if (records.length === 0)
|
|
7389
|
+
return null;
|
|
7390
|
+
return serializeCollectionRows(schema, records.map((record) => sortMapsForSchema(schema, conformRecord(schema, record))), 1024);
|
|
7391
|
+
}
|
|
7392
|
+
function decodeASDCollection(schema, bytes) {
|
|
7393
|
+
if (bytes == null)
|
|
7394
|
+
return [];
|
|
7395
|
+
const output = [];
|
|
7396
|
+
const batches = deserializeBatches(bytes);
|
|
7397
|
+
const validateSchema = (actualSchema) => {
|
|
7398
|
+
if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
|
|
7399
|
+
const actual = actualSchema.fields[i];
|
|
7400
|
+
return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
|
|
7401
|
+
}))
|
|
7402
|
+
throw new Error("catalog collection has an incompatible metadata schema");
|
|
7403
|
+
};
|
|
7404
|
+
if (batches.length === 0)
|
|
7405
|
+
validateSchema(deserializeSchema(bytes));
|
|
7406
|
+
for (const batch of batches) {
|
|
7407
|
+
validateSchema(batch.schema);
|
|
7408
|
+
for (let row = 0;row < batch.numRows; row++) {
|
|
7409
|
+
const item = {};
|
|
7410
|
+
for (const field of schema.fields) {
|
|
7411
|
+
const value = batch.getChild(field.name)?.get(row);
|
|
7412
|
+
if (value == null && !field.nullable)
|
|
7413
|
+
throw new Error(`catalog collection has null ${field.name}`);
|
|
7414
|
+
item[field.name] = normalizeValue(value, field.type);
|
|
7415
|
+
}
|
|
7416
|
+
output.push(item);
|
|
7417
|
+
}
|
|
7418
|
+
}
|
|
7419
|
+
return output;
|
|
7420
|
+
}
|
|
7200
7421
|
|
|
7201
7422
|
// src/generated/vgi-protocol-schemas.ts
|
|
7202
7423
|
init_arrow();
|
|
7424
|
+
var VGI_CATALOG_CONTRACT_HASH = "121e8fe1c074bce00a6d0fcec49d7a90f05e45498cd9ca8a5a3b4a9ae2377a2d";
|
|
7203
7425
|
var CatalogInfoSchema = schema2([
|
|
7204
7426
|
field2("name", utf82(), false),
|
|
7205
7427
|
field2("implementation_version", utf82(), true),
|
|
@@ -7211,7 +7433,6 @@ var CatalogInfoSchema = schema2([
|
|
|
7211
7433
|
var SchemaInfoSchema = schema2([
|
|
7212
7434
|
field2("comment", utf82(), true),
|
|
7213
7435
|
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
7214
|
-
field2("attach_opaque_data", binary2(), false),
|
|
7215
7436
|
field2("path", list2(field2("item", utf82(), true)), false),
|
|
7216
7437
|
field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true)
|
|
7217
7438
|
]);
|
|
@@ -7252,9 +7473,9 @@ var FunctionInfoSchema = schema2([
|
|
|
7252
7473
|
field2("name", utf82(), false),
|
|
7253
7474
|
field2("schema_path", list2(field2("item", utf82(), true)), false),
|
|
7254
7475
|
field2("function_type", dictionary2(utf82(), int162()), false),
|
|
7255
|
-
field2("arguments", binary2(), false),
|
|
7256
|
-
field2("output_schema", binary2(), false),
|
|
7257
|
-
field2("parameter_default_values", binary2(), true),
|
|
7476
|
+
field2("arguments", dictionary2(binary2(), int322()), false),
|
|
7477
|
+
field2("output_schema", dictionary2(binary2(), int322()), false),
|
|
7478
|
+
field2("parameter_default_values", dictionary2(binary2(), int322()), true),
|
|
7258
7479
|
field2("stability", dictionary2(utf82(), int162()), true),
|
|
7259
7480
|
field2("null_handling", dictionary2(utf82(), int162()), true),
|
|
7260
7481
|
field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
|
|
@@ -7715,7 +7936,12 @@ var CatalogContentsResultSchema = schema2([
|
|
|
7715
7936
|
field2("catalog_version", int642(), false),
|
|
7716
7937
|
field2("etag", utf82(), true),
|
|
7717
7938
|
field2("not_modified", bool2(), false),
|
|
7718
|
-
field2("schemas",
|
|
7939
|
+
field2("schemas", binary2(), true),
|
|
7940
|
+
field2("tables", binary2(), true),
|
|
7941
|
+
field2("views", binary2(), true),
|
|
7942
|
+
field2("functions", binary2(), true),
|
|
7943
|
+
field2("macros", binary2(), true),
|
|
7944
|
+
field2("indexes", binary2(), true)
|
|
7719
7945
|
]);
|
|
7720
7946
|
var CatalogCopyFromFormatsResultSchema = schema2([
|
|
7721
7947
|
field2("items", list2(field2("item", binary2(), true)), false)
|
|
@@ -8192,26 +8418,17 @@ function buildCatalogAttachResult(init) {
|
|
|
8192
8418
|
supports_catalog_contents: init.supports_catalog_contents ?? false
|
|
8193
8419
|
};
|
|
8194
8420
|
}
|
|
8195
|
-
function buildSchemaContents(init) {
|
|
8196
|
-
return {
|
|
8197
|
-
path: init.path,
|
|
8198
|
-
schema: init.schema,
|
|
8199
|
-
tables: init.tables ?? [],
|
|
8200
|
-
views: init.views ?? [],
|
|
8201
|
-
scalar_functions: init.scalar_functions ?? [],
|
|
8202
|
-
aggregate_functions: init.aggregate_functions ?? [],
|
|
8203
|
-
table_functions: init.table_functions ?? [],
|
|
8204
|
-
scalar_macros: init.scalar_macros ?? [],
|
|
8205
|
-
table_macros: init.table_macros ?? [],
|
|
8206
|
-
indexes: init.indexes ?? []
|
|
8207
|
-
};
|
|
8208
|
-
}
|
|
8209
8421
|
function buildCatalogContentsResponse(init) {
|
|
8210
8422
|
return {
|
|
8211
8423
|
catalog_version: init.catalog_version,
|
|
8212
8424
|
etag: init.etag ?? null,
|
|
8213
8425
|
not_modified: init.not_modified ?? false,
|
|
8214
|
-
schemas: init.schemas ??
|
|
8426
|
+
schemas: init.schemas ?? null,
|
|
8427
|
+
tables: init.tables ?? null,
|
|
8428
|
+
views: init.views ?? null,
|
|
8429
|
+
functions: init.functions ?? null,
|
|
8430
|
+
macros: init.macros ?? null,
|
|
8431
|
+
indexes: init.indexes ?? null
|
|
8215
8432
|
};
|
|
8216
8433
|
}
|
|
8217
8434
|
var decodeCatalogContentsResponse = (b) => decodeASD(CatalogContentsResultSchema, b);
|
|
@@ -8252,12 +8469,12 @@ var encodeAttachCatalogInfo = (v) => encodeASD(AttachCatalogInfoSchema, {
|
|
|
8252
8469
|
secret_ref: v.secret_ref ?? ""
|
|
8253
8470
|
});
|
|
8254
8471
|
function encodeScanFunctionResult(functionName, argumentsBytes, requiredExtensions = [], schemaPath = null) {
|
|
8255
|
-
return serializeBatch(batchFromColumns({
|
|
8472
|
+
return serializeBatch(batchFromColumns(conformColumns(ScanFunctionResultSchema, {
|
|
8256
8473
|
function_name: [functionName],
|
|
8257
8474
|
arguments: [argumentsBytes],
|
|
8258
8475
|
required_extensions: [requiredExtensions],
|
|
8259
8476
|
schema_path: [schemaPath]
|
|
8260
|
-
}, ScanFunctionResultSchema));
|
|
8477
|
+
}), ScanFunctionResultSchema));
|
|
8261
8478
|
}
|
|
8262
8479
|
function decodeScanFunctionResult(inner) {
|
|
8263
8480
|
const argsBytes = inner.arguments;
|
|
@@ -8301,7 +8518,7 @@ function singleBranchResult(legacy) {
|
|
|
8301
8518
|
};
|
|
8302
8519
|
}
|
|
8303
8520
|
function encodeScanBranch(cols) {
|
|
8304
|
-
return serializeBatch(batchFromColumns({
|
|
8521
|
+
return serializeBatch(batchFromColumns(conformColumns(ScanBranchSchema, {
|
|
8305
8522
|
function_name: [cols.function_name],
|
|
8306
8523
|
arguments: [cols.arguments],
|
|
8307
8524
|
branch_filter: [cols.branch_filter ?? null],
|
|
@@ -8313,7 +8530,7 @@ function encodeScanBranch(cols) {
|
|
|
8313
8530
|
format_locations: [cols.format_locations ?? null],
|
|
8314
8531
|
format_options: [cols.format_options ?? null],
|
|
8315
8532
|
schema_path: [cols.schema_path ?? null]
|
|
8316
|
-
}, ScanBranchSchema));
|
|
8533
|
+
}), ScanBranchSchema));
|
|
8317
8534
|
}
|
|
8318
8535
|
function encodeFormatOptions(options) {
|
|
8319
8536
|
const fields = [];
|
|
@@ -8364,6 +8581,7 @@ function isPromise(v) {
|
|
|
8364
8581
|
}
|
|
8365
8582
|
|
|
8366
8583
|
class CatalogInterface {
|
|
8584
|
+
catalogSnapshotPolicy = null;
|
|
8367
8585
|
catalogContentsEtag = null;
|
|
8368
8586
|
catalogContentsAttachIndependent = false;
|
|
8369
8587
|
catalogVersionFrozen = false;
|
|
@@ -8884,7 +9102,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
8884
9102
|
}
|
|
8885
9103
|
attach(name, options, dataVersionSpec, implementationVersion) {
|
|
8886
9104
|
if (!this.catalogs().includes(name)) {
|
|
8887
|
-
throw new
|
|
9105
|
+
throw new VgiError(`No worker handles catalog '${name}'`, "NOT_FOUND");
|
|
8888
9106
|
}
|
|
8889
9107
|
validateRequiredAttachOptions(name, this.attachOptionSpecs(name), options ?? {});
|
|
8890
9108
|
const attachOpaqueData = new Uint8Array(16);
|
|
@@ -8934,7 +9152,6 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
8934
9152
|
}
|
|
8935
9153
|
schemas(attachOpaqueData, transactionOpaqueData) {
|
|
8936
9154
|
return this._descriptor.schemas.map((s) => ({
|
|
8937
|
-
attach_opaque_data: this.itemAttachId(attachOpaqueData),
|
|
8938
9155
|
path: schemaDescriptorPath(s),
|
|
8939
9156
|
comment: s.comment ?? null,
|
|
8940
9157
|
tags: s.tags ?? {},
|
|
@@ -8966,7 +9183,6 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
8966
9183
|
if (!desc)
|
|
8967
9184
|
return null;
|
|
8968
9185
|
return {
|
|
8969
|
-
attach_opaque_data: this.itemAttachId(attachOpaqueData),
|
|
8970
9186
|
path: schemaDescriptorPath(desc),
|
|
8971
9187
|
comment: desc.comment ?? null,
|
|
8972
9188
|
tags: desc.tags ?? {},
|
|
@@ -9284,11 +9500,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
9284
9500
|
validateAtParams(atUnit, atValue);
|
|
9285
9501
|
const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), schemaPath));
|
|
9286
9502
|
if (!schema || !schema.tables) {
|
|
9287
|
-
throw new
|
|
9503
|
+
throw new VgiError(`Table '${name}' not found in schema ${schemaPathDisplay(schemaPath)}`, "NOT_FOUND");
|
|
9288
9504
|
}
|
|
9289
9505
|
const table = schema.tables.find((t) => t.name === name);
|
|
9290
9506
|
if (!table) {
|
|
9291
|
-
throw new
|
|
9507
|
+
throw new VgiError(`Table '${name}' not found in schema ${schemaPathDisplay(schemaPath)}`, "NOT_FOUND");
|
|
9292
9508
|
}
|
|
9293
9509
|
if (atUnit && !table.supportsTimeTravel) {
|
|
9294
9510
|
throw new Error(`Table ${schemaPathDisplay(schemaPath)}.${name} does not support time travel queries`);
|
|
@@ -9373,12 +9589,12 @@ function resolveIndexGroups(schema, groups) {
|
|
|
9373
9589
|
function serializeForeignKeys(fks, schemaPath) {
|
|
9374
9590
|
if (!fks || fks.length === 0)
|
|
9375
9591
|
return [];
|
|
9376
|
-
return fks.map((fk) => serializeBatch(batchFromColumns({
|
|
9592
|
+
return fks.map((fk) => serializeBatch(batchFromColumns(conformColumns(ForeignKeyInfoSchema, {
|
|
9377
9593
|
fk_columns: [fk.columns],
|
|
9378
9594
|
pk_columns: [fk.referencedColumns],
|
|
9379
9595
|
referenced_table: [fk.referencedTable],
|
|
9380
9596
|
referenced_schema_path: [fk.referencedSchemaPath ?? schemaPath ?? ["main"]]
|
|
9381
|
-
}, ForeignKeyInfoSchema)));
|
|
9597
|
+
}), ForeignKeyInfoSchema)));
|
|
9382
9598
|
}
|
|
9383
9599
|
function defaultToSql(value) {
|
|
9384
9600
|
if (value === null || value === undefined)
|
|
@@ -9518,7 +9734,7 @@ function serializeArgsBatch(args, argSpecSchema) {
|
|
|
9518
9734
|
}
|
|
9519
9735
|
function validateAtParams(atUnit, atValue) {
|
|
9520
9736
|
if (Boolean(atUnit) !== Boolean(atValue)) {
|
|
9521
|
-
throw new
|
|
9737
|
+
throw new VgiError("at_unit and at_value must both be provided or both be absent", "INVALID_ARGUMENT");
|
|
9522
9738
|
}
|
|
9523
9739
|
}
|
|
9524
9740
|
function inferScalarType2(val) {
|
|
@@ -10403,7 +10619,7 @@ class CompositeCatalogInterface extends CatalogInterface {
|
|
|
10403
10619
|
return result;
|
|
10404
10620
|
}
|
|
10405
10621
|
}
|
|
10406
|
-
throw new
|
|
10622
|
+
throw new VgiError(`No worker handles catalog '${name}'`, "NOT_FOUND");
|
|
10407
10623
|
}
|
|
10408
10624
|
async detach(attachOpaqueData) {
|
|
10409
10625
|
await this._route(attachOpaqueData).detach(attachOpaqueData);
|
|
@@ -10727,7 +10943,7 @@ class FunctionRegistry {
|
|
|
10727
10943
|
} else if (candidates && candidates.length > 0) {
|
|
10728
10944
|
const schemas = this.schemasFor(name);
|
|
10729
10945
|
if (schemas.length > 0) {
|
|
10730
|
-
throw new
|
|
10946
|
+
throw new VgiError(`Function '${name}' is not registered in schema ${schemaPathDisplay(schemaPath)}. ` + `It is available in: [${schemas.map(schemaPathDisplay).join(", ")}]`, "NOT_FOUND");
|
|
10731
10947
|
}
|
|
10732
10948
|
}
|
|
10733
10949
|
}
|
|
@@ -11041,7 +11257,7 @@ import {
|
|
|
11041
11257
|
Protocol
|
|
11042
11258
|
} from "@query-farm/vgi-rpc";
|
|
11043
11259
|
var VGI_PROTOCOL_NAME = "vgi.v2";
|
|
11044
|
-
var VGI_PROTOCOL_VERSION = "2.
|
|
11260
|
+
var VGI_PROTOCOL_VERSION = "2.2.0";
|
|
11045
11261
|
function exchangeStream(callbacks) {
|
|
11046
11262
|
return { kind: "exchange", ...callbacks };
|
|
11047
11263
|
}
|
|
@@ -12315,7 +12531,8 @@ function normalizeRequestSchemaPaths(params) {
|
|
|
12315
12531
|
}
|
|
12316
12532
|
function wrapResult(values, innerSchema) {
|
|
12317
12533
|
const a = innerSchema;
|
|
12318
|
-
const
|
|
12534
|
+
const row = conformRecord(a, values);
|
|
12535
|
+
const batch = batchFromColumns(Object.fromEntries(a.fields.map((f) => [f.name, [row[f.name] ?? null]])), a);
|
|
12319
12536
|
return { result: serializeBatch(batch) };
|
|
12320
12537
|
}
|
|
12321
12538
|
function overloadContext(req, catalogInterface) {
|
|
@@ -13192,18 +13409,97 @@ function hex(buf) {
|
|
|
13192
13409
|
return Array.from(buf, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
13193
13410
|
}
|
|
13194
13411
|
|
|
13412
|
+
// src/protocol/handlers/catalog/contents.ts
|
|
13413
|
+
import { ExternalRef as ExternalRef2 } from "@query-farm/vgi-rpc";
|
|
13414
|
+
|
|
13415
|
+
// src/catalog/publication.ts
|
|
13416
|
+
init_arrow();
|
|
13417
|
+
import { ExternalRef, publishExternalResult, resolveExternalLocation } from "@query-farm/vgi-rpc";
|
|
13418
|
+
|
|
13419
|
+
// src/catalog/contents-codec.ts
|
|
13420
|
+
var schemaPathKey2 = (path) => JSON.stringify(path.map((part) => part.toLowerCase()));
|
|
13421
|
+
var CATALOG_STREAM_KINDS = ["schemas", "tables", "views", "functions", "macros", "indexes"];
|
|
13422
|
+
function encodeCatalogStreams(inventory) {
|
|
13423
|
+
const streams = {
|
|
13424
|
+
schemas: encodeASDCollection(SchemaInfoSchema, inventory.map((s) => s.schema)),
|
|
13425
|
+
tables: encodeASDCollection(TableInfoSchema, inventory.flatMap((s) => s.tables)),
|
|
13426
|
+
views: encodeASDCollection(ViewInfoSchema, inventory.flatMap((s) => s.views)),
|
|
13427
|
+
functions: encodeASDCollection(FunctionInfoSchema, inventory.flatMap((s) => [...s.scalar_functions, ...s.aggregate_functions, ...s.table_functions])),
|
|
13428
|
+
macros: encodeASDCollection(MacroInfoSchema, inventory.flatMap((s) => [...s.scalar_macros, ...s.table_macros])),
|
|
13429
|
+
indexes: encodeASDCollection(IndexInfoSchema, inventory.flatMap((s) => s.indexes))
|
|
13430
|
+
};
|
|
13431
|
+
return streams;
|
|
13432
|
+
}
|
|
13433
|
+
function decodeCatalogStreams(response, ifNoneMatch) {
|
|
13434
|
+
if (response.not_modified) {
|
|
13435
|
+
if (response.etag == null || ifNoneMatch !== undefined && response.etag !== ifNoneMatch || CATALOG_STREAM_KINDS.some((kind) => response[kind] != null)) {
|
|
13436
|
+
throw new Error("invalid catalog_contents not_modified response");
|
|
13437
|
+
}
|
|
13438
|
+
return [];
|
|
13439
|
+
}
|
|
13440
|
+
const infos = decodeASDCollection(SchemaInfoSchema, response.schemas);
|
|
13441
|
+
const schemas = [];
|
|
13442
|
+
const index = new Map;
|
|
13443
|
+
for (const schema of infos) {
|
|
13444
|
+
if (!Array.isArray(schema.path) || schema.path.length === 0)
|
|
13445
|
+
throw new Error("catalog schema has an empty path");
|
|
13446
|
+
const key = schemaPathKey2(schema.path);
|
|
13447
|
+
if (index.has(key))
|
|
13448
|
+
throw new Error("catalog contains duplicate schema paths");
|
|
13449
|
+
if (schema.path.length > 1 && !index.has(schemaPathKey2(schema.path.slice(0, -1)))) {
|
|
13450
|
+
throw new Error("catalog schema is missing its preceding parent");
|
|
13451
|
+
}
|
|
13452
|
+
const entry = { schema, tables: [], views: [], scalar_functions: [], aggregate_functions: [], table_functions: [], scalar_macros: [], table_macros: [], indexes: [] };
|
|
13453
|
+
index.set(key, entry);
|
|
13454
|
+
schemas.push(entry);
|
|
13455
|
+
}
|
|
13456
|
+
const owner = (item) => {
|
|
13457
|
+
const entry = index.get(schemaPathKey2(item.schema_path));
|
|
13458
|
+
if (!entry)
|
|
13459
|
+
throw new Error("catalog object references an absent schema");
|
|
13460
|
+
return entry;
|
|
13461
|
+
};
|
|
13462
|
+
for (const item of decodeASDCollection(TableInfoSchema, response.tables))
|
|
13463
|
+
owner(item).tables.push(item);
|
|
13464
|
+
for (const item of decodeASDCollection(ViewInfoSchema, response.views))
|
|
13465
|
+
owner(item).views.push(item);
|
|
13466
|
+
for (const item of decodeASDCollection(FunctionInfoSchema, response.functions)) {
|
|
13467
|
+
const entry = owner(item);
|
|
13468
|
+
switch (String(item.function_type).toUpperCase()) {
|
|
13469
|
+
case "SCALAR":
|
|
13470
|
+
entry.scalar_functions.push(item);
|
|
13471
|
+
break;
|
|
13472
|
+
case "AGGREGATE":
|
|
13473
|
+
entry.aggregate_functions.push(item);
|
|
13474
|
+
break;
|
|
13475
|
+
case "TABLE":
|
|
13476
|
+
case "TABLE_BUFFERING":
|
|
13477
|
+
entry.table_functions.push(item);
|
|
13478
|
+
break;
|
|
13479
|
+
default:
|
|
13480
|
+
throw new Error(`unknown catalog function type ${item.function_type}`);
|
|
13481
|
+
}
|
|
13482
|
+
}
|
|
13483
|
+
for (const item of decodeASDCollection(MacroInfoSchema, response.macros)) {
|
|
13484
|
+
const entry = owner(item);
|
|
13485
|
+
switch (String(item.macro_type).toUpperCase()) {
|
|
13486
|
+
case "SCALAR":
|
|
13487
|
+
entry.scalar_macros.push(item);
|
|
13488
|
+
break;
|
|
13489
|
+
case "TABLE":
|
|
13490
|
+
entry.table_macros.push(item);
|
|
13491
|
+
break;
|
|
13492
|
+
default:
|
|
13493
|
+
throw new Error(`unknown catalog macro type ${item.macro_type}`);
|
|
13494
|
+
}
|
|
13495
|
+
}
|
|
13496
|
+
for (const item of decodeASDCollection(IndexInfoSchema, response.indexes))
|
|
13497
|
+
owner(item).indexes.push(item);
|
|
13498
|
+
return schemas;
|
|
13499
|
+
}
|
|
13500
|
+
|
|
13195
13501
|
// src/catalog/contents-digest.ts
|
|
13196
|
-
|
|
13197
|
-
"tables",
|
|
13198
|
-
"views",
|
|
13199
|
-
"scalar_functions",
|
|
13200
|
-
"aggregate_functions",
|
|
13201
|
-
"table_functions",
|
|
13202
|
-
"scalar_macros",
|
|
13203
|
-
"table_macros",
|
|
13204
|
-
"indexes"
|
|
13205
|
-
];
|
|
13206
|
-
async function catalogContentsDigest(schemas) {
|
|
13502
|
+
async function catalogContentsDigest(streams, version = 0) {
|
|
13207
13503
|
const utf8 = new TextEncoder;
|
|
13208
13504
|
const parts = [];
|
|
13209
13505
|
let total = 0;
|
|
@@ -13223,12 +13519,23 @@ async function catalogContentsDigest(schemas) {
|
|
|
13223
13519
|
for (const v of values)
|
|
13224
13520
|
chunk(v);
|
|
13225
13521
|
};
|
|
13226
|
-
|
|
13227
|
-
|
|
13228
|
-
|
|
13229
|
-
|
|
13230
|
-
|
|
13231
|
-
|
|
13522
|
+
if (Array.isArray(streams)) {
|
|
13523
|
+
count(streams.length);
|
|
13524
|
+
for (const entry of streams) {
|
|
13525
|
+
chunks(entry.path.map((p) => utf8.encode(p)));
|
|
13526
|
+
chunk(entry.schema);
|
|
13527
|
+
for (const kind of ["tables", "views", "scalar_functions", "aggregate_functions", "table_functions", "scalar_macros", "table_macros", "indexes"])
|
|
13528
|
+
chunks(entry[kind]);
|
|
13529
|
+
}
|
|
13530
|
+
} else {
|
|
13531
|
+
chunk(utf8.encode("vgi.catalog-contents.2.2"));
|
|
13532
|
+
count(version);
|
|
13533
|
+
for (const kind of CATALOG_STREAM_KINDS) {
|
|
13534
|
+
const value = streams[kind];
|
|
13535
|
+
count(value == null ? 0 : 1);
|
|
13536
|
+
if (value != null)
|
|
13537
|
+
chunk(value);
|
|
13538
|
+
}
|
|
13232
13539
|
}
|
|
13233
13540
|
const buf = new Uint8Array(total);
|
|
13234
13541
|
let off = 0;
|
|
@@ -13243,7 +13550,391 @@ async function catalogContentsDigest(schemas) {
|
|
|
13243
13550
|
return hex;
|
|
13244
13551
|
}
|
|
13245
13552
|
|
|
13553
|
+
// src/catalog/publication-envelope.ts
|
|
13554
|
+
function validateCatalogPublicationEnvelope(bytes) {
|
|
13555
|
+
try {
|
|
13556
|
+
const stream = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
13557
|
+
let position = 0, messages = 0;
|
|
13558
|
+
while (position < bytes.length) {
|
|
13559
|
+
let length = stream.getInt32(position, true);
|
|
13560
|
+
position += 4;
|
|
13561
|
+
if (length === -1) {
|
|
13562
|
+
length = stream.getInt32(position, true);
|
|
13563
|
+
position += 4;
|
|
13564
|
+
}
|
|
13565
|
+
if (length === 0) {
|
|
13566
|
+
if (position !== bytes.length)
|
|
13567
|
+
throw new Error("trailing data");
|
|
13568
|
+
break;
|
|
13569
|
+
}
|
|
13570
|
+
if (length < 4 || length > bytes.length - position)
|
|
13571
|
+
throw new Error("invalid message length");
|
|
13572
|
+
const head = new DataView(bytes.buffer, bytes.byteOffset + position, length);
|
|
13573
|
+
const tableField = (table, field) => {
|
|
13574
|
+
const vtable = table - head.getInt32(table, true);
|
|
13575
|
+
const vlength = head.getUint16(vtable, true);
|
|
13576
|
+
if (vlength < 4 || vlength % 2 || vtable + vlength > length)
|
|
13577
|
+
throw new Error("invalid vtable");
|
|
13578
|
+
if (4 + 2 * field >= vlength)
|
|
13579
|
+
return null;
|
|
13580
|
+
const offset = head.getUint16(vtable + 4 + 2 * field, true);
|
|
13581
|
+
return offset === 0 ? null : table + offset;
|
|
13582
|
+
};
|
|
13583
|
+
const follow = (pointer) => pointer + head.getUint32(pointer, true);
|
|
13584
|
+
const root = head.getUint32(0, true);
|
|
13585
|
+
const typePosition = tableField(root, 1);
|
|
13586
|
+
const type = typePosition == null ? 0 : head.getUint8(typePosition);
|
|
13587
|
+
if (type !== (messages === 0 ? 1 : messages === 1 ? 3 : -1))
|
|
13588
|
+
throw new Error("expected one schema and one record batch");
|
|
13589
|
+
if (type === 3) {
|
|
13590
|
+
const header = tableField(root, 2);
|
|
13591
|
+
if (header == null)
|
|
13592
|
+
throw new Error("missing record header");
|
|
13593
|
+
const rows = tableField(follow(header), 0);
|
|
13594
|
+
if (rows == null || head.getBigInt64(rows, true) !== 1n)
|
|
13595
|
+
throw new Error("expected one response row");
|
|
13596
|
+
}
|
|
13597
|
+
const metadata = tableField(root, 4);
|
|
13598
|
+
if (metadata != null) {
|
|
13599
|
+
const vector = follow(metadata), count = head.getUint32(vector, true);
|
|
13600
|
+
if (count > length / 4)
|
|
13601
|
+
throw new Error("invalid metadata vector");
|
|
13602
|
+
for (let i = 0;i < count; i++) {
|
|
13603
|
+
const keyPointer = tableField(follow(vector + 4 + 4 * i), 0);
|
|
13604
|
+
if (keyPointer == null)
|
|
13605
|
+
continue;
|
|
13606
|
+
const keyStart = follow(keyPointer), keyLength = head.getUint32(keyStart, true);
|
|
13607
|
+
if (keyStart + 4 + keyLength > length)
|
|
13608
|
+
throw new Error("invalid metadata key");
|
|
13609
|
+
const key = new TextDecoder().decode(new Uint8Array(head.buffer, head.byteOffset + keyStart + 4, keyLength));
|
|
13610
|
+
if (key === "vgi_rpc.location" || key === "vgi_rpc.log_level")
|
|
13611
|
+
throw new Error("pointer/log metadata is not a catalog result");
|
|
13612
|
+
}
|
|
13613
|
+
}
|
|
13614
|
+
const bodyPosition = tableField(root, 3);
|
|
13615
|
+
const bodyLength = bodyPosition == null ? 0 : Number(head.getBigInt64(bodyPosition, true));
|
|
13616
|
+
position += length;
|
|
13617
|
+
if (!Number.isSafeInteger(bodyLength) || bodyLength < 0 || bodyLength > bytes.length - position)
|
|
13618
|
+
throw new Error("invalid body length");
|
|
13619
|
+
position += bodyLength;
|
|
13620
|
+
messages++;
|
|
13621
|
+
}
|
|
13622
|
+
if (messages !== 2)
|
|
13623
|
+
throw new Error("missing response batch");
|
|
13624
|
+
} catch (error) {
|
|
13625
|
+
throw new Error(`invalid published RPC envelope: ${error instanceof Error ? error.message : String(error)}`);
|
|
13626
|
+
}
|
|
13627
|
+
}
|
|
13628
|
+
|
|
13629
|
+
// src/catalog/publication.ts
|
|
13630
|
+
var OUTER_SCHEMA = schema2([field2("result", binary2(), false)]);
|
|
13631
|
+
var DEFAULT_MAX = 64 * 1024 * 1024;
|
|
13632
|
+
var utf83 = new TextEncoder;
|
|
13633
|
+
var equalBytes3 = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
13634
|
+
async function digest(value) {
|
|
13635
|
+
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", utf83.encode(value)));
|
|
13636
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
13637
|
+
}
|
|
13638
|
+
function assertRenewedPublication(before, after) {
|
|
13639
|
+
const unchanged = (m) => JSON.stringify([m.key, m.formatVersion, m.protocolName, m.protocolVersion, m.contractHash, m.codecRevision, m.catalogVersion, m.etag, m.sha256, m.rawSize, m.storedSize, m.objectId, m.retainUntil, m.stable, m.validated]);
|
|
13640
|
+
if (unchanged(before) !== unchanged(after))
|
|
13641
|
+
throw new Error("renewal changed immutable catalog identity");
|
|
13642
|
+
}
|
|
13643
|
+
var manifestSame = (a, b) => a.manifestId === b.manifestId;
|
|
13644
|
+
|
|
13645
|
+
class MemoryCatalogPublicationRepository {
|
|
13646
|
+
profile;
|
|
13647
|
+
storage;
|
|
13648
|
+
resolver;
|
|
13649
|
+
describe;
|
|
13650
|
+
manifests = new Map;
|
|
13651
|
+
constructor(profile, storage, resolver, describe) {
|
|
13652
|
+
this.profile = profile;
|
|
13653
|
+
this.storage = storage;
|
|
13654
|
+
this.resolver = resolver;
|
|
13655
|
+
this.describe = describe;
|
|
13656
|
+
}
|
|
13657
|
+
async lookup(key) {
|
|
13658
|
+
return this.manifests.get(key) ?? null;
|
|
13659
|
+
}
|
|
13660
|
+
async commitIfAbsent(manifest) {
|
|
13661
|
+
const existing = this.manifests.get(manifest.key);
|
|
13662
|
+
if (existing)
|
|
13663
|
+
return existing;
|
|
13664
|
+
const committed = Object.freeze({ ...manifest });
|
|
13665
|
+
this.manifests.set(manifest.key, committed);
|
|
13666
|
+
return committed;
|
|
13667
|
+
}
|
|
13668
|
+
async invalidate(key, expected) {
|
|
13669
|
+
const current = this.manifests.get(key);
|
|
13670
|
+
if (current && manifestSame(current, expected))
|
|
13671
|
+
this.manifests.delete(key);
|
|
13672
|
+
}
|
|
13673
|
+
}
|
|
13674
|
+
|
|
13675
|
+
class S3CatalogPublicationRepository {
|
|
13676
|
+
profile;
|
|
13677
|
+
storage;
|
|
13678
|
+
resolver;
|
|
13679
|
+
objects;
|
|
13680
|
+
describe;
|
|
13681
|
+
prefix;
|
|
13682
|
+
renewReference;
|
|
13683
|
+
constructor(profile, storage, resolver, objects, describe, prefix = "vgi/catalog-manifests/") {
|
|
13684
|
+
this.profile = profile;
|
|
13685
|
+
this.storage = storage;
|
|
13686
|
+
this.resolver = resolver;
|
|
13687
|
+
this.objects = objects;
|
|
13688
|
+
this.describe = describe;
|
|
13689
|
+
this.prefix = prefix;
|
|
13690
|
+
}
|
|
13691
|
+
objectKey(key) {
|
|
13692
|
+
if (!/^[0-9a-f]{64}$/.test(key))
|
|
13693
|
+
throw new Error("invalid publication key");
|
|
13694
|
+
return `${this.prefix}${key}.json`;
|
|
13695
|
+
}
|
|
13696
|
+
async lookup(key) {
|
|
13697
|
+
const value = await this.objects.get(this.objectKey(key));
|
|
13698
|
+
if (!value)
|
|
13699
|
+
return null;
|
|
13700
|
+
if (value.body.byteLength > 64 * 1024)
|
|
13701
|
+
throw new Error("catalog manifest exceeds 64 KiB");
|
|
13702
|
+
return JSON.parse(new TextDecoder().decode(value.body));
|
|
13703
|
+
}
|
|
13704
|
+
async commitIfAbsent(manifest) {
|
|
13705
|
+
const stored = await this.objects.put(this.objectKey(manifest.key), utf83.encode(JSON.stringify(manifest)), { ifNoneMatch: "*" });
|
|
13706
|
+
if (stored)
|
|
13707
|
+
return manifest;
|
|
13708
|
+
const current = await this.lookup(manifest.key);
|
|
13709
|
+
if (!current)
|
|
13710
|
+
throw new Error("catalog manifest changed during commit");
|
|
13711
|
+
return current;
|
|
13712
|
+
}
|
|
13713
|
+
async renew(manifest) {
|
|
13714
|
+
if (!this.renewReference)
|
|
13715
|
+
return null;
|
|
13716
|
+
const current = await this.objects.get(this.objectKey(manifest.key));
|
|
13717
|
+
if (!current)
|
|
13718
|
+
return null;
|
|
13719
|
+
const existing = JSON.parse(new TextDecoder().decode(current.body));
|
|
13720
|
+
if (!manifestSame(existing, manifest))
|
|
13721
|
+
return existing;
|
|
13722
|
+
const renewed = await this.renewReference(manifest);
|
|
13723
|
+
if (!renewed)
|
|
13724
|
+
return null;
|
|
13725
|
+
assertRenewedPublication(manifest, renewed);
|
|
13726
|
+
if (await this.objects.put(this.objectKey(manifest.key), utf83.encode(JSON.stringify(renewed)), { ifMatch: current.etag }))
|
|
13727
|
+
return renewed;
|
|
13728
|
+
return this.lookup(manifest.key);
|
|
13729
|
+
}
|
|
13730
|
+
async invalidate(key, expected) {
|
|
13731
|
+
const current = await this.objects.get(this.objectKey(key));
|
|
13732
|
+
if (current && manifestSame(JSON.parse(new TextDecoder().decode(current.body)), expected)) {
|
|
13733
|
+
await this.objects.delete(this.objectKey(key), { ifMatch: current.etag });
|
|
13734
|
+
}
|
|
13735
|
+
}
|
|
13736
|
+
}
|
|
13737
|
+
|
|
13738
|
+
class CatalogSnapshotManager {
|
|
13739
|
+
policy;
|
|
13740
|
+
cached = new Map;
|
|
13741
|
+
pending = new Map;
|
|
13742
|
+
constructor(policy) {
|
|
13743
|
+
this.policy = policy;
|
|
13744
|
+
for (const value of [policy.maxRawBytes, policy.maxStoredBytes, policy.maxCachedManifests]) {
|
|
13745
|
+
if (value != null && (!Number.isSafeInteger(value) || value <= 0))
|
|
13746
|
+
throw new Error("catalog publication limits must be positive safe integers");
|
|
13747
|
+
}
|
|
13748
|
+
if (policy.referenceGraceMs != null && (!Number.isSafeInteger(policy.referenceGraceMs) || policy.referenceGraceMs < 0))
|
|
13749
|
+
throw new Error("catalog publication reference grace must be a nonnegative safe integer");
|
|
13750
|
+
}
|
|
13751
|
+
usable(m) {
|
|
13752
|
+
const deadline = Date.now() + (this.policy.referenceGraceMs ?? 60000);
|
|
13753
|
+
return (m.stable || m.expiresAt != null) && (m.expiresAt == null || m.expiresAt > deadline) && (m.retainUntil == null || m.retainUntil > deadline);
|
|
13754
|
+
}
|
|
13755
|
+
async key(identity) {
|
|
13756
|
+
for (const value of [identity.catalogNamespace, identity.sourceRevision, identity.visibilityScope])
|
|
13757
|
+
if (!value)
|
|
13758
|
+
throw new Error("published catalogs require explicit namespace, revision and visibility scope");
|
|
13759
|
+
if (!Number.isSafeInteger(identity.catalogVersion))
|
|
13760
|
+
throw new Error("catalog version is not a safe integer");
|
|
13761
|
+
return digest(JSON.stringify([
|
|
13762
|
+
VGI_PROTOCOL_NAME,
|
|
13763
|
+
VGI_PROTOCOL_VERSION,
|
|
13764
|
+
VGI_CATALOG_CONTRACT_HASH,
|
|
13765
|
+
1,
|
|
13766
|
+
identity.catalogNamespace,
|
|
13767
|
+
identity.sourceRevision,
|
|
13768
|
+
identity.visibilityScope,
|
|
13769
|
+
identity.catalogVersion,
|
|
13770
|
+
this.policy.repository.profile,
|
|
13771
|
+
this.policy.compression ?? "identity"
|
|
13772
|
+
]));
|
|
13773
|
+
}
|
|
13774
|
+
remember(m) {
|
|
13775
|
+
this.cached.delete(m.key);
|
|
13776
|
+
this.cached.set(m.key, Object.freeze({ ...m }));
|
|
13777
|
+
while (this.cached.size > (this.policy.maxCachedManifests ?? 128))
|
|
13778
|
+
this.cached.delete(this.cached.keys().next().value);
|
|
13779
|
+
}
|
|
13780
|
+
async invalidate(key) {
|
|
13781
|
+
await this.pending.get(key)?.catch(() => {
|
|
13782
|
+
return;
|
|
13783
|
+
});
|
|
13784
|
+
const m = this.cached.get(key) ?? await this.policy.repository.lookup(key);
|
|
13785
|
+
this.cached.delete(key);
|
|
13786
|
+
if (m)
|
|
13787
|
+
await this.policy.repository.invalidate(key, m);
|
|
13788
|
+
}
|
|
13789
|
+
async validate(m, key, identity, expected) {
|
|
13790
|
+
if (m.formatVersion !== 1 || typeof m.manifestId !== "string" || !m.manifestId || m.key !== key || m.protocolName !== VGI_PROTOCOL_NAME || m.protocolVersion !== VGI_PROTOCOL_VERSION || m.contractHash !== VGI_CATALOG_CONTRACT_HASH || m.codecRevision !== 1 || m.catalogVersion !== identity.catalogVersion || m.validated !== true || typeof m.stable !== "boolean" || typeof m.etag !== "string" || !/^[0-9a-f]{64}$/.test(m.sha256) || !Number.isSafeInteger(m.rawSize) || !Number.isSafeInteger(m.storedSize) || m.rawSize <= 0 || m.storedSize <= 0 || m.rawSize > (this.policy.maxRawBytes ?? DEFAULT_MAX) || m.storedSize > (this.policy.maxStoredBytes ?? DEFAULT_MAX) || !this.usable(m))
|
|
13791
|
+
throw new Error("invalid or expired catalog publication manifest");
|
|
13792
|
+
const ref = new ExternalRef(m.url, m.sha256);
|
|
13793
|
+
const configuredFetch = this.policy.repository.resolver.fetch ?? fetch;
|
|
13794
|
+
const resolved = await resolveExternalLocation(ref.pointerBatch(OUTER_SCHEMA), {
|
|
13795
|
+
...this.policy.repository.resolver,
|
|
13796
|
+
fetch: (input, init) => configuredFetch(input, { ...init, signal: AbortSignal.any([...init?.signal ? [init.signal] : [], AbortSignal.timeout(30000)]) }),
|
|
13797
|
+
maxFetchBytes: Math.min(this.policy.maxStoredBytes ?? DEFAULT_MAX, this.policy.repository.resolver.maxFetchBytes ?? Infinity),
|
|
13798
|
+
maxDecompressedBytes: Math.min(this.policy.maxRawBytes ?? DEFAULT_MAX, this.policy.repository.resolver.maxDecompressedBytes ?? Infinity),
|
|
13799
|
+
validateFetchedIpc: (bytes) => {
|
|
13800
|
+
this.policy.repository.resolver.validateFetchedIpc?.(bytes);
|
|
13801
|
+
if (bytes.length !== m.rawSize)
|
|
13802
|
+
throw new Error("catalog publication raw size mismatch");
|
|
13803
|
+
validateCatalogPublicationEnvelope(bytes);
|
|
13804
|
+
}
|
|
13805
|
+
});
|
|
13806
|
+
if (resolved.numRows !== 1 || resolved.schema.fields.length !== 1 || resolved.schema.fields[0].name !== "result" || typeSignature(resolved.schema.fields[0].type) !== typeSignature(binary2()) || resolved.schema.fields[0].nullable)
|
|
13807
|
+
throw new Error("invalid published RPC envelope");
|
|
13808
|
+
const bytes = resolved.getChild("result")?.get(0);
|
|
13809
|
+
if (!(bytes instanceof Uint8Array))
|
|
13810
|
+
throw new Error("published catalog has no result bytes");
|
|
13811
|
+
const decoded = decodeASDCollection(CatalogContentsResultSchema, bytes);
|
|
13812
|
+
if (decoded.length !== 1)
|
|
13813
|
+
throw new Error("published catalog must contain exactly one response row");
|
|
13814
|
+
const response = decoded[0];
|
|
13815
|
+
if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag)
|
|
13816
|
+
throw new Error("published catalog version or ETag mismatch");
|
|
13817
|
+
decodeCatalogStreams(response);
|
|
13818
|
+
if (expected)
|
|
13819
|
+
for (const kind of CATALOG_STREAM_KINDS) {
|
|
13820
|
+
const a = response[kind], b = expected[kind];
|
|
13821
|
+
if (a == null !== (b == null) || a != null && b != null && !equalBytes3(a, b))
|
|
13822
|
+
throw new Error("publication readback changed catalog metadata");
|
|
13823
|
+
}
|
|
13824
|
+
}
|
|
13825
|
+
async import(manifest, identity) {
|
|
13826
|
+
const key = await this.key(identity);
|
|
13827
|
+
await this.validate(manifest, key, identity);
|
|
13828
|
+
const winner = await this.policy.repository.commitIfAbsent(manifest);
|
|
13829
|
+
if (!manifestSame(manifest, winner))
|
|
13830
|
+
await this.validate(winner, key, identity);
|
|
13831
|
+
this.remember(winner);
|
|
13832
|
+
return winner;
|
|
13833
|
+
}
|
|
13834
|
+
async warm(identity, build) {
|
|
13835
|
+
const key = await this.key(identity);
|
|
13836
|
+
const cached = this.cached.get(key);
|
|
13837
|
+
if (cached && this.usable(cached))
|
|
13838
|
+
return cached;
|
|
13839
|
+
const active = this.pending.get(key);
|
|
13840
|
+
if (active)
|
|
13841
|
+
return active;
|
|
13842
|
+
const pending = this.recoverOrPublish(key, identity, build);
|
|
13843
|
+
this.pending.set(key, pending);
|
|
13844
|
+
try {
|
|
13845
|
+
const m = await pending;
|
|
13846
|
+
this.remember(m);
|
|
13847
|
+
return m;
|
|
13848
|
+
} finally {
|
|
13849
|
+
if (this.pending.get(key) === pending)
|
|
13850
|
+
this.pending.delete(key);
|
|
13851
|
+
}
|
|
13852
|
+
}
|
|
13853
|
+
async recoverOrPublish(key, identity, build) {
|
|
13854
|
+
const repository = this.policy.repository;
|
|
13855
|
+
let existing = await repository.lookup(key);
|
|
13856
|
+
if (existing) {
|
|
13857
|
+
try {
|
|
13858
|
+
if (!this.usable(existing) && repository.renew) {
|
|
13859
|
+
const renewed = await repository.renew(existing);
|
|
13860
|
+
if (renewed) {
|
|
13861
|
+
assertRenewedPublication(existing, renewed);
|
|
13862
|
+
existing = renewed;
|
|
13863
|
+
}
|
|
13864
|
+
}
|
|
13865
|
+
await this.validate(existing, key, identity);
|
|
13866
|
+
return existing;
|
|
13867
|
+
} catch {
|
|
13868
|
+
await repository.invalidate(key, existing);
|
|
13869
|
+
}
|
|
13870
|
+
}
|
|
13871
|
+
const response = await build();
|
|
13872
|
+
if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion)
|
|
13873
|
+
throw new Error("publication requires a full snapshot of the requested version");
|
|
13874
|
+
decodeCatalogStreams(response);
|
|
13875
|
+
response.etag ??= await catalogContentsDigest(response, identity.catalogVersion);
|
|
13876
|
+
const payload = encodeASD(CatalogContentsResultSchema, response);
|
|
13877
|
+
let rawSize = 0, storedSize = 0;
|
|
13878
|
+
const bounded = { upload: async (data, encoding) => {
|
|
13879
|
+
if (encoding)
|
|
13880
|
+
throw new Error("catalog publication uploader requires identity encoding");
|
|
13881
|
+
rawSize = data.byteLength;
|
|
13882
|
+
if (rawSize > (this.policy.maxRawBytes ?? DEFAULT_MAX))
|
|
13883
|
+
throw new Error("catalog publication exceeds byte limit");
|
|
13884
|
+
let body = data;
|
|
13885
|
+
const compression = this.policy.compression ?? "identity";
|
|
13886
|
+
if (compression !== "identity" && compression !== "gzip" && compression !== "zstd")
|
|
13887
|
+
throw new Error("catalog publication compression must be identity, gzip or zstd");
|
|
13888
|
+
if (compression === "gzip") {
|
|
13889
|
+
body = new Uint8Array(await new Response(new Blob([data]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer());
|
|
13890
|
+
} else if (compression === "zstd") {
|
|
13891
|
+
const runtime = globalThis.Bun;
|
|
13892
|
+
if (typeof runtime?.zstdCompress === "function") {
|
|
13893
|
+
body = new Uint8Array(await runtime.zstdCompress(data));
|
|
13894
|
+
} else if (typeof process !== "undefined" && process.versions?.node) {
|
|
13895
|
+
const nodeZlib = "node:zlib";
|
|
13896
|
+
const zlib = await import(nodeZlib);
|
|
13897
|
+
if (typeof zlib.zstdCompressSync !== "function")
|
|
13898
|
+
throw new Error("zstd catalog publication requires Node >=22.15, Bun, or an encoder-capable runtime");
|
|
13899
|
+
body = new Uint8Array(zlib.zstdCompressSync(data));
|
|
13900
|
+
} else {
|
|
13901
|
+
throw new Error("zstd catalog publication requires an encoder-capable runtime; use gzip or identity here");
|
|
13902
|
+
}
|
|
13903
|
+
}
|
|
13904
|
+
storedSize = body.byteLength;
|
|
13905
|
+
if (storedSize > (this.policy.maxStoredBytes ?? DEFAULT_MAX))
|
|
13906
|
+
throw new Error("catalog publication exceeds byte limit");
|
|
13907
|
+
return repository.storage.upload(body, compression === "identity" ? "" : compression);
|
|
13908
|
+
} };
|
|
13909
|
+
const ref = await publishExternalResult(OUTER_SCHEMA, { result: payload }, bounded, { includeSha256: true });
|
|
13910
|
+
const m = {
|
|
13911
|
+
formatVersion: 1,
|
|
13912
|
+
manifestId: crypto.randomUUID(),
|
|
13913
|
+
key,
|
|
13914
|
+
protocolName: VGI_PROTOCOL_NAME,
|
|
13915
|
+
protocolVersion: VGI_PROTOCOL_VERSION,
|
|
13916
|
+
contractHash: VGI_CATALOG_CONTRACT_HASH,
|
|
13917
|
+
codecRevision: 1,
|
|
13918
|
+
catalogVersion: identity.catalogVersion,
|
|
13919
|
+
etag: response.etag,
|
|
13920
|
+
sha256: ref.sha256,
|
|
13921
|
+
rawSize,
|
|
13922
|
+
storedSize,
|
|
13923
|
+
url: ref.url,
|
|
13924
|
+
validated: true,
|
|
13925
|
+
...await repository.describe(ref.url)
|
|
13926
|
+
};
|
|
13927
|
+
await this.validate(m, key, identity, response);
|
|
13928
|
+
const winner = await repository.commitIfAbsent(m);
|
|
13929
|
+
if (!manifestSame(m, winner))
|
|
13930
|
+
await this.validate(winner, key, identity);
|
|
13931
|
+
return winner;
|
|
13932
|
+
}
|
|
13933
|
+
}
|
|
13934
|
+
|
|
13246
13935
|
// src/protocol/handlers/catalog/contents.ts
|
|
13936
|
+
var schemaPathKey3 = (path) => JSON.stringify(path.map((part) => part.toLowerCase()));
|
|
13937
|
+
var PUBLICATIONS = new WeakMap;
|
|
13247
13938
|
var CACHE = new WeakMap;
|
|
13248
13939
|
async function buildCatalogContents(cat, owner, attach, version, ifNoneMatch) {
|
|
13249
13940
|
const result = await cat.catalogContents(attach, ifNoneMatch);
|
|
@@ -13258,39 +13949,74 @@ async function buildCatalogContents(cat, owner, attach, version, ifNoneMatch) {
|
|
|
13258
13949
|
return buildCatalogContentsResponse({ catalog_version: version, etag: etag0, not_modified: true });
|
|
13259
13950
|
}
|
|
13260
13951
|
const infos = [...result.schemas ?? []];
|
|
13261
|
-
const keys = infos.map((c) =>
|
|
13952
|
+
const keys = infos.map((c) => schemaPathKey3(c.schema.path));
|
|
13262
13953
|
const keySet = new Set(keys);
|
|
13263
13954
|
if (keySet.size !== keys.length)
|
|
13264
13955
|
throw new Error("catalog_contents returned duplicate schema paths");
|
|
13265
13956
|
for (const c of infos) {
|
|
13266
|
-
if (c.schema.path.length > 1 && !keySet.has(
|
|
13957
|
+
if (c.schema.path.length > 1 && !keySet.has(schemaPathKey3(c.schema.path.slice(0, -1)))) {
|
|
13267
13958
|
throw new Error(`catalog_contents returned schema path ${JSON.stringify(c.schema.path)} without its parent`);
|
|
13268
13959
|
}
|
|
13269
13960
|
}
|
|
13270
|
-
const
|
|
13271
|
-
path: [...c.schema.path],
|
|
13272
|
-
schema: encodeSchemaInfo(c.schema),
|
|
13273
|
-
tables: c.tables.map((t) => encodeTableInfo(t)),
|
|
13274
|
-
views: c.views.map((v) => encodeViewInfo(v)),
|
|
13275
|
-
scalar_functions: c.scalar_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
13276
|
-
aggregate_functions: c.aggregate_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
13277
|
-
table_functions: c.table_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
13278
|
-
scalar_macros: c.scalar_macros.map((m) => encodeMacroInfo(m)),
|
|
13279
|
-
table_macros: c.table_macros.map((m) => encodeMacroInfo(m)),
|
|
13280
|
-
indexes: c.indexes.map((i) => encodeIndexInfo(i))
|
|
13281
|
-
}));
|
|
13961
|
+
const streams = encodeCatalogStreams(infos.sort((a, b) => a.schema.path.length - b.schema.path.length));
|
|
13282
13962
|
let etag = etag0;
|
|
13283
13963
|
if (etag === null && owner.catalogContentsEtag === "content-hash") {
|
|
13284
|
-
etag = await catalogContentsDigest(
|
|
13964
|
+
etag = await catalogContentsDigest(streams, version);
|
|
13285
13965
|
}
|
|
13286
13966
|
if (etag !== null && ifNoneMatch !== null && etag === ifNoneMatch) {
|
|
13287
13967
|
return buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true });
|
|
13288
13968
|
}
|
|
13289
|
-
|
|
13969
|
+
const response = buildCatalogContentsResponse({ catalog_version: version, etag, ...streams });
|
|
13970
|
+
decodeCatalogStreams(response);
|
|
13971
|
+
return response;
|
|
13290
13972
|
}
|
|
13291
|
-
async function serveCatalogContents(cat, attach, ifNoneMatch) {
|
|
13973
|
+
async function serveCatalogContents(cat, attach, ifNoneMatch, callContext, sealedAttach = attach) {
|
|
13292
13974
|
const owner = cat.catalogContentsOwner(attach);
|
|
13293
13975
|
const version = Number(await cat.version(attach));
|
|
13976
|
+
const policy = owner.catalogSnapshotPolicy;
|
|
13977
|
+
if (policy?.delivery === "published") {
|
|
13978
|
+
const request = { catalog: cat, attachOpaqueData: attach, callContext, catalogVersion: version };
|
|
13979
|
+
const inline = (etag) => wrapResult(buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true }), CatalogContentsResultSchema);
|
|
13980
|
+
const cheapEtag = await policy.etag?.(request);
|
|
13981
|
+
if (cheapEtag != null && cheapEtag === ifNoneMatch)
|
|
13982
|
+
return inline(cheapEtag);
|
|
13983
|
+
let manager = PUBLICATIONS.get(policy);
|
|
13984
|
+
if (!manager) {
|
|
13985
|
+
manager = new CatalogSnapshotManager(policy);
|
|
13986
|
+
PUBLICATIONS.set(policy, manager);
|
|
13987
|
+
}
|
|
13988
|
+
const scopeBytes = new Uint8Array(await crypto.subtle.digest("SHA-256", sealedAttach));
|
|
13989
|
+
const attachmentScope = "attachment:" + Array.from(scopeBytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
13990
|
+
const identify = async (input) => {
|
|
13991
|
+
const id = await policy.identity(input);
|
|
13992
|
+
return { ...id, visibilityScope: id.visibilityScope ?? attachmentScope };
|
|
13993
|
+
};
|
|
13994
|
+
const identity = await identify(request);
|
|
13995
|
+
if (identity.catalogVersion !== version)
|
|
13996
|
+
throw new Error("snapshot identity version differs from the attached catalog");
|
|
13997
|
+
const assertCurrentIdentity = async () => {
|
|
13998
|
+
const currentVersion = Number(await cat.version(attach));
|
|
13999
|
+
const current = await identify({ ...request, catalogVersion: currentVersion });
|
|
14000
|
+
if (currentVersion !== version || await manager.key(identity) !== await manager.key(current))
|
|
14001
|
+
throw new Error("catalog changed while resolving its publication");
|
|
14002
|
+
};
|
|
14003
|
+
const buildSnapshot = async (validator) => {
|
|
14004
|
+
const response = await buildCatalogContents(cat, owner, attach, version, validator);
|
|
14005
|
+
await assertCurrentIdentity();
|
|
14006
|
+
return response;
|
|
14007
|
+
};
|
|
14008
|
+
try {
|
|
14009
|
+
const manifest = await manager.warm(identity, () => buildSnapshot(null));
|
|
14010
|
+
await assertCurrentIdentity();
|
|
14011
|
+
if (manifest.etag === ifNoneMatch)
|
|
14012
|
+
return inline(manifest.etag);
|
|
14013
|
+
return new ExternalRef2(manifest.url, manifest.sha256);
|
|
14014
|
+
} catch (error) {
|
|
14015
|
+
if (policy.onPublicationFailure !== "ordinary")
|
|
14016
|
+
throw error;
|
|
14017
|
+
return wrapResult(await buildSnapshot(ifNoneMatch), CatalogContentsResultSchema);
|
|
14018
|
+
}
|
|
14019
|
+
}
|
|
13294
14020
|
if (owner.catalogContentsCacheable()) {
|
|
13295
14021
|
let pending = CACHE.get(owner);
|
|
13296
14022
|
let snapshot = pending ? await pending.catch(() => null) : null;
|
|
@@ -13331,7 +14057,7 @@ import {
|
|
|
13331
14057
|
var ATTACH_TICKET_PREFIX = "vgia1.";
|
|
13332
14058
|
var ATTACH_TICKET_OPTION = RESERVED_ATTACH_OPTION;
|
|
13333
14059
|
var ATTACH_TICKETS_PROTOCOL_NAME = "vgi.attach_tickets.v1";
|
|
13334
|
-
var ATTACH_TICKETS_PROTOCOL_VERSION = "
|
|
14060
|
+
var ATTACH_TICKETS_PROTOCOL_VERSION = "2.0.0";
|
|
13335
14061
|
var TICKET_ENVELOPE_VERSION = 1;
|
|
13336
14062
|
var MAX_OPTIONS_BYTES = 16 * 1024;
|
|
13337
14063
|
var MAX_TICKET_CHARS = 32 * 1024;
|
|
@@ -13606,8 +14332,19 @@ var SEAL_ATTACH_REQUEST_SCHEMA = schema2([
|
|
|
13606
14332
|
]);
|
|
13607
14333
|
var ATTACH_TICKET_SCHEMA = schema2([
|
|
13608
14334
|
field2("ticket", utf82(), false),
|
|
13609
|
-
field2("expires_at",
|
|
14335
|
+
field2("expires_at", timestamp2(TimeUnit2.MICROSECOND, "UTC"), true)
|
|
13610
14336
|
]);
|
|
14337
|
+
function expiresAtMicros(value) {
|
|
14338
|
+
if (value === null)
|
|
14339
|
+
return null;
|
|
14340
|
+
const ms = value.getTime();
|
|
14341
|
+
if (!Number.isFinite(ms))
|
|
14342
|
+
throw new TypeError("AttachTicket.expires_at must be a valid Date or null");
|
|
14343
|
+
return BigInt(ms) * 1000n;
|
|
14344
|
+
}
|
|
14345
|
+
function encodeAttachTicket(ticket) {
|
|
14346
|
+
return serializeBatch(batchFromColumns({ ticket: [ticket.ticket], expires_at: [expiresAtMicros(ticket.expires_at)] }, ATTACH_TICKET_SCHEMA));
|
|
14347
|
+
}
|
|
13611
14348
|
function resolveTicketMaxTtl(grantKeys, env) {
|
|
13612
14349
|
if (grantKeys)
|
|
13613
14350
|
return Math.trunc(grantKeys.maxTtlSeconds);
|
|
@@ -13694,7 +14431,7 @@ async function sealAttach2(config, request, auth) {
|
|
|
13694
14431
|
} catch (e) {
|
|
13695
14432
|
throw new AttachTicketRequestError("seal_attach request is invalid", [["request", e.message]]);
|
|
13696
14433
|
}
|
|
13697
|
-
return { ticket: token, expires_at: expiresAt === 0 ?
|
|
14434
|
+
return { ticket: token, expires_at: expiresAt === 0 ? null : new Date(expiresAt * 1000) };
|
|
13698
14435
|
}
|
|
13699
14436
|
function buildAttachTicketsProtocol(config) {
|
|
13700
14437
|
const p = new Protocol2(ATTACH_TICKETS_PROTOCOL_NAME, { protocolVersion: ATTACH_TICKETS_PROTOCOL_VERSION });
|
|
@@ -13705,8 +14442,7 @@ function buildAttachTicketsProtocol(config) {
|
|
|
13705
14442
|
handler: async (params, ctx) => {
|
|
13706
14443
|
const request = unwrapRequest(params.request);
|
|
13707
14444
|
const sealed = await sealAttach2(config, request, ctx?.auth);
|
|
13708
|
-
|
|
13709
|
-
return { result: serializeBatch(batch) };
|
|
14445
|
+
return { result: encodeAttachTicket(sealed) };
|
|
13710
14446
|
}
|
|
13711
14447
|
});
|
|
13712
14448
|
return p;
|
|
@@ -13792,10 +14528,13 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
13792
14528
|
items: schemas.map((s) => encodeSchemaInfo(s))
|
|
13793
14529
|
}, CatalogSchemasResultSchema);
|
|
13794
14530
|
});
|
|
13795
|
-
const catalogContents =
|
|
13796
|
-
const
|
|
13797
|
-
return
|
|
13798
|
-
|
|
14531
|
+
const catalogContents = async (params, ctx) => {
|
|
14532
|
+
const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
|
|
14533
|
+
return catalogHandler(signingKey, async (opened, context) => {
|
|
14534
|
+
const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
|
|
14535
|
+
return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
|
|
14536
|
+
})(params, ctx);
|
|
14537
|
+
};
|
|
13799
14538
|
const catalogCopyFromFormats = catalogHandler(signingKey, async (params) => {
|
|
13800
14539
|
const cat = getCatalog();
|
|
13801
14540
|
const formats = await cat.copyFromFormats(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
@@ -14386,6 +15125,10 @@ function toAsyncIterator(input) {
|
|
|
14386
15125
|
}
|
|
14387
15126
|
|
|
14388
15127
|
// src/client/client.ts
|
|
15128
|
+
function onConflictName(onConflict) {
|
|
15129
|
+
return String(onConflict).toUpperCase();
|
|
15130
|
+
}
|
|
15131
|
+
|
|
14389
15132
|
class VgiClient {
|
|
14390
15133
|
rpc;
|
|
14391
15134
|
defaultAttachOpaqueData;
|
|
@@ -14718,23 +15461,7 @@ class VgiClient {
|
|
|
14718
15461
|
if (!result)
|
|
14719
15462
|
throw new VgiClientError("catalog_contents returned null");
|
|
14720
15463
|
const response = decodeCatalogContentsResponse(toUint8Array(result.result));
|
|
14721
|
-
const schemas = response
|
|
14722
|
-
const schema = decodeSchemaInfo(c.schema);
|
|
14723
|
-
if (JSON.stringify(c.path) !== JSON.stringify(schema.path)) {
|
|
14724
|
-
throw new VgiClientError(`catalog_contents: SchemaContents.path ${JSON.stringify(c.path)} != SchemaInfo.path ${JSON.stringify(schema.path)}`);
|
|
14725
|
-
}
|
|
14726
|
-
return {
|
|
14727
|
-
schema,
|
|
14728
|
-
tables: c.tables.map(decodeTableInfo),
|
|
14729
|
-
views: c.views.map(decodeViewInfo),
|
|
14730
|
-
scalar_functions: c.scalar_functions.map(decodeFunctionInfo),
|
|
14731
|
-
aggregate_functions: c.aggregate_functions.map(decodeFunctionInfo),
|
|
14732
|
-
table_functions: c.table_functions.map(decodeFunctionInfo),
|
|
14733
|
-
scalar_macros: c.scalar_macros.map(decodeMacroInfo),
|
|
14734
|
-
table_macros: c.table_macros.map(decodeMacroInfo),
|
|
14735
|
-
indexes: c.indexes.map(decodeIndexInfo)
|
|
14736
|
-
};
|
|
14737
|
-
});
|
|
15464
|
+
const schemas = decodeCatalogStreams(response, ifNoneMatch);
|
|
14738
15465
|
return {
|
|
14739
15466
|
catalog_version: Number(response.catalog_version ?? 0),
|
|
14740
15467
|
etag: response.etag ?? null,
|
|
@@ -14841,7 +15568,7 @@ class VgiClient {
|
|
|
14841
15568
|
}
|
|
14842
15569
|
await this.rpc.call("catalog_create", {
|
|
14843
15570
|
name,
|
|
14844
|
-
on_conflict: onConflict,
|
|
15571
|
+
on_conflict: onConflictName(onConflict),
|
|
14845
15572
|
options: wireOptions
|
|
14846
15573
|
});
|
|
14847
15574
|
}
|
|
@@ -14909,7 +15636,7 @@ class VgiClient {
|
|
|
14909
15636
|
await this.rpc.call("catalog_schema_create", {
|
|
14910
15637
|
attach_opaque_data: attachOpaqueData,
|
|
14911
15638
|
path: normalizeSchemaPath(path),
|
|
14912
|
-
on_conflict: opts?.onConflict ?? "error",
|
|
15639
|
+
on_conflict: onConflictName(opts?.onConflict ?? "error"),
|
|
14913
15640
|
comment: opts?.comment ?? null,
|
|
14914
15641
|
tags: tagsMap,
|
|
14915
15642
|
transaction_opaque_data: opts?.transactionOpaqueData ?? null
|
|
@@ -14988,7 +15715,7 @@ class VgiClient {
|
|
|
14988
15715
|
schema_path: normalizeSchemaPath(schemaPath),
|
|
14989
15716
|
name,
|
|
14990
15717
|
columns,
|
|
14991
|
-
on_conflict: onConflict,
|
|
15718
|
+
on_conflict: onConflictName(onConflict),
|
|
14992
15719
|
not_null_constraints: notNullConstraints ?? null,
|
|
14993
15720
|
unique_constraints: uniqueConstraints ?? null,
|
|
14994
15721
|
check_constraints: checkConstraints ?? null,
|
|
@@ -15142,7 +15869,7 @@ class VgiClient {
|
|
|
15142
15869
|
schema_path: normalizeSchemaPath(schemaPath),
|
|
15143
15870
|
name,
|
|
15144
15871
|
definition,
|
|
15145
|
-
on_conflict: onConflict,
|
|
15872
|
+
on_conflict: onConflictName(onConflict),
|
|
15146
15873
|
transaction_opaque_data: transactionOpaqueData ?? null
|
|
15147
15874
|
});
|
|
15148
15875
|
}
|
|
@@ -15209,7 +15936,7 @@ class VgiClient {
|
|
|
15209
15936
|
macro_type: [macroType],
|
|
15210
15937
|
parameters: [parameters],
|
|
15211
15938
|
definition: [definition],
|
|
15212
|
-
on_conflict: [onConflict],
|
|
15939
|
+
on_conflict: [onConflictName(onConflict)],
|
|
15213
15940
|
parameter_default_values: [parameterDefaultValues ?? null],
|
|
15214
15941
|
arguments_schema: [argumentsSchema ?? null],
|
|
15215
15942
|
transaction_opaque_data: [transactionOpaqueData ?? null]
|
|
@@ -15286,7 +16013,7 @@ function validatedHostedProtocols(hosting, primary) {
|
|
|
15286
16013
|
}
|
|
15287
16014
|
const name = p.name;
|
|
15288
16015
|
if (name.startsWith(RESERVED_PREFIX)) {
|
|
15289
|
-
throw new Error(`${owner} entry ${index} is named '${name}', which claims the reserved '${RESERVED_PREFIX}' prefix. ` + "Framework protocols are not supplied through this hook: reflection is hosted automatically, and " + "vgi_rpc.Identity.
|
|
16016
|
+
throw new Error(`${owner} entry ${index} is named '${name}', which claims the reserved '${RESERVED_PREFIX}' prefix. ` + "Framework protocols are not supplied through this hook: reflection is hosted automatically, and " + "vgi_rpc.Identity.v2 is enabled by supplying resolveToken and/or mintGrant.");
|
|
15290
16017
|
}
|
|
15291
16018
|
if (!/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name)) {
|
|
15292
16019
|
throw new Error(`${owner} entry ${index}: protocol name '${name}' is not an identifier, optionally dot-qualified ` + "(e.g. 'acme.Reports.v1').");
|
|
@@ -15336,7 +16063,7 @@ function resolveIntrospectPrincipals(explicit, env) {
|
|
|
15336
16063
|
principals = raw.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
15337
16064
|
}
|
|
15338
16065
|
if (principals.length === 0) {
|
|
15339
|
-
throw new Error("This worker supplies resolveToken, which hosts the vgi_rpc.Identity.
|
|
16066
|
+
throw new Error("This worker supplies resolveToken, which hosts the vgi_rpc.Identity.v2 protocol, but no " + `introspector allowlist was configured. Set ${INTROSPECT_PRINCIPALS_ENV} (comma-separated) or pass ` + `introspectPrincipals.
|
|
15340
16067
|
|
|
15341
16068
|
` + "There is no permissive default on purpose: introspection is a separate capability from " + "authentication, and allowing every authenticated caller lets any user resolve any other user's " + "credential to its owner. Remove resolveToken to leave the protocol unhosted entirely.");
|
|
15342
16069
|
}
|
|
@@ -15563,6 +16290,111 @@ ${err.stack}
|
|
|
15563
16290
|
await serveStreamRpc(this.buildServer(this.buildProtocol(), "stream"), { readable, writable });
|
|
15564
16291
|
}
|
|
15565
16292
|
}
|
|
16293
|
+
// src/catalog/s3-publication.ts
|
|
16294
|
+
class S3CatalogObjectStorage {
|
|
16295
|
+
sign;
|
|
16296
|
+
request;
|
|
16297
|
+
objectPrefix;
|
|
16298
|
+
retentionMs;
|
|
16299
|
+
locations = new Map;
|
|
16300
|
+
constructor(sign, request = fetch, objectPrefix = "vgi/catalog-results/", retentionMs) {
|
|
16301
|
+
this.sign = sign;
|
|
16302
|
+
this.request = request;
|
|
16303
|
+
this.objectPrefix = objectPrefix;
|
|
16304
|
+
this.retentionMs = retentionMs;
|
|
16305
|
+
}
|
|
16306
|
+
async upload(data, contentEncoding) {
|
|
16307
|
+
const key = `${this.objectPrefix}${crypto.randomUUID()}.arrow`;
|
|
16308
|
+
const headers = { "Content-Type": "application/vnd.apache.arrow.stream", "If-None-Match": "*" };
|
|
16309
|
+
if (contentEncoding)
|
|
16310
|
+
headers["Content-Encoding"] = contentEncoding;
|
|
16311
|
+
const put = await this.sign({ key, method: "PUT", headers });
|
|
16312
|
+
const response = await this.request(put.url, { method: "PUT", headers, body: data, redirect: "error", signal: AbortSignal.timeout(30000) });
|
|
16313
|
+
if (!response.ok)
|
|
16314
|
+
throw new Error(`catalog object upload failed (${response.status})`);
|
|
16315
|
+
const get = await this.sign({ key, method: "GET", headers: {} });
|
|
16316
|
+
if (!get.stable && get.expiresAt == null)
|
|
16317
|
+
throw new Error("S3 catalog signer must declare GET URL expiration or stability");
|
|
16318
|
+
this.locations.set(get.url, {
|
|
16319
|
+
objectId: key,
|
|
16320
|
+
expiresAt: get.expiresAt,
|
|
16321
|
+
stable: get.stable ?? false,
|
|
16322
|
+
retainUntil: this.retentionMs == null ? undefined : Date.now() + this.retentionMs
|
|
16323
|
+
});
|
|
16324
|
+
return get.url;
|
|
16325
|
+
}
|
|
16326
|
+
async describe(url) {
|
|
16327
|
+
const value = this.locations.get(url);
|
|
16328
|
+
if (!value)
|
|
16329
|
+
throw new Error("unknown catalog object location");
|
|
16330
|
+
this.locations.delete(url);
|
|
16331
|
+
return value;
|
|
16332
|
+
}
|
|
16333
|
+
async get(key) {
|
|
16334
|
+
const signed = await this.sign({ key, method: "GET", headers: {} });
|
|
16335
|
+
const response = await this.request(signed.url, { redirect: "error", signal: AbortSignal.timeout(30000) });
|
|
16336
|
+
if (response.status === 404)
|
|
16337
|
+
return null;
|
|
16338
|
+
if (!response.ok)
|
|
16339
|
+
throw new Error(`catalog manifest GET failed (${response.status})`);
|
|
16340
|
+
const etag = response.headers.get("etag");
|
|
16341
|
+
if (!etag)
|
|
16342
|
+
throw new Error("S3 catalog manifest lacks conditional-operation ETag");
|
|
16343
|
+
const reader = response.body?.getReader();
|
|
16344
|
+
if (!reader)
|
|
16345
|
+
throw new Error("empty catalog manifest body");
|
|
16346
|
+
let size = 0;
|
|
16347
|
+
const parts = [];
|
|
16348
|
+
while (true) {
|
|
16349
|
+
const { done, value } = await reader.read();
|
|
16350
|
+
if (done)
|
|
16351
|
+
break;
|
|
16352
|
+
size += value.byteLength;
|
|
16353
|
+
if (size > 64 * 1024) {
|
|
16354
|
+
await reader.cancel();
|
|
16355
|
+
throw new Error("catalog manifest exceeds 64 KiB");
|
|
16356
|
+
}
|
|
16357
|
+
parts.push(value);
|
|
16358
|
+
}
|
|
16359
|
+
const body = new Uint8Array(size);
|
|
16360
|
+
let offset = 0;
|
|
16361
|
+
for (const part of parts) {
|
|
16362
|
+
body.set(part, offset);
|
|
16363
|
+
offset += part.byteLength;
|
|
16364
|
+
}
|
|
16365
|
+
return { body, etag };
|
|
16366
|
+
}
|
|
16367
|
+
async put(key, body, condition) {
|
|
16368
|
+
const headers = { "Content-Type": "application/json", ..."ifNoneMatch" in condition ? { "If-None-Match": condition.ifNoneMatch } : { "If-Match": condition.ifMatch } };
|
|
16369
|
+
const signed = await this.sign({ key, method: "PUT", headers });
|
|
16370
|
+
const response = await this.request(signed.url, { method: "PUT", headers, body, redirect: "error", signal: AbortSignal.timeout(30000) });
|
|
16371
|
+
if (response.status === 412 || response.status === 409)
|
|
16372
|
+
return false;
|
|
16373
|
+
if (!response.ok)
|
|
16374
|
+
throw new Error(`catalog manifest PUT failed (${response.status})`);
|
|
16375
|
+
return true;
|
|
16376
|
+
}
|
|
16377
|
+
async delete(key, condition) {
|
|
16378
|
+
const headers = { "If-Match": condition.ifMatch };
|
|
16379
|
+
const signed = await this.sign({ key, method: "DELETE", headers });
|
|
16380
|
+
const response = await this.request(signed.url, { method: "DELETE", headers, redirect: "error", signal: AbortSignal.timeout(30000) });
|
|
16381
|
+
if (response.status === 412 || response.status === 404)
|
|
16382
|
+
return false;
|
|
16383
|
+
if (!response.ok)
|
|
16384
|
+
throw new Error(`catalog manifest DELETE failed (${response.status})`);
|
|
16385
|
+
return true;
|
|
16386
|
+
}
|
|
16387
|
+
repository(profile, resolver = {}, manifestPrefix = "vgi/catalog-manifests/") {
|
|
16388
|
+
const repository = new S3CatalogPublicationRepository(profile, this, { ...resolver, storage: this }, this, (url) => this.describe(url), manifestPrefix);
|
|
16389
|
+
repository.renewReference = async (manifest) => {
|
|
16390
|
+
if (!manifest.objectId)
|
|
16391
|
+
return null;
|
|
16392
|
+
const signed = await this.sign({ key: manifest.objectId, method: "GET", headers: {} });
|
|
16393
|
+
return { ...manifest, manifestId: crypto.randomUUID(), url: signed.url, expiresAt: signed.expiresAt, stable: signed.stable ?? false };
|
|
16394
|
+
};
|
|
16395
|
+
return repository;
|
|
16396
|
+
}
|
|
16397
|
+
}
|
|
15566
16398
|
export {
|
|
15567
16399
|
ATTACH_TICKETS_PROTOCOL_NAME,
|
|
15568
16400
|
ATTACH_TICKETS_PROTOCOL_VERSION,
|
|
@@ -15600,6 +16432,7 @@ export {
|
|
|
15600
16432
|
CatalogInterface,
|
|
15601
16433
|
CatalogNotFoundError,
|
|
15602
16434
|
CatalogReadOnlyError,
|
|
16435
|
+
CatalogSnapshotManager,
|
|
15603
16436
|
ComparisonOp,
|
|
15604
16437
|
CompositeCatalogInterface,
|
|
15605
16438
|
DEFAULT_MAX_WORKERS,
|
|
@@ -15619,6 +16452,7 @@ export {
|
|
|
15619
16452
|
INTROSPECT_PRINCIPALS_ENV,
|
|
15620
16453
|
IdentityUnavailableError,
|
|
15621
16454
|
IntervalUnit2 as IntervalUnit,
|
|
16455
|
+
MemoryCatalogPublicationRepository,
|
|
15622
16456
|
NoCatalogError,
|
|
15623
16457
|
NullHandling,
|
|
15624
16458
|
OrderDependence,
|
|
@@ -15631,6 +16465,8 @@ export {
|
|
|
15631
16465
|
ReadOnlyCatalogInterface,
|
|
15632
16466
|
ReservedAttachOptionError,
|
|
15633
16467
|
RowCountMismatchError,
|
|
16468
|
+
S3CatalogObjectStorage,
|
|
16469
|
+
S3CatalogPublicationRepository,
|
|
15634
16470
|
SEAL_ATTACH_REQUEST_SCHEMA,
|
|
15635
16471
|
ScanFunctionResultSchema,
|
|
15636
16472
|
SealAttachDeniedError,
|
|
@@ -15719,6 +16555,7 @@ export {
|
|
|
15719
16555
|
durationNanos,
|
|
15720
16556
|
durationSeconds,
|
|
15721
16557
|
emptyBatch,
|
|
16558
|
+
encodeAttachTicket,
|
|
15722
16559
|
encodeCatalogInfo,
|
|
15723
16560
|
encodeCopyFromFormatInfo,
|
|
15724
16561
|
encodeFormatOptions,
|
|
@@ -15832,4 +16669,4 @@ export {
|
|
|
15832
16669
|
utf82 as utf8
|
|
15833
16670
|
};
|
|
15834
16671
|
|
|
15835
|
-
//# debugId=
|
|
16672
|
+
//# debugId=0EC791465ED38B7C64756E2164756E21
|