@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
@@ -3,9 +3,9 @@ export type { VgiFetchOptions } from "./http/fetch.js";
3
3
  export type { HostingOptions } from "./rpc-server.js";
4
4
  export { AuthUnavailableError, GrantKeys, GrantRefusedError, IdentityUnavailableError, StatusError, } from "@query-farm/vgi-rpc";
5
5
  export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
6
- export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
6
+ export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, normalizeRequiredSecrets, } from "./index.core.js";
7
7
  export * from "./catalog/public-codecs.js";
8
- export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, } from "./index.core.js";
8
+ export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, SecretFields, SecretsDict, RequiredSecret, SecretRequirement, SecretRequirementSpec, } from "./index.core.js";
9
9
  export type { ProtocolConfig } from "./protocol/dispatch.js";
10
10
  export type { LandingInfo } from "./http/landing.js";
11
11
  export { createLandingRoutes } from "./http/landing.js";
@@ -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;
@@ -10400,13 +10384,14 @@ function functionHandlers(config) {
10400
10384
  } else {
10401
10385
  const carried = parseCarriedInitRequest(state.initRequestPacked);
10402
10386
  const request = carried.request;
10387
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
10403
10388
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
10404
10389
  auth: currentRequestAuth(),
10405
10390
  signingKey,
10406
10391
  catalogInterface,
10407
10392
  checkAnchor: false
10408
10393
  });
10409
- const func = registry.get(state.functionName, await strippedContext(request.bind_call));
10394
+ const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
10410
10395
  const executionId = state.executionId;
10411
10396
  const opaqueData = state.opaqueData ?? null;
10412
10397
  const initResponse = {
@@ -10415,10 +10400,11 @@ function functionHandlers(config) {
10415
10400
  opaque_data: opaqueData
10416
10401
  };
10417
10402
  handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
10403
+ const restored = state.userState != null ? { state: state.userState } : undefined;
10418
10404
  if (handlers.producerInit) {
10419
- handlerState = handlers.producerInit();
10405
+ handlerState = handlers.producerInit(restored);
10420
10406
  } else if (handlers.exchangeInit) {
10421
- handlerState = handlers.exchangeInit();
10407
+ handlerState = handlers.exchangeInit(restored);
10422
10408
  }
10423
10409
  if (state.userState != null && handlerState?.state !== undefined) {
10424
10410
  handlerState.state = state.userState;
@@ -10556,6 +10542,65 @@ function functionHandlers(config) {
10556
10542
  // src/protocol/handlers/aggregate.ts
10557
10543
  init_arrow();
10558
10544
 
10545
+ // src/secrets/requirements.ts
10546
+ var KNOWN_KEYS = new Set(["secretType", "secret_type", "scope", "secretName", "secret_name"]);
10547
+ function optionalString(value, what, where) {
10548
+ if (value === undefined || value === null)
10549
+ return null;
10550
+ if (typeof value !== "string") {
10551
+ throw new TypeError(`${where}: ${what} must be a string, got ${typeof value}`);
10552
+ }
10553
+ return value === "" ? null : value;
10554
+ }
10555
+ function normalizeRequiredSecrets(value, functionName = "<function>") {
10556
+ if (value === undefined || value === null)
10557
+ return [];
10558
+ const where = `requiredSecrets of '${functionName}'`;
10559
+ if (!Array.isArray(value)) {
10560
+ throw new TypeError(`${where} must be an array of secret types or { secretType, scope?, secretName? } objects, got ${typeof value}`);
10561
+ }
10562
+ const out = [];
10563
+ const seen = new Set;
10564
+ value.forEach((entry, i) => {
10565
+ const at = `${where}[${i}]`;
10566
+ let req;
10567
+ if (typeof entry === "string") {
10568
+ if (entry === "")
10569
+ throw new TypeError(`${at}: secret type must not be empty`);
10570
+ req = { secretType: entry, scope: null, secretName: null };
10571
+ } else if (entry !== null && typeof entry === "object" && !Array.isArray(entry)) {
10572
+ const obj = entry;
10573
+ const unknown = Object.keys(obj).filter((k) => !KNOWN_KEYS.has(k));
10574
+ if (unknown.length > 0) {
10575
+ throw new TypeError(`${at}: unknown key(s) ${unknown.map((k) => `'${k}'`).join(", ")}; ` + `expected secretType, scope, secretName`);
10576
+ }
10577
+ if (obj.secretType !== undefined && obj.secret_type !== undefined && obj.secretType !== obj.secret_type) {
10578
+ throw new TypeError(`${at}: secretType and secret_type disagree`);
10579
+ }
10580
+ if (obj.secretName !== undefined && obj.secret_name !== undefined && obj.secretName !== obj.secret_name) {
10581
+ throw new TypeError(`${at}: secretName and secret_name disagree`);
10582
+ }
10583
+ const secretType = obj.secretType ?? obj.secret_type;
10584
+ if (typeof secretType !== "string" || secretType === "") {
10585
+ throw new TypeError(`${at}: secretType must be a non-empty string`);
10586
+ }
10587
+ req = {
10588
+ secretType,
10589
+ scope: optionalString(obj.scope, "scope", at),
10590
+ secretName: optionalString(obj.secretName ?? obj.secret_name, "secretName", at)
10591
+ };
10592
+ } else {
10593
+ 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));
10594
+ }
10595
+ const key = JSON.stringify([req.secretType, req.scope, req.secretName]);
10596
+ if (seen.has(key))
10597
+ return;
10598
+ seen.add(key);
10599
+ out.push(req);
10600
+ });
10601
+ return out;
10602
+ }
10603
+
10559
10604
  // src/functions/aggregate.ts
10560
10605
  init_arrow();
10561
10606
 
@@ -10884,7 +10929,7 @@ function defineAggregate(config) {
10884
10929
  tags: config.tags,
10885
10930
  parameterDefaultValues: config.parameterDefaultValues,
10886
10931
  nullHandling: config.nullHandling,
10887
- requiredSecrets: config.requiredSecrets
10932
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
10888
10933
  };
10889
10934
  const isAnyType = isNull(config.outputType);
10890
10935
  const defaultOutputSchema = isAnyType ? schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]) : schema2([field2("result", config.outputType, true)]);
@@ -14365,7 +14410,7 @@ function defineScalarFunction(config) {
14365
14410
  parameterDefaultValues: config.parameterDefaultValues,
14366
14411
  maxWorkers: config.maxWorkers,
14367
14412
  requiredSettings: config.requiredSettings,
14368
- requiredSecrets: config.requiredSecrets
14413
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
14369
14414
  };
14370
14415
  const defaultOutputSchema = config.returns ? schema2([field2("result", config.returns, true)]) : schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]);
14371
14416
  return {
@@ -14436,8 +14481,15 @@ function defineScalarFunction(config) {
14436
14481
  outputSchema,
14437
14482
  inputSchema: inputSchema ?? undefined,
14438
14483
  exchangeInit: () => ({}),
14439
- exchangeFn: (state, input, out) => {
14440
- const result = config.compute(input, constArgs, { settings, secrets, auth: out.auth });
14484
+ exchangeFn: async (state, input, out) => {
14485
+ let result = config.compute(input, constArgs, {
14486
+ settings,
14487
+ secrets,
14488
+ auth: out.auth,
14489
+ bindCall: request.bind_call
14490
+ });
14491
+ if (result != null && typeof result.then === "function")
14492
+ result = await result;
14441
14493
  let outputBatch;
14442
14494
  if (isBatch(result)) {
14443
14495
  outputBatch = result;
@@ -14546,7 +14598,7 @@ function defineTableFunction(config) {
14546
14598
  parameterDefaultValues: config.parameterDefaultValues,
14547
14599
  maxWorkers: config.maxWorkers,
14548
14600
  requiredSettings: config.requiredSettings,
14549
- requiredSecrets: config.requiredSecrets,
14601
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
14550
14602
  preservesOrder: config.preservesOrder,
14551
14603
  nullHandling: config.nullHandling,
14552
14604
  orderDependent: config.orderDependent,
@@ -14676,11 +14728,10 @@ function defineTableFunction(config) {
14676
14728
  if (request.phase != null) {
14677
14729
  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().`);
14678
14730
  }
14679
- const state = config.initialState ? config.initialState(processParams) : null;
14680
14731
  return {
14681
14732
  outputSchema,
14682
- producerInit: () => ({
14683
- state,
14733
+ producerInit: (restored) => ({
14734
+ state: restored ? restored.state : config.initialState ? config.initialState(processParams) : null,
14684
14735
  processParams,
14685
14736
  filterHistory: carriedFilterHistory
14686
14737
  }),
@@ -14797,7 +14848,8 @@ function defineTableInOutFunction(config) {
14797
14848
  name: "data",
14798
14849
  position: posIdx++,
14799
14850
  arrowType: nullType2(),
14800
- isTableInput: true
14851
+ isTableInput: true,
14852
+ ...config.argDocs?.data !== undefined ? { doc: config.argDocs.data } : {}
14801
14853
  });
14802
14854
  if (config.namedArgs) {
14803
14855
  for (const [name, type] of Object.entries(config.namedArgs)) {
@@ -14823,7 +14875,7 @@ function defineTableInOutFunction(config) {
14823
14875
  parameterDefaultValues: config.parameterDefaultValues,
14824
14876
  maxWorkers: config.maxWorkers,
14825
14877
  requiredSettings: config.requiredSettings,
14826
- requiredSecrets: config.requiredSecrets,
14878
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
14827
14879
  hasFinalize: !!config.finalize
14828
14880
  };
14829
14881
  function extractArgs(request) {
@@ -14931,7 +14983,7 @@ function defineTableInOutFunction(config) {
14931
14983
  for (const bytes of stored) {
14932
14984
  finalizeStates.push(deserializeUserState(bytes));
14933
14985
  }
14934
- if (finalizeStates.length === 0) {
14986
+ if (finalizeStates.length === 0 && config.finalize) {
14935
14987
  finalizeStates.push(config.initialState ? config.initialState(processParams) : null);
14936
14988
  }
14937
14989
  const batches = config.finalize ? await config.finalize(processParams, finalizeStates) : [];
@@ -14954,7 +15006,7 @@ function defineTableInOutFunction(config) {
14954
15006
  if (request.bind_call.input_schema == null) {
14955
15007
  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().`);
14956
15008
  }
14957
- const state = config.initialState ? config.initialState(processParams) : null;
15009
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
14958
15010
  const processFn = config.process ?? ((_params, _state, batch, out) => {
14959
15011
  out.emit(projIds ? projectBatch(projIds, batch) : batch);
14960
15012
  });
@@ -14962,7 +15014,12 @@ function defineTableInOutFunction(config) {
14962
15014
  outputSchema,
14963
15015
  inputSchema: request.bind_call.input_schema,
14964
15016
  continuesOutput: true,
14965
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
15017
+ exchangeInit: (restored) => ({
15018
+ state: restored ? restored.state : freshState(),
15019
+ processParams,
15020
+ filterHistory: carriedFilterHistory,
15021
+ morePending: false
15022
+ }),
14966
15023
  exchangeFn: async (eState, input, out) => {
14967
15024
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
14968
15025
  applyRevalidationValidators(eState.processParams, input);
@@ -15128,7 +15185,7 @@ function defineRowTransformFunction(config) {
15128
15185
  parameterDefaultValues: config.parameterDefaultValues,
15129
15186
  maxWorkers: config.maxWorkers,
15130
15187
  requiredSettings: config.requiredSettings,
15131
- requiredSecrets: config.requiredSecrets,
15188
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
15132
15189
  hasFinalize: false,
15133
15190
  inputFromArgs: true,
15134
15191
  inputRowsPerCall
@@ -15216,12 +15273,17 @@ function defineRowTransformFunction(config) {
15216
15273
  if (request.bind_call.input_schema == null) {
15217
15274
  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().`);
15218
15275
  }
15219
- const state = config.initialState ? config.initialState(processParams) : null;
15276
+ const freshState = () => config.initialState ? config.initialState(processParams) : null;
15220
15277
  return {
15221
15278
  outputSchema,
15222
15279
  inputSchema: request.bind_call.input_schema,
15223
15280
  continuesOutput: true,
15224
- exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
15281
+ exchangeInit: (restored) => ({
15282
+ state: restored ? restored.state : freshState(),
15283
+ processParams,
15284
+ filterHistory: carriedFilterHistory,
15285
+ morePending: false
15286
+ }),
15225
15287
  exchangeFn: async (eState, input, out) => {
15226
15288
  await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
15227
15289
  applyRevalidationValidators(eState.processParams, input);
@@ -15360,7 +15422,7 @@ function resolveMetadata(func) {
15360
15422
  nullHandling: meta.nullHandling ?? "DEFAULT" /* DEFAULT */,
15361
15423
  argumentMonotonicity,
15362
15424
  requiredSettings: meta.requiredSettings ?? [],
15363
- requiredSecrets: meta.requiredSecrets ?? [],
15425
+ requiredSecrets: normalizeRequiredSecrets(meta.requiredSecrets, meta.name),
15364
15426
  projectionPushdown: meta.projectionPushdown ?? false,
15365
15427
  filterPushdown: meta.filterPushdown ?? false,
15366
15428
  samplingPushdown: meta.samplingPushdown ?? false,
@@ -15470,8 +15532,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15470
15532
  for (const tbl of sch.tables ?? []) {
15471
15533
  for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"]) {
15472
15534
  const fn = tbl[key];
15473
- if (fn)
15474
- registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
15535
+ if (!fn)
15536
+ continue;
15537
+ registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
15538
+ registry.register(fn);
15475
15539
  }
15476
15540
  }
15477
15541
  }
@@ -15487,14 +15551,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15487
15551
  return [this._descriptor.name];
15488
15552
  }
15489
15553
  attachOptionSpecs(_name) {
15490
- return [];
15554
+ return this._descriptor.attachOptions ?? [];
15491
15555
  }
15492
15556
  catalogsInfo() {
15493
15557
  return [{
15494
15558
  name: this._descriptor.name,
15495
15559
  implementation_version: null,
15496
15560
  data_version_spec: null,
15497
- attach_option_specs: [],
15561
+ attach_option_specs: serializeAttachOptionSpecs(this.attachOptionSpecs(this._descriptor.name)),
15498
15562
  releases: [],
15499
15563
  source_url: this._descriptor.sourceUrl ?? null
15500
15564
  }];
@@ -15796,7 +15860,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15796
15860
  }
15797
15861
  }
15798
15862
  const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
15799
- const requiredSecrets = (meta.requiredSecrets ?? []).map((secretType) => ({ secret_type: secretType, scope: null, secret_name: null }));
15863
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
15864
+ secret_type: s.secretType,
15865
+ scope: s.scope,
15866
+ secret_name: s.secretName
15867
+ }));
15800
15868
  const derivedTags = {};
15801
15869
  const tags = { ...derivedTags, ...meta.tags ?? {} };
15802
15870
  return {
@@ -16567,10 +16635,12 @@ class FunctionRegistry {
16567
16635
  _byCatalog = new Map;
16568
16636
  register(func) {
16569
16637
  const name = func.meta.name;
16570
- if (!this._functions.has(name)) {
16571
- this._functions.set(name, []);
16638
+ const bucket = this._functions.get(name);
16639
+ if (!bucket) {
16640
+ this._functions.set(name, [func]);
16641
+ } else if (!bucket.includes(func)) {
16642
+ bucket.push(func);
16572
16643
  }
16573
- this._functions.get(name).push(func);
16574
16644
  }
16575
16645
  registerInSchema(func, schemaPath, catalogName) {
16576
16646
  const add = (map, key) => {
@@ -16703,6 +16773,80 @@ class FunctionRegistry {
16703
16773
  return result;
16704
16774
  }
16705
16775
  }
16776
+ // src/secrets/helpers.ts
16777
+ function scalarStr(v) {
16778
+ if (v === null || v === undefined)
16779
+ return "";
16780
+ return typeof v === "string" ? v : String(v);
16781
+ }
16782
+ function secretType(secrets, name) {
16783
+ const f = secrets?.[name];
16784
+ return f && "type" in f ? scalarStr(f.type) : undefined;
16785
+ }
16786
+ function untyped(fields) {
16787
+ return !!fields && scalarStr(fields.type) === "";
16788
+ }
16789
+ function keyedByType(secrets, type) {
16790
+ const f = secrets?.[type];
16791
+ return untyped(f) ? f : undefined;
16792
+ }
16793
+ function secretsOfType(secrets, type) {
16794
+ const typed = Object.values(secrets ?? {}).filter((f) => scalarStr(f.type) === type);
16795
+ if (typed.length > 0)
16796
+ return typed;
16797
+ const legacy = keyedByType(secrets, type);
16798
+ return legacy ? [legacy] : [];
16799
+ }
16800
+ function secretOfType(secrets, type) {
16801
+ const all = secretsOfType(secrets, type);
16802
+ return all.find((f) => scalarStr(f.scope) === "") ?? all[0];
16803
+ }
16804
+ function requireSecretOfType(secrets, type) {
16805
+ const found = secretOfType(secrets, type);
16806
+ if (!found) {
16807
+ throw new Error(`required secret of type '${type}' was not found; create one with CREATE SECRET (TYPE ${type}, ...)`);
16808
+ }
16809
+ return found;
16810
+ }
16811
+ function secretByName(secrets, name, type) {
16812
+ if (!secrets || !Object.prototype.hasOwnProperty.call(secrets, name))
16813
+ return;
16814
+ const f = secrets[name];
16815
+ if (!f)
16816
+ return;
16817
+ if (type === undefined || untyped(f) || scalarStr(f.type) === type)
16818
+ return f;
16819
+ return;
16820
+ }
16821
+ function secretForScope(secrets, path) {
16822
+ return selectForScope(secrets, path, undefined);
16823
+ }
16824
+ function secretForScopeOfType(secrets, path, type) {
16825
+ return selectForScope(secrets, path, type) ?? keyedByType(secrets, type);
16826
+ }
16827
+ function selectForScope(secrets, path, type) {
16828
+ let best;
16829
+ let bestLen = -1;
16830
+ let fallback;
16831
+ for (const fields of Object.values(secrets ?? {})) {
16832
+ if (type !== undefined && scalarStr(fields.type) !== type)
16833
+ continue;
16834
+ const scope = scalarStr(fields.scope);
16835
+ if (!scope) {
16836
+ if (!fallback)
16837
+ fallback = fields;
16838
+ continue;
16839
+ }
16840
+ for (const prefix of scope.split(`
16841
+ `)) {
16842
+ if (prefix && path.startsWith(prefix) && prefix.length > bestLen) {
16843
+ bestLen = prefix.length;
16844
+ best = fields;
16845
+ }
16846
+ }
16847
+ }
16848
+ return best ?? fallback;
16849
+ }
16706
16850
  // src/index.core.ts
16707
16851
  import { str, bytes, int as int3, int32 as int323, float, float32 as float323, bool as bool3, toSchema, OutputCollector, AuthContext as AuthContext2 } from "@query-farm/vgi-rpc";
16708
16852
  import { subprocessConnect, httpConnect, tcpConnect } from "@query-farm/vgi-rpc";
@@ -16852,13 +16996,21 @@ export {
16852
16996
  list2 as list,
16853
16997
  map2 as map,
16854
16998
  moreOutputMetadata,
16999
+ normalizeRequiredSecrets,
16855
17000
  nullType2 as nullType,
16856
17001
  parentRowsMetadata,
16857
17002
  projectBatch,
16858
17003
  projectSchema,
16859
17004
  readConstraintRecord,
17005
+ requireSecretOfType,
16860
17006
  safeNumber,
16861
17007
  schema2 as schema,
17008
+ secretByName,
17009
+ secretForScope,
17010
+ secretForScopeOfType,
17011
+ secretOfType,
17012
+ secretType,
17013
+ secretsOfType,
16862
17014
  selectCatalogCapabilities,
16863
17015
  selectReadProfiles,
16864
17016
  serializeAttachOptionSpec,
@@ -16891,4 +17043,4 @@ export {
16891
17043
  validateTableConstraints
16892
17044
  };
16893
17045
 
16894
- //# debugId=F3074584951B62A064756E2164756E21
17046
+ //# debugId=701969C8B78DAA6864756E2164756E21