@query-farm/vgi 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache-control.d.ts +26 -0
- package/dist/catalog/composite.d.ts +2 -0
- package/dist/catalog/interface.d.ts +11 -0
- package/dist/client-entry.js +5 -3
- package/dist/client-entry.js.map +5 -5
- package/dist/functions/registry.d.ts +31 -0
- package/dist/functions/scalar.d.ts +7 -3
- package/dist/generated/vgi-client.d.ts +16 -0
- package/dist/index.core.d.ts +1 -1
- package/dist/index.js +135 -25
- package/dist/index.js.map +17 -17
- package/dist/protocol/handlers/function.d.ts +8 -0
- package/dist/protocol/handlers/shared.d.ts +4 -0
- package/dist/protocol/types.d.ts +8 -0
- package/dist/serve-entry.js +50 -22
- package/dist/serve-entry.js.map +10 -10
- package/dist/worker-cf-entry.js +130 -23
- package/dist/worker-cf-entry.js.map +15 -15
- package/dist/worker.d.ts +9 -0
- package/package.json +3 -3
- package/src/cache-control.ts +27 -0
- package/src/catalog/composite.ts +9 -0
- package/src/catalog/interface.ts +15 -0
- package/src/catalog/read-only.ts +13 -0
- package/src/functions/registry.ts +106 -1
- package/src/functions/scalar.ts +10 -5
- package/src/generated/vgi-client.ts +17 -1
- package/src/index.core.ts +1 -0
- package/src/protocol/dispatch.ts +1 -0
- package/src/protocol/handlers/aggregate.ts +18 -6
- package/src/protocol/handlers/function.ts +29 -8
- package/src/protocol/handlers/shared.ts +25 -1
- package/src/protocol/handlers/table-buffering.ts +10 -2
- package/src/protocol/serializers/bind.ts +7 -0
- package/src/protocol/types.ts +8 -0
- package/src/worker.ts +15 -1
|
@@ -4,5 +4,13 @@ export interface FunctionHandlerConfig {
|
|
|
4
4
|
registry: FunctionRegistry;
|
|
5
5
|
recoverExchangeState?: (opaqueData: Uint8Array) => any;
|
|
6
6
|
signingKey?: Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
|
|
9
|
+
* be scoped when two catalogs declare the same schema and function name.
|
|
10
|
+
* Optional — without it, resolution falls back to (schema, name).
|
|
11
|
+
*/
|
|
12
|
+
catalogInterface?: {
|
|
13
|
+
catalogNameForAttach(a: Uint8Array): string | null;
|
|
14
|
+
};
|
|
7
15
|
}
|
|
8
16
|
export declare function registerFunctionMethods(protocol: Protocol, config: FunctionHandlerConfig): void;
|
|
@@ -22,6 +22,10 @@ export declare function overloadContext(req: {
|
|
|
22
22
|
arguments: any;
|
|
23
23
|
input_schema: any;
|
|
24
24
|
function_type: any;
|
|
25
|
+
schema_name?: string | null;
|
|
26
|
+
attach_opaque_data?: Uint8Array | null;
|
|
27
|
+
}, catalogInterface?: {
|
|
28
|
+
catalogNameForAttach(a: Uint8Array): string | null;
|
|
25
29
|
}): OverloadContext;
|
|
26
30
|
/**
|
|
27
31
|
* Recover accumulated exchange state from a FINALIZE init request.
|
package/dist/protocol/types.d.ts
CHANGED
|
@@ -73,6 +73,14 @@ export interface BindRequest {
|
|
|
73
73
|
*/
|
|
74
74
|
at_unit?: string | null;
|
|
75
75
|
at_value?: string | null;
|
|
76
|
+
/**
|
|
77
|
+
* Catalog schema that declares the function being bound. A worker may
|
|
78
|
+
* register the same name in more than one schema, so the bare name does not
|
|
79
|
+
* identify an implementation — resolution is by `(schema_name,
|
|
80
|
+
* function_name)`. Null for callers with no catalog context (COPY handler
|
|
81
|
+
* binds). Mirrors vgi-python's `BindRequest.schema_name`.
|
|
82
|
+
*/
|
|
83
|
+
schema_name?: string | null;
|
|
76
84
|
}
|
|
77
85
|
export interface BindResponse {
|
|
78
86
|
output_schema: VgiSchema;
|
package/dist/serve-entry.js
CHANGED
|
@@ -3029,7 +3029,8 @@ var BIND_REQUEST_SCHEMA = schema2([
|
|
|
3029
3029
|
field2("transaction_opaque_data", binary2(), true),
|
|
3030
3030
|
field2("resolved_secrets_provided", bool2(), false),
|
|
3031
3031
|
field2("at_unit", utf82(), true),
|
|
3032
|
-
field2("at_value", utf82(), true)
|
|
3032
|
+
field2("at_value", utf82(), true),
|
|
3033
|
+
field2("schema_name", utf82(), true)
|
|
3033
3034
|
]);
|
|
3034
3035
|
var COPY_FROM_STRUCT_TYPE = struct2([
|
|
3035
3036
|
field2("format", utf82(), false),
|
|
@@ -3097,6 +3098,7 @@ function deserializeBindRequest(params) {
|
|
|
3097
3098
|
resolved_secrets_provided: params.resolved_secrets_provided ?? false,
|
|
3098
3099
|
at_unit: params.at_unit ? String(params.at_unit) : null,
|
|
3099
3100
|
at_value: params.at_value ? String(params.at_value) : null,
|
|
3101
|
+
schema_name: params.schema_name ? String(params.schema_name) : null,
|
|
3100
3102
|
copy_from: parseCopyFromContext(params.copy_from),
|
|
3101
3103
|
copy_to: parseCopyToContext(params.copy_to)
|
|
3102
3104
|
};
|
|
@@ -3922,11 +3924,21 @@ function wrapResult(values, innerSchema) {
|
|
|
3922
3924
|
const batch = batchFromColumns(Object.fromEntries(a.fields.map((f) => [f.name, [values[f.name] ?? null]])), a);
|
|
3923
3925
|
return { result: serializeBatch(batch) };
|
|
3924
3926
|
}
|
|
3925
|
-
function overloadContext(req) {
|
|
3927
|
+
function overloadContext(req, catalogInterface) {
|
|
3928
|
+
let catalogName = null;
|
|
3929
|
+
if (catalogInterface && req.attach_opaque_data) {
|
|
3930
|
+
try {
|
|
3931
|
+
catalogName = catalogInterface.catalogNameForAttach(req.attach_opaque_data);
|
|
3932
|
+
} catch {
|
|
3933
|
+
catalogName = null;
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3926
3936
|
return {
|
|
3927
3937
|
arguments: req.arguments,
|
|
3928
3938
|
inputSchema: req.input_schema,
|
|
3929
|
-
isScalar: String(req.function_type).toLowerCase() === "scalar"
|
|
3939
|
+
isScalar: String(req.function_type).toLowerCase() === "scalar",
|
|
3940
|
+
schemaName: req.schema_name ?? null,
|
|
3941
|
+
catalogName
|
|
3930
3942
|
};
|
|
3931
3943
|
}
|
|
3932
3944
|
function recoverFinalizeState(request, recoverExchangeState) {
|
|
@@ -4917,7 +4929,7 @@ var columnOpParams = schema2([
|
|
|
4917
4929
|
|
|
4918
4930
|
// src/protocol/handlers/function.ts
|
|
4919
4931
|
function registerFunctionMethods(protocol, config) {
|
|
4920
|
-
const { registry, signingKey } = config;
|
|
4932
|
+
const { registry, signingKey, catalogInterface } = config;
|
|
4921
4933
|
async function stripAttach(attach, ctx) {
|
|
4922
4934
|
if (attach == null)
|
|
4923
4935
|
return null;
|
|
@@ -4926,6 +4938,15 @@ function registerFunctionMethods(protocol, config) {
|
|
|
4926
4938
|
return env;
|
|
4927
4939
|
return openAttach(env, ctx?.auth, signingKey);
|
|
4928
4940
|
}
|
|
4941
|
+
async function strippedContext(bindCall, ctx) {
|
|
4942
|
+
let attach = null;
|
|
4943
|
+
try {
|
|
4944
|
+
attach = await stripAttach(bindCall.attach_opaque_data, ctx);
|
|
4945
|
+
} catch {
|
|
4946
|
+
attach = null;
|
|
4947
|
+
}
|
|
4948
|
+
return overloadContext({ ...bindCall, attach_opaque_data: attach }, catalogInterface);
|
|
4949
|
+
}
|
|
4929
4950
|
const initHeaderSchema = schema2([
|
|
4930
4951
|
field2("execution_id", binary2(), false),
|
|
4931
4952
|
field2("opaque_data", binary2(), true),
|
|
@@ -4942,7 +4963,7 @@ function registerFunctionMethods(protocol, config) {
|
|
|
4942
4963
|
const innerParams = unwrapRequest(params.request);
|
|
4943
4964
|
const request = deserializeBindRequest(innerParams);
|
|
4944
4965
|
request.attach_opaque_data = await stripAttach(request.attach_opaque_data, ctx);
|
|
4945
|
-
const func = registry.get(request.function_name, overloadContext(request));
|
|
4966
|
+
const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
|
|
4946
4967
|
const response = await func.bind(request);
|
|
4947
4968
|
const serialized = serializeBindResponse(response);
|
|
4948
4969
|
return wrapResult(serialized, BindResultSchema);
|
|
@@ -4957,7 +4978,7 @@ function registerFunctionMethods(protocol, config) {
|
|
|
4957
4978
|
const innerParams = unwrapRequest(params.request);
|
|
4958
4979
|
const request = deserializeInitRequest(innerParams);
|
|
4959
4980
|
request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
|
|
4960
|
-
const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
|
|
4981
|
+
const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call, catalogInterface));
|
|
4961
4982
|
const initResponse = await func.globalInit(request);
|
|
4962
4983
|
const accumulatedState = recoverFinalizeState(request, config.recoverExchangeState);
|
|
4963
4984
|
const handlers = func.createStreamHandlers(request, initResponse, accumulatedState);
|
|
@@ -4997,7 +5018,7 @@ function registerFunctionMethods(protocol, config) {
|
|
|
4997
5018
|
const initRequestBatch = deserializeBatch(state.initRequestIpc);
|
|
4998
5019
|
const initRequestDict = batchToScalarDict(initRequestBatch);
|
|
4999
5020
|
const request = deserializeInitRequest(initRequestDict);
|
|
5000
|
-
const func = registry.get(state.functionName,
|
|
5021
|
+
const func = registry.get(state.functionName, await strippedContext(request.bind_call));
|
|
5001
5022
|
const executionId = state.executionId;
|
|
5002
5023
|
const opaqueData = state.opaqueData ?? null;
|
|
5003
5024
|
const initResponse = {
|
|
@@ -5045,7 +5066,7 @@ function registerFunctionMethods(protocol, config) {
|
|
|
5045
5066
|
handler: async (params) => {
|
|
5046
5067
|
const innerParams = unwrapRequest(params.request);
|
|
5047
5068
|
const request = deserializeCardinalityRequest(innerParams);
|
|
5048
|
-
const func = registry.get(request.bind_call.function_name,
|
|
5069
|
+
const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
|
|
5049
5070
|
let cardResult;
|
|
5050
5071
|
if (func.cardinality) {
|
|
5051
5072
|
cardResult = serializeTableCardinality(await func.cardinality(request));
|
|
@@ -5058,10 +5079,10 @@ function registerFunctionMethods(protocol, config) {
|
|
|
5058
5079
|
protocol.unary("table_function_statistics", {
|
|
5059
5080
|
params: REQUEST_PARAMS_SCHEMA,
|
|
5060
5081
|
result: RESULT_BINARY_NULLABLE_SCHEMA,
|
|
5061
|
-
handler: (params) => {
|
|
5082
|
+
handler: async (params) => {
|
|
5062
5083
|
const innerParams = unwrapRequest(params.request);
|
|
5063
5084
|
const request = deserializeCardinalityRequest(innerParams);
|
|
5064
|
-
const func = registry.get(request.bind_call.function_name,
|
|
5085
|
+
const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
|
|
5065
5086
|
if (!func.statistics)
|
|
5066
5087
|
return { result: null };
|
|
5067
5088
|
const stats = func.statistics(request);
|
|
@@ -5081,7 +5102,7 @@ function registerFunctionMethods(protocol, config) {
|
|
|
5081
5102
|
const bindCall = deserializeBindRequest(bindParams);
|
|
5082
5103
|
const globalExecutionId = toUint8Array(innerParams.global_execution_id);
|
|
5083
5104
|
const bindOpaqueData = innerParams.bind_opaque_data ? toUint8Array(innerParams.bind_opaque_data) : null;
|
|
5084
|
-
const func = registry.get(bindCall.function_name,
|
|
5105
|
+
const func = registry.get(bindCall.function_name, await strippedContext(bindCall));
|
|
5085
5106
|
const map3 = func.dynamicToString ? await func.dynamicToString({ bindCall, bindOpaqueData, globalExecutionId }) : {};
|
|
5086
5107
|
const keys = Object.keys(map3);
|
|
5087
5108
|
const values = keys.map((k) => map3[k] ?? "");
|
|
@@ -5259,8 +5280,13 @@ function persistGroupStates(executionId, gids) {
|
|
|
5259
5280
|
|
|
5260
5281
|
// src/protocol/handlers/aggregate.ts
|
|
5261
5282
|
function registerAggregateMethods(protocol, registry) {
|
|
5262
|
-
function resolveAggregate(name) {
|
|
5263
|
-
const func = registry.get(name, {
|
|
5283
|
+
function resolveAggregate(name, schemaName) {
|
|
5284
|
+
const func = registry.get(name, {
|
|
5285
|
+
arguments: new Arguments,
|
|
5286
|
+
inputSchema: null,
|
|
5287
|
+
isScalar: false,
|
|
5288
|
+
schemaName: schemaName ?? null
|
|
5289
|
+
});
|
|
5264
5290
|
if (!func || func.kind !== "aggregate") {
|
|
5265
5291
|
throw new Error(`Function '${name}' is not an aggregate function`);
|
|
5266
5292
|
}
|
|
@@ -5272,7 +5298,7 @@ function registerAggregateMethods(protocol, registry) {
|
|
|
5272
5298
|
handler: async (params) => {
|
|
5273
5299
|
const innerParams = unwrapRequest(params.request);
|
|
5274
5300
|
const functionName = innerParams.function_name;
|
|
5275
|
-
const cfg = resolveAggregate(functionName);
|
|
5301
|
+
const cfg = resolveAggregate(functionName, innerParams.schema_name ?? null);
|
|
5276
5302
|
const argBytes = toUint8Array(innerParams.arguments);
|
|
5277
5303
|
const args = deserializeArguments(argBytes);
|
|
5278
5304
|
const inputSchema = innerParams.input_schema ? deserializeSchema(toUint8Array(innerParams.input_schema)) : null;
|
|
@@ -5305,7 +5331,7 @@ function registerAggregateMethods(protocol, registry) {
|
|
|
5305
5331
|
const innerParams = unwrapRequest(params.request);
|
|
5306
5332
|
const functionName = innerParams.function_name;
|
|
5307
5333
|
const executionId = toUint8Array(innerParams.execution_id);
|
|
5308
|
-
const cfg = resolveAggregate(functionName);
|
|
5334
|
+
const cfg = resolveAggregate(functionName, innerParams.schema_name ?? null);
|
|
5309
5335
|
const batch = readSingleBatch(toUint8Array(innerParams.input_batch));
|
|
5310
5336
|
if (!batch || batch.numRows === 0)
|
|
5311
5337
|
return wrapResult({}, schema2([]));
|
|
@@ -5358,7 +5384,7 @@ function registerAggregateMethods(protocol, registry) {
|
|
|
5358
5384
|
const innerParams = unwrapRequest(params.request);
|
|
5359
5385
|
const functionName = innerParams.function_name;
|
|
5360
5386
|
const executionId = toUint8Array(innerParams.execution_id);
|
|
5361
|
-
const cfg = resolveAggregate(functionName);
|
|
5387
|
+
const cfg = resolveAggregate(functionName, innerParams.schema_name ?? null);
|
|
5362
5388
|
const batch = readSingleBatch(toUint8Array(innerParams.merge_batch));
|
|
5363
5389
|
if (!batch || batch.numRows === 0)
|
|
5364
5390
|
return wrapResult({}, schema2([]));
|
|
@@ -5403,7 +5429,7 @@ function registerAggregateMethods(protocol, registry) {
|
|
|
5403
5429
|
const innerParams = unwrapRequest(params.request);
|
|
5404
5430
|
const functionName = innerParams.function_name;
|
|
5405
5431
|
const executionId = toUint8Array(innerParams.execution_id);
|
|
5406
|
-
const cfg = resolveAggregate(functionName);
|
|
5432
|
+
const cfg = resolveAggregate(functionName, innerParams.schema_name ?? null);
|
|
5407
5433
|
const outputSchema = deserializeSchema(toUint8Array(innerParams.output_schema));
|
|
5408
5434
|
const gidBatch = readSingleBatch(toUint8Array(innerParams.group_ids_batch));
|
|
5409
5435
|
const groupIds = [];
|
|
@@ -5549,11 +5575,12 @@ function splitLenPrefixed(buf, count) {
|
|
|
5549
5575
|
|
|
5550
5576
|
// src/protocol/handlers/table-buffering.ts
|
|
5551
5577
|
function registerTableBufferingMethods(protocol, registry, signingKey) {
|
|
5552
|
-
function resolveBuffering(name) {
|
|
5578
|
+
function resolveBuffering(name, schemaName) {
|
|
5553
5579
|
const func = registry.get(name, {
|
|
5554
5580
|
arguments: new Arguments,
|
|
5555
5581
|
inputSchema: null,
|
|
5556
|
-
isScalar: false
|
|
5582
|
+
isScalar: false,
|
|
5583
|
+
schemaName: schemaName ?? null
|
|
5557
5584
|
});
|
|
5558
5585
|
if (!func || func.kind !== "table_buffering") {
|
|
5559
5586
|
throw new Error(`Function '${name}' is not a table_buffering function`);
|
|
@@ -5566,7 +5593,7 @@ function registerTableBufferingMethods(protocol, registry, signingKey) {
|
|
|
5566
5593
|
const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
|
|
5567
5594
|
const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey) : rawAttach;
|
|
5568
5595
|
const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
|
|
5569
|
-
const func = resolveBuffering(functionName);
|
|
5596
|
+
const func = resolveBuffering(functionName, inner.schema_name ?? null);
|
|
5570
5597
|
const bound = new BoundStorage(storage, executionId);
|
|
5571
5598
|
const payload = await bound.stateGet(FrameworkNS.BUFFERING_INIT, BoundStorage.packIntKey(-1));
|
|
5572
5599
|
if (payload == null) {
|
|
@@ -6300,7 +6327,8 @@ function buildVgiProtocol(config) {
|
|
|
6300
6327
|
registerFunctionMethods(protocol, {
|
|
6301
6328
|
registry: config.registry,
|
|
6302
6329
|
recoverExchangeState: config.recoverExchangeState,
|
|
6303
|
-
signingKey: config.signingKey
|
|
6330
|
+
signingKey: config.signingKey,
|
|
6331
|
+
catalogInterface: config.catalogInterface
|
|
6304
6332
|
});
|
|
6305
6333
|
registerAggregateMethods(protocol, config.registry);
|
|
6306
6334
|
registerTableBufferingMethods(protocol, config.registry, config.signingKey);
|
|
@@ -6440,4 +6468,4 @@ export {
|
|
|
6440
6468
|
DEFAULT_PORT
|
|
6441
6469
|
};
|
|
6442
6470
|
|
|
6443
|
-
//# debugId=
|
|
6471
|
+
//# debugId=21DF07825CC8B15864756E2164756E21
|