@query-farm/vgi 0.42.0 → 0.44.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.
Files changed (59) hide show
  1. package/README.md +5 -2
  2. package/dist/attach-ticket.d.ts +18 -7
  3. package/dist/client-entry.js +215 -91
  4. package/dist/client-entry.js.map +10 -9
  5. package/dist/codec/asd.d.ts +3 -1
  6. package/dist/codec/conform.d.ts +51 -0
  7. package/dist/errors.d.ts +5 -1
  8. package/dist/generated/vgi-service.d.ts +1315 -0
  9. package/dist/index.core.d.ts +1 -1
  10. package/dist/index.js +2143 -932
  11. package/dist/index.js.map +29 -28
  12. package/dist/protocol/dispatch.d.ts +14 -5
  13. package/dist/protocol/handlers/aggregate.d.ts +3 -2
  14. package/dist/protocol/handlers/catalog/admin.d.ts +2 -2
  15. package/dist/protocol/handlers/catalog/index.d.ts +3 -2
  16. package/dist/protocol/handlers/catalog/index_methods.d.ts +2 -2
  17. package/dist/protocol/handlers/catalog/macro.d.ts +2 -2
  18. package/dist/protocol/handlers/catalog/shared.d.ts +7 -14
  19. package/dist/protocol/handlers/catalog/table.d.ts +2 -2
  20. package/dist/protocol/handlers/catalog/view.d.ts +2 -2
  21. package/dist/protocol/handlers/function.d.ts +3 -2
  22. package/dist/protocol/handlers/shared.d.ts +2 -2
  23. package/dist/protocol/handlers/table-buffering.d.ts +3 -2
  24. package/dist/protocol/handlers/unimplemented.d.ts +4 -17
  25. package/dist/protocol/serializers/shared.d.ts +2 -1
  26. package/dist/rpc-server.d.ts +2 -2
  27. package/dist/serve-entry.js +2104 -903
  28. package/dist/serve-entry.js.map +25 -24
  29. package/dist/worker-cf-entry.js +2045 -842
  30. package/dist/worker-cf-entry.js.map +29 -28
  31. package/package.json +3 -3
  32. package/src/attach-ticket.ts +41 -13
  33. package/src/catalog/composite.ts +2 -1
  34. package/src/catalog/interface.ts +5 -4
  35. package/src/catalog/read-only.ts +8 -6
  36. package/src/client/client.ts +13 -5
  37. package/src/codec/asd.ts +5 -2
  38. package/src/codec/conform.ts +193 -0
  39. package/src/errors.ts +27 -7
  40. package/src/functions/registry.ts +3 -2
  41. package/src/generated/vgi-service.ts +2678 -0
  42. package/src/http/fetch.ts +1 -1
  43. package/src/index.core.ts +3 -1
  44. package/src/protocol/dispatch.ts +40 -29
  45. package/src/protocol/handlers/aggregate.ts +205 -232
  46. package/src/protocol/handlers/catalog/admin.ts +228 -299
  47. package/src/protocol/handlers/catalog/index.ts +17 -16
  48. package/src/protocol/handlers/catalog/index_methods.ts +26 -36
  49. package/src/protocol/handlers/catalog/macro.ts +54 -77
  50. package/src/protocol/handlers/catalog/shared.ts +30 -47
  51. package/src/protocol/handlers/catalog/table.ts +205 -270
  52. package/src/protocol/handlers/catalog/view.ts +59 -85
  53. package/src/protocol/handlers/function.ts +127 -156
  54. package/src/protocol/handlers/shared.ts +8 -6
  55. package/src/protocol/handlers/table-buffering.ts +53 -71
  56. package/src/protocol/handlers/unimplemented.ts +18 -62
  57. package/src/protocol/serializers/bind.ts +3 -1
  58. package/src/protocol/serializers/shared.ts +5 -2
  59. package/src/rpc-server.ts +7 -7
@@ -1,6 +1,7 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { Protocol } from "@query-farm/vgi-rpc";
2
2
  import type { FunctionRegistry } from "../functions/registry.js";
3
3
  import type { CatalogInterface } from "../catalog/interface.js";
4
+ import { VGI_PROTOCOL_NAME, type VgiService } from "../generated/vgi-service.js";
4
5
  export interface ProtocolConfig {
5
6
  registry: FunctionRegistry;
6
7
  catalogInterface?: CatalogInterface;
@@ -24,7 +25,8 @@ export interface ProtocolConfig {
24
25
  * That matters for this consumer specifically: the DuckDB extension ships to
25
26
  * users and cannot be flag-dayed.
26
27
  *
27
- * Declared rather than derived. Until the transports made the routing key
28
+ * Declared rather than derived, and now generated with the method table
29
+ * (src/generated/vgi-service.ts). Until the transports made the routing key
28
30
  * required, each implementation's wire name defaulted to whatever its local
29
31
  * type was called, which left the six ports disagreeing four ways — Python
30
32
  * `VgiProtocol`, Java and C# `VgiService`, Go the framework default `Service`,
@@ -38,18 +40,25 @@ export interface ProtocolConfig {
38
40
  * so the HTTP entry points build that scope from the same constant the
39
41
  * protocol is registered under rather than a second copy of the literal.
40
42
  */
41
- export declare const VGI_PROTOCOL_NAME = "vgi.v2";
43
+ export { VGI_PROTOCOL_NAME };
42
44
  /**
43
45
  * The `vgi.v2` protocol hash `vgi_rpc.Reflection.v1` must report for this
44
46
  * worker: the reference's (vgi-python 0.43.0, 72 methods). Every SDK hosts
45
47
  * every `vgi.v2` method with the reference's schemas, so the hash is one value
46
48
  * across the ports; a method this SDK does not implement is still registered
47
- * (handlers/unimplemented.ts). The hash covers method names, types and the
48
- * params/result/header schemas only (WIRE_PROTOCOL.md §14).
49
+ * with the generated UNIMPLEMENTED default (src/generated/vgi-service.ts). The
50
+ * hash covers method names, types and the params/result/header schemas only
51
+ * (WIRE_PROTOCOL.md §14).
49
52
  *
50
53
  * It changes only with vgi.v2's protocol version (currently 2.1.0). Asserted
51
54
  * by src/protocol/__tests__/vgi-v2-hash.test.ts; if that test fails, the
52
55
  * surface drifted from the reference -- fix the schemas, do not bump this.
53
56
  */
54
57
  export declare const VGI_V2_PROTOCOL_HASH = "774cb80090d71ea76d09aa311b9cda4ca4c33c3bf72c43242eb6dc87b6f79ce5";
58
+ /**
59
+ * This worker's `vgi.v2` implementation: the generated UNIMPLEMENTED default
60
+ * for every method, overridden by the handler groups for what this SDK serves.
61
+ */
62
+ export declare function buildVgiService(config: ProtocolConfig): VgiService;
63
+ /** The `vgi.v2` protocol, registered from the generated table with {@link buildVgiService}. */
55
64
  export declare function buildVgiProtocol(config: ProtocolConfig): Protocol;
@@ -1,3 +1,4 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../generated/vgi-service.js";
2
2
  import type { FunctionRegistry } from "../../functions/registry.js";
3
- export declare function registerAggregateMethods(protocol: Protocol, registry: FunctionRegistry): void;
3
+ /** The aggregate lifecycle's `vgi.v2` handlers. */
4
+ export declare function aggregateHandlers(registry: FunctionRegistry): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function registerCatalogAdminMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
3
+ export declare function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,4 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
2
1
  import type { CatalogInterface } from "../../../catalog/interface.js";
3
- export declare function registerCatalogMethods(protocol: Protocol, catalog: CatalogInterface | undefined, _catalogName: string | undefined, signingKey?: Uint8Array): void;
2
+ import type { VgiService } from "../../../generated/vgi-service.js";
3
+ /** The catalog_* `vgi.v2` handlers, over *catalog* (or `NoCatalogError` without one). */
4
+ export declare function catalogHandlers(catalog: CatalogInterface | undefined, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function registerCatalogIndexMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
3
+ export declare function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function registerCatalogMacroMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
3
+ export declare function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,5 +1,4 @@
1
- import { type VgiSchema } from "../../../arrow/index.js";
2
- import { Protocol, type AuthContext, type CallContext } from "@query-farm/vgi-rpc";
1
+ import type { AuthContext, CallContext } from "@query-farm/vgi-rpc";
3
2
  import type { CatalogInterface } from "../../../catalog/interface.js";
4
3
  export type GetCatalog = () => CatalogInterface;
5
4
  /**
@@ -40,17 +39,12 @@ export declare function shardKeyForAttach(sealed: Uint8Array | undefined, auth:
40
39
  */
41
40
  export declare function sealTransaction(plaintext: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
42
41
  /**
43
- * Register a catalog unary handler whose request opaque-data fields are
44
- * unwrapped before the handler body runs. Used for every catalog_* method
45
- * except catalog_attach / catalog_transaction_begin, which seal their outputs
46
- * and are registered bespoke.
47
- */
48
- export declare function catalogUnary(protocol: Protocol, signingKey: Uint8Array | undefined, name: string, config: {
49
- params: unknown;
50
- result: unknown;
51
- handler: (params: Record<string, any>, ctx: CallContext) => unknown;
52
- doc?: string;
53
- }): void;
42
+ * Wrap a catalog unary handler so its request opaque-data fields are unwrapped
43
+ * before the body runs. Used for every catalog_* method except catalog_attach
44
+ * / catalog_transaction_begin, which seal their outputs and are written
45
+ * bespoke. The body sees the flattened params as a plain record.
46
+ */
47
+ export declare function catalogHandler<R>(signingKey: Uint8Array | undefined, handler: (params: Record<string, any>, ctx: CallContext) => R | Promise<R>): (params: object, ctx: CallContext) => Promise<R>;
54
48
  export declare function makeGetCatalog(catalog: CatalogInterface | undefined): GetCatalog;
55
49
  /**
56
50
  * Decode the `options` field of a catalog_attach request into a plain
@@ -59,4 +53,3 @@ export declare function makeGetCatalog(catalog: CatalogInterface | undefined): G
59
53
  * one row with the value. Returns `{}` for null / empty input.
60
54
  */
61
55
  export declare function decodeOptionsBatch(bytes: any): Record<string, unknown>;
62
- export declare const emptyResultSchema: VgiSchema;
@@ -1,3 +1,3 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function registerCatalogTableMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
3
+ export declare function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function registerCatalogViewMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
3
+ export declare function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,4 +1,4 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import { type VgiService } from "../../generated/vgi-service.js";
2
2
  import type { FunctionRegistry } from "../../functions/registry.js";
3
3
  export interface FunctionHandlerConfig {
4
4
  registry: FunctionRegistry;
@@ -23,4 +23,5 @@ export interface FunctionHandlerConfig {
23
23
  version?(attach: Uint8Array, txn?: Uint8Array): number | Promise<number>;
24
24
  };
25
25
  }
26
- export declare function registerFunctionMethods(protocol: Protocol, config: FunctionHandlerConfig): void;
26
+ /** The per-function lifecycle's `vgi.v2` handlers. */
27
+ export declare function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService>;
@@ -2,7 +2,6 @@ import { type VgiSchema } from "../../arrow/index.js";
2
2
  import type { OverloadContext } from "../../functions/registry.js";
3
3
  export declare const RESULT_BINARY_SCHEMA: VgiSchema;
4
4
  export declare const REQUEST_PARAMS_SCHEMA: VgiSchema;
5
- export declare const RESULT_BINARY_NULLABLE_SCHEMA: VgiSchema;
6
5
  /**
7
6
  * Unwrap a "request" Binary column: deserialize the inner Arrow IPC batch
8
7
  * and return flat columns as a dict (row 0).
@@ -12,7 +11,8 @@ export declare function unwrapRequest(requestBytes: any): Record<string, any>;
12
11
  export declare function normalizeRequestSchemaPaths(params: Record<string, any>): void;
13
12
  /**
14
13
  * Wrap a dict of values into a single "result" Binary column.
15
- * Builds a 1-row batch from the values using the given schema,
14
+ * Builds a 1-row batch from the values using the given schema (conformed to
15
+ * the protocol's container rules, see `conformRecord`),
16
16
  * serializes it to IPC bytes, and returns { result: bytes }.
17
17
  */
18
18
  export declare function wrapResult(values: Record<string, any>, innerSchema: VgiSchema | import("../../arrow/index.js").VgiSchema): {
@@ -1,3 +1,4 @@
1
- import { Protocol } from "@query-farm/vgi-rpc";
1
+ import type { VgiService } from "../../generated/vgi-service.js";
2
2
  import type { FunctionRegistry } from "../../functions/registry.js";
3
- export declare function registerTableBufferingMethods(protocol: Protocol, registry: FunctionRegistry, signingKey?: Uint8Array): void;
3
+ /** The table_buffering lifecycle's `vgi.v2` handlers. */
4
+ export declare function tableBufferingHandlers(registry: FunctionRegistry, signingKey?: Uint8Array): Partial<VgiService>;
@@ -1,17 +1,4 @@
1
- import { type Protocol } from "@query-farm/vgi-rpc";
2
- import type { VgiSchema } from "../../arrow/index.js";
3
- /** One unimplemented method: its wire name and the reference's schemas. */
4
- interface UnimplementedMethod {
5
- readonly name: string;
6
- readonly params: VgiSchema;
7
- readonly result: VgiSchema;
8
- }
9
- /**
10
- * The vgi.v2 methods (of the reference's 72) this SDK does not implement.
11
- * Exported so a test can assert each one refuses with UNIMPLEMENTED.
12
- */
13
- export declare const UNIMPLEMENTED_METHODS: readonly UnimplementedMethod[];
14
- /** The message every unimplemented method answers with. */
15
- export declare function unimplementedMessage(method: string): string;
16
- export declare function registerUnimplementedMethods(protocol: Protocol): void;
17
- export {};
1
+ import { type VgiMethodSpec } from "../../generated/vgi-service.js";
2
+ export { unimplementedMessage } from "../../generated/vgi-service.js";
3
+ /** The vgi.v2 methods (of the reference's 72) this SDK leaves at the generated default. */
4
+ export declare const UNIMPLEMENTED_METHODS: readonly VgiMethodSpec[];
@@ -7,6 +7,7 @@ import { type VgiSchema, type VgiBatch } from "../../arrow/index.js";
7
7
  export declare function toUint8Array(val: any): Uint8Array;
8
8
  /**
9
9
  * Build a single-row RecordBatch from a {fieldName: value} dict matching the
10
- * given schema. Auto-coerces JS numbers to BigInt for Int64 fields.
10
+ * given schema. Auto-coerces JS numbers to BigInt for Int64 fields, and
11
+ * applies the protocol's container rules (`conformRecord`).
11
12
  */
12
13
  export declare function buildSingleRowBatch(schema: VgiSchema, values: Record<string, any>): VgiBatch;
@@ -31,13 +31,13 @@ export interface HostingOptions {
31
31
  *
32
32
  * Each needs a distinct wire name, which may not be `vgi.v2` and may not
33
33
  * use the reserved `vgi_rpc.` prefix: reflection is hosted automatically and
34
- * `vgi_rpc.Identity.v1` is enabled through {@link resolveToken} /
34
+ * `vgi_rpc.Identity.v2` is enabled through {@link resolveToken} /
35
35
  * {@link mintGrant}. Violations are a startup error naming this hook.
36
36
  */
37
37
  hostedProtocols?: () => Iterable<Protocol>;
38
38
  /**
39
39
  * Resolve an opaque bearer credential to the identity it authenticates as.
40
- * Supplying it hosts `vgi_rpc.Identity.v1`'s `introspect_token` -- on HTTP,
40
+ * Supplying it hosts `vgi_rpc.Identity.v2`'s `introspect_token` -- on HTTP,
41
41
  * the transport that authenticates callers. Absent, the method is absent
42
42
  * (not hosted-and-refusing), which keeps a dependency upgrade from growing a
43
43
  * credential-to-identity oracle on every existing worker.