@query-farm/vgi 0.48.0 → 0.48.2

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 (98) hide show
  1. package/README.md +24 -1
  2. package/dist/arguments/argument-spec.d.ts +17 -11
  3. package/dist/catalog/descriptors.d.ts +16 -2
  4. package/dist/catalog/publication.d.ts +7 -7
  5. package/dist/catalog/read-only.d.ts +4 -5
  6. package/dist/client/client.d.ts +9 -3
  7. package/dist/client/errors.d.ts +2 -2
  8. package/dist/client/types.d.ts +21 -0
  9. package/dist/client-entry.d.ts +1 -1
  10. package/dist/client-entry.js +31 -7
  11. package/dist/client-entry.js.map +20 -20
  12. package/dist/filter-pushdown/deserialize.d.ts +1 -1
  13. package/dist/filter-pushdown/types.d.ts +10 -10
  14. package/dist/functions/registry.d.ts +1 -0
  15. package/dist/functions/scalar.d.ts +17 -6
  16. package/dist/functions/table-buffering.d.ts +20 -20
  17. package/dist/functions/table-in-out.d.ts +4 -4
  18. package/dist/functions/table.d.ts +7 -7
  19. package/dist/functions/types.d.ts +51 -47
  20. package/dist/http/fetch.d.ts +10 -10
  21. package/dist/index.core.d.ts +2 -2
  22. package/dist/index.js +201 -116
  23. package/dist/index.js.map +53 -52
  24. package/dist/protocol/dispatch.d.ts +3 -3
  25. package/dist/protocol/handlers/function.d.ts +2 -2
  26. package/dist/protocol/serializers/cardinality.d.ts +4 -1
  27. package/dist/protocol/types.d.ts +5 -5
  28. package/dist/rpc-server.d.ts +6 -6
  29. package/dist/serve-entry.d.ts +16 -16
  30. package/dist/serve-entry.js +47 -24
  31. package/dist/serve-entry.js.map +38 -37
  32. package/dist/split-token.d.ts +6 -6
  33. package/dist/types.d.ts +9 -2
  34. package/dist/util/defined.d.ts +21 -0
  35. package/dist/worker-cf-entry.js +164 -106
  36. package/dist/worker-cf-entry.js.map +51 -50
  37. package/dist/worker.d.ts +2 -2
  38. package/package.json +6 -4
  39. package/src/arguments/argument-spec.ts +17 -11
  40. package/src/arrow/codec/registry.ts +2 -2
  41. package/src/arrow/impl-arrowjs/build.ts +1 -1
  42. package/src/arrow/impl-arrowjs/canonical.ts +23 -23
  43. package/src/arrow/impl-arrowjs/empty.ts +2 -2
  44. package/src/arrow/impl-arrowjs/ipc.ts +2 -2
  45. package/src/arrow/impl-arrowjs/iterate.ts +2 -2
  46. package/src/arrow/impl-arrowjs/project.ts +2 -2
  47. package/src/arrow/impl-flechette/build.ts +2 -1
  48. package/src/arrow/impl-flechette/canonical.ts +10 -9
  49. package/src/arrow/impl-flechette/compat.ts +3 -3
  50. package/src/arrow/impl-flechette/message-meta.ts +5 -4
  51. package/src/arrow/impl-flechette/statistics.ts +2 -2
  52. package/src/attach-ticket.ts +2 -2
  53. package/src/catalog/column-metadata.ts +1 -1
  54. package/src/catalog/composite.ts +2 -2
  55. package/src/catalog/constraints.ts +9 -9
  56. package/src/catalog/descriptors.ts +15 -1
  57. package/src/catalog/interface.ts +12 -12
  58. package/src/catalog/publication.ts +9 -8
  59. package/src/catalog/read-only.ts +27 -21
  60. package/src/catalog/sql-grammar.ts +6 -6
  61. package/src/client/client.ts +52 -15
  62. package/src/client/errors.ts +1 -1
  63. package/src/client/types.ts +23 -0
  64. package/src/client-entry.ts +2 -0
  65. package/src/codec/asd.ts +3 -3
  66. package/src/codec/conform.ts +3 -3
  67. package/src/filter-pushdown/collector.ts +1 -1
  68. package/src/filter-pushdown/deserialize.ts +13 -10
  69. package/src/filter-pushdown/evaluate.ts +3 -2
  70. package/src/filter-pushdown/history.ts +3 -2
  71. package/src/filter-pushdown/types.ts +10 -10
  72. package/src/functions/continuation.ts +1 -1
  73. package/src/functions/projection.ts +1 -1
  74. package/src/functions/registry.ts +20 -17
  75. package/src/functions/scalar.ts +33 -11
  76. package/src/functions/storage-cf-do.ts +2 -2
  77. package/src/functions/table-buffering.ts +28 -21
  78. package/src/functions/table-in-out.ts +37 -17
  79. package/src/functions/table.ts +36 -31
  80. package/src/functions/types.ts +58 -48
  81. package/src/generated/vgi-service.ts +5 -3
  82. package/src/http/fetch.ts +17 -12
  83. package/src/index.core.ts +3 -1
  84. package/src/protocol/carried-init-request.ts +1 -1
  85. package/src/protocol/dispatch.ts +3 -3
  86. package/src/protocol/handlers/aggregate.ts +8 -7
  87. package/src/protocol/handlers/catalog/shared.ts +1 -1
  88. package/src/protocol/handlers/function.ts +18 -5
  89. package/src/protocol/serializers/cardinality.ts +16 -3
  90. package/src/protocol/state-serializer.ts +1 -1
  91. package/src/protocol/types.ts +5 -5
  92. package/src/rpc-server.ts +13 -12
  93. package/src/serve-entry.ts +18 -18
  94. package/src/split-token.ts +10 -9
  95. package/src/types.ts +9 -2
  96. package/src/util/defined.ts +30 -0
  97. package/src/util/parent-rows.ts +2 -2
  98. package/src/worker.ts +15 -14
package/dist/index.js CHANGED
@@ -3155,8 +3155,15 @@ function defineScalarFunction(config) {
3155
3155
  outputSchema,
3156
3156
  inputSchema: inputSchema ?? undefined,
3157
3157
  exchangeInit: () => ({}),
3158
- exchangeFn: (state, input, out) => {
3159
- const result = config.compute(input, constArgs, { settings, secrets, auth: out.auth });
3158
+ exchangeFn: async (state, input, out) => {
3159
+ let result = config.compute(input, constArgs, {
3160
+ settings,
3161
+ secrets,
3162
+ auth: out.auth,
3163
+ bindCall: request.bind_call
3164
+ });
3165
+ if (result != null && typeof result.then === "function")
3166
+ result = await result;
3160
3167
  let outputBatch;
3161
3168
  if (isBatch(result)) {
3162
3169
  outputBatch = result;
@@ -3496,10 +3503,11 @@ class FilterParser {
3496
3503
  if (new Set(names).size !== names.length)
3497
3504
  throw new FilterV2Error("filter payload names must be unique");
3498
3505
  for (let i = 1;i < names.length; i++) {
3499
- if (!PAYLOAD_NAME.test(names[i]))
3500
- throw new FilterV2Error(`noncanonical payload name ${names[i]}`);
3501
- if (names[i].startsWith("type_") && this.valueAt(i) !== null) {
3502
- throw new FilterV2Error(`${names[i]} must contain NULL`);
3506
+ const name = names[i];
3507
+ if (!PAYLOAD_NAME.test(name))
3508
+ throw new FilterV2Error(`noncanonical payload name ${name}`);
3509
+ if (name.startsWith("type_") && this.valueAt(i) !== null) {
3510
+ throw new FilterV2Error(`${name} must contain NULL`);
3503
3511
  }
3504
3512
  }
3505
3513
  this.context = parseContext(batch.schema);
@@ -3512,9 +3520,10 @@ class FilterParser {
3512
3520
  }
3513
3521
  valueAt(index) {
3514
3522
  const column = this.batch.getChildAt(index);
3515
- if (!column)
3523
+ const field = this.batch.schema.fields[index];
3524
+ if (!column || !field)
3516
3525
  throw new FilterV2Error(`missing payload column ${index}`);
3517
- return readCanonicalValue(this.batch.schema.fields[index].type, column, 0);
3526
+ return readCanonicalValue(field.type, column, 0);
3518
3527
  }
3519
3528
  validateContextCapability() {
3520
3529
  if (this.context.profile === NO_EVALUATION_CONTEXT)
@@ -3635,9 +3644,10 @@ class FilterParser {
3635
3644
  const ref = expectUint(rawRef, `${prefix}_ref`);
3636
3645
  const name = `${prefix}_${ref}`;
3637
3646
  const indexes = this.batch.schema.fields.flatMap((field, index) => field.name === name ? [index] : []);
3638
- if (indexes.length !== 1)
3647
+ const index = indexes.length === 1 ? indexes[0] : undefined;
3648
+ if (index === undefined)
3639
3649
  throw new FilterV2Error(`missing or duplicate payload ${name}`);
3640
- return { ref, field: this.batch.schema.fields[indexes[0]], value: this.valueAt(indexes[0]) };
3650
+ return { ref, field: this.batch.schema.fields[index], value: this.valueAt(index) };
3641
3651
  }
3642
3652
  identity(raw, where) {
3643
3653
  const object = expectObject(raw, where);
@@ -3926,7 +3936,8 @@ function resolveColumn(batch, columnName) {
3926
3936
  throw new FilterV2Error(`filter column ${columnName} is unavailable in emitted batch`);
3927
3937
  }
3928
3938
  const column = batch.getChildAt(index);
3929
- resolved = column ? { type: batch.schema.fields[index].type, column } : null;
3939
+ const field = batch.schema.fields[index];
3940
+ resolved = column && field ? { type: field.type, column } : null;
3930
3941
  byName.set(columnName, resolved);
3931
3942
  }
3932
3943
  return resolved;
@@ -4526,9 +4537,10 @@ function decodeFilterDelta(bytes) {
4526
4537
  }
4527
4538
  function deltaRevisionKeys(batch) {
4528
4539
  const column = batch.getChildAt(0);
4529
- if (!column)
4540
+ const field = batch.schema.fields[0];
4541
+ if (!column || !field)
4530
4542
  throw new FilterV2Error("delta document has no filter_spec column");
4531
- const raw = readCanonicalValue(batch.schema.fields[0].type, column, 0);
4543
+ const raw = readCanonicalValue(field.type, column, 0);
4532
4544
  const document = JSON.parse(String(raw));
4533
4545
  return (document.updates ?? []).map((update) => revisionKey(update.id, update.revision));
4534
4546
  }
@@ -4928,7 +4940,7 @@ function defineTableFunction(config) {
4928
4940
  lookup_names: result.lookupNames
4929
4941
  };
4930
4942
  },
4931
- projection: config.projection ? (proposal) => config.projection({ args: extractArgs(proposal.bindCall), bindCall: proposal.bindCall, settings: batchToScalarDict(proposal.bindCall.settings), secrets: batchToSecretDict(proposal.bindCall.secrets), resolvedSecretsProvided: proposal.bindCall.resolved_secrets_provided }, proposal) : undefined,
4943
+ ...config.projection ? { projection: (proposal) => config.projection({ args: extractArgs(proposal.bindCall), bindCall: proposal.bindCall, settings: batchToScalarDict(proposal.bindCall.settings), secrets: batchToSecretDict(proposal.bindCall.secrets), resolvedSecretsProvided: proposal.bindCall.resolved_secrets_provided }, proposal) } : {},
4932
4944
  async globalInit(request) {
4933
4945
  const executionId = new Uint8Array(16);
4934
4946
  crypto.getRandomValues(executionId);
@@ -5004,11 +5016,10 @@ function defineTableFunction(config) {
5004
5016
  if (request.phase != null) {
5005
5017
  throw new Error(`${config.name}: is a plain table function (it takes no input row ` + `stream) but was called with an init phase set -- call it via ` + `table_function(), not table_in_out_function().`);
5006
5018
  }
5007
- const state = config.initialState ? config.initialState(processParams) : null;
5008
5019
  return {
5009
5020
  outputSchema,
5010
- producerInit: () => ({
5011
- state,
5021
+ producerInit: (restored) => ({
5022
+ state: restored ? restored.state : config.initialState ? config.initialState(processParams) : null,
5012
5023
  processParams,
5013
5024
  filterHistory: carriedFilterHistory
5014
5025
  }),
@@ -5041,55 +5052,63 @@ function defineTableFunction(config) {
5041
5052
  }
5042
5053
  };
5043
5054
  },
5044
- cardinality: config.cardinality ? (request) => {
5045
- const args = extractArgs(request.bind_call);
5046
- const settings = batchToScalarDict(request.bind_call.settings);
5047
- const secrets = batchToSecretDict(request.bind_call.secrets);
5048
- return config.cardinality({
5049
- args,
5050
- bindCall: request.bind_call,
5051
- settings,
5052
- secrets,
5053
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5054
- });
5055
- } : undefined,
5056
- plan: config.plan ? (request) => {
5057
- const args = extractArgs(request.bind_call);
5058
- const settings = batchToScalarDict(request.bind_call.settings);
5059
- const secrets = batchToSecretDict(request.bind_call.secrets);
5060
- return config.plan({
5061
- args,
5062
- bindCall: request.bind_call,
5063
- settings,
5064
- secrets,
5065
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5066
- }, request);
5067
- } : undefined,
5068
- statistics: config.statistics ? (request) => {
5069
- const args = extractArgs(request.bind_call);
5070
- const settings = batchToScalarDict(request.bind_call.settings);
5071
- const secrets = batchToSecretDict(request.bind_call.secrets);
5072
- return config.statistics({
5073
- args,
5074
- bindCall: request.bind_call,
5075
- settings,
5076
- secrets,
5077
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5078
- });
5079
- } : undefined,
5080
- dynamicToString: config.dynamicToString ? (request) => {
5081
- const args = extractArgs(request.bindCall);
5082
- const settings = batchToScalarDict(request.bindCall.settings);
5083
- const secrets = batchToSecretDict(request.bindCall.secrets);
5084
- const storage2 = new BoundStorage(storage, request.globalExecutionId);
5085
- return config.dynamicToString({
5086
- args,
5087
- bindCall: request.bindCall,
5088
- settings,
5089
- secrets,
5090
- resolvedSecretsProvided: request.bindCall.resolved_secrets_provided ?? false
5091
- }, request.globalExecutionId, storage2);
5092
- } : undefined
5055
+ ...config.cardinality ? {
5056
+ cardinality: (request) => {
5057
+ const args = extractArgs(request.bind_call);
5058
+ const settings = batchToScalarDict(request.bind_call.settings);
5059
+ const secrets = batchToSecretDict(request.bind_call.secrets);
5060
+ return config.cardinality({
5061
+ args,
5062
+ bindCall: request.bind_call,
5063
+ settings,
5064
+ secrets,
5065
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5066
+ });
5067
+ }
5068
+ } : {},
5069
+ ...config.plan ? {
5070
+ plan: (request) => {
5071
+ const args = extractArgs(request.bind_call);
5072
+ const settings = batchToScalarDict(request.bind_call.settings);
5073
+ const secrets = batchToSecretDict(request.bind_call.secrets);
5074
+ return config.plan({
5075
+ args,
5076
+ bindCall: request.bind_call,
5077
+ settings,
5078
+ secrets,
5079
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5080
+ }, request);
5081
+ }
5082
+ } : {},
5083
+ ...config.statistics ? {
5084
+ statistics: (request) => {
5085
+ const args = extractArgs(request.bind_call);
5086
+ const settings = batchToScalarDict(request.bind_call.settings);
5087
+ const secrets = batchToSecretDict(request.bind_call.secrets);
5088
+ return config.statistics({
5089
+ args,
5090
+ bindCall: request.bind_call,
5091
+ settings,
5092
+ secrets,
5093
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
5094
+ });
5095
+ }
5096
+ } : {},
5097
+ ...config.dynamicToString ? {
5098
+ dynamicToString: (request) => {
5099
+ const args = extractArgs(request.bindCall);
5100
+ const settings = batchToScalarDict(request.bindCall.settings);
5101
+ const secrets = batchToSecretDict(request.bindCall.secrets);
5102
+ const storage2 = new BoundStorage(storage, request.globalExecutionId);
5103
+ return config.dynamicToString({
5104
+ args,
5105
+ bindCall: request.bindCall,
5106
+ settings,
5107
+ secrets,
5108
+ resolvedSecretsProvided: request.bindCall.resolved_secrets_provided ?? false
5109
+ }, request.globalExecutionId, storage2);
5110
+ }
5111
+ } : {}
5093
5112
  };
5094
5113
  }
5095
5114
  // src/functions/aggregate.ts
@@ -6008,10 +6027,19 @@ function deserializeCardinalityRequest(params) {
6008
6027
  bind_opaque_data: params.bind_opaque_data ? toUint8Array2(params.bind_opaque_data) : null
6009
6028
  };
6010
6029
  }
6030
+ function cardinalityValue(name, v) {
6031
+ if (v === null || v === undefined)
6032
+ return null;
6033
+ if (typeof v === "bigint")
6034
+ return v;
6035
+ if (typeof v === "number" && Number.isInteger(v))
6036
+ return BigInt(v);
6037
+ throw new TypeError(`TableCardinality.${name} must be an integer number, a bigint, or null (got ${typeof v}: ${String(v)})`);
6038
+ }
6011
6039
  function serializeTableCardinality(card) {
6012
6040
  return {
6013
- estimate: card.estimate,
6014
- max: card.max
6041
+ estimate: cardinalityValue("estimate", card.estimate),
6042
+ max: cardinalityValue("max", card.max)
6015
6043
  };
6016
6044
  }
6017
6045
  // src/protocol/carried-init-request.ts
@@ -6381,7 +6409,8 @@ function defineTableInOutFunction(config) {
6381
6409
  name: "data",
6382
6410
  position: posIdx++,
6383
6411
  arrowType: nullType2(),
6384
- isTableInput: true
6412
+ isTableInput: true,
6413
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
6385
6414
  });
6386
6415
  if (config.namedArgs) {
6387
6416
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -6515,7 +6544,7 @@ function defineTableInOutFunction(config) {
6515
6544
  for (const bytes of stored) {
6516
6545
  finalizeStates.push(deserializeUserState(bytes));
6517
6546
  }
6518
- if (finalizeStates.length === 0) {
6547
+ if (finalizeStates.length === 0 && config.finalize) {
6519
6548
  finalizeStates.push(config.initialState ? config.initialState(processParams) : null);
6520
6549
  }
6521
6550
  const batches = config.finalize ? await config.finalize(processParams, finalizeStates) : [];
@@ -6538,7 +6567,7 @@ function defineTableInOutFunction(config) {
6538
6567
  if (request.bind_call.input_schema == null) {
6539
6568
  throw new Error(`${config.name}: is a table-in-out function (it requires an input row ` + `stream) but no input schema was supplied -- call it via ` + `table_in_out_function(input=...), not table_function().`);
6540
6569
  }
6541
- const state = config.initialState ? config.initialState(processParams) : null;
6570
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
6542
6571
  const processFn = config.process ?? ((_params, _state, batch, out) => {
6543
6572
  out.emit(projIds ? projectBatch(projIds, batch) : batch);
6544
6573
  });
@@ -6546,7 +6575,12 @@ function defineTableInOutFunction(config) {
6546
6575
  outputSchema,
6547
6576
  inputSchema: request.bind_call.input_schema,
6548
6577
  continuesOutput: true,
6549
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
6578
+ exchangeInit: (restored) => ({
6579
+ state: restored ? restored.state : freshState(),
6580
+ processParams,
6581
+ filterHistory: carriedFilterHistory,
6582
+ morePending: false
6583
+ }),
6550
6584
  exchangeFn: async (eState, input, out) => {
6551
6585
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
6552
6586
  applyRevalidationValidators(eState.processParams, input);
@@ -6800,12 +6834,17 @@ function defineRowTransformFunction(config) {
6800
6834
  if (request.bind_call.input_schema == null) {
6801
6835
  throw new Error(`${config.name}: is a table-in-out function (its positional args are ` + `per-row input columns) but no input schema was supplied -- call it ` + `via table_in_out_function(input=...), not table_function().`);
6802
6836
  }
6803
- const state = config.initialState ? config.initialState(processParams) : null;
6837
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
6804
6838
  return {
6805
6839
  outputSchema,
6806
6840
  inputSchema: request.bind_call.input_schema,
6807
6841
  continuesOutput: true,
6808
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
6842
+ exchangeInit: (restored) => ({
6843
+ state: restored ? restored.state : freshState(),
6844
+ processParams,
6845
+ filterHistory: carriedFilterHistory,
6846
+ morePending: false
6847
+ }),
6809
6848
  exchangeFn: async (eState, input, out) => {
6810
6849
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
6811
6850
  applyRevalidationValidators(eState.processParams, input);
@@ -6856,7 +6895,8 @@ function defineTableBufferingFunction(config) {
6856
6895
  name: "data",
6857
6896
  position: posIdx++,
6858
6897
  arrowType: nullType2(),
6859
- isTableInput: true
6898
+ isTableInput: true,
6899
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
6860
6900
  });
6861
6901
  if (config.namedArgs) {
6862
6902
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -11274,8 +11314,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11274
11314
  for (const tbl of sch.tables ?? []) {
11275
11315
  for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"]) {
11276
11316
  const fn = tbl[key];
11277
- if (fn)
11278
- registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
11317
+ if (!fn)
11318
+ continue;
11319
+ registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
11320
+ registry.register(fn);
11279
11321
  }
11280
11322
  }
11281
11323
  }
@@ -11291,14 +11333,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11291
11333
  return [this._descriptor.name];
11292
11334
  }
11293
11335
  attachOptionSpecs(_name) {
11294
- return [];
11336
+ return this._descriptor.attachOptions ?? [];
11295
11337
  }
11296
11338
  catalogsInfo() {
11297
11339
  return [{
11298
11340
  name: this._descriptor.name,
11299
11341
  implementation_version: null,
11300
11342
  data_version_spec: null,
11301
- attach_option_specs: [],
11343
+ attach_option_specs: serializeAttachOptionSpecs(this.attachOptionSpecs(this._descriptor.name)),
11302
11344
  releases: [],
11303
11345
  source_url: this._descriptor.sourceUrl ?? null
11304
11346
  }];
@@ -11478,12 +11520,13 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11478
11520
  if (typeof part !== "string" || !part || part.includes("\x00"))
11479
11521
  throw new Error("invalid requiredFilters component");
11480
11522
  const matches = fields.filter((f) => f.name === part);
11481
- if (matches.length !== 1)
11523
+ const match = matches.length === 1 ? matches[0] : undefined;
11524
+ if (!match)
11482
11525
  throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
11483
11526
  if (i + 1 < path.length) {
11484
- if (!isStruct(matches[0].type))
11527
+ if (!isStruct(match.type))
11485
11528
  throw new Error(`non-struct requiredFilters parent: ${part}`);
11486
- fields = matches[0].type.children;
11529
+ fields = match.type.children;
11487
11530
  }
11488
11531
  }
11489
11532
  }
@@ -12828,7 +12871,7 @@ class CompositeCatalogInterface extends CatalogInterface {
12828
12871
  }
12829
12872
  _route(attachOpaqueData) {
12830
12873
  const idx = attachOpaqueData[ROUTE_BYTE];
12831
- const route = this._backends[idx];
12874
+ const route = idx === undefined ? undefined : this._backends[idx];
12832
12875
  if (!route) {
12833
12876
  throw new OpaqueDataRejectedError("attach_opaque_data");
12834
12877
  }
@@ -13157,10 +13200,12 @@ class FunctionRegistry {
13157
13200
  _byCatalog = new Map;
13158
13201
  register(func) {
13159
13202
  const name = func.meta.name;
13160
- if (!this._functions.has(name)) {
13161
- this._functions.set(name, []);
13203
+ const bucket = this._functions.get(name);
13204
+ if (!bucket) {
13205
+ this._functions.set(name, [func]);
13206
+ } else if (!bucket.includes(func)) {
13207
+ bucket.push(func);
13162
13208
  }
13163
- this._functions.get(name).push(func);
13164
13209
  }
13165
13210
  registerInSchema(func, schemaPath, catalogName) {
13166
13211
  const add = (map, key) => {
@@ -14967,9 +15012,9 @@ function registerVgiService(protocol, service) {
14967
15012
  const common = {
14968
15013
  params: m.params,
14969
15014
  outputSchema: stream.outputSchema,
14970
- headerSchema: m.header ?? undefined,
14971
- headerInit: stream.headerInit,
14972
- onCancel: stream.onCancel,
15015
+ ...m.header ? { headerSchema: m.header } : {},
15016
+ ...stream.headerInit ? { headerInit: stream.headerInit } : {},
15017
+ ...stream.onCancel ? { onCancel: stream.onCancel } : {},
14973
15018
  doc: m.doc
14974
15019
  };
14975
15020
  if (stream.kind === "exchange") {
@@ -15579,13 +15624,14 @@ function functionHandlers(config) {
15579
15624
  } else {
15580
15625
  const carried = parseCarriedInitRequest(state.initRequestPacked);
15581
15626
  const request = carried.request;
15627
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
15582
15628
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
15583
15629
  auth: currentRequestAuth(),
15584
15630
  signingKey,
15585
15631
  catalogInterface,
15586
15632
  checkAnchor: false
15587
15633
  });
15588
- const func = registry.get(state.functionName, await strippedContext(request.bind_call));
15634
+ const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
15589
15635
  const executionId = state.executionId;
15590
15636
  const opaqueData = state.opaqueData ?? null;
15591
15637
  const initResponse = {
@@ -15594,10 +15640,11 @@ function functionHandlers(config) {
15594
15640
  opaque_data: opaqueData
15595
15641
  };
15596
15642
  handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
15643
+ const restored = state.userState != null ? { state: state.userState } : undefined;
15597
15644
  if (handlers.producerInit) {
15598
- handlerState = handlers.producerInit();
15645
+ handlerState = handlers.producerInit(restored);
15599
15646
  } else if (handlers.exchangeInit) {
15600
- handlerState = handlers.exchangeInit();
15647
+ handlerState = handlers.exchangeInit(restored);
15601
15648
  }
15602
15649
  if (state.userState != null && handlerState?.state !== undefined) {
15603
15650
  handlerState.state = state.userState;
@@ -15933,6 +15980,7 @@ function extractArgMap(cfg, args) {
15933
15980
  }
15934
15981
  }
15935
15982
  for (let i = 0;i < constNames.length; i++) {
15983
+ const name = constNames[i];
15936
15984
  let v;
15937
15985
  try {
15938
15986
  v = args.get(i);
@@ -15947,16 +15995,16 @@ function extractArgMap(cfg, args) {
15947
15995
  v = Number(v);
15948
15996
  }
15949
15997
  } catch {
15950
- const def = cfg.argDefaults?.[constNames[i]];
15998
+ const def = cfg.argDefaults?.[name];
15951
15999
  if (def !== undefined)
15952
- out[constNames[i]] = def;
16000
+ out[name] = def;
15953
16001
  continue;
15954
16002
  }
15955
- const constraints = cfg.argConstraints?.[constNames[i]];
16003
+ const constraints = cfg.argConstraints?.[name];
15956
16004
  if (constraints !== undefined) {
15957
- validateConstConstraints(constNames[i], constraints, v);
16005
+ validateConstConstraints(name, constraints, v);
15958
16006
  }
15959
- out[constNames[i]] = v;
16007
+ out[name] = v;
15960
16008
  }
15961
16009
  if (cfg.argDefaults) {
15962
16010
  for (const [name, def] of Object.entries(cfg.argDefaults)) {
@@ -16501,15 +16549,16 @@ class CatalogSnapshotManager {
16501
16549
  validateCatalogPublicationEnvelope(bytes);
16502
16550
  }
16503
16551
  });
16504
- if (resolved.numRows !== 1 || resolved.schema.fields.length !== 1 || resolved.schema.fields[0].name !== "result" || typeSignature(resolved.schema.fields[0].type) !== typeSignature(binary2()) || resolved.schema.fields[0].nullable)
16552
+ const resultField = resolved.schema.fields.length === 1 ? resolved.schema.fields[0] : undefined;
16553
+ if (resolved.numRows !== 1 || !resultField || resultField.name !== "result" || typeSignature(resultField.type) !== typeSignature(binary2()) || resultField.nullable)
16505
16554
  throw new Error("invalid published RPC envelope");
16506
16555
  const bytes = resolved.getChild("result")?.get(0);
16507
16556
  if (!(bytes instanceof Uint8Array))
16508
16557
  throw new Error("published catalog has no result bytes");
16509
16558
  const decoded = decodeASDCollection(CatalogContentsResultSchema, bytes);
16510
- if (decoded.length !== 1)
16559
+ const response = decoded.length === 1 ? decoded[0] : undefined;
16560
+ if (!response)
16511
16561
  throw new Error("published catalog must contain exactly one response row");
16512
- const response = decoded[0];
16513
16562
  if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag)
16514
16563
  throw new Error("published catalog version or ETag mismatch");
16515
16564
  decodeCatalogStreams(response);
@@ -17961,6 +18010,26 @@ function toAsyncIterator(input) {
17961
18010
  }
17962
18011
 
17963
18012
  // src/client/client.ts
18013
+ function int64ColumnNames(s) {
18014
+ if (!s)
18015
+ return [];
18016
+ return s.fields.filter((f) => isInt(f.type) && f.type.bitWidth === 64).map((f) => f.name);
18017
+ }
18018
+ var MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
18019
+ var MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
18020
+ function applyInt64Mode(rows, columns, mode) {
18021
+ for (const row of rows) {
18022
+ for (const name of columns) {
18023
+ const v = row[name];
18024
+ if (mode === "bigint") {
18025
+ if (typeof v === "number" && Number.isInteger(v))
18026
+ row[name] = BigInt(v);
18027
+ } else if (typeof v === "bigint" && v >= MIN_SAFE_BIGINT && v <= MAX_SAFE_BIGINT) {
18028
+ row[name] = Number(v);
18029
+ }
18030
+ }
18031
+ }
18032
+ }
17964
18033
  function onConflictName(onConflict) {
17965
18034
  return String(onConflict).toUpperCase();
17966
18035
  }
@@ -18252,10 +18321,14 @@ class VgiClient {
18252
18321
  tablesample: opts.tablesample,
18253
18322
  joinKeys: opts.joinKeys
18254
18323
  });
18324
+ const int64Columns = opts.int64 === undefined ? [] : int64ColumnNames(bindResp.output_schema);
18255
18325
  try {
18256
18326
  for await (const rows of session) {
18257
- if (rows.length > 0)
18258
- yield rows;
18327
+ if (rows.length === 0)
18328
+ continue;
18329
+ if (int64Columns.length > 0)
18330
+ applyInt64Mode(rows, int64Columns, opts.int64);
18331
+ yield rows;
18259
18332
  }
18260
18333
  } finally {
18261
18334
  session.close();
@@ -18497,7 +18570,7 @@ class VgiClient {
18497
18570
  return null;
18498
18571
  const inner = unwrapResult(result);
18499
18572
  const items = deserializeInfoList(inner.items, decodeSchemaInfo);
18500
- return items.length > 0 ? items[0] : null;
18573
+ return items[0] ?? null;
18501
18574
  }
18502
18575
  async schemaCreate(attachOpaqueData, path, opts) {
18503
18576
  const tagsMap = opts?.tags ? new Map(Object.entries(opts.tags)) : null;
@@ -18575,7 +18648,7 @@ class VgiClient {
18575
18648
  return null;
18576
18649
  const inner = unwrapResult(result);
18577
18650
  const items = deserializeInfoList(inner.items, decodeTableInfo);
18578
- return items.length > 0 ? items[0] : null;
18651
+ return items[0] ?? null;
18579
18652
  }
18580
18653
  async tableCreate(attachOpaqueData, schemaPath, name, columns, onConflict, constraintDefinitions = [], transactionOpaqueData) {
18581
18654
  await this.rpc.call("catalog_table_create", {
@@ -18743,7 +18816,7 @@ class VgiClient {
18743
18816
  return null;
18744
18817
  const inner = unwrapResult(result);
18745
18818
  const items = deserializeInfoList(inner.items, decodeViewInfo);
18746
- return items.length > 0 ? items[0] : null;
18819
+ return items[0] ?? null;
18747
18820
  }
18748
18821
  async viewCreate(attachOpaqueData, schemaPath, name, definition, onConflict, transactionOpaqueData, aliases, security = "regular", comment, tags, columnComments) {
18749
18822
  await this.rpc.call("catalog_view_create", {
@@ -18812,7 +18885,7 @@ class VgiClient {
18812
18885
  return null;
18813
18886
  const inner = unwrapResult(result);
18814
18887
  const items = deserializeInfoList(inner.items, decodeMacroInfo);
18815
- return items.length > 0 ? items[0] : null;
18888
+ return items[0] ?? null;
18816
18889
  }
18817
18890
  async schemaContentsMacros(attachOpaqueData, path, type, transactionOpaqueData) {
18818
18891
  const result = await this.rpc.call("catalog_schema_contents_macros", {
@@ -18862,6 +18935,18 @@ import {
18862
18935
  IdentityImpl,
18863
18936
  VgiRpcServer
18864
18937
  } from "@query-farm/vgi-rpc";
18938
+
18939
+ // src/util/defined.ts
18940
+ function omitUndefined(obj) {
18941
+ const out = {};
18942
+ for (const [k, v] of Object.entries(obj)) {
18943
+ if (v !== undefined)
18944
+ out[k] = v;
18945
+ }
18946
+ return out;
18947
+ }
18948
+
18949
+ // src/rpc-server.ts
18865
18950
  var TRANSPORTS = new Set(["pipe", "unix", "tcp", "iroh", "stream", "http"]);
18866
18951
  var IDENTITY_TRANSPORTS = new Set(["http"]);
18867
18952
  var RESERVED_PREFIX = "vgi_rpc.";
@@ -18880,12 +18965,12 @@ function buildRpcServer(primary, hosting, options) {
18880
18965
  if (tickets)
18881
18966
  protocols.push(tickets);
18882
18967
  }
18883
- return new VgiRpcServer(primary, {
18968
+ return new VgiRpcServer(primary, omitUndefined({
18884
18969
  serverId: options.serverId,
18885
18970
  protocols,
18886
18971
  identity,
18887
18972
  grantKeys: null
18888
- });
18973
+ }));
18889
18974
  }
18890
18975
  function validatedHostedProtocols(hosting, primary) {
18891
18976
  if (hosting.hostedProtocols === undefined)
@@ -18929,13 +19014,13 @@ function buildIdentity(hosting, grantKeys, env) {
18929
19014
  const { resolveToken, mintGrant } = hosting;
18930
19015
  if (!resolveToken && !mintGrant && !grantKeys)
18931
19016
  return;
18932
- return new IdentityImpl({
19017
+ return new IdentityImpl(omitUndefined({
18933
19018
  resolveToken,
18934
19019
  mintGrant,
18935
19020
  grantKeys: grantKeys ?? undefined,
18936
19021
  introspectPrincipals: resolveToken ? resolveIntrospectPrincipals(hosting.introspectPrincipals, env) : undefined,
18937
19022
  maxAuthAge: hosting.maxAuthAge
18938
- });
19023
+ }));
18939
19024
  }
18940
19025
  function buildAttachTickets(hosting, grantKeys, config, env) {
18941
19026
  if (!config || !config.signingKeyConfigured || !config.signingKey)
@@ -19117,10 +19202,10 @@ class Worker {
19117
19202
  const envOverride = process.env.VGI_WORKER_IDLE_TIMEOUT;
19118
19203
  const idleTimeout = envOverride !== undefined && envOverride !== "" ? Number(envOverride) : launcher.idleTimeout;
19119
19204
  debug(() => `[worker] AF_UNIX mode: ${launcher.unixPath} idle=${idleTimeout ?? 300}s${envOverride !== undefined && envOverride !== "" ? " (env override)" : ""}`);
19120
- serveUnix(this.buildServer(protocol, "unix"), {
19205
+ serveUnix(this.buildServer(protocol, "unix"), omitUndefined({
19121
19206
  unixPath: launcher.unixPath,
19122
19207
  idleTimeout
19123
- }).then((handle) => handle.done).then(() => {
19208
+ })).then((handle) => handle.done).then(() => {
19124
19209
  debug(() => `[worker] serveUnix done (idle shutdown)`);
19125
19210
  }).catch((err) => {
19126
19211
  process.stderr.write(`Worker error: ${err.message}
@@ -19134,7 +19219,7 @@ ${err.stack}
19134
19219
  const envOverride = process.env.VGI_WORKER_IDLE_TIMEOUT;
19135
19220
  const idleTimeout = envOverride !== undefined && envOverride !== "" ? Number(envOverride) : launcher.idleTimeout;
19136
19221
  debug(() => `[worker] TCP mode: ${launcher.tcpHost}:${launcher.tcpPort} idle=${idleTimeout ?? 300}s${envOverride !== undefined && envOverride !== "" ? " (env override)" : ""}`);
19137
- serveTcp(this.buildServer(protocol, launcher.irohRawUpstream ? "iroh" : "tcp"), {
19222
+ serveTcp(this.buildServer(protocol, launcher.irohRawUpstream ? "iroh" : "tcp"), omitUndefined({
19138
19223
  host: launcher.tcpHost,
19139
19224
  port: launcher.tcpPort,
19140
19225
  idleTimeout,
@@ -19144,7 +19229,7 @@ ${err.stack}
19144
19229
  irohProxyIssuer: launcher.irohIssuer,
19145
19230
  peerAuthenticationPolicy: launcher.irohAuthenticate ? peerIdentityPrimary("iroh") : observePeerIdentity
19146
19231
  } : {}
19147
- }).then((handle) => handle.done).then(() => {
19232
+ })).then((handle) => handle.done).then(() => {
19148
19233
  debug(() => `[worker] serveTcp done (idle shutdown)`);
19149
19234
  }).catch((err) => {
19150
19235
  process.stderr.write(`Worker error: ${err.message}
@@ -19182,7 +19267,7 @@ ${err.stack}
19182
19267
  });
19183
19268
  }
19184
19269
  async serveStream(readable, writable) {
19185
- await serveStreamRpc(this.buildServer(this.buildProtocol(), "stream"), { readable, writable });
19270
+ await serveStreamRpc(this.buildServer(this.buildProtocol(), "stream"), omitUndefined({ readable, writable }));
19186
19271
  }
19187
19272
  }
19188
19273
  // src/catalog/s3-publication.ts
@@ -19639,4 +19724,4 @@ export {
19639
19724
  validateTableConstraints
19640
19725
  };
19641
19726
 
19642
- //# debugId=67FF9BC53B3C318564756E2164756E21
19727
+ //# debugId=0D39EB7B8CA153F964756E2164756E21