@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/worker-cf-entry.js
CHANGED
|
@@ -9965,13 +9965,402 @@ async function openBytes(token, key, aad, version, field = "opaque data") {
|
|
|
9965
9965
|
}
|
|
9966
9966
|
}
|
|
9967
9967
|
|
|
9968
|
+
// src/attach-secret-options.ts
|
|
9969
|
+
init_arrow();
|
|
9970
|
+
|
|
9971
|
+
// src/attach-secret-keyfile.ts
|
|
9972
|
+
function builtins() {
|
|
9973
|
+
const proc = globalThis.process;
|
|
9974
|
+
const get = proc?.getBuiltinModule?.bind(proc);
|
|
9975
|
+
const fs = get?.("node:fs");
|
|
9976
|
+
const os = get?.("node:os");
|
|
9977
|
+
const path = get?.("node:path");
|
|
9978
|
+
if (!fs || !os || !path)
|
|
9979
|
+
throw new Error("this runtime has no filesystem for the host-local attach secret key file.");
|
|
9980
|
+
return { fs, os, path };
|
|
9981
|
+
}
|
|
9982
|
+
var ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
|
|
9983
|
+
var KEY_LEN = 32;
|
|
9984
|
+
var FILE_NAME = "attach-secret-options.key";
|
|
9985
|
+
var REMEDY = "Set VGI_SIGNING_KEY (or configure attachSecretKey), or point VGI_ATTACH_SECRET_KEY_FILE at a valid key file.";
|
|
9986
|
+
function username() {
|
|
9987
|
+
try {
|
|
9988
|
+
const name = builtins().os.userInfo().username;
|
|
9989
|
+
if (name)
|
|
9990
|
+
return name;
|
|
9991
|
+
} catch {}
|
|
9992
|
+
return process.env.USER || process.env.USERNAME || String(process.getuid?.() ?? "user");
|
|
9993
|
+
}
|
|
9994
|
+
function isDirectory(path) {
|
|
9995
|
+
try {
|
|
9996
|
+
return builtins().fs.statSync(path).isDirectory();
|
|
9997
|
+
} catch {
|
|
9998
|
+
return false;
|
|
9999
|
+
}
|
|
10000
|
+
}
|
|
10001
|
+
function hostLocalAttachSecretKeyPath(env = globalThis.process?.env ?? {}) {
|
|
10002
|
+
const { os, path: { join } } = builtins();
|
|
10003
|
+
const explicit = env[ATTACH_SECRET_KEY_FILE_ENV];
|
|
10004
|
+
if (explicit)
|
|
10005
|
+
return explicit;
|
|
10006
|
+
const xdg = env.XDG_RUNTIME_DIR;
|
|
10007
|
+
if (xdg && isDirectory(xdg))
|
|
10008
|
+
return join(xdg, "vgi", FILE_NAME);
|
|
10009
|
+
return join(os.tmpdir(), `vgi-${username()}`, FILE_NAME);
|
|
10010
|
+
}
|
|
10011
|
+
var POSIX = typeof process === "undefined" || process.platform !== "win32";
|
|
10012
|
+
function checkOwnedPrivate(path, mode, uid, what) {
|
|
10013
|
+
if (!POSIX)
|
|
10014
|
+
return;
|
|
10015
|
+
const me = process.getuid?.();
|
|
10016
|
+
if (me !== undefined && uid !== me) {
|
|
10017
|
+
throw new Error(`attach secret key ${what} ${path} is not owned by the current user. ${REMEDY}`);
|
|
10018
|
+
}
|
|
10019
|
+
if ((mode & 63) !== 0) {
|
|
10020
|
+
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}`);
|
|
10021
|
+
}
|
|
10022
|
+
}
|
|
10023
|
+
function ensureDir(dir) {
|
|
10024
|
+
const { mkdirSync, lstatSync } = builtins().fs;
|
|
10025
|
+
try {
|
|
10026
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
10027
|
+
} catch (e) {
|
|
10028
|
+
if (e.code !== "EEXIST")
|
|
10029
|
+
throw e;
|
|
10030
|
+
}
|
|
10031
|
+
const st = lstatSync(dir);
|
|
10032
|
+
if (!st.isDirectory())
|
|
10033
|
+
throw new Error(`attach secret key directory ${dir} is not a directory. ${REMEDY}`);
|
|
10034
|
+
checkOwnedPrivate(dir, st.mode, st.uid, "directory");
|
|
10035
|
+
}
|
|
10036
|
+
function readKey(path) {
|
|
10037
|
+
const { openSync, fstatSync, readSync, closeSync, constants } = builtins().fs;
|
|
10038
|
+
let fd;
|
|
10039
|
+
try {
|
|
10040
|
+
fd = openSync(path, constants.O_RDONLY | (POSIX ? constants.O_NOFOLLOW : 0));
|
|
10041
|
+
} catch (e) {
|
|
10042
|
+
if (e.code === "ENOENT")
|
|
10043
|
+
return null;
|
|
10044
|
+
throw new Error(`attach secret key file ${path} cannot be opened (${e.code}). ${REMEDY}`);
|
|
10045
|
+
}
|
|
10046
|
+
try {
|
|
10047
|
+
const st = fstatSync(fd);
|
|
10048
|
+
if (!st.isFile())
|
|
10049
|
+
throw new Error(`attach secret key file ${path} is not a regular file. ${REMEDY}`);
|
|
10050
|
+
checkOwnedPrivate(path, st.mode, st.uid, "file");
|
|
10051
|
+
const buf = new Uint8Array(KEY_LEN + 1);
|
|
10052
|
+
let n = 0;
|
|
10053
|
+
for (;; ) {
|
|
10054
|
+
const got = readSync(fd, buf, n, buf.length - n, null);
|
|
10055
|
+
if (got <= 0)
|
|
10056
|
+
break;
|
|
10057
|
+
n += got;
|
|
10058
|
+
if (n === buf.length)
|
|
10059
|
+
break;
|
|
10060
|
+
}
|
|
10061
|
+
if (n !== KEY_LEN || st.size !== KEY_LEN) {
|
|
10062
|
+
throw new Error(`attach secret key file ${path} must contain exactly ${KEY_LEN} raw bytes (found ${st.size}). ${REMEDY}`);
|
|
10063
|
+
}
|
|
10064
|
+
return buf.subarray(0, KEY_LEN);
|
|
10065
|
+
} finally {
|
|
10066
|
+
closeSync(fd);
|
|
10067
|
+
}
|
|
10068
|
+
}
|
|
10069
|
+
function createKey(path) {
|
|
10070
|
+
const { openSync, writeSync, fsyncSync, closeSync, linkSync, unlinkSync, constants } = builtins().fs;
|
|
10071
|
+
const { dirname, join } = builtins().path;
|
|
10072
|
+
const tmp = join(dirname(path), `.${FILE_NAME}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
10073
|
+
const fd = openSync(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 384);
|
|
10074
|
+
try {
|
|
10075
|
+
const key = crypto.getRandomValues(new Uint8Array(KEY_LEN));
|
|
10076
|
+
let off = 0;
|
|
10077
|
+
while (off < KEY_LEN)
|
|
10078
|
+
off += writeSync(fd, key, off, KEY_LEN - off);
|
|
10079
|
+
fsyncSync(fd);
|
|
10080
|
+
} finally {
|
|
10081
|
+
closeSync(fd);
|
|
10082
|
+
}
|
|
10083
|
+
try {
|
|
10084
|
+
linkSync(tmp, path);
|
|
10085
|
+
} catch (e) {
|
|
10086
|
+
if (e.code !== "EEXIST") {
|
|
10087
|
+
unlinkSync(tmp);
|
|
10088
|
+
throw e;
|
|
10089
|
+
}
|
|
10090
|
+
}
|
|
10091
|
+
unlinkSync(tmp);
|
|
10092
|
+
}
|
|
10093
|
+
function loadHostLocalAttachSecretKey(path = hostLocalAttachSecretKeyPath()) {
|
|
10094
|
+
ensureDir(builtins().path.dirname(path));
|
|
10095
|
+
const existing = readKey(path);
|
|
10096
|
+
if (existing)
|
|
10097
|
+
return existing;
|
|
10098
|
+
createKey(path);
|
|
10099
|
+
const created = readKey(path);
|
|
10100
|
+
if (!created)
|
|
10101
|
+
throw new Error(`attach secret key file ${path} vanished after creation. ${REMEDY}`);
|
|
10102
|
+
return created;
|
|
10103
|
+
}
|
|
10104
|
+
var cached;
|
|
10105
|
+
async function hostLocalAttachSecretKey() {
|
|
10106
|
+
const path = hostLocalAttachSecretKeyPath();
|
|
10107
|
+
if (cached?.path === path)
|
|
10108
|
+
return cached.key;
|
|
10109
|
+
const key = loadHostLocalAttachSecretKey(path);
|
|
10110
|
+
cached = { path, key };
|
|
10111
|
+
return key;
|
|
10112
|
+
}
|
|
10113
|
+
|
|
10114
|
+
// src/attach-secret-options.ts
|
|
10115
|
+
var UTF82 = new TextEncoder;
|
|
10116
|
+
var ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
|
|
10117
|
+
var ATTACH_SECRET_OPTIONS_VERSION = 1;
|
|
10118
|
+
var TRAILER_MAGIC = Uint8Array.of(0, 86, 71, 73, 65, 79, 1, 255);
|
|
10119
|
+
var TRAILER_FIXED = 4 + TRAILER_MAGIC.length;
|
|
10120
|
+
var NONCE_LEN2 = 24;
|
|
10121
|
+
var TAG_LEN2 = 16;
|
|
10122
|
+
var AAD_PREFIX = UTF82.encode(`${ATTACH_SECRET_OPTIONS_INFO}\x00`);
|
|
10123
|
+
var UUID_LEN = 16;
|
|
10124
|
+
var FIELD = "attach_opaque_data";
|
|
10125
|
+
|
|
10126
|
+
class AttachSecretKeyUnavailableError extends Error {
|
|
10127
|
+
constructor(message) {
|
|
10128
|
+
super(message);
|
|
10129
|
+
this.name = "AttachSecretKeyUnavailableError";
|
|
10130
|
+
}
|
|
10131
|
+
}
|
|
10132
|
+
|
|
10133
|
+
class AttachOptionsUnavailableError extends Error {
|
|
10134
|
+
constructor() {
|
|
10135
|
+
super("attachOptions(): these bytes are not an attach_opaque_data value the framework handed to this call. " + "Pass the attach value exactly as received (bindCall.attach_opaque_data, a TableBuffering attachId, or a " + "catalog method's attachOpaqueData argument, or a subarray of it), not a copy.");
|
|
10136
|
+
this.name = "AttachOptionsUnavailableError";
|
|
10137
|
+
}
|
|
10138
|
+
}
|
|
10139
|
+
var subkeys = new Map;
|
|
10140
|
+
function hexOf(b) {
|
|
10141
|
+
let s = "";
|
|
10142
|
+
for (let i = 0;i < b.length; i++)
|
|
10143
|
+
s += b[i].toString(16).padStart(2, "0");
|
|
10144
|
+
return s;
|
|
10145
|
+
}
|
|
10146
|
+
function deriveAttachSecretKey(root) {
|
|
10147
|
+
const id = hexOf(root);
|
|
10148
|
+
let derived = subkeys.get(id);
|
|
10149
|
+
if (!derived) {
|
|
10150
|
+
derived = (async () => {
|
|
10151
|
+
const ikm = await crypto.subtle.importKey("raw", root, "HKDF", false, ["deriveBits"]);
|
|
10152
|
+
const bits = await crypto.subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: UTF82.encode(ATTACH_SECRET_OPTIONS_INFO) }, ikm, 256);
|
|
10153
|
+
return new Uint8Array(bits);
|
|
10154
|
+
})();
|
|
10155
|
+
subkeys.set(id, derived);
|
|
10156
|
+
derived.catch(() => subkeys.delete(id));
|
|
10157
|
+
}
|
|
10158
|
+
return derived;
|
|
10159
|
+
}
|
|
10160
|
+
function defaultHostLocal() {
|
|
10161
|
+
return hostLocalAttachSecretKey();
|
|
10162
|
+
}
|
|
10163
|
+
function noKeyMessage() {
|
|
10164
|
+
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.";
|
|
10165
|
+
}
|
|
10166
|
+
async function rootKey(source) {
|
|
10167
|
+
if (source.explicit && source.explicit.length > 0)
|
|
10168
|
+
return source.explicit;
|
|
10169
|
+
if (source.signingKey && source.signingKey.length > 0)
|
|
10170
|
+
return source.signingKey;
|
|
10171
|
+
return (source.hostLocal ?? defaultHostLocal)();
|
|
10172
|
+
}
|
|
10173
|
+
function aadFor(uuid) {
|
|
10174
|
+
const out = new Uint8Array(AAD_PREFIX.length + uuid.length);
|
|
10175
|
+
out.set(AAD_PREFIX, 0);
|
|
10176
|
+
out.set(uuid, AAD_PREFIX.length);
|
|
10177
|
+
return out;
|
|
10178
|
+
}
|
|
10179
|
+
function u32le(n) {
|
|
10180
|
+
const b = new Uint8Array(4);
|
|
10181
|
+
new DataView(b.buffer).setUint32(0, n, true);
|
|
10182
|
+
return b;
|
|
10183
|
+
}
|
|
10184
|
+
function readU32le(b, off) {
|
|
10185
|
+
return new DataView(b.buffer, b.byteOffset, b.byteLength).getUint32(off, true);
|
|
10186
|
+
}
|
|
10187
|
+
function concat2(...parts) {
|
|
10188
|
+
let total = 0;
|
|
10189
|
+
for (const p of parts)
|
|
10190
|
+
total += p.length;
|
|
10191
|
+
const out = new Uint8Array(total);
|
|
10192
|
+
let off = 0;
|
|
10193
|
+
for (const p of parts) {
|
|
10194
|
+
out.set(p, off);
|
|
10195
|
+
off += p.length;
|
|
10196
|
+
}
|
|
10197
|
+
return out;
|
|
10198
|
+
}
|
|
10199
|
+
function splitOptions(optionsIpc, secretNames) {
|
|
10200
|
+
if (!optionsIpc || optionsIpc.length === 0)
|
|
10201
|
+
return null;
|
|
10202
|
+
const batch = deserializeBatch(optionsIpc);
|
|
10203
|
+
if (batch.numRows === 0 || batch.schema.fields.length === 0)
|
|
10204
|
+
return null;
|
|
10205
|
+
const row = iterRows(batch).next().value ?? {};
|
|
10206
|
+
const plainFields = [];
|
|
10207
|
+
const secretFields = [];
|
|
10208
|
+
const plainCols = {};
|
|
10209
|
+
const secretCols = {};
|
|
10210
|
+
for (const f of batch.schema.fields) {
|
|
10211
|
+
const value = row[f.name];
|
|
10212
|
+
if (secretNames.has(f.name.toLowerCase()) && value !== null && value !== undefined) {
|
|
10213
|
+
secretFields.push(f);
|
|
10214
|
+
secretCols[f.name] = [value];
|
|
10215
|
+
} else {
|
|
10216
|
+
plainFields.push(f);
|
|
10217
|
+
plainCols[f.name] = [value ?? null];
|
|
10218
|
+
}
|
|
10219
|
+
}
|
|
10220
|
+
return {
|
|
10221
|
+
plain: plainFields.length ? serializeBatch(batchFromColumns(plainCols, schema2(plainFields))) : null,
|
|
10222
|
+
secret: secretFields.length ? serializeBatch(batchFromColumns(secretCols, schema2(secretFields))) : null
|
|
10223
|
+
};
|
|
10224
|
+
}
|
|
10225
|
+
async function packAttachOptionsTrailer(uuid, optionsIpc, secretNames, keys, fixedNonce) {
|
|
10226
|
+
const split = splitOptions(optionsIpc, secretNames);
|
|
10227
|
+
if (split === null)
|
|
10228
|
+
return new Uint8Array(0);
|
|
10229
|
+
const plain = split.plain ?? new Uint8Array(0);
|
|
10230
|
+
let secret = new Uint8Array(0);
|
|
10231
|
+
if (split.secret) {
|
|
10232
|
+
let root;
|
|
10233
|
+
try {
|
|
10234
|
+
root = await rootKey(keys);
|
|
10235
|
+
} catch (e) {
|
|
10236
|
+
if (e instanceof AttachSecretKeyUnavailableError)
|
|
10237
|
+
throw e;
|
|
10238
|
+
throw new AttachSecretKeyUnavailableError(`${noKeyMessage()} ${e.message}`);
|
|
10239
|
+
}
|
|
10240
|
+
const key = await deriveAttachSecretKey(root);
|
|
10241
|
+
const nonce = fixedNonce ?? crypto.getRandomValues(new Uint8Array(NONCE_LEN2));
|
|
10242
|
+
const ct = xchacha20poly1305(key, nonce, aadFor(uuid)).encrypt(split.secret);
|
|
10243
|
+
secret = concat2(Uint8Array.of(ATTACH_SECRET_OPTIONS_VERSION), nonce, ct);
|
|
10244
|
+
}
|
|
10245
|
+
const body = concat2(u32le(plain.length), plain, secret);
|
|
10246
|
+
return concat2(body, u32le(body.length), TRAILER_MAGIC);
|
|
10247
|
+
}
|
|
10248
|
+
function endsWithMagic(b) {
|
|
10249
|
+
if (b.length < TRAILER_MAGIC.length)
|
|
10250
|
+
return false;
|
|
10251
|
+
const off = b.length - TRAILER_MAGIC.length;
|
|
10252
|
+
for (let i = 0;i < TRAILER_MAGIC.length; i++)
|
|
10253
|
+
if (b[off + i] !== TRAILER_MAGIC[i])
|
|
10254
|
+
return false;
|
|
10255
|
+
return true;
|
|
10256
|
+
}
|
|
10257
|
+
function decodeOptions(ipc) {
|
|
10258
|
+
const batch = deserializeBatch(ipc);
|
|
10259
|
+
if (batch.numRows === 0)
|
|
10260
|
+
return {};
|
|
10261
|
+
return { ...iterRows(batch).next().value ?? {} };
|
|
10262
|
+
}
|
|
10263
|
+
var registry = new WeakMap;
|
|
10264
|
+
var EMPTY = Object.freeze({});
|
|
10265
|
+
async function openFrameworkAttach(full, keys) {
|
|
10266
|
+
if (full.length < UUID_LEN)
|
|
10267
|
+
return full;
|
|
10268
|
+
const copy = full.slice();
|
|
10269
|
+
let end = copy.length;
|
|
10270
|
+
let options = EMPTY;
|
|
10271
|
+
if (copy.length >= UUID_LEN + TRAILER_FIXED && endsWithMagic(copy)) {
|
|
10272
|
+
const bodyLen = readU32le(copy, copy.length - TRAILER_FIXED);
|
|
10273
|
+
const bodyStart = copy.length - TRAILER_FIXED - bodyLen;
|
|
10274
|
+
if (bodyLen < 4 || bodyStart < UUID_LEN)
|
|
10275
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10276
|
+
const body = copy.subarray(bodyStart, copy.length - TRAILER_FIXED);
|
|
10277
|
+
const plainLen = readU32le(body, 0);
|
|
10278
|
+
if (4 + plainLen > body.length)
|
|
10279
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10280
|
+
const plain = body.subarray(4, 4 + plainLen);
|
|
10281
|
+
const secret = body.subarray(4 + plainLen);
|
|
10282
|
+
const values = {};
|
|
10283
|
+
try {
|
|
10284
|
+
if (plain.length)
|
|
10285
|
+
Object.assign(values, decodeOptions(plain));
|
|
10286
|
+
} catch {
|
|
10287
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10288
|
+
}
|
|
10289
|
+
if (secret.length) {
|
|
10290
|
+
if (secret.length < 1 + NONCE_LEN2 + TAG_LEN2 || secret[0] !== ATTACH_SECRET_OPTIONS_VERSION) {
|
|
10291
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10292
|
+
}
|
|
10293
|
+
let opened;
|
|
10294
|
+
try {
|
|
10295
|
+
const key = await deriveAttachSecretKey(await rootKey(keys));
|
|
10296
|
+
const nonce = secret.subarray(1, 1 + NONCE_LEN2);
|
|
10297
|
+
opened = xchacha20poly1305(key, nonce, aadFor(copy.subarray(0, UUID_LEN))).decrypt(secret.subarray(1 + NONCE_LEN2));
|
|
10298
|
+
} catch {
|
|
10299
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10300
|
+
}
|
|
10301
|
+
try {
|
|
10302
|
+
Object.assign(values, decodeOptions(opened));
|
|
10303
|
+
} catch {
|
|
10304
|
+
throw new OpaqueDataRejectedError(FIELD);
|
|
10305
|
+
}
|
|
10306
|
+
}
|
|
10307
|
+
options = Object.freeze(values);
|
|
10308
|
+
end = bodyStart;
|
|
10309
|
+
}
|
|
10310
|
+
registry.set(copy.buffer, options);
|
|
10311
|
+
return copy.subarray(UUID_LEN, end);
|
|
10312
|
+
}
|
|
10313
|
+
function attachOptions(attachOpaqueData) {
|
|
10314
|
+
if (attachOpaqueData == null)
|
|
10315
|
+
return EMPTY;
|
|
10316
|
+
const found = registry.get(attachOpaqueData.buffer);
|
|
10317
|
+
if (found !== undefined)
|
|
10318
|
+
return found;
|
|
10319
|
+
if (attachOpaqueData.length === 0)
|
|
10320
|
+
return EMPTY;
|
|
10321
|
+
throw new AttachOptionsUnavailableError;
|
|
10322
|
+
}
|
|
10323
|
+
async function secretAttachOptionNames(catalog, name, deserialize) {
|
|
10324
|
+
const names = new Set;
|
|
10325
|
+
if (typeof catalog.attachOptionSpecs === "function") {
|
|
10326
|
+
for (const spec of catalog.attachOptionSpecs(name) ?? [])
|
|
10327
|
+
if (spec.secret)
|
|
10328
|
+
names.add(spec.name.toLowerCase());
|
|
10329
|
+
}
|
|
10330
|
+
if (typeof catalog.catalogsInfo === "function") {
|
|
10331
|
+
let infos;
|
|
10332
|
+
try {
|
|
10333
|
+
infos = await catalog.catalogsInfo();
|
|
10334
|
+
} catch {
|
|
10335
|
+
infos = [];
|
|
10336
|
+
}
|
|
10337
|
+
for (const info of infos ?? []) {
|
|
10338
|
+
if (info.name !== name)
|
|
10339
|
+
continue;
|
|
10340
|
+
for (const raw of info.attach_option_specs ?? []) {
|
|
10341
|
+
try {
|
|
10342
|
+
const spec = deserialize(raw);
|
|
10343
|
+
if (spec.secret)
|
|
10344
|
+
names.add(spec.name.toLowerCase());
|
|
10345
|
+
} catch {}
|
|
10346
|
+
}
|
|
10347
|
+
}
|
|
10348
|
+
}
|
|
10349
|
+
return names;
|
|
10350
|
+
}
|
|
10351
|
+
|
|
9968
10352
|
// src/protocol/handlers/catalog/shared.ts
|
|
9969
|
-
async function sealAttach(plaintext, auth, signingKey) {
|
|
10353
|
+
async function sealAttach(plaintext, auth, signingKey, options) {
|
|
9970
10354
|
const uuid = new Uint8Array(ATTACH_UUID_LEN);
|
|
9971
10355
|
crypto.getRandomValues(uuid);
|
|
9972
|
-
const
|
|
10356
|
+
const trailer = options ? await packAttachOptionsTrailer(uuid, options.optionsIpc, options.secretNames, {
|
|
10357
|
+
explicit: options.attachSecretKey,
|
|
10358
|
+
signingKey
|
|
10359
|
+
}) : new Uint8Array(0);
|
|
10360
|
+
const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length + trailer.length);
|
|
9973
10361
|
minted.set(uuid, 0);
|
|
9974
10362
|
minted.set(plaintext, ATTACH_UUID_LEN);
|
|
10363
|
+
minted.set(trailer, ATTACH_UUID_LEN + plaintext.length);
|
|
9975
10364
|
if (!signingKey)
|
|
9976
10365
|
return minted;
|
|
9977
10366
|
return sealBytes(minted, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION);
|
|
@@ -9981,16 +10370,22 @@ async function openAttachFull(envelope, auth, signingKey) {
|
|
|
9981
10370
|
return envelope;
|
|
9982
10371
|
return openBytes(envelope, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data");
|
|
9983
10372
|
}
|
|
9984
|
-
async function openAttach(envelope, auth, signingKey) {
|
|
10373
|
+
async function openAttach(envelope, auth, signingKey, attachSecretKey) {
|
|
9985
10374
|
const full = await openAttachFull(envelope, auth, signingKey);
|
|
9986
|
-
return full
|
|
10375
|
+
return openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
|
|
9987
10376
|
}
|
|
9988
10377
|
async function sealTransaction(plaintext, attachEnvelope, auth, signingKey) {
|
|
9989
10378
|
if (!signingKey)
|
|
9990
10379
|
return plaintext;
|
|
9991
10380
|
return sealBytes(plaintext, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION);
|
|
9992
10381
|
}
|
|
9993
|
-
async function
|
|
10382
|
+
async function openTransaction(envelope, attachEnvelope, auth, signingKey) {
|
|
10383
|
+
if (!signingKey || envelope.length === 0)
|
|
10384
|
+
return envelope;
|
|
10385
|
+
return openBytes(envelope, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION, "transaction_opaque_data");
|
|
10386
|
+
}
|
|
10387
|
+
async function unwrapParamsOpaque(params, ctx, keys) {
|
|
10388
|
+
const { signingKey, attachSecretKey } = keys;
|
|
9994
10389
|
const auth = ctx?.auth;
|
|
9995
10390
|
let sealedAttach = new Uint8Array(0);
|
|
9996
10391
|
if (params.attach_opaque_data != null) {
|
|
@@ -9998,7 +10393,7 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
|
|
|
9998
10393
|
if (env.length > 0) {
|
|
9999
10394
|
sealedAttach = env;
|
|
10000
10395
|
const full = signingKey ? await openBytes(env, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data") : env;
|
|
10001
|
-
params.attach_opaque_data = full
|
|
10396
|
+
params.attach_opaque_data = await openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
|
|
10002
10397
|
}
|
|
10003
10398
|
}
|
|
10004
10399
|
if (signingKey && params.transaction_opaque_data != null) {
|
|
@@ -10008,14 +10403,15 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
|
|
|
10008
10403
|
}
|
|
10009
10404
|
}
|
|
10010
10405
|
}
|
|
10011
|
-
function catalogHandler(
|
|
10406
|
+
function catalogHandler(keysOrSigningKey, handler) {
|
|
10407
|
+
const keys = keysOrSigningKey instanceof Uint8Array || keysOrSigningKey === undefined ? { signingKey: keysOrSigningKey } : keysOrSigningKey;
|
|
10012
10408
|
return async (wire, ctx) => {
|
|
10013
10409
|
let params = wire;
|
|
10014
10410
|
if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
|
|
10015
10411
|
params = unwrapRequest(params.request);
|
|
10016
10412
|
}
|
|
10017
10413
|
normalizeRequestSchemaPaths(params);
|
|
10018
|
-
await unwrapParamsOpaque(params, ctx,
|
|
10414
|
+
await unwrapParamsOpaque(params, ctx, keys);
|
|
10019
10415
|
return handler(params, ctx);
|
|
10020
10416
|
};
|
|
10021
10417
|
}
|
|
@@ -10157,7 +10553,7 @@ var RESERVED_FLAGS_MASK = 254;
|
|
|
10157
10553
|
var FINGERPRINT_LEN = 16;
|
|
10158
10554
|
var HEADER_LEN = 4 + FINGERPRINT_LEN;
|
|
10159
10555
|
var SEAL_VERSION = 1;
|
|
10160
|
-
var
|
|
10556
|
+
var AAD_PREFIX2 = new TextEncoder().encode("vgi.split_token.v1\x00");
|
|
10161
10557
|
var SPLIT_TOKEN_INVALID = "SPLIT_TOKEN_INVALID";
|
|
10162
10558
|
var SPLIT_SNAPSHOT_EXPIRED = "SPLIT_SNAPSHOT_EXPIRED";
|
|
10163
10559
|
class SplitTokenError extends Error {
|
|
@@ -10168,7 +10564,7 @@ class SplitTokenError extends Error {
|
|
|
10168
10564
|
this.kind = kind;
|
|
10169
10565
|
}
|
|
10170
10566
|
}
|
|
10171
|
-
function
|
|
10567
|
+
function concat3(...parts) {
|
|
10172
10568
|
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
10173
10569
|
const out = new Uint8Array(total);
|
|
10174
10570
|
let at = 0;
|
|
@@ -10189,13 +10585,13 @@ function equalBytes2(a, b) {
|
|
|
10189
10585
|
async function bindFingerprint(schemaPath, functionName, args, settings, projection) {
|
|
10190
10586
|
const enc = new TextEncoder;
|
|
10191
10587
|
const zero = Uint8Array.of(0);
|
|
10192
|
-
const field = (label, value) =>
|
|
10193
|
-
const message =
|
|
10588
|
+
const field = (label, value) => concat3(enc.encode(label), zero, value, zero);
|
|
10589
|
+
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));
|
|
10194
10590
|
const digest = await crypto.subtle.digest("SHA-256", message);
|
|
10195
10591
|
return new Uint8Array(digest).slice(0, FINGERPRINT_LEN);
|
|
10196
10592
|
}
|
|
10197
10593
|
function splitTokenAad(header, auth) {
|
|
10198
|
-
return
|
|
10594
|
+
return concat3(header, identityTail(auth));
|
|
10199
10595
|
}
|
|
10200
10596
|
function splitAnchor(catalogVersion) {
|
|
10201
10597
|
const out = new Uint8Array(8);
|
|
@@ -10214,11 +10610,11 @@ async function buildSplitToken(opts) {
|
|
|
10214
10610
|
head[0] = SPLIT_TOKEN_FORMAT_VERSION;
|
|
10215
10611
|
head[1] = signingKey ? FLAG_PAYLOAD_SEALED : 0;
|
|
10216
10612
|
new DataView(head.buffer).setUint16(2, anchor.length, true);
|
|
10217
|
-
const body =
|
|
10613
|
+
const body = concat3(head, fingerprint, anchor);
|
|
10218
10614
|
if (!signingKey)
|
|
10219
|
-
return
|
|
10615
|
+
return concat3(body, payload);
|
|
10220
10616
|
const sealed = await sealBytes(payload, signingKey, splitTokenAad(body, auth), SEAL_VERSION);
|
|
10221
|
-
return
|
|
10617
|
+
return concat3(body, sealed);
|
|
10222
10618
|
}
|
|
10223
10619
|
async function openSplitToken(token, opts = {}) {
|
|
10224
10620
|
const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
|
|
@@ -10266,14 +10662,19 @@ async function openSplitToken(token, opts = {}) {
|
|
|
10266
10662
|
}
|
|
10267
10663
|
|
|
10268
10664
|
// src/protocol/handlers/function.ts
|
|
10269
|
-
async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
|
|
10665
|
+
async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey, attachSecretKey) {
|
|
10270
10666
|
if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
|
|
10271
10667
|
return;
|
|
10272
10668
|
const raw = toUint8Array(bindCall.attach_opaque_data);
|
|
10273
|
-
|
|
10669
|
+
let txn = bindCall.transaction_opaque_data ? toUint8Array(bindCall.transaction_opaque_data) : undefined;
|
|
10670
|
+
if (txn && txn.length > 0 && signingKey) {
|
|
10671
|
+
try {
|
|
10672
|
+
txn = await openTransaction(txn, raw, auth, signingKey);
|
|
10673
|
+
} catch {}
|
|
10674
|
+
}
|
|
10274
10675
|
const forms = [
|
|
10275
10676
|
async () => raw,
|
|
10276
|
-
async () => openAttach(raw, auth, signingKey)
|
|
10677
|
+
async () => openAttach(raw, auth, signingKey, attachSecretKey)
|
|
10277
10678
|
];
|
|
10278
10679
|
for (const form of forms) {
|
|
10279
10680
|
try {
|
|
@@ -10287,7 +10688,7 @@ async function resolveSplitPayloads(request, innerParams, opts) {
|
|
|
10287
10688
|
return;
|
|
10288
10689
|
const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
|
|
10289
10690
|
const expected = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
|
|
10290
|
-
const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey) : undefined;
|
|
10691
|
+
const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey, opts.attachSecretKey) : undefined;
|
|
10291
10692
|
request.split_payloads = [];
|
|
10292
10693
|
for (const token of request.split_tokens) {
|
|
10293
10694
|
request.split_payloads.push(await openSplitToken(token, {
|
|
@@ -10299,23 +10700,31 @@ async function resolveSplitPayloads(request, innerParams, opts) {
|
|
|
10299
10700
|
}
|
|
10300
10701
|
}
|
|
10301
10702
|
function functionHandlers(config) {
|
|
10302
|
-
const { registry, signingKey, catalogInterface } = config;
|
|
10703
|
+
const { registry, signingKey, catalogInterface, attachSecretKey } = config;
|
|
10303
10704
|
async function stripAttach(attach, ctx) {
|
|
10304
10705
|
if (attach == null)
|
|
10305
10706
|
return null;
|
|
10306
10707
|
const env = toUint8Array(attach);
|
|
10307
10708
|
if (env.length === 0)
|
|
10308
10709
|
return env;
|
|
10309
|
-
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
10710
|
+
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
|
|
10711
|
+
}
|
|
10712
|
+
async function openOpaque(bindCall, ctx) {
|
|
10713
|
+
const sealedAttach = bindCall.attach_opaque_data != null ? toUint8Array(bindCall.attach_opaque_data) : new Uint8Array(0);
|
|
10714
|
+
if (bindCall.transaction_opaque_data != null) {
|
|
10715
|
+
bindCall.transaction_opaque_data = await openTransaction(toUint8Array(bindCall.transaction_opaque_data), sealedAttach, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
10716
|
+
}
|
|
10717
|
+
bindCall.attach_opaque_data = await stripAttach(bindCall.attach_opaque_data, ctx);
|
|
10310
10718
|
}
|
|
10311
10719
|
async function strippedContext(bindCall, ctx) {
|
|
10312
|
-
|
|
10720
|
+
const copy = { ...bindCall };
|
|
10313
10721
|
try {
|
|
10314
|
-
|
|
10722
|
+
await openOpaque(copy, ctx);
|
|
10315
10723
|
} catch {
|
|
10316
|
-
|
|
10724
|
+
copy.attach_opaque_data = null;
|
|
10725
|
+
copy.transaction_opaque_data = null;
|
|
10317
10726
|
}
|
|
10318
|
-
return overloadContext(
|
|
10727
|
+
return overloadContext(copy, catalogInterface);
|
|
10319
10728
|
}
|
|
10320
10729
|
const emptySchema = schema2([]);
|
|
10321
10730
|
const dummyInputSchema = schema2([
|
|
@@ -10324,7 +10733,7 @@ function functionHandlers(config) {
|
|
|
10324
10733
|
const bind = async (params, ctx) => {
|
|
10325
10734
|
const innerParams = unwrapRequest(params.request);
|
|
10326
10735
|
const request = deserializeBindRequest(innerParams);
|
|
10327
|
-
|
|
10736
|
+
await openOpaque(request, ctx);
|
|
10328
10737
|
const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
|
|
10329
10738
|
const response = await func.bind(request);
|
|
10330
10739
|
validateProjectionOffer(response);
|
|
@@ -10339,10 +10748,11 @@ function functionHandlers(config) {
|
|
|
10339
10748
|
const innerParams = unwrapRequest(params.request);
|
|
10340
10749
|
const request = deserializeInitRequest(innerParams);
|
|
10341
10750
|
const auth = ctx?.auth ?? currentRequestAuth();
|
|
10342
|
-
|
|
10751
|
+
await openOpaque(request.bind_call, ctx);
|
|
10343
10752
|
await resolveSplitPayloads(request, innerParams, {
|
|
10344
10753
|
auth,
|
|
10345
10754
|
signingKey,
|
|
10755
|
+
attachSecretKey,
|
|
10346
10756
|
catalogInterface,
|
|
10347
10757
|
checkAnchor: true
|
|
10348
10758
|
});
|
|
@@ -10384,10 +10794,11 @@ function functionHandlers(config) {
|
|
|
10384
10794
|
} else {
|
|
10385
10795
|
const carried = parseCarriedInitRequest(state.initRequestPacked);
|
|
10386
10796
|
const request = carried.request;
|
|
10387
|
-
|
|
10797
|
+
await openOpaque(request.bind_call, undefined);
|
|
10388
10798
|
await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
|
|
10389
10799
|
auth: currentRequestAuth(),
|
|
10390
10800
|
signingKey,
|
|
10801
|
+
attachSecretKey,
|
|
10391
10802
|
catalogInterface,
|
|
10392
10803
|
checkAnchor: false
|
|
10393
10804
|
});
|
|
@@ -10459,7 +10870,7 @@ function functionHandlers(config) {
|
|
|
10459
10870
|
const plan = func.plan ? await func.plan(request) : { splits: [{ payload: new Uint8Array(0) }] };
|
|
10460
10871
|
const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
|
|
10461
10872
|
const fingerprint = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
|
|
10462
|
-
const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey) ?? splitAnchor(0);
|
|
10873
|
+
const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey, attachSecretKey) ?? splitAnchor(0);
|
|
10463
10874
|
const blobs = [];
|
|
10464
10875
|
for (const split of plan.splits) {
|
|
10465
10876
|
const token = await buildSplitToken({
|
|
@@ -11320,7 +11731,7 @@ function splitLenPrefixed(buf, count) {
|
|
|
11320
11731
|
}
|
|
11321
11732
|
|
|
11322
11733
|
// src/protocol/handlers/table-buffering.ts
|
|
11323
|
-
function tableBufferingHandlers(registry, signingKey) {
|
|
11734
|
+
function tableBufferingHandlers(registry, signingKey, attachSecretKey) {
|
|
11324
11735
|
function resolveBuffering(name, schemaPath) {
|
|
11325
11736
|
const func = registry.get(name, {
|
|
11326
11737
|
arguments: new Arguments,
|
|
@@ -11337,7 +11748,7 @@ function tableBufferingHandlers(registry, signingKey) {
|
|
|
11337
11748
|
const functionName = inner.function_name;
|
|
11338
11749
|
const executionId = toUint8Array(inner.execution_id);
|
|
11339
11750
|
const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
|
|
11340
|
-
const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey) : rawAttach;
|
|
11751
|
+
const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey) : rawAttach;
|
|
11341
11752
|
const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
|
|
11342
11753
|
const func = resolveBuffering(functionName, inner.schema_path ?? null);
|
|
11343
11754
|
const bound = new BoundStorage(storage, executionId);
|
|
@@ -12804,6 +13215,15 @@ class CatalogInterface {
|
|
|
12804
13215
|
tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
|
|
12805
13216
|
throw new CatalogReadOnlyError("table_scan_function_get");
|
|
12806
13217
|
}
|
|
13218
|
+
tableInsertFunctionGet(attachOpaqueData, schemaPath, name, transactionOpaqueData, writableBranchFunctionName) {
|
|
13219
|
+
throw new CatalogReadOnlyError("table_insert_function_get");
|
|
13220
|
+
}
|
|
13221
|
+
tableUpdateFunctionGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
13222
|
+
throw new CatalogReadOnlyError("table_update_function_get");
|
|
13223
|
+
}
|
|
13224
|
+
tableDeleteFunctionGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
13225
|
+
throw new CatalogReadOnlyError("table_delete_function_get");
|
|
13226
|
+
}
|
|
12807
13227
|
tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
|
|
12808
13228
|
const legacy = this.tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
12809
13229
|
return isPromise(legacy) ? legacy.then((r) => singleBranchResult(r)) : singleBranchResult(legacy);
|
|
@@ -12919,6 +13339,9 @@ class CatalogInterface {
|
|
|
12919
13339
|
catalogContentsOwner(_attachOpaqueData) {
|
|
12920
13340
|
return this;
|
|
12921
13341
|
}
|
|
13342
|
+
attachOptions(attachOpaqueData) {
|
|
13343
|
+
return attachOptions(attachOpaqueData);
|
|
13344
|
+
}
|
|
12922
13345
|
transactionBegin(attachOpaqueData) {
|
|
12923
13346
|
return null;
|
|
12924
13347
|
}
|
|
@@ -13080,9 +13503,9 @@ var TICKET_ENVELOPE_VERSION = 1;
|
|
|
13080
13503
|
var MAX_OPTIONS_BYTES = 16 * 1024;
|
|
13081
13504
|
var MAX_TICKET_CHARS = 32 * 1024;
|
|
13082
13505
|
var CLOCK_SKEW_SECONDS = 60;
|
|
13083
|
-
var
|
|
13506
|
+
var UTF83 = new TextEncoder;
|
|
13084
13507
|
var STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
13085
|
-
var TICKET_AAD_DOMAIN =
|
|
13508
|
+
var TICKET_AAD_DOMAIN = UTF83.encode("vgi.attach_ticket.v1\x00");
|
|
13086
13509
|
var TICKET_ID = /^[0-9a-f]{32}$/;
|
|
13087
13510
|
var B64URL = /^[A-Za-z0-9_-]+$/;
|
|
13088
13511
|
var MAX_TEXT = 65535;
|
|
@@ -13136,14 +13559,14 @@ class SealAttachDeniedError extends Error {
|
|
|
13136
13559
|
}
|
|
13137
13560
|
}
|
|
13138
13561
|
function attachTicketAad(principal) {
|
|
13139
|
-
const p =
|
|
13562
|
+
const p = UTF83.encode(principal);
|
|
13140
13563
|
const out = new Uint8Array(TICKET_AAD_DOMAIN.length + p.length);
|
|
13141
13564
|
out.set(TICKET_AAD_DOMAIN, 0);
|
|
13142
13565
|
out.set(p, TICKET_AAD_DOMAIN.length);
|
|
13143
13566
|
return out;
|
|
13144
13567
|
}
|
|
13145
13568
|
function packText(value, name) {
|
|
13146
|
-
const raw =
|
|
13569
|
+
const raw = UTF83.encode(value);
|
|
13147
13570
|
if (raw.length > MAX_TEXT)
|
|
13148
13571
|
throw new Error(`${name} is longer than 65535 bytes`);
|
|
13149
13572
|
const out = new Uint8Array(2 + raw.length);
|
|
@@ -13467,8 +13890,9 @@ function buildAttachTicketsProtocol(config) {
|
|
|
13467
13890
|
}
|
|
13468
13891
|
|
|
13469
13892
|
// src/protocol/handlers/catalog/admin.ts
|
|
13470
|
-
function catalogAdminHandlers(getCatalog, signingKey) {
|
|
13471
|
-
const
|
|
13893
|
+
function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
13894
|
+
const keys = { signingKey, attachSecretKey };
|
|
13895
|
+
const catalogCatalogs = catalogHandler(keys, async () => {
|
|
13472
13896
|
const cat = getCatalog();
|
|
13473
13897
|
const infos = cat.catalogsInfo ? await cat.catalogsInfo() : cat.catalogs().map((name) => ({
|
|
13474
13898
|
name,
|
|
@@ -13499,29 +13923,31 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
13499
13923
|
result.catalog_capabilities = encodeCatalogCapabilities(catalogCapabilities(advertised));
|
|
13500
13924
|
result.selected_capabilities = encodeCatalogCapabilities(selectCatalogCapabilities(advertised, clientCapabilities, result.supports_transactions ?? false));
|
|
13501
13925
|
}
|
|
13502
|
-
const
|
|
13926
|
+
const optionsIpc = innerParams.options == null ? null : toUint8Array(innerParams.options);
|
|
13927
|
+
const secretNames = optionsIpc && optionsIpc.length > 0 ? await secretAttachOptionNames(cat, innerParams.name, deserializeAttachOptionSpec) : new Set;
|
|
13928
|
+
const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey, { optionsIpc, secretNames, attachSecretKey });
|
|
13503
13929
|
return wrapResult(buildCatalogAttachResult({
|
|
13504
13930
|
...result,
|
|
13505
13931
|
attach_opaque_data: sealedAttach,
|
|
13506
13932
|
supports_column_statistics: result.supports_column_statistics ?? true
|
|
13507
13933
|
}), CatalogAttachResultSchema);
|
|
13508
13934
|
};
|
|
13509
|
-
const catalogDetach = catalogHandler(
|
|
13935
|
+
const catalogDetach = catalogHandler(keys, async (params) => {
|
|
13510
13936
|
const cat = getCatalog();
|
|
13511
13937
|
await cat.detach(toUint8Array(params.attach_opaque_data));
|
|
13512
13938
|
return {};
|
|
13513
13939
|
});
|
|
13514
|
-
const catalogCreate = catalogHandler(
|
|
13940
|
+
const catalogCreate = catalogHandler(keys, async (params) => {
|
|
13515
13941
|
const cat = getCatalog();
|
|
13516
13942
|
await cat.create(params.name, params.on_conflict, params.options);
|
|
13517
13943
|
return {};
|
|
13518
13944
|
});
|
|
13519
|
-
const catalogDrop = catalogHandler(
|
|
13945
|
+
const catalogDrop = catalogHandler(keys, async (params) => {
|
|
13520
13946
|
const cat = getCatalog();
|
|
13521
13947
|
await cat.drop(params.name);
|
|
13522
13948
|
return {};
|
|
13523
13949
|
});
|
|
13524
|
-
const catalogVersion = catalogHandler(
|
|
13950
|
+
const catalogVersion = catalogHandler(keys, async (params) => {
|
|
13525
13951
|
const cat = getCatalog();
|
|
13526
13952
|
const version = await cat.version(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13527
13953
|
return wrapResult({ version }, CatalogVersionResultSchema);
|
|
@@ -13529,23 +13955,23 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
13529
13955
|
const catalogTransactionBegin = async (params, ctx) => {
|
|
13530
13956
|
const auth = ctx?.auth;
|
|
13531
13957
|
const sealedAttach = params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
|
|
13532
|
-
const attachPlain = await openAttach(sealedAttach, auth, signingKey);
|
|
13958
|
+
const attachPlain = await openAttach(sealedAttach, auth, signingKey, attachSecretKey);
|
|
13533
13959
|
const cat = getCatalog();
|
|
13534
13960
|
const txPlain = await cat.transactionBegin(attachPlain);
|
|
13535
13961
|
const transaction_opaque_data = txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
|
|
13536
13962
|
return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
|
|
13537
13963
|
};
|
|
13538
|
-
const catalogTransactionCommit = catalogHandler(
|
|
13964
|
+
const catalogTransactionCommit = catalogHandler(keys, async (params) => {
|
|
13539
13965
|
const cat = getCatalog();
|
|
13540
13966
|
await cat.transactionCommit(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
|
|
13541
13967
|
return {};
|
|
13542
13968
|
});
|
|
13543
|
-
const catalogTransactionRollback = catalogHandler(
|
|
13969
|
+
const catalogTransactionRollback = catalogHandler(keys, async (params) => {
|
|
13544
13970
|
const cat = getCatalog();
|
|
13545
13971
|
await cat.transactionRollback(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
|
|
13546
13972
|
return {};
|
|
13547
13973
|
});
|
|
13548
|
-
const catalogSchemas = catalogHandler(
|
|
13974
|
+
const catalogSchemas = catalogHandler(keys, async (params) => {
|
|
13549
13975
|
const cat = getCatalog();
|
|
13550
13976
|
const schemas = await cat.schemas(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13551
13977
|
return wrapResult({
|
|
@@ -13554,52 +13980,52 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
13554
13980
|
});
|
|
13555
13981
|
const catalogContents = async (params, ctx) => {
|
|
13556
13982
|
const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
|
|
13557
|
-
return catalogHandler(
|
|
13983
|
+
return catalogHandler(keys, async (opened, context) => {
|
|
13558
13984
|
const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
|
|
13559
13985
|
return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
|
|
13560
13986
|
})(params, ctx);
|
|
13561
13987
|
};
|
|
13562
|
-
const catalogCopyFromFormats = catalogHandler(
|
|
13988
|
+
const catalogCopyFromFormats = catalogHandler(keys, async (params) => {
|
|
13563
13989
|
const cat = getCatalog();
|
|
13564
13990
|
const formats = await cat.copyFromFormats(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13565
13991
|
return wrapResult({
|
|
13566
13992
|
items: formats.map((f) => encodeCopyFromFormatInfo(f))
|
|
13567
13993
|
}, CatalogCopyFromFormatsResultSchema);
|
|
13568
13994
|
});
|
|
13569
|
-
const catalogSchemaGet = catalogHandler(
|
|
13995
|
+
const catalogSchemaGet = catalogHandler(keys, async (params) => {
|
|
13570
13996
|
const cat = getCatalog();
|
|
13571
13997
|
const info = await cat.schemaGet(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13572
13998
|
return wrapResult({
|
|
13573
13999
|
items: info ? [encodeSchemaInfo(info)] : []
|
|
13574
14000
|
}, CatalogSchemaGetResultSchema);
|
|
13575
14001
|
});
|
|
13576
|
-
const catalogSchemaCreate = catalogHandler(
|
|
14002
|
+
const catalogSchemaCreate = catalogHandler(keys, async (params) => {
|
|
13577
14003
|
if (params.options != null)
|
|
13578
14004
|
throw new MethodNotImplementedError2("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
|
|
13579
14005
|
const cat = getCatalog();
|
|
13580
14006
|
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));
|
|
13581
14007
|
return {};
|
|
13582
14008
|
});
|
|
13583
|
-
const catalogSchemaDrop = catalogHandler(
|
|
14009
|
+
const catalogSchemaDrop = catalogHandler(keys, async (params) => {
|
|
13584
14010
|
const cat = getCatalog();
|
|
13585
14011
|
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);
|
|
13586
14012
|
return {};
|
|
13587
14013
|
});
|
|
13588
|
-
const catalogSchemaContentsTables = catalogHandler(
|
|
14014
|
+
const catalogSchemaContentsTables = catalogHandler(keys, async (params) => {
|
|
13589
14015
|
const cat = getCatalog();
|
|
13590
14016
|
const tables = await cat.schemaContentsTables(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13591
14017
|
return wrapResult({
|
|
13592
14018
|
items: tables.map((t) => encodeValidatedTableInfo(t))
|
|
13593
14019
|
}, CatalogSchemaContentsTablesResultSchema);
|
|
13594
14020
|
});
|
|
13595
|
-
const catalogSchemaContentsViews = catalogHandler(
|
|
14021
|
+
const catalogSchemaContentsViews = catalogHandler(keys, async (params) => {
|
|
13596
14022
|
const cat = getCatalog();
|
|
13597
14023
|
const views = await cat.schemaContentsViews(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13598
14024
|
return wrapResult({
|
|
13599
14025
|
items: views.map((v) => encodeViewInfo(v))
|
|
13600
14026
|
}, CatalogSchemaContentsViewsResultSchema);
|
|
13601
14027
|
});
|
|
13602
|
-
const catalogSchemaContentsFunctions = catalogHandler(
|
|
14028
|
+
const catalogSchemaContentsFunctions = catalogHandler(keys, async (params) => {
|
|
13603
14029
|
const cat = getCatalog();
|
|
13604
14030
|
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);
|
|
13605
14031
|
return wrapResult({
|
|
@@ -13677,15 +14103,16 @@ function requireFlatColumnPath(value, operation) {
|
|
|
13677
14103
|
}
|
|
13678
14104
|
return path;
|
|
13679
14105
|
}
|
|
13680
|
-
function catalogTableHandlers(getCatalog, signingKey) {
|
|
13681
|
-
const
|
|
14106
|
+
function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
14107
|
+
const keys = { signingKey, attachSecretKey };
|
|
14108
|
+
const catalogTableGet = catalogHandler(keys, async (params) => {
|
|
13682
14109
|
const cat = getCatalog();
|
|
13683
14110
|
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);
|
|
13684
14111
|
return wrapResult({
|
|
13685
14112
|
items: info ? [encodeValidatedTableInfo(info)] : []
|
|
13686
14113
|
}, CatalogTableGetResultSchema);
|
|
13687
14114
|
});
|
|
13688
|
-
const catalogTableCreate = catalogHandler(
|
|
14115
|
+
const catalogTableCreate = catalogHandler(keys, async (params) => {
|
|
13689
14116
|
if (params.constraint_definitions == null)
|
|
13690
14117
|
throw new Error("constraint_definitions is required");
|
|
13691
14118
|
const definitions = Array.from(params.constraint_definitions, (d) => toUint8Array(d));
|
|
@@ -13706,7 +14133,7 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
13706
14133
|
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);
|
|
13707
14134
|
return {};
|
|
13708
14135
|
});
|
|
13709
|
-
const catalogTableConstraintsApply = catalogHandler(
|
|
14136
|
+
const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
|
|
13710
14137
|
const attach = toUint8Array(params.attach_opaque_data);
|
|
13711
14138
|
const cat = getCatalog();
|
|
13712
14139
|
const caps = await cat.catalogCapabilities(attach);
|
|
@@ -13739,37 +14166,50 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
13739
14166
|
}
|
|
13740
14167
|
return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) }, CatalogTableConstraintsApplyResultSchema);
|
|
13741
14168
|
});
|
|
13742
|
-
const catalogTableDrop = catalogHandler(
|
|
14169
|
+
const catalogTableDrop = catalogHandler(keys, async (params) => {
|
|
13743
14170
|
const cat = getCatalog();
|
|
13744
14171
|
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);
|
|
13745
14172
|
return {};
|
|
13746
14173
|
});
|
|
13747
|
-
const catalogTableColumnStatisticsGet = catalogHandler(
|
|
14174
|
+
const catalogTableColumnStatisticsGet = catalogHandler(keys, async (params) => {
|
|
13748
14175
|
const cat = getCatalog();
|
|
13749
14176
|
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);
|
|
13750
14177
|
return { result: stats?.bytes ?? null };
|
|
13751
14178
|
});
|
|
13752
|
-
const catalogTableScanFunctionGet = catalogHandler(
|
|
14179
|
+
const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
|
|
13753
14180
|
const cat = getCatalog();
|
|
13754
14181
|
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);
|
|
13755
14182
|
return wrapResult(scanResult, ScanFunctionResultSchema);
|
|
13756
14183
|
});
|
|
13757
|
-
const
|
|
14184
|
+
const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
|
|
14185
|
+
const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
|
|
14186
|
+
const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
|
|
14187
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
14188
|
+
});
|
|
14189
|
+
const catalogTableUpdateFunctionGet = catalogHandler(keys, async (params) => {
|
|
14190
|
+
const result = await getCatalog().tableUpdateFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
14191
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
14192
|
+
});
|
|
14193
|
+
const catalogTableDeleteFunctionGet = catalogHandler(keys, async (params) => {
|
|
14194
|
+
const result = await getCatalog().tableDeleteFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
14195
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
14196
|
+
});
|
|
14197
|
+
const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
|
|
13758
14198
|
const cat = getCatalog();
|
|
13759
14199
|
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);
|
|
13760
14200
|
return wrapResult(branchesResult, ScanBranchesResultSchema);
|
|
13761
14201
|
});
|
|
13762
|
-
const catalogTableCommentSet = catalogHandler(
|
|
14202
|
+
const catalogTableCommentSet = catalogHandler(keys, async (params) => {
|
|
13763
14203
|
const cat = getCatalog();
|
|
13764
14204
|
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);
|
|
13765
14205
|
return {};
|
|
13766
14206
|
});
|
|
13767
|
-
const catalogTableRename = catalogHandler(
|
|
14207
|
+
const catalogTableRename = catalogHandler(keys, async (params) => {
|
|
13768
14208
|
const cat = getCatalog();
|
|
13769
14209
|
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);
|
|
13770
14210
|
return {};
|
|
13771
14211
|
});
|
|
13772
|
-
const catalogTableColumnAdd = catalogHandler(
|
|
14212
|
+
const catalogTableColumnAdd = catalogHandler(keys, async (params) => {
|
|
13773
14213
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
|
|
13774
14214
|
validateColumnMetadataIpc(toUint8Array(params.column_definition));
|
|
13775
14215
|
validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
|
|
@@ -13777,49 +14217,49 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
13777
14217
|
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);
|
|
13778
14218
|
return {};
|
|
13779
14219
|
});
|
|
13780
|
-
const catalogTableColumnDrop = catalogHandler(
|
|
14220
|
+
const catalogTableColumnDrop = catalogHandler(keys, async (params) => {
|
|
13781
14221
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
|
|
13782
14222
|
const cat = getCatalog();
|
|
13783
14223
|
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);
|
|
13784
14224
|
return {};
|
|
13785
14225
|
});
|
|
13786
|
-
const catalogTableColumnRename = catalogHandler(
|
|
14226
|
+
const catalogTableColumnRename = catalogHandler(keys, async (params) => {
|
|
13787
14227
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
|
|
13788
14228
|
const cat = getCatalog();
|
|
13789
14229
|
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);
|
|
13790
14230
|
return {};
|
|
13791
14231
|
});
|
|
13792
|
-
const catalogTableColumnCommentSet = catalogHandler(
|
|
14232
|
+
const catalogTableColumnCommentSet = catalogHandler(keys, async (params) => {
|
|
13793
14233
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
|
|
13794
14234
|
const cat = getCatalog();
|
|
13795
14235
|
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);
|
|
13796
14236
|
return {};
|
|
13797
14237
|
});
|
|
13798
|
-
const catalogTableColumnDefaultSet = catalogHandler(
|
|
14238
|
+
const catalogTableColumnDefaultSet = catalogHandler(keys, async (params) => {
|
|
13799
14239
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
|
|
13800
14240
|
const cat = getCatalog();
|
|
13801
14241
|
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);
|
|
13802
14242
|
return {};
|
|
13803
14243
|
});
|
|
13804
|
-
const catalogTableColumnDefaultDrop = catalogHandler(
|
|
14244
|
+
const catalogTableColumnDefaultDrop = catalogHandler(keys, async (params) => {
|
|
13805
14245
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
|
|
13806
14246
|
const cat = getCatalog();
|
|
13807
14247
|
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);
|
|
13808
14248
|
return {};
|
|
13809
14249
|
});
|
|
13810
|
-
const catalogTableColumnTypeChange = catalogHandler(
|
|
14250
|
+
const catalogTableColumnTypeChange = catalogHandler(keys, async (params) => {
|
|
13811
14251
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
|
|
13812
14252
|
const cat = getCatalog();
|
|
13813
14253
|
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);
|
|
13814
14254
|
return {};
|
|
13815
14255
|
});
|
|
13816
|
-
const catalogTableNotNullSet = catalogHandler(
|
|
14256
|
+
const catalogTableNotNullSet = catalogHandler(keys, async (params) => {
|
|
13817
14257
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
|
|
13818
14258
|
const cat = getCatalog();
|
|
13819
14259
|
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);
|
|
13820
14260
|
return {};
|
|
13821
14261
|
});
|
|
13822
|
-
const catalogTableNotNullDrop = catalogHandler(
|
|
14262
|
+
const catalogTableNotNullDrop = catalogHandler(keys, async (params) => {
|
|
13823
14263
|
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
|
|
13824
14264
|
const cat = getCatalog();
|
|
13825
14265
|
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);
|
|
@@ -13832,6 +14272,9 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
13832
14272
|
catalogTableDrop,
|
|
13833
14273
|
catalogTableColumnStatisticsGet,
|
|
13834
14274
|
catalogTableScanFunctionGet,
|
|
14275
|
+
catalogTableInsertFunctionGet,
|
|
14276
|
+
catalogTableUpdateFunctionGet,
|
|
14277
|
+
catalogTableDeleteFunctionGet,
|
|
13835
14278
|
catalogTableScanBranchesGet,
|
|
13836
14279
|
catalogTableCommentSet,
|
|
13837
14280
|
catalogTableRename,
|
|
@@ -13848,15 +14291,16 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
13848
14291
|
}
|
|
13849
14292
|
|
|
13850
14293
|
// src/protocol/handlers/catalog/view.ts
|
|
13851
|
-
function catalogViewHandlers(getCatalog, signingKey) {
|
|
13852
|
-
const
|
|
14294
|
+
function catalogViewHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
14295
|
+
const keys = { signingKey, attachSecretKey };
|
|
14296
|
+
const catalogViewGet = catalogHandler(keys, async (params) => {
|
|
13853
14297
|
const cat = getCatalog();
|
|
13854
14298
|
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);
|
|
13855
14299
|
return wrapResult({
|
|
13856
14300
|
items: info ? [encodeViewInfo(info)] : []
|
|
13857
14301
|
}, CatalogViewGetResultSchema);
|
|
13858
14302
|
});
|
|
13859
|
-
const catalogViewCreate = catalogHandler(
|
|
14303
|
+
const catalogViewCreate = catalogHandler(keys, async (params) => {
|
|
13860
14304
|
if (params.security !== "regular")
|
|
13861
14305
|
throw new Error(`view security mode ${params.security} is unsupported`);
|
|
13862
14306
|
const tags = catalogStringMap(params.tags);
|
|
@@ -13867,22 +14311,22 @@ function catalogViewHandlers(getCatalog, signingKey) {
|
|
|
13867
14311
|
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);
|
|
13868
14312
|
return {};
|
|
13869
14313
|
});
|
|
13870
|
-
const catalogViewDrop = catalogHandler(
|
|
14314
|
+
const catalogViewDrop = catalogHandler(keys, async (params) => {
|
|
13871
14315
|
const cat = getCatalog();
|
|
13872
14316
|
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);
|
|
13873
14317
|
return {};
|
|
13874
14318
|
});
|
|
13875
|
-
const catalogViewRename = catalogHandler(
|
|
14319
|
+
const catalogViewRename = catalogHandler(keys, async (params) => {
|
|
13876
14320
|
const cat = getCatalog();
|
|
13877
14321
|
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);
|
|
13878
14322
|
return {};
|
|
13879
14323
|
});
|
|
13880
|
-
const catalogViewCommentSet = catalogHandler(
|
|
14324
|
+
const catalogViewCommentSet = catalogHandler(keys, async (params) => {
|
|
13881
14325
|
const cat = getCatalog();
|
|
13882
14326
|
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);
|
|
13883
14327
|
return {};
|
|
13884
14328
|
});
|
|
13885
|
-
const catalogViewColumnCommentSet = catalogHandler(
|
|
14329
|
+
const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
|
|
13886
14330
|
const path = Array.from(params.column_path);
|
|
13887
14331
|
if (path.length !== 1 || !path[0] || path[0].includes("\x00"))
|
|
13888
14332
|
throw new Error("view column comments require one raw output identifier");
|
|
@@ -13893,15 +14337,16 @@ function catalogViewHandlers(getCatalog, signingKey) {
|
|
|
13893
14337
|
}
|
|
13894
14338
|
|
|
13895
14339
|
// src/protocol/handlers/catalog/macro.ts
|
|
13896
|
-
function catalogMacroHandlers(getCatalog, signingKey) {
|
|
13897
|
-
const
|
|
14340
|
+
function catalogMacroHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
14341
|
+
const keys = { signingKey, attachSecretKey };
|
|
14342
|
+
const catalogMacroGet = catalogHandler(keys, async (params) => {
|
|
13898
14343
|
const cat = getCatalog();
|
|
13899
14344
|
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);
|
|
13900
14345
|
return wrapResult({
|
|
13901
14346
|
items: info ? [encodeMacroInfo(info)] : []
|
|
13902
14347
|
}, CatalogMacroGetResultSchema);
|
|
13903
14348
|
});
|
|
13904
|
-
const catalogMacroCreate = catalogHandler(
|
|
14349
|
+
const catalogMacroCreate = catalogHandler(keys, async (params) => {
|
|
13905
14350
|
const cat = getCatalog();
|
|
13906
14351
|
const innerParams = decodeASD(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
|
|
13907
14352
|
if (!innerParams.overloads?.length)
|
|
@@ -13909,12 +14354,12 @@ function catalogMacroHandlers(getCatalog, signingKey) {
|
|
|
13909
14354
|
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);
|
|
13910
14355
|
return {};
|
|
13911
14356
|
});
|
|
13912
|
-
const catalogMacroDrop = catalogHandler(
|
|
14357
|
+
const catalogMacroDrop = catalogHandler(keys, async (params) => {
|
|
13913
14358
|
const cat = getCatalog();
|
|
13914
14359
|
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);
|
|
13915
14360
|
return {};
|
|
13916
14361
|
});
|
|
13917
|
-
const catalogSchemaContentsMacros = catalogHandler(
|
|
14362
|
+
const catalogSchemaContentsMacros = catalogHandler(keys, async (params) => {
|
|
13918
14363
|
const cat = getCatalog();
|
|
13919
14364
|
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);
|
|
13920
14365
|
return wrapResult({
|
|
@@ -13925,15 +14370,16 @@ function catalogMacroHandlers(getCatalog, signingKey) {
|
|
|
13925
14370
|
}
|
|
13926
14371
|
|
|
13927
14372
|
// src/protocol/handlers/catalog/index_methods.ts
|
|
13928
|
-
function catalogIndexHandlers(getCatalog, signingKey) {
|
|
13929
|
-
const
|
|
14373
|
+
function catalogIndexHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
14374
|
+
const keys = { signingKey, attachSecretKey };
|
|
14375
|
+
const catalogSchemaContentsIndexes = catalogHandler(keys, async (params) => {
|
|
13930
14376
|
const cat = getCatalog();
|
|
13931
14377
|
const indexes = await cat.schemaContentsIndexes(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
13932
14378
|
return wrapResult({
|
|
13933
14379
|
items: indexes.map((i) => encodeIndexInfo(i))
|
|
13934
14380
|
}, CatalogSchemaContentsIndexesResultSchema);
|
|
13935
14381
|
});
|
|
13936
|
-
const catalogIndexGet = catalogHandler(
|
|
14382
|
+
const catalogIndexGet = catalogHandler(keys, async (params) => {
|
|
13937
14383
|
const cat = getCatalog();
|
|
13938
14384
|
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);
|
|
13939
14385
|
return wrapResult({
|
|
@@ -13944,14 +14390,14 @@ function catalogIndexHandlers(getCatalog, signingKey) {
|
|
|
13944
14390
|
}
|
|
13945
14391
|
|
|
13946
14392
|
// src/protocol/handlers/catalog/index.ts
|
|
13947
|
-
function catalogHandlers(catalog, signingKey) {
|
|
14393
|
+
function catalogHandlers(catalog, signingKey, attachSecretKey) {
|
|
13948
14394
|
const getCatalog = makeGetCatalog(catalog);
|
|
13949
14395
|
return {
|
|
13950
|
-
...catalogAdminHandlers(getCatalog, signingKey),
|
|
13951
|
-
...catalogTableHandlers(getCatalog, signingKey),
|
|
13952
|
-
...catalogViewHandlers(getCatalog, signingKey),
|
|
13953
|
-
...catalogMacroHandlers(getCatalog, signingKey),
|
|
13954
|
-
...catalogIndexHandlers(getCatalog, signingKey)
|
|
14396
|
+
...catalogAdminHandlers(getCatalog, signingKey, attachSecretKey),
|
|
14397
|
+
...catalogTableHandlers(getCatalog, signingKey, attachSecretKey),
|
|
14398
|
+
...catalogViewHandlers(getCatalog, signingKey, attachSecretKey),
|
|
14399
|
+
...catalogMacroHandlers(getCatalog, signingKey, attachSecretKey),
|
|
14400
|
+
...catalogIndexHandlers(getCatalog, signingKey, attachSecretKey)
|
|
13955
14401
|
};
|
|
13956
14402
|
}
|
|
13957
14403
|
|
|
@@ -13962,11 +14408,12 @@ function buildVgiService(config) {
|
|
|
13962
14408
|
...functionHandlers({
|
|
13963
14409
|
registry: config.registry,
|
|
13964
14410
|
signingKey: config.signingKey,
|
|
14411
|
+
attachSecretKey: config.attachSecretKey,
|
|
13965
14412
|
catalogInterface: config.catalogInterface
|
|
13966
14413
|
}),
|
|
13967
14414
|
...aggregateHandlers(config.registry),
|
|
13968
|
-
...tableBufferingHandlers(config.registry, config.signingKey),
|
|
13969
|
-
...catalogHandlers(config.catalogInterface, config.signingKey)
|
|
14415
|
+
...tableBufferingHandlers(config.registry, config.signingKey, config.attachSecretKey),
|
|
14416
|
+
...catalogHandlers(config.catalogInterface, config.signingKey, config.attachSecretKey)
|
|
13970
14417
|
};
|
|
13971
14418
|
}
|
|
13972
14419
|
function buildVgiProtocol(config) {
|
|
@@ -14326,6 +14773,24 @@ function cacheControlMetadata(cc, extra) {
|
|
|
14326
14773
|
md.set(CACHE_PER_VALUE_KEY, "1");
|
|
14327
14774
|
return md;
|
|
14328
14775
|
}
|
|
14776
|
+
// src/write-results.ts
|
|
14777
|
+
var WRITE_OPERATIONS = ["insert", "update", "delete"];
|
|
14778
|
+
var MODE_RANK = { count: 0, rows: 1, changes: 2 };
|
|
14779
|
+
function validateWriteResultModes(modes) {
|
|
14780
|
+
const out = {};
|
|
14781
|
+
const unknown = Object.keys(modes).filter((op) => !WRITE_OPERATIONS.includes(op)).sort();
|
|
14782
|
+
if (unknown.length)
|
|
14783
|
+
throw new Error(`Unknown write operation(s): ${unknown.join(", ")}`);
|
|
14784
|
+
for (const [operation, mode] of Object.entries(modes)) {
|
|
14785
|
+
if (mode === undefined)
|
|
14786
|
+
continue;
|
|
14787
|
+
if (!(mode in MODE_RANK))
|
|
14788
|
+
throw new Error(`Unknown write result mode '${mode}' for '${operation}'`);
|
|
14789
|
+
out[operation] = mode;
|
|
14790
|
+
}
|
|
14791
|
+
return out;
|
|
14792
|
+
}
|
|
14793
|
+
|
|
14329
14794
|
// src/functions/scalar.ts
|
|
14330
14795
|
init_arrow();
|
|
14331
14796
|
function defineScalarFunction(config) {
|
|
@@ -15526,6 +15991,9 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
15526
15991
|
this._registry = registry;
|
|
15527
15992
|
if (options.perAttachItemIds)
|
|
15528
15993
|
this.perAttachItemIds = true;
|
|
15994
|
+
for (const sch of descriptor.schemas ?? [])
|
|
15995
|
+
for (const tbl of sch.tables ?? [])
|
|
15996
|
+
validateWritableTable(tbl);
|
|
15529
15997
|
for (const sch of descriptor.schemas ?? []) {
|
|
15530
15998
|
for (const fn of sch.functions ?? [])
|
|
15531
15999
|
registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
|
|
@@ -15574,8 +16042,9 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
15574
16042
|
const settings = (this._descriptor.settings ?? []).map((s) => serializeSetting(s));
|
|
15575
16043
|
const secretTypes = (this._descriptor.secretTypes ?? []).map((s) => serializeSecretType(s));
|
|
15576
16044
|
const attachCatalogs = (this._descriptor.attachCatalogs ?? []).map((c) => encodeAttachCatalogInfo(c));
|
|
15577
|
-
const available = this.catalogReadProfiles();
|
|
15578
|
-
const
|
|
16045
|
+
const available = catalogCapabilities({ read: this.catalogReadProfiles(), write: this.catalogWriteProfiles() });
|
|
16046
|
+
const advertised = available.read.length + available.write.length > 0;
|
|
16047
|
+
const selected = selectCatalogCapabilities(available, clientCapabilities);
|
|
15579
16048
|
const hasTimeTravel = this._descriptor.schemas.some((s) => s.tables?.some((t) => t.supportsTimeTravel) ?? false);
|
|
15580
16049
|
return buildCatalogAttachResult({
|
|
15581
16050
|
attach_opaque_data: attachOpaqueData,
|
|
@@ -15596,17 +16065,21 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
15596
16065
|
resolved_data_version: null,
|
|
15597
16066
|
resolved_implementation_version: null,
|
|
15598
16067
|
supports_catalog_contents: this.supportsCatalogContents,
|
|
15599
|
-
catalog_capabilities:
|
|
15600
|
-
selected_capabilities:
|
|
16068
|
+
catalog_capabilities: advertised ? encodeCatalogCapabilities(available) : null,
|
|
16069
|
+
selected_capabilities: advertised ? encodeCatalogCapabilities(selected) : null
|
|
15601
16070
|
});
|
|
15602
16071
|
}
|
|
15603
16072
|
catalogReadProfiles() {
|
|
15604
16073
|
const hasConstraints = this._descriptor.schemas.some((s) => s.tables?.some((t) => (t.constraints?.length ?? 0) > 0) ?? false);
|
|
15605
16074
|
return hasConstraints ? [CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION] : [];
|
|
15606
16075
|
}
|
|
16076
|
+
catalogWriteProfiles() {
|
|
16077
|
+
const writableConstrained = this._descriptor.schemas.some((s) => s.tables?.some((t) => (t.constraints?.length ?? 0) > 0 && (t.insertFunction || t.updateFunction || t.deleteFunction)) ?? false);
|
|
16078
|
+
return writableConstrained ? [CONSTRAINT_ENFORCE] : [];
|
|
16079
|
+
}
|
|
15607
16080
|
catalogCapabilities(_attachOpaqueData) {
|
|
15608
|
-
const
|
|
15609
|
-
return read.length
|
|
16081
|
+
const caps = catalogCapabilities({ read: this.catalogReadProfiles(), write: this.catalogWriteProfiles() });
|
|
16082
|
+
return caps.read.length + caps.write.length ? caps : null;
|
|
15610
16083
|
}
|
|
15611
16084
|
detach(attachOpaqueData) {
|
|
15612
16085
|
for (const [name, id] of this._attachments) {
|
|
@@ -15757,12 +16230,12 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
15757
16230
|
columns,
|
|
15758
16231
|
constraints: [...constraints],
|
|
15759
16232
|
definition_revision: t.definitionRevision ?? null,
|
|
15760
|
-
write_result_modes:
|
|
16233
|
+
write_result_modes: writeResultModesFor(t),
|
|
15761
16234
|
supports_column_statistics: t.statistics != null && Object.keys(t.statistics).length > 0,
|
|
15762
16235
|
scan_function: t.function && !t.columns ? inlineScanFunction(t.function, t.arguments, this._schemaForFunction(t.function)) : null,
|
|
15763
|
-
insert_function: null,
|
|
15764
|
-
update_function: null,
|
|
15765
|
-
delete_function: null,
|
|
16236
|
+
insert_function: t.insertFunction ? inlineScanFunction(t.insertFunction, undefined, this._schemaForFunction(t.insertFunction)) : null,
|
|
16237
|
+
update_function: t.updateFunction ? inlineScanFunction(t.updateFunction, undefined, this._schemaForFunction(t.updateFunction)) : null,
|
|
16238
|
+
delete_function: t.deleteFunction ? inlineScanFunction(t.deleteFunction, undefined, this._schemaForFunction(t.deleteFunction)) : null,
|
|
15766
16239
|
cardinality_estimate: t.inlinedCardinality ? Number(t.inlinedCardinality.estimate) : null,
|
|
15767
16240
|
cardinality_max: t.inlinedCardinality ? Number(t.inlinedCardinality.max) : null,
|
|
15768
16241
|
required_filters: requiredFilters
|
|
@@ -16024,6 +16497,32 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
16024
16497
|
}
|
|
16025
16498
|
throw new Error(`Table '${name}' is not function-backed`);
|
|
16026
16499
|
}
|
|
16500
|
+
_writeFunctionGet(schemaPath, name, operation) {
|
|
16501
|
+
const schema = this._descriptor.schemas.find((sch) => schemaPathsEqual(schemaDescriptorPath(sch), schemaPath));
|
|
16502
|
+
const table = schema?.tables?.find((t) => t.name.toLowerCase() === name.toLowerCase());
|
|
16503
|
+
if (!table) {
|
|
16504
|
+
throw new VgiError(`Table '${name}' not found in schema ${schemaPathDisplay(schemaPath)}`, "NOT_FOUND");
|
|
16505
|
+
}
|
|
16506
|
+
const fn = writeFunctionOf(table, operation);
|
|
16507
|
+
if (!fn) {
|
|
16508
|
+
throw new CatalogReadOnlyError(`Table ${schemaPathDisplay(schemaPath)}.${table.name} does not support ${operation.toUpperCase()}`);
|
|
16509
|
+
}
|
|
16510
|
+
return {
|
|
16511
|
+
function_name: fn.meta.name,
|
|
16512
|
+
arguments: serializeArgsBatch(new Arguments, argumentSpecsToSchema(fn.argumentSpecs)),
|
|
16513
|
+
required_extensions: [],
|
|
16514
|
+
schema_path: this._schemaForFunction(fn)
|
|
16515
|
+
};
|
|
16516
|
+
}
|
|
16517
|
+
tableInsertFunctionGet(_attachOpaqueData, schemaPath, name, _transactionOpaqueData, _writableBranchFunctionName) {
|
|
16518
|
+
return this._writeFunctionGet(schemaPath, name, "insert");
|
|
16519
|
+
}
|
|
16520
|
+
tableUpdateFunctionGet(_attachOpaqueData, schemaPath, name, _transactionOpaqueData) {
|
|
16521
|
+
return this._writeFunctionGet(schemaPath, name, "update");
|
|
16522
|
+
}
|
|
16523
|
+
tableDeleteFunctionGet(_attachOpaqueData, schemaPath, name, _transactionOpaqueData) {
|
|
16524
|
+
return this._writeFunctionGet(schemaPath, name, "delete");
|
|
16525
|
+
}
|
|
16027
16526
|
async tableGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
|
|
16028
16527
|
validateAtParams(atUnit, atValue);
|
|
16029
16528
|
const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), schemaPath));
|
|
@@ -16269,6 +16768,28 @@ function sameSpelling(left, right) {
|
|
|
16269
16768
|
const b = normalizeSchemaPath(right);
|
|
16270
16769
|
return a.length === b.length && a.every((part, i) => part === b[i]);
|
|
16271
16770
|
}
|
|
16771
|
+
function writeFunctionOf(table, operation) {
|
|
16772
|
+
return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
|
|
16773
|
+
}
|
|
16774
|
+
function validateWritableTable(table) {
|
|
16775
|
+
const modes = validateWriteResultModes(table.writeResultModes ?? {});
|
|
16776
|
+
for (const operation of Object.keys(modes)) {
|
|
16777
|
+
if (!writeFunctionOf(table, operation)) {
|
|
16778
|
+
throw new Error(`Table '${table.name}': writeResultModes declares '${operation}' without a corresponding ${operation}Function`);
|
|
16779
|
+
}
|
|
16780
|
+
}
|
|
16781
|
+
if ((table.updateFunction || table.deleteFunction) && !table.function) {
|
|
16782
|
+
throw new Error(`Table '${table.name}': updateFunction and deleteFunction require a scan function (set 'function') to provide row ids`);
|
|
16783
|
+
}
|
|
16784
|
+
}
|
|
16785
|
+
function writeResultModesFor(table) {
|
|
16786
|
+
const out = {};
|
|
16787
|
+
for (const operation of WRITE_OPERATIONS) {
|
|
16788
|
+
if (writeFunctionOf(table, operation))
|
|
16789
|
+
out[operation] = table.writeResultModes?.[operation] ?? "count";
|
|
16790
|
+
}
|
|
16791
|
+
return out;
|
|
16792
|
+
}
|
|
16272
16793
|
// src/catalog/indexes.ts
|
|
16273
16794
|
var NO_OPTIONS_B64 = "/////zgAAAAQAAAAAAAKABAADgAHAAgACgAAAAAAAAEQAAAAAAAEAAgACAAAAAQACAAAAAQAAAAAAAAAAAAAAP////9QAAAAFAAAAAAAAAAAAAoADgAMAAcACAAKAAAAAAAAAxAAAAAEAAoAGAAMAAgABAAKAAAAFAAAABgAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////AAAAAA==";
|
|
16274
16795
|
function emptyIndexOptions() {
|
|
@@ -17043,4 +17564,4 @@ export {
|
|
|
17043
17564
|
validateTableConstraints
|
|
17044
17565
|
};
|
|
17045
17566
|
|
|
17046
|
-
//# debugId=
|
|
17567
|
+
//# debugId=1A848F9DA6F0C91464756E2164756E21
|