@query-farm/vgi 0.48.2 → 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 (43) hide show
  1. package/README.md +27 -0
  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/client-entry.js +9 -25
  5. package/dist/client-entry.js.map +3 -3
  6. package/dist/functions/aggregate.d.ts +2 -1
  7. package/dist/functions/copy-from.d.ts +2 -1
  8. package/dist/functions/copy-to.d.ts +2 -1
  9. package/dist/functions/scalar.d.ts +2 -1
  10. package/dist/functions/table-buffering.d.ts +2 -1
  11. package/dist/functions/table-in-out.d.ts +3 -2
  12. package/dist/functions/table.d.ts +2 -1
  13. package/dist/functions/types.d.ts +2 -1
  14. package/dist/index.core.d.ts +2 -1
  15. package/dist/index.js +131 -39
  16. package/dist/index.js.map +18 -17
  17. package/dist/metadata/types.d.ts +3 -1
  18. package/dist/secrets/helpers.d.ts +31 -3
  19. package/dist/secrets/requirements.d.ts +38 -0
  20. package/dist/serve-entry.js +9 -25
  21. package/dist/serve-entry.js.map +5 -5
  22. package/dist/worker-cf-entry.d.ts +2 -2
  23. package/dist/worker-cf-entry.js +161 -32
  24. package/dist/worker-cf-entry.js.map +15 -13
  25. package/package.json +1 -1
  26. package/src/arrow/impl-arrowjs/iterate.ts +17 -40
  27. package/src/arrow/impl-flechette/iterate.ts +5 -24
  28. package/src/catalog/read-only.ts +6 -3
  29. package/src/functions/aggregate.ts +3 -2
  30. package/src/functions/copy-from.ts +3 -2
  31. package/src/functions/copy-to.ts +2 -1
  32. package/src/functions/scalar.ts +3 -2
  33. package/src/functions/table-buffering.ts +3 -2
  34. package/src/functions/table-in-out.ts +5 -4
  35. package/src/functions/table.ts +3 -2
  36. package/src/functions/types.ts +2 -1
  37. package/src/index.core.ts +10 -0
  38. package/src/metadata/resolve.ts +2 -1
  39. package/src/metadata/serialize.ts +25 -5
  40. package/src/metadata/types.ts +3 -1
  41. package/src/secrets/helpers.ts +96 -9
  42. package/src/secrets/requirements.ts +121 -0
  43. package/src/worker-cf-entry.ts +14 -0
@@ -3,9 +3,9 @@ export type { VgiFetchOptions } from "./http/fetch.js";
3
3
  export type { HostingOptions } from "./rpc-server.js";
4
4
  export { AuthUnavailableError, GrantKeys, GrantRefusedError, IdentityUnavailableError, StatusError, } from "@query-farm/vgi-rpc";
5
5
  export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
6
- export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
6
+ export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, normalizeRequiredSecrets, } from "./index.core.js";
7
7
  export * from "./catalog/public-codecs.js";
8
- export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, } from "./index.core.js";
8
+ export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, SecretFields, SecretsDict, RequiredSecret, SecretRequirement, SecretRequirementSpec, } from "./index.core.js";
9
9
  export type { ProtocolConfig } from "./protocol/dispatch.js";
10
10
  export type { LandingInfo } from "./http/landing.js";
11
11
  export { createLandingRoutes } from "./http/landing.js";
@@ -1554,30 +1554,14 @@ function batchToSecretDict(batch) {
1554
1554
  const result = {};
1555
1555
  for (const field of a.schema.fields) {
1556
1556
  const col = a.getChild(field.name);
1557
- if (col) {
1558
- const type = field.type;
1559
- const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1560
- let key = field.name;
1561
- let scope;
1562
- if (field.name.startsWith("secret_")) {
1563
- const secretType = field.metadata?.get?.("secret_type");
1564
- if (secretType) {
1565
- key = secretType;
1566
- scope = field.metadata?.get?.("scope") ?? undefined;
1567
- }
1568
- }
1569
- if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1570
- const dict = { ...val };
1571
- if (key in result) {
1572
- throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
1573
- }
1574
- result[key] = dict;
1575
- if (scope) {
1576
- result[`${key}:${scope}`] = dict;
1577
- }
1578
- } else if (val === null || val === undefined) {} else {
1579
- result[key] = {};
1580
- }
1557
+ if (!col)
1558
+ continue;
1559
+ const type = field.type;
1560
+ const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1561
+ if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1562
+ result[field.name] = { ...val };
1563
+ } else if (val !== null && val !== undefined) {
1564
+ result[field.name] = {};
1581
1565
  }
1582
1566
  }
1583
1567
  return result;
@@ -10558,6 +10542,65 @@ function functionHandlers(config) {
10558
10542
  // src/protocol/handlers/aggregate.ts
10559
10543
  init_arrow();
10560
10544
 
10545
+ // src/secrets/requirements.ts
10546
+ var KNOWN_KEYS = new Set(["secretType", "secret_type", "scope", "secretName", "secret_name"]);
10547
+ function optionalString(value, what, where) {
10548
+ if (value === undefined || value === null)
10549
+ return null;
10550
+ if (typeof value !== "string") {
10551
+ throw new TypeError(`${where}: ${what} must be a string, got ${typeof value}`);
10552
+ }
10553
+ return value === "" ? null : value;
10554
+ }
10555
+ function normalizeRequiredSecrets(value, functionName = "<function>") {
10556
+ if (value === undefined || value === null)
10557
+ return [];
10558
+ const where = `requiredSecrets of '${functionName}'`;
10559
+ if (!Array.isArray(value)) {
10560
+ throw new TypeError(`${where} must be an array of secret types or { secretType, scope?, secretName? } objects, got ${typeof value}`);
10561
+ }
10562
+ const out = [];
10563
+ const seen = new Set;
10564
+ value.forEach((entry, i) => {
10565
+ const at = `${where}[${i}]`;
10566
+ let req;
10567
+ if (typeof entry === "string") {
10568
+ if (entry === "")
10569
+ throw new TypeError(`${at}: secret type must not be empty`);
10570
+ req = { secretType: entry, scope: null, secretName: null };
10571
+ } else if (entry !== null && typeof entry === "object" && !Array.isArray(entry)) {
10572
+ const obj = entry;
10573
+ const unknown = Object.keys(obj).filter((k) => !KNOWN_KEYS.has(k));
10574
+ if (unknown.length > 0) {
10575
+ throw new TypeError(`${at}: unknown key(s) ${unknown.map((k) => `'${k}'`).join(", ")}; ` + `expected secretType, scope, secretName`);
10576
+ }
10577
+ if (obj.secretType !== undefined && obj.secret_type !== undefined && obj.secretType !== obj.secret_type) {
10578
+ throw new TypeError(`${at}: secretType and secret_type disagree`);
10579
+ }
10580
+ if (obj.secretName !== undefined && obj.secret_name !== undefined && obj.secretName !== obj.secret_name) {
10581
+ throw new TypeError(`${at}: secretName and secret_name disagree`);
10582
+ }
10583
+ const secretType = obj.secretType ?? obj.secret_type;
10584
+ if (typeof secretType !== "string" || secretType === "") {
10585
+ throw new TypeError(`${at}: secretType must be a non-empty string`);
10586
+ }
10587
+ req = {
10588
+ secretType,
10589
+ scope: optionalString(obj.scope, "scope", at),
10590
+ secretName: optionalString(obj.secretName ?? obj.secret_name, "secretName", at)
10591
+ };
10592
+ } else {
10593
+ throw new TypeError(`${at}: expected a secret type string or a { secretType, scope?, secretName? } object, got ` + (entry === null ? "null" : Array.isArray(entry) ? "array" : typeof entry));
10594
+ }
10595
+ const key = JSON.stringify([req.secretType, req.scope, req.secretName]);
10596
+ if (seen.has(key))
10597
+ return;
10598
+ seen.add(key);
10599
+ out.push(req);
10600
+ });
10601
+ return out;
10602
+ }
10603
+
10561
10604
  // src/functions/aggregate.ts
10562
10605
  init_arrow();
10563
10606
 
@@ -10886,7 +10929,7 @@ function defineAggregate(config) {
10886
10929
  tags: config.tags,
10887
10930
  parameterDefaultValues: config.parameterDefaultValues,
10888
10931
  nullHandling: config.nullHandling,
10889
- requiredSecrets: config.requiredSecrets
10932
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
10890
10933
  };
10891
10934
  const isAnyType = isNull(config.outputType);
10892
10935
  const defaultOutputSchema = isAnyType ? schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]) : schema2([field2("result", config.outputType, true)]);
@@ -14367,7 +14410,7 @@ function defineScalarFunction(config) {
14367
14410
  parameterDefaultValues: config.parameterDefaultValues,
14368
14411
  maxWorkers: config.maxWorkers,
14369
14412
  requiredSettings: config.requiredSettings,
14370
- requiredSecrets: config.requiredSecrets
14413
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name)
14371
14414
  };
14372
14415
  const defaultOutputSchema = config.returns ? schema2([field2("result", config.returns, true)]) : schema2([field2("result", nullType2(), true, new Map([["vgi:any", "true"]]))]);
14373
14416
  return {
@@ -14555,7 +14598,7 @@ function defineTableFunction(config) {
14555
14598
  parameterDefaultValues: config.parameterDefaultValues,
14556
14599
  maxWorkers: config.maxWorkers,
14557
14600
  requiredSettings: config.requiredSettings,
14558
- requiredSecrets: config.requiredSecrets,
14601
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
14559
14602
  preservesOrder: config.preservesOrder,
14560
14603
  nullHandling: config.nullHandling,
14561
14604
  orderDependent: config.orderDependent,
@@ -14832,7 +14875,7 @@ function defineTableInOutFunction(config) {
14832
14875
  parameterDefaultValues: config.parameterDefaultValues,
14833
14876
  maxWorkers: config.maxWorkers,
14834
14877
  requiredSettings: config.requiredSettings,
14835
- requiredSecrets: config.requiredSecrets,
14878
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
14836
14879
  hasFinalize: !!config.finalize
14837
14880
  };
14838
14881
  function extractArgs(request) {
@@ -15142,7 +15185,7 @@ function defineRowTransformFunction(config) {
15142
15185
  parameterDefaultValues: config.parameterDefaultValues,
15143
15186
  maxWorkers: config.maxWorkers,
15144
15187
  requiredSettings: config.requiredSettings,
15145
- requiredSecrets: config.requiredSecrets,
15188
+ requiredSecrets: normalizeRequiredSecrets(config.requiredSecrets, config.name),
15146
15189
  hasFinalize: false,
15147
15190
  inputFromArgs: true,
15148
15191
  inputRowsPerCall
@@ -15379,7 +15422,7 @@ function resolveMetadata(func) {
15379
15422
  nullHandling: meta.nullHandling ?? "DEFAULT" /* DEFAULT */,
15380
15423
  argumentMonotonicity,
15381
15424
  requiredSettings: meta.requiredSettings ?? [],
15382
- requiredSecrets: meta.requiredSecrets ?? [],
15425
+ requiredSecrets: normalizeRequiredSecrets(meta.requiredSecrets, meta.name),
15383
15426
  projectionPushdown: meta.projectionPushdown ?? false,
15384
15427
  filterPushdown: meta.filterPushdown ?? false,
15385
15428
  samplingPushdown: meta.samplingPushdown ?? false,
@@ -15817,7 +15860,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
15817
15860
  }
15818
15861
  }
15819
15862
  const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
15820
- const requiredSecrets = (meta.requiredSecrets ?? []).map((secretType) => ({ secret_type: secretType, scope: null, secret_name: null }));
15863
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
15864
+ secret_type: s.secretType,
15865
+ scope: s.scope,
15866
+ secret_name: s.secretName
15867
+ }));
15821
15868
  const derivedTags = {};
15822
15869
  const tags = { ...derivedTags, ...meta.tags ?? {} };
15823
15870
  return {
@@ -16726,6 +16773,80 @@ class FunctionRegistry {
16726
16773
  return result;
16727
16774
  }
16728
16775
  }
16776
+ // src/secrets/helpers.ts
16777
+ function scalarStr(v) {
16778
+ if (v === null || v === undefined)
16779
+ return "";
16780
+ return typeof v === "string" ? v : String(v);
16781
+ }
16782
+ function secretType(secrets, name) {
16783
+ const f = secrets?.[name];
16784
+ return f && "type" in f ? scalarStr(f.type) : undefined;
16785
+ }
16786
+ function untyped(fields) {
16787
+ return !!fields && scalarStr(fields.type) === "";
16788
+ }
16789
+ function keyedByType(secrets, type) {
16790
+ const f = secrets?.[type];
16791
+ return untyped(f) ? f : undefined;
16792
+ }
16793
+ function secretsOfType(secrets, type) {
16794
+ const typed = Object.values(secrets ?? {}).filter((f) => scalarStr(f.type) === type);
16795
+ if (typed.length > 0)
16796
+ return typed;
16797
+ const legacy = keyedByType(secrets, type);
16798
+ return legacy ? [legacy] : [];
16799
+ }
16800
+ function secretOfType(secrets, type) {
16801
+ const all = secretsOfType(secrets, type);
16802
+ return all.find((f) => scalarStr(f.scope) === "") ?? all[0];
16803
+ }
16804
+ function requireSecretOfType(secrets, type) {
16805
+ const found = secretOfType(secrets, type);
16806
+ if (!found) {
16807
+ throw new Error(`required secret of type '${type}' was not found; create one with CREATE SECRET (TYPE ${type}, ...)`);
16808
+ }
16809
+ return found;
16810
+ }
16811
+ function secretByName(secrets, name, type) {
16812
+ if (!secrets || !Object.prototype.hasOwnProperty.call(secrets, name))
16813
+ return;
16814
+ const f = secrets[name];
16815
+ if (!f)
16816
+ return;
16817
+ if (type === undefined || untyped(f) || scalarStr(f.type) === type)
16818
+ return f;
16819
+ return;
16820
+ }
16821
+ function secretForScope(secrets, path) {
16822
+ return selectForScope(secrets, path, undefined);
16823
+ }
16824
+ function secretForScopeOfType(secrets, path, type) {
16825
+ return selectForScope(secrets, path, type) ?? keyedByType(secrets, type);
16826
+ }
16827
+ function selectForScope(secrets, path, type) {
16828
+ let best;
16829
+ let bestLen = -1;
16830
+ let fallback;
16831
+ for (const fields of Object.values(secrets ?? {})) {
16832
+ if (type !== undefined && scalarStr(fields.type) !== type)
16833
+ continue;
16834
+ const scope = scalarStr(fields.scope);
16835
+ if (!scope) {
16836
+ if (!fallback)
16837
+ fallback = fields;
16838
+ continue;
16839
+ }
16840
+ for (const prefix of scope.split(`
16841
+ `)) {
16842
+ if (prefix && path.startsWith(prefix) && prefix.length > bestLen) {
16843
+ bestLen = prefix.length;
16844
+ best = fields;
16845
+ }
16846
+ }
16847
+ }
16848
+ return best ?? fallback;
16849
+ }
16729
16850
  // src/index.core.ts
16730
16851
  import { str, bytes, int as int3, int32 as int323, float, float32 as float323, bool as bool3, toSchema, OutputCollector, AuthContext as AuthContext2 } from "@query-farm/vgi-rpc";
16731
16852
  import { subprocessConnect, httpConnect, tcpConnect } from "@query-farm/vgi-rpc";
@@ -16875,13 +16996,21 @@ export {
16875
16996
  list2 as list,
16876
16997
  map2 as map,
16877
16998
  moreOutputMetadata,
16999
+ normalizeRequiredSecrets,
16878
17000
  nullType2 as nullType,
16879
17001
  parentRowsMetadata,
16880
17002
  projectBatch,
16881
17003
  projectSchema,
16882
17004
  readConstraintRecord,
17005
+ requireSecretOfType,
16883
17006
  safeNumber,
16884
17007
  schema2 as schema,
17008
+ secretByName,
17009
+ secretForScope,
17010
+ secretForScopeOfType,
17011
+ secretOfType,
17012
+ secretType,
17013
+ secretsOfType,
16885
17014
  selectCatalogCapabilities,
16886
17015
  selectReadProfiles,
16887
17016
  serializeAttachOptionSpec,
@@ -16914,4 +17043,4 @@ export {
16914
17043
  validateTableConstraints
16915
17044
  };
16916
17045
 
16917
- //# debugId=F8503787BE8D309164756E2164756E21
17046
+ //# debugId=701969C8B78DAA6864756E2164756E21