@query-farm/vgi 0.48.0 → 0.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/dist/arguments/argument-spec.d.ts +17 -11
- package/dist/catalog/descriptors.d.ts +16 -2
- package/dist/catalog/publication.d.ts +7 -7
- package/dist/catalog/read-only.d.ts +4 -5
- package/dist/client/client.d.ts +9 -3
- package/dist/client/errors.d.ts +2 -2
- package/dist/client/types.d.ts +21 -0
- package/dist/client-entry.d.ts +1 -1
- package/dist/client-entry.js +31 -7
- package/dist/client-entry.js.map +20 -20
- package/dist/filter-pushdown/deserialize.d.ts +1 -1
- package/dist/filter-pushdown/types.d.ts +10 -10
- package/dist/functions/registry.d.ts +1 -0
- package/dist/functions/scalar.d.ts +17 -6
- package/dist/functions/table-buffering.d.ts +20 -20
- package/dist/functions/table-in-out.d.ts +4 -4
- package/dist/functions/table.d.ts +7 -7
- package/dist/functions/types.d.ts +51 -47
- package/dist/http/fetch.d.ts +10 -10
- package/dist/index.core.d.ts +2 -2
- package/dist/index.js +201 -116
- package/dist/index.js.map +53 -52
- package/dist/protocol/dispatch.d.ts +3 -3
- package/dist/protocol/handlers/function.d.ts +2 -2
- package/dist/protocol/serializers/cardinality.d.ts +4 -1
- package/dist/protocol/types.d.ts +5 -5
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.d.ts +16 -16
- package/dist/serve-entry.js +47 -24
- package/dist/serve-entry.js.map +38 -37
- package/dist/split-token.d.ts +6 -6
- package/dist/types.d.ts +9 -2
- package/dist/util/defined.d.ts +21 -0
- package/dist/worker-cf-entry.js +164 -106
- package/dist/worker-cf-entry.js.map +51 -50
- package/dist/worker.d.ts +2 -2
- package/package.json +6 -4
- package/src/arguments/argument-spec.ts +17 -11
- package/src/arrow/codec/registry.ts +2 -2
- package/src/arrow/impl-arrowjs/build.ts +1 -1
- package/src/arrow/impl-arrowjs/canonical.ts +23 -23
- package/src/arrow/impl-arrowjs/empty.ts +2 -2
- package/src/arrow/impl-arrowjs/ipc.ts +2 -2
- package/src/arrow/impl-arrowjs/iterate.ts +2 -2
- package/src/arrow/impl-arrowjs/project.ts +2 -2
- package/src/arrow/impl-flechette/build.ts +2 -1
- package/src/arrow/impl-flechette/canonical.ts +10 -9
- package/src/arrow/impl-flechette/compat.ts +3 -3
- package/src/arrow/impl-flechette/message-meta.ts +5 -4
- package/src/arrow/impl-flechette/statistics.ts +2 -2
- package/src/attach-ticket.ts +2 -2
- package/src/catalog/column-metadata.ts +1 -1
- package/src/catalog/composite.ts +2 -2
- package/src/catalog/constraints.ts +9 -9
- package/src/catalog/descriptors.ts +15 -1
- package/src/catalog/interface.ts +12 -12
- package/src/catalog/publication.ts +9 -8
- package/src/catalog/read-only.ts +27 -21
- package/src/catalog/sql-grammar.ts +6 -6
- package/src/client/client.ts +52 -15
- package/src/client/errors.ts +1 -1
- package/src/client/types.ts +23 -0
- package/src/client-entry.ts +2 -0
- package/src/codec/asd.ts +3 -3
- package/src/codec/conform.ts +3 -3
- package/src/filter-pushdown/collector.ts +1 -1
- package/src/filter-pushdown/deserialize.ts +13 -10
- package/src/filter-pushdown/evaluate.ts +3 -2
- package/src/filter-pushdown/history.ts +3 -2
- package/src/filter-pushdown/types.ts +10 -10
- package/src/functions/continuation.ts +1 -1
- package/src/functions/projection.ts +1 -1
- package/src/functions/registry.ts +20 -17
- package/src/functions/scalar.ts +33 -11
- package/src/functions/storage-cf-do.ts +2 -2
- package/src/functions/table-buffering.ts +28 -21
- package/src/functions/table-in-out.ts +37 -17
- package/src/functions/table.ts +36 -31
- package/src/functions/types.ts +58 -48
- package/src/generated/vgi-service.ts +5 -3
- package/src/http/fetch.ts +17 -12
- package/src/index.core.ts +3 -1
- package/src/protocol/carried-init-request.ts +1 -1
- package/src/protocol/dispatch.ts +3 -3
- package/src/protocol/handlers/aggregate.ts +8 -7
- package/src/protocol/handlers/catalog/shared.ts +1 -1
- package/src/protocol/handlers/function.ts +18 -5
- package/src/protocol/serializers/cardinality.ts +16 -3
- package/src/protocol/state-serializer.ts +1 -1
- package/src/protocol/types.ts +5 -5
- package/src/rpc-server.ts +13 -12
- package/src/serve-entry.ts +18 -18
- package/src/split-token.ts +10 -9
- package/src/types.ts +9 -2
- package/src/util/defined.ts +30 -0
- package/src/util/parent-rows.ts +2 -2
- package/src/worker.ts +15 -14
package/src/functions/table.ts
CHANGED
|
@@ -32,6 +32,7 @@ import type {
|
|
|
32
32
|
FunctionMeta,
|
|
33
33
|
StreamHandlers,
|
|
34
34
|
FunctionExample,
|
|
35
|
+
RestoredUserState,
|
|
35
36
|
} from "./types.js";
|
|
36
37
|
import {
|
|
37
38
|
constraintSpecFields,
|
|
@@ -75,7 +76,7 @@ function makeProjectingCollector(inner: OutputCollector, targetSchema: VgiSchema
|
|
|
75
76
|
function alreadyMatches(batch: VgiBatch): boolean {
|
|
76
77
|
if (batch.schema.fields.length !== targetSchema.fields.length) return false;
|
|
77
78
|
for (let i = 0; i < targetSchema.fields.length; i++) {
|
|
78
|
-
if (batch.schema.fields[i]
|
|
79
|
+
if (batch.schema.fields[i]!.name !== targetSchema.fields[i]!.name) return false;
|
|
79
80
|
}
|
|
80
81
|
return true;
|
|
81
82
|
}
|
|
@@ -140,7 +141,7 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
|
|
|
140
141
|
outputSchema: VgiSchema;
|
|
141
142
|
settings: Record<string, any>;
|
|
142
143
|
secrets: Record<string, Record<string, any>>;
|
|
143
|
-
pushdownFilters?: PushdownFilters;
|
|
144
|
+
pushdownFilters?: PushdownFilters | undefined;
|
|
144
145
|
/**
|
|
145
146
|
* The verified payloads of the splits this init claimed, in the order given,
|
|
146
147
|
* or undefined when this is not a split scan.
|
|
@@ -149,8 +150,8 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
|
|
|
149
150
|
* the client did not plan (a split-only function should fail loudly rather
|
|
150
151
|
* than answer the same query differently), empty means a claim of no work.
|
|
151
152
|
*/
|
|
152
|
-
splitPayloads?: Uint8Array[];
|
|
153
|
-
storage?: BoundStorage;
|
|
153
|
+
splitPayloads?: Uint8Array[] | undefined;
|
|
154
|
+
storage?: BoundStorage | undefined;
|
|
154
155
|
/**
|
|
155
156
|
* AT (TIMESTAMP|VERSION) clause for this scan, or `undefined` when the scan
|
|
156
157
|
* has no AT clause. Carried on the per-scan bind embedded in the init request
|
|
@@ -158,8 +159,8 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
|
|
|
158
159
|
* read time travel at init alongside their pushdown filters. Mirrors
|
|
159
160
|
* vgi-python's `ProcessParams.at_unit` / `.at_value`. See `BindRequest.at_unit`.
|
|
160
161
|
*/
|
|
161
|
-
atUnit?: string;
|
|
162
|
-
atValue?: string;
|
|
162
|
+
atUnit?: string | undefined;
|
|
163
|
+
atValue?: string | undefined;
|
|
163
164
|
/**
|
|
164
165
|
* Conditional-revalidation validator (the client's stored ETag). Set when the
|
|
165
166
|
* client holds a stale-but-revalidatable cached result and asks the worker to
|
|
@@ -168,10 +169,10 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
|
|
|
168
169
|
* `cacheControlMetadata({ notModified: true })` instead of re-streaming.
|
|
169
170
|
* Undefined on a normal call.
|
|
170
171
|
*/
|
|
171
|
-
ifNoneMatch?: string;
|
|
172
|
+
ifNoneMatch?: string | undefined;
|
|
172
173
|
/** Conditional-revalidation validator (the client's stored Last-Modified).
|
|
173
174
|
* Companion to {@link ifNoneMatch}. Undefined on a normal call. */
|
|
174
|
-
ifModifiedSince?: string;
|
|
175
|
+
ifModifiedSince?: string | undefined;
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
/**
|
|
@@ -449,6 +450,8 @@ export function defineTableFunction<
|
|
|
449
450
|
return args as TArgs;
|
|
450
451
|
}
|
|
451
452
|
|
|
453
|
+
// Optional hooks are spread in only when configured, so an unconfigured
|
|
454
|
+
// hook is absent rather than present-and-undefined.
|
|
452
455
|
return {
|
|
453
456
|
kind: "table",
|
|
454
457
|
meta,
|
|
@@ -474,7 +477,7 @@ export function defineTableFunction<
|
|
|
474
477
|
};
|
|
475
478
|
},
|
|
476
479
|
|
|
477
|
-
|
|
480
|
+
...(config.projection ? { projection: (proposal) => config.projection!({args: extractArgs(proposal.bindCall), bindCall:proposal.bindCall, settings:batchToScalarDict(proposal.bindCall.settings),secrets:batchToSecretDict(proposal.bindCall.secrets),resolvedSecretsProvided:proposal.bindCall.resolved_secrets_provided},proposal) } : {}),
|
|
478
481
|
|
|
479
482
|
async globalInit(request: InitRequest): Promise<GlobalInitResponse> {
|
|
480
483
|
const executionId = new Uint8Array(16);
|
|
@@ -596,14 +599,16 @@ export function defineTableFunction<
|
|
|
596
599
|
);
|
|
597
600
|
}
|
|
598
601
|
|
|
599
|
-
const state = config.initialState
|
|
600
|
-
? config.initialState(processParams)
|
|
601
|
-
: (null as TState);
|
|
602
|
-
|
|
603
602
|
return {
|
|
604
603
|
outputSchema,
|
|
605
|
-
|
|
606
|
-
|
|
604
|
+
// initialState runs only for a fresh stream; a rebuilt HTTP turn
|
|
605
|
+
// adopts the state its cursor carried.
|
|
606
|
+
producerInit: (restored?: RestoredUserState): TableHandlerState<TArgs, TState> => ({
|
|
607
|
+
state: restored
|
|
608
|
+
? (restored.state as TState)
|
|
609
|
+
: config.initialState
|
|
610
|
+
? config.initialState(processParams)
|
|
611
|
+
: (null as TState),
|
|
607
612
|
processParams,
|
|
608
613
|
filterHistory: carriedFilterHistory,
|
|
609
614
|
}),
|
|
@@ -660,8 +665,8 @@ export function defineTableFunction<
|
|
|
660
665
|
};
|
|
661
666
|
},
|
|
662
667
|
|
|
663
|
-
|
|
664
|
-
|
|
668
|
+
...(config.cardinality ? {
|
|
669
|
+
cardinality: (request: TableFunctionCardinalityRequest) => {
|
|
665
670
|
const args = extractArgs(request.bind_call);
|
|
666
671
|
const settings = batchToScalarDict(request.bind_call.settings);
|
|
667
672
|
const secrets = batchToSecretDict(request.bind_call.secrets);
|
|
@@ -672,8 +677,8 @@ export function defineTableFunction<
|
|
|
672
677
|
secrets,
|
|
673
678
|
resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false,
|
|
674
679
|
});
|
|
675
|
-
}
|
|
676
|
-
|
|
680
|
+
},
|
|
681
|
+
} : {}),
|
|
677
682
|
|
|
678
683
|
// Wired through with decoded arguments, exactly as cardinality and
|
|
679
684
|
// statistics are.
|
|
@@ -683,8 +688,8 @@ export function defineTableFunction<
|
|
|
683
688
|
// `supportsSplits` and a `plan`, advertise split capability on the wire, and
|
|
684
689
|
// silently serve the framework default of one empty-payload split. Nothing
|
|
685
690
|
// failed — the scan just quietly stopped being divided.
|
|
686
|
-
|
|
687
|
-
|
|
691
|
+
...(config.plan ? {
|
|
692
|
+
plan: (request: TableFunctionPlanRequest) => {
|
|
688
693
|
const args = extractArgs(request.bind_call);
|
|
689
694
|
const settings = batchToScalarDict(request.bind_call.settings);
|
|
690
695
|
const secrets = batchToSecretDict(request.bind_call.secrets);
|
|
@@ -698,11 +703,11 @@ export function defineTableFunction<
|
|
|
698
703
|
},
|
|
699
704
|
request,
|
|
700
705
|
);
|
|
701
|
-
}
|
|
702
|
-
|
|
706
|
+
},
|
|
707
|
+
} : {}),
|
|
703
708
|
|
|
704
|
-
|
|
705
|
-
|
|
709
|
+
...(config.statistics ? {
|
|
710
|
+
statistics: (request: TableFunctionCardinalityRequest) => {
|
|
706
711
|
const args = extractArgs(request.bind_call);
|
|
707
712
|
const settings = batchToScalarDict(request.bind_call.settings);
|
|
708
713
|
const secrets = batchToSecretDict(request.bind_call.secrets);
|
|
@@ -713,11 +718,11 @@ export function defineTableFunction<
|
|
|
713
718
|
secrets,
|
|
714
719
|
resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false,
|
|
715
720
|
});
|
|
716
|
-
}
|
|
717
|
-
|
|
721
|
+
},
|
|
722
|
+
} : {}),
|
|
718
723
|
|
|
719
|
-
|
|
720
|
-
|
|
724
|
+
...(config.dynamicToString ? {
|
|
725
|
+
dynamicToString: (request) => {
|
|
721
726
|
const args = extractArgs(request.bindCall);
|
|
722
727
|
const settings = batchToScalarDict(request.bindCall.settings);
|
|
723
728
|
const secrets = batchToSecretDict(request.bindCall.secrets);
|
|
@@ -733,7 +738,7 @@ export function defineTableFunction<
|
|
|
733
738
|
request.globalExecutionId,
|
|
734
739
|
storage,
|
|
735
740
|
);
|
|
736
|
-
}
|
|
737
|
-
|
|
741
|
+
},
|
|
742
|
+
} : {}),
|
|
738
743
|
};
|
|
739
744
|
}
|
package/src/functions/types.ts
CHANGED
|
@@ -60,23 +60,23 @@ export interface EvaluationContextCapability {
|
|
|
60
60
|
|
|
61
61
|
export interface FunctionMeta {
|
|
62
62
|
name: string;
|
|
63
|
-
description?: string;
|
|
64
|
-
stability?: FunctionStability;
|
|
65
|
-
nullHandling?: NullHandling;
|
|
63
|
+
description?: string | undefined;
|
|
64
|
+
stability?: FunctionStability | undefined;
|
|
65
|
+
nullHandling?: NullHandling | undefined;
|
|
66
66
|
/** Scalar-only claims in argument declaration order. A vararg is one slot. */
|
|
67
|
-
argumentMonotonicity?: ArgumentMonotonicity[] | null;
|
|
68
|
-
examples?: FunctionExample[];
|
|
69
|
-
categories?: string[];
|
|
70
|
-
tags?: Record<string, string
|
|
67
|
+
argumentMonotonicity?: ArgumentMonotonicity[] | null | undefined;
|
|
68
|
+
examples?: FunctionExample[] | undefined;
|
|
69
|
+
categories?: string[] | undefined;
|
|
70
|
+
tags?: Record<string, string> | undefined;
|
|
71
71
|
/**
|
|
72
72
|
* Authoritative typed parameter defaults. The batch must contain one row
|
|
73
73
|
* and only defaulted parameters, in signature order; a present null is an
|
|
74
74
|
* explicit null default. `vgi_default` field metadata remains discovery-only.
|
|
75
75
|
*/
|
|
76
|
-
parameterDefaultValues?: VgiBatch | null;
|
|
77
|
-
projectionPushdown?: boolean;
|
|
78
|
-
filterPushdown?: boolean;
|
|
79
|
-
samplingPushdown?: boolean;
|
|
76
|
+
parameterDefaultValues?: VgiBatch | null | undefined;
|
|
77
|
+
projectionPushdown?: boolean | undefined;
|
|
78
|
+
filterPushdown?: boolean | undefined;
|
|
79
|
+
samplingPushdown?: boolean | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* table (generator): opt in to DuckDB's late-materialization rewrite. A
|
|
82
82
|
* TOP_N/LIMIT/SAMPLE over a rowid-bearing table is rewritten into a SEMI
|
|
@@ -85,24 +85,24 @@ export interface FunctionMeta {
|
|
|
85
85
|
* as FunctionInfo `late_materialization`. Only honoured by the C++ extension
|
|
86
86
|
* for tables whose worker also guarantees a UNIQUE, snapshot-stable rowid.
|
|
87
87
|
*/
|
|
88
|
-
lateMaterialization?: boolean;
|
|
89
|
-
filterSemanticProfiles?: string[];
|
|
90
|
-
additionalFilterFunctions?: FilterFunctionCapability[];
|
|
91
|
-
runtimeFilterAlgorithms?: FilterFunctionCapability[];
|
|
92
|
-
filterEvaluationContexts?: EvaluationContextCapability[];
|
|
93
|
-
autoApplyFilters?: boolean;
|
|
94
|
-
preservesOrder?: OrderPreservation;
|
|
95
|
-
maxWorkers?: number;
|
|
96
|
-
requiredSettings?: string[];
|
|
97
|
-
requiredSecrets?: string[];
|
|
98
|
-
orderDependent?: OrderDependence;
|
|
99
|
-
distinctDependent?: DistinctDependence;
|
|
88
|
+
lateMaterialization?: boolean | undefined;
|
|
89
|
+
filterSemanticProfiles?: string[] | undefined;
|
|
90
|
+
additionalFilterFunctions?: FilterFunctionCapability[] | undefined;
|
|
91
|
+
runtimeFilterAlgorithms?: FilterFunctionCapability[] | undefined;
|
|
92
|
+
filterEvaluationContexts?: EvaluationContextCapability[] | undefined;
|
|
93
|
+
autoApplyFilters?: boolean | undefined;
|
|
94
|
+
preservesOrder?: OrderPreservation | undefined;
|
|
95
|
+
maxWorkers?: number | undefined;
|
|
96
|
+
requiredSettings?: string[] | undefined;
|
|
97
|
+
requiredSecrets?: string[] | undefined;
|
|
98
|
+
orderDependent?: OrderDependence | undefined;
|
|
99
|
+
distinctDependent?: DistinctDependence | undefined;
|
|
100
100
|
/**
|
|
101
101
|
* For table_in_out functions: whether the user defined a finalize callback.
|
|
102
102
|
* DuckDB issues a separate FINALIZE init() phase only when this is true;
|
|
103
103
|
* otherwise calling FinalExecute is unsupported and crashes the C++ side.
|
|
104
104
|
*/
|
|
105
|
-
hasFinalize?: boolean;
|
|
105
|
+
hasFinalize?: boolean | undefined;
|
|
106
106
|
/**
|
|
107
107
|
* Blended ("UNNEST-style") table-in-out: the function's positional args ARE
|
|
108
108
|
* its per-row input columns (real typed args, no synthetic TABLE
|
|
@@ -114,36 +114,36 @@ export interface FunctionMeta {
|
|
|
114
114
|
* single-row scan-mode. Mirrors vgi-python's RowTransformFunction /
|
|
115
115
|
* ResolvedMetadata.input_from_args.
|
|
116
116
|
*/
|
|
117
|
-
inputFromArgs?: boolean;
|
|
117
|
+
inputFromArgs?: boolean | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* Blended only: the most input rows one worker call receives; the client
|
|
120
120
|
* splits each input chunk into calls of at most this many rows. Unset sends
|
|
121
121
|
* a whole chunk per call. Set by {@link defineRowTransformFunction}'s
|
|
122
122
|
* `inputRowsPerCall`; surfaces as FunctionInfo.input_rows_per_call.
|
|
123
123
|
*/
|
|
124
|
-
inputRowsPerCall?: number;
|
|
124
|
+
inputRowsPerCall?: number | undefined;
|
|
125
125
|
/**
|
|
126
126
|
* table_buffering: force ParallelSink=false in the C++ operator
|
|
127
127
|
* (single-thread, source-ordered ingest).
|
|
128
128
|
*/
|
|
129
|
-
sinkOrderDependent?: boolean;
|
|
129
|
+
sinkOrderDependent?: boolean | undefined;
|
|
130
130
|
/**
|
|
131
131
|
* table_buffering: force serial Source drain in finalize_queue order
|
|
132
132
|
* (ParallelSource=false, SourceOrder=FIXED_ORDER).
|
|
133
133
|
*/
|
|
134
|
-
sourceOrderDependent?: boolean;
|
|
134
|
+
sourceOrderDependent?: boolean | undefined;
|
|
135
135
|
/**
|
|
136
136
|
* table_buffering: thread DuckDB's per-chunk batch_index into every
|
|
137
137
|
* process() call (RequiredPartitionInfo=BatchIndex).
|
|
138
138
|
*/
|
|
139
|
-
requiresInputBatchIndex?: boolean;
|
|
139
|
+
requiresInputBatchIndex?: boolean | undefined;
|
|
140
140
|
/**
|
|
141
141
|
* table (generator): the function tags every emitted Arrow batch with a
|
|
142
142
|
* per-partition `vgi_batch_index` so DuckDB's ordered sinks reassemble
|
|
143
143
|
* parallel output in partition order. Surfaces as FunctionInfo
|
|
144
144
|
* `supports_batch_index`.
|
|
145
145
|
*/
|
|
146
|
-
supportsBatchIndex?: boolean;
|
|
146
|
+
supportsBatchIndex?: boolean | undefined;
|
|
147
147
|
/**
|
|
148
148
|
* table (generator): the scan divides into named, independently redeemable
|
|
149
149
|
* splits (see the `plan` / `onSplit` hooks). Surfaces as FunctionInfo
|
|
@@ -154,19 +154,19 @@ export interface FunctionMeta {
|
|
|
154
154
|
* same rows. Without it, the division lives behind an opaque worker-side queue
|
|
155
155
|
* and a retry reads neither what it read before nor what it missed.
|
|
156
156
|
*/
|
|
157
|
-
supportsSplits?: boolean;
|
|
157
|
+
supportsSplits?: boolean | undefined;
|
|
158
158
|
/**
|
|
159
159
|
* table (generator): the worker applies every pushed filter EXACTLY, so the
|
|
160
160
|
* engine may drop its own copy rather than re-filtering. Wrong answers if
|
|
161
161
|
* declared falsely — leave unset unless certain.
|
|
162
162
|
*/
|
|
163
|
-
filtersExactlyApplied?: boolean;
|
|
163
|
+
filtersExactlyApplied?: boolean | undefined;
|
|
164
164
|
/**
|
|
165
165
|
* table (generator): addressable positions in the data, for incremental and
|
|
166
166
|
* streaming reads. The engine owns the checkpoint; this declares only that
|
|
167
167
|
* positions are meaningful to externalize.
|
|
168
168
|
*/
|
|
169
|
-
supportsPositions?: boolean;
|
|
169
|
+
supportsPositions?: boolean | undefined;
|
|
170
170
|
/**
|
|
171
171
|
* table (generator): how long a split token stays redeemable.
|
|
172
172
|
*
|
|
@@ -175,14 +175,14 @@ export interface FunctionMeta {
|
|
|
175
175
|
* plan whose TTL is below its own planning-to-task-start horizon, which on a
|
|
176
176
|
* busy cluster is hours rather than seconds.
|
|
177
177
|
*/
|
|
178
|
-
splitTokenTtlSeconds?: number;
|
|
178
|
+
splitTokenTtlSeconds?: number | undefined;
|
|
179
179
|
/**
|
|
180
180
|
* table (generator): Hive-style partition-columns mode. Functions declare
|
|
181
181
|
* a PartitionKind and annotate bind-schema fields; emitted batches carry
|
|
182
182
|
* `vgi_partition_values#b64` metadata. Surfaces as FunctionInfo
|
|
183
183
|
* `partition_kind`.
|
|
184
184
|
*/
|
|
185
|
-
partitionKind?: "NOT_PARTITIONED" | "SINGLE_VALUE_PARTITIONS" | "OVERLAPPING_PARTITIONS" | "DISJOINT_PARTITIONS";
|
|
185
|
+
partitionKind?: "NOT_PARTITIONED" | "SINGLE_VALUE_PARTITIONS" | "OVERLAPPING_PARTITIONS" | "DISJOINT_PARTITIONS" | undefined;
|
|
186
186
|
/**
|
|
187
187
|
* COPY ... FROM custom format reader: the SQL `FORMAT` identifier this
|
|
188
188
|
* function backs (e.g. `example_lines`). Set by {@link defineCopyFromFunction}.
|
|
@@ -191,11 +191,11 @@ export interface FunctionMeta {
|
|
|
191
191
|
* extension registers a DuckDB CopyFunction for it. Mirrors vgi-python's
|
|
192
192
|
* `CopyFromFunction.COPY_FROM_FORMAT`.
|
|
193
193
|
*/
|
|
194
|
-
copyFromFormat?: string;
|
|
194
|
+
copyFromFormat?: string | undefined;
|
|
195
195
|
/** COPY direction; only `"from"` is supported today. Default `"from"`. */
|
|
196
|
-
copyFromDirection?: string;
|
|
196
|
+
copyFromDirection?: string | undefined;
|
|
197
197
|
/** Optional free-text comment surfaced by `vgi_copy_formats()`. */
|
|
198
|
-
copyFromComment?: string | null;
|
|
198
|
+
copyFromComment?: string | null | undefined;
|
|
199
199
|
/**
|
|
200
200
|
* COPY ... TO custom format writer: the SQL `FORMAT` identifier this function
|
|
201
201
|
* backs (e.g. `example_lines_out`). Set by {@link defineCopyToFunction}. When
|
|
@@ -206,19 +206,29 @@ export interface FunctionMeta {
|
|
|
206
206
|
* `table_buffering_process` / `table_buffering_combine` RPCs. Mirrors
|
|
207
207
|
* vgi-python's `CopyToFunction.COPY_TO_FORMAT`.
|
|
208
208
|
*/
|
|
209
|
-
copyToFormat?: string;
|
|
209
|
+
copyToFormat?: string | undefined;
|
|
210
210
|
/** COPY direction for a TO writer; always `"to"`. Default `"to"`. */
|
|
211
|
-
copyToDirection?: string;
|
|
211
|
+
copyToDirection?: string | undefined;
|
|
212
212
|
/** Optional free-text comment surfaced by `vgi_copy_formats()`. */
|
|
213
|
-
copyToComment?: string | null;
|
|
213
|
+
copyToComment?: string | null | undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The user state a rebuilt HTTP turn restores, boxed so `null` state survives. */
|
|
217
|
+
export interface RestoredUserState {
|
|
218
|
+
state: unknown;
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
export interface StreamHandlers {
|
|
217
|
-
// For producer streams (table functions, finalize phase)
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
// For producer streams (table functions, finalize phase).
|
|
223
|
+
//
|
|
224
|
+
// `restored` is the user state an HTTP turn carried in its cursor. When it
|
|
225
|
+
// is given the handler must adopt it instead of computing a fresh one, so
|
|
226
|
+
// `initialState` runs once per stream, not once per turn (a rebuilt turn
|
|
227
|
+
// used to call it and then discard the result).
|
|
228
|
+
producerInit?: ((restored?: RestoredUserState) => any) | undefined;
|
|
229
|
+
producerFn?: ((state: any, out: OutputCollector) => void | Promise<void>) | undefined;
|
|
220
230
|
// For exchange streams (scalar, table-in-out input phase)
|
|
221
|
-
exchangeInit?: () => any;
|
|
231
|
+
exchangeInit?: ((restored?: RestoredUserState) => any) | undefined;
|
|
222
232
|
exchangeFn?: (
|
|
223
233
|
state: any,
|
|
224
234
|
input: VgiBatch,
|
|
@@ -227,7 +237,7 @@ export interface StreamHandlers {
|
|
|
227
237
|
// Output schema for the stream
|
|
228
238
|
outputSchema: VgiSchema;
|
|
229
239
|
// Input schema for exchange (empty for producer)
|
|
230
|
-
inputSchema?: VgiSchema;
|
|
240
|
+
inputSchema?: VgiSchema | undefined;
|
|
231
241
|
/**
|
|
232
242
|
* Fires once per tick batch on the producer path, before `producerFn`.
|
|
233
243
|
* Receives the tick's Arrow custom metadata so the handler can pick up
|
|
@@ -241,7 +251,7 @@ export interface StreamHandlers {
|
|
|
241
251
|
* handler state, which the dispatcher carries in the HTTP state token. Every
|
|
242
252
|
* other stream's reply is refused if it says HAVE_MORE_OUTPUT.
|
|
243
253
|
*/
|
|
244
|
-
continuesOutput?: boolean;
|
|
254
|
+
continuesOutput?: boolean | undefined;
|
|
245
255
|
}
|
|
246
256
|
|
|
247
257
|
/**
|
|
@@ -252,7 +262,7 @@ export interface VgiFunction {
|
|
|
252
262
|
meta: FunctionMeta;
|
|
253
263
|
argumentSpecs: ArgumentSpec[];
|
|
254
264
|
/** Default output schema (for catalog registration). May be overridden at bind time. */
|
|
255
|
-
defaultOutputSchema?: VgiSchema;
|
|
265
|
+
defaultOutputSchema?: VgiSchema | undefined;
|
|
256
266
|
bind(request: BindRequest): BindResponse | Promise<BindResponse>;
|
|
257
267
|
globalInit(request: InitRequest): GlobalInitResponse | Promise<GlobalInitResponse>;
|
|
258
268
|
/**
|
|
@@ -3123,12 +3123,14 @@ export function registerVgiService(protocol: Protocol, service: VgiService): Pro
|
|
|
3123
3123
|
continue;
|
|
3124
3124
|
}
|
|
3125
3125
|
const stream = service[m.key] as VgiStream;
|
|
3126
|
+
// Optional members are spread in only when present, so the options bag
|
|
3127
|
+
// type-checks under exactOptionalPropertyTypes.
|
|
3126
3128
|
const common = {
|
|
3127
3129
|
params: m.params,
|
|
3128
3130
|
outputSchema: stream.outputSchema,
|
|
3129
|
-
headerSchema: m.header
|
|
3130
|
-
headerInit: stream.headerInit,
|
|
3131
|
-
onCancel: stream.onCancel,
|
|
3131
|
+
...(m.header ? { headerSchema: m.header } : {}),
|
|
3132
|
+
...(stream.headerInit ? { headerInit: stream.headerInit } : {}),
|
|
3133
|
+
...(stream.onCancel ? { onCancel: stream.onCancel } : {}),
|
|
3132
3134
|
doc: m.doc,
|
|
3133
3135
|
};
|
|
3134
3136
|
if (stream.kind === "exchange") {
|
package/src/http/fetch.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// `buildVgiProtocol` as `signingKey`, from one source. Passing different keys to
|
|
11
11
|
// those two seams produces a worker that mints tokens it cannot recover.
|
|
12
12
|
|
|
13
|
+
import { omitUndefined } from "../util/defined.js";
|
|
13
14
|
import {
|
|
14
15
|
AuthContext,
|
|
15
16
|
createHttpHandler,
|
|
@@ -41,14 +42,14 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
41
42
|
* configured key hosts `vgi.attach_tickets.v1` (with the ability to issue
|
|
42
43
|
* grants): tickets sealed under a generated key would die on restart.
|
|
43
44
|
* Defaults to `true`, since this factory requires the key to be passed. */
|
|
44
|
-
signingKeyConfigured?: boolean;
|
|
45
|
+
signingKeyConfigured?: boolean | undefined;
|
|
45
46
|
/** State-token TTL in seconds (default 3600). */
|
|
46
|
-
tokenTtl?: number;
|
|
47
|
+
tokenTtl?: number | undefined;
|
|
47
48
|
/** URL path prefix for VGI requests (default "/vgi"). Pass "" to mount at
|
|
48
49
|
* the root, which is what a dedicated single-worker HTTP server wants. */
|
|
49
|
-
prefix?: string;
|
|
50
|
+
prefix?: string | undefined;
|
|
50
51
|
/** Server ID for state-token attribution (default "vgi-cf"). */
|
|
51
|
-
serverId?: string;
|
|
52
|
+
serverId?: string | undefined;
|
|
52
53
|
/** CORS allowed origins, added to all responses so the preflight `OPTIONS`
|
|
53
54
|
* that browser clients send before `__describe__` succeeds.
|
|
54
55
|
*
|
|
@@ -60,9 +61,9 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
60
61
|
* always defaulted this way; this matches it so both entries agree.
|
|
61
62
|
*
|
|
62
63
|
* Pass `null` to disable CORS. */
|
|
63
|
-
corsOrigins?: string | null;
|
|
64
|
+
corsOrigins?: string | null | undefined;
|
|
64
65
|
/** Public source-repository URL, surfaced on the landing page. */
|
|
65
|
-
repositoryUrl?: string;
|
|
66
|
+
repositoryUrl?: string | undefined;
|
|
66
67
|
/** Worker identity for the standardized VGI landing surface: `GET /` serves
|
|
67
68
|
* the shared landing.html plus a JSON status document carrying this
|
|
68
69
|
* identity, and `GET /vgi-client.js` serves the browser client build the
|
|
@@ -85,13 +86,13 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
85
86
|
* Supplying it is what makes a worker able to serve more than one principal,
|
|
86
87
|
* and the identity it returns is the one the worker seals `attach_opaque_data`
|
|
87
88
|
* and split tokens under. */
|
|
88
|
-
authenticate?: AuthenticateFn;
|
|
89
|
+
authenticate?: AuthenticateFn | undefined;
|
|
89
90
|
/** Off-wire transport identities, including a trusted Iroh HTTP bridge. */
|
|
90
|
-
peerIdentityProviders?: readonly PeerIdentityProvider[];
|
|
91
|
+
peerIdentityProviders?: readonly PeerIdentityProvider[] | undefined;
|
|
91
92
|
/** Policy composing peer evidence with application authentication. */
|
|
92
|
-
peerAuthenticationPolicy?: PeerAuthenticationPolicy;
|
|
93
|
+
peerAuthenticationPolicy?: PeerAuthenticationPolicy | undefined;
|
|
93
94
|
/** Host adapter supplying the physical peer and multiplicity-preserving headers. */
|
|
94
|
-
peerResolutionContext?: (request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions
|
|
95
|
+
peerResolutionContext?: ((request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>) | undefined;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// ---------------------------------------------------------------------------
|
|
@@ -226,7 +227,11 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
|
|
|
226
227
|
const reservedCheck = checkReservedAttachOptions(opts.protocol.catalogInterface);
|
|
227
228
|
reservedCheck.catch((e) => console.error(`VGI worker refused to serve: ${(e as Error).message}`));
|
|
228
229
|
|
|
229
|
-
|
|
230
|
+
// vgi-rpc's own types disagree under exactOptionalPropertyTypes:
|
|
231
|
+
// `VgiRpcServer.identity` is `IdentityImpl | undefined` while `ProtocolHost`
|
|
232
|
+
// declares `identity?: {...}` without `| undefined`. Both mean "may be
|
|
233
|
+
// absent"; the cast only bridges the declarations.
|
|
234
|
+
const handler = createHttpHandler(server as Parameters<typeof createHttpHandler>[0], omitUndefined({
|
|
230
235
|
prefix,
|
|
231
236
|
serverId,
|
|
232
237
|
tokenKey: opts.signingKey,
|
|
@@ -249,7 +254,7 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
|
|
|
249
254
|
// no reason — a VGI worker always has the real thing.
|
|
250
255
|
extraRoutes: createLandingRoutes(opts.landingInfo),
|
|
251
256
|
enableLandingPage: false,
|
|
252
|
-
});
|
|
257
|
+
}));
|
|
253
258
|
return async (req: Request) => {
|
|
254
259
|
await reservedCheck;
|
|
255
260
|
const storage = await ensureRequestAuthStorage();
|
package/src/index.core.ts
CHANGED
|
@@ -31,7 +31,7 @@ export {
|
|
|
31
31
|
} from "./cache-control.js";
|
|
32
32
|
|
|
33
33
|
// Function factories (primary API)
|
|
34
|
-
export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarParameterDef } from "./functions/scalar.js";
|
|
34
|
+
export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarComputeInfo, type ScalarParameterDef } from "./functions/scalar.js";
|
|
35
35
|
export { defineTableFunction, type TableFunctionConfig, type TableBindParams, type TableProcessParams } from "./functions/table.js";
|
|
36
36
|
export {
|
|
37
37
|
defineAggregate,
|
|
@@ -366,6 +366,8 @@ export { VgiClient, VgiClientError } from "./client/client.js";
|
|
|
366
366
|
export type {
|
|
367
367
|
VgiClientOptions,
|
|
368
368
|
TableFunctionOptions,
|
|
369
|
+
TableFunctionRowsOptions,
|
|
370
|
+
Int64Mode,
|
|
369
371
|
ScalarFunctionOptions,
|
|
370
372
|
TableInOutFunctionOptions,
|
|
371
373
|
OnCreateConflict,
|
|
@@ -93,7 +93,7 @@ const stats = { parses: 0, hits: 0 };
|
|
|
93
93
|
function hashBytes(bytes: Uint8Array): number {
|
|
94
94
|
let h = 0x811c9dc5 ^ bytes.byteLength;
|
|
95
95
|
for (let i = 0; i < bytes.byteLength; i++) {
|
|
96
|
-
h ^= bytes[i]
|
|
96
|
+
h ^= bytes[i]!;
|
|
97
97
|
h = Math.imul(h, 0x01000193);
|
|
98
98
|
}
|
|
99
99
|
return h >>> 0;
|
package/src/protocol/dispatch.ts
CHANGED
|
@@ -21,15 +21,15 @@ import { catalogHandlers } from "./handlers/catalog/index.js";
|
|
|
21
21
|
|
|
22
22
|
export interface ProtocolConfig {
|
|
23
23
|
registry: FunctionRegistry;
|
|
24
|
-
catalogInterface?: CatalogInterface;
|
|
25
|
-
catalogName?: string;
|
|
24
|
+
catalogInterface?: CatalogInterface | undefined;
|
|
25
|
+
catalogName?: string | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* AEAD signing key for sealing catalog opaque-data envelopes. Pass the same
|
|
28
28
|
* 32-byte key used for HTTP state tokens. When omitted (subprocess / unix
|
|
29
29
|
* transports) attach_opaque_data / transaction_opaque_data pass through
|
|
30
30
|
* unsealed — OS process ownership already enforces identity there.
|
|
31
31
|
*/
|
|
32
|
-
signingKey?: Uint8Array;
|
|
32
|
+
signingKey?: Uint8Array | undefined;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -203,8 +203,8 @@ export function aggregateHandlers(registry: FunctionRegistry): Partial<VgiServic
|
|
|
203
203
|
}
|
|
204
204
|
const touchedTargets = new Set<bigint>();
|
|
205
205
|
for (let i = 0; i < batch.numRows; i++) {
|
|
206
|
-
const src = srcIds[i]
|
|
207
|
-
const tgt = tgtIds[i]
|
|
206
|
+
const src = srcIds[i]!;
|
|
207
|
+
const tgt = tgtIds[i]!;
|
|
208
208
|
const srcHas = exec.states.has(src);
|
|
209
209
|
const tgtHas = exec.states.has(tgt);
|
|
210
210
|
if (!srcHas && !tgtHas) continue;
|
|
@@ -307,6 +307,7 @@ function extractArgMap(
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
for (let i = 0; i < constNames.length; i++) {
|
|
310
|
+
const name = constNames[i]!;
|
|
310
311
|
let v: any;
|
|
311
312
|
try {
|
|
312
313
|
v = args.get(i);
|
|
@@ -325,18 +326,18 @@ function extractArgMap(
|
|
|
325
326
|
// args.get throws when the arg isn't set — fall back to the declared
|
|
326
327
|
// default so aggregates called without an explicit const value still
|
|
327
328
|
// see it in update/finalize.
|
|
328
|
-
const def = cfg.argDefaults?.[
|
|
329
|
-
if (def !== undefined) out[
|
|
329
|
+
const def = cfg.argDefaults?.[name];
|
|
330
|
+
if (def !== undefined) out[name] = def;
|
|
330
331
|
continue;
|
|
331
332
|
}
|
|
332
333
|
// Enforce declared constraints on the supplied value. This sits OUTSIDE the
|
|
333
334
|
// try above so a constraint violation propagates as a bind error rather than
|
|
334
335
|
// being swallowed and silently replaced by the default.
|
|
335
|
-
const constraints = cfg.argConstraints?.[
|
|
336
|
+
const constraints = cfg.argConstraints?.[name];
|
|
336
337
|
if (constraints !== undefined) {
|
|
337
|
-
validateConstConstraints(
|
|
338
|
+
validateConstConstraints(name, constraints, v);
|
|
338
339
|
}
|
|
339
|
-
out[
|
|
340
|
+
out[name] = v;
|
|
340
341
|
}
|
|
341
342
|
// Non-const args aren't in the wire Arguments, but users may still want
|
|
342
343
|
// defaults surfaced for `params.args` — apply them here.
|
|
@@ -81,7 +81,7 @@ export async function openAttach(
|
|
|
81
81
|
/** Hex of a byte array (lowercase). */
|
|
82
82
|
function toHex(b: Uint8Array): string {
|
|
83
83
|
let s = "";
|
|
84
|
-
for (let i = 0; i < b.length; i++) s += b[i]
|
|
84
|
+
for (let i = 0; i < b.length; i++) s += b[i]!.toString(16).padStart(2, "0");
|
|
85
85
|
return s;
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
|
|
56
56
|
export interface FunctionHandlerConfig {
|
|
57
57
|
registry: FunctionRegistry;
|
|
58
|
-
signingKey?: Uint8Array;
|
|
58
|
+
signingKey?: Uint8Array | undefined;
|
|
59
59
|
/**
|
|
60
60
|
* Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
|
|
61
61
|
* be scoped when two catalogs declare the same schema and function name.
|
|
@@ -74,7 +74,7 @@ export interface FunctionHandlerConfig {
|
|
|
74
74
|
* livelock returning no rows, blaming the data for moving when it has not.
|
|
75
75
|
*/
|
|
76
76
|
version?(attach: Uint8Array, txn?: Uint8Array): number | Promise<number>;
|
|
77
|
-
};
|
|
77
|
+
} | undefined;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -374,6 +374,14 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
374
374
|
// cursor carries the packed request unchanged on every turn.
|
|
375
375
|
const carried = parseCarriedInitRequest(state.initRequestPacked);
|
|
376
376
|
const request = carried.request;
|
|
377
|
+
// The cursor carries the wire request, whose attach is still the sealed
|
|
378
|
+
// envelope. Strip it exactly as the init turn did, before any user code
|
|
379
|
+
// or split resolution sees it: every turn of a stream must hand the
|
|
380
|
+
// function the catalog's own bytes, not just the first. (Unopenable is
|
|
381
|
+
// a hard error here, as on the init turn: the cursor is caller-bound.)
|
|
382
|
+
// `carried.request.bind_call` is a per-call copy, so this does not
|
|
383
|
+
// disturb the memoised parse other turns share.
|
|
384
|
+
request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
|
|
377
385
|
// Re-derive the split payloads. The cursor carries the wire request,
|
|
378
386
|
// which has `split_tokens` but not the opened `split_payloads` — that
|
|
379
387
|
// field only ever existed in memory on the init turn. Without this a
|
|
@@ -396,7 +404,9 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
396
404
|
catalogInterface,
|
|
397
405
|
checkAnchor: false,
|
|
398
406
|
});
|
|
399
|
-
|
|
407
|
+
// Already stripped above, so resolve directly (strippedContext would try
|
|
408
|
+
// to open the plaintext again and fall back to an unscoped lookup).
|
|
409
|
+
const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
|
|
400
410
|
const executionId = state.executionId;
|
|
401
411
|
const opaqueData = state.opaqueData ?? null;
|
|
402
412
|
const initResponse: GlobalInitResponse = {
|
|
@@ -409,10 +419,13 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
409
419
|
// after the one that received a delta would scan under the init
|
|
410
420
|
// snapshot again, because the extension sends each delta only once.
|
|
411
421
|
handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
|
|
422
|
+
// Hand the carried user state to the init hook, so a handler that
|
|
423
|
+
// supports it skips initialState (which already ran on the init turn).
|
|
424
|
+
const restored = state.userState != null ? { state: state.userState } : undefined;
|
|
412
425
|
if (handlers.producerInit) {
|
|
413
|
-
handlerState = handlers.producerInit();
|
|
426
|
+
handlerState = handlers.producerInit(restored);
|
|
414
427
|
} else if (handlers.exchangeInit) {
|
|
415
|
-
handlerState = handlers.exchangeInit();
|
|
428
|
+
handlerState = handlers.exchangeInit(restored);
|
|
416
429
|
}
|
|
417
430
|
// Merge preserved user state (e.g. { remaining, currentIndex })
|
|
418
431
|
if (state.userState != null && handlerState?.state !== undefined) {
|