@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
package/README.md CHANGED
@@ -237,6 +237,33 @@ SELECT demo.multiply(6, 7); -- 42
237
237
  SELECT * FROM demo.sequence(5); -- 0,1,2,3,4
238
238
  ```
239
239
 
240
+ ### Secrets
241
+
242
+ A function gets only the secrets it asks for. Declare them in `requiredSecrets`:
243
+ a bare type string means "a secret of this type", and an object adds a scope or a name.
244
+
245
+ ```ts
246
+ requiredSecrets: [
247
+ "brave", // a brave secret (unscoped)
248
+ { secretType: "s3", scope: "s3://my-bucket/" }, // the s3 secret for this prefix
249
+ { secretType: "http", secretName: "corp_api" }, // one secret, by its DuckDB name
250
+ ],
251
+ ```
252
+
253
+ An entry in any other shape throws when the function is defined, so a typo can't
254
+ quietly declare nothing. Resolved secrets arrive on `params.secrets`, keyed by each
255
+ secret's DuckDB **name**, not its type. An unnamed `CREATE SECRET (TYPE brave, ...)`
256
+ arrives as `__default_brave`, so `params.secrets.brave` is usually `undefined`. Use the
257
+ selectors instead:
258
+
259
+ | Selector | Picks |
260
+ |---|---|
261
+ | `secretOfType(secrets, type)` | the unscoped secret of `type`, else the first one of `type` |
262
+ | `requireSecretOfType(secrets, type)` | the same, but throws an error naming the type when there is none (call it in `onBind`) |
263
+ | `secretsOfType(secrets, type)` | every secret of `type` |
264
+ | `secretByName(secrets, name, type?)` | the secret named `name`, if its type matches |
265
+ | `secretForScopeOfType(secrets, path, type)` | the secret of `type` whose scope is the longest prefix of `path`, else an unscoped one, else none |
266
+
240
267
  ## Function types
241
268
 
242
269
  Five factories, each mapping to a DuckDB function shape with its own lifecycle:
@@ -28,9 +28,13 @@ export declare function batchToScalarDict(batch: RecordBatch | VgiBatch | null):
28
28
  */
29
29
  export declare function decodeDictValue(value: any, index?: number): any;
30
30
  /**
31
- * Extract single-row batch to a secret dict (column per secret, each value is a struct).
32
- * Handles both named secrets (column name = secret type) and scoped secrets
33
- * (column name = "secret_N" with secret_type in field metadata).
31
+ * Extract a single-row resolved-secrets batch to a dict: one entry per column,
32
+ * keyed by the column name — the secret's unique DuckDB NAME, not its type (an
33
+ * unnamed secret arrives as `__default_<type>`). Each value is the secret's
34
+ * struct as a plain object, including its serialized `type`, `name` and `scope`
35
+ * fields. Select from it with the helpers in `secrets/helpers.ts`
36
+ * (`secretOfType`, `secretByName`, `secretForScopeOfType`, ...), never by
37
+ * indexing it with a type. A null struct (secret not found) is skipped.
34
38
  */
35
39
  export declare function batchToSecretDict(batch: RecordBatch | VgiBatch | null): Record<string, Record<string, any>>;
36
40
  /**
@@ -20,7 +20,8 @@ export declare function batchToScalarDict(batch: VgiBatch | null): Record<string
20
20
  */
21
21
  export declare function decodeDictValue(value: any, _index?: number): any;
22
22
  /**
23
- * Single-row batch → secret dict. Mirrors impl-arrowjs's same-named function.
23
+ * Single-row resolved-secrets batch → dict keyed by column name (the secret's
24
+ * unique DuckDB NAME, not its type). Mirrors impl-arrowjs's same-named function.
24
25
  */
25
26
  export declare function batchToSecretDict(batch: VgiBatch | null): Record<string, Record<string, any>>;
26
27
  /**
@@ -1578,30 +1578,14 @@ function batchToSecretDict(batch) {
1578
1578
  const result = {};
1579
1579
  for (const field of a.schema.fields) {
1580
1580
  const col = a.getChild(field.name);
1581
- if (col) {
1582
- const type = field.type;
1583
- const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1584
- let key = field.name;
1585
- let scope;
1586
- if (field.name.startsWith("secret_")) {
1587
- const secretType = field.metadata?.get?.("secret_type");
1588
- if (secretType) {
1589
- key = secretType;
1590
- scope = field.metadata?.get?.("scope") ?? undefined;
1591
- }
1592
- }
1593
- if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1594
- const dict = { ...val };
1595
- if (key in result) {
1596
- throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
1597
- }
1598
- result[key] = dict;
1599
- if (scope) {
1600
- result[`${key}:${scope}`] = dict;
1601
- }
1602
- } else if (val === null || val === undefined) {} else {
1603
- result[key] = {};
1604
- }
1581
+ if (!col)
1582
+ continue;
1583
+ const type = field.type;
1584
+ const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
1585
+ if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
1586
+ result[field.name] = { ...val };
1587
+ } else if (val !== null && val !== undefined) {
1588
+ result[field.name] = {};
1605
1589
  }
1606
1590
  }
1607
1591
  return result;
@@ -6873,4 +6857,4 @@ export {
6873
6857
  validateTableConstraints
6874
6858
  };
6875
6859
 
6876
- //# debugId=F1A002FFA544727064756E2164756E21
6860
+ //# debugId=5B57243B0DE10BAA64756E2164756E21