@query-farm/vgi 0.42.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 -813
  3. package/dist/index.js.map +16 -16
  4. package/dist/protocol/dispatch.d.ts +14 -5
  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 -17
  17. package/dist/serve-entry.js +1844 -813
  18. package/dist/serve-entry.js.map +16 -16
  19. package/dist/worker-cf-entry.js +1845 -813
  20. package/dist/worker-cf-entry.js.map +16 -16
  21. package/package.json +1 -1
  22. package/src/generated/vgi-service.ts +2678 -0
  23. package/src/protocol/dispatch.ts +40 -29
  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 +18 -62
@@ -2,8 +2,9 @@
2
2
  // Catalog admin handlers: attach/detach/create/drop, version, transactions,
3
3
  // schemas (list, get, create, drop), schema contents listings.
4
4
 
5
- import { type VgiSchema, schema, type VgiField, field, type VgiDataType, binary, utf8, bool } from "../../../arrow/index.js";
6
- import { Protocol, type CallContext } from "@query-farm/vgi-rpc";
5
+ import { schema } from "../../../arrow/index.js";
6
+ import type { CallContext } from "@query-farm/vgi-rpc";
7
+ import type { VgiService } from "../../../generated/vgi-service.js";
7
8
  import {
8
9
  encodeSchemaInfo,
9
10
  encodeTableInfo,
@@ -15,33 +16,15 @@ import { serveCatalogContents } from "./contents.js";
15
16
  import { encodeFunctionInfoOnce } from "../../../catalog/item-encoding.js";
16
17
  import { encodeCopyFromFormatInfo } from "../../../catalog/interface.js";
17
18
  import {
18
- CatalogAttachParamsSchema,
19
19
  CatalogAttachResultSchema,
20
- CatalogContentsParamsSchema,
21
- CatalogCatalogsParamsSchema,
22
20
  CatalogCatalogsResultSchema,
23
- CatalogCopyFromFormatsParamsSchema,
24
21
  CatalogCopyFromFormatsResultSchema,
25
- CatalogCreateParamsSchema,
26
- CatalogDetachParamsSchema,
27
- CatalogDropParamsSchema,
28
- CatalogSchemaContentsFunctionsParamsSchema,
29
22
  CatalogSchemaContentsFunctionsResultSchema,
30
- CatalogSchemaContentsTablesParamsSchema,
31
23
  CatalogSchemaContentsTablesResultSchema,
32
- CatalogSchemaContentsViewsParamsSchema,
33
24
  CatalogSchemaContentsViewsResultSchema,
34
- CatalogSchemaCreateParamsSchema,
35
- CatalogSchemaDropParamsSchema,
36
- CatalogSchemaGetParamsSchema,
37
25
  CatalogSchemaGetResultSchema,
38
- CatalogSchemasParamsSchema,
39
26
  CatalogSchemasResultSchema,
40
- CatalogTransactionBeginParamsSchema,
41
27
  CatalogTransactionBeginResultSchema,
42
- CatalogTransactionCommitParamsSchema,
43
- CatalogTransactionRollbackParamsSchema,
44
- CatalogVersionParamsSchema,
45
28
  CatalogVersionResultSchema,
46
29
  } from "../../../generated/vgi-protocol-schemas.js";
47
30
  import { toUint8Array } from "../../../util/bytes.js";
@@ -49,216 +32,173 @@ import { redeemAttachTicket } from "../../../attach-ticket.js";
49
32
  import { currentRequestAuth } from "../../../request-auth.js";
50
33
  import { decodeDictValue } from "../../../util/arrow/index.js";
51
34
  import {
52
- REQUEST_PARAMS_SCHEMA,
53
- RESULT_BINARY_SCHEMA,
54
35
  unwrapRequest,
55
36
  wrapResult,
56
37
  } from "../shared.js";
57
38
  import {
58
39
  type GetCatalog,
59
40
  decodeOptionsBatch,
60
- emptyResultSchema,
61
- catalogUnary,
41
+ catalogHandler,
62
42
  sealAttach,
63
43
  openAttach,
64
44
  sealTransaction,
65
45
  } from "./shared.js";
66
46
 
67
- export function registerCatalogAdminMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
47
+ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
68
48
  // catalog_catalogs
69
- catalogUnary(protocol, signingKey, "catalog_catalogs", {
70
- params: CatalogCatalogsParamsSchema,
71
- result: RESULT_BINARY_SCHEMA,
72
- handler: async () => {
73
- const cat = getCatalog();
74
- // Each catalog advertised as an IPC-serialized CatalogInfo
75
- // {name, implementation_version?, data_version_spec?}. Versioned workers
76
- // override catalogsInfo() to supply real values; otherwise both version
77
- // fields default to null.
78
- const infos = cat.catalogsInfo
79
- ? await cat.catalogsInfo()
80
- : cat.catalogs().map((name) => ({
81
- name,
82
- implementation_version: null,
83
- data_version_spec: null,
84
- attach_option_specs: [],
85
- releases: [],
86
- }));
87
- const items = infos.map((info) => encodeCatalogInfo(info));
88
- return wrapResult({ items }, CatalogCatalogsResultSchema);
89
- },
49
+ const catalogCatalogs = catalogHandler(signingKey, async () => {
50
+ const cat = getCatalog();
51
+ // Each catalog advertised as an IPC-serialized CatalogInfo
52
+ // {name, implementation_version?, data_version_spec?}. Versioned workers
53
+ // override catalogsInfo() to supply real values; otherwise both version
54
+ // fields default to null.
55
+ const infos = cat.catalogsInfo
56
+ ? await cat.catalogsInfo()
57
+ : cat.catalogs().map((name) => ({
58
+ name,
59
+ implementation_version: null,
60
+ data_version_spec: null,
61
+ attach_option_specs: [],
62
+ releases: [],
63
+ }));
64
+ const items = infos.map((info) => encodeCatalogInfo(info));
65
+ return wrapResult({ items }, CatalogCatalogsResultSchema);
90
66
  });
91
67
 
92
68
  // catalog_attach (params wrapped in request: Binary like bind/init)
93
- protocol.unary("catalog_attach", {
94
- params: CatalogAttachParamsSchema,
95
- result: RESULT_BINARY_SCHEMA,
96
- handler: async (params, ctx) => {
97
- const innerParams = unwrapRequest(params.request);
98
- const cat = getCatalog();
99
- // The extension sends user-supplied ATTACH options as an IPC-serialized
100
- // RecordBatch of typed columns — one column per option. Deserialize
101
- // once here so workers see an ergonomic {name: value} dict instead of
102
- // raw bytes. Nullable / absent → {}.
103
- let optionsDict = decodeOptionsBatch(innerParams.options);
104
- // A `vgi_attach_ticket` is redeemed here, before any catalog code runs:
105
- // the request becomes the attach the ticket seals (catalog name,
106
- // options, version specs). A composite catalog therefore routes on the
107
- // sealed name, not the request's. The ticket opens only under the
108
- // caller's principal and this worker's signing key; neither it nor a
109
- // restored option is ever logged.
110
- const restored = await redeemAttachTicket(
111
- optionsDict,
112
- signingKey,
113
- (ctx as CallContext | undefined)?.auth ?? currentRequestAuth(),
114
- );
115
- if (restored !== null) {
116
- innerParams.name = restored.name;
117
- innerParams.options = restored.optionsIpc;
118
- innerParams.data_version_spec = restored.dataVersionSpec;
119
- innerParams.implementation_version = restored.implementationVersion;
120
- optionsDict = restored.options;
121
- }
122
- const result = await cat.attach(
123
- innerParams.name,
124
- optionsDict,
125
- innerParams.data_version_spec ?? null,
126
- innerParams.implementation_version ?? null,
127
- );
128
- // Seal the attach value into an AEAD envelope bound to the caller's
129
- // identity before it leaves the worker (HTTP transport; pass-through
130
- // when there is no signing key).
131
- const sealedAttach = await sealAttach(
132
- toUint8Array(result.attach_opaque_data),
133
- (ctx as CallContext | undefined)?.auth,
134
- signingKey,
135
- );
136
- // The generated builder emits every column of the pinned
137
- // CatalogAttachResult schema, filling vgi-python's defaults for any a
138
- // catalog left out (supports_catalog_contents=false: the client then
139
- // keeps to the per-schema RPCs).
140
- return wrapResult(buildCatalogAttachResult({
141
- ...result,
142
- attach_opaque_data: sealedAttach,
143
- // SDK default, unlike vgi-python's false: true so DuckDB will route
144
- // catalog_table_column_statistics_get RPCs to our handler for tables
145
- // whose TableInfo.supports_column_statistics is also true. Catalogs
146
- // that never serve column stats set it false in attach().
147
- supports_column_statistics: result.supports_column_statistics ?? true,
148
- }), CatalogAttachResultSchema);
149
- },
150
- });
69
+ const catalogAttach: VgiService["catalogAttach"] = async (params, ctx) => {
70
+ const innerParams = unwrapRequest(params.request);
71
+ const cat = getCatalog();
72
+ // The extension sends user-supplied ATTACH options as an IPC-serialized
73
+ // RecordBatch of typed columns — one column per option. Deserialize
74
+ // once here so workers see an ergonomic {name: value} dict instead of
75
+ // raw bytes. Nullable / absent → {}.
76
+ let optionsDict = decodeOptionsBatch(innerParams.options);
77
+ // A `vgi_attach_ticket` is redeemed here, before any catalog code runs:
78
+ // the request becomes the attach the ticket seals (catalog name,
79
+ // options, version specs). A composite catalog therefore routes on the
80
+ // sealed name, not the request's. The ticket opens only under the
81
+ // caller's principal and this worker's signing key; neither it nor a
82
+ // restored option is ever logged.
83
+ const restored = await redeemAttachTicket(
84
+ optionsDict,
85
+ signingKey,
86
+ (ctx as CallContext | undefined)?.auth ?? currentRequestAuth(),
87
+ );
88
+ if (restored !== null) {
89
+ innerParams.name = restored.name;
90
+ innerParams.options = restored.optionsIpc;
91
+ innerParams.data_version_spec = restored.dataVersionSpec;
92
+ innerParams.implementation_version = restored.implementationVersion;
93
+ optionsDict = restored.options;
94
+ }
95
+ const result = await cat.attach(
96
+ innerParams.name,
97
+ optionsDict,
98
+ innerParams.data_version_spec ?? null,
99
+ innerParams.implementation_version ?? null,
100
+ );
101
+ // Seal the attach value into an AEAD envelope bound to the caller's
102
+ // identity before it leaves the worker (HTTP transport; pass-through
103
+ // when there is no signing key).
104
+ const sealedAttach = await sealAttach(
105
+ toUint8Array(result.attach_opaque_data),
106
+ (ctx as CallContext | undefined)?.auth,
107
+ signingKey,
108
+ );
109
+ // The generated builder emits every column of the pinned
110
+ // CatalogAttachResult schema, filling vgi-python's defaults for any a
111
+ // catalog left out (supports_catalog_contents=false: the client then
112
+ // keeps to the per-schema RPCs).
113
+ return wrapResult(buildCatalogAttachResult({
114
+ ...result,
115
+ attach_opaque_data: sealedAttach,
116
+ // SDK default, unlike vgi-python's false: true so DuckDB will route
117
+ // catalog_table_column_statistics_get RPCs to our handler for tables
118
+ // whose TableInfo.supports_column_statistics is also true. Catalogs
119
+ // that never serve column stats set it false in attach().
120
+ supports_column_statistics: result.supports_column_statistics ?? true,
121
+ }), CatalogAttachResultSchema);
122
+ };
151
123
 
152
124
  // catalog_detach
153
- catalogUnary(protocol, signingKey, "catalog_detach", {
154
- params: CatalogDetachParamsSchema,
155
- result: emptyResultSchema,
156
- handler: async (params) => {
157
- const cat = getCatalog();
158
- await cat.detach(toUint8Array(params.attach_opaque_data));
159
- return {};
160
- },
125
+ const catalogDetach = catalogHandler(signingKey, async (params) => {
126
+ const cat = getCatalog();
127
+ await cat.detach(toUint8Array(params.attach_opaque_data));
128
+ return {};
161
129
  });
162
130
 
163
131
  // catalog_create
164
- catalogUnary(protocol, signingKey, "catalog_create", {
165
- params: CatalogCreateParamsSchema,
166
- result: emptyResultSchema,
167
- handler: async (params) => {
168
- const cat = getCatalog();
169
- await cat.create(params.name, params.on_conflict, params.options);
170
- return {};
171
- },
132
+ const catalogCreate = catalogHandler(signingKey, async (params) => {
133
+ const cat = getCatalog();
134
+ await cat.create(params.name, params.on_conflict, params.options);
135
+ return {};
172
136
  });
173
137
 
174
138
  // catalog_drop
175
- catalogUnary(protocol, signingKey, "catalog_drop", {
176
- params: CatalogDropParamsSchema,
177
- result: emptyResultSchema,
178
- handler: async (params) => {
179
- const cat = getCatalog();
180
- await cat.drop(params.name);
181
- return {};
182
- },
139
+ const catalogDrop = catalogHandler(signingKey, async (params) => {
140
+ const cat = getCatalog();
141
+ await cat.drop(params.name);
142
+ return {};
183
143
  });
184
144
 
185
145
  // catalog_version
186
- catalogUnary(protocol, signingKey, "catalog_version", {
187
- params: CatalogVersionParamsSchema,
188
- result: RESULT_BINARY_SCHEMA,
189
- handler: async (params) => {
190
- const cat = getCatalog();
191
- const version = await cat.version(
192
- toUint8Array(params.attach_opaque_data),
193
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
194
- );
195
- return wrapResult({ version }, CatalogVersionResultSchema);
196
- },
146
+ const catalogVersion = catalogHandler(signingKey, async (params) => {
147
+ const cat = getCatalog();
148
+ const version = await cat.version(
149
+ toUint8Array(params.attach_opaque_data),
150
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
151
+ );
152
+ return wrapResult({ version }, CatalogVersionResultSchema);
197
153
  });
198
154
 
199
155
  // catalog_transaction_begin — bespoke: it must keep the *sealed* attach
200
156
  // envelope to bind the transaction envelope's AAD, so it cannot route
201
- // through catalogUnary (which would replace it with plaintext).
202
- protocol.unary("catalog_transaction_begin", {
203
- params: CatalogTransactionBeginParamsSchema,
204
- result: RESULT_BINARY_SCHEMA,
205
- handler: async (params, ctx) => {
206
- const auth = (ctx as CallContext | undefined)?.auth;
207
- const sealedAttach =
208
- params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
209
- const attachPlain = await openAttach(sealedAttach, auth, signingKey);
210
- const cat = getCatalog();
211
- const txPlain = await cat.transactionBegin(attachPlain);
212
- // Seal the transaction value, binding it to the caller's identity and
213
- // the parent attach envelope it was minted under. null → null.
214
- const transaction_opaque_data =
215
- txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
216
- return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
217
- },
218
- });
157
+ // through catalogHandler (which would replace it with plaintext).
158
+ const catalogTransactionBegin: VgiService["catalogTransactionBegin"] = async (params, ctx) => {
159
+ const auth = (ctx as CallContext | undefined)?.auth;
160
+ const sealedAttach =
161
+ params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
162
+ const attachPlain = await openAttach(sealedAttach, auth, signingKey);
163
+ const cat = getCatalog();
164
+ const txPlain = await cat.transactionBegin(attachPlain);
165
+ // Seal the transaction value, binding it to the caller's identity and
166
+ // the parent attach envelope it was minted under. null → null.
167
+ const transaction_opaque_data =
168
+ txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
169
+ return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
170
+ };
219
171
 
220
172
  // catalog_transaction_commit
221
- catalogUnary(protocol, signingKey, "catalog_transaction_commit", {
222
- params: CatalogTransactionCommitParamsSchema,
223
- result: emptyResultSchema,
224
- handler: async (params) => {
225
- const cat = getCatalog();
226
- await cat.transactionCommit(
227
- toUint8Array(params.attach_opaque_data),
228
- toUint8Array(params.transaction_opaque_data)
229
- );
230
- return {};
231
- },
173
+ const catalogTransactionCommit = catalogHandler(signingKey, async (params) => {
174
+ const cat = getCatalog();
175
+ await cat.transactionCommit(
176
+ toUint8Array(params.attach_opaque_data),
177
+ toUint8Array(params.transaction_opaque_data)
178
+ );
179
+ return {};
232
180
  });
233
181
 
234
182
  // catalog_transaction_rollback
235
- catalogUnary(protocol, signingKey, "catalog_transaction_rollback", {
236
- params: CatalogTransactionRollbackParamsSchema,
237
- result: emptyResultSchema,
238
- handler: async (params) => {
239
- const cat = getCatalog();
240
- await cat.transactionRollback(
241
- toUint8Array(params.attach_opaque_data),
242
- toUint8Array(params.transaction_opaque_data)
243
- );
244
- return {};
245
- },
183
+ const catalogTransactionRollback = catalogHandler(signingKey, async (params) => {
184
+ const cat = getCatalog();
185
+ await cat.transactionRollback(
186
+ toUint8Array(params.attach_opaque_data),
187
+ toUint8Array(params.transaction_opaque_data)
188
+ );
189
+ return {};
246
190
  });
247
191
 
248
192
  // catalog_schemas
249
- catalogUnary(protocol, signingKey, "catalog_schemas", {
250
- params: CatalogSchemasParamsSchema,
251
- result: RESULT_BINARY_SCHEMA,
252
- handler: async (params) => {
253
- const cat = getCatalog();
254
- const schemas = await cat.schemas(
255
- toUint8Array(params.attach_opaque_data),
256
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
257
- );
258
- return wrapResult({
259
- items: schemas.map((s) => encodeSchemaInfo(s)),
260
- }, CatalogSchemasResultSchema);
261
- },
193
+ const catalogSchemas = catalogHandler(signingKey, async (params) => {
194
+ const cat = getCatalog();
195
+ const schemas = await cat.schemas(
196
+ toUint8Array(params.attach_opaque_data),
197
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
198
+ );
199
+ return wrapResult({
200
+ items: schemas.map((s) => encodeSchemaInfo(s)),
201
+ }, CatalogSchemasResultSchema);
262
202
  });
263
203
 
264
204
  // catalog_contents — every schema and all of its contents in one result,
@@ -267,134 +207,123 @@ export function registerCatalogAdminMethods(protocol: Protocol, getCatalog: GetC
267
207
  // the committed catalog at catalog_version. `if_none_match` revalidates a
268
208
  // snapshot the client holds (etag / not_modified); see ./contents.ts for the
269
209
  // rules, the content-hash etag and the frozen-catalog cache.
270
- catalogUnary(protocol, signingKey, "catalog_contents", {
271
- params: CatalogContentsParamsSchema,
272
- result: RESULT_BINARY_SCHEMA,
273
- handler: async (params) => {
274
- const ifNoneMatch = params.if_none_match == null ? null : String(params.if_none_match);
275
- return serveCatalogContents(getCatalog(), toUint8Array(params.attach_opaque_data), ifNoneMatch);
276
- },
210
+ const catalogContents = catalogHandler(signingKey, async (params) => {
211
+ const ifNoneMatch = params.if_none_match == null ? null : String(params.if_none_match);
212
+ return serveCatalogContents(getCatalog(), toUint8Array(params.attach_opaque_data), ifNoneMatch);
277
213
  });
278
214
 
279
215
  // catalog_copy_from_formats — catalog-level (not schema-scoped). Lists the
280
216
  // custom COPY ... FROM formats this catalog advertises; empty list when none.
281
- catalogUnary(protocol, signingKey, "catalog_copy_from_formats", {
282
- params: CatalogCopyFromFormatsParamsSchema,
283
- result: RESULT_BINARY_SCHEMA,
284
- handler: async (params) => {
285
- const cat = getCatalog();
286
- const formats = await cat.copyFromFormats(
287
- toUint8Array(params.attach_opaque_data),
288
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
289
- );
290
- return wrapResult({
291
- items: formats.map((f) => encodeCopyFromFormatInfo(f)),
292
- }, CatalogCopyFromFormatsResultSchema);
293
- },
217
+ const catalogCopyFromFormats = catalogHandler(signingKey, async (params) => {
218
+ const cat = getCatalog();
219
+ const formats = await cat.copyFromFormats(
220
+ toUint8Array(params.attach_opaque_data),
221
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
222
+ );
223
+ return wrapResult({
224
+ items: formats.map((f) => encodeCopyFromFormatInfo(f)),
225
+ }, CatalogCopyFromFormatsResultSchema);
294
226
  });
295
227
 
296
228
  // catalog_schema_get
297
- catalogUnary(protocol, signingKey, "catalog_schema_get", {
298
- params: CatalogSchemaGetParamsSchema,
299
- result: RESULT_BINARY_SCHEMA,
300
- handler: async (params) => {
301
- const cat = getCatalog();
302
- const info = await cat.schemaGet(
303
- toUint8Array(params.attach_opaque_data),
304
- params.path,
305
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
306
- );
307
- return wrapResult({
308
- items: info ? [encodeSchemaInfo(info)] : [],
309
- }, CatalogSchemaGetResultSchema);
310
- },
229
+ const catalogSchemaGet = catalogHandler(signingKey, async (params) => {
230
+ const cat = getCatalog();
231
+ const info = await cat.schemaGet(
232
+ toUint8Array(params.attach_opaque_data),
233
+ params.path,
234
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
235
+ );
236
+ return wrapResult({
237
+ items: info ? [encodeSchemaInfo(info)] : [],
238
+ }, CatalogSchemaGetResultSchema);
311
239
  });
312
240
 
313
241
  // catalog_schema_create
314
- catalogUnary(protocol, signingKey, "catalog_schema_create", {
315
- params: CatalogSchemaCreateParamsSchema,
316
- result: emptyResultSchema,
317
- handler: async (params) => {
318
- const cat = getCatalog();
319
- await cat.schemaCreate(
320
- toUint8Array(params.attach_opaque_data),
321
- params.path,
322
- params.comment,
323
- null, // tags
324
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
325
- );
326
- return {};
327
- },
242
+ const catalogSchemaCreate = catalogHandler(signingKey, async (params) => {
243
+ const cat = getCatalog();
244
+ await cat.schemaCreate(
245
+ toUint8Array(params.attach_opaque_data),
246
+ params.path,
247
+ params.comment,
248
+ null, // tags
249
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
250
+ );
251
+ return {};
328
252
  });
329
253
 
330
254
  // catalog_schema_drop
331
- catalogUnary(protocol, signingKey, "catalog_schema_drop", {
332
- params: CatalogSchemaDropParamsSchema,
333
- result: emptyResultSchema,
334
- handler: async (params) => {
335
- const cat = getCatalog();
336
- await cat.schemaDrop(
337
- toUint8Array(params.attach_opaque_data),
338
- params.path,
339
- params.ignore_not_found,
340
- params.cascade,
341
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
342
- );
343
- return {};
344
- },
255
+ const catalogSchemaDrop = catalogHandler(signingKey, async (params) => {
256
+ const cat = getCatalog();
257
+ await cat.schemaDrop(
258
+ toUint8Array(params.attach_opaque_data),
259
+ params.path,
260
+ params.ignore_not_found,
261
+ params.cascade,
262
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
263
+ );
264
+ return {};
345
265
  });
346
266
 
347
267
  // catalog_schema_contents_tables
348
- catalogUnary(protocol, signingKey, "catalog_schema_contents_tables", {
349
- params: CatalogSchemaContentsTablesParamsSchema,
350
- result: RESULT_BINARY_SCHEMA,
351
- handler: async (params) => {
352
- const cat = getCatalog();
353
- const tables = await cat.schemaContentsTables(
354
- toUint8Array(params.attach_opaque_data),
355
- params.path,
356
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
357
- );
358
- return wrapResult({
359
- items: tables.map((t) => encodeTableInfo(t)),
360
- }, CatalogSchemaContentsTablesResultSchema);
361
- },
268
+ const catalogSchemaContentsTables = catalogHandler(signingKey, async (params) => {
269
+ const cat = getCatalog();
270
+ const tables = await cat.schemaContentsTables(
271
+ toUint8Array(params.attach_opaque_data),
272
+ params.path,
273
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
274
+ );
275
+ return wrapResult({
276
+ items: tables.map((t) => encodeTableInfo(t)),
277
+ }, CatalogSchemaContentsTablesResultSchema);
362
278
  });
363
279
 
364
280
  // catalog_schema_contents_views
365
- catalogUnary(protocol, signingKey, "catalog_schema_contents_views", {
366
- params: CatalogSchemaContentsViewsParamsSchema,
367
- result: RESULT_BINARY_SCHEMA,
368
- handler: async (params) => {
369
- const cat = getCatalog();
370
- const views = await cat.schemaContentsViews(
371
- toUint8Array(params.attach_opaque_data),
372
- params.path,
373
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
374
- );
375
- return wrapResult({
376
- items: views.map((v) => encodeViewInfo(v)),
377
- }, CatalogSchemaContentsViewsResultSchema);
378
- },
281
+ const catalogSchemaContentsViews = catalogHandler(signingKey, async (params) => {
282
+ const cat = getCatalog();
283
+ const views = await cat.schemaContentsViews(
284
+ toUint8Array(params.attach_opaque_data),
285
+ params.path,
286
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
287
+ );
288
+ return wrapResult({
289
+ items: views.map((v) => encodeViewInfo(v)),
290
+ }, CatalogSchemaContentsViewsResultSchema);
379
291
  });
380
292
 
381
293
  // catalog_schema_contents_functions
382
- catalogUnary(protocol, signingKey, "catalog_schema_contents_functions", {
383
- params: CatalogSchemaContentsFunctionsParamsSchema,
384
- result: RESULT_BINARY_SCHEMA,
385
- handler: async (params) => {
386
- const cat = getCatalog();
387
- const funcs = await cat.schemaContentsFunctions(
388
- toUint8Array(params.attach_opaque_data),
389
- params.path,
390
- decodeDictValue(params.type),
391
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
392
- );
393
- // A frozen item (a descriptor catalog's cached listing) is encoded once;
394
- // anything else is encoded per call, as before (see item-encoding.ts).
395
- return wrapResult({
396
- items: funcs.map((f) => encodeFunctionInfoOnce(f)),
397
- }, CatalogSchemaContentsFunctionsResultSchema);
398
- },
294
+ const catalogSchemaContentsFunctions = catalogHandler(signingKey, async (params) => {
295
+ const cat = getCatalog();
296
+ const funcs = await cat.schemaContentsFunctions(
297
+ toUint8Array(params.attach_opaque_data),
298
+ params.path,
299
+ decodeDictValue(params.type),
300
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
301
+ );
302
+ // A frozen item (a descriptor catalog's cached listing) is encoded once;
303
+ // anything else is encoded per call, as before (see item-encoding.ts).
304
+ return wrapResult({
305
+ items: funcs.map((f) => encodeFunctionInfoOnce(f)),
306
+ }, CatalogSchemaContentsFunctionsResultSchema);
399
307
  });
308
+
309
+ return {
310
+ catalogCatalogs,
311
+ catalogAttach,
312
+ catalogDetach,
313
+ catalogCreate,
314
+ catalogDrop,
315
+ catalogVersion,
316
+ catalogTransactionBegin,
317
+ catalogTransactionCommit,
318
+ catalogTransactionRollback,
319
+ catalogSchemas,
320
+ catalogContents,
321
+ catalogCopyFromFormats,
322
+ catalogSchemaGet,
323
+ catalogSchemaCreate,
324
+ catalogSchemaDrop,
325
+ catalogSchemaContentsTables,
326
+ catalogSchemaContentsViews,
327
+ catalogSchemaContentsFunctions,
328
+ };
400
329
  }