@query-farm/vgi 0.45.0 → 0.47.0
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 +19 -6
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/iterate.d.ts +2 -0
- package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/iterate.d.ts +2 -0
- package/dist/arrow/impl-flechette/schema.d.ts +19 -5
- package/dist/arrow/index.d.ts +1 -1
- package/dist/catalog/column-expressions.d.ts +8 -0
- package/dist/catalog/column-metadata.d.ts +11 -0
- package/dist/catalog/composite.d.ts +2 -1
- package/dist/catalog/descriptors.d.ts +21 -29
- package/dist/catalog/interface.d.ts +15 -20
- package/dist/catalog/macro-overloads.d.ts +4 -0
- package/dist/catalog/read-only.d.ts +1 -1
- package/dist/catalog/unconstrained-columns.d.ts +2 -0
- package/dist/client/client.d.ts +38 -14
- package/dist/client-entry.js +806 -115
- package/dist/client-entry.js.map +18 -14
- package/dist/functions/continuation.d.ts +69 -0
- package/dist/functions/projection.d.ts +18 -0
- package/dist/functions/table-in-out.d.ts +51 -7
- package/dist/functions/table.d.ts +6 -1
- package/dist/functions/types.d.ts +21 -0
- package/dist/generated/vgi-client.d.ts +178 -36
- package/dist/generated/vgi-protocol-schemas.d.ts +51 -1
- package/dist/generated/vgi-protocol-types.d.ts +317 -3
- package/dist/generated/vgi-service.d.ts +266 -29
- package/dist/index.core.d.ts +3 -1
- package/dist/index.js +1747 -320
- package/dist/index.js.map +45 -37
- package/dist/protocol/dispatch.d.ts +9 -9
- package/dist/protocol/handlers/aggregate.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index.d.ts +1 -1
- package/dist/protocol/handlers/catalog/metadata.d.ts +1 -0
- package/dist/protocol/handlers/function.d.ts +1 -1
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/protocol/handlers/unimplemented.d.ts +1 -1
- package/dist/protocol/serializers/bind.d.ts +5 -1
- package/dist/protocol/types.d.ts +5 -0
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.js +1607 -436
- package/dist/serve-entry.js.map +33 -27
- package/dist/util/arrow/index.d.ts +1 -1
- package/dist/util/parent-rows.d.ts +8 -0
- package/dist/worker-cf-entry.d.ts +1 -1
- package/dist/worker-cf-entry.js +1901 -526
- package/dist/worker-cf-entry.js.map +45 -37
- package/dist/worker.d.ts +1 -1
- package/package.json +8 -7
- package/src/arrow/impl-arrowjs/index.ts +1 -1
- package/src/arrow/impl-arrowjs/iterate.ts +9 -1
- package/src/arrow/impl-arrowjs/project.ts +1 -1
- package/src/arrow/impl-flechette/canonical.ts +7 -5
- package/src/arrow/impl-flechette/index.ts +1 -1
- package/src/arrow/impl-flechette/ipc.ts +12 -0
- package/src/arrow/impl-flechette/iterate.ts +5 -0
- package/src/arrow/impl-flechette/project.ts +6 -8
- package/src/arrow/index.ts +1 -1
- package/src/catalog/column-expressions.ts +224 -0
- package/src/catalog/column-metadata.ts +151 -0
- package/src/catalog/composite.ts +5 -1
- package/src/catalog/contents-codec.ts +6 -1
- package/src/catalog/descriptors.ts +21 -29
- package/src/catalog/interface.ts +70 -55
- package/src/catalog/macro-overloads.ts +44 -0
- package/src/catalog/read-only.ts +69 -71
- package/src/catalog/unconstrained-columns.ts +23 -0
- package/src/client/client.ts +180 -69
- package/src/codec/asd.ts +3 -1
- package/src/filter-pushdown/collector.ts +17 -1
- package/src/functions/continuation.ts +202 -0
- package/src/functions/projection.ts +207 -0
- package/src/functions/table-in-out.ts +131 -56
- package/src/functions/table.ts +10 -0
- package/src/functions/types.ts +21 -0
- package/src/generated/vgi-client.ts +200 -37
- package/src/generated/vgi-protocol-schemas.ts +456 -41
- package/src/generated/vgi-protocol-types.ts +879 -5
- package/src/generated/vgi-service.ts +514 -42
- package/src/http/client-bundle.ts +1 -1
- package/src/http/fetch.ts +1 -1
- package/src/index.core.ts +10 -0
- package/src/protocol/dispatch.ts +9 -9
- package/src/protocol/handlers/aggregate.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +10 -5
- package/src/protocol/handlers/catalog/index.ts +2 -2
- package/src/protocol/handlers/catalog/macro.ts +6 -5
- package/src/protocol/handlers/catalog/metadata.ts +16 -0
- package/src/protocol/handlers/catalog/table.ts +72 -26
- package/src/protocol/handlers/catalog/view.ts +24 -3
- package/src/protocol/handlers/function.ts +79 -1
- package/src/protocol/handlers/table-buffering.ts +1 -1
- package/src/protocol/handlers/unimplemented.ts +6 -6
- package/src/protocol/serializers/bind.ts +17 -1
- package/src/protocol/state-serializer.ts +7 -1
- package/src/protocol/types.ts +6 -0
- package/src/rpc-server.ts +9 -9
- package/src/util/arrow/index.ts +1 -1
- package/src/util/parent-rows.ts +41 -0
- package/src/worker-cf-entry.ts +3 -0
- package/src/worker.ts +1 -1
package/src/http/fetch.ts
CHANGED
|
@@ -205,7 +205,7 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
|
|
|
205
205
|
...opts.protocol,
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
-
// The same builder every other transport uses: `vgi.
|
|
208
|
+
// The same builder every other transport uses: `vgi.v3`, the worker's
|
|
209
209
|
// hostedProtocols(), reflection, and -- HTTP being the transport that
|
|
210
210
|
// authenticates callers -- vgi_rpc.Identity.v2 when the worker opts in.
|
|
211
211
|
// Built at construction, so a worker that opts into introspection without an
|
package/src/index.core.ts
CHANGED
|
@@ -52,6 +52,12 @@ export {
|
|
|
52
52
|
type RowTransformConfig,
|
|
53
53
|
type RowTransformProcessParams,
|
|
54
54
|
} from "./functions/table-in-out.js";
|
|
55
|
+
export {
|
|
56
|
+
moreOutputMetadata,
|
|
57
|
+
STATUS_KEY,
|
|
58
|
+
HAVE_MORE_OUTPUT,
|
|
59
|
+
CONTINUE,
|
|
60
|
+
} from "./functions/continuation.js";
|
|
55
61
|
export {
|
|
56
62
|
defineTableBufferingFunction,
|
|
57
63
|
type TableBufferingConfig,
|
|
@@ -100,6 +106,7 @@ export {
|
|
|
100
106
|
export type {
|
|
101
107
|
BindRequest,
|
|
102
108
|
BindResponse,
|
|
109
|
+
BindRepeatability,
|
|
103
110
|
CopyFromContext,
|
|
104
111
|
CopyToContext,
|
|
105
112
|
InitRequest,
|
|
@@ -361,3 +368,6 @@ export {
|
|
|
361
368
|
} from "@query-farm/vgi-rpc";
|
|
362
369
|
export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
|
|
363
370
|
export { normalizeSchemaPath, schemaPathDisplay, schemaPathKey, schemaPathsEqual, type SchemaPath } from "./schema-path.js";
|
|
371
|
+
|
|
372
|
+
// Optional scalar projection negotiation and its explicit offer.
|
|
373
|
+
export { SCALAR_PROJECTION_PROFILE, type ProjectionProposal, type ProjectionAcceptance } from "./functions/projection.js";
|
package/src/protocol/dispatch.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface ProtocolConfig {
|
|
|
39
39
|
* The name carries the major version, so an incompatible major is a
|
|
40
40
|
* *different* protocol and therefore a 404 — an answer every proxy, WAF and
|
|
41
41
|
* load balancer understands without an Arrow parser, and one that lets
|
|
42
|
-
* `vgi.v2` and
|
|
42
|
+
* `vgi.v2` and `vgi.v3` be served side by side while clients migrate.
|
|
43
43
|
* That matters for this consumer specifically: the DuckDB extension ships to
|
|
44
44
|
* users and cannot be flag-dayed.
|
|
45
45
|
*
|
|
@@ -61,22 +61,22 @@ export interface ProtocolConfig {
|
|
|
61
61
|
export { VGI_PROTOCOL_NAME };
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* The `vgi.
|
|
65
|
-
* worker: the reference's
|
|
66
|
-
* every `vgi.
|
|
64
|
+
* The `vgi.v3` protocol hash `vgi_rpc.Reflection.v1` must report for this
|
|
65
|
+
* worker: the combined reference's 85 methods. Every SDK hosts
|
|
66
|
+
* every `vgi.v3` method with the reference's schemas, so the hash is one value
|
|
67
67
|
* across the ports; a method this SDK does not implement is still registered
|
|
68
68
|
* with the generated UNIMPLEMENTED default (src/generated/vgi-service.ts). The
|
|
69
69
|
* hash covers method names, types and the params/result/header schemas only
|
|
70
70
|
* (WIRE_PROTOCOL.md §14).
|
|
71
71
|
*
|
|
72
|
-
* It changes only with vgi.
|
|
73
|
-
* by src/protocol/__tests__/vgi-
|
|
72
|
+
* It changes only with vgi.v3's protocol version (currently 3.0.0). Asserted
|
|
73
|
+
* by src/protocol/__tests__/vgi-v3-hash.test.ts; if that test fails, the
|
|
74
74
|
* surface drifted from the reference -- fix the schemas, do not bump this.
|
|
75
75
|
*/
|
|
76
|
-
export const
|
|
76
|
+
export const VGI_V3_PROTOCOL_HASH = "50e9404173bee3262e96b8939eb5c425463336abca2a17916812d68b6e0f6cad";
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* This worker's `vgi.
|
|
79
|
+
* This worker's `vgi.v3` implementation: the generated UNIMPLEMENTED default
|
|
80
80
|
* for every method, overridden by the handler groups for what this SDK serves.
|
|
81
81
|
*/
|
|
82
82
|
export function buildVgiService(config: ProtocolConfig): VgiService {
|
|
@@ -93,7 +93,7 @@ export function buildVgiService(config: ProtocolConfig): VgiService {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
/** The `vgi.
|
|
96
|
+
/** The `vgi.v3` protocol, registered from the generated table with {@link buildVgiService}. */
|
|
97
97
|
export function buildVgiProtocol(config: ProtocolConfig): Protocol {
|
|
98
98
|
return createVgiProtocol(buildVgiService(config));
|
|
99
99
|
}
|
|
@@ -35,7 +35,7 @@ import { Arguments } from "../../arguments/arguments.js";
|
|
|
35
35
|
import { validateConstConstraints } from "../../arguments/argument-spec.js";
|
|
36
36
|
import { unwrapRequest, wrapResult } from "./shared.js";
|
|
37
37
|
|
|
38
|
-
/** The aggregate lifecycle's `vgi.
|
|
38
|
+
/** The aggregate lifecycle's `vgi.v3` handlers. */
|
|
39
39
|
export function aggregateHandlers(registry: FunctionRegistry): Partial<VgiService> {
|
|
40
40
|
// `schemaPath` scopes resolution to the schema the caller named. Every
|
|
41
41
|
// aggregate RPC carries it (protocol 1.2.0), so an aggregate name declared in
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
import { encodeValidatedTableInfo } from "../../../catalog/column-metadata.js";
|
|
3
|
+
import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
|
|
2
4
|
// Catalog admin handlers: attach/detach/create/drop, version, transactions,
|
|
3
5
|
// schemas (list, get, create, drop), schema contents listings.
|
|
4
6
|
|
|
7
|
+
import { catalogStringMap } from "./metadata.js";
|
|
5
8
|
import { schema } from "../../../arrow/index.js";
|
|
6
9
|
import type { CallContext } from "@query-farm/vgi-rpc";
|
|
7
10
|
import type { VgiService } from "../../../generated/vgi-service.js";
|
|
8
11
|
import {
|
|
9
12
|
encodeSchemaInfo,
|
|
10
|
-
encodeTableInfo,
|
|
11
13
|
encodeViewInfo,
|
|
12
14
|
encodeCatalogInfo,
|
|
13
15
|
} from "../../../generated/vgi-client.js";
|
|
@@ -97,6 +99,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
97
99
|
optionsDict,
|
|
98
100
|
innerParams.data_version_spec ?? null,
|
|
99
101
|
innerParams.implementation_version ?? null,
|
|
102
|
+
innerParams.client_capabilities == null ? null : toUint8Array(innerParams.client_capabilities),
|
|
100
103
|
);
|
|
101
104
|
// Seal the attach value into an AEAD envelope bound to the caller's
|
|
102
105
|
// identity before it leaves the worker (HTTP transport; pass-through
|
|
@@ -243,13 +246,15 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
243
246
|
|
|
244
247
|
// catalog_schema_create
|
|
245
248
|
const catalogSchemaCreate = catalogHandler(signingKey, async (params) => {
|
|
249
|
+
if (params.options != null) throw new MethodNotImplementedError("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
|
|
246
250
|
const cat = getCatalog();
|
|
247
251
|
await cat.schemaCreate(
|
|
248
252
|
toUint8Array(params.attach_opaque_data),
|
|
249
|
-
params.path,
|
|
253
|
+
Array.from(params.path),
|
|
250
254
|
params.comment,
|
|
251
|
-
|
|
252
|
-
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
255
|
+
catalogStringMap(params.tags),
|
|
256
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
|
|
257
|
+
decodeDictValue(params.on_conflict)
|
|
253
258
|
);
|
|
254
259
|
return {};
|
|
255
260
|
});
|
|
@@ -276,7 +281,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
276
281
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
277
282
|
);
|
|
278
283
|
return wrapResult({
|
|
279
|
-
items: tables.map((t) =>
|
|
284
|
+
items: tables.map((t) => encodeValidatedTableInfo(t)),
|
|
280
285
|
}, CatalogSchemaContentsTablesResultSchema);
|
|
281
286
|
});
|
|
282
287
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
-
// Catalog handler orchestrator: every catalog_* `vgi.
|
|
2
|
+
// Catalog handler orchestrator: every catalog_* `vgi.v3` handler.
|
|
3
3
|
|
|
4
4
|
import type { CatalogInterface } from "../../../catalog/interface.js";
|
|
5
5
|
import type { VgiService } from "../../../generated/vgi-service.js";
|
|
@@ -10,7 +10,7 @@ import { catalogViewHandlers } from "./view.js";
|
|
|
10
10
|
import { catalogMacroHandlers } from "./macro.js";
|
|
11
11
|
import { catalogIndexHandlers } from "./index_methods.js";
|
|
12
12
|
|
|
13
|
-
/** The catalog_* `vgi.
|
|
13
|
+
/** The catalog_* `vgi.v3` handlers, over *catalog* (or `NoCatalogError` without one). */
|
|
14
14
|
export function catalogHandlers(
|
|
15
15
|
catalog: CatalogInterface | undefined,
|
|
16
16
|
signingKey?: Uint8Array,
|
|
@@ -5,11 +5,14 @@ import type { VgiService } from "../../../generated/vgi-service.js";
|
|
|
5
5
|
import { encodeMacroInfo } from "../../../generated/vgi-client.js";
|
|
6
6
|
import {
|
|
7
7
|
CatalogMacroGetResultSchema,
|
|
8
|
+
MacroCreateRequestSchema,
|
|
8
9
|
CatalogSchemaContentsMacrosResultSchema,
|
|
9
10
|
} from "../../../generated/vgi-protocol-schemas.js";
|
|
10
11
|
import type { MacroType } from "../../../catalog/interface.js";
|
|
11
12
|
import { toUint8Array } from "../../../util/bytes.js";
|
|
12
13
|
import { decodeDictValue } from "../../../util/arrow/index.js";
|
|
14
|
+
import { decodeASD, encodeASD } from "../../../codec/asd.js";
|
|
15
|
+
import type { MacroCreateRequest } from "../../../generated/vgi-client.js";
|
|
13
16
|
import {
|
|
14
17
|
wrapResult,
|
|
15
18
|
} from "../shared.js";
|
|
@@ -37,17 +40,15 @@ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
37
40
|
const catalogMacroCreate = catalogHandler(signingKey, async (params) => {
|
|
38
41
|
const cat = getCatalog();
|
|
39
42
|
// catalogHandler already flattened the wrapped request.
|
|
40
|
-
const innerParams = params;
|
|
43
|
+
const innerParams = decodeASD<MacroCreateRequest>(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
|
|
44
|
+
if (!innerParams.overloads?.length) throw new Error("macro overload family must be nonempty");
|
|
41
45
|
await cat.macroCreate(
|
|
42
46
|
toUint8Array(innerParams.attach_opaque_data),
|
|
43
47
|
innerParams.schema_path,
|
|
44
48
|
innerParams.name,
|
|
45
49
|
innerParams.macro_type as MacroType,
|
|
46
|
-
innerParams.
|
|
47
|
-
innerParams.definition,
|
|
50
|
+
innerParams.overloads,
|
|
48
51
|
innerParams.on_conflict,
|
|
49
|
-
innerParams.parameter_default_values ? toUint8Array(innerParams.parameter_default_values) : null,
|
|
50
|
-
innerParams.arguments_schema ? toUint8Array(innerParams.arguments_schema) : null,
|
|
51
52
|
innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined
|
|
52
53
|
);
|
|
53
54
|
return {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
import { decodeMapValue } from "../../../util/arrow/index.js";
|
|
3
|
+
|
|
4
|
+
export function catalogStringMap(raw: any): Record<string, string> {
|
|
5
|
+
raw = decodeMapValue(raw);
|
|
6
|
+
const result: Record<string, string> = {};
|
|
7
|
+
if (raw == null) return result;
|
|
8
|
+
const entries = raw[Symbol.iterator] ? raw : Object.entries(raw);
|
|
9
|
+
for (const entry of entries) {
|
|
10
|
+
const [key, value] = Array.isArray(entry) ? entry : [entry.key, entry.value];
|
|
11
|
+
if (typeof key !== "string" || typeof value !== "string") throw new Error("catalog metadata must map strings to strings");
|
|
12
|
+
Object.defineProperty(result, key, { value, enumerable: true, writable: true, configurable: true });
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
import { encodeValidatedTableInfo, validateColumnMetadataIpc } from "../../../catalog/column-metadata.js";
|
|
3
|
+
import { validateColumnExpressionsIpc } from "../../../catalog/column-expressions.js";
|
|
4
|
+
import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
|
|
2
5
|
// Catalog table handlers: table_get/create/drop, scan_function_get,
|
|
3
6
|
// column_statistics_get, comment_set, rename, plus all column_* mutations.
|
|
4
7
|
|
|
5
8
|
import type { VgiService } from "../../../generated/vgi-service.js";
|
|
6
|
-
import { encodeTableInfo } from "../../../generated/vgi-client.js";
|
|
7
9
|
import {
|
|
8
10
|
CatalogTableGetResultSchema,
|
|
9
11
|
ScanBranchesResultSchema,
|
|
10
12
|
ScanFunctionResultSchema,
|
|
11
13
|
} from "../../../generated/vgi-protocol-schemas.js";
|
|
12
14
|
import { toUint8Array } from "../../../util/bytes.js";
|
|
15
|
+
import { requireUnconstrainedColumns } from "../../../catalog/unconstrained-columns.js";
|
|
13
16
|
import {
|
|
14
17
|
wrapResult,
|
|
15
18
|
} from "../shared.js";
|
|
@@ -18,6 +21,17 @@ import {
|
|
|
18
21
|
catalogHandler,
|
|
19
22
|
} from "./shared.js";
|
|
20
23
|
|
|
24
|
+
function requireFlatColumnPath(value: unknown, operation: string): string[] {
|
|
25
|
+
// The raw RPC codec returns Arrow list scalars as iterable vectors.
|
|
26
|
+
const path = value != null && typeof value === "object" && Symbol.iterator in value
|
|
27
|
+
? Array.from(value as Iterable<unknown>) : value;
|
|
28
|
+
if (!Array.isArray(path) || path.length !== 1 ||
|
|
29
|
+
typeof path[0] !== "string" || !path[0] || path[0].includes("\0")) {
|
|
30
|
+
throw new MethodNotImplementedError(`${operation}: nested column paths require a negotiated capability`);
|
|
31
|
+
}
|
|
32
|
+
return path as string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
21
35
|
export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
|
|
22
36
|
// catalog_table_get
|
|
23
37
|
const catalogTableGet = catalogHandler(signingKey, async (params) => {
|
|
@@ -31,12 +45,22 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
31
45
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
32
46
|
);
|
|
33
47
|
return wrapResult({
|
|
34
|
-
items: info ? [
|
|
48
|
+
items: info ? [encodeValidatedTableInfo(info)] : [],
|
|
35
49
|
}, CatalogTableGetResultSchema);
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
// catalog_table_create
|
|
39
53
|
const catalogTableCreate = catalogHandler(signingKey, async (params) => {
|
|
54
|
+
if (params.constraint_definitions == null) throw new Error("constraint_definitions is required");
|
|
55
|
+
if (Array.from(params.constraint_definitions as Iterable<unknown>).length > 0) {
|
|
56
|
+
throw new MethodNotImplementedError("catalog_table_create: canonical constraint enforcement is not supported");
|
|
57
|
+
}
|
|
58
|
+
if (params.comment != null || params.tags != null || params.options != null || params.layout != null) {
|
|
59
|
+
throw new MethodNotImplementedError("catalog_table_create: table metadata/options/layout profiles are not supported");
|
|
60
|
+
}
|
|
61
|
+
validateColumnMetadataIpc(toUint8Array(params.columns));
|
|
62
|
+
validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
|
|
63
|
+
requireUnconstrainedColumns(toUint8Array(params.columns));
|
|
40
64
|
const cat = getCatalog();
|
|
41
65
|
await cat.tableCreate(
|
|
42
66
|
toUint8Array(params.attach_opaque_data),
|
|
@@ -44,9 +68,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
44
68
|
params.name,
|
|
45
69
|
toUint8Array(params.columns),
|
|
46
70
|
params.on_conflict,
|
|
47
|
-
|
|
48
|
-
params.unique_constraints ?? [],
|
|
49
|
-
params.check_constraints ?? [],
|
|
71
|
+
[],
|
|
50
72
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
51
73
|
);
|
|
52
74
|
return {};
|
|
@@ -137,122 +159,145 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
137
159
|
|
|
138
160
|
// catalog_table_column_add
|
|
139
161
|
const catalogTableColumnAdd = catalogHandler(signingKey, async (params) => {
|
|
162
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
|
|
163
|
+
validateColumnMetadataIpc(toUint8Array(params.column_definition));
|
|
164
|
+
validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
|
|
140
165
|
const cat = getCatalog();
|
|
141
166
|
await cat.tableColumnAdd(
|
|
142
167
|
toUint8Array(params.attach_opaque_data),
|
|
143
168
|
params.schema_path,
|
|
144
169
|
params.name,
|
|
145
|
-
params.
|
|
146
|
-
params.
|
|
147
|
-
params.default_value,
|
|
170
|
+
params.column_path,
|
|
171
|
+
toUint8Array(params.column_definition),
|
|
148
172
|
params.ignore_not_found,
|
|
173
|
+
params.if_column_not_exists,
|
|
149
174
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
150
175
|
);
|
|
151
176
|
return {};
|
|
152
177
|
});
|
|
153
|
-
|
|
154
178
|
// catalog_table_column_drop
|
|
155
179
|
const catalogTableColumnDrop = catalogHandler(signingKey, async (params) => {
|
|
180
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
|
|
156
181
|
const cat = getCatalog();
|
|
157
182
|
await cat.tableColumnDrop(
|
|
158
183
|
toUint8Array(params.attach_opaque_data),
|
|
159
184
|
params.schema_path,
|
|
160
185
|
params.name,
|
|
161
|
-
params.
|
|
186
|
+
params.column_path,
|
|
162
187
|
params.ignore_not_found,
|
|
188
|
+
params.if_column_exists,
|
|
189
|
+
params.cascade,
|
|
163
190
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
164
191
|
);
|
|
165
192
|
return {};
|
|
166
193
|
});
|
|
167
|
-
|
|
168
194
|
// catalog_table_column_rename
|
|
169
195
|
const catalogTableColumnRename = catalogHandler(signingKey, async (params) => {
|
|
196
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
|
|
170
197
|
const cat = getCatalog();
|
|
171
198
|
await cat.tableColumnRename(
|
|
172
199
|
toUint8Array(params.attach_opaque_data),
|
|
173
200
|
params.schema_path,
|
|
174
201
|
params.name,
|
|
175
|
-
params.
|
|
176
|
-
params.
|
|
202
|
+
params.column_path,
|
|
203
|
+
params.new_column_name,
|
|
204
|
+
params.ignore_not_found,
|
|
205
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
206
|
+
);
|
|
207
|
+
return {};
|
|
208
|
+
});
|
|
209
|
+
// catalog_table_column_comment_set
|
|
210
|
+
const catalogTableColumnCommentSet = catalogHandler(signingKey, async (params) => {
|
|
211
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
|
|
212
|
+
const cat = getCatalog();
|
|
213
|
+
await cat.tableColumnCommentSet(
|
|
214
|
+
toUint8Array(params.attach_opaque_data),
|
|
215
|
+
params.schema_path,
|
|
216
|
+
params.name,
|
|
217
|
+
params.column_path,
|
|
218
|
+
params.comment,
|
|
177
219
|
params.ignore_not_found,
|
|
178
220
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
179
221
|
);
|
|
180
222
|
return {};
|
|
181
223
|
});
|
|
182
|
-
|
|
183
224
|
// catalog_table_column_default_set
|
|
184
225
|
const catalogTableColumnDefaultSet = catalogHandler(signingKey, async (params) => {
|
|
226
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
|
|
185
227
|
const cat = getCatalog();
|
|
186
228
|
await cat.tableColumnDefaultSet(
|
|
187
229
|
toUint8Array(params.attach_opaque_data),
|
|
188
230
|
params.schema_path,
|
|
189
231
|
params.name,
|
|
190
|
-
params.
|
|
191
|
-
params.
|
|
232
|
+
params.column_path,
|
|
233
|
+
toUint8Array(params.expression),
|
|
192
234
|
params.ignore_not_found,
|
|
193
235
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
194
236
|
);
|
|
195
237
|
return {};
|
|
196
238
|
});
|
|
197
|
-
|
|
198
239
|
// catalog_table_column_default_drop
|
|
199
240
|
const catalogTableColumnDefaultDrop = catalogHandler(signingKey, async (params) => {
|
|
241
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
|
|
200
242
|
const cat = getCatalog();
|
|
201
243
|
await cat.tableColumnDefaultDrop(
|
|
202
244
|
toUint8Array(params.attach_opaque_data),
|
|
203
245
|
params.schema_path,
|
|
204
246
|
params.name,
|
|
205
|
-
params.
|
|
247
|
+
params.column_path,
|
|
206
248
|
params.ignore_not_found,
|
|
207
249
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
208
250
|
);
|
|
209
251
|
return {};
|
|
210
252
|
});
|
|
211
|
-
|
|
212
253
|
// catalog_table_column_type_change
|
|
213
254
|
const catalogTableColumnTypeChange = catalogHandler(signingKey, async (params) => {
|
|
255
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
|
|
214
256
|
const cat = getCatalog();
|
|
215
257
|
await cat.tableColumnTypeChange(
|
|
216
258
|
toUint8Array(params.attach_opaque_data),
|
|
217
259
|
params.schema_path,
|
|
218
260
|
params.name,
|
|
219
|
-
params.
|
|
220
|
-
params.
|
|
261
|
+
params.column_path,
|
|
262
|
+
toUint8Array(params.column_definition),
|
|
263
|
+
params.expression == null ? null : toUint8Array(params.expression),
|
|
221
264
|
params.ignore_not_found,
|
|
222
265
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
223
266
|
);
|
|
224
267
|
return {};
|
|
225
268
|
});
|
|
226
|
-
|
|
227
269
|
// catalog_table_not_null_set
|
|
228
270
|
const catalogTableNotNullSet = catalogHandler(signingKey, async (params) => {
|
|
271
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
|
|
229
272
|
const cat = getCatalog();
|
|
230
273
|
await cat.tableNotNullSet(
|
|
231
274
|
toUint8Array(params.attach_opaque_data),
|
|
232
275
|
params.schema_path,
|
|
233
276
|
params.name,
|
|
234
|
-
params.
|
|
277
|
+
params.column_path,
|
|
235
278
|
params.ignore_not_found,
|
|
236
279
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
237
280
|
);
|
|
238
281
|
return {};
|
|
239
282
|
});
|
|
240
|
-
|
|
241
283
|
// catalog_table_not_null_drop
|
|
242
284
|
const catalogTableNotNullDrop = catalogHandler(signingKey, async (params) => {
|
|
285
|
+
params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
|
|
243
286
|
const cat = getCatalog();
|
|
244
287
|
await cat.tableNotNullDrop(
|
|
245
288
|
toUint8Array(params.attach_opaque_data),
|
|
246
289
|
params.schema_path,
|
|
247
290
|
params.name,
|
|
248
|
-
params.
|
|
291
|
+
params.column_path,
|
|
249
292
|
params.ignore_not_found,
|
|
250
293
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
251
294
|
);
|
|
252
295
|
return {};
|
|
253
296
|
});
|
|
254
|
-
|
|
255
297
|
return {
|
|
298
|
+
catalogTableConstraintsApply: async () => {
|
|
299
|
+
throw new MethodNotImplementedError("catalog_table_constraints_apply");
|
|
300
|
+
},
|
|
256
301
|
catalogTableGet,
|
|
257
302
|
catalogTableCreate,
|
|
258
303
|
catalogTableDrop,
|
|
@@ -264,6 +309,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
264
309
|
catalogTableColumnAdd,
|
|
265
310
|
catalogTableColumnDrop,
|
|
266
311
|
catalogTableColumnRename,
|
|
312
|
+
catalogTableColumnCommentSet,
|
|
267
313
|
catalogTableColumnDefaultSet,
|
|
268
314
|
catalogTableColumnDefaultDrop,
|
|
269
315
|
catalogTableColumnTypeChange,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
2
|
// Catalog view handlers: view_get/create/drop/rename/comment_set.
|
|
3
3
|
|
|
4
|
+
import { catalogStringMap } from "./metadata.js";
|
|
4
5
|
import type { VgiService } from "../../../generated/vgi-service.js";
|
|
5
6
|
import { encodeViewInfo } from "../../../generated/vgi-client.js";
|
|
6
7
|
import {
|
|
7
8
|
CatalogViewGetResultSchema,
|
|
8
9
|
} from "../../../generated/vgi-protocol-schemas.js";
|
|
10
|
+
import { decodeDictValue } from "../../../util/arrow/index.js";
|
|
9
11
|
import { toUint8Array } from "../../../util/bytes.js";
|
|
10
12
|
import {
|
|
11
13
|
wrapResult,
|
|
@@ -32,14 +34,22 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
32
34
|
|
|
33
35
|
// catalog_view_create
|
|
34
36
|
const catalogViewCreate = catalogHandler(signingKey, async (params) => {
|
|
37
|
+
if (params.security !== "regular") throw new Error(`view security mode ${params.security} is unsupported`);
|
|
38
|
+
const tags = catalogStringMap(params.tags);
|
|
39
|
+
const columnComments = catalogStringMap(params.column_comments);
|
|
40
|
+
if (Object.keys(columnComments).some((key) => !key || key.includes("\0"))) throw new Error("view column comments require raw output identifiers");
|
|
35
41
|
const cat = getCatalog();
|
|
36
42
|
await cat.viewCreate(
|
|
37
43
|
toUint8Array(params.attach_opaque_data),
|
|
38
44
|
params.schema_path,
|
|
39
45
|
params.name,
|
|
40
46
|
params.definition,
|
|
41
|
-
params.on_conflict,
|
|
42
|
-
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
47
|
+
decodeDictValue(params.on_conflict),
|
|
48
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
|
|
49
|
+
params.aliases ?? [],
|
|
50
|
+
params.comment,
|
|
51
|
+
tags,
|
|
52
|
+
columnComments
|
|
43
53
|
);
|
|
44
54
|
return {};
|
|
45
55
|
});
|
|
@@ -85,5 +95,16 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
|
|
|
85
95
|
return {};
|
|
86
96
|
});
|
|
87
97
|
|
|
88
|
-
|
|
98
|
+
const catalogViewColumnCommentSet = catalogHandler(signingKey, async (params) => {
|
|
99
|
+
const path: string[] = Array.from(params.column_path);
|
|
100
|
+
if (path.length !== 1 || !path[0] || path[0].includes("\0")) throw new Error("view column comments require one raw output identifier");
|
|
101
|
+
await getCatalog().viewColumnCommentSet(
|
|
102
|
+
toUint8Array(params.attach_opaque_data), params.schema_path, params.name, path,
|
|
103
|
+
params.comment, params.ignore_not_found,
|
|
104
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
105
|
+
);
|
|
106
|
+
return {};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return { catalogViewColumnCommentSet, catalogViewGet, catalogViewCreate, catalogViewDrop, catalogViewRename, catalogViewCommentSet };
|
|
89
110
|
}
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
// implements VgiFunction.bind/globalInit/createStreamHandlers.
|
|
5
5
|
|
|
6
6
|
import { type VgiSchema, schema, type VgiField, field, type VgiDataType, binary, int64 } from "../../arrow/index.js";
|
|
7
|
+
import { projectionRecord, validateProjectionOffer, validateProjectionProposal, validateProjectionAcceptance, type ProjectionProposal } from "../../functions/projection.js";
|
|
8
|
+
import { deserializeBindResponse } from "../serializers/bind.js";
|
|
9
|
+
import { deserializeSchema } from "../../arrow/index.js";
|
|
7
10
|
import type { AuthContext } from "@query-farm/vgi-rpc";
|
|
8
11
|
import { exchangeStream, type VgiService } from "../../generated/vgi-service.js";
|
|
9
12
|
import type { FunctionRegistry } from "../../functions/registry.js";
|
|
10
13
|
import type { StreamHandlers, HandlerState } from "../../functions/types.js";
|
|
14
|
+
import { refuseMoreOutput } from "../../functions/continuation.js";
|
|
11
15
|
import {
|
|
12
16
|
deserializeBindRequest,
|
|
13
17
|
serializeBindResponse,
|
|
@@ -22,6 +26,9 @@ import { toUint8Array } from "../../util/bytes.js";
|
|
|
22
26
|
import { serializeColumnStatistics } from "../../util/statistics.js";
|
|
23
27
|
import {
|
|
24
28
|
BindResultSchema,
|
|
29
|
+
BindRequestSchema,
|
|
30
|
+
TableFunctionProjectionRequestSchema,
|
|
31
|
+
TableFunctionProjectionResultSchema,
|
|
25
32
|
TableFunctionCardinalityResultSchema,
|
|
26
33
|
TableFunctionDynamicToStringResultSchema,
|
|
27
34
|
} from "../../generated/vgi-protocol-schemas.js";
|
|
@@ -184,7 +191,7 @@ async function resolveSplitPayloads(
|
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
193
|
|
|
187
|
-
/** The per-function lifecycle's `vgi.
|
|
194
|
+
/** The per-function lifecycle's `vgi.v3` handlers. */
|
|
188
195
|
export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService> {
|
|
189
196
|
const { registry, signingKey, catalogInterface } = config;
|
|
190
197
|
|
|
@@ -239,6 +246,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
239
246
|
request.attach_opaque_data = await stripAttach(request.attach_opaque_data, ctx);
|
|
240
247
|
const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
|
|
241
248
|
const response = await func.bind(request);
|
|
249
|
+
validateProjectionOffer(response);
|
|
242
250
|
const serialized = serializeBindResponse(response);
|
|
243
251
|
return wrapResult(serialized, BindResultSchema);
|
|
244
252
|
};
|
|
@@ -410,6 +418,11 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
410
418
|
if (state.userState != null && handlerState?.state !== undefined) {
|
|
411
419
|
handlerState!.state = state.userState;
|
|
412
420
|
}
|
|
421
|
+
// Whether the last reply said more, so only a continuation tick is
|
|
422
|
+
// valid now (functions/continuation.ts).
|
|
423
|
+
if (handlers.continuesOutput) {
|
|
424
|
+
handlerState!.morePending = state.morePending === true;
|
|
425
|
+
}
|
|
413
426
|
}
|
|
414
427
|
|
|
415
428
|
if (state.isProducer && handlers.producerFn) {
|
|
@@ -427,6 +440,11 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
427
440
|
} else if (handlers.exchangeFn) {
|
|
428
441
|
await handlers.exchangeFn(handlerState, input, out);
|
|
429
442
|
}
|
|
443
|
+
// Only a table-in-out exchange can continue its output; anywhere else
|
|
444
|
+
// the client would never send the tick.
|
|
445
|
+
if (!handlers.continuesOutput) {
|
|
446
|
+
refuseMoreOutput(state.functionName, out);
|
|
447
|
+
}
|
|
430
448
|
|
|
431
449
|
// Save mutated user state for the next exchange round
|
|
432
450
|
if (handlerState?.state !== undefined) {
|
|
@@ -435,6 +453,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
435
453
|
// And the dynamic-filter history this turn left (compacted: bounded by
|
|
436
454
|
// the number of predicate ids, not the number of turns).
|
|
437
455
|
state.filterHistory = handlerState?.filterHistory ?? null;
|
|
456
|
+
state.morePending = handlerState?.morePending === true;
|
|
438
457
|
},
|
|
439
458
|
headerInit: (params: any, state: any, ctx: any) => {
|
|
440
459
|
// During init, _initResponse is still in memory.
|
|
@@ -587,7 +606,66 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
|
|
|
587
606
|
return wrapResult({ keys, values }, TableFunctionDynamicToStringResultSchema);
|
|
588
607
|
};
|
|
589
608
|
|
|
609
|
+
const tableFunctionProjection: VgiService["tableFunctionProjection"] = async (
|
|
610
|
+
params,
|
|
611
|
+
) => {
|
|
612
|
+
if (toUint8Array(params.request).length > 8 * 1024 * 1024)
|
|
613
|
+
throw new Error("projection exceeds 8MiB");
|
|
614
|
+
const inner = projectionRecord(toUint8Array(params.request), TableFunctionProjectionRequestSchema);
|
|
615
|
+
const size =
|
|
616
|
+
toUint8Array(inner.bind_call).length +
|
|
617
|
+
toUint8Array(inner.bind_result).length +
|
|
618
|
+
toUint8Array(inner.result_schema).length +
|
|
619
|
+
Array.from(
|
|
620
|
+
inner.expressions as any[],
|
|
621
|
+
(v) => toUint8Array(v).length,
|
|
622
|
+
).reduce((a, b) => a + b, 0);
|
|
623
|
+
if (size > 8 * 1024 * 1024) throw new Error("projection exceeds 8MiB");
|
|
624
|
+
const proposal: ProjectionProposal = {
|
|
625
|
+
bindCall: deserializeBindRequest(
|
|
626
|
+
projectionRecord(toUint8Array(inner.bind_call), BindRequestSchema),
|
|
627
|
+
),
|
|
628
|
+
bindResult: deserializeBindResponse(
|
|
629
|
+
projectionRecord(toUint8Array(inner.bind_result), BindResultSchema),
|
|
630
|
+
),
|
|
631
|
+
expressions: Array.from(inner.expressions as any[], toUint8Array),
|
|
632
|
+
resultSchema: deserializeSchema(toUint8Array(inner.result_schema)),
|
|
633
|
+
};
|
|
634
|
+
validateProjectionProposal(proposal);
|
|
635
|
+
const func = registry.get(
|
|
636
|
+
proposal.bindCall.function_name,
|
|
637
|
+
await strippedContext(proposal.bindCall),
|
|
638
|
+
);
|
|
639
|
+
if (func.kind !== "table")
|
|
640
|
+
throw new Error("projection requires an ordinary table");
|
|
641
|
+
const response = func.projection
|
|
642
|
+
? await func.projection(proposal)
|
|
643
|
+
: { acceptedIndices: [], bindResult: null };
|
|
644
|
+
validateProjectionAcceptance(proposal, response);
|
|
645
|
+
const packed = wrapResult(
|
|
646
|
+
{
|
|
647
|
+
accepted_indices: response.acceptedIndices,
|
|
648
|
+
bind_result: response.bindResult
|
|
649
|
+
? serializeBatch(
|
|
650
|
+
batchFromColumns(
|
|
651
|
+
Object.fromEntries(
|
|
652
|
+
Object.entries(
|
|
653
|
+
serializeBindResponse(response.bindResult),
|
|
654
|
+
).map(([k, v]) => [k, [v]]),
|
|
655
|
+
),
|
|
656
|
+
BindResultSchema,
|
|
657
|
+
),
|
|
658
|
+
)
|
|
659
|
+
: null,
|
|
660
|
+
},
|
|
661
|
+
TableFunctionProjectionResultSchema,
|
|
662
|
+
);
|
|
663
|
+
if (packed.result.length > 8 * 1024 * 1024)
|
|
664
|
+
throw new Error("projection response exceeds 8MiB");
|
|
665
|
+
return packed;
|
|
666
|
+
};
|
|
590
667
|
return {
|
|
668
|
+
tableFunctionProjection,
|
|
591
669
|
bind,
|
|
592
670
|
init,
|
|
593
671
|
tableFunctionCardinality,
|