@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.
- package/README.md +51 -1
- package/dist/arrow/impl-arrowjs/iterate.d.ts +7 -3
- package/dist/arrow/impl-flechette/iterate.d.ts +2 -1
- package/dist/catalog/descriptors.d.ts +14 -0
- package/dist/catalog/read-only.d.ts +4 -5
- package/dist/client-entry.js +9 -25
- package/dist/client-entry.js.map +3 -3
- package/dist/functions/aggregate.d.ts +2 -1
- package/dist/functions/copy-from.d.ts +2 -1
- package/dist/functions/copy-to.d.ts +2 -1
- package/dist/functions/registry.d.ts +1 -0
- package/dist/functions/scalar.d.ts +18 -6
- package/dist/functions/table-buffering.d.ts +2 -1
- package/dist/functions/table-in-out.d.ts +3 -2
- package/dist/functions/table.d.ts +2 -1
- package/dist/functions/types.d.ts +8 -3
- package/dist/index.core.d.ts +3 -2
- package/dist/index.js +177 -61
- package/dist/index.js.map +21 -20
- package/dist/metadata/types.d.ts +3 -1
- package/dist/secrets/helpers.d.ts +31 -3
- package/dist/secrets/requirements.d.ts +38 -0
- package/dist/serve-entry.js +14 -28
- package/dist/serve-entry.js.map +6 -6
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +205 -53
- package/dist/worker-cf-entry.js.map +18 -16
- package/package.json +1 -1
- package/src/arrow/impl-arrowjs/iterate.ts +17 -40
- package/src/arrow/impl-flechette/iterate.ts +5 -24
- package/src/catalog/descriptors.ts +14 -0
- package/src/catalog/read-only.ts +24 -16
- package/src/functions/aggregate.ts +3 -2
- package/src/functions/copy-from.ts +3 -2
- package/src/functions/copy-to.ts +2 -1
- package/src/functions/registry.ts +6 -3
- package/src/functions/scalar.ts +33 -10
- package/src/functions/table-buffering.ts +6 -2
- package/src/functions/table-in-out.ts +34 -13
- package/src/functions/table.ts +12 -8
- package/src/functions/types.ts +15 -4
- package/src/index.core.ts +11 -1
- package/src/metadata/resolve.ts +2 -1
- package/src/metadata/serialize.ts +25 -5
- package/src/metadata/types.ts +3 -1
- package/src/protocol/handlers/function.ts +16 -3
- package/src/secrets/helpers.ts +96 -9
- package/src/secrets/requirements.ts +121 -0
- package/src/worker-cf-entry.ts +14 -0
package/README.md
CHANGED
|
@@ -31,6 +31,26 @@ ATTACH 'demo' AS demo (TYPE vgi, LOCATION '/path/to/your-worker');
|
|
|
31
31
|
SELECT demo.upper_case(name) FROM users;
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## Start a new worker
|
|
35
|
+
|
|
36
|
+
The fastest way to a new TypeScript worker is the
|
|
37
|
+
[**vgi-starter-typescript**](https://github.com/Query-farm/vgi-starter-typescript) template: a complete,
|
|
38
|
+
tested worker with a scalar, a table function and a paginated REST API example, recipes for
|
|
39
|
+
common data-engineering tasks, SQL and unit tests, metadata that scores 100 on
|
|
40
|
+
[vgi-lint](https://github.com/Query-farm/vgi-lint-check), CI, Docker, signed release workflows,
|
|
41
|
+
and an `AGENTS.md` for coding agents.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
gh repo create my-worker --template Query-farm/vgi-starter-typescript --private --clone
|
|
45
|
+
cd my-worker
|
|
46
|
+
make init NAME=my_worker # rename the catalog, package and binary
|
|
47
|
+
make check # everything CI runs
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or click **Use this template** on GitHub. See
|
|
51
|
+
[starter templates](https://query.farm/vgi/docs/concepts/starter-templates/) for details. The
|
|
52
|
+
rest of this README covers the SDK itself.
|
|
53
|
+
|
|
34
54
|
## Install
|
|
35
55
|
|
|
36
56
|
```bash
|
|
@@ -108,7 +128,10 @@ const upperCase = defineScalarFunction({
|
|
|
108
128
|
// position (column 0 = first arg); return one output value per row (null ok).
|
|
109
129
|
// Full signature: compute(batch, consts, info) where
|
|
110
130
|
// consts → values of any `constParams` (literals folded at bind time)
|
|
111
|
-
// info → { settings, secrets, auth } — session settings,
|
|
131
|
+
// info → { settings, secrets, auth, bindCall } — session settings,
|
|
132
|
+
// secrets, caller, and the bind request (its attach_opaque_data
|
|
133
|
+
// carries the catalog's attach-time state, already unsealed)
|
|
134
|
+
// compute may be async: return a Promise to call a service per batch.
|
|
112
135
|
compute: (batch) => {
|
|
113
136
|
const values = batch.getChildAt(0)!; // first positional argument
|
|
114
137
|
return Array.from(values, (v) =>
|
|
@@ -214,6 +237,33 @@ SELECT demo.multiply(6, 7); -- 42
|
|
|
214
237
|
SELECT * FROM demo.sequence(5); -- 0,1,2,3,4
|
|
215
238
|
```
|
|
216
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
|
+
|
|
217
267
|
## Function types
|
|
218
268
|
|
|
219
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
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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 →
|
|
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
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { VgiSchema, VgiDataType } from "../arrow/index.js";
|
|
2
2
|
import type { AttachCatalogInfo } from "./interface.js";
|
|
3
|
+
import type { AttachOptionSpec } from "./attach-option.js";
|
|
3
4
|
import type { VgiFunction } from "../functions/types.js";
|
|
4
5
|
import type { Arguments } from "../arguments/arguments.js";
|
|
5
6
|
import type { ColumnStatistics } from "../util/statistics.js";
|
|
@@ -163,6 +164,19 @@ export interface CatalogDescriptor {
|
|
|
163
164
|
schemas: SchemaDescriptor[];
|
|
164
165
|
settings?: SettingDescriptor[];
|
|
165
166
|
secretTypes?: SecretTypeDescriptor[];
|
|
167
|
+
/**
|
|
168
|
+
* Options the catalog accepts at `ATTACH` time
|
|
169
|
+
* (`ATTACH 'x' (TYPE vgi, LOCATION '...', region 'eu', api_key '...')`).
|
|
170
|
+
* Advertised in the catalog's discovery record so the DuckDB extension
|
|
171
|
+
* validates and casts them (and redacts `secret` ones), and `required` ones
|
|
172
|
+
* are enforced at attach. Mirrors vgi-python's
|
|
173
|
+
* `ReadOnlyCatalogInterface.attach_option_specs`.
|
|
174
|
+
*
|
|
175
|
+
* The values reach `attach()` as its `options`; to hand them to functions,
|
|
176
|
+
* override `attach()` and carry them in `attach_opaque_data`
|
|
177
|
+
* (examples/attach-options-worker.ts), which every function call receives.
|
|
178
|
+
*/
|
|
179
|
+
attachOptions?: AttachOptionSpec[];
|
|
166
180
|
/**
|
|
167
181
|
* Companion catalogs (lakehouse federation) the client should ATTACH when this
|
|
168
182
|
* VGI catalog attaches. Surfaced via `catalog_attach.attach_catalogs`.
|
|
@@ -79,11 +79,10 @@ export declare class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
79
79
|
/**
|
|
80
80
|
* Attach-time options this catalog declares, for the named catalog.
|
|
81
81
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* several catalogs with different option sets.
|
|
82
|
+
* The descriptor's `attachOptions` (empty when it declares none). A
|
|
83
|
+
* subclass serving several catalogs with different option sets overrides
|
|
84
|
+
* this; `catalogsInfo()` advertises whatever it returns and `attach()`
|
|
85
|
+
* enforces the `required` ones, so the two never disagree.
|
|
87
86
|
*/
|
|
88
87
|
attachOptionSpecs(_name: string): AttachOptionSpec[];
|
|
89
88
|
catalogsInfo(): CatalogInfo[];
|
package/dist/client-entry.js
CHANGED
|
@@ -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
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
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=
|
|
6860
|
+
//# debugId=5B57243B0DE10BAA64756E2164756E21
|