@query-farm/vgi 0.48.2 → 0.48.4
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 +27 -0
- 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 +30 -0
- package/dist/catalog/interface.d.ts +28 -0
- package/dist/catalog/read-only.d.ts +16 -2
- package/dist/client-entry.js +9 -25
- package/dist/client-entry.js.map +4 -4
- 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/scalar.d.ts +2 -1
- 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 +2 -1
- package/dist/index.core.d.ts +4 -1
- package/dist/index.js +360 -72
- package/dist/index.js.map +25 -23
- package/dist/metadata/types.d.ts +3 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +8 -0
- package/dist/secrets/helpers.d.ts +31 -3
- package/dist/secrets/requirements.d.ts +38 -0
- package/dist/serve-entry.js +51 -33
- package/dist/serve-entry.js.map +9 -9
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +296 -50
- package/dist/worker-cf-entry.js.map +21 -18
- package/dist/write-results.d.ts +57 -0
- 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 +30 -0
- package/src/catalog/interface.ts +51 -0
- package/src/catalog/read-only.ts +129 -21
- 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/scalar.ts +3 -2
- package/src/functions/table-buffering.ts +3 -2
- package/src/functions/table-in-out.ts +5 -4
- package/src/functions/table.ts +3 -2
- package/src/functions/types.ts +2 -1
- package/src/index.core.ts +33 -0
- 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/catalog/shared.ts +17 -0
- package/src/protocol/handlers/catalog/table.ts +37 -0
- package/src/protocol/handlers/function.ts +42 -14
- package/src/secrets/helpers.ts +96 -9
- package/src/secrets/requirements.ts +121 -0
- package/src/worker-cf-entry.ts +14 -0
- package/src/write-results.ts +174 -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
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import type { VgiSchema, VgiDataType } from "../arrow/index.js";
|
|
2
2
|
import type { AttachCatalogInfo } from "./interface.js";
|
|
3
3
|
import type { AttachOptionSpec } from "./attach-option.js";
|
|
4
|
+
import type { WriteOperation, WriteResultMode } from "../write-results.js";
|
|
4
5
|
import type { VgiFunction } from "../functions/types.js";
|
|
5
6
|
import type { Arguments } from "../arguments/arguments.js";
|
|
6
7
|
import type { ColumnStatistics } from "../util/statistics.js";
|
|
@@ -33,6 +34,35 @@ export interface TableDescriptor {
|
|
|
33
34
|
columns?: VgiSchema;
|
|
34
35
|
function?: VgiFunction;
|
|
35
36
|
arguments?: Arguments;
|
|
37
|
+
/**
|
|
38
|
+
* Table in-out function backing `INSERT INTO <table>`. It receives the new
|
|
39
|
+
* rows (the table's user columns) and returns a `writeResultSchema` batch
|
|
40
|
+
* for the mode in its `write_options` (see `write-results.ts`). Omitted
|
|
41
|
+
* means the table does not accept INSERT.
|
|
42
|
+
*/
|
|
43
|
+
insertFunction?: VgiFunction;
|
|
44
|
+
/**
|
|
45
|
+
* Table in-out function backing `UPDATE <table>`. It receives the changed
|
|
46
|
+
* columns plus the row-id column (`rowIdField()`, which the scan
|
|
47
|
+
* `function` must emit) for each updated row. Requires `function`, which
|
|
48
|
+
* must also support projection pushdown and be listed in the schema's
|
|
49
|
+
* `functions` (see `rowIdField`).
|
|
50
|
+
*/
|
|
51
|
+
updateFunction?: VgiFunction;
|
|
52
|
+
/**
|
|
53
|
+
* Table in-out function backing `DELETE FROM <table>`. It receives the
|
|
54
|
+
* row-id column of each deleted row. Requires `function`, with the same
|
|
55
|
+
* projection-pushdown conditions as `updateFunction`.
|
|
56
|
+
*/
|
|
57
|
+
deleteFunction?: VgiFunction;
|
|
58
|
+
/**
|
|
59
|
+
* The richest result mode each write function produces: `count` (plain
|
|
60
|
+
* DML), `rows` (`RETURNING`) or `changes` (old/new pairs). Ordered
|
|
61
|
+
* `count < rows < changes`; supporting one mode promises every lower one.
|
|
62
|
+
* An operation with a write function but no entry defaults to `count`.
|
|
63
|
+
* Mirrors vgi-python's `Table.write_result_modes`.
|
|
64
|
+
*/
|
|
65
|
+
writeResultModes?: Partial<Record<WriteOperation, WriteResultMode>>;
|
|
36
66
|
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "NOT_NULL", ... })]`. */
|
|
37
67
|
notNull?: string[];
|
|
38
68
|
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "UNIQUE", ... })]`. */
|
|
@@ -108,6 +108,18 @@ export interface ScanFunctionResult {
|
|
|
108
108
|
*/
|
|
109
109
|
schemaPath: string[] | null;
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The `ScanFunctionResult` wire record as a catalog method returns it:
|
|
113
|
+
* `tableScanFunctionGet` (untyped, for history) and the write-function lookups
|
|
114
|
+
* `tableInsertFunctionGet` / `tableUpdateFunctionGet` / `tableDeleteFunctionGet`.
|
|
115
|
+
* `arguments` is the serialized inner arguments batch.
|
|
116
|
+
*/
|
|
117
|
+
export interface ScanFunctionResultRecord {
|
|
118
|
+
function_name: string;
|
|
119
|
+
arguments: Uint8Array;
|
|
120
|
+
required_extensions: string[];
|
|
121
|
+
schema_path: string[] | null;
|
|
122
|
+
}
|
|
111
123
|
/**
|
|
112
124
|
* Encode a ScanFunctionResult wire record — the single-row batch shape
|
|
113
125
|
* `{ function_name, arguments, required_extensions, schema_path }` that
|
|
@@ -405,6 +417,22 @@ export declare abstract class CatalogInterface {
|
|
|
405
417
|
tableConstraintsApply(request: ConstraintsApplyRequest): Promise<ConstraintSnapshot>;
|
|
406
418
|
tableDrop(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
407
419
|
tableScanFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<any>;
|
|
420
|
+
/**
|
|
421
|
+
* The table in-out function backing `INSERT INTO` this table. Default:
|
|
422
|
+
* the table is read-only. `writableBranchFunctionName` names the writable
|
|
423
|
+
* arm of a multi-branch table (null for a single-branch one).
|
|
424
|
+
*/
|
|
425
|
+
tableInsertFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData, writableBranchFunctionName?: string | null): Awaitable<ScanFunctionResultRecord>;
|
|
426
|
+
/**
|
|
427
|
+
* The table in-out function backing `UPDATE` of this table. Its input is the
|
|
428
|
+
* changed columns plus the row-id column. Default: the table is read-only.
|
|
429
|
+
*/
|
|
430
|
+
tableUpdateFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<ScanFunctionResultRecord>;
|
|
431
|
+
/**
|
|
432
|
+
* The table in-out function backing `DELETE FROM` this table. Its input is
|
|
433
|
+
* the row-id column. Default: the table is read-only.
|
|
434
|
+
*/
|
|
435
|
+
tableDeleteFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<ScanFunctionResultRecord>;
|
|
408
436
|
/**
|
|
409
437
|
* Return the scan branches for a (possibly multi-source) table. Default
|
|
410
438
|
* delegates to `tableScanFunctionGet` and wraps the single result as a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CatalogInterface, type AttachOpaqueData, type TransactionOpaqueData, type CatalogAttachResult, type SchemaInfo, type CatalogInfo, type TableInfo, type ViewInfo, type FunctionInfo, type MacroInfo, type IndexInfo, type CopyFromFormatInfo } from "./interface.js";
|
|
1
|
+
import { CatalogInterface, type AttachOpaqueData, type TransactionOpaqueData, type CatalogAttachResult, type SchemaInfo, type CatalogInfo, type TableInfo, type ViewInfo, type FunctionInfo, type MacroInfo, type IndexInfo, type CopyFromFormatInfo, type ScanFunctionResultRecord } from "./interface.js";
|
|
2
2
|
import { type CatalogDescriptor } from "./descriptors.js";
|
|
3
3
|
import type { FunctionRegistry } from "../functions/registry.js";
|
|
4
4
|
import { type AttachOptionSpec } from "./attach-option.js";
|
|
@@ -93,7 +93,16 @@ export declare class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
93
93
|
* `constraints`; override when tables are served outside the descriptor.
|
|
94
94
|
*/
|
|
95
95
|
catalogReadProfiles(): string[];
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Write profiles this catalog implements. A table that carries constraint
|
|
98
|
+
* records AND has a write function makes the catalog advertise
|
|
99
|
+
* `vgi.constraint.enforce.v1`: DuckDB only writes to a constrained table
|
|
100
|
+
* when the provider promises to keep its ENFORCED constraints, so such a
|
|
101
|
+
* table's write functions must reject rows that would violate them (for
|
|
102
|
+
* instance by refusing to change key columns).
|
|
103
|
+
*/
|
|
104
|
+
catalogWriteProfiles(): string[];
|
|
105
|
+
/** The descriptor's profiles: records are served, never mutated here; writable constrained tables enforce. */
|
|
97
106
|
catalogCapabilities(_attachOpaqueData: AttachOpaqueData): CatalogCapabilities | null;
|
|
98
107
|
detach(attachOpaqueData: AttachOpaqueData): void;
|
|
99
108
|
version(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): number | Promise<number>;
|
|
@@ -143,6 +152,11 @@ export declare class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
143
152
|
indexGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): IndexInfo | null;
|
|
144
153
|
macroGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): MacroInfo | null;
|
|
145
154
|
tableScanFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): any;
|
|
155
|
+
/** The write function for `operation`, or a read-only / not-found error. */
|
|
156
|
+
private _writeFunctionGet;
|
|
157
|
+
tableInsertFunctionGet(_attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, _transactionOpaqueData?: TransactionOpaqueData, _writableBranchFunctionName?: string | null): ScanFunctionResultRecord;
|
|
158
|
+
tableUpdateFunctionGet(_attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, _transactionOpaqueData?: TransactionOpaqueData): ScanFunctionResultRecord;
|
|
159
|
+
tableDeleteFunctionGet(_attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, _transactionOpaqueData?: TransactionOpaqueData): ScanFunctionResultRecord;
|
|
146
160
|
tableGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<TableInfo | null>;
|
|
147
161
|
viewGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): ViewInfo | null;
|
|
148
162
|
copyFromFormats(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): CopyFromFormatInfo[];
|
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
|