@query-farm/vgi 0.48.1 → 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 (49) hide show
  1. package/README.md +51 -1
  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/catalog/descriptors.d.ts +14 -0
  5. package/dist/catalog/read-only.d.ts +4 -5
  6. package/dist/client-entry.js +9 -25
  7. package/dist/client-entry.js.map +3 -3
  8. package/dist/functions/aggregate.d.ts +2 -1
  9. package/dist/functions/copy-from.d.ts +2 -1
  10. package/dist/functions/copy-to.d.ts +2 -1
  11. package/dist/functions/registry.d.ts +1 -0
  12. package/dist/functions/scalar.d.ts +18 -6
  13. package/dist/functions/table-buffering.d.ts +2 -1
  14. package/dist/functions/table-in-out.d.ts +3 -2
  15. package/dist/functions/table.d.ts +2 -1
  16. package/dist/functions/types.d.ts +8 -3
  17. package/dist/index.core.d.ts +3 -2
  18. package/dist/index.js +177 -61
  19. package/dist/index.js.map +21 -20
  20. package/dist/metadata/types.d.ts +3 -1
  21. package/dist/secrets/helpers.d.ts +31 -3
  22. package/dist/secrets/requirements.d.ts +38 -0
  23. package/dist/serve-entry.js +14 -28
  24. package/dist/serve-entry.js.map +6 -6
  25. package/dist/worker-cf-entry.d.ts +2 -2
  26. package/dist/worker-cf-entry.js +205 -53
  27. package/dist/worker-cf-entry.js.map +18 -16
  28. package/package.json +1 -1
  29. package/src/arrow/impl-arrowjs/iterate.ts +17 -40
  30. package/src/arrow/impl-flechette/iterate.ts +5 -24
  31. package/src/catalog/descriptors.ts +14 -0
  32. package/src/catalog/read-only.ts +24 -16
  33. package/src/functions/aggregate.ts +3 -2
  34. package/src/functions/copy-from.ts +3 -2
  35. package/src/functions/copy-to.ts +2 -1
  36. package/src/functions/registry.ts +6 -3
  37. package/src/functions/scalar.ts +33 -10
  38. package/src/functions/table-buffering.ts +6 -2
  39. package/src/functions/table-in-out.ts +34 -13
  40. package/src/functions/table.ts +12 -8
  41. package/src/functions/types.ts +15 -4
  42. package/src/index.core.ts +11 -1
  43. package/src/metadata/resolve.ts +2 -1
  44. package/src/metadata/serialize.ts +25 -5
  45. package/src/metadata/types.ts +3 -1
  46. package/src/protocol/handlers/function.ts +16 -3
  47. package/src/secrets/helpers.ts +96 -9
  48. package/src/secrets/requirements.ts +121 -0
  49. package/src/worker-cf-entry.ts +14 -0
@@ -1,3 +1,4 @@
1
+ import type { SecretRequirement } from "../secrets/requirements.js";
1
2
  import { FunctionStability, NullHandling, ArgumentMonotonicity, OrderPreservation, OrderDependence, DistinctDependence } from "../types.js";
2
3
  export declare enum CatalogFunctionType {
3
4
  SCALAR = "SCALAR",
@@ -45,7 +46,8 @@ export interface ResolvedMetadata {
45
46
  nullHandling: NullHandling;
46
47
  argumentMonotonicity: ArgumentMonotonicity[] | null;
47
48
  requiredSettings: string[];
48
- requiredSecrets: string[];
49
+ /** Validated static secret requirements (FunctionInfo `required_secrets`). */
50
+ requiredSecrets: SecretRequirement[];
49
51
  projectionPushdown: boolean;
50
52
  filterPushdown: boolean;
51
53
  samplingPushdown: boolean;
@@ -2,14 +2,42 @@ export type SecretFields = Record<string, any>;
2
2
  export type SecretsDict = Record<string, SecretFields>;
3
3
  /** The DuckDB secret type of the named secret (its serialized `type` field). */
4
4
  export declare function secretType(secrets: SecretsDict, name: string): string | undefined;
5
- /** Every resolved secret whose serialized `type` field matches `type`. */
5
+ /**
6
+ * Every resolved secret whose serialized `type` field matches `type`, in
7
+ * delivery order. Falls back to an untyped secret keyed by `type` only when no
8
+ * secret carries the type.
9
+ */
6
10
  export declare function secretsOfType(secrets: SecretsDict, type: string): SecretFields[];
11
+ /**
12
+ * The secret a by-TYPE request refers to: a secret of `type` with an empty
13
+ * scope, else the first secret of `type`, else undefined. This is the rule the
14
+ * client applies to a `requiredSecrets: ["<type>"]` declaration, so it picks the
15
+ * secret that declaration resolved even when other same-type secrets (from
16
+ * scoped declarations) were delivered alongside it.
17
+ */
18
+ export declare function secretOfType(secrets: SecretsDict, type: string): SecretFields | undefined;
19
+ /**
20
+ * Like {@link secretOfType}, but throws when no secret of `type` was resolved.
21
+ * Call it from `onBind` to fail the bind of a function that cannot run without
22
+ * credentials. The message names the type and never includes a secret value.
23
+ */
24
+ export declare function requireSecretOfType(secrets: SecretsDict, type: string): SecretFields;
25
+ /**
26
+ * The secret with DuckDB name `name` (its key in the resolved batch). With
27
+ * `type`, only if that secret's `type` field is `type` (or absent, for a bare
28
+ * key/value struct) — the rule the client applies to a by-name request.
29
+ */
30
+ export declare function secretByName(secrets: SecretsDict, name: string, type?: string): SecretFields | undefined;
7
31
  /**
8
32
  * The secret whose `scope` is the longest prefix of `path`. The connector
9
33
  * serializes each secret's scope as a newline-joined list of prefixes; a secret
10
34
  * with no (or empty) scope matches as a last-resort fallback. Returns undefined
11
- * only when there are no candidate secrets.
35
+ * when no scope is a prefix of `path` and no unscoped secret was delivered.
12
36
  */
13
37
  export declare function secretForScope(secrets: SecretsDict, path: string): SecretFields | undefined;
14
- /** Like {@link secretForScope} but only over secrets of `type`. */
38
+ /**
39
+ * Like {@link secretForScope} but only over secrets of `type`: the one whose
40
+ * scope is the longest prefix of `path`, else one of `type` with an empty scope,
41
+ * else undefined.
42
+ */
15
43
  export declare function secretForScopeOfType(secrets: SecretsDict, path: string, type: string): SecretFields | undefined;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A secret requirement in object form. `scope` asks the client for the secret of
3
+ * `secretType` whose scope is the longest prefix of it; `secretName` asks for one
4
+ * secret by its DuckDB name (and takes precedence over `scope`, as it does on
5
+ * the client). Neither means "a secret of this type with an empty scope".
6
+ *
7
+ * The snake_case spelling of the wire entry (`secret_type` / `secret_name`) is
8
+ * accepted too.
9
+ */
10
+ export interface SecretRequirementSpec {
11
+ secretType?: string;
12
+ scope?: string | null;
13
+ secretName?: string | null;
14
+ secret_type?: string;
15
+ secret_name?: string | null;
16
+ }
17
+ /**
18
+ * One `requiredSecrets` entry: a bare secret type (the simplest form — "a secret
19
+ * of this type"), or a {@link SecretRequirementSpec} with a scope or a name.
20
+ */
21
+ export type RequiredSecret = string | SecretRequirementSpec;
22
+ /** A validated, normalized requirement — the shape sent on the wire. */
23
+ export interface SecretRequirement {
24
+ secretType: string;
25
+ scope: string | null;
26
+ secretName: string | null;
27
+ }
28
+ /**
29
+ * Validate and normalize a `requiredSecrets` declaration. Throws on anything
30
+ * that is not a list of bare type strings / requirement objects, on an empty
31
+ * type, on unknown object keys (a typo such as `{ type: "s3" }` would otherwise
32
+ * declare nothing), and on conflicting camelCase/snake_case spellings.
33
+ * Duplicate requirements (same type, scope and name) are collapsed.
34
+ *
35
+ * @param value The declared `requiredSecrets` (undefined → no requirements).
36
+ * @param functionName Used in error messages.
37
+ */
38
+ export declare function normalizeRequiredSecrets(value: unknown, functionName?: string): SecretRequirement[];
@@ -2133,30 +2133,14 @@ function batchToSecretDict(batch) {
2133
2133
  const result = {};
2134
2134
  for (const field of a.schema.fields) {
2135
2135
  const col = a.getChild(field.name);
2136
- if (col) {
2137
- const type = field.type;
2138
- const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
2139
- let key = field.name;
2140
- let scope;
2141
- if (field.name.startsWith("secret_")) {
2142
- const secretType = field.metadata?.get?.("secret_type");
2143
- if (secretType) {
2144
- key = secretType;
2145
- scope = field.metadata?.get?.("scope") ?? undefined;
2146
- }
2147
- }
2148
- if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
2149
- const dict = { ...val };
2150
- if (key in result) {
2151
- throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
2152
- }
2153
- result[key] = dict;
2154
- if (scope) {
2155
- result[`${key}:${scope}`] = dict;
2156
- }
2157
- } else if (val === null || val === undefined) {} else {
2158
- result[key] = {};
2159
- }
2136
+ if (!col)
2137
+ continue;
2138
+ const type = field.type;
2139
+ const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
2140
+ if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
2141
+ result[field.name] = { ...val };
2142
+ } else if (val !== null && val !== undefined) {
2143
+ result[field.name] = {};
2160
2144
  }
2161
2145
  }
2162
2146
  return result;
@@ -8705,13 +8689,14 @@ function functionHandlers(config) {
8705
8689
  } else {
8706
8690
  const carried = parseCarriedInitRequest(state.initRequestPacked);
8707
8691
  const request = carried.request;
8692
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
8708
8693
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
8709
8694
  auth: currentRequestAuth(),
8710
8695
  signingKey,
8711
8696
  catalogInterface,
8712
8697
  checkAnchor: false
8713
8698
  });
8714
- const func = registry.get(state.functionName, await strippedContext(request.bind_call));
8699
+ const func = registry.get(state.functionName, overloadContext(request.bind_call, catalogInterface));
8715
8700
  const executionId = state.executionId;
8716
8701
  const opaqueData = state.opaqueData ?? null;
8717
8702
  const initResponse = {
@@ -8720,10 +8705,11 @@ function functionHandlers(config) {
8720
8705
  opaque_data: opaqueData
8721
8706
  };
8722
8707
  handlers = func.createStreamHandlers(request, initResponse, state.filterHistory ?? null);
8708
+ const restored = state.userState != null ? { state: state.userState } : undefined;
8723
8709
  if (handlers.producerInit) {
8724
- handlerState = handlers.producerInit();
8710
+ handlerState = handlers.producerInit(restored);
8725
8711
  } else if (handlers.exchangeInit) {
8726
- handlerState = handlers.exchangeInit();
8712
+ handlerState = handlers.exchangeInit(restored);
8727
8713
  }
8728
8714
  if (state.userState != null && handlerState?.state !== undefined) {
8729
8715
  handlerState.state = state.userState;
@@ -11923,4 +11909,4 @@ export {
11923
11909
  serveVgiWorker
11924
11910
  };
11925
11911
 
11926
- //# debugId=7B9431FBBB6E4B0564756E2164756E21
11912
+ //# debugId=0D0A3CC5D765A2FD64756E2164756E21