@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
@@ -10,24 +10,16 @@
10
10
  // vgi-python's worker._load_table_buffering_params.
11
11
 
12
12
  import { deserializeBatch } from "../../arrow/index.js";
13
- import { Protocol } from "@query-farm/vgi-rpc";
13
+ import type { VgiService } from "../../generated/vgi-service.js";
14
14
  import type { FunctionRegistry } from "../../functions/registry.js";
15
15
  import { toUint8Array } from "../../util/bytes.js";
16
16
  import { batchToScalarDict, batchToSecretDict } from "../../util/arrow/index.js";
17
17
  import {
18
- TableBufferingCombineParamsSchema,
19
18
  TableBufferingCombineResultSchema,
20
- TableBufferingDestructorParamsSchema,
21
19
  TableBufferingDestructorResultSchema,
22
- TableBufferingProcessParamsSchema,
23
20
  TableBufferingProcessResultSchema,
24
21
  } from "../../generated/vgi-protocol-schemas.js";
25
- import {
26
- REQUEST_PARAMS_SCHEMA,
27
- RESULT_BINARY_SCHEMA,
28
- unwrapRequest,
29
- wrapResult,
30
- } from "./shared.js";
22
+ import { unwrapRequest, wrapResult } from "./shared.js";
31
23
  import { openAttach } from "./catalog/shared.js";
32
24
  import {
33
25
  BoundStorage,
@@ -41,11 +33,11 @@ import {
41
33
  } from "../../functions/table-buffering.js";
42
34
  import { Arguments } from "../../arguments/arguments.js";
43
35
 
44
- export function registerTableBufferingMethods(
45
- protocol: Protocol,
36
+ /** The table_buffering lifecycle's `vgi.v2` handlers. */
37
+ export function tableBufferingHandlers(
46
38
  registry: FunctionRegistry,
47
39
  signingKey?: Uint8Array,
48
- ): void {
40
+ ): Partial<VgiService> {
49
41
  // `schemaPath` scopes resolution to the schema the caller named. The
50
42
  // buffering process/combine RPCs carry it (protocol 1.2.0), so a name
51
43
  // declared in two schemas resolves to the one the request names rather than
@@ -123,72 +115,62 @@ export function registerTableBufferingMethods(
123
115
  // ------------------------------------------------------------------------
124
116
  // table_buffering_process — sink one batch, return state_id (unary)
125
117
  // ------------------------------------------------------------------------
126
- protocol.unary("table_buffering_process", {
127
- params: TableBufferingProcessParamsSchema,
128
- result: RESULT_BINARY_SCHEMA,
129
- handler: async (rpcParams, ctx?: any) => {
130
- const inner = unwrapRequest(rpcParams.request);
131
- const clientLog = makeClientLog(ctx);
132
- const { func, params } = await loadParams(inner, clientLog, ctx);
133
- if (inner.batch_index != null) {
134
- params.batchIndex = Number(inner.batch_index);
135
- }
136
- const batch = deserializeBatch(toUint8Array(inner.input_batch));
137
- const stateId = await func.bufferingConfig.process(batch, params);
138
- if (!(stateId instanceof Uint8Array)) {
139
- throw new Error(
140
- `${func.meta.name}.process() must return Uint8Array (the opaque state_id)`,
141
- );
142
- }
143
- return wrapResult({ state_id: stateId }, TableBufferingProcessResultSchema);
144
- },
145
- });
118
+ const tableBufferingProcess: VgiService["tableBufferingProcess"] = async (rpcParams, ctx?: any) => {
119
+ const inner = unwrapRequest(rpcParams.request);
120
+ const clientLog = makeClientLog(ctx);
121
+ const { func, params } = await loadParams(inner, clientLog, ctx);
122
+ if (inner.batch_index != null) {
123
+ params.batchIndex = Number(inner.batch_index);
124
+ }
125
+ const batch = deserializeBatch(toUint8Array(inner.input_batch));
126
+ const stateId = await func.bufferingConfig.process(batch, params);
127
+ if (!(stateId instanceof Uint8Array)) {
128
+ throw new Error(
129
+ `${func.meta.name}.process() must return Uint8Array (the opaque state_id)`,
130
+ );
131
+ }
132
+ return wrapResult({ state_id: stateId }, TableBufferingProcessResultSchema);
133
+ };
146
134
 
147
135
  // ------------------------------------------------------------------------
148
136
  // table_buffering_combine — group/merge state_ids (unary)
149
137
  // ------------------------------------------------------------------------
150
- protocol.unary("table_buffering_combine", {
151
- params: TableBufferingCombineParamsSchema,
152
- result: RESULT_BINARY_SCHEMA,
153
- handler: async (rpcParams, ctx?: any) => {
154
- const inner = unwrapRequest(rpcParams.request);
155
- const clientLog = makeClientLog(ctx);
156
- const { func, params } = await loadParams(inner, clientLog, ctx);
157
- const stateIds = decodeBytesList(inner.state_ids);
158
- const finalizeStateIds = await func.bufferingConfig.combine(stateIds, params);
159
- const out = finalizeStateIds.map((fid, i) => {
160
- if (!(fid instanceof Uint8Array)) {
161
- throw new Error(
162
- `${func.meta.name}.combine() returned non-Uint8Array finalize_state_id at index ${i}`,
163
- );
164
- }
165
- return fid;
166
- });
167
- return wrapResult(
168
- { finalize_state_ids: out },
169
- TableBufferingCombineResultSchema,
170
- );
171
- },
172
- });
138
+ const tableBufferingCombine: VgiService["tableBufferingCombine"] = async (rpcParams, ctx?: any) => {
139
+ const inner = unwrapRequest(rpcParams.request);
140
+ const clientLog = makeClientLog(ctx);
141
+ const { func, params } = await loadParams(inner, clientLog, ctx);
142
+ const stateIds = decodeBytesList(inner.state_ids);
143
+ const finalizeStateIds = await func.bufferingConfig.combine(stateIds, params);
144
+ const out = finalizeStateIds.map((fid, i) => {
145
+ if (!(fid instanceof Uint8Array)) {
146
+ throw new Error(
147
+ `${func.meta.name}.combine() returned non-Uint8Array finalize_state_id at index ${i}`,
148
+ );
149
+ }
150
+ return fid;
151
+ });
152
+ return wrapResult(
153
+ { finalize_state_ids: out },
154
+ TableBufferingCombineResultSchema,
155
+ );
156
+ };
173
157
 
174
158
  // ------------------------------------------------------------------------
175
159
  // table_buffering_destructor — best-effort end-of-query cleanup (unary)
176
160
  // ------------------------------------------------------------------------
177
- protocol.unary("table_buffering_destructor", {
178
- params: TableBufferingDestructorParamsSchema,
179
- result: RESULT_BINARY_SCHEMA,
180
- handler: async (rpcParams) => {
181
- try {
182
- const inner = unwrapRequest(rpcParams.request);
183
- const executionId = toUint8Array(inner.execution_id);
184
- const bound = new BoundStorage(defaultStorage, executionId);
185
- await bound.executionClear();
186
- } catch {
187
- // Teardown path — swallow; the entry is wiped when the worker exits.
188
- }
189
- return wrapResult({}, TableBufferingDestructorResultSchema);
190
- },
191
- });
161
+ const tableBufferingDestructor: VgiService["tableBufferingDestructor"] = async (rpcParams) => {
162
+ try {
163
+ const inner = unwrapRequest(rpcParams.request);
164
+ const executionId = toUint8Array(inner.execution_id);
165
+ const bound = new BoundStorage(defaultStorage, executionId);
166
+ await bound.executionClear();
167
+ } catch {
168
+ // Teardown path — swallow; the entry is wiped when the worker exits.
169
+ }
170
+ return wrapResult({}, TableBufferingDestructorResultSchema);
171
+ };
172
+
173
+ return { tableBufferingProcess, tableBufferingCombine, tableBufferingDestructor };
192
174
  }
193
175
 
194
176
  function makeClientLog(ctx: any): (level: string, message: string) => void {
@@ -0,0 +1,30 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // vgi.v2 methods this SDK registers but does not implement.
3
+ //
4
+ // "The protocol is the unit of optionality": every SDK hosts EVERY vgi.v2
5
+ // method with exactly the reference's schemas, so vgi_rpc.Reflection.v1
6
+ // reports one vgi.v2 protocol hash everywhere (see VGI_V2_PROTOCOL_HASH in
7
+ // ../dispatch.ts). The registration and the UNIMPLEMENTED default for every
8
+ // method are generated (src/generated/vgi-service.ts); this module only names
9
+ // the methods whose generated default this worker leaves in place, so a test
10
+ // can assert each one refuses with UNIMPLEMENTED.
11
+ //
12
+ // To implement one, add its handler to a group in this directory; it drops off
13
+ // this list by itself.
14
+
15
+ import { FunctionRegistry } from "../../functions/registry.js";
16
+ import {
17
+ UNIMPLEMENTED_VGI_SERVICE,
18
+ VGI_V2_METHODS,
19
+ type VgiMethodSpec,
20
+ } from "../../generated/vgi-service.js";
21
+ import { buildVgiService } from "../dispatch.js";
22
+
23
+ export { unimplementedMessage } from "../../generated/vgi-service.js";
24
+
25
+ const service = buildVgiService({ registry: new FunctionRegistry() });
26
+
27
+ /** The vgi.v2 methods (of the reference's 72) this SDK leaves at the generated default. */
28
+ export const UNIMPLEMENTED_METHODS: readonly VgiMethodSpec[] = VGI_V2_METHODS.filter(
29
+ (m) => service[m.key] === UNIMPLEMENTED_VGI_SERVICE[m.key],
30
+ );