@query-farm/vgi 0.6.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 (206) hide show
  1. package/LICENSE +134 -0
  2. package/README.md +494 -0
  3. package/dist/__dbg.test-d.d.ts +1 -0
  4. package/dist/arguments/argument-spec.d.ts +51 -0
  5. package/dist/arguments/arguments.d.ts +13 -0
  6. package/dist/arrow/codec/branded.d.ts +83 -0
  7. package/dist/arrow/codec/registry.d.ts +29 -0
  8. package/dist/arrow/codec/repr.d.ts +23 -0
  9. package/dist/arrow/codec/type-descriptors.d.ts +109 -0
  10. package/dist/arrow/impl-arrowjs/build.d.ts +19 -0
  11. package/dist/arrow/impl-arrowjs/canonical.d.ts +15 -0
  12. package/dist/arrow/impl-arrowjs/empty.d.ts +7 -0
  13. package/dist/arrow/impl-arrowjs/filter.d.ts +11 -0
  14. package/dist/arrow/impl-arrowjs/index.d.ts +11 -0
  15. package/dist/arrow/impl-arrowjs/ipc.d.ts +24 -0
  16. package/dist/arrow/impl-arrowjs/iterate.d.ts +39 -0
  17. package/dist/arrow/impl-arrowjs/project.d.ts +10 -0
  18. package/dist/arrow/impl-arrowjs/schema.d.ts +62 -0
  19. package/dist/arrow/impl-arrowjs/statistics.d.ts +13 -0
  20. package/dist/arrow/impl-flechette/build.d.ts +14 -0
  21. package/dist/arrow/impl-flechette/canonical.d.ts +18 -0
  22. package/dist/arrow/impl-flechette/empty.d.ts +9 -0
  23. package/dist/arrow/impl-flechette/filter.d.ts +10 -0
  24. package/dist/arrow/impl-flechette/index.d.ts +11 -0
  25. package/dist/arrow/impl-flechette/ipc.d.ts +33 -0
  26. package/dist/arrow/impl-flechette/iterate.d.ts +29 -0
  27. package/dist/arrow/impl-flechette/message-meta.d.ts +10 -0
  28. package/dist/arrow/impl-flechette/normalize-type.d.ts +11 -0
  29. package/dist/arrow/impl-flechette/project.d.ts +3 -0
  30. package/dist/arrow/impl-flechette/schema.d.ts +47 -0
  31. package/dist/arrow/impl-flechette/statistics.d.ts +13 -0
  32. package/dist/arrow/index.d.ts +11 -0
  33. package/dist/arrow/predicates.d.ts +47 -0
  34. package/dist/arrow/repr.test-d.d.ts +52 -0
  35. package/dist/arrow/schema-types.d.ts +71 -0
  36. package/dist/arrow/types.d.ts +57 -0
  37. package/dist/catalog/attach-option.d.ts +33 -0
  38. package/dist/catalog/attach-options.d.ts +30 -0
  39. package/dist/catalog/composite.d.ts +33 -0
  40. package/dist/catalog/descriptors.d.ts +154 -0
  41. package/dist/catalog/interface.d.ts +239 -0
  42. package/dist/catalog/read-only.d.ts +33 -0
  43. package/dist/client/client.d.ts +189 -0
  44. package/dist/client/errors.d.ts +26 -0
  45. package/dist/client/helpers.d.ts +12 -0
  46. package/dist/client/protocol.d.ts +16 -0
  47. package/dist/client/types.d.ts +125 -0
  48. package/dist/client-entry.d.ts +11 -0
  49. package/dist/client-entry.js +48 -0
  50. package/dist/client-entry.js.map +9 -0
  51. package/dist/codec/asd.d.ts +25 -0
  52. package/dist/crypto.d.ts +36 -0
  53. package/dist/errors.d.ts +24 -0
  54. package/dist/filter-pushdown/collector.d.ts +32 -0
  55. package/dist/filter-pushdown/deserialize.d.ts +16 -0
  56. package/dist/filter-pushdown/evaluate.d.ts +51 -0
  57. package/dist/filter-pushdown/index.d.ts +4 -0
  58. package/dist/filter-pushdown/types.d.ts +84 -0
  59. package/dist/functions/aggregate.d.ts +129 -0
  60. package/dist/functions/copy-from.d.ts +81 -0
  61. package/dist/functions/copy-to.d.ts +121 -0
  62. package/dist/functions/registry.d.ts +16 -0
  63. package/dist/functions/scalar.d.ts +98 -0
  64. package/dist/functions/storage-cf-do.d.ts +47 -0
  65. package/dist/functions/storage.d.ts +86 -0
  66. package/dist/functions/table-buffering.d.ts +99 -0
  67. package/dist/functions/table-in-out.d.ts +64 -0
  68. package/dist/functions/table.d.ts +118 -0
  69. package/dist/functions/types.d.ts +157 -0
  70. package/dist/generated/vgi-client.d.ts +466 -0
  71. package/dist/generated/vgi-protocol-schemas.d.ts +115 -0
  72. package/dist/index.core.d.ts +42 -0
  73. package/dist/index.d.ts +2 -0
  74. package/dist/index.js +10888 -0
  75. package/dist/index.js.map +85 -0
  76. package/dist/metadata/resolve.d.ts +3 -0
  77. package/dist/metadata/serialize.d.ts +12 -0
  78. package/dist/metadata/types.d.ts +47 -0
  79. package/dist/protocol/dispatch.d.ts +23 -0
  80. package/dist/protocol/handlers/aggregate.d.ts +3 -0
  81. package/dist/protocol/handlers/catalog/admin.d.ts +3 -0
  82. package/dist/protocol/handlers/catalog/index.d.ts +3 -0
  83. package/dist/protocol/handlers/catalog/index_methods.d.ts +3 -0
  84. package/dist/protocol/handlers/catalog/macro.d.ts +3 -0
  85. package/dist/protocol/handlers/catalog/shared.d.ts +70 -0
  86. package/dist/protocol/handlers/catalog/table.d.ts +3 -0
  87. package/dist/protocol/handlers/catalog/view.d.ts +3 -0
  88. package/dist/protocol/handlers/function.d.ts +8 -0
  89. package/dist/protocol/handlers/shared.d.ts +31 -0
  90. package/dist/protocol/handlers/table-buffering.d.ts +3 -0
  91. package/dist/protocol/serialize.d.ts +4 -0
  92. package/dist/protocol/serializers/arguments.d.ts +3 -0
  93. package/dist/protocol/serializers/bind.d.ts +9 -0
  94. package/dist/protocol/serializers/cardinality.d.ts +7 -0
  95. package/dist/protocol/serializers/init.d.ts +9 -0
  96. package/dist/protocol/serializers/shared.d.ts +12 -0
  97. package/dist/protocol/state-serializer.d.ts +23 -0
  98. package/dist/protocol/types.d.ts +129 -0
  99. package/dist/secrets/helpers.d.ts +15 -0
  100. package/dist/types.d.ts +52 -0
  101. package/dist/util/arrow/index.d.ts +1 -0
  102. package/dist/util/bytes.d.ts +2 -0
  103. package/dist/util/statistics.d.ts +7 -0
  104. package/dist/worker-cf-entry.d.ts +30 -0
  105. package/dist/worker-cf-entry.js +8767 -0
  106. package/dist/worker-cf-entry.js.map +74 -0
  107. package/dist/worker.d.ts +36 -0
  108. package/package.json +96 -0
  109. package/src/arguments/argument-spec.ts +200 -0
  110. package/src/arguments/arguments.ts +81 -0
  111. package/src/arrow/codec/branded.ts +206 -0
  112. package/src/arrow/codec/registry.ts +674 -0
  113. package/src/arrow/codec/repr.ts +181 -0
  114. package/src/arrow/codec/type-descriptors.ts +137 -0
  115. package/src/arrow/impl-arrowjs/build.ts +88 -0
  116. package/src/arrow/impl-arrowjs/canonical.ts +509 -0
  117. package/src/arrow/impl-arrowjs/empty.ts +72 -0
  118. package/src/arrow/impl-arrowjs/filter.ts +53 -0
  119. package/src/arrow/impl-arrowjs/index.ts +54 -0
  120. package/src/arrow/impl-arrowjs/ipc.ts +67 -0
  121. package/src/arrow/impl-arrowjs/iterate.ts +159 -0
  122. package/src/arrow/impl-arrowjs/project.ts +73 -0
  123. package/src/arrow/impl-arrowjs/schema.ts +256 -0
  124. package/src/arrow/impl-arrowjs/statistics.ts +185 -0
  125. package/src/arrow/impl-flechette/build.ts +65 -0
  126. package/src/arrow/impl-flechette/canonical.ts +289 -0
  127. package/src/arrow/impl-flechette/empty.ts +20 -0
  128. package/src/arrow/impl-flechette/filter.ts +42 -0
  129. package/src/arrow/impl-flechette/index.ts +54 -0
  130. package/src/arrow/impl-flechette/ipc.ts +110 -0
  131. package/src/arrow/impl-flechette/iterate.ts +121 -0
  132. package/src/arrow/impl-flechette/message-meta.ts +175 -0
  133. package/src/arrow/impl-flechette/normalize-type.ts +99 -0
  134. package/src/arrow/impl-flechette/project.ts +64 -0
  135. package/src/arrow/impl-flechette/schema.ts +202 -0
  136. package/src/arrow/impl-flechette/statistics.ts +198 -0
  137. package/src/arrow/index.ts +129 -0
  138. package/src/arrow/predicates.ts +66 -0
  139. package/src/arrow/repr.test-d.ts +189 -0
  140. package/src/arrow/schema-types.ts +213 -0
  141. package/src/arrow/types.ts +74 -0
  142. package/src/catalog/attach-option.ts +107 -0
  143. package/src/catalog/attach-options.ts +79 -0
  144. package/src/catalog/composite.ts +180 -0
  145. package/src/catalog/descriptors.ts +164 -0
  146. package/src/catalog/interface.ts +721 -0
  147. package/src/catalog/read-only.ts +909 -0
  148. package/src/client/client.ts +1348 -0
  149. package/src/client/errors.ts +69 -0
  150. package/src/client/helpers.ts +56 -0
  151. package/src/client/protocol.ts +33 -0
  152. package/src/client/types.ts +140 -0
  153. package/src/client-entry.ts +112 -0
  154. package/src/codec/asd.ts +147 -0
  155. package/src/crypto.ts +143 -0
  156. package/src/errors.ts +61 -0
  157. package/src/filter-pushdown/collector.ts +147 -0
  158. package/src/filter-pushdown/deserialize.ts +253 -0
  159. package/src/filter-pushdown/evaluate.ts +591 -0
  160. package/src/filter-pushdown/index.ts +28 -0
  161. package/src/filter-pushdown/types.ts +91 -0
  162. package/src/functions/aggregate.ts +384 -0
  163. package/src/functions/copy-from.ts +282 -0
  164. package/src/functions/copy-to.ts +319 -0
  165. package/src/functions/registry.ts +258 -0
  166. package/src/functions/scalar.ts +356 -0
  167. package/src/functions/storage-cf-do.ts +303 -0
  168. package/src/functions/storage.ts +521 -0
  169. package/src/functions/table-buffering.ts +562 -0
  170. package/src/functions/table-in-out.ts +373 -0
  171. package/src/functions/table.ts +521 -0
  172. package/src/functions/types.ts +192 -0
  173. package/src/generated/vgi-client.ts +560 -0
  174. package/src/generated/vgi-protocol-schemas.ts +864 -0
  175. package/src/index.core.ts +267 -0
  176. package/src/index.ts +11 -0
  177. package/src/metadata/resolve.ts +109 -0
  178. package/src/metadata/serialize.ts +242 -0
  179. package/src/metadata/types.ts +60 -0
  180. package/src/protocol/dispatch.ts +52 -0
  181. package/src/protocol/handlers/aggregate.ts +355 -0
  182. package/src/protocol/handlers/catalog/admin.ts +368 -0
  183. package/src/protocol/handlers/catalog/index.ts +25 -0
  184. package/src/protocol/handlers/catalog/index_methods.ts +65 -0
  185. package/src/protocol/handlers/catalog/macro.ts +114 -0
  186. package/src/protocol/handlers/catalog/shared.ts +291 -0
  187. package/src/protocol/handlers/catalog/table.ts +401 -0
  188. package/src/protocol/handlers/catalog/view.ts +119 -0
  189. package/src/protocol/handlers/function.ts +302 -0
  190. package/src/protocol/handlers/shared.ts +80 -0
  191. package/src/protocol/handlers/table-buffering.ts +207 -0
  192. package/src/protocol/serialize.ts +23 -0
  193. package/src/protocol/serializers/arguments.ts +160 -0
  194. package/src/protocol/serializers/bind.ts +212 -0
  195. package/src/protocol/serializers/cardinality.ts +45 -0
  196. package/src/protocol/serializers/init.ts +247 -0
  197. package/src/protocol/serializers/shared.ts +46 -0
  198. package/src/protocol/state-serializer.ts +181 -0
  199. package/src/protocol/types.ts +153 -0
  200. package/src/secrets/helpers.ts +70 -0
  201. package/src/types.ts +71 -0
  202. package/src/util/arrow/index.ts +23 -0
  203. package/src/util/bytes.ts +14 -0
  204. package/src/util/statistics.ts +40 -0
  205. package/src/worker-cf-entry.ts +172 -0
  206. package/src/worker.ts +212 -0
@@ -0,0 +1,3 @@
1
+ import type { VgiFunction } from "../functions/types.js";
2
+ import { type ResolvedMetadata } from "./types.js";
3
+ export declare function resolveMetadata(func: VgiFunction): ResolvedMetadata;
@@ -0,0 +1,12 @@
1
+ import { type VgiBatch } from "../arrow/index.js";
2
+ import type { ResolvedMetadata } from "./types.js";
3
+ declare const METADATA_SCHEMA: import("../index.core.js").VgiSchema;
4
+ export { METADATA_SCHEMA };
5
+ /**
6
+ * Serialize multiple ResolvedMetadata to a single Arrow RecordBatch.
7
+ */
8
+ export declare function metadatasToArrow(metadatas: ResolvedMetadata[]): VgiBatch;
9
+ /**
10
+ * Deserialize Arrow RecordBatch to ResolvedMetadata array.
11
+ */
12
+ export declare function arrowToMetadatas(batch: VgiBatch): ResolvedMetadata[];
@@ -0,0 +1,47 @@
1
+ import { FunctionStability, NullHandling, OrderPreservation, OrderDependence, DistinctDependence } from "../types.js";
2
+ export declare enum CatalogFunctionType {
3
+ SCALAR = "SCALAR",
4
+ TABLE = "TABLE",
5
+ TABLE_BUFFERING = "TABLE_BUFFERING",
6
+ AGGREGATE = "AGGREGATE"
7
+ }
8
+ export interface ParameterInfo {
9
+ name: string;
10
+ position: number | null;
11
+ positionName: string | null;
12
+ typeName: string | null;
13
+ description: string;
14
+ required: boolean;
15
+ default: string | null;
16
+ constraints: string | null;
17
+ isTableInput: boolean;
18
+ isVarargs: boolean;
19
+ isConst: boolean;
20
+ }
21
+ export interface FunctionExample {
22
+ sql: string;
23
+ description: string;
24
+ expectedOutput: string | null;
25
+ }
26
+ export interface ResolvedMetadata {
27
+ name: string;
28
+ className: string;
29
+ functionType: CatalogFunctionType;
30
+ description: string;
31
+ examples: FunctionExample[];
32
+ categories: string[];
33
+ tags: Record<string, string>;
34
+ parameters: ParameterInfo[];
35
+ stability: FunctionStability;
36
+ nullHandling: NullHandling;
37
+ requiredSettings: string[];
38
+ requiredSecrets: string[];
39
+ projectionPushdown: boolean;
40
+ filterPushdown: boolean;
41
+ samplingPushdown: boolean;
42
+ supportedExpressionFilters: string[];
43
+ preservesOrder: OrderPreservation;
44
+ maxWorkers: number | null;
45
+ orderDependent: OrderDependence;
46
+ distinctDependent: DistinctDependence;
47
+ }
@@ -0,0 +1,23 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import type { FunctionRegistry } from "../functions/registry.js";
3
+ import type { CatalogInterface } from "../catalog/interface.js";
4
+ export interface ProtocolConfig {
5
+ registry: FunctionRegistry;
6
+ catalogInterface?: CatalogInterface;
7
+ catalogName?: string;
8
+ /**
9
+ * Recover accumulated exchange state from FINALIZE init_opaque_data.
10
+ * For HTTP transport, this unpacks the state token that the C++ extension
11
+ * passes from the last INPUT exchange to the FINALIZE init request.
12
+ * Returns the deserialized VGI dispatch state object (with userState field).
13
+ */
14
+ recoverExchangeState?: (opaqueData: Uint8Array) => any;
15
+ /**
16
+ * AEAD signing key for sealing catalog opaque-data envelopes. Pass the same
17
+ * 32-byte key used for HTTP state tokens. When omitted (subprocess / unix
18
+ * transports) attach_opaque_data / transaction_opaque_data pass through
19
+ * unsealed — OS process ownership already enforces identity there.
20
+ */
21
+ signingKey?: Uint8Array;
22
+ }
23
+ export declare function buildVgiProtocol(config: ProtocolConfig): Protocol;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import type { FunctionRegistry } from "../../functions/registry.js";
3
+ export declare function registerAggregateMethods(protocol: Protocol, registry: FunctionRegistry): void;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import { type GetCatalog } from "./shared.js";
3
+ export declare function registerCatalogAdminMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import type { CatalogInterface } from "../../../catalog/interface.js";
3
+ export declare function registerCatalogMethods(protocol: Protocol, catalog: CatalogInterface | undefined, _catalogName: string | undefined, signingKey?: Uint8Array): void;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import { type GetCatalog } from "./shared.js";
3
+ export declare function registerCatalogIndexMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import { type GetCatalog } from "./shared.js";
3
+ export declare function registerCatalogMacroMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
@@ -0,0 +1,70 @@
1
+ import { type VgiSchema } from "../../../arrow/index.js";
2
+ import { Protocol, type AuthContext, type CallContext } from "@query-farm/vgi-rpc";
3
+ import type { CatalogInterface } from "../../../catalog/interface.js";
4
+ export type GetCatalog = () => CatalogInterface;
5
+ /**
6
+ * Mint and seal a catalog_attach value: prepend a fresh framework UUID
7
+ * (uuid(16) || catalog_bytes), then seal. Storage shards on the UUID — stable
8
+ * across re-seals and globally unique, unlike the random-nonce ciphertext or
9
+ * the (possibly non-unique) catalog bytes. openAttach strips the UUID back off
10
+ * so the catalog only ever sees its own bytes. Mirrors vgi-python/-go.
11
+ */
12
+ export declare function sealAttach(plaintext: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
13
+ /**
14
+ * Open an attach envelope returning the FULL framework plaintext
15
+ * uuid(16) || catalog_bytes (not stripped). Storage shards on the leading UUID.
16
+ */
17
+ export declare function openAttachFull(envelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
18
+ /**
19
+ * Open an attach_opaque_data envelope, returning the catalog's own bytes — the
20
+ * framework UUID prefix is stripped. This is what catalog/function bodies see;
21
+ * storage routing uses openAttachFull / deriveShardKey to reach the UUID.
22
+ */
23
+ export declare function openAttach(envelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
24
+ /**
25
+ * deriveShardKey returns the Cloudflare-DO routing key for an attach:
26
+ * "att-" + hex(the 16-byte framework UUID at the head of the unwrapped attach).
27
+ * One DO per logical ATTACH. Throws if the uuid is not 16 bytes (the storage
28
+ * path is always bound to a logical ATTACH).
29
+ */
30
+ export declare function deriveShardKey(attachUuid: Uint8Array): string;
31
+ /**
32
+ * shardKeyForAttach unwraps the sealed attach and derives its shard key. An
33
+ * empty/absent attach yields "" (non-sharding backends ignore the key; the
34
+ * CfDo backend rejects an empty key server-side, the "must not happen" case).
35
+ */
36
+ export declare function shardKeyForAttach(sealed: Uint8Array | undefined, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<string>;
37
+ /**
38
+ * Seal a plaintext transaction value (catalog_transaction_begin output), bound
39
+ * to the caller's identity and the parent attach envelope it was minted under.
40
+ */
41
+ export declare function sealTransaction(plaintext: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
42
+ /**
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;
54
+ export declare function makeGetCatalog(catalog: CatalogInterface | undefined): GetCatalog;
55
+ /**
56
+ * Decode the `options` field of a catalog_attach request into a plain
57
+ * {name: value} dict. The wire field is either null (no options) or an
58
+ * IPC-serialized RecordBatch of typed columns — one column per option,
59
+ * one row with the value. Returns `{}` for null / empty input.
60
+ */
61
+ export declare function decodeOptionsBatch(bytes: any): Record<string, unknown>;
62
+ export declare const emptyResultSchema: VgiSchema;
63
+ export declare const attachOpaqueDataParam: VgiSchema;
64
+ export declare const attachOpaqueDataTxnParams: VgiSchema;
65
+ export declare const attachOpaqueDataNameTxnParams: VgiSchema;
66
+ export declare const attachOpaqueDataSchemaNameTxnParams: VgiSchema;
67
+ export declare const schemaNameIgnoreNotFoundTxnParams: VgiSchema;
68
+ export declare const schemaNameCommentParams: VgiSchema;
69
+ export declare const schemaNameRenameParams: VgiSchema;
70
+ export declare const columnOpParams: VgiSchema;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import { type GetCatalog } from "./shared.js";
3
+ export declare function registerCatalogTableMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import { type GetCatalog } from "./shared.js";
3
+ export declare function registerCatalogViewMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void;
@@ -0,0 +1,8 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import type { FunctionRegistry } from "../../functions/registry.js";
3
+ export interface FunctionHandlerConfig {
4
+ registry: FunctionRegistry;
5
+ recoverExchangeState?: (opaqueData: Uint8Array) => any;
6
+ signingKey?: Uint8Array;
7
+ }
8
+ export declare function registerFunctionMethods(protocol: Protocol, config: FunctionHandlerConfig): void;
@@ -0,0 +1,31 @@
1
+ import { type VgiSchema } from "../../arrow/index.js";
2
+ import type { OverloadContext } from "../../functions/registry.js";
3
+ import type { InitRequest } from "../types.js";
4
+ export declare const RESULT_BINARY_SCHEMA: VgiSchema;
5
+ export declare const REQUEST_PARAMS_SCHEMA: VgiSchema;
6
+ export declare const RESULT_BINARY_NULLABLE_SCHEMA: VgiSchema;
7
+ /**
8
+ * Unwrap a "request" Binary column: deserialize the inner Arrow IPC batch
9
+ * and return flat columns as a dict (row 0).
10
+ */
11
+ export declare function unwrapRequest(requestBytes: any): Record<string, any>;
12
+ /**
13
+ * Wrap a dict of values into a single "result" Binary column.
14
+ * Builds a 1-row batch from the values using the given schema,
15
+ * serializes it to IPC bytes, and returns { result: bytes }.
16
+ */
17
+ export declare function wrapResult(values: Record<string, any>, innerSchema: VgiSchema | import("../../arrow/index.js").VgiSchema): {
18
+ result: Uint8Array;
19
+ };
20
+ export declare function overloadContext(req: {
21
+ function_name: string;
22
+ arguments: any;
23
+ input_schema: any;
24
+ function_type: any;
25
+ }): OverloadContext;
26
+ /**
27
+ * Recover accumulated exchange state from a FINALIZE init request.
28
+ * For HTTP transport, this unpacks the state token that the C++ extension
29
+ * passes from the last INPUT exchange to the FINALIZE init request.
30
+ */
31
+ export declare function recoverFinalizeState(request: InitRequest, recoverExchangeState: ((opaqueData: Uint8Array) => any) | undefined): any;
@@ -0,0 +1,3 @@
1
+ import { Protocol } from "@query-farm/vgi-rpc";
2
+ import type { FunctionRegistry } from "../../functions/registry.js";
3
+ export declare function registerTableBufferingMethods(protocol: Protocol, registry: FunctionRegistry, signingKey?: Uint8Array): void;
@@ -0,0 +1,4 @@
1
+ export { serializeArguments, deserializeArguments } from "./serializers/arguments.js";
2
+ export { serializeBindRequest, deserializeBindRequest, serializeBindResponse, deserializeBindResponse, } from "./serializers/bind.js";
3
+ export { serializeInitRequest, deserializeInitRequest, serializeGlobalInitResponse, deserializeGlobalInitResponse, } from "./serializers/init.js";
4
+ export { deserializeCardinalityRequest, serializeTableCardinality, } from "./serializers/cardinality.js";
@@ -0,0 +1,3 @@
1
+ import { Arguments } from "../../arguments/arguments.js";
2
+ export declare function serializeArguments(args: Arguments): Uint8Array;
3
+ export declare function deserializeArguments(bytes: Uint8Array): Arguments;
@@ -0,0 +1,9 @@
1
+ import { type VgiSchema, type VgiBatch } from "../../arrow/index.js";
2
+ import type { BindRequest, BindResponse } from "../types.js";
3
+ declare const BIND_REQUEST_SCHEMA: VgiSchema;
4
+ declare const BIND_RESPONSE_SCHEMA: VgiSchema;
5
+ export declare function serializeBindRequest(req: BindRequest): VgiBatch;
6
+ export declare function deserializeBindRequest(params: Record<string, any>): BindRequest;
7
+ export declare function serializeBindResponse(resp: BindResponse): Record<string, any>;
8
+ export declare function deserializeBindResponse(params: Record<string, any>): BindResponse;
9
+ export { BIND_REQUEST_SCHEMA, BIND_RESPONSE_SCHEMA };
@@ -0,0 +1,7 @@
1
+ import { type VgiSchema } from "../../arrow/index.js";
2
+ import type { TableFunctionCardinalityRequest, TableCardinality } from "../types.js";
3
+ declare const TABLE_CARDINALITY_SCHEMA: VgiSchema;
4
+ declare const TABLE_FUNCTION_CARDINALITY_REQUEST_SCHEMA: VgiSchema;
5
+ export declare function deserializeCardinalityRequest(params: Record<string, any>): TableFunctionCardinalityRequest;
6
+ export declare function serializeTableCardinality(card: TableCardinality): Record<string, any>;
7
+ export { TABLE_CARDINALITY_SCHEMA, TABLE_FUNCTION_CARDINALITY_REQUEST_SCHEMA };
@@ -0,0 +1,9 @@
1
+ import { type VgiBatch } from "../../arrow/index.js";
2
+ import { type InitRequest, type GlobalInitResponse } from "../types.js";
3
+ declare const INIT_REQUEST_SCHEMA: import("../../index.core.js").VgiSchema;
4
+ declare const GLOBAL_INIT_RESPONSE_SCHEMA: import("../../index.core.js").VgiSchema;
5
+ export declare function serializeInitRequest(req: InitRequest): VgiBatch;
6
+ export declare function deserializeInitRequest(params: Record<string, any>): InitRequest;
7
+ export declare function serializeGlobalInitResponse(resp: GlobalInitResponse): Record<string, any>;
8
+ export declare function deserializeGlobalInitResponse(params: Record<string, any>): GlobalInitResponse;
9
+ export { INIT_REQUEST_SCHEMA, GLOBAL_INIT_RESPONSE_SCHEMA };
@@ -0,0 +1,12 @@
1
+ import { type VgiSchema, type VgiBatch } from "../../arrow/index.js";
2
+ /**
3
+ * Coerce a wire value (string / Uint8Array / Buffer / etc.) to a Uint8Array.
4
+ * Throws when the input is non-null but produces zero bytes — that signals a
5
+ * truly unsupported shape, distinct from a legitimate empty Uint8Array.
6
+ */
7
+ export declare function toUint8Array(val: any): Uint8Array;
8
+ /**
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.
11
+ */
12
+ export declare function buildSingleRowBatch(schema: VgiSchema, values: Record<string, any>): VgiBatch;
@@ -0,0 +1,23 @@
1
+ import { type VgiDataType } from "../arrow/index.js";
2
+ import type { StateSerializer } from "@query-farm/vgi-rpc";
3
+ /** Schema for the exchange state carried in HTTP state tokens. */
4
+ export declare const EXCHANGE_STATE_SCHEMA: import("../index.core.js").VgiSchema;
5
+ /** Infer an Arrow DataType from a JS value for user state serialization. */
6
+ export declare function inferFieldType(value: any): VgiDataType;
7
+ /**
8
+ * Serialize userState to Arrow IPC bytes.
9
+ * Infers schema from the JS object at runtime. Arrow IPC is self-describing,
10
+ * so deserialization doesn't need the schema ahead of time.
11
+ *
12
+ * For an empty object `{}`, we emit a 0-row batch with empty schema —
13
+ * `deserializeUserState` recognizes that shape and returns `{}` rather than
14
+ * `null`. (`null` is reserved for "no userState declared at all".)
15
+ */
16
+ export declare function serializeUserState(userState: any): Uint8Array | null;
17
+ /**
18
+ * Deserialize userState from Arrow IPC bytes.
19
+ * Reconstructs a plain JS object, preserving BigInt for Int64 columns.
20
+ */
21
+ export declare function deserializeUserState(bytes: Uint8Array | null): any;
22
+ /** Arrow IPC state serializer — stores all data as native binary columns. */
23
+ export declare const arrowStateSerializer: StateSerializer;
@@ -0,0 +1,129 @@
1
+ import type { VgiSchema, VgiBatch } from "../arrow/index.js";
2
+ import type { Arguments } from "../arguments/arguments.js";
3
+ import { FunctionType, TableInOutPhase, type TableCardinality } from "../types.js";
4
+ /**
5
+ * Context for a `COPY ... FROM` read, threaded onto {@link BindRequest}.
6
+ *
7
+ * Present only when the bind/init opens a COPY-FROM scan (`null`/absent
8
+ * otherwise — set by the VGI extension's `copy_from_bind`). `InitRequest`
9
+ * embeds the same `BindRequest` as `bind_call`, so process()/init also reach it
10
+ * via `initCall.bind_call.copy_from`. The handler's options arrive through the
11
+ * normal `BindRequest.arguments` (built from the COPY options), so they are not
12
+ * duplicated here. Mirrors vgi-python's `protocol.CopyFromContext`.
13
+ */
14
+ export interface CopyFromContext {
15
+ /** The `FORMAT` name resolved at COPY bind time. */
16
+ format: string;
17
+ /** The source path from the `COPY ... FROM 'path'` statement. */
18
+ file_path: string;
19
+ /**
20
+ * The COPY target's column schema (name + type, in target order). The worker
21
+ * must bind its output to, and emit columns whose types match, this schema
22
+ * exactly — DuckDB inserts no cast between the scan and the INSERT. Holds the
23
+ * parsed Arrow Schema (the wire field is binary; deserialized here).
24
+ */
25
+ expected_schema: VgiSchema;
26
+ }
27
+ /**
28
+ * Context for a `COPY ... TO` write, threaded onto {@link BindRequest}.
29
+ *
30
+ * Present only when the bind/init opens a COPY-TO sink (`null`/absent
31
+ * otherwise — set by the VGI extension's `copy_to_bind`). `InitRequest`
32
+ * embeds the same `BindRequest` as `bind_call`, so process()/combine() also
33
+ * reach it via `initCall.bind_call.copy_to`. The handler's options arrive
34
+ * through the normal `BindRequest.arguments`; the **source** columns ride the
35
+ * existing `BindRequest.input_schema` (so they are not duplicated here).
36
+ * Mirrors vgi-python's `protocol.CopyToContext`.
37
+ */
38
+ export interface CopyToContext {
39
+ /** The `FORMAT` name resolved at COPY bind time. */
40
+ format: string;
41
+ /** The destination path from the `COPY ... TO 'path'` statement. */
42
+ file_path: string;
43
+ }
44
+ export interface BindRequest {
45
+ function_name: string;
46
+ arguments: Arguments;
47
+ function_type: FunctionType;
48
+ input_schema: VgiSchema | null;
49
+ settings: VgiBatch | null;
50
+ secrets: VgiBatch | null;
51
+ attach_opaque_data: Uint8Array | null;
52
+ transaction_opaque_data: Uint8Array | null;
53
+ resolved_secrets_provided: boolean;
54
+ /**
55
+ * COPY ... FROM context — `null`/absent unless this bind/init opens a
56
+ * COPY-FROM scan. Additive + name-keyed, so ordinary scans (which omit it on
57
+ * the wire) deserialize to `null`. Mirrors vgi-python's `BindRequest.copy_from`.
58
+ */
59
+ copy_from?: CopyFromContext | null;
60
+ /**
61
+ * COPY ... TO context — `null`/absent unless this bind/init opens a COPY-TO
62
+ * sink. Additive + name-keyed, same wire-safe rationale as `copy_from`.
63
+ * Mirrors vgi-python's `BindRequest.copy_to`.
64
+ */
65
+ copy_to?: CopyToContext | null;
66
+ /**
67
+ * Time travel: the AT (TIMESTAMP|VERSION ...) clause for this scan, threaded
68
+ * from DuckDB's per-reference bind. Both `null` when the scan has no AT clause.
69
+ * For inline-bound (function-backed) tables the actual on_bind RPC runs once at
70
+ * attach with no AT, so the per-scan AT is carried on the bind request embedded
71
+ * in each InitRequest — read it at init via `init_call.bind_call.at_unit` (or
72
+ * `TableProcessParams.atUnit`). Mirrors vgi-python's `BindRequest.at_unit`.
73
+ */
74
+ at_unit?: string | null;
75
+ at_value?: string | null;
76
+ }
77
+ export interface BindResponse {
78
+ output_schema: VgiSchema;
79
+ opaque_data: Uint8Array | null;
80
+ lookup_secret_types?: string[];
81
+ lookup_scopes?: string[];
82
+ lookup_names?: string[];
83
+ }
84
+ export interface InitRequest {
85
+ bind_call: BindRequest;
86
+ output_schema: VgiSchema;
87
+ bind_opaque_data: Uint8Array | null;
88
+ projection_ids: number[] | null;
89
+ pushdown_filters: VgiBatch | null;
90
+ /**
91
+ * Join-key value batches, one per join-keys column. Keyed by the column
92
+ * name inside each batch's schema. Populated when DuckDB promotes
93
+ * IN/OR lists or join predicates to batched join-keys pushdowns.
94
+ */
95
+ join_keys: VgiBatch[];
96
+ phase: TableInOutPhase | null;
97
+ /**
98
+ * Buffered-table finalize stream: which finalize_state_id this stream
99
+ * serves. Set when phase=TABLE_BUFFERING_FINALIZE; null otherwise. Opaque
100
+ * bytes the worker's combine() chose.
101
+ */
102
+ finalize_state_id: Uint8Array | null;
103
+ execution_id: Uint8Array | null;
104
+ init_opaque_data: Uint8Array | null;
105
+ order_by_column_name: string | null;
106
+ order_by_direction: OrderByDirection | null;
107
+ order_by_null_order: OrderByNullOrder | null;
108
+ order_by_limit: bigint | null;
109
+ tablesample_percentage: number | null;
110
+ tablesample_seed: bigint | null;
111
+ }
112
+ export declare enum OrderByDirection {
113
+ ASC = "ASC",
114
+ DESC = "DESC"
115
+ }
116
+ export declare enum OrderByNullOrder {
117
+ NULLS_FIRST = "NULLS_FIRST",
118
+ NULLS_LAST = "NULLS_LAST"
119
+ }
120
+ export interface GlobalInitResponse {
121
+ max_workers: number;
122
+ execution_id: Uint8Array;
123
+ opaque_data: Uint8Array | null;
124
+ }
125
+ export interface TableFunctionCardinalityRequest {
126
+ bind_call: BindRequest;
127
+ bind_opaque_data: Uint8Array | null;
128
+ }
129
+ export { TableCardinality };
@@ -0,0 +1,15 @@
1
+ export type SecretFields = Record<string, any>;
2
+ export type SecretsDict = Record<string, SecretFields>;
3
+ /** The DuckDB secret type of the named secret (its serialized `type` field). */
4
+ export declare function secretType(secrets: SecretsDict, name: string): string | undefined;
5
+ /** Every resolved secret whose serialized `type` field matches `type`. */
6
+ export declare function secretsOfType(secrets: SecretsDict, type: string): SecretFields[];
7
+ /**
8
+ * The secret whose `scope` is the longest prefix of `path`. The connector
9
+ * serializes each secret's scope as a newline-joined list of prefixes; a secret
10
+ * with no (or empty) scope matches as a last-resort fallback. Returns undefined
11
+ * only when there are no candidate secrets.
12
+ */
13
+ export declare function secretForScope(secrets: SecretsDict, path: string): SecretFields | undefined;
14
+ /** Like {@link secretForScope} but only over secrets of `type`. */
15
+ export declare function secretForScopeOfType(secrets: SecretsDict, path: string, type: string): SecretFields | undefined;
@@ -0,0 +1,52 @@
1
+ export declare enum FunctionType {
2
+ SCALAR = "scalar",
3
+ TABLE = "table",
4
+ AGGREGATE = "aggregate"
5
+ }
6
+ export declare enum FunctionStability {
7
+ CONSISTENT = "CONSISTENT",
8
+ VOLATILE = "VOLATILE",
9
+ CONSISTENT_WITHIN_QUERY = "CONSISTENT_WITHIN_QUERY"
10
+ }
11
+ export declare enum NullHandling {
12
+ DEFAULT = "DEFAULT",
13
+ SPECIAL = "SPECIAL"
14
+ }
15
+ export declare enum OrderPreservation {
16
+ /** Output rows are in same order as input rows (DuckDB INSERTION_ORDER). */
17
+ PRESERVES_ORDER = "PRESERVES_ORDER",
18
+ /** Output order is undefined; may be reordered (DuckDB NO_ORDER). */
19
+ NO_ORDER_GUARANTEE = "NO_ORDER_GUARANTEE",
20
+ /** Output is in a fixed mandatory order; DuckDB serialises the pipeline
21
+ * (single worker) to preserve it (DuckDB FIXED_ORDER). */
22
+ FIXED_ORDER = "FIXED_ORDER"
23
+ }
24
+ export declare enum OrderDependence {
25
+ ORDER_DEPENDENT = "ORDER_DEPENDENT",
26
+ NOT_ORDER_DEPENDENT = "NOT_ORDER_DEPENDENT"
27
+ }
28
+ export declare enum DistinctDependence {
29
+ DISTINCT_DEPENDENT = "DISTINCT_DEPENDENT",
30
+ NOT_DISTINCT_DEPENDENT = "NOT_DISTINCT_DEPENDENT"
31
+ }
32
+ export declare enum TableInOutPhase {
33
+ INPUT = "INPUT",
34
+ FINALIZE = "FINALIZE",
35
+ TABLE_BUFFERING = "TABLE_BUFFERING",
36
+ TABLE_BUFFERING_FINALIZE = "TABLE_BUFFERING_FINALIZE"
37
+ }
38
+ export declare const VGI_ARG_KEY = "vgi_arg";
39
+ export declare const VGI_ARG_NAMED = "named";
40
+ export declare const VGI_TYPE_KEY = "vgi_type";
41
+ export declare const VGI_TYPE_TABLE = "table";
42
+ export declare const VGI_TYPE_ANY = "any";
43
+ export declare const VGI_VARARGS_KEY = "vgi_varargs";
44
+ export declare const VGI_VARARGS_TRUE = "true";
45
+ export declare const VGI_CONST_KEY = "vgi_const";
46
+ export declare const VGI_CONST_TRUE = "true";
47
+ export declare const VGI_DOC_KEY = "vgi_doc";
48
+ export interface TableCardinality {
49
+ estimate: number | null;
50
+ max: number | null;
51
+ }
52
+ export declare const DEFAULT_MAX_WORKERS = 99999;
@@ -0,0 +1 @@
1
+ export { emptyBatch, batchFromRows, batchFromColumns, iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, filterBatch, projectSchema, projectBatch, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, } from "../../arrow/index.js";
@@ -0,0 +1,2 @@
1
+ /** Convert any binary-ish value to a Uint8Array. Returns empty array for null/undefined. */
2
+ export declare function toUint8Array(val: any): Uint8Array;
@@ -0,0 +1,7 @@
1
+ import { type ColumnStatistics } from "../arrow/index.js";
2
+ export type { ColumnStatistics };
3
+ /**
4
+ * Serialize column statistics to IPC bytes per vgi-python's wire format.
5
+ * Returns an empty-stats batch when `stats` is empty (matching Python).
6
+ */
7
+ export declare function serializeColumnStatistics(stats: ColumnStatistics[], _cacheMaxAgeSeconds?: number | null): Uint8Array;
@@ -0,0 +1,30 @@
1
+ import { type ProtocolConfig } from "./protocol/dispatch.js";
2
+ export interface VgiFetchOptions {
3
+ /** Wire-protocol config (registry + catalogInterface). */
4
+ protocol: Omit<ProtocolConfig, "recoverExchangeState">;
5
+ /** HMAC key for state-token signing. Pass a stable, secret 32-byte key
6
+ * (e.g. derived from a Wrangler secret). Required because Workers don't
7
+ * preserve in-memory state across requests/instances. */
8
+ signingKey: Uint8Array;
9
+ /** State-token TTL in seconds (default 3600). */
10
+ tokenTtl?: number;
11
+ /** URL path prefix for VGI requests (default "/vgi"). */
12
+ prefix?: string;
13
+ /** Server ID for state-token attribution (default "vgi-cf"). */
14
+ serverId?: string;
15
+ }
16
+ /**
17
+ * Build a fetch handler suitable for `export default { fetch }` in a CF
18
+ * Worker module. The returned handler is async-safe across Workers'
19
+ * isolate-per-request execution model — all state round-trips through the
20
+ * signed state token created here.
21
+ */
22
+ export declare function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise<Response>;
23
+ export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
24
+ export type { AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, } from "./index.core.js";
25
+ export type { ProtocolConfig } from "./protocol/dispatch.js";
26
+ export { TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, backend, schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, emptyBatch, batchFromRows, batchFromColumns, columnFromArray, iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, filterBatch, projectSchema, projectBatch, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, buildStatisticsBatch, } from "./arrow/index.js";
27
+ export type { VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnData, VgiBatch, VgiBackendInfo, } from "./arrow/index.js";
28
+ export { arrowStateSerializer, EXCHANGE_STATE_SCHEMA } from "./protocol/state-serializer.js";
29
+ export { OutputCollector, AuthContext } from "@query-farm/vgi-rpc";
30
+ export type { LogMessage } from "@query-farm/vgi-rpc";