@query-farm/vgi 0.48.2 → 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 (43) hide show
  1. package/README.md +27 -0
  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/client-entry.js +9 -25
  5. package/dist/client-entry.js.map +3 -3
  6. package/dist/functions/aggregate.d.ts +2 -1
  7. package/dist/functions/copy-from.d.ts +2 -1
  8. package/dist/functions/copy-to.d.ts +2 -1
  9. package/dist/functions/scalar.d.ts +2 -1
  10. package/dist/functions/table-buffering.d.ts +2 -1
  11. package/dist/functions/table-in-out.d.ts +3 -2
  12. package/dist/functions/table.d.ts +2 -1
  13. package/dist/functions/types.d.ts +2 -1
  14. package/dist/index.core.d.ts +2 -1
  15. package/dist/index.js +131 -39
  16. package/dist/index.js.map +18 -17
  17. package/dist/metadata/types.d.ts +3 -1
  18. package/dist/secrets/helpers.d.ts +31 -3
  19. package/dist/secrets/requirements.d.ts +38 -0
  20. package/dist/serve-entry.js +9 -25
  21. package/dist/serve-entry.js.map +5 -5
  22. package/dist/worker-cf-entry.d.ts +2 -2
  23. package/dist/worker-cf-entry.js +161 -32
  24. package/dist/worker-cf-entry.js.map +15 -13
  25. package/package.json +1 -1
  26. package/src/arrow/impl-arrowjs/iterate.ts +17 -40
  27. package/src/arrow/impl-flechette/iterate.ts +5 -24
  28. package/src/catalog/read-only.ts +6 -3
  29. package/src/functions/aggregate.ts +3 -2
  30. package/src/functions/copy-from.ts +3 -2
  31. package/src/functions/copy-to.ts +2 -1
  32. package/src/functions/scalar.ts +3 -2
  33. package/src/functions/table-buffering.ts +3 -2
  34. package/src/functions/table-in-out.ts +5 -4
  35. package/src/functions/table.ts +3 -2
  36. package/src/functions/types.ts +2 -1
  37. package/src/index.core.ts +10 -0
  38. package/src/metadata/resolve.ts +2 -1
  39. package/src/metadata/serialize.ts +25 -5
  40. package/src/metadata/types.ts +3 -1
  41. package/src/secrets/helpers.ts +96 -9
  42. package/src/secrets/requirements.ts +121 -0
  43. package/src/worker-cf-entry.ts +14 -0
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiBatch, type VgiDataType } from "../arrow/index.js";
2
3
  import type { Arguments } from "../arguments/arguments.js";
3
4
  import { type ArgumentConstraints } from "../arguments/argument-spec.js";
@@ -106,7 +107,7 @@ export interface AggregateFunctionConfig<TArgs = Record<string, any>, TState = a
106
107
  * empty ResolvedSecrets. Mirrors vgi-python's `Secret()` annotation on an
107
108
  * aggregate `on_bind`.
108
109
  */
109
- requiredSecrets?: string[];
110
+ requiredSecrets?: RequiredSecret[];
110
111
  }
111
112
  type StateMap = Map<bigint, any>;
112
113
  interface ExecEntry {
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiDataType } from "../arrow/index.js";
2
3
  import type { OutputCollector } from "@query-farm/vgi-rpc";
3
4
  import type { BindRequest } from "../protocol/types.js";
@@ -54,7 +55,7 @@ export interface CopyFromFunctionConfig<TArgs = Record<string, unknown>> {
54
55
  tags?: Record<string, string>;
55
56
  examples?: FunctionExample[];
56
57
  requiredSettings?: string[];
57
- requiredSecrets?: string[];
58
+ requiredSecrets?: RequiredSecret[];
58
59
  /**
59
60
  * Optional secret-bind hook: forward CREATE SECRET credentials for
60
61
  * secret-backed cloud sources (S3/GCS/HTTP/…). Called during bind (only on the
@@ -1,3 +1,4 @@
1
+ import type { RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiBatch, type VgiDataType } from "../arrow/index.js";
2
3
  import type { BindRequest } from "../protocol/types.js";
3
4
  import type { FunctionExample } from "./types.js";
@@ -86,7 +87,7 @@ export interface CopyToFunctionConfig<TArgs = Record<string, unknown>> {
86
87
  tags?: Record<string, string>;
87
88
  examples?: FunctionExample[];
88
89
  requiredSettings?: string[];
89
- requiredSecrets?: string[];
90
+ requiredSecrets?: RequiredSecret[];
90
91
  /**
91
92
  * Optional secret-bind hook: forward CREATE SECRET credentials for
92
93
  * secret-backed cloud writes (S3/GCS/HTTP/…). Called during bind (only on the
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiBatch, type VgiDataType, type ValueFor, type Repr } from "../arrow/index.js";
2
3
  import type { AuthContext } from "@query-farm/vgi-rpc";
3
4
  import { FunctionStability, NullHandling, ArgumentMonotonicity } from "../types.js";
@@ -124,7 +125,7 @@ export interface ScalarFunctionConfig<P extends Record<string, VgiDataType> = Re
124
125
  parameterDefaultValues?: VgiBatch | null;
125
126
  maxWorkers?: number;
126
127
  requiredSettings?: string[];
127
- requiredSecrets?: string[];
128
+ requiredSecrets?: RequiredSecret[];
128
129
  /**
129
130
  * Result-cache opt-in: when set, this CacheControl's `vgi.cache.*` metadata
130
131
  * rides every output batch's custom metadata (per-batch — NOT the schema,
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiDataType, type VgiBatch } from "../arrow/index.js";
2
3
  import type { OutputCollector } from "@query-farm/vgi-rpc";
3
4
  import type { BindRequest, InitRequest, GlobalInitResponse } from "../protocol/types.js";
@@ -90,7 +91,7 @@ export interface TableBufferingConfig<TArgs = Record<string, any>, TState = any>
90
91
  tags?: Record<string, string> | undefined;
91
92
  maxWorkers?: number | undefined;
92
93
  requiredSettings?: string[] | undefined;
93
- requiredSecrets?: string[] | undefined;
94
+ requiredSecrets?: RequiredSecret[] | undefined;
94
95
  }
95
96
  /**
96
97
  * A table_buffering VgiFunction also carries its callback config so the
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiDataType, type VgiBatch } from "../arrow/index.js";
2
3
  import type { OutputCollector } from "@query-farm/vgi-rpc";
3
4
  import type { BindRequest, InitRequest, GlobalInitResponse } from "../protocol/types.js";
@@ -109,7 +110,7 @@ export interface TableInOutConfig<TArgs = Record<string, any>, TState = null> {
109
110
  tags?: Record<string, string>;
110
111
  maxWorkers?: number;
111
112
  requiredSettings?: string[];
112
- requiredSecrets?: string[];
113
+ requiredSecrets?: RequiredSecret[];
113
114
  }
114
115
  export declare function defineTableInOutFunction<TArgs = Record<string, any>, TState = null>(config: TableInOutConfig<TArgs, TState>): VgiFunction;
115
116
  export { PARENT_ROW_METADATA_KEY };
@@ -231,7 +232,7 @@ export interface RowTransformConfig<TArgs = Record<string, any>, TState = null>
231
232
  tags?: Record<string, string>;
232
233
  maxWorkers?: number;
233
234
  requiredSettings?: string[];
234
- requiredSecrets?: string[];
235
+ requiredSecrets?: RequiredSecret[];
235
236
  }
236
237
  /**
237
238
  * Define a blended ("UNNEST-style") table-in-out function: its positional args
@@ -1,3 +1,4 @@
1
+ import { type RequiredSecret } from "../secrets/requirements.js";
1
2
  import { type VgiSchema, type VgiBatch, type VgiDataType } from "../arrow/index.js";
2
3
  import type { OutputCollector } from "@query-farm/vgi-rpc";
3
4
  import type { PlanResult, TableFunctionPlanRequest } from "../protocol/serializers/splits.js";
@@ -179,7 +180,7 @@ export interface TableFunctionConfig<TArgs = Record<string, any>, TState = null>
179
180
  tags?: Record<string, string>;
180
181
  maxWorkers?: number;
181
182
  requiredSettings?: string[];
182
- requiredSecrets?: string[];
183
+ requiredSecrets?: RequiredSecret[];
183
184
  /** Row-order preservation behavior; flows to DuckDB's
184
185
  * TableFunction::order_preservation_type. */
185
186
  preservesOrder?: OrderPreservation;
@@ -1,3 +1,4 @@
1
+ import type { RequiredSecret } from "../secrets/requirements.js";
1
2
  import type { VgiSchema, VgiBatch } from "../arrow/index.js";
2
3
  import type { OutputCollector } from "@query-farm/vgi-rpc";
3
4
  import type { FunctionStability, NullHandling, ArgumentMonotonicity, OrderPreservation, OrderDependence, DistinctDependence, TableCardinality } from "../types.js";
@@ -71,7 +72,7 @@ export interface FunctionMeta {
71
72
  preservesOrder?: OrderPreservation | undefined;
72
73
  maxWorkers?: number | undefined;
73
74
  requiredSettings?: string[] | undefined;
74
- requiredSecrets?: string[] | undefined;
75
+ requiredSecrets?: RequiredSecret[] | undefined;
75
76
  orderDependent?: OrderDependence | undefined;
76
77
  distinctDependent?: DistinctDependence | undefined;
77
78
  /**
@@ -36,7 +36,8 @@ export { ATTACH_TICKET_OPTION, ATTACH_TICKET_PREFIX, ATTACH_TICKETS_PROTOCOL_NAM
36
36
  export { type ColumnStatistics, serializeColumnStatistics } from "./util/statistics.js";
37
37
  export { toUint8Array } from "./util/bytes.js";
38
38
  export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, batchToSecretDict, safeNumber, } from "./util/arrow/index.js";
39
- export { type SecretFields, type SecretsDict, secretType, secretsOfType, secretForScope, secretForScopeOfType, } from "./secrets/helpers.js";
39
+ export { type SecretFields, type SecretsDict, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, } from "./secrets/helpers.js";
40
+ export { type RequiredSecret, type SecretRequirement, type SecretRequirementSpec, normalizeRequiredSecrets, } from "./secrets/requirements.js";
40
41
  export { serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, } from "./util/arrow/index.js";
41
42
  export { schema, field, nullType, int8, int16, int64, uint8, uint16, uint32, uint64, float16, float64, utf8, largeUtf8, binary, largeBinary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, timestampSeconds, timestampMillis, timestampMicros, timestampNanos, durationSeconds, durationMillis, durationMicros, durationNanos, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, codecFor, asDate32, asDate64Ms, asTime32S, asTime32Ms, asTime64Us, asTime64Ns, asTimestampSeconds, asTimestampMillis, asTimestampMicros, asTimestampNanos, asDurationSeconds, asDurationMillis, asDurationMicros, asDurationNanos, asUnscaledDecimal, asInt64, asUint64, fromBranded, fromBrandedNumber, fromBrandedBigInt, TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, typeSignature, readCanonicalValue, columnFromArray, decodeDictValue, backend, adoptArrowJsShape, } from "./arrow/index.js";
42
43
  export type { VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnData, VgiBatch, VgiBackendInfo, TaggedUnion, NullDescriptor, BoolType, IntType, Int8Type, Int16Type, Int32Type, Int64Type, Uint8Type, Uint16Type, Uint32Type, Uint64Type, FloatType, Utf8Type, LargeUtf8Type, BinaryType, LargeBinaryType, FixedSizeBinaryType, DecimalType, Date32Type, Date64Type, Time32Type, Time64Type, TimestampType, DurationType, IntervalType, ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType, TypedField, TUnit, RichValue, RawValue, ValueFor, Repr, Codec, Branded, Date32, Date64Ms, Time32S, Time32Ms, Time64Us, Time64Ns, TimestampSeconds, TimestampMillis, TimestampMicros, TimestampNanos, DurationSeconds, DurationMillis, DurationMicros, DurationNanos, UnscaledDecimal, Int64Raw, Uint64Raw, } from "./arrow/index.js";
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 {
@@ -4886,7 +4929,7 @@ function defineTableFunction(config) {
4886
4929
  parameterDefaultValues: config.parameterDefaultValues,
4887
4930
  maxWorkers: config.maxWorkers,
4888
4931
  requiredSettings: config.requiredSettings,
4889
- requiredSecrets: config.requiredSecrets,
4932
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
4890
4933
  preservesOrder: config.preservesOrder,
4891
4934
  nullHandling: config.nullHandling,
4892
4935
  orderDependent: config.orderDependent,
@@ -5257,7 +5300,7 @@ function defineAggregate(config) {
5257
5300
  tags: config.tags,
5258
5301
  parameterDefaultValues: config.parameterDefaultValues,
5259
5302
  nullHandling: config.nullHandling,
5260
- requiredSecrets: config.requiredSecrets
5303
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
5261
5304
  };
5262
5305
  const isAnyType = isNull(config.outputType);
5263
5306
  const defaultOutputSchema = isAnyType ? schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]) : schema2([field2("result", config.outputType, true)]);
@@ -6436,7 +6479,7 @@ function defineTableInOutFunction(config) {
6436
6479
  parameterDefaultValues: config.parameterDefaultValues,
6437
6480
  maxWorkers: config.maxWorkers,
6438
6481
  requiredSettings: config.requiredSettings,
6439
- requiredSecrets: config.requiredSecrets,
6482
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6440
6483
  hasFinalize: !!config.finalize
6441
6484
  };
6442
6485
  function extractArgs(request) {
@@ -6746,7 +6789,7 @@ function defineRowTransformFunction(config) {
6746
6789
  parameterDefaultValues: config.parameterDefaultValues,
6747
6790
  maxWorkers: config.maxWorkers,
6748
6791
  requiredSettings: config.requiredSettings,
6749
- requiredSecrets: config.requiredSecrets,
6792
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6750
6793
  hasFinalize: false,
6751
6794
  inputFromArgs: true,
6752
6795
  inputRowsPerCall
@@ -6922,7 +6965,7 @@ function defineTableBufferingFunction(config) {
6922
6965
  parameterDefaultValues: config.parameterDefaultValues,
6923
6966
  maxWorkers: config.maxWorkers,
6924
6967
  requiredSettings: config.requiredSettings,
6925
- requiredSecrets: config.requiredSecrets,
6968
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
6926
6969
  hasFinalize: true,
6927
6970
  sinkOrderDependent: config.sinkOrderDependent,
6928
6971
  sourceOrderDependent: config.sourceOrderDependent,
@@ -7194,7 +7237,7 @@ function defineCopyFromFunction(config) {
7194
7237
  tags: config.tags,
7195
7238
  examples: config.examples,
7196
7239
  requiredSettings: config.requiredSettings,
7197
- requiredSecrets: config.requiredSecrets,
7240
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
7198
7241
  copyFromFormat: config.format,
7199
7242
  copyFromDirection: config.direction ?? "from",
7200
7243
  copyFromComment: config.comment ?? null
@@ -11051,7 +11094,7 @@ function resolveMetadata(func) {
11051
11094
  nullHandling: meta.nullHandling ?? "DEFAULT" /* DEFAULT */,
11052
11095
  argumentMonotonicity,
11053
11096
  requiredSettings: meta.requiredSettings ?? [],
11054
- requiredSecrets: meta.requiredSecrets ?? [],
11097
+ requiredSecrets: normalizeRequiredSecrets(meta.requiredSecrets, meta.name),
11055
11098
  projectionPushdown: meta.projectionPushdown ?? false,
11056
11099
  filterPushdown: meta.filterPushdown ?? false,
11057
11100
  samplingPushdown: meta.samplingPushdown ?? false,
@@ -11642,7 +11685,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
11642
11685
  }
11643
11686
  }
11644
11687
  const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
11645
- 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
+ }));
11646
11693
  const derivedTags = {};
11647
11694
  const tags = { ...derivedTags, ...meta.tags ?? {} };
11648
11695
  return {
@@ -13367,6 +13414,11 @@ var FILTER_CONTEXT_STRUCT = struct2([
13367
13414
  field2("profile", utf82(), false),
13368
13415
  field2("provider_fingerprint", utf82(), true)
13369
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
+ ]);
13370
13422
  var METADATA_SCHEMA = schema2([
13371
13423
  field2("name", utf82(), false),
13372
13424
  field2("class_name", utf82(), false),
@@ -13380,7 +13432,7 @@ var METADATA_SCHEMA = schema2([
13380
13432
  field2("null_handling", utf82(), false),
13381
13433
  field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
13382
13434
  field2("required_settings", list2(field2("item", utf82(), true)), false),
13383
- field2("required_secrets", list2(field2("item", utf82(), true)), false),
13435
+ field2("required_secrets", list2(field2("item", SECRET_REQUIREMENT_STRUCT, true)), false),
13384
13436
  field2("projection_pushdown", bool2(), false),
13385
13437
  field2("filter_pushdown", bool2(), false),
13386
13438
  field2("filter_semantic_profiles", list2(field2("item", utf82(), true)), false),
@@ -13422,7 +13474,11 @@ function metadataToRow(m) {
13422
13474
  null_handling: m.nullHandling,
13423
13475
  argument_monotonicity: m.argumentMonotonicity,
13424
13476
  required_settings: m.requiredSettings,
13425
- 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
+ })),
13426
13482
  projection_pushdown: m.projectionPushdown,
13427
13483
  filter_pushdown: m.filterPushdown,
13428
13484
  sampling_pushdown: m.samplingPushdown,
@@ -13515,7 +13571,7 @@ function arrowToMetadatas(batch) {
13515
13571
  const rawRequiredSettings = get("required_settings") ?? [];
13516
13572
  const requiredSettings = rawRequiredSettings ? [...rawRequiredSettings].filter((s) => s != null) : [];
13517
13573
  const rawRequiredSecrets = get("required_secrets") ?? [];
13518
- 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>");
13519
13575
  results.push({
13520
13576
  name: get("name") ?? "",
13521
13577
  className: get("class_name") ?? "",
@@ -17813,14 +17869,46 @@ function secretType(secrets, name) {
17813
17869
  const f = secrets?.[name];
17814
17870
  return f && "type" in f ? scalarStr(f.type) : undefined;
17815
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
+ }
17816
17879
  function secretsOfType(secrets, type) {
17817
- 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;
17818
17906
  }
17819
17907
  function secretForScope(secrets, path) {
17820
17908
  return selectForScope(secrets, path, undefined);
17821
17909
  }
17822
17910
  function secretForScopeOfType(secrets, path, type) {
17823
- return selectForScope(secrets, path, type);
17911
+ return selectForScope(secrets, path, type) ?? keyedByType(secrets, type);
17824
17912
  }
17825
17913
  function selectForScope(secrets, path, type) {
17826
17914
  let best;
@@ -19658,6 +19746,7 @@ export {
19658
19746
  metadatasToArrow,
19659
19747
  mintAttachTicket,
19660
19748
  moreOutputMetadata,
19749
+ normalizeRequiredSecrets,
19661
19750
  normalizeSchemaPath,
19662
19751
  nullType2 as nullType,
19663
19752
  openAttachTicket,
@@ -19668,6 +19757,7 @@ export {
19668
19757
  readConstraintRecord,
19669
19758
  redeemAttachTicket,
19670
19759
  reprPushedFilters,
19760
+ requireSecretOfType,
19671
19761
  resolveMetadata,
19672
19762
  resolveStorageFromEnv,
19673
19763
  safeNumber,
@@ -19676,8 +19766,10 @@ export {
19676
19766
  schemaPathKey,
19677
19767
  schemaPathsEqual,
19678
19768
  schemaToArgumentSpecs,
19769
+ secretByName,
19679
19770
  secretForScope,
19680
19771
  secretForScopeOfType,
19772
+ secretOfType,
19681
19773
  secretType,
19682
19774
  secretsOfType,
19683
19775
  selectCatalogCapabilities,
@@ -19724,4 +19816,4 @@ export {
19724
19816
  validateTableConstraints
19725
19817
  };
19726
19818
 
19727
- //# debugId=0D39EB7B8CA153F964756E2164756E21
19819
+ //# debugId=1EBCEB0AE170D1AF64756E2164756E21