@query-farm/vgi 0.48.3 → 0.48.5
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 +51 -0
- package/dist/attach-secret-keyfile.d.ts +11 -0
- package/dist/attach-secret-options.d.ts +96 -0
- package/dist/catalog/attach-option.d.ts +6 -0
- package/dist/catalog/descriptors.d.ts +30 -0
- package/dist/catalog/interface.d.ts +43 -0
- package/dist/catalog/read-only.d.ts +16 -2
- package/dist/client-entry.js +1 -1
- package/dist/client-entry.js.map +4 -4
- package/dist/index.core.d.ts +4 -0
- package/dist/index.js +5854 -5234
- package/dist/index.js.map +28 -25
- package/dist/protocol/dispatch.d.ts +11 -0
- package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
- package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +36 -3
- package/dist/protocol/handlers/catalog/table.d.ts +1 -1
- package/dist/protocol/handlers/catalog/view.d.ts +1 -1
- package/dist/protocol/handlers/function.d.ts +2 -0
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/serve-entry.d.ts +5 -0
- package/dist/serve-entry.js +514 -99
- package/dist/serve-entry.js.map +18 -16
- package/dist/worker-cf-entry.js +629 -108
- package/dist/worker-cf-entry.js.map +21 -18
- package/dist/worker.d.ts +10 -0
- package/dist/write-results.d.ts +57 -0
- package/package.json +1 -1
- package/src/attach-secret-keyfile.ts +185 -0
- package/src/attach-secret-options.ts +418 -0
- package/src/catalog/attach-option.ts +6 -0
- package/src/catalog/descriptors.ts +30 -0
- package/src/catalog/interface.ts +70 -0
- package/src/catalog/read-only.ts +123 -18
- package/src/index.core.ts +33 -0
- package/src/protocol/dispatch.ts +14 -2
- package/src/protocol/handlers/catalog/admin.ts +33 -18
- package/src/protocol/handlers/catalog/index.ts +6 -5
- package/src/protocol/handlers/catalog/index_methods.ts +5 -3
- package/src/protocol/handlers/catalog/macro.ts +7 -5
- package/src/protocol/handlers/catalog/shared.ts +69 -6
- package/src/protocol/handlers/catalog/table.ts +58 -19
- package/src/protocol/handlers/catalog/view.ts +9 -7
- package/src/protocol/handlers/function.ts +53 -19
- package/src/protocol/handlers/table-buffering.ts +2 -1
- package/src/serve-entry.ts +6 -1
- package/src/worker.ts +12 -0
- package/src/write-results.ts +174 -0
package/dist/serve-entry.js
CHANGED
|
@@ -8270,13 +8270,382 @@ async function openBytes(token, key, aad, version, field = "opaque data") {
|
|
|
8270
8270
|
}
|
|
8271
8271
|
}
|
|
8272
8272
|
|
|
8273
|
+
// src/attach-secret-keyfile.ts
|
|
8274
|
+
function builtins() {
|
|
8275
|
+
const proc = globalThis.process;
|
|
8276
|
+
const get = proc?.getBuiltinModule?.bind(proc);
|
|
8277
|
+
const fs = get?.("node:fs");
|
|
8278
|
+
const os = get?.("node:os");
|
|
8279
|
+
const path = get?.("node:path");
|
|
8280
|
+
if (!fs || !os || !path)
|
|
8281
|
+
throw new Error("this runtime has no filesystem for the host-local attach secret key file.");
|
|
8282
|
+
return { fs, os, path };
|
|
8283
|
+
}
|
|
8284
|
+
var ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
|
|
8285
|
+
var KEY_LEN = 32;
|
|
8286
|
+
var FILE_NAME = "attach-secret-options.key";
|
|
8287
|
+
var REMEDY = "Set VGI_SIGNING_KEY (or configure attachSecretKey), or point VGI_ATTACH_SECRET_KEY_FILE at a valid key file.";
|
|
8288
|
+
function username() {
|
|
8289
|
+
try {
|
|
8290
|
+
const name = builtins().os.userInfo().username;
|
|
8291
|
+
if (name)
|
|
8292
|
+
return name;
|
|
8293
|
+
} catch {}
|
|
8294
|
+
return process.env.USER || process.env.USERNAME || String(process.getuid?.() ?? "user");
|
|
8295
|
+
}
|
|
8296
|
+
function isDirectory(path) {
|
|
8297
|
+
try {
|
|
8298
|
+
return builtins().fs.statSync(path).isDirectory();
|
|
8299
|
+
} catch {
|
|
8300
|
+
return false;
|
|
8301
|
+
}
|
|
8302
|
+
}
|
|
8303
|
+
function hostLocalAttachSecretKeyPath(env = globalThis.process?.env ?? {}) {
|
|
8304
|
+
const { os, path: { join } } = builtins();
|
|
8305
|
+
const explicit = env[ATTACH_SECRET_KEY_FILE_ENV];
|
|
8306
|
+
if (explicit)
|
|
8307
|
+
return explicit;
|
|
8308
|
+
const xdg = env.XDG_RUNTIME_DIR;
|
|
8309
|
+
if (xdg && isDirectory(xdg))
|
|
8310
|
+
return join(xdg, "vgi", FILE_NAME);
|
|
8311
|
+
return join(os.tmpdir(), `vgi-${username()}`, FILE_NAME);
|
|
8312
|
+
}
|
|
8313
|
+
var POSIX = typeof process === "undefined" || process.platform !== "win32";
|
|
8314
|
+
function checkOwnedPrivate(path, mode, uid, what) {
|
|
8315
|
+
if (!POSIX)
|
|
8316
|
+
return;
|
|
8317
|
+
const me = process.getuid?.();
|
|
8318
|
+
if (me !== undefined && uid !== me) {
|
|
8319
|
+
throw new Error(`attach secret key ${what} ${path} is not owned by the current user. ${REMEDY}`);
|
|
8320
|
+
}
|
|
8321
|
+
if ((mode & 63) !== 0) {
|
|
8322
|
+
throw new Error(`attach secret key ${what} ${path} is accessible by group/other (mode ${(mode & 511).toString(8)}); ` + `it must be ${what === "directory" ? "0700" : "0600"}. ${REMEDY}`);
|
|
8323
|
+
}
|
|
8324
|
+
}
|
|
8325
|
+
function ensureDir(dir) {
|
|
8326
|
+
const { mkdirSync, lstatSync } = builtins().fs;
|
|
8327
|
+
try {
|
|
8328
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
8329
|
+
} catch (e) {
|
|
8330
|
+
if (e.code !== "EEXIST")
|
|
8331
|
+
throw e;
|
|
8332
|
+
}
|
|
8333
|
+
const st = lstatSync(dir);
|
|
8334
|
+
if (!st.isDirectory())
|
|
8335
|
+
throw new Error(`attach secret key directory ${dir} is not a directory. ${REMEDY}`);
|
|
8336
|
+
checkOwnedPrivate(dir, st.mode, st.uid, "directory");
|
|
8337
|
+
}
|
|
8338
|
+
function readKey(path) {
|
|
8339
|
+
const { openSync, fstatSync, readSync, closeSync, constants } = builtins().fs;
|
|
8340
|
+
let fd;
|
|
8341
|
+
try {
|
|
8342
|
+
fd = openSync(path, constants.O_RDONLY | (POSIX ? constants.O_NOFOLLOW : 0));
|
|
8343
|
+
} catch (e) {
|
|
8344
|
+
if (e.code === "ENOENT")
|
|
8345
|
+
return null;
|
|
8346
|
+
throw new Error(`attach secret key file ${path} cannot be opened (${e.code}). ${REMEDY}`);
|
|
8347
|
+
}
|
|
8348
|
+
try {
|
|
8349
|
+
const st = fstatSync(fd);
|
|
8350
|
+
if (!st.isFile())
|
|
8351
|
+
throw new Error(`attach secret key file ${path} is not a regular file. ${REMEDY}`);
|
|
8352
|
+
checkOwnedPrivate(path, st.mode, st.uid, "file");
|
|
8353
|
+
const buf = new Uint8Array(KEY_LEN + 1);
|
|
8354
|
+
let n = 0;
|
|
8355
|
+
for (;; ) {
|
|
8356
|
+
const got = readSync(fd, buf, n, buf.length - n, null);
|
|
8357
|
+
if (got <= 0)
|
|
8358
|
+
break;
|
|
8359
|
+
n += got;
|
|
8360
|
+
if (n === buf.length)
|
|
8361
|
+
break;
|
|
8362
|
+
}
|
|
8363
|
+
if (n !== KEY_LEN || st.size !== KEY_LEN) {
|
|
8364
|
+
throw new Error(`attach secret key file ${path} must contain exactly ${KEY_LEN} raw bytes (found ${st.size}). ${REMEDY}`);
|
|
8365
|
+
}
|
|
8366
|
+
return buf.subarray(0, KEY_LEN);
|
|
8367
|
+
} finally {
|
|
8368
|
+
closeSync(fd);
|
|
8369
|
+
}
|
|
8370
|
+
}
|
|
8371
|
+
function createKey(path) {
|
|
8372
|
+
const { openSync, writeSync, fsyncSync, closeSync, linkSync, unlinkSync, constants } = builtins().fs;
|
|
8373
|
+
const { dirname, join } = builtins().path;
|
|
8374
|
+
const tmp = join(dirname(path), `.${FILE_NAME}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
8375
|
+
const fd = openSync(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 384);
|
|
8376
|
+
try {
|
|
8377
|
+
const key = crypto.getRandomValues(new Uint8Array(KEY_LEN));
|
|
8378
|
+
let off = 0;
|
|
8379
|
+
while (off < KEY_LEN)
|
|
8380
|
+
off += writeSync(fd, key, off, KEY_LEN - off);
|
|
8381
|
+
fsyncSync(fd);
|
|
8382
|
+
} finally {
|
|
8383
|
+
closeSync(fd);
|
|
8384
|
+
}
|
|
8385
|
+
try {
|
|
8386
|
+
linkSync(tmp, path);
|
|
8387
|
+
} catch (e) {
|
|
8388
|
+
if (e.code !== "EEXIST") {
|
|
8389
|
+
unlinkSync(tmp);
|
|
8390
|
+
throw e;
|
|
8391
|
+
}
|
|
8392
|
+
}
|
|
8393
|
+
unlinkSync(tmp);
|
|
8394
|
+
}
|
|
8395
|
+
function loadHostLocalAttachSecretKey(path = hostLocalAttachSecretKeyPath()) {
|
|
8396
|
+
ensureDir(builtins().path.dirname(path));
|
|
8397
|
+
const existing = readKey(path);
|
|
8398
|
+
if (existing)
|
|
8399
|
+
return existing;
|
|
8400
|
+
createKey(path);
|
|
8401
|
+
const created = readKey(path);
|
|
8402
|
+
if (!created)
|
|
8403
|
+
throw new Error(`attach secret key file ${path} vanished after creation. ${REMEDY}`);
|
|
8404
|
+
return created;
|
|
8405
|
+
}
|
|
8406
|
+
var cached;
|
|
8407
|
+
async function hostLocalAttachSecretKey() {
|
|
8408
|
+
const path = hostLocalAttachSecretKeyPath();
|
|
8409
|
+
if (cached?.path === path)
|
|
8410
|
+
return cached.key;
|
|
8411
|
+
const key = loadHostLocalAttachSecretKey(path);
|
|
8412
|
+
cached = { path, key };
|
|
8413
|
+
return key;
|
|
8414
|
+
}
|
|
8415
|
+
|
|
8416
|
+
// src/attach-secret-options.ts
|
|
8417
|
+
var UTF82 = new TextEncoder;
|
|
8418
|
+
var ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
|
|
8419
|
+
var ATTACH_SECRET_OPTIONS_VERSION = 1;
|
|
8420
|
+
var TRAILER_MAGIC = Uint8Array.of(0, 86, 71, 73, 65, 79, 1, 255);
|
|
8421
|
+
var TRAILER_FIXED = 4 + TRAILER_MAGIC.length;
|
|
8422
|
+
var NONCE_LEN2 = 24;
|
|
8423
|
+
var TAG_LEN2 = 16;
|
|
8424
|
+
var AAD_PREFIX = UTF82.encode(`${ATTACH_SECRET_OPTIONS_INFO}\x00`);
|
|
8425
|
+
var UUID_LEN = 16;
|
|
8426
|
+
var FIELD = "attach_opaque_data";
|
|
8427
|
+
|
|
8428
|
+
class AttachSecretKeyUnavailableError extends Error {
|
|
8429
|
+
constructor(message) {
|
|
8430
|
+
super(message);
|
|
8431
|
+
this.name = "AttachSecretKeyUnavailableError";
|
|
8432
|
+
}
|
|
8433
|
+
}
|
|
8434
|
+
var subkeys = new Map;
|
|
8435
|
+
function hexOf(b) {
|
|
8436
|
+
let s = "";
|
|
8437
|
+
for (let i = 0;i < b.length; i++)
|
|
8438
|
+
s += b[i].toString(16).padStart(2, "0");
|
|
8439
|
+
return s;
|
|
8440
|
+
}
|
|
8441
|
+
function deriveAttachSecretKey(root) {
|
|
8442
|
+
const id = hexOf(root);
|
|
8443
|
+
let derived = subkeys.get(id);
|
|
8444
|
+
if (!derived) {
|
|
8445
|
+
derived = (async () => {
|
|
8446
|
+
const ikm = await crypto.subtle.importKey("raw", root, "HKDF", false, ["deriveBits"]);
|
|
8447
|
+
const bits = await crypto.subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: UTF82.encode(ATTACH_SECRET_OPTIONS_INFO) }, ikm, 256);
|
|
8448
|
+
return new Uint8Array(bits);
|
|
8449
|
+
})();
|
|
8450
|
+
subkeys.set(id, derived);
|
|
8451
|
+
derived.catch(() => subkeys.delete(id));
|
|
8452
|
+
}
|
|
8453
|
+
return derived;
|
|
8454
|
+
}
|
|
8455
|
+
function defaultHostLocal() {
|
|
8456
|
+
return hostLocalAttachSecretKey();
|
|
8457
|
+
}
|
|
8458
|
+
function noKeyMessage() {
|
|
8459
|
+
return "A secret ATTACH option has a value but this worker has no key to encrypt it with: configure " + "`attachSecretKey`, run with a signing key (VGI_SIGNING_KEY), or run where the host-local key file " + "(VGI_ATTACH_SECRET_KEY_FILE) can be used.";
|
|
8460
|
+
}
|
|
8461
|
+
async function rootKey(source) {
|
|
8462
|
+
if (source.explicit && source.explicit.length > 0)
|
|
8463
|
+
return source.explicit;
|
|
8464
|
+
if (source.signingKey && source.signingKey.length > 0)
|
|
8465
|
+
return source.signingKey;
|
|
8466
|
+
return (source.hostLocal ?? defaultHostLocal)();
|
|
8467
|
+
}
|
|
8468
|
+
function aadFor(uuid) {
|
|
8469
|
+
const out = new Uint8Array(AAD_PREFIX.length + uuid.length);
|
|
8470
|
+
out.set(AAD_PREFIX, 0);
|
|
8471
|
+
out.set(uuid, AAD_PREFIX.length);
|
|
8472
|
+
return out;
|
|
8473
|
+
}
|
|
8474
|
+
function u32le(n) {
|
|
8475
|
+
const b = new Uint8Array(4);
|
|
8476
|
+
new DataView(b.buffer).setUint32(0, n, true);
|
|
8477
|
+
return b;
|
|
8478
|
+
}
|
|
8479
|
+
function readU32le(b, off) {
|
|
8480
|
+
return new DataView(b.buffer, b.byteOffset, b.byteLength).getUint32(off, true);
|
|
8481
|
+
}
|
|
8482
|
+
function concat2(...parts) {
|
|
8483
|
+
let total = 0;
|
|
8484
|
+
for (const p of parts)
|
|
8485
|
+
total += p.length;
|
|
8486
|
+
const out = new Uint8Array(total);
|
|
8487
|
+
let off = 0;
|
|
8488
|
+
for (const p of parts) {
|
|
8489
|
+
out.set(p, off);
|
|
8490
|
+
off += p.length;
|
|
8491
|
+
}
|
|
8492
|
+
return out;
|
|
8493
|
+
}
|
|
8494
|
+
function splitOptions(optionsIpc, secretNames) {
|
|
8495
|
+
if (!optionsIpc || optionsIpc.length === 0)
|
|
8496
|
+
return null;
|
|
8497
|
+
const batch = deserializeBatch(optionsIpc);
|
|
8498
|
+
if (batch.numRows === 0 || batch.schema.fields.length === 0)
|
|
8499
|
+
return null;
|
|
8500
|
+
const row = iterRows(batch).next().value ?? {};
|
|
8501
|
+
const plainFields = [];
|
|
8502
|
+
const secretFields = [];
|
|
8503
|
+
const plainCols = {};
|
|
8504
|
+
const secretCols = {};
|
|
8505
|
+
for (const f of batch.schema.fields) {
|
|
8506
|
+
const value = row[f.name];
|
|
8507
|
+
if (secretNames.has(f.name.toLowerCase()) && value !== null && value !== undefined) {
|
|
8508
|
+
secretFields.push(f);
|
|
8509
|
+
secretCols[f.name] = [value];
|
|
8510
|
+
} else {
|
|
8511
|
+
plainFields.push(f);
|
|
8512
|
+
plainCols[f.name] = [value ?? null];
|
|
8513
|
+
}
|
|
8514
|
+
}
|
|
8515
|
+
return {
|
|
8516
|
+
plain: plainFields.length ? serializeBatch(batchFromColumns(plainCols, schema2(plainFields))) : null,
|
|
8517
|
+
secret: secretFields.length ? serializeBatch(batchFromColumns(secretCols, schema2(secretFields))) : null
|
|
8518
|
+
};
|
|
8519
|
+
}
|
|
8520
|
+
async function packAttachOptionsTrailer(uuid, optionsIpc, secretNames, keys, fixedNonce) {
|
|
8521
|
+
const split = splitOptions(optionsIpc, secretNames);
|
|
8522
|
+
if (split === null)
|
|
8523
|
+
return new Uint8Array(0);
|
|
8524
|
+
const plain = split.plain ?? new Uint8Array(0);
|
|
8525
|
+
let secret = new Uint8Array(0);
|
|
8526
|
+
if (split.secret) {
|
|
8527
|
+
let root;
|
|
8528
|
+
try {
|
|
8529
|
+
root = await rootKey(keys);
|
|
8530
|
+
} catch (e) {
|
|
8531
|
+
if (e instanceof AttachSecretKeyUnavailableError)
|
|
8532
|
+
throw e;
|
|
8533
|
+
throw new AttachSecretKeyUnavailableError(`${noKeyMessage()} ${e.message}`);
|
|
8534
|
+
}
|
|
8535
|
+
const key = await deriveAttachSecretKey(root);
|
|
8536
|
+
const nonce = fixedNonce ?? crypto.getRandomValues(new Uint8Array(NONCE_LEN2));
|
|
8537
|
+
const ct = xchacha20poly1305(key, nonce, aadFor(uuid)).encrypt(split.secret);
|
|
8538
|
+
secret = concat2(Uint8Array.of(ATTACH_SECRET_OPTIONS_VERSION), nonce, ct);
|
|
8539
|
+
}
|
|
8540
|
+
const body = concat2(u32le(plain.length), plain, secret);
|
|
8541
|
+
return concat2(body, u32le(body.length), TRAILER_MAGIC);
|
|
8542
|
+
}
|
|
8543
|
+
function endsWithMagic(b) {
|
|
8544
|
+
if (b.length < TRAILER_MAGIC.length)
|
|
8545
|
+
return false;
|
|
8546
|
+
const off = b.length - TRAILER_MAGIC.length;
|
|
8547
|
+
for (let i = 0;i < TRAILER_MAGIC.length; i++)
|
|
8548
|
+
if (b[off + i] !== TRAILER_MAGIC[i])
|
|
8549
|
+
return false;
|
|
8550
|
+
return true;
|
|
8551
|
+
}
|
|
8552
|
+
function decodeOptions(ipc) {
|
|
8553
|
+
const batch = deserializeBatch(ipc);
|
|
8554
|
+
if (batch.numRows === 0)
|
|
8555
|
+
return {};
|
|
8556
|
+
return { ...iterRows(batch).next().value ?? {} };
|
|
8557
|
+
}
|
|
8558
|
+
var registry = new WeakMap;
|
|
8559
|
+
var EMPTY = Object.freeze({});
|
|
8560
|
+
async function openFrameworkAttach(full, keys) {
|
|
8561
|
+
if (full.length < UUID_LEN)
|
|
8562
|
+
return full;
|
|
8563
|
+
const copy = full.slice();
|
|
8564
|
+
let end = copy.length;
|
|
8565
|
+
let options = EMPTY;
|
|
8566
|
+
if (copy.length >= UUID_LEN + TRAILER_FIXED && endsWithMagic(copy)) {
|
|
8567
|
+
const bodyLen = readU32le(copy, copy.length - TRAILER_FIXED);
|
|
8568
|
+
const bodyStart = copy.length - TRAILER_FIXED - bodyLen;
|
|
8569
|
+
if (bodyLen < 4 || bodyStart < UUID_LEN)
|
|
8570
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8571
|
+
const body = copy.subarray(bodyStart, copy.length - TRAILER_FIXED);
|
|
8572
|
+
const plainLen = readU32le(body, 0);
|
|
8573
|
+
if (4 + plainLen > body.length)
|
|
8574
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8575
|
+
const plain = body.subarray(4, 4 + plainLen);
|
|
8576
|
+
const secret = body.subarray(4 + plainLen);
|
|
8577
|
+
const values = {};
|
|
8578
|
+
try {
|
|
8579
|
+
if (plain.length)
|
|
8580
|
+
Object.assign(values, decodeOptions(plain));
|
|
8581
|
+
} catch {
|
|
8582
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8583
|
+
}
|
|
8584
|
+
if (secret.length) {
|
|
8585
|
+
if (secret.length < 1 + NONCE_LEN2 + TAG_LEN2 || secret[0] !== ATTACH_SECRET_OPTIONS_VERSION) {
|
|
8586
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8587
|
+
}
|
|
8588
|
+
let opened;
|
|
8589
|
+
try {
|
|
8590
|
+
const key = await deriveAttachSecretKey(await rootKey(keys));
|
|
8591
|
+
const nonce = secret.subarray(1, 1 + NONCE_LEN2);
|
|
8592
|
+
opened = xchacha20poly1305(key, nonce, aadFor(copy.subarray(0, UUID_LEN))).decrypt(secret.subarray(1 + NONCE_LEN2));
|
|
8593
|
+
} catch {
|
|
8594
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8595
|
+
}
|
|
8596
|
+
try {
|
|
8597
|
+
Object.assign(values, decodeOptions(opened));
|
|
8598
|
+
} catch {
|
|
8599
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
8600
|
+
}
|
|
8601
|
+
}
|
|
8602
|
+
options = Object.freeze(values);
|
|
8603
|
+
end = bodyStart;
|
|
8604
|
+
}
|
|
8605
|
+
registry.set(copy.buffer, options);
|
|
8606
|
+
return copy.subarray(UUID_LEN, end);
|
|
8607
|
+
}
|
|
8608
|
+
async function secretAttachOptionNames(catalog, name, deserialize) {
|
|
8609
|
+
const names = new Set;
|
|
8610
|
+
if (typeof catalog.attachOptionSpecs === "function") {
|
|
8611
|
+
for (const spec of catalog.attachOptionSpecs(name) ?? [])
|
|
8612
|
+
if (spec.secret)
|
|
8613
|
+
names.add(spec.name.toLowerCase());
|
|
8614
|
+
}
|
|
8615
|
+
if (typeof catalog.catalogsInfo === "function") {
|
|
8616
|
+
let infos;
|
|
8617
|
+
try {
|
|
8618
|
+
infos = await catalog.catalogsInfo();
|
|
8619
|
+
} catch {
|
|
8620
|
+
infos = [];
|
|
8621
|
+
}
|
|
8622
|
+
for (const info of infos ?? []) {
|
|
8623
|
+
if (info.name !== name)
|
|
8624
|
+
continue;
|
|
8625
|
+
for (const raw of info.attach_option_specs ?? []) {
|
|
8626
|
+
try {
|
|
8627
|
+
const spec = deserialize(raw);
|
|
8628
|
+
if (spec.secret)
|
|
8629
|
+
names.add(spec.name.toLowerCase());
|
|
8630
|
+
} catch {}
|
|
8631
|
+
}
|
|
8632
|
+
}
|
|
8633
|
+
}
|
|
8634
|
+
return names;
|
|
8635
|
+
}
|
|
8636
|
+
|
|
8273
8637
|
// src/protocol/handlers/catalog/shared.ts
|
|
8274
|
-
async function sealAttach(plaintext, auth, signingKey) {
|
|
8638
|
+
async function sealAttach(plaintext, auth, signingKey, options) {
|
|
8275
8639
|
const uuid = new Uint8Array(ATTACH_UUID_LEN);
|
|
8276
8640
|
crypto.getRandomValues(uuid);
|
|
8277
|
-
const
|
|
8641
|
+
const trailer = options ? await packAttachOptionsTrailer(uuid, options.optionsIpc, options.secretNames, {
|
|
8642
|
+
explicit: options.attachSecretKey,
|
|
8643
|
+
signingKey
|
|
8644
|
+
}) : new Uint8Array(0);
|
|
8645
|
+
const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length + trailer.length);
|
|
8278
8646
|
minted.set(uuid, 0);
|
|
8279
8647
|
minted.set(plaintext, ATTACH_UUID_LEN);
|
|
8648
|
+
minted.set(trailer, ATTACH_UUID_LEN + plaintext.length);
|
|
8280
8649
|
if (!signingKey)
|
|
8281
8650
|
return minted;
|
|
8282
8651
|
return sealBytes(minted, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION);
|
|
@@ -8286,16 +8655,22 @@ async function openAttachFull(envelope, auth, signingKey) {
|
|
|
8286
8655
|
return envelope;
|
|
8287
8656
|
return openBytes(envelope, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data");
|
|
8288
8657
|
}
|
|
8289
|
-
async function openAttach(envelope, auth, signingKey) {
|
|
8658
|
+
async function openAttach(envelope, auth, signingKey, attachSecretKey) {
|
|
8290
8659
|
const full = await openAttachFull(envelope, auth, signingKey);
|
|
8291
|
-
return full
|
|
8660
|
+
return openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
|
|
8292
8661
|
}
|
|
8293
8662
|
async function sealTransaction(plaintext, attachEnvelope, auth, signingKey) {
|
|
8294
8663
|
if (!signingKey)
|
|
8295
8664
|
return plaintext;
|
|
8296
8665
|
return sealBytes(plaintext, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION);
|
|
8297
8666
|
}
|
|
8298
|
-
async function
|
|
8667
|
+
async function openTransaction(envelope, attachEnvelope, auth, signingKey) {
|
|
8668
|
+
if (!signingKey || envelope.length === 0)
|
|
8669
|
+
return envelope;
|
|
8670
|
+
return openBytes(envelope, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION, "transaction_opaque_data");
|
|
8671
|
+
}
|
|
8672
|
+
async function unwrapParamsOpaque(params, ctx, keys) {
|
|
8673
|
+
const { signingKey, attachSecretKey } = keys;
|
|
8299
8674
|
const auth = ctx?.auth;
|
|
8300
8675
|
let sealedAttach = new Uint8Array(0);
|
|
8301
8676
|
if (params.attach_opaque_data != null) {
|
|
@@ -8303,7 +8678,7 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
|
|
|
8303
8678
|
if (env.length > 0) {
|
|
8304
8679
|
sealedAttach = env;
|
|
8305
8680
|
const full = signingKey ? await openBytes(env, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data") : env;
|
|
8306
|
-
params.attach_opaque_data = full
|
|
8681
|
+
params.attach_opaque_data = await openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
|
|
8307
8682
|
}
|
|
8308
8683
|
}
|
|
8309
8684
|
if (signingKey && params.transaction_opaque_data != null) {
|
|
@@ -8313,14 +8688,15 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
|
|
|
8313
8688
|
}
|
|
8314
8689
|
}
|
|
8315
8690
|
}
|
|
8316
|
-
function catalogHandler(
|
|
8691
|
+
function catalogHandler(keysOrSigningKey, handler) {
|
|
8692
|
+
const keys = keysOrSigningKey instanceof Uint8Array || keysOrSigningKey === undefined ? { signingKey: keysOrSigningKey } : keysOrSigningKey;
|
|
8317
8693
|
return async (wire, ctx) => {
|
|
8318
8694
|
let params = wire;
|
|
8319
8695
|
if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
|
|
8320
8696
|
params = unwrapRequest(params.request);
|
|
8321
8697
|
}
|
|
8322
8698
|
normalizeRequestSchemaPaths(params);
|
|
8323
|
-
await unwrapParamsOpaque(params, ctx,
|
|
8699
|
+
await unwrapParamsOpaque(params, ctx, keys);
|
|
8324
8700
|
return handler(params, ctx);
|
|
8325
8701
|
};
|
|
8326
8702
|
}
|
|
@@ -8462,7 +8838,7 @@ var RESERVED_FLAGS_MASK = 254;
|
|
|
8462
8838
|
var FINGERPRINT_LEN = 16;
|
|
8463
8839
|
var HEADER_LEN = 4 + FINGERPRINT_LEN;
|
|
8464
8840
|
var SEAL_VERSION = 1;
|
|
8465
|
-
var
|
|
8841
|
+
var AAD_PREFIX2 = new TextEncoder().encode("vgi.split_token.v1\x00");
|
|
8466
8842
|
var SPLIT_TOKEN_INVALID = "SPLIT_TOKEN_INVALID";
|
|
8467
8843
|
var SPLIT_SNAPSHOT_EXPIRED = "SPLIT_SNAPSHOT_EXPIRED";
|
|
8468
8844
|
class SplitTokenError extends Error {
|
|
@@ -8473,7 +8849,7 @@ class SplitTokenError extends Error {
|
|
|
8473
8849
|
this.kind = kind;
|
|
8474
8850
|
}
|
|
8475
8851
|
}
|
|
8476
|
-
function
|
|
8852
|
+
function concat3(...parts) {
|
|
8477
8853
|
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
8478
8854
|
const out = new Uint8Array(total);
|
|
8479
8855
|
let at = 0;
|
|
@@ -8494,13 +8870,13 @@ function equalBytes2(a, b) {
|
|
|
8494
8870
|
async function bindFingerprint(schemaPath, functionName, args, settings, projection) {
|
|
8495
8871
|
const enc = new TextEncoder;
|
|
8496
8872
|
const zero = Uint8Array.of(0);
|
|
8497
|
-
const field = (label, value) =>
|
|
8498
|
-
const message =
|
|
8873
|
+
const field = (label, value) => concat3(enc.encode(label), zero, value, zero);
|
|
8874
|
+
const message = concat3(AAD_PREFIX2, field("schema_path", enc.encode(JSON.stringify(schemaPath))), field("function_name", enc.encode(functionName)), field("arguments", args), field("settings", settings), field("projection_ids", projection));
|
|
8499
8875
|
const digest = await crypto.subtle.digest("SHA-256", message);
|
|
8500
8876
|
return new Uint8Array(digest).slice(0, FINGERPRINT_LEN);
|
|
8501
8877
|
}
|
|
8502
8878
|
function splitTokenAad(header, auth) {
|
|
8503
|
-
return
|
|
8879
|
+
return concat3(header, identityTail(auth));
|
|
8504
8880
|
}
|
|
8505
8881
|
function splitAnchor(catalogVersion) {
|
|
8506
8882
|
const out = new Uint8Array(8);
|
|
@@ -8519,11 +8895,11 @@ async function buildSplitToken(opts) {
|
|
|
8519
8895
|
head[0] = SPLIT_TOKEN_FORMAT_VERSION;
|
|
8520
8896
|
head[1] = signingKey ? FLAG_PAYLOAD_SEALED : 0;
|
|
8521
8897
|
new DataView(head.buffer).setUint16(2, anchor.length, true);
|
|
8522
|
-
const body =
|
|
8898
|
+
const body = concat3(head, fingerprint, anchor);
|
|
8523
8899
|
if (!signingKey)
|
|
8524
|
-
return
|
|
8900
|
+
return concat3(body, payload);
|
|
8525
8901
|
const sealed = await sealBytes(payload, signingKey, splitTokenAad(body, auth), SEAL_VERSION);
|
|
8526
|
-
return
|
|
8902
|
+
return concat3(body, sealed);
|
|
8527
8903
|
}
|
|
8528
8904
|
async function openSplitToken(token, opts = {}) {
|
|
8529
8905
|
const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
|
|
@@ -8571,14 +8947,19 @@ async function openSplitToken(token, opts = {}) {
|
|
|
8571
8947
|
}
|
|
8572
8948
|
|
|
8573
8949
|
// src/protocol/handlers/function.ts
|
|
8574
|
-
async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
|
|
8950
|
+
async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey, attachSecretKey) {
|
|
8575
8951
|
if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
|
|
8576
8952
|
return;
|
|
8577
8953
|
const raw = toUint8Array(bindCall.attach_opaque_data);
|
|
8578
|
-
|
|
8954
|
+
let txn = bindCall.transaction_opaque_data ? toUint8Array(bindCall.transaction_opaque_data) : undefined;
|
|
8955
|
+
if (txn && txn.length > 0 && signingKey) {
|
|
8956
|
+
try {
|
|
8957
|
+
txn = await openTransaction(txn, raw, auth, signingKey);
|
|
8958
|
+
} catch {}
|
|
8959
|
+
}
|
|
8579
8960
|
const forms = [
|
|
8580
8961
|
async () => raw,
|
|
8581
|
-
async () => openAttach(raw, auth, signingKey)
|
|
8962
|
+
async () => openAttach(raw, auth, signingKey, attachSecretKey)
|
|
8582
8963
|
];
|
|
8583
8964
|
for (const form of forms) {
|
|
8584
8965
|
try {
|
|
@@ -8592,7 +8973,7 @@ async function resolveSplitPayloads(request, innerParams, opts) {
|
|
|
8592
8973
|
return;
|
|
8593
8974
|
const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
|
|
8594
8975
|
const expected = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
|
|
8595
|
-
const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey) : undefined;
|
|
8976
|
+
const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey, opts.attachSecretKey) : undefined;
|
|
8596
8977
|
request.split_payloads = [];
|
|
8597
8978
|
for (const token of request.split_tokens) {
|
|
8598
8979
|
request.split_payloads.push(await openSplitToken(token, {
|
|
@@ -8604,23 +8985,31 @@ async function resolveSplitPayloads(request, innerParams, opts) {
|
|
|
8604
8985
|
}
|
|
8605
8986
|
}
|
|
8606
8987
|
function functionHandlers(config) {
|
|
8607
|
-
const { registry, signingKey, catalogInterface } = config;
|
|
8988
|
+
const { registry, signingKey, catalogInterface, attachSecretKey } = config;
|
|
8608
8989
|
async function stripAttach(attach, ctx) {
|
|
8609
8990
|
if (attach == null)
|
|
8610
8991
|
return null;
|
|
8611
8992
|
const env = toUint8Array(attach);
|
|
8612
8993
|
if (env.length === 0)
|
|
8613
8994
|
return env;
|
|
8614
|
-
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
8995
|
+
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
|
|
8996
|
+
}
|
|
8997
|
+
async function openOpaque(bindCall, ctx) {
|
|
8998
|
+
const sealedAttach = bindCall.attach_opaque_data != null ? toUint8Array(bindCall.attach_opaque_data) : new Uint8Array(0);
|
|
8999
|
+
if (bindCall.transaction_opaque_data != null) {
|
|
9000
|
+
bindCall.transaction_opaque_data = await openTransaction(toUint8Array(bindCall.transaction_opaque_data), sealedAttach, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
9001
|
+
}
|
|
9002
|
+
bindCall.attach_opaque_data = await stripAttach(bindCall.attach_opaque_data, ctx);
|
|
8615
9003
|
}
|
|
8616
9004
|
async function strippedContext(bindCall, ctx) {
|
|
8617
|
-
|
|
9005
|
+
const copy = { ...bindCall };
|
|
8618
9006
|
try {
|
|
8619
|
-
|
|
9007
|
+
await openOpaque(copy, ctx);
|
|
8620
9008
|
} catch {
|
|
8621
|
-
|
|
9009
|
+
copy.attach_opaque_data = null;
|
|
9010
|
+
copy.transaction_opaque_data = null;
|
|
8622
9011
|
}
|
|
8623
|
-
return overloadContext(
|
|
9012
|
+
return overloadContext(copy, catalogInterface);
|
|
8624
9013
|
}
|
|
8625
9014
|
const emptySchema = schema2([]);
|
|
8626
9015
|
const dummyInputSchema = schema2([
|
|
@@ -8629,7 +9018,7 @@ function functionHandlers(config) {
|
|
|
8629
9018
|
const bind = async (params, ctx) => {
|
|
8630
9019
|
const innerParams = unwrapRequest(params.request);
|
|
8631
9020
|
const request = deserializeBindRequest(innerParams);
|
|
8632
|
-
|
|
9021
|
+
await openOpaque(request, ctx);
|
|
8633
9022
|
const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
|
|
8634
9023
|
const response = await func.bind(request);
|
|
8635
9024
|
validateProjectionOffer(response);
|
|
@@ -8644,10 +9033,11 @@ function functionHandlers(config) {
|
|
|
8644
9033
|
const innerParams = unwrapRequest(params.request);
|
|
8645
9034
|
const request = deserializeInitRequest(innerParams);
|
|
8646
9035
|
const auth = ctx?.auth ?? currentRequestAuth();
|
|
8647
|
-
|
|
9036
|
+
await openOpaque(request.bind_call, ctx);
|
|
8648
9037
|
await resolveSplitPayloads(request, innerParams, {
|
|
8649
9038
|
auth,
|
|
8650
9039
|
signingKey,
|
|
9040
|
+
attachSecretKey,
|
|
8651
9041
|
catalogInterface,
|
|
8652
9042
|
checkAnchor: true
|
|
8653
9043
|
});
|
|
@@ -8689,10 +9079,11 @@ function functionHandlers(config) {
|
|
|
8689
9079
|
} else {
|
|
8690
9080
|
const carried = parseCarriedInitRequest(state.initRequestPacked);
|
|
8691
9081
|
const request = carried.request;
|
|
8692
|
-
|
|
9082
|
+
await openOpaque(request.bind_call, undefined);
|
|
8693
9083
|
await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
|
|
8694
9084
|
auth: currentRequestAuth(),
|
|
8695
9085
|
signingKey,
|
|
9086
|
+
attachSecretKey,
|
|
8696
9087
|
catalogInterface,
|
|
8697
9088
|
checkAnchor: false
|
|
8698
9089
|
});
|
|
@@ -8764,7 +9155,7 @@ function functionHandlers(config) {
|
|
|
8764
9155
|
const plan = func.plan ? await func.plan(request) : { splits: [{ payload: new Uint8Array(0) }] };
|
|
8765
9156
|
const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
|
|
8766
9157
|
const fingerprint = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
|
|
8767
|
-
const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey) ?? splitAnchor(0);
|
|
9158
|
+
const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey, attachSecretKey) ?? splitAnchor(0);
|
|
8768
9159
|
const blobs = [];
|
|
8769
9160
|
for (const split of plan.splits) {
|
|
8770
9161
|
const token = await buildSplitToken({
|
|
@@ -9290,7 +9681,7 @@ function splitLenPrefixed(buf, count) {
|
|
|
9290
9681
|
}
|
|
9291
9682
|
|
|
9292
9683
|
// src/protocol/handlers/table-buffering.ts
|
|
9293
|
-
function tableBufferingHandlers(registry, signingKey) {
|
|
9684
|
+
function tableBufferingHandlers(registry, signingKey, attachSecretKey) {
|
|
9294
9685
|
function resolveBuffering(name, schemaPath) {
|
|
9295
9686
|
const func = registry.get(name, {
|
|
9296
9687
|
arguments: new Arguments,
|
|
@@ -9307,7 +9698,7 @@ function tableBufferingHandlers(registry, signingKey) {
|
|
|
9307
9698
|
const functionName = inner.function_name;
|
|
9308
9699
|
const executionId = toUint8Array(inner.execution_id);
|
|
9309
9700
|
const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
|
|
9310
|
-
const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey) : rawAttach;
|
|
9701
|
+
const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey) : rawAttach;
|
|
9311
9702
|
const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
|
|
9312
9703
|
const func = resolveBuffering(functionName, inner.schema_path ?? null);
|
|
9313
9704
|
const bound = new BoundStorage(storage, executionId);
|
|
@@ -10577,9 +10968,9 @@ var TICKET_ENVELOPE_VERSION = 1;
|
|
|
10577
10968
|
var MAX_OPTIONS_BYTES = 16 * 1024;
|
|
10578
10969
|
var MAX_TICKET_CHARS = 32 * 1024;
|
|
10579
10970
|
var CLOCK_SKEW_SECONDS = 60;
|
|
10580
|
-
var
|
|
10971
|
+
var UTF83 = new TextEncoder;
|
|
10581
10972
|
var STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
10582
|
-
var TICKET_AAD_DOMAIN =
|
|
10973
|
+
var TICKET_AAD_DOMAIN = UTF83.encode("vgi.attach_ticket.v1\x00");
|
|
10583
10974
|
var TICKET_ID = /^[0-9a-f]{32}$/;
|
|
10584
10975
|
var B64URL = /^[A-Za-z0-9_-]+$/;
|
|
10585
10976
|
var MAX_TEXT = 65535;
|
|
@@ -10633,14 +11024,14 @@ class SealAttachDeniedError extends Error {
|
|
|
10633
11024
|
}
|
|
10634
11025
|
}
|
|
10635
11026
|
function attachTicketAad(principal) {
|
|
10636
|
-
const p =
|
|
11027
|
+
const p = UTF83.encode(principal);
|
|
10637
11028
|
const out = new Uint8Array(TICKET_AAD_DOMAIN.length + p.length);
|
|
10638
11029
|
out.set(TICKET_AAD_DOMAIN, 0);
|
|
10639
11030
|
out.set(p, TICKET_AAD_DOMAIN.length);
|
|
10640
11031
|
return out;
|
|
10641
11032
|
}
|
|
10642
11033
|
function packText(value, name) {
|
|
10643
|
-
const raw =
|
|
11034
|
+
const raw = UTF83.encode(value);
|
|
10644
11035
|
if (raw.length > MAX_TEXT)
|
|
10645
11036
|
throw new Error(`${name} is longer than 65535 bytes`);
|
|
10646
11037
|
const out = new Uint8Array(2 + raw.length);
|
|
@@ -10964,8 +11355,9 @@ function buildAttachTicketsProtocol(config) {
|
|
|
10964
11355
|
}
|
|
10965
11356
|
|
|
10966
11357
|
// src/protocol/handlers/catalog/admin.ts
|
|
10967
|
-
function catalogAdminHandlers(getCatalog, signingKey) {
|
|
10968
|
-
const
|
|
11358
|
+
function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
11359
|
+
const keys = { signingKey, attachSecretKey };
|
|
11360
|
+
const catalogCatalogs = catalogHandler(keys, async () => {
|
|
10969
11361
|
const cat = getCatalog();
|
|
10970
11362
|
const infos = cat.catalogsInfo ? await cat.catalogsInfo() : cat.catalogs().map((name) => ({
|
|
10971
11363
|
name,
|
|
@@ -10996,29 +11388,31 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
10996
11388
|
result.catalog_capabilities = encodeCatalogCapabilities(catalogCapabilities(advertised));
|
|
10997
11389
|
result.selected_capabilities = encodeCatalogCapabilities(selectCatalogCapabilities(advertised, clientCapabilities, result.supports_transactions ?? false));
|
|
10998
11390
|
}
|
|
10999
|
-
const
|
|
11391
|
+
const optionsIpc = innerParams.options == null ? null : toUint8Array(innerParams.options);
|
|
11392
|
+
const secretNames = optionsIpc && optionsIpc.length > 0 ? await secretAttachOptionNames(cat, innerParams.name, deserializeAttachOptionSpec) : new Set;
|
|
11393
|
+
const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey, { optionsIpc, secretNames, attachSecretKey });
|
|
11000
11394
|
return wrapResult(buildCatalogAttachResult({
|
|
11001
11395
|
...result,
|
|
11002
11396
|
attach_opaque_data: sealedAttach,
|
|
11003
11397
|
supports_column_statistics: result.supports_column_statistics ?? true
|
|
11004
11398
|
}), CatalogAttachResultSchema);
|
|
11005
11399
|
};
|
|
11006
|
-
const catalogDetach = catalogHandler(
|
|
11400
|
+
const catalogDetach = catalogHandler(keys, async (params) => {
|
|
11007
11401
|
const cat = getCatalog();
|
|
11008
11402
|
await cat.detach(toUint8Array(params.attach_opaque_data));
|
|
11009
11403
|
return {};
|
|
11010
11404
|
});
|
|
11011
|
-
const catalogCreate = catalogHandler(
|
|
11405
|
+
const catalogCreate = catalogHandler(keys, async (params) => {
|
|
11012
11406
|
const cat = getCatalog();
|
|
11013
11407
|
await cat.create(params.name, params.on_conflict, params.options);
|
|
11014
11408
|
return {};
|
|
11015
11409
|
});
|
|
11016
|
-
const catalogDrop = catalogHandler(
|
|
11410
|
+
const catalogDrop = catalogHandler(keys, async (params) => {
|
|
11017
11411
|
const cat = getCatalog();
|
|
11018
11412
|
await cat.drop(params.name);
|
|
11019
11413
|
return {};
|
|
11020
11414
|
});
|
|
11021
|
-
const catalogVersion = catalogHandler(
|
|
11415
|
+
const catalogVersion = catalogHandler(keys, async (params) => {
|
|
11022
11416
|
const cat = getCatalog();
|
|
11023
11417
|
const version = await cat.version(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11024
11418
|
return wrapResult({ version }, CatalogVersionResultSchema);
|
|
@@ -11026,23 +11420,23 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
11026
11420
|
const catalogTransactionBegin = async (params, ctx) => {
|
|
11027
11421
|
const auth = ctx?.auth;
|
|
11028
11422
|
const sealedAttach = params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
|
|
11029
|
-
const attachPlain = await openAttach(sealedAttach, auth, signingKey);
|
|
11423
|
+
const attachPlain = await openAttach(sealedAttach, auth, signingKey, attachSecretKey);
|
|
11030
11424
|
const cat = getCatalog();
|
|
11031
11425
|
const txPlain = await cat.transactionBegin(attachPlain);
|
|
11032
11426
|
const transaction_opaque_data = txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
|
|
11033
11427
|
return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
|
|
11034
11428
|
};
|
|
11035
|
-
const catalogTransactionCommit = catalogHandler(
|
|
11429
|
+
const catalogTransactionCommit = catalogHandler(keys, async (params) => {
|
|
11036
11430
|
const cat = getCatalog();
|
|
11037
11431
|
await cat.transactionCommit(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
|
|
11038
11432
|
return {};
|
|
11039
11433
|
});
|
|
11040
|
-
const catalogTransactionRollback = catalogHandler(
|
|
11434
|
+
const catalogTransactionRollback = catalogHandler(keys, async (params) => {
|
|
11041
11435
|
const cat = getCatalog();
|
|
11042
11436
|
await cat.transactionRollback(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
|
|
11043
11437
|
return {};
|
|
11044
11438
|
});
|
|
11045
|
-
const catalogSchemas = catalogHandler(
|
|
11439
|
+
const catalogSchemas = catalogHandler(keys, async (params) => {
|
|
11046
11440
|
const cat = getCatalog();
|
|
11047
11441
|
const schemas = await cat.schemas(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11048
11442
|
return wrapResult({
|
|
@@ -11051,52 +11445,52 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
11051
11445
|
});
|
|
11052
11446
|
const catalogContents = async (params, ctx) => {
|
|
11053
11447
|
const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
|
|
11054
|
-
return catalogHandler(
|
|
11448
|
+
return catalogHandler(keys, async (opened, context) => {
|
|
11055
11449
|
const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
|
|
11056
11450
|
return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
|
|
11057
11451
|
})(params, ctx);
|
|
11058
11452
|
};
|
|
11059
|
-
const catalogCopyFromFormats = catalogHandler(
|
|
11453
|
+
const catalogCopyFromFormats = catalogHandler(keys, async (params) => {
|
|
11060
11454
|
const cat = getCatalog();
|
|
11061
11455
|
const formats = await cat.copyFromFormats(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11062
11456
|
return wrapResult({
|
|
11063
11457
|
items: formats.map((f) => encodeCopyFromFormatInfo(f))
|
|
11064
11458
|
}, CatalogCopyFromFormatsResultSchema);
|
|
11065
11459
|
});
|
|
11066
|
-
const catalogSchemaGet = catalogHandler(
|
|
11460
|
+
const catalogSchemaGet = catalogHandler(keys, async (params) => {
|
|
11067
11461
|
const cat = getCatalog();
|
|
11068
11462
|
const info = await cat.schemaGet(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11069
11463
|
return wrapResult({
|
|
11070
11464
|
items: info ? [encodeSchemaInfo(info)] : []
|
|
11071
11465
|
}, CatalogSchemaGetResultSchema);
|
|
11072
11466
|
});
|
|
11073
|
-
const catalogSchemaCreate = catalogHandler(
|
|
11467
|
+
const catalogSchemaCreate = catalogHandler(keys, async (params) => {
|
|
11074
11468
|
if (params.options != null)
|
|
11075
11469
|
throw new MethodNotImplementedError2("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
|
|
11076
11470
|
const cat = getCatalog();
|
|
11077
11471
|
await cat.schemaCreate(toUint8Array(params.attach_opaque_data), Array.from(params.path), params.comment, catalogStringMap(params.tags), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined, decodeDictValue(params.on_conflict));
|
|
11078
11472
|
return {};
|
|
11079
11473
|
});
|
|
11080
|
-
const catalogSchemaDrop = catalogHandler(
|
|
11474
|
+
const catalogSchemaDrop = catalogHandler(keys, async (params) => {
|
|
11081
11475
|
const cat = getCatalog();
|
|
11082
11476
|
await cat.schemaDrop(toUint8Array(params.attach_opaque_data), params.path, params.ignore_not_found, params.cascade, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11083
11477
|
return {};
|
|
11084
11478
|
});
|
|
11085
|
-
const catalogSchemaContentsTables = catalogHandler(
|
|
11479
|
+
const catalogSchemaContentsTables = catalogHandler(keys, async (params) => {
|
|
11086
11480
|
const cat = getCatalog();
|
|
11087
11481
|
const tables = await cat.schemaContentsTables(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11088
11482
|
return wrapResult({
|
|
11089
11483
|
items: tables.map((t) => encodeValidatedTableInfo(t))
|
|
11090
11484
|
}, CatalogSchemaContentsTablesResultSchema);
|
|
11091
11485
|
});
|
|
11092
|
-
const catalogSchemaContentsViews = catalogHandler(
|
|
11486
|
+
const catalogSchemaContentsViews = catalogHandler(keys, async (params) => {
|
|
11093
11487
|
const cat = getCatalog();
|
|
11094
11488
|
const views = await cat.schemaContentsViews(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11095
11489
|
return wrapResult({
|
|
11096
11490
|
items: views.map((v) => encodeViewInfo(v))
|
|
11097
11491
|
}, CatalogSchemaContentsViewsResultSchema);
|
|
11098
11492
|
});
|
|
11099
|
-
const catalogSchemaContentsFunctions = catalogHandler(
|
|
11493
|
+
const catalogSchemaContentsFunctions = catalogHandler(keys, async (params) => {
|
|
11100
11494
|
const cat = getCatalog();
|
|
11101
11495
|
const funcs = await cat.schemaContentsFunctions(toUint8Array(params.attach_opaque_data), params.path, decodeDictValue(params.type), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11102
11496
|
return wrapResult({
|
|
@@ -11173,15 +11567,16 @@ function requireFlatColumnPath(value, operation) {
|
|
|
11173
11567
|
}
|
|
11174
11568
|
return path;
|
|
11175
11569
|
}
|
|
11176
|
-
function catalogTableHandlers(getCatalog, signingKey) {
|
|
11177
|
-
const
|
|
11570
|
+
function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
11571
|
+
const keys = { signingKey, attachSecretKey };
|
|
11572
|
+
const catalogTableGet = catalogHandler(keys, async (params) => {
|
|
11178
11573
|
const cat = getCatalog();
|
|
11179
11574
|
const info = await cat.tableGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11180
11575
|
return wrapResult({
|
|
11181
11576
|
items: info ? [encodeValidatedTableInfo(info)] : []
|
|
11182
11577
|
}, CatalogTableGetResultSchema);
|
|
11183
11578
|
});
|
|
11184
|
-
const catalogTableCreate = catalogHandler(
|
|
11579
|
+
const catalogTableCreate = catalogHandler(keys, async (params) => {
|
|
11185
11580
|
if (params.constraint_definitions == null)
|
|
11186
11581
|
throw new Error("constraint_definitions is required");
|
|
11187
11582
|
const definitions = Array.from(params.constraint_definitions, (d) => toUint8Array(d));
|
|
@@ -11202,7 +11597,7 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11202
11597
|
await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11203
11598
|
return {};
|
|
11204
11599
|
});
|
|
11205
|
-
const catalogTableConstraintsApply = catalogHandler(
|
|
11600
|
+
const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
|
|
11206
11601
|
const attach = toUint8Array(params.attach_opaque_data);
|
|
11207
11602
|
const cat = getCatalog();
|
|
11208
11603
|
const caps = await cat.catalogCapabilities(attach);
|
|
@@ -11235,37 +11630,50 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11235
11630
|
}
|
|
11236
11631
|
return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) }, CatalogTableConstraintsApplyResultSchema);
|
|
11237
11632
|
});
|
|
11238
|
-
const catalogTableDrop = catalogHandler(
|
|
11633
|
+
const catalogTableDrop = catalogHandler(keys, async (params) => {
|
|
11239
11634
|
const cat = getCatalog();
|
|
11240
11635
|
await cat.tableDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11241
11636
|
return {};
|
|
11242
11637
|
});
|
|
11243
|
-
const catalogTableColumnStatisticsGet = catalogHandler(
|
|
11638
|
+
const catalogTableColumnStatisticsGet = catalogHandler(keys, async (params) => {
|
|
11244
11639
|
const cat = getCatalog();
|
|
11245
11640
|
const stats = await cat.tableColumnStatisticsGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11246
11641
|
return { result: stats?.bytes ?? null };
|
|
11247
11642
|
});
|
|
11248
|
-
const catalogTableScanFunctionGet = catalogHandler(
|
|
11643
|
+
const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
|
|
11249
11644
|
const cat = getCatalog();
|
|
11250
11645
|
const scanResult = await cat.tableScanFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11251
11646
|
return wrapResult(scanResult, ScanFunctionResultSchema);
|
|
11252
11647
|
});
|
|
11253
|
-
const
|
|
11648
|
+
const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
|
|
11649
|
+
const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
|
|
11650
|
+
const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
|
|
11651
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11652
|
+
});
|
|
11653
|
+
const catalogTableUpdateFunctionGet = catalogHandler(keys, async (params) => {
|
|
11654
|
+
const result = await getCatalog().tableUpdateFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
11655
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11656
|
+
});
|
|
11657
|
+
const catalogTableDeleteFunctionGet = catalogHandler(keys, async (params) => {
|
|
11658
|
+
const result = await getCatalog().tableDeleteFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
11659
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11660
|
+
});
|
|
11661
|
+
const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
|
|
11254
11662
|
const cat = getCatalog();
|
|
11255
11663
|
const branchesResult = await cat.tableScanBranchesGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11256
11664
|
return wrapResult(branchesResult, ScanBranchesResultSchema);
|
|
11257
11665
|
});
|
|
11258
|
-
const catalogTableCommentSet = catalogHandler(
|
|
11666
|
+
const catalogTableCommentSet = catalogHandler(keys, async (params) => {
|
|
11259
11667
|
const cat = getCatalog();
|
|
11260
11668
|
await cat.tableCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11261
11669
|
return {};
|
|
11262
11670
|
});
|
|
11263
|
-
const catalogTableRename = catalogHandler(
|
|
11671
|
+
const catalogTableRename = catalogHandler(keys, async (params) => {
|
|
11264
11672
|
const cat = getCatalog();
|
|
11265
11673
|
await cat.tableRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.new_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11266
11674
|
return {};
|
|
11267
11675
|
});
|
|
11268
|
-
const catalogTableColumnAdd = catalogHandler(
|
|
11676
|
+
const catalogTableColumnAdd = catalogHandler(keys, async (params) => {
|
|
11269
11677
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
|
|
11270
11678
|
validateColumnMetadataIpc(toUint8Array(params.column_definition));
|
|
11271
11679
|
validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
|
|
@@ -11273,49 +11681,49 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11273
11681
|
await cat.tableColumnAdd(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.column_definition), params.ignore_not_found, params.if_column_not_exists, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11274
11682
|
return {};
|
|
11275
11683
|
});
|
|
11276
|
-
const catalogTableColumnDrop = catalogHandler(
|
|
11684
|
+
const catalogTableColumnDrop = catalogHandler(keys, async (params) => {
|
|
11277
11685
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
|
|
11278
11686
|
const cat = getCatalog();
|
|
11279
11687
|
await cat.tableColumnDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.if_column_exists, params.cascade, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11280
11688
|
return {};
|
|
11281
11689
|
});
|
|
11282
|
-
const catalogTableColumnRename = catalogHandler(
|
|
11690
|
+
const catalogTableColumnRename = catalogHandler(keys, async (params) => {
|
|
11283
11691
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
|
|
11284
11692
|
const cat = getCatalog();
|
|
11285
11693
|
await cat.tableColumnRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.new_column_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11286
11694
|
return {};
|
|
11287
11695
|
});
|
|
11288
|
-
const catalogTableColumnCommentSet = catalogHandler(
|
|
11696
|
+
const catalogTableColumnCommentSet = catalogHandler(keys, async (params) => {
|
|
11289
11697
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
|
|
11290
11698
|
const cat = getCatalog();
|
|
11291
11699
|
await cat.tableColumnCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11292
11700
|
return {};
|
|
11293
11701
|
});
|
|
11294
|
-
const catalogTableColumnDefaultSet = catalogHandler(
|
|
11702
|
+
const catalogTableColumnDefaultSet = catalogHandler(keys, async (params) => {
|
|
11295
11703
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
|
|
11296
11704
|
const cat = getCatalog();
|
|
11297
11705
|
await cat.tableColumnDefaultSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.expression), params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11298
11706
|
return {};
|
|
11299
11707
|
});
|
|
11300
|
-
const catalogTableColumnDefaultDrop = catalogHandler(
|
|
11708
|
+
const catalogTableColumnDefaultDrop = catalogHandler(keys, async (params) => {
|
|
11301
11709
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
|
|
11302
11710
|
const cat = getCatalog();
|
|
11303
11711
|
await cat.tableColumnDefaultDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11304
11712
|
return {};
|
|
11305
11713
|
});
|
|
11306
|
-
const catalogTableColumnTypeChange = catalogHandler(
|
|
11714
|
+
const catalogTableColumnTypeChange = catalogHandler(keys, async (params) => {
|
|
11307
11715
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
|
|
11308
11716
|
const cat = getCatalog();
|
|
11309
11717
|
await cat.tableColumnTypeChange(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.column_definition), params.expression == null ? null : toUint8Array(params.expression), params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11310
11718
|
return {};
|
|
11311
11719
|
});
|
|
11312
|
-
const catalogTableNotNullSet = catalogHandler(
|
|
11720
|
+
const catalogTableNotNullSet = catalogHandler(keys, async (params) => {
|
|
11313
11721
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
|
|
11314
11722
|
const cat = getCatalog();
|
|
11315
11723
|
await cat.tableNotNullSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11316
11724
|
return {};
|
|
11317
11725
|
});
|
|
11318
|
-
const catalogTableNotNullDrop = catalogHandler(
|
|
11726
|
+
const catalogTableNotNullDrop = catalogHandler(keys, async (params) => {
|
|
11319
11727
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
|
|
11320
11728
|
const cat = getCatalog();
|
|
11321
11729
|
await cat.tableNotNullDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
@@ -11328,6 +11736,9 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11328
11736
|
catalogTableDrop,
|
|
11329
11737
|
catalogTableColumnStatisticsGet,
|
|
11330
11738
|
catalogTableScanFunctionGet,
|
|
11739
|
+
catalogTableInsertFunctionGet,
|
|
11740
|
+
catalogTableUpdateFunctionGet,
|
|
11741
|
+
catalogTableDeleteFunctionGet,
|
|
11331
11742
|
catalogTableScanBranchesGet,
|
|
11332
11743
|
catalogTableCommentSet,
|
|
11333
11744
|
catalogTableRename,
|
|
@@ -11344,15 +11755,16 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11344
11755
|
}
|
|
11345
11756
|
|
|
11346
11757
|
// src/protocol/handlers/catalog/view.ts
|
|
11347
|
-
function catalogViewHandlers(getCatalog, signingKey) {
|
|
11348
|
-
const
|
|
11758
|
+
function catalogViewHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
11759
|
+
const keys = { signingKey, attachSecretKey };
|
|
11760
|
+
const catalogViewGet = catalogHandler(keys, async (params) => {
|
|
11349
11761
|
const cat = getCatalog();
|
|
11350
11762
|
const info = await cat.viewGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11351
11763
|
return wrapResult({
|
|
11352
11764
|
items: info ? [encodeViewInfo(info)] : []
|
|
11353
11765
|
}, CatalogViewGetResultSchema);
|
|
11354
11766
|
});
|
|
11355
|
-
const catalogViewCreate = catalogHandler(
|
|
11767
|
+
const catalogViewCreate = catalogHandler(keys, async (params) => {
|
|
11356
11768
|
if (params.security !== "regular")
|
|
11357
11769
|
throw new Error(`view security mode ${params.security} is unsupported`);
|
|
11358
11770
|
const tags = catalogStringMap(params.tags);
|
|
@@ -11363,22 +11775,22 @@ function catalogViewHandlers(getCatalog, signingKey) {
|
|
|
11363
11775
|
await cat.viewCreate(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.definition, decodeDictValue(params.on_conflict), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined, params.aliases ?? [], params.comment, tags, columnComments);
|
|
11364
11776
|
return {};
|
|
11365
11777
|
});
|
|
11366
|
-
const catalogViewDrop = catalogHandler(
|
|
11778
|
+
const catalogViewDrop = catalogHandler(keys, async (params) => {
|
|
11367
11779
|
const cat = getCatalog();
|
|
11368
11780
|
await cat.viewDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11369
11781
|
return {};
|
|
11370
11782
|
});
|
|
11371
|
-
const catalogViewRename = catalogHandler(
|
|
11783
|
+
const catalogViewRename = catalogHandler(keys, async (params) => {
|
|
11372
11784
|
const cat = getCatalog();
|
|
11373
11785
|
await cat.viewRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.new_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11374
11786
|
return {};
|
|
11375
11787
|
});
|
|
11376
|
-
const catalogViewCommentSet = catalogHandler(
|
|
11788
|
+
const catalogViewCommentSet = catalogHandler(keys, async (params) => {
|
|
11377
11789
|
const cat = getCatalog();
|
|
11378
11790
|
await cat.viewCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11379
11791
|
return {};
|
|
11380
11792
|
});
|
|
11381
|
-
const catalogViewColumnCommentSet = catalogHandler(
|
|
11793
|
+
const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
|
|
11382
11794
|
const path = Array.from(params.column_path);
|
|
11383
11795
|
if (path.length !== 1 || !path[0] || path[0].includes("\x00"))
|
|
11384
11796
|
throw new Error("view column comments require one raw output identifier");
|
|
@@ -11389,15 +11801,16 @@ function catalogViewHandlers(getCatalog, signingKey) {
|
|
|
11389
11801
|
}
|
|
11390
11802
|
|
|
11391
11803
|
// src/protocol/handlers/catalog/macro.ts
|
|
11392
|
-
function catalogMacroHandlers(getCatalog, signingKey) {
|
|
11393
|
-
const
|
|
11804
|
+
function catalogMacroHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
11805
|
+
const keys = { signingKey, attachSecretKey };
|
|
11806
|
+
const catalogMacroGet = catalogHandler(keys, async (params) => {
|
|
11394
11807
|
const cat = getCatalog();
|
|
11395
11808
|
const info = await cat.macroGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11396
11809
|
return wrapResult({
|
|
11397
11810
|
items: info ? [encodeMacroInfo(info)] : []
|
|
11398
11811
|
}, CatalogMacroGetResultSchema);
|
|
11399
11812
|
});
|
|
11400
|
-
const catalogMacroCreate = catalogHandler(
|
|
11813
|
+
const catalogMacroCreate = catalogHandler(keys, async (params) => {
|
|
11401
11814
|
const cat = getCatalog();
|
|
11402
11815
|
const innerParams = decodeASD(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
|
|
11403
11816
|
if (!innerParams.overloads?.length)
|
|
@@ -11405,12 +11818,12 @@ function catalogMacroHandlers(getCatalog, signingKey) {
|
|
|
11405
11818
|
await cat.macroCreate(toUint8Array(innerParams.attach_opaque_data), innerParams.schema_path, innerParams.name, innerParams.macro_type, innerParams.overloads, innerParams.on_conflict, innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined);
|
|
11406
11819
|
return {};
|
|
11407
11820
|
});
|
|
11408
|
-
const catalogMacroDrop = catalogHandler(
|
|
11821
|
+
const catalogMacroDrop = catalogHandler(keys, async (params) => {
|
|
11409
11822
|
const cat = getCatalog();
|
|
11410
11823
|
await cat.macroDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11411
11824
|
return {};
|
|
11412
11825
|
});
|
|
11413
|
-
const catalogSchemaContentsMacros = catalogHandler(
|
|
11826
|
+
const catalogSchemaContentsMacros = catalogHandler(keys, async (params) => {
|
|
11414
11827
|
const cat = getCatalog();
|
|
11415
11828
|
const macros = await cat.schemaContentsMacros(toUint8Array(params.attach_opaque_data), params.path, decodeDictValue(params.type), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11416
11829
|
return wrapResult({
|
|
@@ -11421,15 +11834,16 @@ function catalogMacroHandlers(getCatalog, signingKey) {
|
|
|
11421
11834
|
}
|
|
11422
11835
|
|
|
11423
11836
|
// src/protocol/handlers/catalog/index_methods.ts
|
|
11424
|
-
function catalogIndexHandlers(getCatalog, signingKey) {
|
|
11425
|
-
const
|
|
11837
|
+
function catalogIndexHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
11838
|
+
const keys = { signingKey, attachSecretKey };
|
|
11839
|
+
const catalogSchemaContentsIndexes = catalogHandler(keys, async (params) => {
|
|
11426
11840
|
const cat = getCatalog();
|
|
11427
11841
|
const indexes = await cat.schemaContentsIndexes(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11428
11842
|
return wrapResult({
|
|
11429
11843
|
items: indexes.map((i) => encodeIndexInfo(i))
|
|
11430
11844
|
}, CatalogSchemaContentsIndexesResultSchema);
|
|
11431
11845
|
});
|
|
11432
|
-
const catalogIndexGet = catalogHandler(
|
|
11846
|
+
const catalogIndexGet = catalogHandler(keys, async (params) => {
|
|
11433
11847
|
const cat = getCatalog();
|
|
11434
11848
|
const info = await cat.indexGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11435
11849
|
return wrapResult({
|
|
@@ -11440,14 +11854,14 @@ function catalogIndexHandlers(getCatalog, signingKey) {
|
|
|
11440
11854
|
}
|
|
11441
11855
|
|
|
11442
11856
|
// src/protocol/handlers/catalog/index.ts
|
|
11443
|
-
function catalogHandlers(catalog, signingKey) {
|
|
11857
|
+
function catalogHandlers(catalog, signingKey, attachSecretKey) {
|
|
11444
11858
|
const getCatalog = makeGetCatalog(catalog);
|
|
11445
11859
|
return {
|
|
11446
|
-
...catalogAdminHandlers(getCatalog, signingKey),
|
|
11447
|
-
...catalogTableHandlers(getCatalog, signingKey),
|
|
11448
|
-
...catalogViewHandlers(getCatalog, signingKey),
|
|
11449
|
-
...catalogMacroHandlers(getCatalog, signingKey),
|
|
11450
|
-
...catalogIndexHandlers(getCatalog, signingKey)
|
|
11860
|
+
...catalogAdminHandlers(getCatalog, signingKey, attachSecretKey),
|
|
11861
|
+
...catalogTableHandlers(getCatalog, signingKey, attachSecretKey),
|
|
11862
|
+
...catalogViewHandlers(getCatalog, signingKey, attachSecretKey),
|
|
11863
|
+
...catalogMacroHandlers(getCatalog, signingKey, attachSecretKey),
|
|
11864
|
+
...catalogIndexHandlers(getCatalog, signingKey, attachSecretKey)
|
|
11451
11865
|
};
|
|
11452
11866
|
}
|
|
11453
11867
|
|
|
@@ -11458,11 +11872,12 @@ function buildVgiService(config) {
|
|
|
11458
11872
|
...functionHandlers({
|
|
11459
11873
|
registry: config.registry,
|
|
11460
11874
|
signingKey: config.signingKey,
|
|
11875
|
+
attachSecretKey: config.attachSecretKey,
|
|
11461
11876
|
catalogInterface: config.catalogInterface
|
|
11462
11877
|
}),
|
|
11463
11878
|
...aggregateHandlers(config.registry),
|
|
11464
|
-
...tableBufferingHandlers(config.registry, config.signingKey),
|
|
11465
|
-
...catalogHandlers(config.catalogInterface, config.signingKey)
|
|
11879
|
+
...tableBufferingHandlers(config.registry, config.signingKey, config.attachSecretKey),
|
|
11880
|
+
...catalogHandlers(config.catalogInterface, config.signingKey, config.attachSecretKey)
|
|
11466
11881
|
};
|
|
11467
11882
|
}
|
|
11468
11883
|
function buildVgiProtocol(config) {
|
|
@@ -11843,7 +12258,7 @@ function createVgiWorkerFetch(opts) {
|
|
|
11843
12258
|
}
|
|
11844
12259
|
const trustedProxyAddresses = bridge?.trustedProxyAddresses ?? ["127.0.0.1"];
|
|
11845
12260
|
return createVgiFetch({
|
|
11846
|
-
protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface },
|
|
12261
|
+
protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface, attachSecretKey: opts.attachSecretKey },
|
|
11847
12262
|
signingKey,
|
|
11848
12263
|
signingKeyConfigured,
|
|
11849
12264
|
tokenTtl,
|
|
@@ -11909,4 +12324,4 @@ export {
|
|
|
11909
12324
|
serveVgiWorker
|
|
11910
12325
|
};
|
|
11911
12326
|
|
|
11912
|
-
//# debugId=
|
|
12327
|
+
//# debugId=421A831E60B471AC64756E2164756E21
|