@query-farm/vgi 0.48.1 → 0.48.3

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 (49) hide show
  1. package/README.md +51 -1
  2. package/dist/arrow/impl-arrowjs/iterate.d.ts +7 -3
  3. package/dist/arrow/impl-flechette/iterate.d.ts +2 -1
  4. package/dist/catalog/descriptors.d.ts +14 -0
  5. package/dist/catalog/read-only.d.ts +4 -5
  6. package/dist/client-entry.js +9 -25
  7. package/dist/client-entry.js.map +3 -3
  8. package/dist/functions/aggregate.d.ts +2 -1
  9. package/dist/functions/copy-from.d.ts +2 -1
  10. package/dist/functions/copy-to.d.ts +2 -1
  11. package/dist/functions/registry.d.ts +1 -0
  12. package/dist/functions/scalar.d.ts +18 -6
  13. package/dist/functions/table-buffering.d.ts +2 -1
  14. package/dist/functions/table-in-out.d.ts +3 -2
  15. package/dist/functions/table.d.ts +2 -1
  16. package/dist/functions/types.d.ts +8 -3
  17. package/dist/index.core.d.ts +3 -2
  18. package/dist/index.js +177 -61
  19. package/dist/index.js.map +21 -20
  20. package/dist/metadata/types.d.ts +3 -1
  21. package/dist/secrets/helpers.d.ts +31 -3
  22. package/dist/secrets/requirements.d.ts +38 -0
  23. package/dist/serve-entry.js +14 -28
  24. package/dist/serve-entry.js.map +6 -6
  25. package/dist/worker-cf-entry.d.ts +2 -2
  26. package/dist/worker-cf-entry.js +205 -53
  27. package/dist/worker-cf-entry.js.map +18 -16
  28. package/package.json +1 -1
  29. package/src/arrow/impl-arrowjs/iterate.ts +17 -40
  30. package/src/arrow/impl-flechette/iterate.ts +5 -24
  31. package/src/catalog/descriptors.ts +14 -0
  32. package/src/catalog/read-only.ts +24 -16
  33. package/src/functions/aggregate.ts +3 -2
  34. package/src/functions/copy-from.ts +3 -2
  35. package/src/functions/copy-to.ts +2 -1
  36. package/src/functions/registry.ts +6 -3
  37. package/src/functions/scalar.ts +33 -10
  38. package/src/functions/table-buffering.ts +6 -2
  39. package/src/functions/table-in-out.ts +34 -13
  40. package/src/functions/table.ts +12 -8
  41. package/src/functions/types.ts +15 -4
  42. package/src/index.core.ts +11 -1
  43. package/src/metadata/resolve.ts +2 -1
  44. package/src/metadata/serialize.ts +25 -5
  45. package/src/metadata/types.ts +3 -1
  46. package/src/protocol/handlers/function.ts +16 -3
  47. package/src/secrets/helpers.ts +96 -9
  48. package/src/secrets/requirements.ts +121 -0
  49. package/src/worker-cf-entry.ts +14 -0
package/dist/index.js CHANGED
@@ -1554,30 +1554,14 @@ function batchToSecretDict(batch) {
1554
1554
  const result = {};
1555
1555
  for (const field of a.schema.fields) {
1556
1556
  const col = a.getChild(field.name);
1557
- if (col) {
1558
- const type = field.type;
1559
- const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1560
- let key = field.name;
1561
- let scope;
1562
- if (field.name.startsWith("secret_")) {
1563
- const secretType = field.metadata?.get?.("secret_type");
1564
- if (secretType) {
1565
- key = secretType;
1566
- scope = field.metadata?.get?.("scope") ?? undefined;
1567
- }
1568
- }
1569
- if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1570
- const dict = { ...val };
1571
- if (key in result) {
1572
- throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
1573
- }
1574
- result[key] = dict;
1575
- if (scope) {
1576
- result[`${key}:${scope}`] = dict;
1577
- }
1578
- } else if (val === null || val === undefined) {} else {
1579
- result[key] = {};
1580
- }
1557
+ if (!col)
1558
+ continue;
1559
+ const type = field.type;
1560
+ const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1561
+ if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1562
+ result[field.name] = { ...val };
1563
+ } else if (val !== null && val !== undefined) {
1564
+ result[field.name] = {};
1581
1565
  }
1582
1566
  }
1583
1567
  return result;
@@ -2623,6 +2607,65 @@ function cacheControlMetadata(cc, extra) {
2623
2607
  md.set(CACHE_PER_VALUE_KEY, "1");
2624
2608
  return md;
2625
2609
  }
2610
+ // src/secrets/requirements.ts
2611
+ var KNOWN_KEYS = new Set(["secretType", "secret_type", "scope", "secretName", "secret_name"]);
2612
+ function optionalString(value, what, where) {
2613
+ if (value === undefined || value === null)
2614
+ return null;
2615
+ if (typeof value !== "string") {
2616
+ throw new TypeError(`${where}: ${what} must be a string, got ${typeof value}`);
2617
+ }
2618
+ return value === "" ? null : value;
2619
+ }
2620
+ function normalizeRequiredSecrets(value, functionName = "<function>") {
2621
+ if (value === undefined || value === null)
2622
+ return [];
2623
+ const where = `requiredSecrets of '${functionName}'`;
2624
+ if (!Array.isArray(value)) {
2625
+ throw new TypeError(`${where} must be an array of secret types or { secretType, scope?, secretName? } objects, got ${typeof value}`);
2626
+ }
2627
+ const out = [];
2628
+ const seen = new Set;
2629
+ value.forEach((entry, i) => {
2630
+ const at = `${where}[${i}]`;
2631
+ let req;
2632
+ if (typeof entry === "string") {
2633
+ if (entry === "")
2634
+ throw new TypeError(`${at}: secret type must not be empty`);
2635
+ req = { secretType: entry, scope: null, secretName: null };
2636
+ } else if (entry !== null && typeof entry === "object" && !Array.isArray(entry)) {
2637
+ const obj = entry;
2638
+ const unknown = Object.keys(obj).filter((k) => !KNOWN_KEYS.has(k));
2639
+ if (unknown.length > 0) {
2640
+ throw new TypeError(`${at}: unknown key(s) ${unknown.map((k) => `'${k}'`).join(", ")}; ` + `expected secretType, scope, secretName`);
2641
+ }
2642
+ if (obj.secretType !== undefined && obj.secret_type !== undefined && obj.secretType !== obj.secret_type) {
2643
+ throw new TypeError(`${at}: secretType and secret_type disagree`);
2644
+ }
2645
+ if (obj.secretName !== undefined && obj.secret_name !== undefined && obj.secretName !== obj.secret_name) {
2646
+ throw new TypeError(`${at}: secretName and secret_name disagree`);
2647
+ }
2648
+ const secretType = obj.secretType ?? obj.secret_type;
2649
+ if (typeof secretType !== "string" || secretType === "") {
2650
+ throw new TypeError(`${at}: secretType must be a non-empty string`);
2651
+ }
2652
+ req = {
2653
+ secretType,
2654
+ scope: optionalString(obj.scope, "scope", at),
2655
+ secretName: optionalString(obj.secretName ?? obj.secret_name, "secretName", at)
2656
+ };
2657
+ } else {
2658
+ throw new TypeError(`${at}: expected a secret type string or a { secretType, scope?, secretName? } object, got ` + (entry === null ? "null" : Array.isArray(entry) ? "array" : typeof entry));
2659
+ }
2660
+ const key = JSON.stringify([req.secretType, req.scope, req.secretName]);
2661
+ if (seen.has(key))
2662
+ return;
2663
+ seen.add(key);
2664
+ out.push(req);
2665
+ });
2666
+ return out;
2667
+ }
2668
+
2626
2669
  // src/functions/scalar.ts
2627
2670
  init_arrow();
2628
2671
 
@@ -3084,7 +3127,7 @@ function defineScalarFunction(config) {
3084
3127
  parameterDefaultValues: config.parameterDefaultValues,
3085
3128
  maxWorkers: config.maxWorkers,
3086
3129
  requiredSettings: config.requiredSettings,
3087
- requiredSecrets: config.requiredSecrets
3130
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
3088
3131
  };
3089
3132
  const defaultOutputSchema = config.returns ? schema2([field2("result", config.returns, true)]) : schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]);
3090
3133
  return {
@@ -3155,8 +3198,15 @@ function defineScalarFunction(config) {
3155
3198
  outputSchema,
3156
3199
  inputSchema: inputSchema ?? undefined,
3157
3200
  exchangeInit: () => ({}),
3158
- exchangeFn: (state, input, out) => {
3159
- const result = config.compute(input, constArgs, { settings, secrets, auth: out.auth });
3201
+ exchangeFn: async (state, input, out) => {
3202
+ let result = config.compute(input, constArgs, {
3203
+ settings,
3204
+ secrets,
3205
+ auth: out.auth,
3206
+ bindCall: request.bind_call
3207
+ });
3208
+ if (result != null && typeof result.then === "function")
3209
+ result = await result;
3160
3210
  let outputBatch;
3161
3211
  if (isBatch(result)) {
3162
3212
  outputBatch = result;
@@ -4879,7 +4929,7 @@ function defineTableFunction(config) {
4879
4929
  parameterDefaultValues: config.parameterDefaultValues,
4880
4930
  maxWorkers: config.maxWorkers,
4881
4931
  requiredSettings: config.requiredSettings,
4882
- requiredSecrets: config.requiredSecrets,
4932
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
4883
4933
  preservesOrder: config.preservesOrder,
4884
4934
  nullHandling: config.nullHandling,
4885
4935
  orderDependent: config.orderDependent,
@@ -5009,11 +5059,10 @@ function defineTableFunction(config) {
5009
5059
  if (request.phase != null) {
5010
5060
  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().`);
5011
5061
  }
5012
- const state = config.initialState ? config.initialState(processParams) : null;
5013
5062
  return {
5014
5063
  outputSchema,
5015
- producerInit: () => ({
5016
- state,
5064
+ producerInit: (restored) => ({
5065
+ state: restored ? restored.state : config.initialState ? config.initialState(processParams) : null,
5017
5066
  processParams,
5018
5067
  filterHistory: carriedFilterHistory
5019
5068
  }),
@@ -5251,7 +5300,7 @@ function defineAggregate(config) {
5251
5300
  tags: config.tags,
5252
5301
  parameterDefaultValues: config.parameterDefaultValues,
5253
5302
  nullHandling: config.nullHandling,
5254
- requiredSecrets: config.requiredSecrets
5303
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
5255
5304
  };
5256
5305
  const isAnyType = isNull(config.outputType);
5257
5306
  const defaultOutputSchema = isAnyType ? schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]) : schema2([field2("result", config.outputType, true)]);
@@ -6403,7 +6452,8 @@ function defineTableInOutFunction(config) {
6403
6452
  name: "data",
6404
6453
  position: posIdx++,
6405
6454
  arrowType: nullType2(),
6406
- isTableInput: true
6455
+ isTableInput: true,
6456
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
6407
6457
  });
6408
6458
  if (config.namedArgs) {
6409
6459
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -6429,7 +6479,7 @@ function defineTableInOutFunction(config) {
6429
6479
  parameterDefaultValues: config.parameterDefaultValues,
6430
6480
  maxWorkers: config.maxWorkers,
6431
6481
  requiredSettings: config.requiredSettings,
6432
- requiredSecrets: config.requiredSecrets,
6482
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6433
6483
  hasFinalize: !!config.finalize
6434
6484
  };
6435
6485
  function extractArgs(request) {
@@ -6537,7 +6587,7 @@ function defineTableInOutFunction(config) {
6537
6587
  for (const bytes of stored) {
6538
6588
  finalizeStates.push(deserializeUserState(bytes));
6539
6589
  }
6540
- if (finalizeStates.length === 0) {
6590
+ if (finalizeStates.length === 0 && config.finalize) {
6541
6591
  finalizeStates.push(config.initialState ? config.initialState(processParams) : null);
6542
6592
  }
6543
6593
  const batches = config.finalize ? await config.finalize(processParams, finalizeStates) : [];
@@ -6560,7 +6610,7 @@ function defineTableInOutFunction(config) {
6560
6610
  if (request.bind_call.input_schema == null) {
6561
6611
  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().`);
6562
6612
  }
6563
- const state = config.initialState ? config.initialState(processParams) : null;
6613
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
6564
6614
  const processFn = config.process ?? ((_params, _state, batch, out) => {
6565
6615
  out.emit(projIds ? projectBatch(projIds, batch) : batch);
6566
6616
  });
@@ -6568,7 +6618,12 @@ function defineTableInOutFunction(config) {
6568
6618
  outputSchema,
6569
6619
  inputSchema: request.bind_call.input_schema,
6570
6620
  continuesOutput: true,
6571
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
6621
+ exchangeInit: (restored) => ({
6622
+ state: restored ? restored.state : freshState(),
6623
+ processParams,
6624
+ filterHistory: carriedFilterHistory,
6625
+ morePending: false
6626
+ }),
6572
6627
  exchangeFn: async (eState, input, out) => {
6573
6628
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
6574
6629
  applyRevalidationValidators(eState.processParams, input);
@@ -6734,7 +6789,7 @@ function defineRowTransformFunction(config) {
6734
6789
  parameterDefaultValues: config.parameterDefaultValues,
6735
6790
  maxWorkers: config.maxWorkers,
6736
6791
  requiredSettings: config.requiredSettings,
6737
- requiredSecrets: config.requiredSecrets,
6792
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6738
6793
  hasFinalize: false,
6739
6794
  inputFromArgs: true,
6740
6795
  inputRowsPerCall
@@ -6822,12 +6877,17 @@ function defineRowTransformFunction(config) {
6822
6877
  if (request.bind_call.input_schema == null) {
6823
6878
  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().`);
6824
6879
  }
6825
- const state = config.initialState ? config.initialState(processParams) : null;
6880
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
6826
6881
  return {
6827
6882
  outputSchema,
6828
6883
  inputSchema: request.bind_call.input_schema,
6829
6884
  continuesOutput: true,
6830
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
6885
+ exchangeInit: (restored) => ({
6886
+ state: restored ? restored.state : freshState(),
6887
+ processParams,
6888
+ filterHistory: carriedFilterHistory,
6889
+ morePending: false
6890
+ }),
6831
6891
  exchangeFn: async (eState, input, out) => {
6832
6892
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
6833
6893
  applyRevalidationValidators(eState.processParams, input);
@@ -6878,7 +6938,8 @@ function defineTableBufferingFunction(config) {
6878
6938
  name: "data",
6879
6939
  position: posIdx++,
6880
6940
  arrowType: nullType2(),
6881
- isTableInput: true
6941
+ isTableInput: true,
6942
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
6882
6943
  });
6883
6944
  if (config.namedArgs) {
6884
6945
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -6904,7 +6965,7 @@ function defineTableBufferingFunction(config) {
6904
6965
  parameterDefaultValues: config.parameterDefaultValues,
6905
6966
  maxWorkers: config.maxWorkers,
6906
6967
  requiredSettings: config.requiredSettings,
6907
- requiredSecrets: config.requiredSecrets,
6968
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6908
6969
  hasFinalize: true,
6909
6970
  sinkOrderDependent: config.sinkOrderDependent,
6910
6971
  sourceOrderDependent: config.sourceOrderDependent,
@@ -7176,7 +7237,7 @@ function defineCopyFromFunction(config) {
7176
7237
  tags: config.tags,
7177
7238
  examples: config.examples,
7178
7239
  requiredSettings: config.requiredSettings,
7179
- requiredSecrets: config.requiredSecrets,
7240
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
7180
7241
  copyFromFormat: config.format,
7181
7242
  copyFromDirection: config.direction ?? "from",
7182
7243
  copyFromComment: config.comment ?? null
@@ -11033,7 +11094,7 @@ function resolveMetadata(func) {
11033
11094
  nullHandling: meta.nullHandling ?? "DEFAULT" /* DEFAULT */,
11034
11095
  argumentMonotonicity,
11035
11096
  requiredSettings: meta.requiredSettings ?? [],
11036
- requiredSecrets: meta.requiredSecrets ?? [],
11097
+ requiredSecrets: normalizeRequiredSecrets(meta.requiredSecrets, meta.name),
11037
11098
  projectionPushdown: meta.projectionPushdown ?? false,
11038
11099
  filterPushdown: meta.filterPushdown ?? false,
11039
11100
  samplingPushdown: meta.samplingPushdown ?? false,
@@ -11296,8 +11357,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11296
11357
  for (const tbl of sch.tables ?? []) {
11297
11358
  for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"]) {
11298
11359
  const fn = tbl[key];
11299
- if (fn)
11300
- registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
11360
+ if (!fn)
11361
+ continue;
11362
+ registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
11363
+ registry.register(fn);
11301
11364
  }
11302
11365
  }
11303
11366
  }
@@ -11313,14 +11376,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11313
11376
  return [this._descriptor.name];
11314
11377
  }
11315
11378
  attachOptionSpecs(_name) {
11316
- return [];
11379
+ return this._descriptor.attachOptions ?? [];
11317
11380
  }
11318
11381
  catalogsInfo() {
11319
11382
  return [{
11320
11383
  name: this._descriptor.name,
11321
11384
  implementation_version: null,
11322
11385
  data_version_spec: null,
11323
- attach_option_specs: [],
11386
+ attach_option_specs: serializeAttachOptionSpecs(this.attachOptionSpecs(this._descriptor.name)),
11324
11387
  releases: [],
11325
11388
  source_url: this._descriptor.sourceUrl ?? null
11326
11389
  }];
@@ -11622,7 +11685,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11622
11685
  }
11623
11686
  }
11624
11687
  const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
11625
- const requiredSecrets = (meta.requiredSecrets ?? []).map((secretType) => ({ secret_type: secretType, scope: null, secret_name: null }));
11688
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
11689
+ secret_type: s.secretType,
11690
+ scope: s.scope,
11691
+ secret_name: s.secretName
11692
+ }));
11626
11693
  const derivedTags = {};
11627
11694
  const tags = { ...derivedTags, ...meta.tags ?? {} };
11628
11695
  return {
@@ -13180,10 +13247,12 @@ class FunctionRegistry {
13180
13247
  _byCatalog = new Map;
13181
13248
  register(func) {
13182
13249
  const name = func.meta.name;
13183
- if (!this._functions.has(name)) {
13184
- this._functions.set(name, []);
13250
+ const bucket = this._functions.get(name);
13251
+ if (!bucket) {
13252
+ this._functions.set(name, [func]);
13253
+ } else if (!bucket.includes(func)) {
13254
+ bucket.push(func);
13185
13255
  }
13186
- this._functions.get(name).push(func);
13187
13256
  }
13188
13257
  registerInSchema(func, schemaPath, catalogName) {
13189
13258
  const add = (map, key) => {
@@ -13345,6 +13414,11 @@ var FILTER_CONTEXT_STRUCT = struct2([
13345
13414
  field2("profile", utf82(), false),
13346
13415
  field2("provider_fingerprint", utf82(), true)
13347
13416
  ]);
13417
+ var SECRET_REQUIREMENT_STRUCT = struct2([
13418
+ field2("secret_type", utf82(), false),
13419
+ field2("secret_name", utf82(), true),
13420
+ field2("scope", utf82(), true)
13421
+ ]);
13348
13422
  var METADATA_SCHEMA = schema2([
13349
13423
  field2("name", utf82(), false),
13350
13424
  field2("class_name", utf82(), false),
@@ -13358,7 +13432,7 @@ var METADATA_SCHEMA = schema2([
13358
13432
  field2("null_handling", utf82(), false),
13359
13433
  field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
13360
13434
  field2("required_settings", list2(field2("item", utf82(), true)), false),
13361
- field2("required_secrets", list2(field2("item", utf82(), true)), false),
13435
+ field2("required_secrets", list2(field2("item", SECRET_REQUIREMENT_STRUCT, true)), false),
13362
13436
  field2("projection_pushdown", bool2(), false),
13363
13437
  field2("filter_pushdown", bool2(), false),
13364
13438
  field2("filter_semantic_profiles", list2(field2("item", utf82(), true)), false),
@@ -13400,7 +13474,11 @@ function metadataToRow(m) {
13400
13474
  null_handling: m.nullHandling,
13401
13475
  argument_monotonicity: m.argumentMonotonicity,
13402
13476
  required_settings: m.requiredSettings,
13403
- required_secrets: m.requiredSecrets,
13477
+ required_secrets: m.requiredSecrets.map((s) => ({
13478
+ secret_type: s.secretType,
13479
+ secret_name: s.secretName,
13480
+ scope: s.scope
13481
+ })),
13404
13482
  projection_pushdown: m.projectionPushdown,
13405
13483
  filter_pushdown: m.filterPushdown,
13406
13484
  sampling_pushdown: m.samplingPushdown,
@@ -13493,7 +13571,7 @@ function arrowToMetadatas(batch) {
13493
13571
  const rawRequiredSettings = get("required_settings") ?? [];
13494
13572
  const requiredSettings = rawRequiredSettings ? [...rawRequiredSettings].filter((s) => s != null) : [];
13495
13573
  const rawRequiredSecrets = get("required_secrets") ?? [];
13496
- const requiredSecrets = rawRequiredSecrets ? [...rawRequiredSecrets].filter((s) => s != null) : [];
13574
+ const requiredSecrets = normalizeRequiredSecrets(rawRequiredSecrets ? [...rawRequiredSecrets].filter((s) => s != null).map((s) => typeof s === "string" ? s : { secretType: s.secret_type, secretName: s.secret_name ?? null, scope: s.scope ?? null }) : [], get("name") ?? "<function>");
13497
13575
  results.push({
13498
13576
  name: get("name") ?? "",
13499
13577
  className: get("class_name") ?? "",
@@ -15602,13 +15680,14 @@ function functionHandlers(config) {
15602
15680
  } else {
15603
15681
  const carried = parseCarriedInitRequest(state.initRequestPacked);
15604
15682
  const request = carried.request;
15683
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
15605
15684
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
15606
15685
  auth: currentRequestAuth(),
15607
15686
  signingKey,
15608
15687
  catalogInterface,
15609
15688
  checkAnchor: false
15610
15689
  });
15611
- const func = registry.get(state.functionName, await strippedContext(request.bind_call));
15690
+ const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
15612
15691
  const executionId = state.executionId;
15613
15692
  const opaqueData = state.opaqueData ?? null;
15614
15693
  const initResponse = {
@@ -15617,10 +15696,11 @@ function functionHandlers(config) {
15617
15696
  opaque_data: opaqueData
15618
15697
  };
15619
15698
  handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
15699
+ const restored = state.userState != null ? { state: state.userState } : undefined;
15620
15700
  if (handlers.producerInit) {
15621
- handlerState = handlers.producerInit();
15701
+ handlerState = handlers.producerInit(restored);
15622
15702
  } else if (handlers.exchangeInit) {
15623
- handlerState = handlers.exchangeInit();
15703
+ handlerState = handlers.exchangeInit(restored);
15624
15704
  }
15625
15705
  if (state.userState != null && handlerState?.state !== undefined) {
15626
15706
  handlerState.state = state.userState;
@@ -17789,14 +17869,46 @@ function secretType(secrets, name) {
17789
17869
  const f = secrets?.[name];
17790
17870
  return f && "type" in f ? scalarStr(f.type) : undefined;
17791
17871
  }
17872
+ function untyped(fields) {
17873
+ return !!fields && scalarStr(fields.type) === "";
17874
+ }
17875
+ function keyedByType(secrets, type) {
17876
+ const f = secrets?.[type];
17877
+ return untyped(f) ? f : undefined;
17878
+ }
17792
17879
  function secretsOfType(secrets, type) {
17793
- return Object.values(secrets ?? {}).filter((f) => scalarStr(f.type) === type);
17880
+ const typed = Object.values(secrets ?? {}).filter((f) => scalarStr(f.type) === type);
17881
+ if (typed.length > 0)
17882
+ return typed;
17883
+ const legacy = keyedByType(secrets, type);
17884
+ return legacy ? [legacy] : [];
17885
+ }
17886
+ function secretOfType(secrets, type) {
17887
+ const all = secretsOfType(secrets, type);
17888
+ return all.find((f) => scalarStr(f.scope) === "") ?? all[0];
17889
+ }
17890
+ function requireSecretOfType(secrets, type) {
17891
+ const found = secretOfType(secrets, type);
17892
+ if (!found) {
17893
+ throw new Error(`required secret of type '${type}' was not found; create one with CREATE SECRET (TYPE ${type}, ...)`);
17894
+ }
17895
+ return found;
17896
+ }
17897
+ function secretByName(secrets, name, type) {
17898
+ if (!secrets || !Object.prototype.hasOwnProperty.call(secrets, name))
17899
+ return;
17900
+ const f = secrets[name];
17901
+ if (!f)
17902
+ return;
17903
+ if (type === undefined || untyped(f) || scalarStr(f.type) === type)
17904
+ return f;
17905
+ return;
17794
17906
  }
17795
17907
  function secretForScope(secrets, path) {
17796
17908
  return selectForScope(secrets, path, undefined);
17797
17909
  }
17798
17910
  function secretForScopeOfType(secrets, path, type) {
17799
- return selectForScope(secrets, path, type);
17911
+ return selectForScope(secrets, path, type) ?? keyedByType(secrets, type);
17800
17912
  }
17801
17913
  function selectForScope(secrets, path, type) {
17802
17914
  let best;
@@ -19634,6 +19746,7 @@ export {
19634
19746
  metadatasToArrow,
19635
19747
  mintAttachTicket,
19636
19748
  moreOutputMetadata,
19749
+ normalizeRequiredSecrets,
19637
19750
  normalizeSchemaPath,
19638
19751
  nullType2 as nullType,
19639
19752
  openAttachTicket,
@@ -19644,6 +19757,7 @@ export {
19644
19757
  readConstraintRecord,
19645
19758
  redeemAttachTicket,
19646
19759
  reprPushedFilters,
19760
+ requireSecretOfType,
19647
19761
  resolveMetadata,
19648
19762
  resolveStorageFromEnv,
19649
19763
  safeNumber,
@@ -19652,8 +19766,10 @@ export {
19652
19766
  schemaPathKey,
19653
19767
  schemaPathsEqual,
19654
19768
  schemaToArgumentSpecs,
19769
+ secretByName,
19655
19770
  secretForScope,
19656
19771
  secretForScopeOfType,
19772
+ secretOfType,
19657
19773
  secretType,
19658
19774
  secretsOfType,
19659
19775
  selectCatalogCapabilities,
@@ -19700,4 +19816,4 @@ export {
19700
19816
  validateTableConstraints
19701
19817
  };
19702
19818
 
19703
- //# debugId=9CC3A9354AA50B4D64756E2164756E21
19819
+ //# debugId=1EBCEB0AE170D1AF64756E2164756E21