@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.
- package/LICENSE +134 -0
- package/README.md +494 -0
- package/dist/__dbg.test-d.d.ts +1 -0
- package/dist/arguments/argument-spec.d.ts +51 -0
- package/dist/arguments/arguments.d.ts +13 -0
- package/dist/arrow/codec/branded.d.ts +83 -0
- package/dist/arrow/codec/registry.d.ts +29 -0
- package/dist/arrow/codec/repr.d.ts +23 -0
- package/dist/arrow/codec/type-descriptors.d.ts +109 -0
- package/dist/arrow/impl-arrowjs/build.d.ts +19 -0
- package/dist/arrow/impl-arrowjs/canonical.d.ts +15 -0
- package/dist/arrow/impl-arrowjs/empty.d.ts +7 -0
- package/dist/arrow/impl-arrowjs/filter.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/index.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/ipc.d.ts +24 -0
- package/dist/arrow/impl-arrowjs/iterate.d.ts +39 -0
- package/dist/arrow/impl-arrowjs/project.d.ts +10 -0
- package/dist/arrow/impl-arrowjs/schema.d.ts +62 -0
- package/dist/arrow/impl-arrowjs/statistics.d.ts +13 -0
- package/dist/arrow/impl-flechette/build.d.ts +14 -0
- package/dist/arrow/impl-flechette/canonical.d.ts +18 -0
- package/dist/arrow/impl-flechette/empty.d.ts +9 -0
- package/dist/arrow/impl-flechette/filter.d.ts +10 -0
- package/dist/arrow/impl-flechette/index.d.ts +11 -0
- package/dist/arrow/impl-flechette/ipc.d.ts +33 -0
- package/dist/arrow/impl-flechette/iterate.d.ts +29 -0
- package/dist/arrow/impl-flechette/message-meta.d.ts +10 -0
- package/dist/arrow/impl-flechette/normalize-type.d.ts +11 -0
- package/dist/arrow/impl-flechette/project.d.ts +3 -0
- package/dist/arrow/impl-flechette/schema.d.ts +47 -0
- package/dist/arrow/impl-flechette/statistics.d.ts +13 -0
- package/dist/arrow/index.d.ts +11 -0
- package/dist/arrow/predicates.d.ts +47 -0
- package/dist/arrow/repr.test-d.d.ts +52 -0
- package/dist/arrow/schema-types.d.ts +71 -0
- package/dist/arrow/types.d.ts +57 -0
- package/dist/catalog/attach-option.d.ts +33 -0
- package/dist/catalog/attach-options.d.ts +30 -0
- package/dist/catalog/composite.d.ts +33 -0
- package/dist/catalog/descriptors.d.ts +154 -0
- package/dist/catalog/interface.d.ts +239 -0
- package/dist/catalog/read-only.d.ts +33 -0
- package/dist/client/client.d.ts +189 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/helpers.d.ts +12 -0
- package/dist/client/protocol.d.ts +16 -0
- package/dist/client/types.d.ts +125 -0
- package/dist/client-entry.d.ts +11 -0
- package/dist/client-entry.js +48 -0
- package/dist/client-entry.js.map +9 -0
- package/dist/codec/asd.d.ts +25 -0
- package/dist/crypto.d.ts +36 -0
- package/dist/errors.d.ts +24 -0
- package/dist/filter-pushdown/collector.d.ts +32 -0
- package/dist/filter-pushdown/deserialize.d.ts +16 -0
- package/dist/filter-pushdown/evaluate.d.ts +51 -0
- package/dist/filter-pushdown/index.d.ts +4 -0
- package/dist/filter-pushdown/types.d.ts +84 -0
- package/dist/functions/aggregate.d.ts +129 -0
- package/dist/functions/copy-from.d.ts +81 -0
- package/dist/functions/copy-to.d.ts +121 -0
- package/dist/functions/registry.d.ts +16 -0
- package/dist/functions/scalar.d.ts +98 -0
- package/dist/functions/storage-cf-do.d.ts +47 -0
- package/dist/functions/storage.d.ts +86 -0
- package/dist/functions/table-buffering.d.ts +99 -0
- package/dist/functions/table-in-out.d.ts +64 -0
- package/dist/functions/table.d.ts +118 -0
- package/dist/functions/types.d.ts +157 -0
- package/dist/generated/vgi-client.d.ts +466 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +115 -0
- package/dist/index.core.d.ts +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10888 -0
- package/dist/index.js.map +85 -0
- package/dist/metadata/resolve.d.ts +3 -0
- package/dist/metadata/serialize.d.ts +12 -0
- package/dist/metadata/types.d.ts +47 -0
- package/dist/protocol/dispatch.d.ts +23 -0
- package/dist/protocol/handlers/aggregate.d.ts +3 -0
- package/dist/protocol/handlers/catalog/admin.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index_methods.d.ts +3 -0
- package/dist/protocol/handlers/catalog/macro.d.ts +3 -0
- package/dist/protocol/handlers/catalog/shared.d.ts +70 -0
- package/dist/protocol/handlers/catalog/table.d.ts +3 -0
- package/dist/protocol/handlers/catalog/view.d.ts +3 -0
- package/dist/protocol/handlers/function.d.ts +8 -0
- package/dist/protocol/handlers/shared.d.ts +31 -0
- package/dist/protocol/handlers/table-buffering.d.ts +3 -0
- package/dist/protocol/serialize.d.ts +4 -0
- package/dist/protocol/serializers/arguments.d.ts +3 -0
- package/dist/protocol/serializers/bind.d.ts +9 -0
- package/dist/protocol/serializers/cardinality.d.ts +7 -0
- package/dist/protocol/serializers/init.d.ts +9 -0
- package/dist/protocol/serializers/shared.d.ts +12 -0
- package/dist/protocol/state-serializer.d.ts +23 -0
- package/dist/protocol/types.d.ts +129 -0
- package/dist/secrets/helpers.d.ts +15 -0
- package/dist/types.d.ts +52 -0
- package/dist/util/arrow/index.d.ts +1 -0
- package/dist/util/bytes.d.ts +2 -0
- package/dist/util/statistics.d.ts +7 -0
- package/dist/worker-cf-entry.d.ts +30 -0
- package/dist/worker-cf-entry.js +8767 -0
- package/dist/worker-cf-entry.js.map +74 -0
- package/dist/worker.d.ts +36 -0
- package/package.json +96 -0
- package/src/arguments/argument-spec.ts +200 -0
- package/src/arguments/arguments.ts +81 -0
- package/src/arrow/codec/branded.ts +206 -0
- package/src/arrow/codec/registry.ts +674 -0
- package/src/arrow/codec/repr.ts +181 -0
- package/src/arrow/codec/type-descriptors.ts +137 -0
- package/src/arrow/impl-arrowjs/build.ts +88 -0
- package/src/arrow/impl-arrowjs/canonical.ts +509 -0
- package/src/arrow/impl-arrowjs/empty.ts +72 -0
- package/src/arrow/impl-arrowjs/filter.ts +53 -0
- package/src/arrow/impl-arrowjs/index.ts +54 -0
- package/src/arrow/impl-arrowjs/ipc.ts +67 -0
- package/src/arrow/impl-arrowjs/iterate.ts +159 -0
- package/src/arrow/impl-arrowjs/project.ts +73 -0
- package/src/arrow/impl-arrowjs/schema.ts +256 -0
- package/src/arrow/impl-arrowjs/statistics.ts +185 -0
- package/src/arrow/impl-flechette/build.ts +65 -0
- package/src/arrow/impl-flechette/canonical.ts +289 -0
- package/src/arrow/impl-flechette/empty.ts +20 -0
- package/src/arrow/impl-flechette/filter.ts +42 -0
- package/src/arrow/impl-flechette/index.ts +54 -0
- package/src/arrow/impl-flechette/ipc.ts +110 -0
- package/src/arrow/impl-flechette/iterate.ts +121 -0
- package/src/arrow/impl-flechette/message-meta.ts +175 -0
- package/src/arrow/impl-flechette/normalize-type.ts +99 -0
- package/src/arrow/impl-flechette/project.ts +64 -0
- package/src/arrow/impl-flechette/schema.ts +202 -0
- package/src/arrow/impl-flechette/statistics.ts +198 -0
- package/src/arrow/index.ts +129 -0
- package/src/arrow/predicates.ts +66 -0
- package/src/arrow/repr.test-d.ts +189 -0
- package/src/arrow/schema-types.ts +213 -0
- package/src/arrow/types.ts +74 -0
- package/src/catalog/attach-option.ts +107 -0
- package/src/catalog/attach-options.ts +79 -0
- package/src/catalog/composite.ts +180 -0
- package/src/catalog/descriptors.ts +164 -0
- package/src/catalog/interface.ts +721 -0
- package/src/catalog/read-only.ts +909 -0
- package/src/client/client.ts +1348 -0
- package/src/client/errors.ts +69 -0
- package/src/client/helpers.ts +56 -0
- package/src/client/protocol.ts +33 -0
- package/src/client/types.ts +140 -0
- package/src/client-entry.ts +112 -0
- package/src/codec/asd.ts +147 -0
- package/src/crypto.ts +143 -0
- package/src/errors.ts +61 -0
- package/src/filter-pushdown/collector.ts +147 -0
- package/src/filter-pushdown/deserialize.ts +253 -0
- package/src/filter-pushdown/evaluate.ts +591 -0
- package/src/filter-pushdown/index.ts +28 -0
- package/src/filter-pushdown/types.ts +91 -0
- package/src/functions/aggregate.ts +384 -0
- package/src/functions/copy-from.ts +282 -0
- package/src/functions/copy-to.ts +319 -0
- package/src/functions/registry.ts +258 -0
- package/src/functions/scalar.ts +356 -0
- package/src/functions/storage-cf-do.ts +303 -0
- package/src/functions/storage.ts +521 -0
- package/src/functions/table-buffering.ts +562 -0
- package/src/functions/table-in-out.ts +373 -0
- package/src/functions/table.ts +521 -0
- package/src/functions/types.ts +192 -0
- package/src/generated/vgi-client.ts +560 -0
- package/src/generated/vgi-protocol-schemas.ts +864 -0
- package/src/index.core.ts +267 -0
- package/src/index.ts +11 -0
- package/src/metadata/resolve.ts +109 -0
- package/src/metadata/serialize.ts +242 -0
- package/src/metadata/types.ts +60 -0
- package/src/protocol/dispatch.ts +52 -0
- package/src/protocol/handlers/aggregate.ts +355 -0
- package/src/protocol/handlers/catalog/admin.ts +368 -0
- package/src/protocol/handlers/catalog/index.ts +25 -0
- package/src/protocol/handlers/catalog/index_methods.ts +65 -0
- package/src/protocol/handlers/catalog/macro.ts +114 -0
- package/src/protocol/handlers/catalog/shared.ts +291 -0
- package/src/protocol/handlers/catalog/table.ts +401 -0
- package/src/protocol/handlers/catalog/view.ts +119 -0
- package/src/protocol/handlers/function.ts +302 -0
- package/src/protocol/handlers/shared.ts +80 -0
- package/src/protocol/handlers/table-buffering.ts +207 -0
- package/src/protocol/serialize.ts +23 -0
- package/src/protocol/serializers/arguments.ts +160 -0
- package/src/protocol/serializers/bind.ts +212 -0
- package/src/protocol/serializers/cardinality.ts +45 -0
- package/src/protocol/serializers/init.ts +247 -0
- package/src/protocol/serializers/shared.ts +46 -0
- package/src/protocol/state-serializer.ts +181 -0
- package/src/protocol/types.ts +153 -0
- package/src/secrets/helpers.ts +70 -0
- package/src/types.ts +71 -0
- package/src/util/arrow/index.ts +23 -0
- package/src/util/bytes.ts +14 -0
- package/src/util/statistics.ts +40 -0
- package/src/worker-cf-entry.ts +172 -0
- package/src/worker.ts +212 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Catalog admin handlers: attach/detach/create/drop, version, transactions,
|
|
3
|
+
// schemas (list, get, create, drop), schema contents listings.
|
|
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";
|
|
7
|
+
import { encodeSchemaInfo, encodeTableInfo, encodeViewInfo, encodeFunctionInfo, encodeCatalogInfo } from "../../../generated/vgi-client.js";
|
|
8
|
+
import { encodeCopyFromFormatInfo } from "../../../catalog/interface.js";
|
|
9
|
+
import {
|
|
10
|
+
CatalogCatalogsResultSchema,
|
|
11
|
+
CatalogAttachResultSchema,
|
|
12
|
+
CatalogVersionResultSchema,
|
|
13
|
+
CatalogTransactionBeginResultSchema,
|
|
14
|
+
CatalogSchemasResultSchema,
|
|
15
|
+
CatalogSchemaGetResultSchema,
|
|
16
|
+
CatalogSchemaContentsTablesResultSchema,
|
|
17
|
+
CatalogSchemaContentsViewsResultSchema,
|
|
18
|
+
CatalogSchemaContentsFunctionsResultSchema,
|
|
19
|
+
CatalogCopyFromFormatsResultSchema,
|
|
20
|
+
} from "../../../generated/vgi-protocol-schemas.js";
|
|
21
|
+
import { toUint8Array } from "../../../util/bytes.js";
|
|
22
|
+
import { decodeDictValue } from "../../../util/arrow/index.js";
|
|
23
|
+
import {
|
|
24
|
+
REQUEST_PARAMS_SCHEMA,
|
|
25
|
+
RESULT_BINARY_SCHEMA,
|
|
26
|
+
unwrapRequest,
|
|
27
|
+
wrapResult,
|
|
28
|
+
} from "../shared.js";
|
|
29
|
+
import {
|
|
30
|
+
type GetCatalog,
|
|
31
|
+
decodeOptionsBatch,
|
|
32
|
+
emptyResultSchema,
|
|
33
|
+
attachOpaqueDataParam,
|
|
34
|
+
attachOpaqueDataTxnParams,
|
|
35
|
+
attachOpaqueDataNameTxnParams,
|
|
36
|
+
catalogUnary,
|
|
37
|
+
sealAttach,
|
|
38
|
+
openAttach,
|
|
39
|
+
sealTransaction,
|
|
40
|
+
} from "./shared.js";
|
|
41
|
+
|
|
42
|
+
export function registerCatalogAdminMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
|
|
43
|
+
// catalog_catalogs
|
|
44
|
+
catalogUnary(protocol, signingKey, "catalog_catalogs", {
|
|
45
|
+
params: emptyResultSchema,
|
|
46
|
+
result: RESULT_BINARY_SCHEMA,
|
|
47
|
+
handler: async () => {
|
|
48
|
+
const cat = getCatalog();
|
|
49
|
+
// Each catalog advertised as an IPC-serialized CatalogInfo
|
|
50
|
+
// {name, implementation_version?, data_version_spec?}. Versioned workers
|
|
51
|
+
// override catalogsInfo() to supply real values; otherwise both version
|
|
52
|
+
// fields default to null.
|
|
53
|
+
const infos = cat.catalogsInfo
|
|
54
|
+
? await cat.catalogsInfo()
|
|
55
|
+
: cat.catalogs().map((name) => ({
|
|
56
|
+
name,
|
|
57
|
+
implementation_version: null,
|
|
58
|
+
data_version_spec: null,
|
|
59
|
+
attach_option_specs: [],
|
|
60
|
+
releases: [],
|
|
61
|
+
}));
|
|
62
|
+
const items = infos.map((info) => encodeCatalogInfo(info));
|
|
63
|
+
return wrapResult({ items }, CatalogCatalogsResultSchema);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// catalog_attach (params wrapped in request: Binary like bind/init)
|
|
68
|
+
protocol.unary("catalog_attach", {
|
|
69
|
+
params: REQUEST_PARAMS_SCHEMA,
|
|
70
|
+
result: RESULT_BINARY_SCHEMA,
|
|
71
|
+
handler: async (params, ctx) => {
|
|
72
|
+
const innerParams = unwrapRequest(params.request);
|
|
73
|
+
const cat = getCatalog();
|
|
74
|
+
// The extension sends user-supplied ATTACH options as an IPC-serialized
|
|
75
|
+
// RecordBatch of typed columns — one column per option. Deserialize
|
|
76
|
+
// once here so workers see an ergonomic {name: value} dict instead of
|
|
77
|
+
// raw bytes. Nullable / absent → {}.
|
|
78
|
+
const optionsDict = decodeOptionsBatch(innerParams.options);
|
|
79
|
+
const result = await cat.attach(
|
|
80
|
+
innerParams.name,
|
|
81
|
+
optionsDict,
|
|
82
|
+
innerParams.data_version_spec ?? null,
|
|
83
|
+
innerParams.implementation_version ?? null,
|
|
84
|
+
);
|
|
85
|
+
// Seal the attach value into an AEAD envelope bound to the caller's
|
|
86
|
+
// identity before it leaves the worker (HTTP transport; pass-through
|
|
87
|
+
// when there is no signing key).
|
|
88
|
+
const sealedAttach = await sealAttach(
|
|
89
|
+
toUint8Array(result.attach_opaque_data),
|
|
90
|
+
(ctx as CallContext | undefined)?.auth,
|
|
91
|
+
signingKey,
|
|
92
|
+
);
|
|
93
|
+
return wrapResult({
|
|
94
|
+
attach_opaque_data: sealedAttach,
|
|
95
|
+
supports_transactions: result.supports_transactions,
|
|
96
|
+
supports_time_travel: result.supports_time_travel,
|
|
97
|
+
catalog_version_frozen: result.catalog_version_frozen,
|
|
98
|
+
catalog_version: result.catalog_version,
|
|
99
|
+
attach_opaque_data_required: result.attach_opaque_data_required ?? true,
|
|
100
|
+
default_schema: result.default_schema ?? "main",
|
|
101
|
+
settings: result.settings ?? [],
|
|
102
|
+
secret_types: result.secret_types ?? [],
|
|
103
|
+
comment: result.comment ?? null,
|
|
104
|
+
tags: result.tags ?? {},
|
|
105
|
+
// True so DuckDB will route catalog_table_column_statistics_get RPCs
|
|
106
|
+
// to our handler for tables whose TableInfo.supports_column_statistics
|
|
107
|
+
// is also true. Catalogs that never serve column stats can override
|
|
108
|
+
// this in attach() via CatalogAttachResult.supports_column_statistics.
|
|
109
|
+
supports_column_statistics: result.supports_column_statistics ?? true,
|
|
110
|
+
resolved_data_version: result.resolved_data_version ?? null,
|
|
111
|
+
resolved_implementation_version: result.resolved_implementation_version ?? null,
|
|
112
|
+
}, CatalogAttachResultSchema);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// catalog_detach
|
|
117
|
+
catalogUnary(protocol, signingKey, "catalog_detach", {
|
|
118
|
+
params: attachOpaqueDataParam,
|
|
119
|
+
result: emptyResultSchema,
|
|
120
|
+
handler: async (params) => {
|
|
121
|
+
const cat = getCatalog();
|
|
122
|
+
await cat.detach(toUint8Array(params.attach_opaque_data));
|
|
123
|
+
return {};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// catalog_create
|
|
128
|
+
catalogUnary(protocol, signingKey, "catalog_create", {
|
|
129
|
+
params: schema([
|
|
130
|
+
field("name", utf8(), false),
|
|
131
|
+
field("on_conflict", utf8(), false),
|
|
132
|
+
field("options", binary(), true),
|
|
133
|
+
]),
|
|
134
|
+
result: emptyResultSchema,
|
|
135
|
+
handler: async (params) => {
|
|
136
|
+
const cat = getCatalog();
|
|
137
|
+
await cat.create(params.name, params.on_conflict, params.options);
|
|
138
|
+
return {};
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// catalog_drop
|
|
143
|
+
catalogUnary(protocol, signingKey, "catalog_drop", {
|
|
144
|
+
params: schema([field("name", utf8(), false)]),
|
|
145
|
+
result: emptyResultSchema,
|
|
146
|
+
handler: async (params) => {
|
|
147
|
+
const cat = getCatalog();
|
|
148
|
+
await cat.drop(params.name);
|
|
149
|
+
return {};
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// catalog_version
|
|
154
|
+
catalogUnary(protocol, signingKey, "catalog_version", {
|
|
155
|
+
params: attachOpaqueDataTxnParams,
|
|
156
|
+
result: RESULT_BINARY_SCHEMA,
|
|
157
|
+
handler: async (params) => {
|
|
158
|
+
const cat = getCatalog();
|
|
159
|
+
const version = await cat.version(
|
|
160
|
+
toUint8Array(params.attach_opaque_data),
|
|
161
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
162
|
+
);
|
|
163
|
+
return wrapResult({ version }, CatalogVersionResultSchema);
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// catalog_transaction_begin — bespoke: it must keep the *sealed* attach
|
|
168
|
+
// envelope to bind the transaction envelope's AAD, so it cannot route
|
|
169
|
+
// through catalogUnary (which would replace it with plaintext).
|
|
170
|
+
protocol.unary("catalog_transaction_begin", {
|
|
171
|
+
params: attachOpaqueDataParam,
|
|
172
|
+
result: RESULT_BINARY_SCHEMA,
|
|
173
|
+
handler: async (params, ctx) => {
|
|
174
|
+
const auth = (ctx as CallContext | undefined)?.auth;
|
|
175
|
+
const sealedAttach =
|
|
176
|
+
params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
|
|
177
|
+
const attachPlain = await openAttach(sealedAttach, auth, signingKey);
|
|
178
|
+
const cat = getCatalog();
|
|
179
|
+
const txPlain = await cat.transactionBegin(attachPlain);
|
|
180
|
+
// Seal the transaction value, binding it to the caller's identity and
|
|
181
|
+
// the parent attach envelope it was minted under. null → null.
|
|
182
|
+
const transaction_opaque_data =
|
|
183
|
+
txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
|
|
184
|
+
return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// catalog_transaction_commit
|
|
189
|
+
catalogUnary(protocol, signingKey, "catalog_transaction_commit", {
|
|
190
|
+
params: attachOpaqueDataTxnParams,
|
|
191
|
+
result: emptyResultSchema,
|
|
192
|
+
handler: async (params) => {
|
|
193
|
+
const cat = getCatalog();
|
|
194
|
+
await cat.transactionCommit(
|
|
195
|
+
toUint8Array(params.attach_opaque_data),
|
|
196
|
+
toUint8Array(params.transaction_opaque_data)
|
|
197
|
+
);
|
|
198
|
+
return {};
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// catalog_transaction_rollback
|
|
203
|
+
catalogUnary(protocol, signingKey, "catalog_transaction_rollback", {
|
|
204
|
+
params: attachOpaqueDataTxnParams,
|
|
205
|
+
result: emptyResultSchema,
|
|
206
|
+
handler: async (params) => {
|
|
207
|
+
const cat = getCatalog();
|
|
208
|
+
await cat.transactionRollback(
|
|
209
|
+
toUint8Array(params.attach_opaque_data),
|
|
210
|
+
toUint8Array(params.transaction_opaque_data)
|
|
211
|
+
);
|
|
212
|
+
return {};
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// catalog_schemas
|
|
217
|
+
catalogUnary(protocol, signingKey, "catalog_schemas", {
|
|
218
|
+
params: attachOpaqueDataTxnParams,
|
|
219
|
+
result: RESULT_BINARY_SCHEMA,
|
|
220
|
+
handler: async (params) => {
|
|
221
|
+
const cat = getCatalog();
|
|
222
|
+
const schemas = await cat.schemas(
|
|
223
|
+
toUint8Array(params.attach_opaque_data),
|
|
224
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
225
|
+
);
|
|
226
|
+
return wrapResult({
|
|
227
|
+
items: schemas.map((s) => encodeSchemaInfo(s)),
|
|
228
|
+
}, CatalogSchemasResultSchema);
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// catalog_copy_from_formats — catalog-level (not schema-scoped). Lists the
|
|
233
|
+
// custom COPY ... FROM formats this catalog advertises; empty list when none.
|
|
234
|
+
catalogUnary(protocol, signingKey, "catalog_copy_from_formats", {
|
|
235
|
+
params: attachOpaqueDataTxnParams,
|
|
236
|
+
result: RESULT_BINARY_SCHEMA,
|
|
237
|
+
handler: async (params) => {
|
|
238
|
+
const cat = getCatalog();
|
|
239
|
+
const formats = await cat.copyFromFormats(
|
|
240
|
+
toUint8Array(params.attach_opaque_data),
|
|
241
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
|
|
242
|
+
);
|
|
243
|
+
return wrapResult({
|
|
244
|
+
items: formats.map((f) => encodeCopyFromFormatInfo(f)),
|
|
245
|
+
}, CatalogCopyFromFormatsResultSchema);
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// catalog_schema_get
|
|
250
|
+
catalogUnary(protocol, signingKey, "catalog_schema_get", {
|
|
251
|
+
params: attachOpaqueDataNameTxnParams,
|
|
252
|
+
result: RESULT_BINARY_SCHEMA,
|
|
253
|
+
handler: async (params) => {
|
|
254
|
+
const cat = getCatalog();
|
|
255
|
+
const info = await cat.schemaGet(
|
|
256
|
+
toUint8Array(params.attach_opaque_data),
|
|
257
|
+
params.name,
|
|
258
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
259
|
+
);
|
|
260
|
+
return wrapResult({
|
|
261
|
+
items: info ? [encodeSchemaInfo(info)] : [],
|
|
262
|
+
}, CatalogSchemaGetResultSchema);
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// catalog_schema_create
|
|
267
|
+
catalogUnary(protocol, signingKey, "catalog_schema_create", {
|
|
268
|
+
params: schema([
|
|
269
|
+
field("attach_opaque_data", binary(), true),
|
|
270
|
+
field("name", utf8(), false),
|
|
271
|
+
field("comment", utf8(), true),
|
|
272
|
+
field("tags", binary(), true),
|
|
273
|
+
field("transaction_opaque_data", binary(), true),
|
|
274
|
+
]),
|
|
275
|
+
result: emptyResultSchema,
|
|
276
|
+
handler: async (params) => {
|
|
277
|
+
const cat = getCatalog();
|
|
278
|
+
await cat.schemaCreate(
|
|
279
|
+
toUint8Array(params.attach_opaque_data),
|
|
280
|
+
params.name,
|
|
281
|
+
params.comment,
|
|
282
|
+
null, // tags
|
|
283
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
284
|
+
);
|
|
285
|
+
return {};
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// catalog_schema_drop
|
|
290
|
+
catalogUnary(protocol, signingKey, "catalog_schema_drop", {
|
|
291
|
+
params: schema([
|
|
292
|
+
field("attach_opaque_data", binary(), true),
|
|
293
|
+
field("name", utf8(), false),
|
|
294
|
+
field("ignore_not_found", bool(), true),
|
|
295
|
+
field("cascade", bool(), true),
|
|
296
|
+
field("transaction_opaque_data", binary(), true),
|
|
297
|
+
]),
|
|
298
|
+
result: emptyResultSchema,
|
|
299
|
+
handler: async (params) => {
|
|
300
|
+
const cat = getCatalog();
|
|
301
|
+
await cat.schemaDrop(
|
|
302
|
+
toUint8Array(params.attach_opaque_data),
|
|
303
|
+
params.name,
|
|
304
|
+
params.ignore_not_found,
|
|
305
|
+
params.cascade,
|
|
306
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
307
|
+
);
|
|
308
|
+
return {};
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// catalog_schema_contents_tables
|
|
313
|
+
catalogUnary(protocol, signingKey, "catalog_schema_contents_tables", {
|
|
314
|
+
params: attachOpaqueDataNameTxnParams,
|
|
315
|
+
result: RESULT_BINARY_SCHEMA,
|
|
316
|
+
handler: async (params) => {
|
|
317
|
+
const cat = getCatalog();
|
|
318
|
+
const tables = await cat.schemaContentsTables(
|
|
319
|
+
toUint8Array(params.attach_opaque_data),
|
|
320
|
+
params.name,
|
|
321
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
322
|
+
);
|
|
323
|
+
return wrapResult({
|
|
324
|
+
items: tables.map((t) => encodeTableInfo(t)),
|
|
325
|
+
}, CatalogSchemaContentsTablesResultSchema);
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// catalog_schema_contents_views
|
|
330
|
+
catalogUnary(protocol, signingKey, "catalog_schema_contents_views", {
|
|
331
|
+
params: attachOpaqueDataNameTxnParams,
|
|
332
|
+
result: RESULT_BINARY_SCHEMA,
|
|
333
|
+
handler: async (params) => {
|
|
334
|
+
const cat = getCatalog();
|
|
335
|
+
const views = await cat.schemaContentsViews(
|
|
336
|
+
toUint8Array(params.attach_opaque_data),
|
|
337
|
+
params.name,
|
|
338
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
339
|
+
);
|
|
340
|
+
return wrapResult({
|
|
341
|
+
items: views.map((v) => encodeViewInfo(v)),
|
|
342
|
+
}, CatalogSchemaContentsViewsResultSchema);
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// catalog_schema_contents_functions
|
|
347
|
+
catalogUnary(protocol, signingKey, "catalog_schema_contents_functions", {
|
|
348
|
+
params: schema([
|
|
349
|
+
field("attach_opaque_data", binary(), true),
|
|
350
|
+
field("name", utf8(), false),
|
|
351
|
+
field("type", utf8(), false),
|
|
352
|
+
field("transaction_opaque_data", binary(), true),
|
|
353
|
+
]),
|
|
354
|
+
result: RESULT_BINARY_SCHEMA,
|
|
355
|
+
handler: async (params) => {
|
|
356
|
+
const cat = getCatalog();
|
|
357
|
+
const funcs = await cat.schemaContentsFunctions(
|
|
358
|
+
toUint8Array(params.attach_opaque_data),
|
|
359
|
+
params.name,
|
|
360
|
+
decodeDictValue(params.type),
|
|
361
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
362
|
+
);
|
|
363
|
+
return wrapResult({
|
|
364
|
+
items: funcs.map((f) => encodeFunctionInfo(f)),
|
|
365
|
+
}, CatalogSchemaContentsFunctionsResultSchema);
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Catalog handler orchestrator: registers all catalog_* RPC methods.
|
|
3
|
+
|
|
4
|
+
import { Protocol } from "@query-farm/vgi-rpc";
|
|
5
|
+
import type { CatalogInterface } from "../../../catalog/interface.js";
|
|
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";
|
|
12
|
+
|
|
13
|
+
export function registerCatalogMethods(
|
|
14
|
+
protocol: Protocol,
|
|
15
|
+
catalog: CatalogInterface | undefined,
|
|
16
|
+
_catalogName: string | undefined,
|
|
17
|
+
signingKey?: Uint8Array,
|
|
18
|
+
): void {
|
|
19
|
+
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);
|
|
25
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Catalog index handlers: index_get, schema_contents_indexes.
|
|
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";
|
|
6
|
+
import { encodeIndexInfo } from "../../../generated/vgi-client.js";
|
|
7
|
+
import {
|
|
8
|
+
CatalogIndexGetResultSchema,
|
|
9
|
+
CatalogSchemaContentsIndexesResultSchema,
|
|
10
|
+
} from "../../../generated/vgi-protocol-schemas.js";
|
|
11
|
+
import { toUint8Array } from "../../../util/bytes.js";
|
|
12
|
+
import {
|
|
13
|
+
RESULT_BINARY_SCHEMA,
|
|
14
|
+
wrapResult,
|
|
15
|
+
} from "../shared.js";
|
|
16
|
+
import {
|
|
17
|
+
type GetCatalog,
|
|
18
|
+
catalogUnary,
|
|
19
|
+
} from "./shared.js";
|
|
20
|
+
|
|
21
|
+
export function registerCatalogIndexMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
|
|
22
|
+
// catalog_schema_contents_indexes
|
|
23
|
+
catalogUnary(protocol, signingKey, "catalog_schema_contents_indexes", {
|
|
24
|
+
params: schema([
|
|
25
|
+
field("attach_opaque_data", binary(), true),
|
|
26
|
+
field("name", utf8(), false),
|
|
27
|
+
field("transaction_opaque_data", binary(), true),
|
|
28
|
+
]),
|
|
29
|
+
result: RESULT_BINARY_SCHEMA,
|
|
30
|
+
handler: async (params) => {
|
|
31
|
+
const cat = getCatalog();
|
|
32
|
+
const indexes = await cat.schemaContentsIndexes(
|
|
33
|
+
toUint8Array(params.attach_opaque_data),
|
|
34
|
+
params.name,
|
|
35
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
|
|
36
|
+
);
|
|
37
|
+
return wrapResult({
|
|
38
|
+
items: indexes.map((i) => encodeIndexInfo(i)),
|
|
39
|
+
}, CatalogSchemaContentsIndexesResultSchema);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// catalog_index_get
|
|
44
|
+
catalogUnary(protocol, signingKey, "catalog_index_get", {
|
|
45
|
+
params: schema([
|
|
46
|
+
field("attach_opaque_data", binary(), true),
|
|
47
|
+
field("schema_name", utf8(), false),
|
|
48
|
+
field("name", utf8(), false),
|
|
49
|
+
field("transaction_opaque_data", binary(), true),
|
|
50
|
+
]),
|
|
51
|
+
result: RESULT_BINARY_SCHEMA,
|
|
52
|
+
handler: async (params) => {
|
|
53
|
+
const cat = getCatalog();
|
|
54
|
+
const info = await cat.indexGet(
|
|
55
|
+
toUint8Array(params.attach_opaque_data),
|
|
56
|
+
params.schema_name,
|
|
57
|
+
params.name,
|
|
58
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
|
|
59
|
+
);
|
|
60
|
+
return wrapResult({
|
|
61
|
+
items: info ? [encodeIndexInfo(info)] : [],
|
|
62
|
+
}, CatalogIndexGetResultSchema);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Catalog macro handlers: macro_get/create/drop, schema_contents_macros.
|
|
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";
|
|
6
|
+
import { encodeMacroInfo } from "../../../generated/vgi-client.js";
|
|
7
|
+
import {
|
|
8
|
+
CatalogMacroGetResultSchema,
|
|
9
|
+
CatalogSchemaContentsMacrosResultSchema,
|
|
10
|
+
} from "../../../generated/vgi-protocol-schemas.js";
|
|
11
|
+
import type { MacroType } from "../../../catalog/interface.js";
|
|
12
|
+
import { toUint8Array } from "../../../util/bytes.js";
|
|
13
|
+
import { decodeDictValue } from "../../../util/arrow/index.js";
|
|
14
|
+
import {
|
|
15
|
+
REQUEST_PARAMS_SCHEMA,
|
|
16
|
+
RESULT_BINARY_SCHEMA,
|
|
17
|
+
unwrapRequest,
|
|
18
|
+
wrapResult,
|
|
19
|
+
} from "../shared.js";
|
|
20
|
+
import {
|
|
21
|
+
type GetCatalog,
|
|
22
|
+
emptyResultSchema,
|
|
23
|
+
attachOpaqueDataSchemaNameTxnParams,
|
|
24
|
+
catalogUnary,
|
|
25
|
+
} from "./shared.js";
|
|
26
|
+
|
|
27
|
+
export function registerCatalogMacroMethods(protocol: Protocol, getCatalog: GetCatalog, signingKey?: Uint8Array): void {
|
|
28
|
+
// catalog_macro_get
|
|
29
|
+
catalogUnary(protocol, signingKey, "catalog_macro_get", {
|
|
30
|
+
params: attachOpaqueDataSchemaNameTxnParams,
|
|
31
|
+
result: RESULT_BINARY_SCHEMA,
|
|
32
|
+
handler: async (params) => {
|
|
33
|
+
const cat = getCatalog();
|
|
34
|
+
const info = await cat.macroGet(
|
|
35
|
+
toUint8Array(params.attach_opaque_data),
|
|
36
|
+
params.schema_name,
|
|
37
|
+
params.name,
|
|
38
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
39
|
+
);
|
|
40
|
+
return wrapResult({
|
|
41
|
+
items: info ? [encodeMacroInfo(info)] : [],
|
|
42
|
+
}, CatalogMacroGetResultSchema);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// catalog_macro_create
|
|
47
|
+
catalogUnary(protocol, signingKey, "catalog_macro_create", {
|
|
48
|
+
params: REQUEST_PARAMS_SCHEMA,
|
|
49
|
+
result: emptyResultSchema,
|
|
50
|
+
handler: async (params) => {
|
|
51
|
+
const cat = getCatalog();
|
|
52
|
+
const innerParams = unwrapRequest(params.request);
|
|
53
|
+
await cat.macroCreate(
|
|
54
|
+
toUint8Array(innerParams.attach_opaque_data),
|
|
55
|
+
innerParams.schema_name,
|
|
56
|
+
innerParams.name,
|
|
57
|
+
innerParams.macro_type as MacroType,
|
|
58
|
+
innerParams.parameters ? (Array.isArray(innerParams.parameters) ? innerParams.parameters : [...innerParams.parameters]) : [],
|
|
59
|
+
innerParams.definition,
|
|
60
|
+
innerParams.on_conflict,
|
|
61
|
+
innerParams.parameter_default_values ? toUint8Array(innerParams.parameter_default_values) : null,
|
|
62
|
+
innerParams.arguments_schema ? toUint8Array(innerParams.arguments_schema) : null,
|
|
63
|
+
innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined
|
|
64
|
+
);
|
|
65
|
+
return {};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// catalog_macro_drop
|
|
70
|
+
catalogUnary(protocol, signingKey, "catalog_macro_drop", {
|
|
71
|
+
params: schema([
|
|
72
|
+
field("attach_opaque_data", binary(), true),
|
|
73
|
+
field("schema_name", utf8(), false),
|
|
74
|
+
field("name", utf8(), false),
|
|
75
|
+
field("ignore_not_found", bool(), true),
|
|
76
|
+
field("transaction_opaque_data", binary(), true),
|
|
77
|
+
]),
|
|
78
|
+
result: emptyResultSchema,
|
|
79
|
+
handler: async (params) => {
|
|
80
|
+
const cat = getCatalog();
|
|
81
|
+
await cat.macroDrop(
|
|
82
|
+
toUint8Array(params.attach_opaque_data),
|
|
83
|
+
params.schema_name,
|
|
84
|
+
params.name,
|
|
85
|
+
params.ignore_not_found,
|
|
86
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
87
|
+
);
|
|
88
|
+
return {};
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// catalog_schema_contents_macros
|
|
93
|
+
catalogUnary(protocol, signingKey, "catalog_schema_contents_macros", {
|
|
94
|
+
params: schema([
|
|
95
|
+
field("attach_opaque_data", binary(), true),
|
|
96
|
+
field("name", utf8(), false),
|
|
97
|
+
field("type", utf8(), false),
|
|
98
|
+
field("transaction_opaque_data", binary(), true),
|
|
99
|
+
]),
|
|
100
|
+
result: RESULT_BINARY_SCHEMA,
|
|
101
|
+
handler: async (params) => {
|
|
102
|
+
const cat = getCatalog();
|
|
103
|
+
const macros = await cat.schemaContentsMacros(
|
|
104
|
+
toUint8Array(params.attach_opaque_data),
|
|
105
|
+
params.name,
|
|
106
|
+
decodeDictValue(params.type),
|
|
107
|
+
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
108
|
+
);
|
|
109
|
+
return wrapResult({
|
|
110
|
+
items: macros.map((m) => encodeMacroInfo(m)),
|
|
111
|
+
}, CatalogSchemaContentsMacrosResultSchema);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|