@query-farm/vgi 0.20.0 → 0.22.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.
Files changed (54) hide show
  1. package/dist/arrow/impl-arrowjs/index.d.ts +7 -0
  2. package/dist/arrow/impl-flechette/arrowjs-shape.d.ts +16 -0
  3. package/dist/arrow/impl-flechette/compat.d.ts +22 -0
  4. package/dist/arrow/impl-flechette/index.d.ts +2 -0
  5. package/dist/arrow/impl-flechette/ipc.d.ts +1 -1
  6. package/dist/arrow/index.d.ts +2 -2
  7. package/dist/arrow/predicates.d.ts +16 -0
  8. package/dist/cache-control.d.ts +33 -0
  9. package/dist/catalog/composite.d.ts +2 -0
  10. package/dist/catalog/interface.d.ts +11 -0
  11. package/dist/client-entry.js +9 -3
  12. package/dist/client-entry.js.map +7 -7
  13. package/dist/functions/registry.d.ts +31 -0
  14. package/dist/functions/scalar.d.ts +7 -3
  15. package/dist/generated/vgi-client.d.ts +16 -0
  16. package/dist/index.core.d.ts +2 -2
  17. package/dist/index.js +175 -19
  18. package/dist/index.js.map +19 -19
  19. package/dist/protocol/handlers/function.d.ts +8 -0
  20. package/dist/protocol/handlers/shared.d.ts +4 -0
  21. package/dist/protocol/types.d.ts +8 -0
  22. package/dist/serve-entry.js +40 -13
  23. package/dist/serve-entry.js.map +10 -10
  24. package/dist/util/arrow/index.d.ts +1 -1
  25. package/dist/worker-cf-entry.js +167 -17
  26. package/dist/worker-cf-entry.js.map +17 -17
  27. package/dist/worker.d.ts +9 -0
  28. package/package.json +5 -5
  29. package/src/arrow/impl-arrowjs/index.ts +10 -0
  30. package/src/arrow/impl-flechette/arrowjs-shape.ts +78 -0
  31. package/src/arrow/impl-flechette/canonical.ts +19 -0
  32. package/src/arrow/impl-flechette/compat.ts +254 -0
  33. package/src/arrow/impl-flechette/empty.ts +5 -1
  34. package/src/arrow/impl-flechette/index.ts +8 -0
  35. package/src/arrow/impl-flechette/ipc.ts +72 -6
  36. package/src/arrow/impl-flechette/normalize-type.ts +10 -2
  37. package/src/arrow/impl-flechette/schema.ts +13 -9
  38. package/src/arrow/index.ts +3 -0
  39. package/src/arrow/predicates.ts +59 -0
  40. package/src/cache-control.ts +35 -0
  41. package/src/catalog/composite.ts +9 -0
  42. package/src/catalog/interface.ts +15 -0
  43. package/src/catalog/read-only.ts +13 -0
  44. package/src/functions/registry.ts +127 -5
  45. package/src/functions/scalar.ts +10 -5
  46. package/src/generated/vgi-client.ts +17 -1
  47. package/src/index.core.ts +4 -0
  48. package/src/protocol/dispatch.ts +1 -0
  49. package/src/protocol/handlers/function.ts +38 -9
  50. package/src/protocol/handlers/shared.ts +25 -1
  51. package/src/protocol/serializers/bind.ts +7 -0
  52. package/src/protocol/types.ts +8 -0
  53. package/src/util/arrow/index.ts +1 -0
  54. 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.
@@ -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;
@@ -639,6 +639,7 @@ __export(exports_impl_arrowjs, {
639
639
  batchFromRows: () => batchFromRows,
640
640
  batchFromColumns: () => batchFromColumns,
641
641
  backend: () => backend,
642
+ adoptArrowJsShape: () => adoptArrowJsShape,
642
643
  UnionMode: () => UnionMode,
643
644
  TimeUnit: () => TimeUnit,
644
645
  IntervalUnit: () => IntervalUnit,
@@ -2275,6 +2276,9 @@ function assemble(columnNames, minData, maxData, hasNull, hasNotNull, distinctCo
2275
2276
 
2276
2277
  // src/arrow/impl-arrowjs/index.ts
2277
2278
  var backend = { name: "arrow-js" };
2279
+ function adoptArrowJsShape(batch) {
2280
+ return batch;
2281
+ }
2278
2282
  // src/arrow/schema-types.ts
2279
2283
  var { TimeUnit: TimeUnit2, DateUnit: DateUnit3, IntervalUnit: IntervalUnit2, UnionMode: UnionMode2, schema: schema2 } = exports_impl_arrowjs;
2280
2284
  function field2(name, type, nullable, metadata) {
@@ -3025,7 +3029,8 @@ var BIND_REQUEST_SCHEMA = schema2([
3025
3029
  field2("transaction_opaque_data", binary2(), true),
3026
3030
  field2("resolved_secrets_provided", bool2(), false),
3027
3031
  field2("at_unit", utf82(), true),
3028
- field2("at_value", utf82(), true)
3032
+ field2("at_value", utf82(), true),
3033
+ field2("schema_name", utf82(), true)
3029
3034
  ]);
3030
3035
  var COPY_FROM_STRUCT_TYPE = struct2([
3031
3036
  field2("format", utf82(), false),
@@ -3093,6 +3098,7 @@ function deserializeBindRequest(params) {
3093
3098
  resolved_secrets_provided: params.resolved_secrets_provided ?? false,
3094
3099
  at_unit: params.at_unit ? String(params.at_unit) : null,
3095
3100
  at_value: params.at_value ? String(params.at_value) : null,
3101
+ schema_name: params.schema_name ? String(params.schema_name) : null,
3096
3102
  copy_from: parseCopyFromContext(params.copy_from),
3097
3103
  copy_to: parseCopyToContext(params.copy_to)
3098
3104
  };
@@ -3918,11 +3924,21 @@ function wrapResult(values, innerSchema) {
3918
3924
  const batch = batchFromColumns(Object.fromEntries(a.fields.map((f) => [f.name, [values[f.name] ?? null]])), a);
3919
3925
  return { result: serializeBatch(batch) };
3920
3926
  }
3921
- 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
+ }
3922
3936
  return {
3923
3937
  arguments: req.arguments,
3924
3938
  inputSchema: req.input_schema,
3925
- isScalar: String(req.function_type).toLowerCase() === "scalar"
3939
+ isScalar: String(req.function_type).toLowerCase() === "scalar",
3940
+ schemaName: req.schema_name ?? null,
3941
+ catalogName
3926
3942
  };
3927
3943
  }
3928
3944
  function recoverFinalizeState(request, recoverExchangeState) {
@@ -4913,7 +4929,7 @@ var columnOpParams = schema2([
4913
4929
 
4914
4930
  // src/protocol/handlers/function.ts
4915
4931
  function registerFunctionMethods(protocol, config) {
4916
- const { registry, signingKey } = config;
4932
+ const { registry, signingKey, catalogInterface } = config;
4917
4933
  async function stripAttach(attach, ctx) {
4918
4934
  if (attach == null)
4919
4935
  return null;
@@ -4922,6 +4938,15 @@ function registerFunctionMethods(protocol, config) {
4922
4938
  return env;
4923
4939
  return openAttach(env, ctx?.auth, signingKey);
4924
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
+ }
4925
4950
  const initHeaderSchema = schema2([
4926
4951
  field2("execution_id", binary2(), false),
4927
4952
  field2("opaque_data", binary2(), true),
@@ -4938,7 +4963,7 @@ function registerFunctionMethods(protocol, config) {
4938
4963
  const innerParams = unwrapRequest(params.request);
4939
4964
  const request = deserializeBindRequest(innerParams);
4940
4965
  request.attach_opaque_data = await stripAttach(request.attach_opaque_data, ctx);
4941
- const func = registry.get(request.function_name, overloadContext(request));
4966
+ const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
4942
4967
  const response = await func.bind(request);
4943
4968
  const serialized = serializeBindResponse(response);
4944
4969
  return wrapResult(serialized, BindResultSchema);
@@ -4953,7 +4978,7 @@ function registerFunctionMethods(protocol, config) {
4953
4978
  const innerParams = unwrapRequest(params.request);
4954
4979
  const request = deserializeInitRequest(innerParams);
4955
4980
  request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
4956
- 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));
4957
4982
  const initResponse = await func.globalInit(request);
4958
4983
  const accumulatedState = recoverFinalizeState(request, config.recoverExchangeState);
4959
4984
  const handlers = func.createStreamHandlers(request, initResponse, accumulatedState);
@@ -4983,6 +5008,7 @@ function registerFunctionMethods(protocol, config) {
4983
5008
  return state;
4984
5009
  },
4985
5010
  exchange: async (state, input, out) => {
5011
+ input = adoptArrowJsShape(input);
4986
5012
  let handlers;
4987
5013
  let handlerState;
4988
5014
  if (state._handlers) {
@@ -4992,7 +5018,7 @@ function registerFunctionMethods(protocol, config) {
4992
5018
  const initRequestBatch = deserializeBatch(state.initRequestIpc);
4993
5019
  const initRequestDict = batchToScalarDict(initRequestBatch);
4994
5020
  const request = deserializeInitRequest(initRequestDict);
4995
- const func = registry.get(state.functionName, overloadContext(request.bind_call));
5021
+ const func = registry.get(state.functionName, await strippedContext(request.bind_call));
4996
5022
  const executionId = state.executionId;
4997
5023
  const opaqueData = state.opaqueData ?? null;
4998
5024
  const initResponse = {
@@ -5040,7 +5066,7 @@ function registerFunctionMethods(protocol, config) {
5040
5066
  handler: async (params) => {
5041
5067
  const innerParams = unwrapRequest(params.request);
5042
5068
  const request = deserializeCardinalityRequest(innerParams);
5043
- const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
5069
+ const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
5044
5070
  let cardResult;
5045
5071
  if (func.cardinality) {
5046
5072
  cardResult = serializeTableCardinality(await func.cardinality(request));
@@ -5053,10 +5079,10 @@ function registerFunctionMethods(protocol, config) {
5053
5079
  protocol.unary("table_function_statistics", {
5054
5080
  params: REQUEST_PARAMS_SCHEMA,
5055
5081
  result: RESULT_BINARY_NULLABLE_SCHEMA,
5056
- handler: (params) => {
5082
+ handler: async (params) => {
5057
5083
  const innerParams = unwrapRequest(params.request);
5058
5084
  const request = deserializeCardinalityRequest(innerParams);
5059
- const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
5085
+ const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
5060
5086
  if (!func.statistics)
5061
5087
  return { result: null };
5062
5088
  const stats = func.statistics(request);
@@ -5076,7 +5102,7 @@ function registerFunctionMethods(protocol, config) {
5076
5102
  const bindCall = deserializeBindRequest(bindParams);
5077
5103
  const globalExecutionId = toUint8Array(innerParams.global_execution_id);
5078
5104
  const bindOpaqueData = innerParams.bind_opaque_data ? toUint8Array(innerParams.bind_opaque_data) : null;
5079
- const func = registry.get(bindCall.function_name, overloadContext(bindCall));
5105
+ const func = registry.get(bindCall.function_name, await strippedContext(bindCall));
5080
5106
  const map3 = func.dynamicToString ? await func.dynamicToString({ bindCall, bindOpaqueData, globalExecutionId }) : {};
5081
5107
  const keys = Object.keys(map3);
5082
5108
  const values = keys.map((k) => map3[k] ?? "");
@@ -6295,7 +6321,8 @@ function buildVgiProtocol(config) {
6295
6321
  registerFunctionMethods(protocol, {
6296
6322
  registry: config.registry,
6297
6323
  recoverExchangeState: config.recoverExchangeState,
6298
- signingKey: config.signingKey
6324
+ signingKey: config.signingKey,
6325
+ catalogInterface: config.catalogInterface
6299
6326
  });
6300
6327
  registerAggregateMethods(protocol, config.registry);
6301
6328
  registerTableBufferingMethods(protocol, config.registry, config.signingKey);
@@ -6435,4 +6462,4 @@ export {
6435
6462
  DEFAULT_PORT
6436
6463
  };
6437
6464
 
6438
- //# debugId=51AA40F4C2F8087064756E2164756E21
6465
+ //# debugId=BAA2DFC0A0256E9E64756E2164756E21