@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.
@@ -4973,6 +4973,187 @@ init_arrow();
4973
4973
 
4974
4974
  // src/functions/aggregate.ts
4975
4975
  init_arrow();
4976
+
4977
+ // src/arguments/argument-spec.ts
4978
+ init_arrow();
4979
+ function safeJson(value) {
4980
+ try {
4981
+ const encoded = JSON.stringify(value);
4982
+ if (encoded === undefined) {
4983
+ return JSON.stringify(String(value));
4984
+ }
4985
+ return encoded;
4986
+ } catch {
4987
+ return JSON.stringify(String(value));
4988
+ }
4989
+ }
4990
+ function formatRange(ge, le, gt, lt) {
4991
+ if (ge === undefined && le === undefined && gt === undefined && lt === undefined) {
4992
+ return;
4993
+ }
4994
+ let low;
4995
+ if (gt !== undefined) {
4996
+ low = `(${gt}`;
4997
+ } else if (ge !== undefined) {
4998
+ low = `[${ge}`;
4999
+ } else {
5000
+ low = "(-inf";
5001
+ }
5002
+ let high;
5003
+ if (lt !== undefined) {
5004
+ high = `${lt})`;
5005
+ } else if (le !== undefined) {
5006
+ high = `${le}]`;
5007
+ } else {
5008
+ high = "+inf)";
5009
+ }
5010
+ return `${low}, ${high}`;
5011
+ }
5012
+ function constraintSpecFields(constraints) {
5013
+ const fields = {};
5014
+ if (constraints === undefined)
5015
+ return fields;
5016
+ if ("default" in constraints && constraints.default !== undefined) {
5017
+ fields.defaultJson = safeJson(constraints.default);
5018
+ }
5019
+ if (constraints.choices !== undefined) {
5020
+ fields.choicesJson = safeJson([...constraints.choices]);
5021
+ }
5022
+ const range = formatRange(constraints.ge, constraints.le, constraints.gt, constraints.lt);
5023
+ if (range !== undefined) {
5024
+ fields.rangeNotation = range;
5025
+ }
5026
+ if (constraints.pattern !== undefined) {
5027
+ fields.pattern = constraints.pattern;
5028
+ }
5029
+ return fields;
5030
+ }
5031
+ function toNumber(value) {
5032
+ if (typeof value === "number")
5033
+ return value;
5034
+ if (typeof value === "bigint")
5035
+ return Number(value);
5036
+ return;
5037
+ }
5038
+ function choiceEquals(choice, value) {
5039
+ const cn = toNumber(choice);
5040
+ const vn = toNumber(value);
5041
+ if (cn !== undefined && vn !== undefined)
5042
+ return cn === vn;
5043
+ return choice === value;
5044
+ }
5045
+ function validateConstConstraints(name, constraints, value) {
5046
+ if (value === null || value === undefined)
5047
+ return;
5048
+ const num = toNumber(value);
5049
+ if (num !== undefined) {
5050
+ if (constraints.ge !== undefined && num < constraints.ge) {
5051
+ throw new ArgumentValidationError(`argument '${name}' must be >= ${constraints.ge}`);
5052
+ }
5053
+ if (constraints.le !== undefined && num > constraints.le) {
5054
+ throw new ArgumentValidationError(`argument '${name}' must be <= ${constraints.le}`);
5055
+ }
5056
+ if (constraints.gt !== undefined && num <= constraints.gt) {
5057
+ throw new ArgumentValidationError(`argument '${name}' must be > ${constraints.gt}`);
5058
+ }
5059
+ if (constraints.lt !== undefined && num >= constraints.lt) {
5060
+ throw new ArgumentValidationError(`argument '${name}' must be < ${constraints.lt}`);
5061
+ }
5062
+ }
5063
+ if (constraints.choices !== undefined && constraints.choices.length > 0) {
5064
+ if (!constraints.choices.some((c) => choiceEquals(c, value))) {
5065
+ throw new ArgumentValidationError(`argument '${name}' must be one of ${JSON.stringify([...constraints.choices])}`);
5066
+ }
5067
+ }
5068
+ if (constraints.pattern !== undefined && typeof value === "string") {
5069
+ let re;
5070
+ try {
5071
+ re = new RegExp(constraints.pattern);
5072
+ } catch {
5073
+ re = undefined;
5074
+ }
5075
+ if (re !== undefined && !re.test(value)) {
5076
+ throw new ArgumentValidationError(`argument '${name}' must match pattern ${JSON.stringify(constraints.pattern)}`);
5077
+ }
5078
+ }
5079
+ }
5080
+ function argumentSpecSortKey(spec) {
5081
+ if (typeof spec.position === "number") {
5082
+ return [0, spec.position];
5083
+ }
5084
+ return [1, spec.position];
5085
+ }
5086
+ function argumentSpecsToSchema(specs) {
5087
+ const sorted = [...specs].sort((a, b) => {
5088
+ const ka = argumentSpecSortKey(a);
5089
+ const kb = argumentSpecSortKey(b);
5090
+ if (ka[0] !== kb[0])
5091
+ return ka[0] - kb[0];
5092
+ if (typeof ka[1] === "number" && typeof kb[1] === "number") {
5093
+ return ka[1] - kb[1];
5094
+ }
5095
+ return String(ka[1]).localeCompare(String(kb[1]));
5096
+ });
5097
+ const fields = [];
5098
+ for (const spec of sorted) {
5099
+ const metadata = new Map;
5100
+ if (typeof spec.position === "string") {
5101
+ metadata.set(VGI_ARG_KEY, VGI_ARG_NAMED);
5102
+ }
5103
+ if (spec.isTableInput) {
5104
+ metadata.set(VGI_TYPE_KEY, VGI_TYPE_TABLE);
5105
+ } else if (spec.isAnyType) {
5106
+ metadata.set(VGI_TYPE_KEY, VGI_TYPE_ANY);
5107
+ }
5108
+ if (spec.isVarargs) {
5109
+ metadata.set(VGI_VARARGS_KEY, VGI_VARARGS_TRUE);
5110
+ }
5111
+ if (spec.isConst) {
5112
+ metadata.set(VGI_CONST_KEY, VGI_CONST_TRUE);
5113
+ }
5114
+ if (spec.doc) {
5115
+ metadata.set(VGI_DOC_KEY, spec.doc);
5116
+ }
5117
+ if (spec.defaultJson !== undefined) {
5118
+ metadata.set(VGI_DEFAULT_KEY, spec.defaultJson);
5119
+ }
5120
+ if (spec.choicesJson !== undefined) {
5121
+ metadata.set(VGI_CHOICES_KEY, spec.choicesJson);
5122
+ }
5123
+ if (spec.rangeNotation !== undefined) {
5124
+ metadata.set(VGI_RANGE_KEY, spec.rangeNotation);
5125
+ }
5126
+ if (spec.pattern !== undefined) {
5127
+ metadata.set(VGI_PATTERN_KEY, spec.pattern);
5128
+ }
5129
+ const field3 = field2(spec.name, spec.arrowType, true, metadata.size > 0 ? metadata : undefined);
5130
+ fields.push(field3);
5131
+ }
5132
+ return schema2(fields);
5133
+ }
5134
+ function macroArgumentsSchema(parameters, parameterDefaultValues, parameterDocs) {
5135
+ const docs = parameterDocs ?? {};
5136
+ const defaultTypes = new Map;
5137
+ if (parameterDefaultValues && parameterDefaultValues.length > 0) {
5138
+ const batch = deserializeBatch(parameterDefaultValues);
5139
+ for (const f of batch.schema.fields) {
5140
+ defaultTypes.set(f.name, f.type);
5141
+ }
5142
+ }
5143
+ const fields = [];
5144
+ for (const name of parameters) {
5145
+ const metadata = new Map;
5146
+ const doc = docs[name];
5147
+ if (doc) {
5148
+ metadata.set(VGI_DOC_KEY, doc);
5149
+ }
5150
+ const fieldType = defaultTypes.get(name) ?? nullType2();
5151
+ fields.push(field2(name, fieldType, true, metadata.size > 0 ? metadata : undefined));
5152
+ }
5153
+ return schema2(fields);
5154
+ }
5155
+
5156
+ // src/functions/aggregate.ts
4976
5157
  var _NODE_FS_MOD = "node:fs";
4977
5158
  var _NODE_PATH_MOD = "node:path";
4978
5159
  var _NODE_OS_MOD = "node:os";
@@ -5103,7 +5284,8 @@ function defineAggregate(config) {
5103
5284
  arrowType: isAnyType2 ? nullType2() : type,
5104
5285
  isAnyType: isAnyType2,
5105
5286
  isVarargs: varargsSet.has(name),
5106
- isConst
5287
+ isConst,
5288
+ ...constraintSpecFields(config.argConstraints?.[name])
5107
5289
  });
5108
5290
  }
5109
5291
  }
@@ -5349,8 +5531,9 @@ function extractArgMap(cfg, args) {
5349
5531
  }
5350
5532
  }
5351
5533
  for (let i = 0;i < constNames.length; i++) {
5534
+ let v;
5352
5535
  try {
5353
- let v = args.get(i);
5536
+ v = args.get(i);
5354
5537
  const field3 = args.argumentsSchema?.fields.find((f) => f.name === `positional_${i}`);
5355
5538
  if (field3 && isDecimal(field3.type)) {
5356
5539
  const scale = field3.type.scale;
@@ -5361,12 +5544,17 @@ function extractArgMap(cfg, args) {
5361
5544
  } else if (typeof v === "bigint") {
5362
5545
  v = Number(v);
5363
5546
  }
5364
- out[constNames[i]] = v;
5365
5547
  } catch {
5366
5548
  const def = cfg.argDefaults?.[constNames[i]];
5367
5549
  if (def !== undefined)
5368
5550
  out[constNames[i]] = def;
5551
+ continue;
5369
5552
  }
5553
+ const constraints = cfg.argConstraints?.[constNames[i]];
5554
+ if (constraints !== undefined) {
5555
+ validateConstConstraints(constNames[i], constraints, v);
5556
+ }
5557
+ out[constNames[i]] = v;
5370
5558
  }
5371
5559
  if (cfg.argDefaults) {
5372
5560
  for (const [name, def] of Object.entries(cfg.argDefaults)) {
@@ -6996,187 +7184,6 @@ function buildVgiProtocol(config) {
6996
7184
 
6997
7185
  // src/functions/scalar.ts
6998
7186
  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
7180
7187
  function defineScalarFunction(config) {
7181
7188
  const repr = config.repr ?? "rich";
7182
7189
  const specs = [];
@@ -7406,7 +7413,8 @@ function defineTableFunction(config) {
7406
7413
  arrowType: isAny ? nullType2() : type,
7407
7414
  isAnyType: isAny,
7408
7415
  isVarargs: varargsSet.has(name),
7409
- doc: config.argDocs?.[name]
7416
+ doc: config.argDocs?.[name],
7417
+ ...constraintSpecFields(config.argConstraints?.[name])
7410
7418
  });
7411
7419
  }
7412
7420
  }
@@ -7445,6 +7453,9 @@ function defineTableFunction(config) {
7445
7453
  }
7446
7454
  if (typeof val === "bigint")
7447
7455
  val = safeNumber(val);
7456
+ const constraints = config.argConstraints?.[spec.name];
7457
+ if (constraints)
7458
+ validateConstConstraints(spec.name, constraints, val);
7448
7459
  args[spec.name] = val;
7449
7460
  }
7450
7461
  return args;
@@ -8931,4 +8942,4 @@ export {
8931
8942
  Arguments
8932
8943
  };
8933
8944
 
8934
- //# debugId=1755038A7EDE8C3064756E2164756E21
8945
+ //# debugId=781A5FE31E548B0664756E2164756E21