@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/src/catalog/read-only.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type MacroInfo,
|
|
18
18
|
type IndexInfo,
|
|
19
19
|
type CopyFromFormatInfo,
|
|
20
|
+
type ScanFunctionResultRecord,
|
|
20
21
|
encodeAttachCatalogInfo,
|
|
21
22
|
encodeScanFunctionResult,
|
|
22
23
|
buildCatalogAttachResult,
|
|
@@ -34,11 +35,12 @@ import { Arguments } from "../arguments/arguments.js";
|
|
|
34
35
|
import { normalizeSchemaPath, schemaPathDisplay, schemaPathsEqual } from "../schema-path.js";
|
|
35
36
|
import { ForeignKeyInfoSchema } from "../generated/vgi-protocol-schemas.js";
|
|
36
37
|
import { conformColumns } from "../codec/conform.js";
|
|
37
|
-
import { VgiError } from "../errors.js";
|
|
38
|
+
import { CatalogReadOnlyError, VgiError } from "../errors.js";
|
|
38
39
|
import { encodeFunctionInfoOnce, freezeCatalogItem } from "./item-encoding.js";
|
|
39
40
|
import { macroOverloads } from "./macro-overloads.js";
|
|
40
|
-
import { CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, catalogCapabilities,
|
|
41
|
+
import { CONSTRAINT_ENFORCE, CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, catalogCapabilities, selectCatalogCapabilities, servedTableSchema, validateForeignKeyTargets } from "./constraints.js";
|
|
41
42
|
import { duckdbPrimitive } from "./column-types.js";
|
|
43
|
+
import { WRITE_OPERATIONS, type WriteOperation, validateWriteResultModes } from "../write-results.js";
|
|
42
44
|
import { defaultExpressionMetadata } from "./column-expressions.js";
|
|
43
45
|
import type { CatalogCapabilities } from "../generated/vgi-protocol-types.js";
|
|
44
46
|
import { encodeCatalogCapabilities } from "../generated/vgi-protocol-types.js";
|
|
@@ -114,6 +116,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
114
116
|
this._descriptor = descriptor;
|
|
115
117
|
this._registry = registry;
|
|
116
118
|
if (options.perAttachItemIds) this.perAttachItemIds = true;
|
|
119
|
+
for (const sch of descriptor.schemas ?? []) for (const tbl of sch.tables ?? []) validateWritableTable(tbl);
|
|
117
120
|
// Index every function this catalog declares by its owning schema, so a
|
|
118
121
|
// schema-qualified bind resolves to the right implementation when one name
|
|
119
122
|
// is declared in more than one schema. Table-backing functions are indexed
|
|
@@ -222,9 +225,11 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
222
225
|
encodeAttachCatalogInfo(c)
|
|
223
226
|
);
|
|
224
227
|
|
|
225
|
-
// Constraint records are readable
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
+
// Constraint records are readable, and writes to constrained tables
|
|
229
|
+
// accepted, only under negotiated profiles.
|
|
230
|
+
const available = catalogCapabilities({ read: this.catalogReadProfiles(), write: this.catalogWriteProfiles() });
|
|
231
|
+
const advertised = available.read.length + available.write.length > 0;
|
|
232
|
+
const selected = selectCatalogCapabilities(available, clientCapabilities);
|
|
228
233
|
|
|
229
234
|
// Auto-derive supportsTimeTravel from table descriptors
|
|
230
235
|
const hasTimeTravel = this._descriptor.schemas.some(
|
|
@@ -257,12 +262,8 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
257
262
|
// Static, version-frozen catalog: the whole thing can be served in one
|
|
258
263
|
// catalog_contents call (as vgi-python's ReadOnlyCatalogInterface does).
|
|
259
264
|
supports_catalog_contents: this.supportsCatalogContents,
|
|
260
|
-
catalog_capabilities: available
|
|
261
|
-
|
|
262
|
-
: null,
|
|
263
|
-
selected_capabilities: available.length
|
|
264
|
-
? encodeCatalogCapabilities({ read, ddl: [], write: [], transaction: [] })
|
|
265
|
-
: null,
|
|
265
|
+
catalog_capabilities: advertised ? encodeCatalogCapabilities(available) : null,
|
|
266
|
+
selected_capabilities: advertised ? encodeCatalogCapabilities(selected) : null,
|
|
266
267
|
});
|
|
267
268
|
}
|
|
268
269
|
|
|
@@ -278,10 +279,28 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
278
279
|
return hasConstraints ? [CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION] : [];
|
|
279
280
|
}
|
|
280
281
|
|
|
281
|
-
/**
|
|
282
|
+
/**
|
|
283
|
+
* Write profiles this catalog implements. A table that carries constraint
|
|
284
|
+
* records AND has a write function makes the catalog advertise
|
|
285
|
+
* `vgi.constraint.enforce.v1`: DuckDB only writes to a constrained table
|
|
286
|
+
* when the provider promises to keep its ENFORCED constraints, so such a
|
|
287
|
+
* table's write functions must reject rows that would violate them (for
|
|
288
|
+
* instance by refusing to change key columns).
|
|
289
|
+
*/
|
|
290
|
+
catalogWriteProfiles(): string[] {
|
|
291
|
+
const writableConstrained = this._descriptor.schemas.some(
|
|
292
|
+
(s) =>
|
|
293
|
+
s.tables?.some(
|
|
294
|
+
(t) => (t.constraints?.length ?? 0) > 0 && (t.insertFunction || t.updateFunction || t.deleteFunction),
|
|
295
|
+
) ?? false,
|
|
296
|
+
);
|
|
297
|
+
return writableConstrained ? [CONSTRAINT_ENFORCE] : [];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The descriptor's profiles: records are served, never mutated here; writable constrained tables enforce. */
|
|
282
301
|
override catalogCapabilities(_attachOpaqueData: AttachOpaqueData): CatalogCapabilities | null {
|
|
283
|
-
const
|
|
284
|
-
return read.length
|
|
302
|
+
const caps = catalogCapabilities({ read: this.catalogReadProfiles(), write: this.catalogWriteProfiles() });
|
|
303
|
+
return caps.read.length + caps.write.length ? caps : null;
|
|
285
304
|
}
|
|
286
305
|
|
|
287
306
|
detach(attachOpaqueData: AttachOpaqueData): void {
|
|
@@ -473,7 +492,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
473
492
|
columns,
|
|
474
493
|
constraints: [...constraints],
|
|
475
494
|
definition_revision: t.definitionRevision ?? null,
|
|
476
|
-
write_result_modes:
|
|
495
|
+
write_result_modes: writeResultModesFor(t),
|
|
477
496
|
supports_column_statistics: t.statistics != null && Object.keys(t.statistics).length > 0,
|
|
478
497
|
// Inline scan_function only for purely function-backed tables.
|
|
479
498
|
// When explicit `columns` are also declared, the table is on the
|
|
@@ -483,9 +502,13 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
483
502
|
scan_function: t.function && !t.columns
|
|
484
503
|
? inlineScanFunction(t.function, t.arguments, this._schemaForFunction(t.function))
|
|
485
504
|
: null,
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
505
|
+
// Write functions are inlined like a purely function-backed scan:
|
|
506
|
+
// they take no catalog-supplied arguments (DuckDB passes the rows and
|
|
507
|
+
// `write_options`), so the extension can skip the per-statement
|
|
508
|
+
// catalog_table_{insert,update,delete}_function_get round trip.
|
|
509
|
+
insert_function: t.insertFunction ? inlineScanFunction(t.insertFunction, undefined, this._schemaForFunction(t.insertFunction)) : null,
|
|
510
|
+
update_function: t.updateFunction ? inlineScanFunction(t.updateFunction, undefined, this._schemaForFunction(t.updateFunction)) : null,
|
|
511
|
+
delete_function: t.deleteFunction ? inlineScanFunction(t.deleteFunction, undefined, this._schemaForFunction(t.deleteFunction)) : null,
|
|
489
512
|
cardinality_estimate: t.inlinedCardinality
|
|
490
513
|
? Number(t.inlinedCardinality.estimate)
|
|
491
514
|
: null,
|
|
@@ -913,6 +936,56 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
913
936
|
throw new Error(`Table '${name}' is not function-backed`);
|
|
914
937
|
}
|
|
915
938
|
|
|
939
|
+
/** The write function for `operation`, or a read-only / not-found error. */
|
|
940
|
+
private _writeFunctionGet(schemaPath: string[], name: string, operation: WriteOperation): ScanFunctionResultRecord {
|
|
941
|
+
const schema = this._descriptor.schemas.find((sch) => schemaPathsEqual(schemaDescriptorPath(sch), schemaPath));
|
|
942
|
+
const table = schema?.tables?.find((t) => t.name.toLowerCase() === name.toLowerCase());
|
|
943
|
+
if (!table) {
|
|
944
|
+
throw new VgiError(`Table '${name}' not found in schema ${schemaPathDisplay(schemaPath)}`, "NOT_FOUND");
|
|
945
|
+
}
|
|
946
|
+
const fn = writeFunctionOf(table, operation);
|
|
947
|
+
if (!fn) {
|
|
948
|
+
throw new CatalogReadOnlyError(
|
|
949
|
+
`Table ${schemaPathDisplay(schemaPath)}.${table.name} does not support ${operation.toUpperCase()}`,
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
function_name: fn.meta.name,
|
|
954
|
+
arguments: serializeArgsBatch(new Arguments(), argumentSpecsToSchema(fn.argumentSpecs)),
|
|
955
|
+
required_extensions: [],
|
|
956
|
+
schema_path: this._schemaForFunction(fn),
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
override tableInsertFunctionGet(
|
|
961
|
+
_attachOpaqueData: AttachOpaqueData,
|
|
962
|
+
schemaPath: string[],
|
|
963
|
+
name: string,
|
|
964
|
+
_transactionOpaqueData?: TransactionOpaqueData,
|
|
965
|
+
// Descriptor tables are single-branch: the writable-arm hint does not apply.
|
|
966
|
+
_writableBranchFunctionName?: string | null,
|
|
967
|
+
): ScanFunctionResultRecord {
|
|
968
|
+
return this._writeFunctionGet(schemaPath, name, "insert");
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
override tableUpdateFunctionGet(
|
|
972
|
+
_attachOpaqueData: AttachOpaqueData,
|
|
973
|
+
schemaPath: string[],
|
|
974
|
+
name: string,
|
|
975
|
+
_transactionOpaqueData?: TransactionOpaqueData,
|
|
976
|
+
): ScanFunctionResultRecord {
|
|
977
|
+
return this._writeFunctionGet(schemaPath, name, "update");
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
override tableDeleteFunctionGet(
|
|
981
|
+
_attachOpaqueData: AttachOpaqueData,
|
|
982
|
+
schemaPath: string[],
|
|
983
|
+
name: string,
|
|
984
|
+
_transactionOpaqueData?: TransactionOpaqueData,
|
|
985
|
+
): ScanFunctionResultRecord {
|
|
986
|
+
return this._writeFunctionGet(schemaPath, name, "delete");
|
|
987
|
+
}
|
|
988
|
+
|
|
916
989
|
override async tableGet(
|
|
917
990
|
attachOpaqueData: AttachOpaqueData,
|
|
918
991
|
schemaPath: string[],
|
|
@@ -1288,3 +1361,35 @@ function sameSpelling(left: Iterable<unknown> | string, right: Iterable<unknown>
|
|
|
1288
1361
|
const b = normalizeSchemaPath(right);
|
|
1289
1362
|
return a.length === b.length && a.every((part, i) => part === b[i]);
|
|
1290
1363
|
}
|
|
1364
|
+
|
|
1365
|
+
// ---------------------------------------------------------------- writable tables
|
|
1366
|
+
|
|
1367
|
+
function writeFunctionOf(table: TableDescriptor, operation: WriteOperation): VgiFunction | undefined {
|
|
1368
|
+
return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Reject a writable-table declaration vgi-python's `Table.__post_init__` would:
|
|
1373
|
+
* an unknown operation or mode, a mode for an operation with no function, or
|
|
1374
|
+
* UPDATE/DELETE without a scan function to supply row ids.
|
|
1375
|
+
*/
|
|
1376
|
+
function validateWritableTable(table: TableDescriptor): void {
|
|
1377
|
+
const modes = validateWriteResultModes((table.writeResultModes ?? {}) as Record<string, string>);
|
|
1378
|
+
for (const operation of Object.keys(modes) as WriteOperation[]) {
|
|
1379
|
+
if (!writeFunctionOf(table, operation)) {
|
|
1380
|
+
throw new Error(`Table '${table.name}': writeResultModes declares '${operation}' without a corresponding ${operation}Function`);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if ((table.updateFunction || table.deleteFunction) && !table.function) {
|
|
1384
|
+
throw new Error(`Table '${table.name}': updateFunction and deleteFunction require a scan function (set 'function') to provide row ids`);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/** TableInfo.write_result_modes: each configured operation's maximum mode (default `count`). */
|
|
1389
|
+
function writeResultModesFor(table: TableDescriptor): Record<string, string> {
|
|
1390
|
+
const out: Record<string, string> = {};
|
|
1391
|
+
for (const operation of WRITE_OPERATIONS) {
|
|
1392
|
+
if (writeFunctionOf(table, operation)) out[operation] = table.writeResultModes?.[operation] ?? "count";
|
|
1393
|
+
}
|
|
1394
|
+
return out;
|
|
1395
|
+
}
|
package/src/index.core.ts
CHANGED
|
@@ -30,6 +30,29 @@ export {
|
|
|
30
30
|
type CacheScope,
|
|
31
31
|
} from "./cache-control.js";
|
|
32
32
|
|
|
33
|
+
// Writable tables: result modes, row ids and the write_options decoder for
|
|
34
|
+
// INSERT / UPDATE / DELETE functions (TableDescriptor.insertFunction etc.).
|
|
35
|
+
export {
|
|
36
|
+
type WriteOperation,
|
|
37
|
+
type WriteResultMode,
|
|
38
|
+
type WriteOptions,
|
|
39
|
+
WRITE_OPERATIONS,
|
|
40
|
+
WRITE_RESULT_MODES,
|
|
41
|
+
ROW_ID_METADATA_KEY,
|
|
42
|
+
rowIdField,
|
|
43
|
+
userColumns,
|
|
44
|
+
validateWriteResultModes,
|
|
45
|
+
supportsWriteResultMode,
|
|
46
|
+
coerceWriteResultMode,
|
|
47
|
+
writeResultSchema,
|
|
48
|
+
writeCountBatch,
|
|
49
|
+
writeRowsBatch,
|
|
50
|
+
writeChangesBatch,
|
|
51
|
+
writeResultBatch,
|
|
52
|
+
writeOptions,
|
|
53
|
+
} from "./write-results.js";
|
|
54
|
+
export type { ScanFunctionResultRecord } from "./catalog/interface.js";
|
|
55
|
+
|
|
33
56
|
// Function factories (primary API)
|
|
34
57
|
export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarComputeInfo, type ScalarParameterDef } from "./functions/scalar.js";
|
|
35
58
|
export { defineTableFunction, type TableFunctionConfig, type TableBindParams, type TableProcessParams } from "./functions/table.js";
|
|
@@ -216,6 +239,16 @@ export {
|
|
|
216
239
|
RESERVED_ATTACH_OPTION,
|
|
217
240
|
ReservedAttachOptionError,
|
|
218
241
|
} from "./catalog/attach-option.js";
|
|
242
|
+
// ATTACH options (secret ones included) as functions and transaction hooks see them.
|
|
243
|
+
export {
|
|
244
|
+
attachOptions,
|
|
245
|
+
attachOption,
|
|
246
|
+
type AttachOptionValues,
|
|
247
|
+
AttachOptionsUnavailableError,
|
|
248
|
+
AttachSecretKeyUnavailableError,
|
|
249
|
+
ATTACH_SECRET_OPTIONS_INFO,
|
|
250
|
+
} from "./attach-secret-options.js";
|
|
251
|
+
export { hostLocalAttachSecretKeyPath, ATTACH_SECRET_KEY_FILE_ENV } from "./attach-secret-keyfile.js";
|
|
219
252
|
export {
|
|
220
253
|
ATTACH_TICKET_OPTION,
|
|
221
254
|
ATTACH_TICKET_PREFIX,
|
package/src/protocol/dispatch.ts
CHANGED
|
@@ -30,6 +30,17 @@ export interface ProtocolConfig {
|
|
|
30
30
|
* unsealed — OS process ownership already enforces identity there.
|
|
31
31
|
*/
|
|
32
32
|
signingKey?: Uint8Array | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Optional root key for secret ATTACH options (`AttachOptionSpec.secret`),
|
|
35
|
+
* which the framework encrypts inside `attach_opaque_data` so functions and
|
|
36
|
+
* transaction hooks can read them with `attachOptions()`. Defaults to the
|
|
37
|
+
* signing key when there is one (HTTP), else the host-local key file
|
|
38
|
+
* (`$VGI_ATTACH_SECRET_KEY_FILE`, or `vgi/attach-secret-options.key` under
|
|
39
|
+
* `$XDG_RUNTIME_DIR` / the per-user temp dir). Any length; the AEAD key is
|
|
40
|
+
* always derived from it with HKDF-SHA256. Every worker process that may
|
|
41
|
+
* receive a given attach must use the same key.
|
|
42
|
+
*/
|
|
43
|
+
attachSecretKey?: Uint8Array | undefined;
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
/**
|
|
@@ -85,11 +96,12 @@ export function buildVgiService(config: ProtocolConfig): VgiService {
|
|
|
85
96
|
...functionHandlers({
|
|
86
97
|
registry: config.registry,
|
|
87
98
|
signingKey: config.signingKey,
|
|
99
|
+
attachSecretKey: config.attachSecretKey,
|
|
88
100
|
catalogInterface: config.catalogInterface,
|
|
89
101
|
}),
|
|
90
102
|
...aggregateHandlers(config.registry),
|
|
91
|
-
...tableBufferingHandlers(config.registry, config.signingKey),
|
|
92
|
-
...catalogHandlers(config.catalogInterface, config.signingKey),
|
|
103
|
+
...tableBufferingHandlers(config.registry, config.signingKey, config.attachSecretKey),
|
|
104
|
+
...catalogHandlers(config.catalogInterface, config.signingKey, config.attachSecretKey),
|
|
93
105
|
};
|
|
94
106
|
}
|
|
95
107
|
|
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
import { toUint8Array } from "../../../util/bytes.js";
|
|
34
34
|
import { redeemAttachTicket } from "../../../attach-ticket.js";
|
|
35
35
|
import { currentRequestAuth } from "../../../request-auth.js";
|
|
36
|
+
import { secretAttachOptionNames } from "../../../attach-secret-options.js";
|
|
37
|
+
import { deserializeAttachOptionSpec } from "../../../catalog/attach-option.js";
|
|
36
38
|
import { decodeDictValue } from "../../../util/arrow/index.js";
|
|
37
39
|
import {
|
|
38
40
|
unwrapRequest,
|
|
@@ -45,11 +47,13 @@ import {
|
|
|
45
47
|
sealAttach,
|
|
46
48
|
openAttach,
|
|
47
49
|
sealTransaction,
|
|
50
|
+
type OpaqueKeys,
|
|
48
51
|
} from "./shared.js";
|
|
49
52
|
|
|
50
|
-
export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
|
|
53
|
+
export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
|
|
54
|
+
const keys: OpaqueKeys = { signingKey, attachSecretKey };
|
|
51
55
|
// catalog_catalogs
|
|
52
|
-
const catalogCatalogs = catalogHandler(
|
|
56
|
+
const catalogCatalogs = catalogHandler(keys, async () => {
|
|
53
57
|
const cat = getCatalog();
|
|
54
58
|
// Each catalog advertised as an IPC-serialized CatalogInfo
|
|
55
59
|
// {name, implementation_version?, data_version_spec?}. Versioned workers
|
|
@@ -121,10 +125,21 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
121
125
|
// Seal the attach value into an AEAD envelope bound to the caller's
|
|
122
126
|
// identity before it leaves the worker (HTTP transport; pass-through
|
|
123
127
|
// when there is no signing key).
|
|
128
|
+
// The framework packs the attach's options after the catalog's bytes —
|
|
129
|
+
// secret ones (declared `secret: true`) encrypted with a worker-held key —
|
|
130
|
+
// so every function call and transaction hook of this attach can read them
|
|
131
|
+
// with attachOptions(), on every transport, without a catalog ever putting
|
|
132
|
+
// a credential into its own attach bytes.
|
|
133
|
+
const optionsIpc = innerParams.options == null ? null : toUint8Array(innerParams.options);
|
|
134
|
+
const secretNames =
|
|
135
|
+
optionsIpc && optionsIpc.length > 0
|
|
136
|
+
? await secretAttachOptionNames(cat as never, innerParams.name, deserializeAttachOptionSpec)
|
|
137
|
+
: new Set<string>();
|
|
124
138
|
const sealedAttach = await sealAttach(
|
|
125
139
|
toUint8Array(result.attach_opaque_data),
|
|
126
140
|
(ctx as CallContext | undefined)?.auth,
|
|
127
141
|
signingKey,
|
|
142
|
+
{ optionsIpc, secretNames, attachSecretKey },
|
|
128
143
|
);
|
|
129
144
|
// The generated builder emits every column of the pinned
|
|
130
145
|
// CatalogAttachResult schema, filling vgi-python's defaults for any a
|
|
@@ -142,28 +157,28 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
142
157
|
};
|
|
143
158
|
|
|
144
159
|
// catalog_detach
|
|
145
|
-
const catalogDetach = catalogHandler(
|
|
160
|
+
const catalogDetach = catalogHandler(keys, async (params) => {
|
|
146
161
|
const cat = getCatalog();
|
|
147
162
|
await cat.detach(toUint8Array(params.attach_opaque_data));
|
|
148
163
|
return {};
|
|
149
164
|
});
|
|
150
165
|
|
|
151
166
|
// catalog_create
|
|
152
|
-
const catalogCreate = catalogHandler(
|
|
167
|
+
const catalogCreate = catalogHandler(keys, async (params) => {
|
|
153
168
|
const cat = getCatalog();
|
|
154
169
|
await cat.create(params.name, params.on_conflict, params.options);
|
|
155
170
|
return {};
|
|
156
171
|
});
|
|
157
172
|
|
|
158
173
|
// catalog_drop
|
|
159
|
-
const catalogDrop = catalogHandler(
|
|
174
|
+
const catalogDrop = catalogHandler(keys, async (params) => {
|
|
160
175
|
const cat = getCatalog();
|
|
161
176
|
await cat.drop(params.name);
|
|
162
177
|
return {};
|
|
163
178
|
});
|
|
164
179
|
|
|
165
180
|
// catalog_version
|
|
166
|
-
const catalogVersion = catalogHandler(
|
|
181
|
+
const catalogVersion = catalogHandler(keys, async (params) => {
|
|
167
182
|
const cat = getCatalog();
|
|
168
183
|
const version = await cat.version(
|
|
169
184
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -179,7 +194,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
179
194
|
const auth = (ctx as CallContext | undefined)?.auth;
|
|
180
195
|
const sealedAttach =
|
|
181
196
|
params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
|
|
182
|
-
const attachPlain = await openAttach(sealedAttach, auth, signingKey);
|
|
197
|
+
const attachPlain = await openAttach(sealedAttach, auth, signingKey, attachSecretKey);
|
|
183
198
|
const cat = getCatalog();
|
|
184
199
|
const txPlain = await cat.transactionBegin(attachPlain);
|
|
185
200
|
// Seal the transaction value, binding it to the caller's identity and
|
|
@@ -190,7 +205,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
190
205
|
};
|
|
191
206
|
|
|
192
207
|
// catalog_transaction_commit
|
|
193
|
-
const catalogTransactionCommit = catalogHandler(
|
|
208
|
+
const catalogTransactionCommit = catalogHandler(keys, async (params) => {
|
|
194
209
|
const cat = getCatalog();
|
|
195
210
|
await cat.transactionCommit(
|
|
196
211
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -200,7 +215,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
200
215
|
});
|
|
201
216
|
|
|
202
217
|
// catalog_transaction_rollback
|
|
203
|
-
const catalogTransactionRollback = catalogHandler(
|
|
218
|
+
const catalogTransactionRollback = catalogHandler(keys, async (params) => {
|
|
204
219
|
const cat = getCatalog();
|
|
205
220
|
await cat.transactionRollback(
|
|
206
221
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -210,7 +225,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
210
225
|
});
|
|
211
226
|
|
|
212
227
|
// catalog_schemas
|
|
213
|
-
const catalogSchemas = catalogHandler(
|
|
228
|
+
const catalogSchemas = catalogHandler(keys, async (params) => {
|
|
214
229
|
const cat = getCatalog();
|
|
215
230
|
const schemas = await cat.schemas(
|
|
216
231
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -229,7 +244,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
229
244
|
// rules, the content-hash etag and the frozen-catalog cache.
|
|
230
245
|
const catalogContents: VgiService["catalogContents"] = async (params, ctx) => {
|
|
231
246
|
const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
|
|
232
|
-
return catalogHandler(
|
|
247
|
+
return catalogHandler(keys, async (opened, context) => {
|
|
233
248
|
const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
|
|
234
249
|
return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
|
|
235
250
|
})(params, ctx);
|
|
@@ -237,7 +252,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
237
252
|
|
|
238
253
|
// catalog_copy_from_formats — catalog-level (not schema-scoped). Lists the
|
|
239
254
|
// custom COPY ... FROM formats this catalog advertises; empty list when none.
|
|
240
|
-
const catalogCopyFromFormats = catalogHandler(
|
|
255
|
+
const catalogCopyFromFormats = catalogHandler(keys, async (params) => {
|
|
241
256
|
const cat = getCatalog();
|
|
242
257
|
const formats = await cat.copyFromFormats(
|
|
243
258
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -249,7 +264,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
249
264
|
});
|
|
250
265
|
|
|
251
266
|
// catalog_schema_get
|
|
252
|
-
const catalogSchemaGet = catalogHandler(
|
|
267
|
+
const catalogSchemaGet = catalogHandler(keys, async (params) => {
|
|
253
268
|
const cat = getCatalog();
|
|
254
269
|
const info = await cat.schemaGet(
|
|
255
270
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -262,7 +277,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
262
277
|
});
|
|
263
278
|
|
|
264
279
|
// catalog_schema_create
|
|
265
|
-
const catalogSchemaCreate = catalogHandler(
|
|
280
|
+
const catalogSchemaCreate = catalogHandler(keys, async (params) => {
|
|
266
281
|
if (params.options != null) throw new MethodNotImplementedError("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
|
|
267
282
|
const cat = getCatalog();
|
|
268
283
|
await cat.schemaCreate(
|
|
@@ -277,7 +292,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
277
292
|
});
|
|
278
293
|
|
|
279
294
|
// catalog_schema_drop
|
|
280
|
-
const catalogSchemaDrop = catalogHandler(
|
|
295
|
+
const catalogSchemaDrop = catalogHandler(keys, async (params) => {
|
|
281
296
|
const cat = getCatalog();
|
|
282
297
|
await cat.schemaDrop(
|
|
283
298
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -290,7 +305,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
290
305
|
});
|
|
291
306
|
|
|
292
307
|
// catalog_schema_contents_tables
|
|
293
|
-
const catalogSchemaContentsTables = catalogHandler(
|
|
308
|
+
const catalogSchemaContentsTables = catalogHandler(keys, async (params) => {
|
|
294
309
|
const cat = getCatalog();
|
|
295
310
|
const tables = await cat.schemaContentsTables(
|
|
296
311
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -303,7 +318,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
303
318
|
});
|
|
304
319
|
|
|
305
320
|
// catalog_schema_contents_views
|
|
306
|
-
const catalogSchemaContentsViews = catalogHandler(
|
|
321
|
+
const catalogSchemaContentsViews = catalogHandler(keys, async (params) => {
|
|
307
322
|
const cat = getCatalog();
|
|
308
323
|
const views = await cat.schemaContentsViews(
|
|
309
324
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -316,7 +331,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
316
331
|
});
|
|
317
332
|
|
|
318
333
|
// catalog_schema_contents_functions
|
|
319
|
-
const catalogSchemaContentsFunctions = catalogHandler(
|
|
334
|
+
const catalogSchemaContentsFunctions = catalogHandler(keys, async (params) => {
|
|
320
335
|
const cat = getCatalog();
|
|
321
336
|
const funcs = await cat.schemaContentsFunctions(
|
|
322
337
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -14,13 +14,14 @@ import { catalogIndexHandlers } from "./index_methods.js";
|
|
|
14
14
|
export function catalogHandlers(
|
|
15
15
|
catalog: CatalogInterface | undefined,
|
|
16
16
|
signingKey?: Uint8Array,
|
|
17
|
+
attachSecretKey?: Uint8Array,
|
|
17
18
|
): Partial<VgiService> {
|
|
18
19
|
const getCatalog = makeGetCatalog(catalog);
|
|
19
20
|
return {
|
|
20
|
-
...catalogAdminHandlers(getCatalog, signingKey),
|
|
21
|
-
...catalogTableHandlers(getCatalog, signingKey),
|
|
22
|
-
...catalogViewHandlers(getCatalog, signingKey),
|
|
23
|
-
...catalogMacroHandlers(getCatalog, signingKey),
|
|
24
|
-
...catalogIndexHandlers(getCatalog, signingKey),
|
|
21
|
+
...catalogAdminHandlers(getCatalog, signingKey, attachSecretKey),
|
|
22
|
+
...catalogTableHandlers(getCatalog, signingKey, attachSecretKey),
|
|
23
|
+
...catalogViewHandlers(getCatalog, signingKey, attachSecretKey),
|
|
24
|
+
...catalogMacroHandlers(getCatalog, signingKey, attachSecretKey),
|
|
25
|
+
...catalogIndexHandlers(getCatalog, signingKey, attachSecretKey),
|
|
25
26
|
};
|
|
26
27
|
}
|
|
@@ -14,11 +14,13 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
type GetCatalog,
|
|
16
16
|
catalogHandler,
|
|
17
|
+
type OpaqueKeys,
|
|
17
18
|
} from "./shared.js";
|
|
18
19
|
|
|
19
|
-
export function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
|
|
20
|
+
export function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
|
|
21
|
+
const keys: OpaqueKeys = { signingKey, attachSecretKey };
|
|
20
22
|
// catalog_schema_contents_indexes
|
|
21
|
-
const catalogSchemaContentsIndexes = catalogHandler(
|
|
23
|
+
const catalogSchemaContentsIndexes = catalogHandler(keys, async (params) => {
|
|
22
24
|
const cat = getCatalog();
|
|
23
25
|
const indexes = await cat.schemaContentsIndexes(
|
|
24
26
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -31,7 +33,7 @@ export function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
// catalog_index_get
|
|
34
|
-
const catalogIndexGet = catalogHandler(
|
|
36
|
+
const catalogIndexGet = catalogHandler(keys, async (params) => {
|
|
35
37
|
const cat = getCatalog();
|
|
36
38
|
const info = await cat.indexGet(
|
|
37
39
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -19,11 +19,13 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
type GetCatalog,
|
|
21
21
|
catalogHandler,
|
|
22
|
+
type OpaqueKeys,
|
|
22
23
|
} from "./shared.js";
|
|
23
24
|
|
|
24
|
-
export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
|
|
25
|
+
export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
|
|
26
|
+
const keys: OpaqueKeys = { signingKey, attachSecretKey };
|
|
25
27
|
// catalog_macro_get
|
|
26
|
-
const catalogMacroGet = catalogHandler(
|
|
28
|
+
const catalogMacroGet = catalogHandler(keys, async (params) => {
|
|
27
29
|
const cat = getCatalog();
|
|
28
30
|
const info = await cat.macroGet(
|
|
29
31
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -37,7 +39,7 @@ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
37
39
|
});
|
|
38
40
|
|
|
39
41
|
// catalog_macro_create
|
|
40
|
-
const catalogMacroCreate = catalogHandler(
|
|
42
|
+
const catalogMacroCreate = catalogHandler(keys, async (params) => {
|
|
41
43
|
const cat = getCatalog();
|
|
42
44
|
// catalogHandler already flattened the wrapped request.
|
|
43
45
|
const innerParams = decodeASD<MacroCreateRequest>(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
|
|
@@ -55,7 +57,7 @@ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
// catalog_macro_drop
|
|
58
|
-
const catalogMacroDrop = catalogHandler(
|
|
60
|
+
const catalogMacroDrop = catalogHandler(keys, async (params) => {
|
|
59
61
|
const cat = getCatalog();
|
|
60
62
|
await cat.macroDrop(
|
|
61
63
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -68,7 +70,7 @@ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
// catalog_schema_contents_macros
|
|
71
|
-
const catalogSchemaContentsMacros = catalogHandler(
|
|
73
|
+
const catalogSchemaContentsMacros = catalogHandler(keys, async (params) => {
|
|
72
74
|
const cat = getCatalog();
|
|
73
75
|
const macros = await cat.schemaContentsMacros(
|
|
74
76
|
toUint8Array(params.attach_opaque_data),
|