@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
@@ -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
@@ -24,6 +24,7 @@ export declare class FunctionRegistry {
24
24
  private _functions;
25
25
  private _bySchema;
26
26
  private _byCatalog;
27
+ /** Add `func` to the by-name index. Idempotent for the same function object. */
27
28
  register(func: VgiFunction): void;
28
29
  /**
29
30
  * Record that `func` is declared in `schemaPath`, in addition to the flat
@@ -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";
@@ -62,6 +63,21 @@ export type ScalarOutputValue<R extends VgiDataType, M extends Repr> = ValueFor<
62
63
  * expects a `Date`), is a COMPILE error.
63
64
  */
64
65
  export type ScalarComputeResult<R extends VgiDataType, M extends Repr> = Array<ScalarOutputValue<R, M>> | Iterable<ScalarOutputValue<R, M>> | VgiBatch;
66
+ /** Per-batch context handed to a scalar's `compute`. */
67
+ export interface ScalarComputeInfo {
68
+ settings: Record<string, any>;
69
+ secrets: Record<string, Record<string, any>>;
70
+ auth: AuthContext;
71
+ /**
72
+ * The bind request this execution was initialized with: the catalog's
73
+ * `attach_opaque_data` (already unsealed, as every function body sees it),
74
+ * `transaction_opaque_data`, arguments, settings and secrets. Mirrors the
75
+ * `init_call.bind_call` vgi-python's `ScalarFunction.process` receives, so a
76
+ * scalar can read attach-time state (e.g. connection options a catalog
77
+ * packed into its attach data).
78
+ */
79
+ bindCall: BindRequest;
80
+ }
65
81
  export interface ScalarFunctionConfig<P extends Record<string, VgiDataType> = Record<string, VgiDataType>, R extends VgiDataType = VgiDataType, M extends Repr = "rich"> {
66
82
  name: string;
67
83
  description?: string;
@@ -98,11 +114,7 @@ export interface ScalarFunctionConfig<P extends Record<string, VgiDataType> = Re
98
114
  * output column as an array/iterable of values (statically typed from
99
115
  * `returns` and `repr`) or a pre-built VgiBatch.
100
116
  */
101
- compute: (batch: VgiBatch, consts: Record<string, any>, info: {
102
- settings: Record<string, any>;
103
- secrets: Record<string, Record<string, any>>;
104
- auth: AuthContext;
105
- }) => ScalarComputeResult<NoInfer<R>, NoInfer<M>>;
117
+ compute: (batch: VgiBatch, consts: Record<string, any>, info: ScalarComputeInfo) => ScalarComputeResult<NoInfer<R>, NoInfer<M>> | Promise<ScalarComputeResult<NoInfer<R>, NoInfer<M>>>;
106
118
  stability?: FunctionStability;
107
119
  nullHandling?: NullHandling;
108
120
  /** One scalar monotonicity claim per ordered parameter declaration. */
@@ -113,7 +125,7 @@ export interface ScalarFunctionConfig<P extends Record<string, VgiDataType> = Re
113
125
  parameterDefaultValues?: VgiBatch | null;
114
126
  maxWorkers?: number;
115
127
  requiredSettings?: string[];
116
- requiredSecrets?: string[];
128
+ requiredSecrets?: RequiredSecret[];
117
129
  /**
118
130
  * Result-cache opt-in: when set, this CacheControl's `vgi.cache.*` metadata
119
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
  /**
@@ -189,10 +190,14 @@ export interface FunctionMeta {
189
190
  /** Optional free-text comment surfaced by `vgi_copy_formats()`. */
190
191
  copyToComment?: string | null | undefined;
191
192
  }
193
+ /** The user state a rebuilt HTTP turn restores, boxed so `null` state survives. */
194
+ export interface RestoredUserState {
195
+ state: unknown;
196
+ }
192
197
  export interface StreamHandlers {
193
- producerInit?: (() => any) | undefined;
198
+ producerInit?: ((restored?: RestoredUserState) => any) | undefined;
194
199
  producerFn?: ((state: any, out: OutputCollector) => void | Promise<void>) | undefined;
195
- exchangeInit?: (() => any) | undefined;
200
+ exchangeInit?: ((restored?: RestoredUserState) => any) | undefined;
196
201
  exchangeFn?: (state: any, input: VgiBatch, out: OutputCollector) => void | Promise<void>;
197
202
  outputSchema: VgiSchema;
198
203
  inputSchema?: VgiSchema | undefined;
@@ -1,5 +1,5 @@
1
1
  export { CACHE_ETAG_KEY, CACHE_EXPIRES_KEY, CACHE_IF_MODIFIED_SINCE_KEY, CACHE_IF_NONE_MATCH_KEY, CACHE_LAST_MODIFIED_KEY, CACHE_NO_STORE_KEY, CACHE_NOT_MODIFIED_KEY, CACHE_PARTITION_SCOPE_KEY, CACHE_PER_VALUE_KEY, CACHE_REVALIDATABLE_KEY, CACHE_SCOPE_CATALOG, CACHE_SCOPE_KEY, CACHE_SCOPE_TRANSACTION, CACHE_STALE_IF_ERROR_KEY, CACHE_STALE_WHILE_REVALIDATE_KEY, CACHE_TTL_KEY, type CacheControl, cacheControlMetadata, type CacheScope, } from "./cache-control.js";
2
- export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarParameterDef } from "./functions/scalar.js";
2
+ export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarComputeInfo, type ScalarParameterDef } from "./functions/scalar.js";
3
3
  export { defineTableFunction, type TableFunctionConfig, type TableBindParams, type TableProcessParams } from "./functions/table.js";
4
4
  export { defineAggregate, GROUP_COLUMN_NAME, type AggregateFunctionConfig, type AggregateBindParams, type AggregateUpdateParams, type AggregateFinalizeParams, } from "./functions/aggregate.js";
5
5
  export { defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, type TableInOutConfig, type TableInOutBindParams, type TableInOutProcessParams, type RowTransformConfig, type RowTransformProcessParams, } from "./functions/table-in-out.js";
@@ -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";