@query-farm/vgi 0.48.4 → 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/interface.d.ts +15 -0
- package/dist/client-entry.js +1 -1
- package/dist/client-entry.js.map +4 -4
- package/dist/index.core.d.ts +2 -0
- package/dist/index.js +5700 -5276
- package/dist/index.js.map +24 -22
- 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 +28 -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 +475 -94
- package/dist/serve-entry.js.map +18 -16
- package/dist/worker-cf-entry.js +497 -93
- package/dist/worker-cf-entry.js.map +18 -16
- package/dist/worker.d.ts +10 -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/interface.ts +19 -0
- package/src/index.core.ts +10 -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 +52 -6
- package/src/protocol/handlers/catalog/table.ts +24 -22
- package/src/protocol/handlers/catalog/view.ts +9 -7
- package/src/protocol/handlers/function.ts +11 -5
- package/src/protocol/handlers/table-buffering.ts +2 -1
- package/src/serve-entry.ts +6 -1
- package/src/worker.ts +12 -0
|
@@ -15,11 +15,13 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
type GetCatalog,
|
|
17
17
|
catalogHandler,
|
|
18
|
+
type OpaqueKeys,
|
|
18
19
|
} from "./shared.js";
|
|
19
20
|
|
|
20
|
-
export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
|
|
21
|
+
export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
|
|
22
|
+
const keys: OpaqueKeys = { signingKey, attachSecretKey };
|
|
21
23
|
// catalog_view_get
|
|
22
|
-
const catalogViewGet = catalogHandler(
|
|
24
|
+
const catalogViewGet = catalogHandler(keys, async (params) => {
|
|
23
25
|
const cat = getCatalog();
|
|
24
26
|
const info = await cat.viewGet(
|
|
25
27
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -33,7 +35,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
// catalog_view_create
|
|
36
|
-
const catalogViewCreate = catalogHandler(
|
|
38
|
+
const catalogViewCreate = catalogHandler(keys, async (params) => {
|
|
37
39
|
if (params.security !== "regular") throw new Error(`view security mode ${params.security} is unsupported`);
|
|
38
40
|
const tags = catalogStringMap(params.tags);
|
|
39
41
|
const columnComments = catalogStringMap(params.column_comments);
|
|
@@ -55,7 +57,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
// catalog_view_drop
|
|
58
|
-
const catalogViewDrop = catalogHandler(
|
|
60
|
+
const catalogViewDrop = catalogHandler(keys, async (params) => {
|
|
59
61
|
const cat = getCatalog();
|
|
60
62
|
await cat.viewDrop(
|
|
61
63
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -68,7 +70,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
// catalog_view_rename
|
|
71
|
-
const catalogViewRename = catalogHandler(
|
|
73
|
+
const catalogViewRename = catalogHandler(keys, async (params) => {
|
|
72
74
|
const cat = getCatalog();
|
|
73
75
|
await cat.viewRename(
|
|
74
76
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -82,7 +84,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
82
84
|
});
|
|
83
85
|
|
|
84
86
|
// catalog_view_comment_set
|
|
85
|
-
const catalogViewCommentSet = catalogHandler(
|
|
87
|
+
const catalogViewCommentSet = catalogHandler(keys, async (params) => {
|
|
86
88
|
const cat = getCatalog();
|
|
87
89
|
await cat.viewCommentSet(
|
|
88
90
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -95,7 +97,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
95
97
|
return {};
|
|
96
98
|
});
|
|
97
99
|
|
|
98
|
-
const catalogViewColumnCommentSet = catalogHandler(
|
|
100
|
+
const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
|
|
99
101
|
const path: string[] = Array.from(params.column_path);
|
|
100
102
|
if (path.length !== 1 || !path[0] || path[0].includes("\0")) throw new Error("view column comments require one raw output identifier");
|
|
101
103
|
await getCatalog().viewColumnCommentSet(
|
|
@@ -56,6 +56,8 @@ import {
|
|
|
56
56
|
export interface FunctionHandlerConfig {
|
|
57
57
|
registry: FunctionRegistry;
|
|
58
58
|
signingKey?: Uint8Array | undefined;
|
|
59
|
+
/** Explicit root key for secret ATTACH options (see attach-secret-options.ts). */
|
|
60
|
+
attachSecretKey?: Uint8Array | undefined;
|
|
59
61
|
/**
|
|
60
62
|
* Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
|
|
61
63
|
* be scoped when two catalogs declare the same schema and function name.
|
|
@@ -90,6 +92,7 @@ async function liveSplitAnchor(
|
|
|
90
92
|
bindCall: { attach_opaque_data?: Uint8Array | null; transaction_opaque_data?: Uint8Array | null },
|
|
91
93
|
auth: AuthContext | undefined,
|
|
92
94
|
signingKey: Uint8Array | undefined,
|
|
95
|
+
attachSecretKey?: Uint8Array,
|
|
93
96
|
): Promise<Uint8Array | undefined> {
|
|
94
97
|
if (!catalogInterface?.version || bindCall.attach_opaque_data == null) return undefined;
|
|
95
98
|
const raw = toUint8Array(bindCall.attach_opaque_data);
|
|
@@ -123,7 +126,7 @@ async function liveSplitAnchor(
|
|
|
123
126
|
// every non-HTTP transport).
|
|
124
127
|
const forms: Array<() => Promise<Uint8Array>> = [
|
|
125
128
|
async () => raw,
|
|
126
|
-
async () => openAttach(raw, auth, signingKey),
|
|
129
|
+
async () => openAttach(raw, auth, signingKey, attachSecretKey),
|
|
127
130
|
];
|
|
128
131
|
for (const form of forms) {
|
|
129
132
|
try {
|
|
@@ -168,6 +171,7 @@ async function resolveSplitPayloads(
|
|
|
168
171
|
opts: {
|
|
169
172
|
auth: any;
|
|
170
173
|
signingKey: Uint8Array | undefined;
|
|
174
|
+
attachSecretKey?: Uint8Array | undefined;
|
|
171
175
|
catalogInterface: any;
|
|
172
176
|
checkAnchor: boolean;
|
|
173
177
|
},
|
|
@@ -182,7 +186,7 @@ async function resolveSplitPayloads(
|
|
|
182
186
|
new Uint8Array(0),
|
|
183
187
|
);
|
|
184
188
|
const currentAnchor = opts.checkAnchor
|
|
185
|
-
? await liveSplitAnchor(opts.catalogInterface, request.bind_call as any, opts.auth, opts.signingKey)
|
|
189
|
+
? await liveSplitAnchor(opts.catalogInterface, request.bind_call as any, opts.auth, opts.signingKey, opts.attachSecretKey)
|
|
186
190
|
: undefined;
|
|
187
191
|
request.split_payloads = [];
|
|
188
192
|
for (const token of request.split_tokens) {
|
|
@@ -202,7 +206,7 @@ async function resolveSplitPayloads(
|
|
|
202
206
|
|
|
203
207
|
/** The per-function lifecycle's `vgi.v3` handlers. */
|
|
204
208
|
export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService> {
|
|
205
|
-
const { registry, signingKey, catalogInterface } = config;
|
|
209
|
+
const { registry, signingKey, catalogInterface, attachSecretKey } = config;
|
|
206
210
|
|
|
207
211
|
// The framework mints every attach as uuid(16) || catalog_bytes (sealed on
|
|
208
212
|
// HTTP, plaintext on subprocess). Function bodies — like catalog bodies —
|
|
@@ -218,7 +222,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
218
222
|
if (attach == null) return null;
|
|
219
223
|
const env = toUint8Array(attach);
|
|
220
224
|
if (env.length === 0) return env;
|
|
221
|
-
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
225
|
+
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
// Unseal a bind call's opaque values in place, as the catalog handlers do:
|
|
@@ -318,6 +322,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
318
322
|
await resolveSplitPayloads(request, innerParams, {
|
|
319
323
|
auth,
|
|
320
324
|
signingKey,
|
|
325
|
+
attachSecretKey,
|
|
321
326
|
catalogInterface,
|
|
322
327
|
checkAnchor: true,
|
|
323
328
|
});
|
|
@@ -429,6 +434,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
429
434
|
// authentication for every authenticated caller's own tokens.
|
|
430
435
|
auth: currentRequestAuth(),
|
|
431
436
|
signingKey,
|
|
437
|
+
attachSecretKey,
|
|
432
438
|
catalogInterface,
|
|
433
439
|
checkAnchor: false,
|
|
434
440
|
});
|
|
@@ -568,7 +574,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
568
574
|
const anchor =
|
|
569
575
|
plan.catalogVersion != null
|
|
570
576
|
? splitAnchor(plan.catalogVersion)
|
|
571
|
-
: ((await liveSplitAnchor(catalogInterface, request.bind_call as any, ctx?.auth, signingKey)) ??
|
|
577
|
+
: ((await liveSplitAnchor(catalogInterface, request.bind_call as any, ctx?.auth, signingKey, attachSecretKey)) ??
|
|
572
578
|
splitAnchor(0));
|
|
573
579
|
|
|
574
580
|
const blobs: Uint8Array[] = [];
|
|
@@ -37,6 +37,7 @@ import { Arguments } from "../../arguments/arguments.js";
|
|
|
37
37
|
export function tableBufferingHandlers(
|
|
38
38
|
registry: FunctionRegistry,
|
|
39
39
|
signingKey?: Uint8Array,
|
|
40
|
+
attachSecretKey?: Uint8Array,
|
|
40
41
|
): Partial<VgiService> {
|
|
41
42
|
// `schemaPath` scopes resolution to the schema the caller named. The
|
|
42
43
|
// buffering process/combine RPCs carry it (protocol 1.2.0), so a name
|
|
@@ -74,7 +75,7 @@ export function tableBufferingHandlers(
|
|
|
74
75
|
const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
|
|
75
76
|
const attach =
|
|
76
77
|
rawAttach && rawAttach.length > 0
|
|
77
|
-
? await openAttach(rawAttach, ctx?.auth, signingKey)
|
|
78
|
+
? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey)
|
|
78
79
|
: rawAttach;
|
|
79
80
|
const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
|
|
80
81
|
|
package/src/serve-entry.ts
CHANGED
|
@@ -91,6 +91,11 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
|
|
|
91
91
|
hostname?: string | undefined;
|
|
92
92
|
/** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
|
|
93
93
|
signingKey?: Uint8Array | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Optional root key for secret ATTACH options (encrypted inside
|
|
96
|
+
* `attach_opaque_data` for `attachOptions()`). Defaults to the signing key.
|
|
97
|
+
*/
|
|
98
|
+
attachSecretKey?: Uint8Array | undefined;
|
|
94
99
|
/** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
|
|
95
100
|
tokenTtl?: number | undefined;
|
|
96
101
|
/** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
|
|
@@ -242,7 +247,7 @@ export function createVgiWorkerFetch(
|
|
|
242
247
|
const trustedProxyAddresses = bridge?.trustedProxyAddresses ?? ["127.0.0.1"];
|
|
243
248
|
|
|
244
249
|
return createVgiFetch({
|
|
245
|
-
protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface },
|
|
250
|
+
protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface, attachSecretKey: opts.attachSecretKey },
|
|
246
251
|
signingKey,
|
|
247
252
|
signingKeyConfigured,
|
|
248
253
|
tokenTtl,
|
package/src/worker.ts
CHANGED
|
@@ -123,6 +123,15 @@ export interface WorkerConfig extends HostingOptions {
|
|
|
123
123
|
* dispatches on. Omit to have the worker create its own.
|
|
124
124
|
*/
|
|
125
125
|
registry?: FunctionRegistry;
|
|
126
|
+
/**
|
|
127
|
+
* Optional root key for secret ATTACH options (`AttachOptionSpec.secret`),
|
|
128
|
+
* which the framework encrypts inside `attach_opaque_data` for
|
|
129
|
+
* `attachOptions()`. Defaults to the host-local key file
|
|
130
|
+
* (`$VGI_ATTACH_SECRET_KEY_FILE`, else `vgi/attach-secret-options.key` under
|
|
131
|
+
* `$XDG_RUNTIME_DIR` or the per-user temp dir). Every worker process that may
|
|
132
|
+
* receive a given attach must use the same key.
|
|
133
|
+
*/
|
|
134
|
+
attachSecretKey?: Uint8Array;
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
export class Worker {
|
|
@@ -130,8 +139,10 @@ export class Worker {
|
|
|
130
139
|
private _hosting: HostingOptions;
|
|
131
140
|
private _catalogInterface: CatalogInterface | undefined;
|
|
132
141
|
private _catalogName: string | undefined;
|
|
142
|
+
private _attachSecretKey: Uint8Array | undefined;
|
|
133
143
|
|
|
134
144
|
constructor(config: WorkerConfig) {
|
|
145
|
+
this._attachSecretKey = config.attachSecretKey;
|
|
135
146
|
// Reuse the caller's registry when given: a catalogInterface built
|
|
136
147
|
// elsewhere recorded its per-schema function ownership there, and that
|
|
137
148
|
// index is what makes a schema-qualified bind resolve correctly.
|
|
@@ -297,6 +308,7 @@ export class Worker {
|
|
|
297
308
|
registry: this._registry,
|
|
298
309
|
catalogInterface: this._catalogInterface,
|
|
299
310
|
catalogName: this._catalogName,
|
|
311
|
+
attachSecretKey: this._attachSecretKey,
|
|
300
312
|
});
|
|
301
313
|
}
|
|
302
314
|
|