@query-farm/vgi 0.41.0 → 0.43.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 (35) hide show
  1. package/dist/generated/vgi-service.d.ts +1315 -0
  2. package/dist/index.js +1845 -780
  3. package/dist/index.js.map +16 -15
  4. package/dist/protocol/dispatch.d.ts +25 -3
  5. package/dist/protocol/handlers/aggregate.d.ts +3 -2
  6. package/dist/protocol/handlers/catalog/admin.d.ts +2 -2
  7. package/dist/protocol/handlers/catalog/index.d.ts +3 -2
  8. package/dist/protocol/handlers/catalog/index_methods.d.ts +2 -2
  9. package/dist/protocol/handlers/catalog/macro.d.ts +2 -2
  10. package/dist/protocol/handlers/catalog/shared.d.ts +7 -14
  11. package/dist/protocol/handlers/catalog/table.d.ts +2 -2
  12. package/dist/protocol/handlers/catalog/view.d.ts +2 -2
  13. package/dist/protocol/handlers/function.d.ts +3 -2
  14. package/dist/protocol/handlers/shared.d.ts +0 -1
  15. package/dist/protocol/handlers/table-buffering.d.ts +3 -2
  16. package/dist/protocol/handlers/unimplemented.d.ts +4 -0
  17. package/dist/serve-entry.js +1844 -780
  18. package/dist/serve-entry.js.map +16 -15
  19. package/dist/worker-cf-entry.js +1845 -780
  20. package/dist/worker-cf-entry.js.map +16 -15
  21. package/package.json +1 -1
  22. package/src/generated/vgi-service.ts +2678 -0
  23. package/src/protocol/dispatch.ts +51 -24
  24. package/src/protocol/handlers/aggregate.ts +205 -232
  25. package/src/protocol/handlers/catalog/admin.ts +228 -299
  26. package/src/protocol/handlers/catalog/index.ts +17 -16
  27. package/src/protocol/handlers/catalog/index_methods.ts +26 -36
  28. package/src/protocol/handlers/catalog/macro.ts +54 -77
  29. package/src/protocol/handlers/catalog/shared.ts +30 -47
  30. package/src/protocol/handlers/catalog/table.ts +205 -270
  31. package/src/protocol/handlers/catalog/view.ts +59 -85
  32. package/src/protocol/handlers/function.ts +127 -156
  33. package/src/protocol/handlers/shared.ts +0 -4
  34. package/src/protocol/handlers/table-buffering.ts +53 -71
  35. package/src/protocol/handlers/unimplemented.ts +30 -0
@@ -1,25 +1,26 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
- // Catalog handler orchestrator: registers all catalog_* RPC methods.
2
+ // Catalog handler orchestrator: every catalog_* `vgi.v2` handler.
3
3
 
4
- import { Protocol } from "@query-farm/vgi-rpc";
5
4
  import type { CatalogInterface } from "../../../catalog/interface.js";
5
+ import type { VgiService } from "../../../generated/vgi-service.js";
6
6
  import { makeGetCatalog } from "./shared.js";
7
- import { registerCatalogAdminMethods } from "./admin.js";
8
- import { registerCatalogTableMethods } from "./table.js";
9
- import { registerCatalogViewMethods } from "./view.js";
10
- import { registerCatalogMacroMethods } from "./macro.js";
11
- import { registerCatalogIndexMethods } from "./index_methods.js";
7
+ import { catalogAdminHandlers } from "./admin.js";
8
+ import { catalogTableHandlers } from "./table.js";
9
+ import { catalogViewHandlers } from "./view.js";
10
+ import { catalogMacroHandlers } from "./macro.js";
11
+ import { catalogIndexHandlers } from "./index_methods.js";
12
12
 
13
- export function registerCatalogMethods(
14
- protocol: Protocol,
13
+ /** The catalog_* `vgi.v2` handlers, over *catalog* (or `NoCatalogError` without one). */
14
+ export function catalogHandlers(
15
15
  catalog: CatalogInterface | undefined,
16
- _catalogName: string | undefined,
17
16
  signingKey?: Uint8Array,
18
- ): void {
17
+ ): Partial<VgiService> {
19
18
  const getCatalog = makeGetCatalog(catalog);
20
- registerCatalogAdminMethods(protocol, getCatalog, signingKey);
21
- registerCatalogTableMethods(protocol, getCatalog, signingKey);
22
- registerCatalogViewMethods(protocol, getCatalog, signingKey);
23
- registerCatalogMacroMethods(protocol, getCatalog, signingKey);
24
- registerCatalogIndexMethods(protocol, getCatalog, signingKey);
19
+ return {
20
+ ...catalogAdminHandlers(getCatalog, signingKey),
21
+ ...catalogTableHandlers(getCatalog, signingKey),
22
+ ...catalogViewHandlers(getCatalog, signingKey),
23
+ ...catalogMacroHandlers(getCatalog, signingKey),
24
+ ...catalogIndexHandlers(getCatalog, signingKey),
25
+ };
25
26
  }
@@ -1,58 +1,48 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // Catalog index handlers: index_get, schema_contents_indexes.
3
3
 
4
- import { type VgiSchema, schema, type VgiField, field, type VgiDataType, binary, utf8 } from "../../../arrow/index.js";
5
- import { Protocol } from "@query-farm/vgi-rpc";
4
+ import type { VgiService } from "../../../generated/vgi-service.js";
6
5
  import { encodeIndexInfo } from "../../../generated/vgi-client.js";
7
6
  import {
8
- CatalogIndexGetParamsSchema,
9
7
  CatalogIndexGetResultSchema,
10
- CatalogSchemaContentsIndexesParamsSchema,
11
8
  CatalogSchemaContentsIndexesResultSchema,
12
9
  } from "../../../generated/vgi-protocol-schemas.js";
13
10
  import { toUint8Array } from "../../../util/bytes.js";
14
11
  import {
15
- RESULT_BINARY_SCHEMA,
16
12
  wrapResult,
17
13
  } from "../shared.js";
18
14
  import {
19
15
  type GetCatalog,
20
- catalogUnary,
16
+ catalogHandler,
21
17
  } from "./shared.js";
22
18
 
23
- export function registerCatalogIndexMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
19
+ export function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
24
20
  // catalog_schema_contents_indexes
25
- catalogUnary(protocol, signingKey, "catalog_schema_contents_indexes", {
26
- params: CatalogSchemaContentsIndexesParamsSchema,
27
- result: RESULT_BINARY_SCHEMA,
28
- handler: async (params) => {
29
- const cat = getCatalog();
30
- const indexes = await cat.schemaContentsIndexes(
31
- toUint8Array(params.attach_opaque_data),
32
- params.path,
33
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
34
- );
35
- return wrapResult({
36
- items: indexes.map((i) => encodeIndexInfo(i)),
37
- }, CatalogSchemaContentsIndexesResultSchema);
38
- },
21
+ const catalogSchemaContentsIndexes = catalogHandler(signingKey, async (params) => {
22
+ const cat = getCatalog();
23
+ const indexes = await cat.schemaContentsIndexes(
24
+ toUint8Array(params.attach_opaque_data),
25
+ params.path,
26
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
27
+ );
28
+ return wrapResult({
29
+ items: indexes.map((i) => encodeIndexInfo(i)),
30
+ }, CatalogSchemaContentsIndexesResultSchema);
39
31
  });
40
32
 
41
33
  // catalog_index_get
42
- catalogUnary(protocol, signingKey, "catalog_index_get", {
43
- params: CatalogIndexGetParamsSchema,
44
- result: RESULT_BINARY_SCHEMA,
45
- handler: async (params) => {
46
- const cat = getCatalog();
47
- const info = await cat.indexGet(
48
- toUint8Array(params.attach_opaque_data),
49
- params.schema_path,
50
- params.name,
51
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
52
- );
53
- return wrapResult({
54
- items: info ? [encodeIndexInfo(info)] : [],
55
- }, CatalogIndexGetResultSchema);
56
- },
34
+ const catalogIndexGet = catalogHandler(signingKey, async (params) => {
35
+ const cat = getCatalog();
36
+ const info = await cat.indexGet(
37
+ toUint8Array(params.attach_opaque_data),
38
+ params.schema_path,
39
+ params.name,
40
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
41
+ );
42
+ return wrapResult({
43
+ items: info ? [encodeIndexInfo(info)] : [],
44
+ }, CatalogIndexGetResultSchema);
57
45
  });
46
+
47
+ return { catalogSchemaContentsIndexes, catalogIndexGet };
58
48
  }
@@ -1,107 +1,84 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // Catalog macro handlers: macro_get/create/drop, schema_contents_macros.
3
3
 
4
- import { type VgiSchema, schema, type VgiField, field, type VgiDataType, binary, utf8, bool } from "../../../arrow/index.js";
5
- import { Protocol } from "@query-farm/vgi-rpc";
4
+ import type { VgiService } from "../../../generated/vgi-service.js";
6
5
  import { encodeMacroInfo } from "../../../generated/vgi-client.js";
7
6
  import {
8
- CatalogMacroCreateParamsSchema,
9
- CatalogMacroDropParamsSchema,
10
- CatalogMacroGetParamsSchema,
11
7
  CatalogMacroGetResultSchema,
12
- CatalogSchemaContentsMacrosParamsSchema,
13
8
  CatalogSchemaContentsMacrosResultSchema,
14
9
  } from "../../../generated/vgi-protocol-schemas.js";
15
10
  import type { MacroType } from "../../../catalog/interface.js";
16
11
  import { toUint8Array } from "../../../util/bytes.js";
17
12
  import { decodeDictValue } from "../../../util/arrow/index.js";
18
13
  import {
19
- REQUEST_PARAMS_SCHEMA,
20
- RESULT_BINARY_SCHEMA,
21
- unwrapRequest,
22
14
  wrapResult,
23
15
  } from "../shared.js";
24
16
  import {
25
17
  type GetCatalog,
26
- emptyResultSchema,
27
- catalogUnary,
18
+ catalogHandler,
28
19
  } from "./shared.js";
29
20
 
30
- export function registerCatalogMacroMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
21
+ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
31
22
  // catalog_macro_get
32
- catalogUnary(protocol, signingKey, "catalog_macro_get", {
33
- params: CatalogMacroGetParamsSchema,
34
- result: RESULT_BINARY_SCHEMA,
35
- handler: async (params) => {
36
- const cat = getCatalog();
37
- const info = await cat.macroGet(
38
- toUint8Array(params.attach_opaque_data),
39
- params.schema_path,
40
- params.name,
41
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
42
- );
43
- return wrapResult({
44
- items: info ? [encodeMacroInfo(info)] : [],
45
- }, CatalogMacroGetResultSchema);
46
- },
23
+ const catalogMacroGet = catalogHandler(signingKey, async (params) => {
24
+ const cat = getCatalog();
25
+ const info = await cat.macroGet(
26
+ toUint8Array(params.attach_opaque_data),
27
+ params.schema_path,
28
+ params.name,
29
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
30
+ );
31
+ return wrapResult({
32
+ items: info ? [encodeMacroInfo(info)] : [],
33
+ }, CatalogMacroGetResultSchema);
47
34
  });
48
35
 
49
36
  // catalog_macro_create
50
- catalogUnary(protocol, signingKey, "catalog_macro_create", {
51
- params: CatalogMacroCreateParamsSchema,
52
- result: emptyResultSchema,
53
- handler: async (params) => {
54
- const cat = getCatalog();
55
- // catalogUnary already flattened the wrapped request.
56
- const innerParams = params;
57
- await cat.macroCreate(
58
- toUint8Array(innerParams.attach_opaque_data),
59
- innerParams.schema_path,
60
- innerParams.name,
61
- innerParams.macro_type as MacroType,
62
- innerParams.parameters ? (Array.isArray(innerParams.parameters) ? innerParams.parameters : [...innerParams.parameters]) : [],
63
- innerParams.definition,
64
- innerParams.on_conflict,
65
- innerParams.parameter_default_values ? toUint8Array(innerParams.parameter_default_values) : null,
66
- innerParams.arguments_schema ? toUint8Array(innerParams.arguments_schema) : null,
67
- innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined
68
- );
69
- return {};
70
- },
37
+ const catalogMacroCreate = catalogHandler(signingKey, async (params) => {
38
+ const cat = getCatalog();
39
+ // catalogHandler already flattened the wrapped request.
40
+ const innerParams = params;
41
+ await cat.macroCreate(
42
+ toUint8Array(innerParams.attach_opaque_data),
43
+ innerParams.schema_path,
44
+ innerParams.name,
45
+ innerParams.macro_type as MacroType,
46
+ innerParams.parameters ? (Array.isArray(innerParams.parameters) ? innerParams.parameters : [...innerParams.parameters]) : [],
47
+ innerParams.definition,
48
+ innerParams.on_conflict,
49
+ innerParams.parameter_default_values ? toUint8Array(innerParams.parameter_default_values) : null,
50
+ innerParams.arguments_schema ? toUint8Array(innerParams.arguments_schema) : null,
51
+ innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined
52
+ );
53
+ return {};
71
54
  });
72
55
 
73
56
  // catalog_macro_drop
74
- catalogUnary(protocol, signingKey, "catalog_macro_drop", {
75
- params: CatalogMacroDropParamsSchema,
76
- result: emptyResultSchema,
77
- handler: async (params) => {
78
- const cat = getCatalog();
79
- await cat.macroDrop(
80
- toUint8Array(params.attach_opaque_data),
81
- params.schema_path,
82
- params.name,
83
- params.ignore_not_found,
84
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
85
- );
86
- return {};
87
- },
57
+ const catalogMacroDrop = catalogHandler(signingKey, async (params) => {
58
+ const cat = getCatalog();
59
+ await cat.macroDrop(
60
+ toUint8Array(params.attach_opaque_data),
61
+ params.schema_path,
62
+ params.name,
63
+ params.ignore_not_found,
64
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
65
+ );
66
+ return {};
88
67
  });
89
68
 
90
69
  // catalog_schema_contents_macros
91
- catalogUnary(protocol, signingKey, "catalog_schema_contents_macros", {
92
- params: CatalogSchemaContentsMacrosParamsSchema,
93
- result: RESULT_BINARY_SCHEMA,
94
- handler: async (params) => {
95
- const cat = getCatalog();
96
- const macros = await cat.schemaContentsMacros(
97
- toUint8Array(params.attach_opaque_data),
98
- params.path,
99
- decodeDictValue(params.type),
100
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
101
- );
102
- return wrapResult({
103
- items: macros.map((m) => encodeMacroInfo(m)),
104
- }, CatalogSchemaContentsMacrosResultSchema);
105
- },
70
+ const catalogSchemaContentsMacros = catalogHandler(signingKey, async (params) => {
71
+ const cat = getCatalog();
72
+ const macros = await cat.schemaContentsMacros(
73
+ toUint8Array(params.attach_opaque_data),
74
+ params.path,
75
+ decodeDictValue(params.type),
76
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
77
+ );
78
+ return wrapResult({
79
+ items: macros.map((m) => encodeMacroInfo(m)),
80
+ }, CatalogSchemaContentsMacrosResultSchema);
106
81
  });
82
+
83
+ return { catalogMacroGet, catalogMacroCreate, catalogMacroDrop, catalogSchemaContentsMacros };
107
84
  }
@@ -1,8 +1,8 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // Shared param schemas and helpers for catalog protocol handlers.
3
3
 
4
- import { type VgiSchema, schema, iterRows } from "../../../arrow/index.js";
5
- import { Protocol, type AuthContext, type CallContext } from "@query-farm/vgi-rpc";
4
+ import { iterRows } from "../../../arrow/index.js";
5
+ import type { AuthContext, CallContext } from "@query-farm/vgi-rpc";
6
6
  import type { CatalogInterface } from "../../../catalog/interface.js";
7
7
  import { NoCatalogError } from "../../../errors.js";
8
8
  import { deserializeBatch } from "../../../util/arrow/index.js";
@@ -174,43 +174,32 @@ async function unwrapParamsOpaque(
174
174
  }
175
175
 
176
176
  /**
177
- * Register a catalog unary handler whose request opaque-data fields are
178
- * unwrapped before the handler body runs. Used for every catalog_* method
179
- * except catalog_attach / catalog_transaction_begin, which seal their outputs
180
- * and are registered bespoke.
177
+ * Wrap a catalog unary handler so its request opaque-data fields are unwrapped
178
+ * before the body runs. Used for every catalog_* method except catalog_attach
179
+ * / catalog_transaction_begin, which seal their outputs and are written
180
+ * bespoke. The body sees the flattened params as a plain record.
181
181
  */
182
- export function catalogUnary(
183
- protocol: Protocol,
182
+ export function catalogHandler<R>(
184
183
  signingKey: Uint8Array | undefined,
185
- name: string,
186
- config: {
187
- params: unknown;
188
- result: unknown;
189
- handler: (params: Record<string, any>, ctx: CallContext) => unknown;
190
- doc?: string;
191
- },
192
- ): void {
193
- protocol.unary(name, {
194
- params: config.params as any,
195
- result: config.result as any,
196
- doc: config.doc,
197
- handler: async (params: Record<string, any>, ctx: any) => {
198
- // catalog_create / catalog_table_create / catalog_macro_create (and
199
- // catalog_index_create) send one `request: binary` column holding the
200
- // IPC-serialized request record, so their attach/transaction values ride
201
- // INSIDE it. Flatten it first, so handlers read the request's fields
202
- // directly and those values are opened (and the framework UUID stripped)
203
- // like every other catalog call's. Before this, table_create read every
204
- // field off the envelope (all undefined) and macro_create handed the
205
- // catalog an unopened attach value.
206
- if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
207
- params = unwrapRequest(params.request);
208
- }
209
- normalizeRequestSchemaPaths(params);
210
- await unwrapParamsOpaque(params, ctx, signingKey);
211
- return config.handler(params, ctx);
212
- },
213
- });
184
+ handler: (params: Record<string, any>, ctx: CallContext) => R | Promise<R>,
185
+ ): (params: object, ctx: CallContext) => Promise<R> {
186
+ return async (wire: object, ctx: CallContext) => {
187
+ let params = wire as Record<string, any>;
188
+ // catalog_create / catalog_table_create / catalog_macro_create (and
189
+ // catalog_index_create) send one `request: binary` column holding the
190
+ // IPC-serialized request record, so their attach/transaction values ride
191
+ // INSIDE it. Flatten it first, so handlers read the request's fields
192
+ // directly and those values are opened (and the framework UUID stripped)
193
+ // like every other catalog call's. Before this, table_create read every
194
+ // field off the envelope (all undefined) and macro_create handed the
195
+ // catalog an unopened attach value.
196
+ if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
197
+ params = unwrapRequest(params.request);
198
+ }
199
+ normalizeRequestSchemaPaths(params);
200
+ await unwrapParamsOpaque(params, ctx, signingKey);
201
+ return handler(params, ctx);
202
+ };
214
203
  }
215
204
 
216
205
  export function makeGetCatalog(catalog: CatalogInterface | undefined): GetCatalog {
@@ -240,18 +229,12 @@ export function decodeOptionsBatch(bytes: any): Record<string, unknown> {
240
229
  return row ?? {};
241
230
  }
242
231
 
243
- // ---------------------------------------------------------------------------
244
- // Common param schemas
245
- // ---------------------------------------------------------------------------
246
-
247
- export const emptyResultSchema = schema([]);
248
-
249
232
  // Eight hand-written catalog param schemas used to live here, restating shapes
250
- // codegen already emits. Every `params:` slot now points at a generated
251
- // `…ParamsSchema` and these were left behind, referenced by nothing but their
233
+ // codegen already emits. Every method's schemas now come from the generated
234
+ // registration table (src/generated/vgi-service.ts) and these were left behind, referenced by nothing but their
252
235
  // own import lines. A stale duplicate is worse than no duplicate: the copies
253
236
  // this SDK kept had drifted on `attach_opaque_data` nullability (45 generated
254
237
  // schemas say non-null, every copy said nullable) and on `type` being
255
238
  // dictionary-encoded utf8 rather than plain utf8, and the result was that a
256
- // CORRECT client got rejected at the very first catalog call. Import from
257
- // src/generated/vgi-protocol-schemas.ts instead of reviving one.
239
+ // CORRECT client got rejected at the very first catalog call. Never revive one:
240
+ // the registration table is generated, schemas and all.