@query-farm/vgi 0.10.0 → 0.12.0
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/dist/functions/aggregate.d.ts +8 -0
- package/dist/functions/table.d.ts +8 -0
- package/dist/index.js +16 -5
- package/dist/index.js.map +5 -5
- package/dist/worker-cf-entry.js +197 -186
- package/dist/worker-cf-entry.js.map +7 -7
- package/package.json +1 -1
- package/src/functions/aggregate.ts +13 -1
- package/src/functions/table.ts +17 -1
- package/src/protocol/handlers/aggregate.ts +12 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VgiSchema, type VgiBatch, type VgiDataType } from "../arrow/index.js";
|
|
2
2
|
import type { Arguments } from "../arguments/arguments.js";
|
|
3
|
+
import { type ArgumentConstraints } from "../arguments/argument-spec.js";
|
|
3
4
|
import type { VgiFunction } from "./types.js";
|
|
4
5
|
import type { FunctionExample } from "./types.js";
|
|
5
6
|
export declare const GROUP_COLUMN_NAME = "__vgi_group_id";
|
|
@@ -70,6 +71,13 @@ export interface AggregateFunctionConfig<TArgs = Record<string, any>, TState = a
|
|
|
70
71
|
onBind?: (params: AggregateBindParams<TArgs>) => VgiDataType | Promise<VgiDataType>;
|
|
71
72
|
/** Optional per-arg default values (positional only here). */
|
|
72
73
|
argDefaults?: Record<string, any>;
|
|
74
|
+
/**
|
|
75
|
+
* Per-argument discovery constraints (choices / ge / le / gt / lt / pattern),
|
|
76
|
+
* keyed by argument name. Surfaced via `vgi_function_arguments()` and enforced
|
|
77
|
+
* at aggregate_bind for const params: a value violating a declared constraint
|
|
78
|
+
* fails the bind with an ArgumentValidationError.
|
|
79
|
+
*/
|
|
80
|
+
argConstraints?: Record<string, ArgumentConstraints>;
|
|
73
81
|
initialState: (params: AggregateBindParams<TArgs>) => TState;
|
|
74
82
|
/**
|
|
75
83
|
* Fold a batch of input rows into the provided per-group state map.
|
|
@@ -2,6 +2,7 @@ import { type VgiSchema, type VgiDataType } from "../arrow/index.js";
|
|
|
2
2
|
import type { OutputCollector } from "@query-farm/vgi-rpc";
|
|
3
3
|
import type { BindRequest, InitRequest, GlobalInitResponse, TableCardinality } from "../protocol/types.js";
|
|
4
4
|
import type { VgiFunction, FunctionExample } from "./types.js";
|
|
5
|
+
import { type ArgumentConstraints } from "../arguments/argument-spec.js";
|
|
5
6
|
import { type PushdownFilters } from "../filter-pushdown/index.js";
|
|
6
7
|
import type { ColumnStatistics } from "../util/statistics.js";
|
|
7
8
|
import { FunctionStability, type NullHandling, type OrderPreservation, type OrderDependence, type DistinctDependence } from "../types.js";
|
|
@@ -41,6 +42,13 @@ export interface TableFunctionConfig<TArgs = Record<string, any>, TState = null>
|
|
|
41
42
|
argDocs?: Record<string, string>;
|
|
42
43
|
/** Argument defaults */
|
|
43
44
|
argDefaults?: Record<string, any>;
|
|
45
|
+
/**
|
|
46
|
+
* Per-argument discovery constraints (choices / ge / le / gt / lt / pattern),
|
|
47
|
+
* keyed by argument name. Surfaced via `vgi_function_arguments()` for agent
|
|
48
|
+
* discovery AND enforced at bind: a value violating a declared constraint
|
|
49
|
+
* fails the bind with an ArgumentValidationError.
|
|
50
|
+
*/
|
|
51
|
+
argConstraints?: Record<string, ArgumentConstraints>;
|
|
44
52
|
/** Names of args that accept variable number of arguments */
|
|
45
53
|
varargs?: string[];
|
|
46
54
|
/** Bind: return output schema. May be async — handlers `await` the result. */
|
package/dist/index.js
CHANGED
|
@@ -3864,7 +3864,8 @@ function defineTableFunction(config) {
|
|
|
3864
3864
|
arrowType: isAny ? nullType2() : type,
|
|
3865
3865
|
isAnyType: isAny,
|
|
3866
3866
|
isVarargs: varargsSet.has(name),
|
|
3867
|
-
doc: config.argDocs?.[name]
|
|
3867
|
+
doc: config.argDocs?.[name],
|
|
3868
|
+
...constraintSpecFields(config.argConstraints?.[name])
|
|
3868
3869
|
});
|
|
3869
3870
|
}
|
|
3870
3871
|
}
|
|
@@ -3903,6 +3904,9 @@ function defineTableFunction(config) {
|
|
|
3903
3904
|
}
|
|
3904
3905
|
if (typeof val === "bigint")
|
|
3905
3906
|
val = safeNumber(val);
|
|
3907
|
+
const constraints = config.argConstraints?.[spec.name];
|
|
3908
|
+
if (constraints)
|
|
3909
|
+
validateConstConstraints(spec.name, constraints, val);
|
|
3906
3910
|
args[spec.name] = val;
|
|
3907
3911
|
}
|
|
3908
3912
|
return args;
|
|
@@ -4178,7 +4182,8 @@ function defineAggregate(config) {
|
|
|
4178
4182
|
arrowType: isAnyType2 ? nullType2() : type,
|
|
4179
4183
|
isAnyType: isAnyType2,
|
|
4180
4184
|
isVarargs: varargsSet.has(name),
|
|
4181
|
-
isConst
|
|
4185
|
+
isConst,
|
|
4186
|
+
...constraintSpecFields(config.argConstraints?.[name])
|
|
4182
4187
|
});
|
|
4183
4188
|
}
|
|
4184
4189
|
}
|
|
@@ -9140,8 +9145,9 @@ function extractArgMap(cfg, args) {
|
|
|
9140
9145
|
}
|
|
9141
9146
|
}
|
|
9142
9147
|
for (let i = 0;i < constNames.length; i++) {
|
|
9148
|
+
let v;
|
|
9143
9149
|
try {
|
|
9144
|
-
|
|
9150
|
+
v = args.get(i);
|
|
9145
9151
|
const field3 = args.argumentsSchema?.fields.find((f) => f.name === `positional_${i}`);
|
|
9146
9152
|
if (field3 && isDecimal(field3.type)) {
|
|
9147
9153
|
const scale = field3.type.scale;
|
|
@@ -9152,12 +9158,17 @@ function extractArgMap(cfg, args) {
|
|
|
9152
9158
|
} else if (typeof v === "bigint") {
|
|
9153
9159
|
v = Number(v);
|
|
9154
9160
|
}
|
|
9155
|
-
out[constNames[i]] = v;
|
|
9156
9161
|
} catch {
|
|
9157
9162
|
const def = cfg.argDefaults?.[constNames[i]];
|
|
9158
9163
|
if (def !== undefined)
|
|
9159
9164
|
out[constNames[i]] = def;
|
|
9165
|
+
continue;
|
|
9166
|
+
}
|
|
9167
|
+
const constraints = cfg.argConstraints?.[constNames[i]];
|
|
9168
|
+
if (constraints !== undefined) {
|
|
9169
|
+
validateConstConstraints(constNames[i], constraints, v);
|
|
9160
9170
|
}
|
|
9171
|
+
out[constNames[i]] = v;
|
|
9161
9172
|
}
|
|
9162
9173
|
if (cfg.argDefaults) {
|
|
9163
9174
|
for (const [name, def] of Object.entries(cfg.argDefaults)) {
|
|
@@ -11057,4 +11068,4 @@ export {
|
|
|
11057
11068
|
ArgumentValidationError
|
|
11058
11069
|
};
|
|
11059
11070
|
|
|
11060
|
-
//# debugId=
|
|
11071
|
+
//# debugId=606DBE277F7C8D1D64756E2164756E21
|