@query-farm/vgi 0.8.0 → 0.10.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/arguments/argument-spec.d.ts +56 -0
- package/dist/functions/scalar.d.ts +14 -0
- package/dist/index.core.d.ts +1 -1
- package/dist/index.js +245 -105
- package/dist/index.js.map +7 -7
- package/dist/types.d.ts +4 -0
- package/dist/worker-cf-entry.js +208 -69
- package/dist/worker-cf-entry.js.map +6 -6
- package/package.json +1 -1
- package/src/arguments/argument-spec.ts +216 -0
- package/src/functions/scalar.ts +48 -2
- package/src/index.core.ts +1 -1
- package/src/types.ts +14 -0
package/dist/types.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ export declare const VGI_VARARGS_TRUE = "true";
|
|
|
45
45
|
export declare const VGI_CONST_KEY = "vgi_const";
|
|
46
46
|
export declare const VGI_CONST_TRUE = "true";
|
|
47
47
|
export declare const VGI_DOC_KEY = "vgi_doc";
|
|
48
|
+
export declare const VGI_DEFAULT_KEY = "vgi_default";
|
|
49
|
+
export declare const VGI_CHOICES_KEY = "vgi_choices";
|
|
50
|
+
export declare const VGI_RANGE_KEY = "vgi_range";
|
|
51
|
+
export declare const VGI_PATTERN_KEY = "vgi_pattern";
|
|
48
52
|
export interface TableCardinality {
|
|
49
53
|
estimate: number | null;
|
|
50
54
|
max: number | null;
|
package/dist/worker-cf-entry.js
CHANGED
|
@@ -2850,6 +2850,10 @@ var VGI_VARARGS_TRUE = "true";
|
|
|
2850
2850
|
var VGI_CONST_KEY = "vgi_const";
|
|
2851
2851
|
var VGI_CONST_TRUE = "true";
|
|
2852
2852
|
var VGI_DOC_KEY = "vgi_doc";
|
|
2853
|
+
var VGI_DEFAULT_KEY = "vgi_default";
|
|
2854
|
+
var VGI_CHOICES_KEY = "vgi_choices";
|
|
2855
|
+
var VGI_RANGE_KEY = "vgi_range";
|
|
2856
|
+
var VGI_PATTERN_KEY = "vgi_pattern";
|
|
2853
2857
|
var DEFAULT_MAX_WORKERS = 99999;
|
|
2854
2858
|
|
|
2855
2859
|
// src/util/arrow/index.ts
|
|
@@ -3823,6 +3827,13 @@ class CatalogReadOnlyError extends VgiError {
|
|
|
3823
3827
|
this.name = "CatalogReadOnlyError";
|
|
3824
3828
|
}
|
|
3825
3829
|
}
|
|
3830
|
+
class ArgumentValidationError extends VgiError {
|
|
3831
|
+
constructor(message) {
|
|
3832
|
+
super(message);
|
|
3833
|
+
this.name = "ArgumentValidationError";
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3826
3837
|
class NoCatalogError extends VgiError {
|
|
3827
3838
|
constructor() {
|
|
3828
3839
|
super("No catalog is configured for this worker");
|
|
@@ -6985,6 +6996,187 @@ function buildVgiProtocol(config) {
|
|
|
6985
6996
|
|
|
6986
6997
|
// src/functions/scalar.ts
|
|
6987
6998
|
init_arrow();
|
|
6999
|
+
|
|
7000
|
+
// src/arguments/argument-spec.ts
|
|
7001
|
+
init_arrow();
|
|
7002
|
+
function safeJson(value) {
|
|
7003
|
+
try {
|
|
7004
|
+
const encoded = JSON.stringify(value);
|
|
7005
|
+
if (encoded === undefined) {
|
|
7006
|
+
return JSON.stringify(String(value));
|
|
7007
|
+
}
|
|
7008
|
+
return encoded;
|
|
7009
|
+
} catch {
|
|
7010
|
+
return JSON.stringify(String(value));
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
function formatRange(ge, le, gt, lt) {
|
|
7014
|
+
if (ge === undefined && le === undefined && gt === undefined && lt === undefined) {
|
|
7015
|
+
return;
|
|
7016
|
+
}
|
|
7017
|
+
let low;
|
|
7018
|
+
if (gt !== undefined) {
|
|
7019
|
+
low = `(${gt}`;
|
|
7020
|
+
} else if (ge !== undefined) {
|
|
7021
|
+
low = `[${ge}`;
|
|
7022
|
+
} else {
|
|
7023
|
+
low = "(-inf";
|
|
7024
|
+
}
|
|
7025
|
+
let high;
|
|
7026
|
+
if (lt !== undefined) {
|
|
7027
|
+
high = `${lt})`;
|
|
7028
|
+
} else if (le !== undefined) {
|
|
7029
|
+
high = `${le}]`;
|
|
7030
|
+
} else {
|
|
7031
|
+
high = "+inf)";
|
|
7032
|
+
}
|
|
7033
|
+
return `${low}, ${high}`;
|
|
7034
|
+
}
|
|
7035
|
+
function constraintSpecFields(constraints) {
|
|
7036
|
+
const fields = {};
|
|
7037
|
+
if (constraints === undefined)
|
|
7038
|
+
return fields;
|
|
7039
|
+
if ("default" in constraints && constraints.default !== undefined) {
|
|
7040
|
+
fields.defaultJson = safeJson(constraints.default);
|
|
7041
|
+
}
|
|
7042
|
+
if (constraints.choices !== undefined) {
|
|
7043
|
+
fields.choicesJson = safeJson([...constraints.choices]);
|
|
7044
|
+
}
|
|
7045
|
+
const range = formatRange(constraints.ge, constraints.le, constraints.gt, constraints.lt);
|
|
7046
|
+
if (range !== undefined) {
|
|
7047
|
+
fields.rangeNotation = range;
|
|
7048
|
+
}
|
|
7049
|
+
if (constraints.pattern !== undefined) {
|
|
7050
|
+
fields.pattern = constraints.pattern;
|
|
7051
|
+
}
|
|
7052
|
+
return fields;
|
|
7053
|
+
}
|
|
7054
|
+
function toNumber(value) {
|
|
7055
|
+
if (typeof value === "number")
|
|
7056
|
+
return value;
|
|
7057
|
+
if (typeof value === "bigint")
|
|
7058
|
+
return Number(value);
|
|
7059
|
+
return;
|
|
7060
|
+
}
|
|
7061
|
+
function choiceEquals(choice, value) {
|
|
7062
|
+
const cn = toNumber(choice);
|
|
7063
|
+
const vn = toNumber(value);
|
|
7064
|
+
if (cn !== undefined && vn !== undefined)
|
|
7065
|
+
return cn === vn;
|
|
7066
|
+
return choice === value;
|
|
7067
|
+
}
|
|
7068
|
+
function validateConstConstraints(name, constraints, value) {
|
|
7069
|
+
if (value === null || value === undefined)
|
|
7070
|
+
return;
|
|
7071
|
+
const num = toNumber(value);
|
|
7072
|
+
if (num !== undefined) {
|
|
7073
|
+
if (constraints.ge !== undefined && num < constraints.ge) {
|
|
7074
|
+
throw new ArgumentValidationError(`argument '${name}' must be >= ${constraints.ge}`);
|
|
7075
|
+
}
|
|
7076
|
+
if (constraints.le !== undefined && num > constraints.le) {
|
|
7077
|
+
throw new ArgumentValidationError(`argument '${name}' must be <= ${constraints.le}`);
|
|
7078
|
+
}
|
|
7079
|
+
if (constraints.gt !== undefined && num <= constraints.gt) {
|
|
7080
|
+
throw new ArgumentValidationError(`argument '${name}' must be > ${constraints.gt}`);
|
|
7081
|
+
}
|
|
7082
|
+
if (constraints.lt !== undefined && num >= constraints.lt) {
|
|
7083
|
+
throw new ArgumentValidationError(`argument '${name}' must be < ${constraints.lt}`);
|
|
7084
|
+
}
|
|
7085
|
+
}
|
|
7086
|
+
if (constraints.choices !== undefined && constraints.choices.length > 0) {
|
|
7087
|
+
if (!constraints.choices.some((c) => choiceEquals(c, value))) {
|
|
7088
|
+
throw new ArgumentValidationError(`argument '${name}' must be one of ${JSON.stringify([...constraints.choices])}`);
|
|
7089
|
+
}
|
|
7090
|
+
}
|
|
7091
|
+
if (constraints.pattern !== undefined && typeof value === "string") {
|
|
7092
|
+
let re;
|
|
7093
|
+
try {
|
|
7094
|
+
re = new RegExp(constraints.pattern);
|
|
7095
|
+
} catch {
|
|
7096
|
+
re = undefined;
|
|
7097
|
+
}
|
|
7098
|
+
if (re !== undefined && !re.test(value)) {
|
|
7099
|
+
throw new ArgumentValidationError(`argument '${name}' must match pattern ${JSON.stringify(constraints.pattern)}`);
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
function argumentSpecSortKey(spec) {
|
|
7104
|
+
if (typeof spec.position === "number") {
|
|
7105
|
+
return [0, spec.position];
|
|
7106
|
+
}
|
|
7107
|
+
return [1, spec.position];
|
|
7108
|
+
}
|
|
7109
|
+
function argumentSpecsToSchema(specs) {
|
|
7110
|
+
const sorted = [...specs].sort((a, b) => {
|
|
7111
|
+
const ka = argumentSpecSortKey(a);
|
|
7112
|
+
const kb = argumentSpecSortKey(b);
|
|
7113
|
+
if (ka[0] !== kb[0])
|
|
7114
|
+
return ka[0] - kb[0];
|
|
7115
|
+
if (typeof ka[1] === "number" && typeof kb[1] === "number") {
|
|
7116
|
+
return ka[1] - kb[1];
|
|
7117
|
+
}
|
|
7118
|
+
return String(ka[1]).localeCompare(String(kb[1]));
|
|
7119
|
+
});
|
|
7120
|
+
const fields = [];
|
|
7121
|
+
for (const spec of sorted) {
|
|
7122
|
+
const metadata = new Map;
|
|
7123
|
+
if (typeof spec.position === "string") {
|
|
7124
|
+
metadata.set(VGI_ARG_KEY, VGI_ARG_NAMED);
|
|
7125
|
+
}
|
|
7126
|
+
if (spec.isTableInput) {
|
|
7127
|
+
metadata.set(VGI_TYPE_KEY, VGI_TYPE_TABLE);
|
|
7128
|
+
} else if (spec.isAnyType) {
|
|
7129
|
+
metadata.set(VGI_TYPE_KEY, VGI_TYPE_ANY);
|
|
7130
|
+
}
|
|
7131
|
+
if (spec.isVarargs) {
|
|
7132
|
+
metadata.set(VGI_VARARGS_KEY, VGI_VARARGS_TRUE);
|
|
7133
|
+
}
|
|
7134
|
+
if (spec.isConst) {
|
|
7135
|
+
metadata.set(VGI_CONST_KEY, VGI_CONST_TRUE);
|
|
7136
|
+
}
|
|
7137
|
+
if (spec.doc) {
|
|
7138
|
+
metadata.set(VGI_DOC_KEY, spec.doc);
|
|
7139
|
+
}
|
|
7140
|
+
if (spec.defaultJson !== undefined) {
|
|
7141
|
+
metadata.set(VGI_DEFAULT_KEY, spec.defaultJson);
|
|
7142
|
+
}
|
|
7143
|
+
if (spec.choicesJson !== undefined) {
|
|
7144
|
+
metadata.set(VGI_CHOICES_KEY, spec.choicesJson);
|
|
7145
|
+
}
|
|
7146
|
+
if (spec.rangeNotation !== undefined) {
|
|
7147
|
+
metadata.set(VGI_RANGE_KEY, spec.rangeNotation);
|
|
7148
|
+
}
|
|
7149
|
+
if (spec.pattern !== undefined) {
|
|
7150
|
+
metadata.set(VGI_PATTERN_KEY, spec.pattern);
|
|
7151
|
+
}
|
|
7152
|
+
const field3 = field2(spec.name, spec.arrowType, true, metadata.size > 0 ? metadata : undefined);
|
|
7153
|
+
fields.push(field3);
|
|
7154
|
+
}
|
|
7155
|
+
return schema2(fields);
|
|
7156
|
+
}
|
|
7157
|
+
function macroArgumentsSchema(parameters, parameterDefaultValues, parameterDocs) {
|
|
7158
|
+
const docs = parameterDocs ?? {};
|
|
7159
|
+
const defaultTypes = new Map;
|
|
7160
|
+
if (parameterDefaultValues && parameterDefaultValues.length > 0) {
|
|
7161
|
+
const batch = deserializeBatch(parameterDefaultValues);
|
|
7162
|
+
for (const f of batch.schema.fields) {
|
|
7163
|
+
defaultTypes.set(f.name, f.type);
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
const fields = [];
|
|
7167
|
+
for (const name of parameters) {
|
|
7168
|
+
const metadata = new Map;
|
|
7169
|
+
const doc = docs[name];
|
|
7170
|
+
if (doc) {
|
|
7171
|
+
metadata.set(VGI_DOC_KEY, doc);
|
|
7172
|
+
}
|
|
7173
|
+
const fieldType = defaultTypes.get(name) ?? nullType2();
|
|
7174
|
+
fields.push(field2(name, fieldType, true, metadata.size > 0 ? metadata : undefined));
|
|
7175
|
+
}
|
|
7176
|
+
return schema2(fields);
|
|
7177
|
+
}
|
|
7178
|
+
|
|
7179
|
+
// src/functions/scalar.ts
|
|
6988
7180
|
function defineScalarFunction(config) {
|
|
6989
7181
|
const repr = config.repr ?? "rich";
|
|
6990
7182
|
const specs = [];
|
|
@@ -6998,7 +7190,8 @@ function defineScalarFunction(config) {
|
|
|
6998
7190
|
isAnyType: isAny,
|
|
6999
7191
|
isConst: p.const,
|
|
7000
7192
|
isVarargs: p.varargs,
|
|
7001
|
-
doc: p.doc
|
|
7193
|
+
doc: p.doc,
|
|
7194
|
+
...constraintSpecFields(p)
|
|
7002
7195
|
});
|
|
7003
7196
|
}
|
|
7004
7197
|
} else {
|
|
@@ -7027,6 +7220,14 @@ function defineScalarFunction(config) {
|
|
|
7027
7220
|
}
|
|
7028
7221
|
}
|
|
7029
7222
|
}
|
|
7223
|
+
const constConstraints = new Map;
|
|
7224
|
+
if (config.parameters) {
|
|
7225
|
+
for (const p of config.parameters) {
|
|
7226
|
+
if (p.const && (p.choices !== undefined || p.ge !== undefined || p.le !== undefined || p.gt !== undefined || p.lt !== undefined || p.pattern !== undefined)) {
|
|
7227
|
+
constConstraints.set(p.name, p);
|
|
7228
|
+
}
|
|
7229
|
+
}
|
|
7230
|
+
}
|
|
7030
7231
|
const meta = {
|
|
7031
7232
|
name: config.name,
|
|
7032
7233
|
description: config.description,
|
|
@@ -7053,7 +7254,11 @@ function defineScalarFunction(config) {
|
|
|
7053
7254
|
let constIdx = 0;
|
|
7054
7255
|
for (const spec of specs) {
|
|
7055
7256
|
if (spec.isConst) {
|
|
7056
|
-
|
|
7257
|
+
const value = request.arguments.get(constIdx, undefined);
|
|
7258
|
+
constArgs[spec.name] = value;
|
|
7259
|
+
const constraints = constConstraints.get(spec.name);
|
|
7260
|
+
if (constraints)
|
|
7261
|
+
validateConstConstraints(spec.name, constraints, value);
|
|
7057
7262
|
constIdx++;
|
|
7058
7263
|
}
|
|
7059
7264
|
}
|
|
@@ -7567,72 +7772,6 @@ function defineTableInOutFunction(config) {
|
|
|
7567
7772
|
// src/catalog/read-only.ts
|
|
7568
7773
|
init_arrow();
|
|
7569
7774
|
|
|
7570
|
-
// src/arguments/argument-spec.ts
|
|
7571
|
-
init_arrow();
|
|
7572
|
-
function argumentSpecSortKey(spec) {
|
|
7573
|
-
if (typeof spec.position === "number") {
|
|
7574
|
-
return [0, spec.position];
|
|
7575
|
-
}
|
|
7576
|
-
return [1, spec.position];
|
|
7577
|
-
}
|
|
7578
|
-
function argumentSpecsToSchema(specs) {
|
|
7579
|
-
const sorted = [...specs].sort((a, b) => {
|
|
7580
|
-
const ka = argumentSpecSortKey(a);
|
|
7581
|
-
const kb = argumentSpecSortKey(b);
|
|
7582
|
-
if (ka[0] !== kb[0])
|
|
7583
|
-
return ka[0] - kb[0];
|
|
7584
|
-
if (typeof ka[1] === "number" && typeof kb[1] === "number") {
|
|
7585
|
-
return ka[1] - kb[1];
|
|
7586
|
-
}
|
|
7587
|
-
return String(ka[1]).localeCompare(String(kb[1]));
|
|
7588
|
-
});
|
|
7589
|
-
const fields = [];
|
|
7590
|
-
for (const spec of sorted) {
|
|
7591
|
-
const metadata = new Map;
|
|
7592
|
-
if (typeof spec.position === "string") {
|
|
7593
|
-
metadata.set(VGI_ARG_KEY, VGI_ARG_NAMED);
|
|
7594
|
-
}
|
|
7595
|
-
if (spec.isTableInput) {
|
|
7596
|
-
metadata.set(VGI_TYPE_KEY, VGI_TYPE_TABLE);
|
|
7597
|
-
} else if (spec.isAnyType) {
|
|
7598
|
-
metadata.set(VGI_TYPE_KEY, VGI_TYPE_ANY);
|
|
7599
|
-
}
|
|
7600
|
-
if (spec.isVarargs) {
|
|
7601
|
-
metadata.set(VGI_VARARGS_KEY, VGI_VARARGS_TRUE);
|
|
7602
|
-
}
|
|
7603
|
-
if (spec.isConst) {
|
|
7604
|
-
metadata.set(VGI_CONST_KEY, VGI_CONST_TRUE);
|
|
7605
|
-
}
|
|
7606
|
-
if (spec.doc) {
|
|
7607
|
-
metadata.set(VGI_DOC_KEY, spec.doc);
|
|
7608
|
-
}
|
|
7609
|
-
const field3 = field2(spec.name, spec.arrowType, true, metadata.size > 0 ? metadata : undefined);
|
|
7610
|
-
fields.push(field3);
|
|
7611
|
-
}
|
|
7612
|
-
return schema2(fields);
|
|
7613
|
-
}
|
|
7614
|
-
function macroArgumentsSchema(parameters, parameterDefaultValues, parameterDocs) {
|
|
7615
|
-
const docs = parameterDocs ?? {};
|
|
7616
|
-
const defaultTypes = new Map;
|
|
7617
|
-
if (parameterDefaultValues && parameterDefaultValues.length > 0) {
|
|
7618
|
-
const batch = deserializeBatch(parameterDefaultValues);
|
|
7619
|
-
for (const f of batch.schema.fields) {
|
|
7620
|
-
defaultTypes.set(f.name, f.type);
|
|
7621
|
-
}
|
|
7622
|
-
}
|
|
7623
|
-
const fields = [];
|
|
7624
|
-
for (const name of parameters) {
|
|
7625
|
-
const metadata = new Map;
|
|
7626
|
-
const doc = docs[name];
|
|
7627
|
-
if (doc) {
|
|
7628
|
-
metadata.set(VGI_DOC_KEY, doc);
|
|
7629
|
-
}
|
|
7630
|
-
const fieldType = defaultTypes.get(name) ?? nullType2();
|
|
7631
|
-
fields.push(field2(name, fieldType, true, metadata.size > 0 ? metadata : undefined));
|
|
7632
|
-
}
|
|
7633
|
-
return schema2(fields);
|
|
7634
|
-
}
|
|
7635
|
-
|
|
7636
7775
|
// src/metadata/resolve.ts
|
|
7637
7776
|
init_arrow();
|
|
7638
7777
|
function arrowTypeToName(type) {
|
|
@@ -8792,4 +8931,4 @@ export {
|
|
|
8792
8931
|
Arguments
|
|
8793
8932
|
};
|
|
8794
8933
|
|
|
8795
|
-
//# debugId=
|
|
8934
|
+
//# debugId=1755038A7EDE8C3064756E2164756E21
|