@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
@@ -71,8 +71,8 @@ export declare function buildSplitToken(opts: {
71
71
  payload: Uint8Array;
72
72
  fingerprint: Uint8Array;
73
73
  anchor: Uint8Array;
74
- signingKey?: Uint8Array;
75
- auth?: AuthContext;
74
+ signingKey?: Uint8Array | undefined;
75
+ auth?: AuthContext | undefined;
76
76
  }): Promise<Uint8Array>;
77
77
  /**
78
78
  * Verify a split token and return the worker's payload.
@@ -81,8 +81,8 @@ export declare function buildSplitToken(opts: {
81
81
  * check.
82
82
  */
83
83
  export declare function openSplitToken(token: Uint8Array, opts?: {
84
- signingKey?: Uint8Array;
85
- auth?: AuthContext;
86
- expectedFingerprint?: Uint8Array;
87
- currentAnchor?: Uint8Array;
84
+ signingKey?: Uint8Array | undefined;
85
+ auth?: AuthContext | undefined;
86
+ expectedFingerprint?: Uint8Array | undefined;
87
+ currentAnchor?: Uint8Array | undefined;
88
88
  }): Promise<Uint8Array>;
package/dist/types.d.ts CHANGED
@@ -58,8 +58,15 @@ export declare const VGI_DEFAULT_KEY = "vgi_default";
58
58
  export declare const VGI_CHOICES_KEY = "vgi_choices";
59
59
  export declare const VGI_RANGE_KEY = "vgi_range";
60
60
  export declare const VGI_PATTERN_KEY = "vgi_pattern";
61
+ /**
62
+ * Row-count estimate/upper bound returned by a table function's `cardinality`
63
+ * hook. Both travel as int64 on the wire, so either a `number` (must be an
64
+ * integer) or a `bigint` is accepted — int64 arguments arrive as `bigint`, so
65
+ * `{ estimate: args.count, max: args.count }` works without a `Number(...)`
66
+ * conversion. `null` means unknown.
67
+ */
61
68
  export interface TableCardinality {
62
- estimate: number | null;
63
- max: number | null;
69
+ estimate: number | bigint | null;
70
+ max: number | bigint | null;
64
71
  }
65
72
  export declare const DEFAULT_MAX_WORKERS = 99999;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The type of `T` with every property whose value may be `undefined` made
3
+ * optional and stripped of `undefined` — the shape `omitUndefined` returns.
4
+ * It is assignable to option bags declared `{ k?: V }` under
5
+ * `exactOptionalPropertyTypes`.
6
+ */
7
+ export type OmitUndefined<T> = {
8
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
9
+ } & {
10
+ [K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
11
+ };
12
+ /**
13
+ * Copy `obj` without the keys whose value is `undefined`.
14
+ *
15
+ * Used when forwarding optional settings to an options bag owned by another
16
+ * package (vgi-rpc, Bun) whose optional properties do not admit an explicit
17
+ * `undefined`. Readers of such bags treat an absent key and an `undefined`
18
+ * one identically (`??`, destructuring defaults), so this only changes the
19
+ * static type.
20
+ */
21
+ export declare function omitUndefined<T extends object>(obj: T): OmitUndefined<T>;
@@ -2522,6 +2522,16 @@ var init_storage = __esm(() => {
2522
2522
  });
2523
2523
  });
2524
2524
 
2525
+ // src/util/defined.ts
2526
+ function omitUndefined(obj) {
2527
+ const out = {};
2528
+ for (const [k, v] of Object.entries(obj)) {
2529
+ if (v !== undefined)
2530
+ out[k] = v;
2531
+ }
2532
+ return out;
2533
+ }
2534
+
2525
2535
  // src/http/fetch.ts
2526
2536
  import {
2527
2537
  AuthContext,
@@ -2600,7 +2610,8 @@ function resolveColumn(batch, columnName) {
2600
2610
  throw new FilterV2Error(`filter column ${columnName} is unavailable in emitted batch`);
2601
2611
  }
2602
2612
  const column = batch.getChildAt(index);
2603
- resolved = column ? { type: batch.schema.fields[index].type, column } : null;
2613
+ const field = batch.schema.fields[index];
2614
+ resolved = column && field ? { type: field.type, column } : null;
2604
2615
  byName.set(columnName, resolved);
2605
2616
  }
2606
2617
  return resolved;
@@ -3448,10 +3459,11 @@ class FilterParser {
3448
3459
  if (new Set(names).size !== names.length)
3449
3460
  throw new FilterV2Error("filter payload names must be unique");
3450
3461
  for (let i = 1;i < names.length; i++) {
3451
- if (!PAYLOAD_NAME.test(names[i]))
3452
- throw new FilterV2Error(`noncanonical payload name ${names[i]}`);
3453
- if (names[i].startsWith("type_") && this.valueAt(i) !== null) {
3454
- throw new FilterV2Error(`${names[i]} must contain NULL`);
3462
+ const name = names[i];
3463
+ if (!PAYLOAD_NAME.test(name))
3464
+ throw new FilterV2Error(`noncanonical payload name ${name}`);
3465
+ if (name.startsWith("type_") && this.valueAt(i) !== null) {
3466
+ throw new FilterV2Error(`${name} must contain NULL`);
3455
3467
  }
3456
3468
  }
3457
3469
  this.context = parseContext(batch.schema);
@@ -3464,9 +3476,10 @@ class FilterParser {
3464
3476
  }
3465
3477
  valueAt(index) {
3466
3478
  const column = this.batch.getChildAt(index);
3467
- if (!column)
3479
+ const field = this.batch.schema.fields[index];
3480
+ if (!column || !field)
3468
3481
  throw new FilterV2Error(`missing payload column ${index}`);
3469
- return readCanonicalValue(this.batch.schema.fields[index].type, column, 0);
3482
+ return readCanonicalValue(field.type, column, 0);
3470
3483
  }
3471
3484
  validateContextCapability() {
3472
3485
  if (this.context.profile === NO_EVALUATION_CONTEXT)
@@ -3587,9 +3600,10 @@ class FilterParser {
3587
3600
  const ref = expectUint(rawRef, `${prefix}_ref`);
3588
3601
  const name = `${prefix}_${ref}`;
3589
3602
  const indexes = this.batch.schema.fields.flatMap((field, index) => field.name === name ? [index] : []);
3590
- if (indexes.length !== 1)
3603
+ const index = indexes.length === 1 ? indexes[0] : undefined;
3604
+ if (index === undefined)
3591
3605
  throw new FilterV2Error(`missing or duplicate payload ${name}`);
3592
- return { ref, field: this.batch.schema.fields[indexes[0]], value: this.valueAt(indexes[0]) };
3606
+ return { ref, field: this.batch.schema.fields[index], value: this.valueAt(index) };
3593
3607
  }
3594
3608
  identity(raw, where) {
3595
3609
  const object = expectObject(raw, where);
@@ -3887,9 +3901,10 @@ function decodeFilterDelta(bytes) {
3887
3901
  }
3888
3902
  function deltaRevisionKeys(batch) {
3889
3903
  const column = batch.getChildAt(0);
3890
- if (!column)
3904
+ const field = batch.schema.fields[0];
3905
+ if (!column || !field)
3891
3906
  throw new FilterV2Error("delta document has no filter_spec column");
3892
- const raw = readCanonicalValue(batch.schema.fields[0].type, column, 0);
3907
+ const raw = readCanonicalValue(field.type, column, 0);
3893
3908
  const document = JSON.parse(String(raw));
3894
3909
  return (document.updates ?? []).map((update) => revisionKey(update.id, update.revision));
3895
3910
  }
@@ -4639,10 +4654,19 @@ function deserializeCardinalityRequest(params) {
4639
4654
  bind_opaque_data: params.bind_opaque_data ? toUint8Array2(params.bind_opaque_data) : null
4640
4655
  };
4641
4656
  }
4657
+ function cardinalityValue(name, v) {
4658
+ if (v === null || v === undefined)
4659
+ return null;
4660
+ if (typeof v === "bigint")
4661
+ return v;
4662
+ if (typeof v === "number" && Number.isInteger(v))
4663
+ return BigInt(v);
4664
+ throw new TypeError(`TableCardinality.${name} must be an integer number, a bigint, or null (got ${typeof v}: ${String(v)})`);
4665
+ }
4642
4666
  function serializeTableCardinality(card) {
4643
4667
  return {
4644
- estimate: card.estimate,
4645
- max: card.max
4668
+ estimate: cardinalityValue("estimate", card.estimate),
4669
+ max: cardinalityValue("max", card.max)
4646
4670
  };
4647
4671
  }
4648
4672
  // src/protocol/carried-init-request.ts
@@ -6364,9 +6388,9 @@ function registerVgiService(protocol, service) {
6364
6388
  const common = {
6365
6389
  params: m.params,
6366
6390
  outputSchema: stream.outputSchema,
6367
- headerSchema: m.header ?? undefined,
6368
- headerInit: stream.headerInit,
6369
- onCancel: stream.onCancel,
6391
+ ...m.header ? { headerSchema: m.header } : {},
6392
+ ...stream.headerInit ? { headerInit: stream.headerInit } : {},
6393
+ ...stream.onCancel ? { onCancel: stream.onCancel } : {},
6370
6394
  doc: m.doc
6371
6395
  };
6372
6396
  if (stream.kind === "exchange") {
@@ -10376,13 +10400,14 @@ function functionHandlers(config) {
10376
10400
  } else {
10377
10401
  const carried = parseCarriedInitRequest(state.initRequestPacked);
10378
10402
  const request = carried.request;
10403
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
10379
10404
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
10380
10405
  auth: currentRequestAuth(),
10381
10406
  signingKey,
10382
10407
  catalogInterface,
10383
10408
  checkAnchor: false
10384
10409
  });
10385
- const func = registry.get(state.functionName, await strippedContext(request.bind_call));
10410
+ const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
10386
10411
  const executionId = state.executionId;
10387
10412
  const opaqueData = state.opaqueData ?? null;
10388
10413
  const initResponse = {
@@ -10391,10 +10416,11 @@ function functionHandlers(config) {
10391
10416
  opaque_data: opaqueData
10392
10417
  };
10393
10418
  handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
10419
+ const restored = state.userState != null ? { state: state.userState } : undefined;
10394
10420
  if (handlers.producerInit) {
10395
- handlerState = handlers.producerInit();
10421
+ handlerState = handlers.producerInit(restored);
10396
10422
  } else if (handlers.exchangeInit) {
10397
- handlerState = handlers.exchangeInit();
10423
+ handlerState = handlers.exchangeInit(restored);
10398
10424
  }
10399
10425
  if (state.userState != null && handlerState?.state !== undefined) {
10400
10426
  handlerState.state = state.userState;
@@ -11082,6 +11108,7 @@ function extractArgMap(cfg, args) {
11082
11108
  }
11083
11109
  }
11084
11110
  for (let i = 0;i < constNames.length; i++) {
11111
+ const name = constNames[i];
11085
11112
  let v;
11086
11113
  try {
11087
11114
  v = args.get(i);
@@ -11096,16 +11123,16 @@ function extractArgMap(cfg, args) {
11096
11123
  v = Number(v);
11097
11124
  }
11098
11125
  } catch {
11099
- const def = cfg.argDefaults?.[constNames[i]];
11126
+ const def = cfg.argDefaults?.[name];
11100
11127
  if (def !== undefined)
11101
- out[constNames[i]] = def;
11128
+ out[name] = def;
11102
11129
  continue;
11103
11130
  }
11104
- const constraints = cfg.argConstraints?.[constNames[i]];
11131
+ const constraints = cfg.argConstraints?.[name];
11105
11132
  if (constraints !== undefined) {
11106
- validateConstConstraints(constNames[i], constraints, v);
11133
+ validateConstConstraints(name, constraints, v);
11107
11134
  }
11108
- out[constNames[i]] = v;
11135
+ out[name] = v;
11109
11136
  }
11110
11137
  if (cfg.argDefaults) {
11111
11138
  for (const [name, def] of Object.entries(cfg.argDefaults)) {
@@ -12306,15 +12333,16 @@ class CatalogSnapshotManager {
12306
12333
  validateCatalogPublicationEnvelope(bytes);
12307
12334
  }
12308
12335
  });
12309
- 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)
12336
+ const resultField = resolved.schema.fields.length === 1 ? resolved.schema.fields[0] : undefined;
12337
+ if (resolved.numRows !== 1 || !resultField || resultField.name !== "result" || typeSignature(resultField.type) !== typeSignature(binary2()) || resultField.nullable)
12310
12338
  throw new Error("invalid published RPC envelope");
12311
12339
  const bytes = resolved.getChild("result")?.get(0);
12312
12340
  if (!(bytes instanceof Uint8Array))
12313
12341
  throw new Error("published catalog has no result bytes");
12314
12342
  const decoded = decodeASDCollection(CatalogContentsResultSchema, bytes);
12315
- if (decoded.length !== 1)
12343
+ const response = decoded.length === 1 ? decoded[0] : undefined;
12344
+ if (!response)
12316
12345
  throw new Error("published catalog must contain exactly one response row");
12317
- const response = decoded[0];
12318
12346
  if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag)
12319
12347
  throw new Error("published catalog version or ETag mismatch");
12320
12348
  decodeCatalogStreams(response);
@@ -14029,12 +14057,12 @@ function buildRpcServer(primary, hosting, options) {
14029
14057
  if (tickets)
14030
14058
  protocols.push(tickets);
14031
14059
  }
14032
- return new VgiRpcServer(primary, {
14060
+ return new VgiRpcServer(primary, omitUndefined({
14033
14061
  serverId: options.serverId,
14034
14062
  protocols,
14035
14063
  identity,
14036
14064
  grantKeys: null
14037
- });
14065
+ }));
14038
14066
  }
14039
14067
  function validatedHostedProtocols(hosting, primary) {
14040
14068
  if (hosting.hostedProtocols === undefined)
@@ -14078,13 +14106,13 @@ function buildIdentity(hosting, grantKeys, env) {
14078
14106
  const { resolveToken, mintGrant } = hosting;
14079
14107
  if (!resolveToken && !mintGrant && !grantKeys)
14080
14108
  return;
14081
- return new IdentityImpl({
14109
+ return new IdentityImpl(omitUndefined({
14082
14110
  resolveToken,
14083
14111
  mintGrant,
14084
14112
  grantKeys: grantKeys ?? undefined,
14085
14113
  introspectPrincipals: resolveToken ? resolveIntrospectPrincipals(hosting.introspectPrincipals, env) : undefined,
14086
14114
  maxAuthAge: hosting.maxAuthAge
14087
- });
14115
+ }));
14088
14116
  }
14089
14117
  function buildAttachTickets(hosting, grantKeys, config, env) {
14090
14118
  if (!config || !config.signingKeyConfigured || !config.signingKey)
@@ -14166,7 +14194,7 @@ function createVgiFetch(opts) {
14166
14194
  });
14167
14195
  const reservedCheck = checkReservedAttachOptions(opts.protocol.catalogInterface);
14168
14196
  reservedCheck.catch((e) => console.error(`VGI worker refused to serve: ${e.message}`));
14169
- const handler = createHttpHandler(server, {
14197
+ const handler = createHttpHandler(server, omitUndefined({
14170
14198
  prefix,
14171
14199
  serverId,
14172
14200
  tokenKey: opts.signingKey,
@@ -14181,7 +14209,7 @@ function createVgiFetch(opts) {
14181
14209
  repositoryUrl: opts.repositoryUrl,
14182
14210
  extraRoutes: createLandingRoutes(opts.landingInfo),
14183
14211
  enableLandingPage: false
14184
- });
14212
+ }));
14185
14213
  return async (req) => {
14186
14214
  await reservedCheck;
14187
14215
  const storage = await ensureRequestAuthStorage();
@@ -14410,8 +14438,15 @@ function defineScalarFunction(config) {
14410
14438
  outputSchema,
14411
14439
  inputSchema: inputSchema ?? undefined,
14412
14440
  exchangeInit: () => ({}),
14413
- exchangeFn: (state, input, out) => {
14414
- const result = config.compute(input, constArgs, { settings, secrets, auth: out.auth });
14441
+ exchangeFn: async (state, input, out) => {
14442
+ let result = config.compute(input, constArgs, {
14443
+ settings,
14444
+ secrets,
14445
+ auth: out.auth,
14446
+ bindCall: request.bind_call
14447
+ });
14448
+ if (result != null && typeof result.then === "function")
14449
+ result = await result;
14415
14450
  let outputBatch;
14416
14451
  if (isBatch(result)) {
14417
14452
  outputBatch = result;
@@ -14574,7 +14609,7 @@ function defineTableFunction(config) {
14574
14609
  lookup_names: result.lookupNames
14575
14610
  };
14576
14611
  },
14577
- 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,
14612
+ ...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) } : {},
14578
14613
  async globalInit(request) {
14579
14614
  const executionId = new Uint8Array(16);
14580
14615
  crypto.getRandomValues(executionId);
@@ -14650,11 +14685,10 @@ function defineTableFunction(config) {
14650
14685
  if (request.phase != null) {
14651
14686
  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().`);
14652
14687
  }
14653
- const state = config.initialState ? config.initialState(processParams) : null;
14654
14688
  return {
14655
14689
  outputSchema,
14656
- producerInit: () => ({
14657
- state,
14690
+ producerInit: (restored) => ({
14691
+ state: restored ? restored.state : config.initialState ? config.initialState(processParams) : null,
14658
14692
  processParams,
14659
14693
  filterHistory: carriedFilterHistory
14660
14694
  }),
@@ -14687,55 +14721,63 @@ function defineTableFunction(config) {
14687
14721
  }
14688
14722
  };
14689
14723
  },
14690
- cardinality: config.cardinality ? (request) => {
14691
- const args = extractArgs(request.bind_call);
14692
- const settings = batchToScalarDict(request.bind_call.settings);
14693
- const secrets = batchToSecretDict(request.bind_call.secrets);
14694
- return config.cardinality({
14695
- args,
14696
- bindCall: request.bind_call,
14697
- settings,
14698
- secrets,
14699
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14700
- });
14701
- } : undefined,
14702
- plan: config.plan ? (request) => {
14703
- const args = extractArgs(request.bind_call);
14704
- const settings = batchToScalarDict(request.bind_call.settings);
14705
- const secrets = batchToSecretDict(request.bind_call.secrets);
14706
- return config.plan({
14707
- args,
14708
- bindCall: request.bind_call,
14709
- settings,
14710
- secrets,
14711
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14712
- }, request);
14713
- } : undefined,
14714
- statistics: config.statistics ? (request) => {
14715
- const args = extractArgs(request.bind_call);
14716
- const settings = batchToScalarDict(request.bind_call.settings);
14717
- const secrets = batchToSecretDict(request.bind_call.secrets);
14718
- return config.statistics({
14719
- args,
14720
- bindCall: request.bind_call,
14721
- settings,
14722
- secrets,
14723
- resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14724
- });
14725
- } : undefined,
14726
- dynamicToString: config.dynamicToString ? (request) => {
14727
- const args = extractArgs(request.bindCall);
14728
- const settings = batchToScalarDict(request.bindCall.settings);
14729
- const secrets = batchToSecretDict(request.bindCall.secrets);
14730
- const storage2 = new BoundStorage(storage, request.globalExecutionId);
14731
- return config.dynamicToString({
14732
- args,
14733
- bindCall: request.bindCall,
14734
- settings,
14735
- secrets,
14736
- resolvedSecretsProvided: request.bindCall.resolved_secrets_provided ?? false
14737
- }, request.globalExecutionId, storage2);
14738
- } : undefined
14724
+ ...config.cardinality ? {
14725
+ cardinality: (request) => {
14726
+ const args = extractArgs(request.bind_call);
14727
+ const settings = batchToScalarDict(request.bind_call.settings);
14728
+ const secrets = batchToSecretDict(request.bind_call.secrets);
14729
+ return config.cardinality({
14730
+ args,
14731
+ bindCall: request.bind_call,
14732
+ settings,
14733
+ secrets,
14734
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14735
+ });
14736
+ }
14737
+ } : {},
14738
+ ...config.plan ? {
14739
+ plan: (request) => {
14740
+ const args = extractArgs(request.bind_call);
14741
+ const settings = batchToScalarDict(request.bind_call.settings);
14742
+ const secrets = batchToSecretDict(request.bind_call.secrets);
14743
+ return config.plan({
14744
+ args,
14745
+ bindCall: request.bind_call,
14746
+ settings,
14747
+ secrets,
14748
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14749
+ }, request);
14750
+ }
14751
+ } : {},
14752
+ ...config.statistics ? {
14753
+ statistics: (request) => {
14754
+ const args = extractArgs(request.bind_call);
14755
+ const settings = batchToScalarDict(request.bind_call.settings);
14756
+ const secrets = batchToSecretDict(request.bind_call.secrets);
14757
+ return config.statistics({
14758
+ args,
14759
+ bindCall: request.bind_call,
14760
+ settings,
14761
+ secrets,
14762
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
14763
+ });
14764
+ }
14765
+ } : {},
14766
+ ...config.dynamicToString ? {
14767
+ dynamicToString: (request) => {
14768
+ const args = extractArgs(request.bindCall);
14769
+ const settings = batchToScalarDict(request.bindCall.settings);
14770
+ const secrets = batchToSecretDict(request.bindCall.secrets);
14771
+ const storage2 = new BoundStorage(storage, request.globalExecutionId);
14772
+ return config.dynamicToString({
14773
+ args,
14774
+ bindCall: request.bindCall,
14775
+ settings,
14776
+ secrets,
14777
+ resolvedSecretsProvided: request.bindCall.resolved_secrets_provided ?? false
14778
+ }, request.globalExecutionId, storage2);
14779
+ }
14780
+ } : {}
14739
14781
  };
14740
14782
  }
14741
14783
  // src/functions/table-in-out.ts
@@ -14763,7 +14805,8 @@ function defineTableInOutFunction(config) {
14763
14805
  name: "data",
14764
14806
  position: posIdx++,
14765
14807
  arrowType: nullType2(),
14766
- isTableInput: true
14808
+ isTableInput: true,
14809
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
14767
14810
  });
14768
14811
  if (config.namedArgs) {
14769
14812
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -14897,7 +14940,7 @@ function defineTableInOutFunction(config) {
14897
14940
  for (const bytes of stored) {
14898
14941
  finalizeStates.push(deserializeUserState(bytes));
14899
14942
  }
14900
- if (finalizeStates.length === 0) {
14943
+ if (finalizeStates.length === 0 && config.finalize) {
14901
14944
  finalizeStates.push(config.initialState ? config.initialState(processParams) : null);
14902
14945
  }
14903
14946
  const batches = config.finalize ? await config.finalize(processParams, finalizeStates) : [];
@@ -14920,7 +14963,7 @@ function defineTableInOutFunction(config) {
14920
14963
  if (request.bind_call.input_schema == null) {
14921
14964
  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().`);
14922
14965
  }
14923
- const state = config.initialState ? config.initialState(processParams) : null;
14966
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
14924
14967
  const processFn = config.process ?? ((_params, _state, batch, out) => {
14925
14968
  out.emit(projIds ? projectBatch(projIds, batch) : batch);
14926
14969
  });
@@ -14928,7 +14971,12 @@ function defineTableInOutFunction(config) {
14928
14971
  outputSchema,
14929
14972
  inputSchema: request.bind_call.input_schema,
14930
14973
  continuesOutput: true,
14931
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
14974
+ exchangeInit: (restored) => ({
14975
+ state: restored ? restored.state : freshState(),
14976
+ processParams,
14977
+ filterHistory: carriedFilterHistory,
14978
+ morePending: false
14979
+ }),
14932
14980
  exchangeFn: async (eState, input, out) => {
14933
14981
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
14934
14982
  applyRevalidationValidators(eState.processParams, input);
@@ -15182,12 +15230,17 @@ function defineRowTransformFunction(config) {
15182
15230
  if (request.bind_call.input_schema == null) {
15183
15231
  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().`);
15184
15232
  }
15185
- const state = config.initialState ? config.initialState(processParams) : null;
15233
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
15186
15234
  return {
15187
15235
  outputSchema,
15188
15236
  inputSchema: request.bind_call.input_schema,
15189
15237
  continuesOutput: true,
15190
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
15238
+ exchangeInit: (restored) => ({
15239
+ state: restored ? restored.state : freshState(),
15240
+ processParams,
15241
+ filterHistory: carriedFilterHistory,
15242
+ morePending: false
15243
+ }),
15191
15244
  exchangeFn: async (eState, input, out) => {
15192
15245
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
15193
15246
  applyRevalidationValidators(eState.processParams, input);
@@ -15436,8 +15489,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15436
15489
  for (const tbl of sch.tables ?? []) {
15437
15490
  for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"]) {
15438
15491
  const fn = tbl[key];
15439
- if (fn)
15440
- registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
15492
+ if (!fn)
15493
+ continue;
15494
+ registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
15495
+ registry.register(fn);
15441
15496
  }
15442
15497
  }
15443
15498
  }
@@ -15453,14 +15508,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15453
15508
  return [this._descriptor.name];
15454
15509
  }
15455
15510
  attachOptionSpecs(_name) {
15456
- return [];
15511
+ return this._descriptor.attachOptions ?? [];
15457
15512
  }
15458
15513
  catalogsInfo() {
15459
15514
  return [{
15460
15515
  name: this._descriptor.name,
15461
15516
  implementation_version: null,
15462
15517
  data_version_spec: null,
15463
- attach_option_specs: [],
15518
+ attach_option_specs: serializeAttachOptionSpecs(this.attachOptionSpecs(this._descriptor.name)),
15464
15519
  releases: [],
15465
15520
  source_url: this._descriptor.sourceUrl ?? null
15466
15521
  }];
@@ -15640,12 +15695,13 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15640
15695
  if (typeof part !== "string" || !part || part.includes("\x00"))
15641
15696
  throw new Error("invalid requiredFilters component");
15642
15697
  const matches = fields.filter((f) => f.name === part);
15643
- if (matches.length !== 1)
15698
+ const match = matches.length === 1 ? matches[0] : undefined;
15699
+ if (!match)
15644
15700
  throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
15645
15701
  if (i + 1 < path.length) {
15646
- if (!isStruct(matches[0].type))
15702
+ if (!isStruct(match.type))
15647
15703
  throw new Error(`non-struct requiredFilters parent: ${part}`);
15648
- fields = matches[0].type.children;
15704
+ fields = match.type.children;
15649
15705
  }
15650
15706
  }
15651
15707
  }
@@ -16203,7 +16259,7 @@ class CompositeCatalogInterface extends CatalogInterface {
16203
16259
  }
16204
16260
  _route(attachOpaqueData) {
16205
16261
  const idx = attachOpaqueData[ROUTE_BYTE];
16206
- const route = this._backends[idx];
16262
+ const route = idx === undefined ? undefined : this._backends[idx];
16207
16263
  if (!route) {
16208
16264
  throw new OpaqueDataRejectedError("attach_opaque_data");
16209
16265
  }
@@ -16532,10 +16588,12 @@ class FunctionRegistry {
16532
16588
  _byCatalog = new Map;
16533
16589
  register(func) {
16534
16590
  const name = func.meta.name;
16535
- if (!this._functions.has(name)) {
16536
- this._functions.set(name, []);
16591
+ const bucket = this._functions.get(name);
16592
+ if (!bucket) {
16593
+ this._functions.set(name, [func]);
16594
+ } else if (!bucket.includes(func)) {
16595
+ bucket.push(func);
16537
16596
  }
16538
- this._functions.get(name).push(func);
16539
16597
  }
16540
16598
  registerInSchema(func, schemaPath, catalogName) {
16541
16599
  const add = (map, key) => {
@@ -16856,4 +16914,4 @@ export {
16856
16914
  validateTableConstraints
16857
16915
  };
16858
16916
 
16859
- //# debugId=BAA5461FE644FC2564756E2164756E21
16917
+ //# debugId=F8503787BE8D309164756E2164756E21