@query-farm/vgi 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +134 -0
  2. package/README.md +494 -0
  3. package/dist/__dbg.test-d.d.ts +1 -0
  4. package/dist/arguments/argument-spec.d.ts +51 -0
  5. package/dist/arguments/arguments.d.ts +13 -0
  6. package/dist/arrow/codec/branded.d.ts +83 -0
  7. package/dist/arrow/codec/registry.d.ts +29 -0
  8. package/dist/arrow/codec/repr.d.ts +23 -0
  9. package/dist/arrow/codec/type-descriptors.d.ts +109 -0
  10. package/dist/arrow/impl-arrowjs/build.d.ts +19 -0
  11. package/dist/arrow/impl-arrowjs/canonical.d.ts +15 -0
  12. package/dist/arrow/impl-arrowjs/empty.d.ts +7 -0
  13. package/dist/arrow/impl-arrowjs/filter.d.ts +11 -0
  14. package/dist/arrow/impl-arrowjs/index.d.ts +11 -0
  15. package/dist/arrow/impl-arrowjs/ipc.d.ts +24 -0
  16. package/dist/arrow/impl-arrowjs/iterate.d.ts +39 -0
  17. package/dist/arrow/impl-arrowjs/project.d.ts +10 -0
  18. package/dist/arrow/impl-arrowjs/schema.d.ts +62 -0
  19. package/dist/arrow/impl-arrowjs/statistics.d.ts +13 -0
  20. package/dist/arrow/impl-flechette/build.d.ts +14 -0
  21. package/dist/arrow/impl-flechette/canonical.d.ts +18 -0
  22. package/dist/arrow/impl-flechette/empty.d.ts +9 -0
  23. package/dist/arrow/impl-flechette/filter.d.ts +10 -0
  24. package/dist/arrow/impl-flechette/index.d.ts +11 -0
  25. package/dist/arrow/impl-flechette/ipc.d.ts +33 -0
  26. package/dist/arrow/impl-flechette/iterate.d.ts +29 -0
  27. package/dist/arrow/impl-flechette/message-meta.d.ts +10 -0
  28. package/dist/arrow/impl-flechette/normalize-type.d.ts +11 -0
  29. package/dist/arrow/impl-flechette/project.d.ts +3 -0
  30. package/dist/arrow/impl-flechette/schema.d.ts +47 -0
  31. package/dist/arrow/impl-flechette/statistics.d.ts +13 -0
  32. package/dist/arrow/index.d.ts +11 -0
  33. package/dist/arrow/predicates.d.ts +47 -0
  34. package/dist/arrow/repr.test-d.d.ts +52 -0
  35. package/dist/arrow/schema-types.d.ts +71 -0
  36. package/dist/arrow/types.d.ts +57 -0
  37. package/dist/catalog/attach-option.d.ts +33 -0
  38. package/dist/catalog/attach-options.d.ts +30 -0
  39. package/dist/catalog/composite.d.ts +33 -0
  40. package/dist/catalog/descriptors.d.ts +154 -0
  41. package/dist/catalog/interface.d.ts +239 -0
  42. package/dist/catalog/read-only.d.ts +33 -0
  43. package/dist/client/client.d.ts +189 -0
  44. package/dist/client/errors.d.ts +26 -0
  45. package/dist/client/helpers.d.ts +12 -0
  46. package/dist/client/protocol.d.ts +16 -0
  47. package/dist/client/types.d.ts +125 -0
  48. package/dist/client-entry.d.ts +11 -0
  49. package/dist/client-entry.js +48 -0
  50. package/dist/client-entry.js.map +9 -0
  51. package/dist/codec/asd.d.ts +25 -0
  52. package/dist/crypto.d.ts +36 -0
  53. package/dist/errors.d.ts +24 -0
  54. package/dist/filter-pushdown/collector.d.ts +32 -0
  55. package/dist/filter-pushdown/deserialize.d.ts +16 -0
  56. package/dist/filter-pushdown/evaluate.d.ts +51 -0
  57. package/dist/filter-pushdown/index.d.ts +4 -0
  58. package/dist/filter-pushdown/types.d.ts +84 -0
  59. package/dist/functions/aggregate.d.ts +129 -0
  60. package/dist/functions/copy-from.d.ts +81 -0
  61. package/dist/functions/copy-to.d.ts +121 -0
  62. package/dist/functions/registry.d.ts +16 -0
  63. package/dist/functions/scalar.d.ts +98 -0
  64. package/dist/functions/storage-cf-do.d.ts +47 -0
  65. package/dist/functions/storage.d.ts +86 -0
  66. package/dist/functions/table-buffering.d.ts +99 -0
  67. package/dist/functions/table-in-out.d.ts +64 -0
  68. package/dist/functions/table.d.ts +118 -0
  69. package/dist/functions/types.d.ts +157 -0
  70. package/dist/generated/vgi-client.d.ts +466 -0
  71. package/dist/generated/vgi-protocol-schemas.d.ts +115 -0
  72. package/dist/index.core.d.ts +42 -0
  73. package/dist/index.d.ts +2 -0
  74. package/dist/index.js +10888 -0
  75. package/dist/index.js.map +85 -0
  76. package/dist/metadata/resolve.d.ts +3 -0
  77. package/dist/metadata/serialize.d.ts +12 -0
  78. package/dist/metadata/types.d.ts +47 -0
  79. package/dist/protocol/dispatch.d.ts +23 -0
  80. package/dist/protocol/handlers/aggregate.d.ts +3 -0
  81. package/dist/protocol/handlers/catalog/admin.d.ts +3 -0
  82. package/dist/protocol/handlers/catalog/index.d.ts +3 -0
  83. package/dist/protocol/handlers/catalog/index_methods.d.ts +3 -0
  84. package/dist/protocol/handlers/catalog/macro.d.ts +3 -0
  85. package/dist/protocol/handlers/catalog/shared.d.ts +70 -0
  86. package/dist/protocol/handlers/catalog/table.d.ts +3 -0
  87. package/dist/protocol/handlers/catalog/view.d.ts +3 -0
  88. package/dist/protocol/handlers/function.d.ts +8 -0
  89. package/dist/protocol/handlers/shared.d.ts +31 -0
  90. package/dist/protocol/handlers/table-buffering.d.ts +3 -0
  91. package/dist/protocol/serialize.d.ts +4 -0
  92. package/dist/protocol/serializers/arguments.d.ts +3 -0
  93. package/dist/protocol/serializers/bind.d.ts +9 -0
  94. package/dist/protocol/serializers/cardinality.d.ts +7 -0
  95. package/dist/protocol/serializers/init.d.ts +9 -0
  96. package/dist/protocol/serializers/shared.d.ts +12 -0
  97. package/dist/protocol/state-serializer.d.ts +23 -0
  98. package/dist/protocol/types.d.ts +129 -0
  99. package/dist/secrets/helpers.d.ts +15 -0
  100. package/dist/types.d.ts +52 -0
  101. package/dist/util/arrow/index.d.ts +1 -0
  102. package/dist/util/bytes.d.ts +2 -0
  103. package/dist/util/statistics.d.ts +7 -0
  104. package/dist/worker-cf-entry.d.ts +30 -0
  105. package/dist/worker-cf-entry.js +8767 -0
  106. package/dist/worker-cf-entry.js.map +74 -0
  107. package/dist/worker.d.ts +36 -0
  108. package/package.json +96 -0
  109. package/src/arguments/argument-spec.ts +200 -0
  110. package/src/arguments/arguments.ts +81 -0
  111. package/src/arrow/codec/branded.ts +206 -0
  112. package/src/arrow/codec/registry.ts +674 -0
  113. package/src/arrow/codec/repr.ts +181 -0
  114. package/src/arrow/codec/type-descriptors.ts +137 -0
  115. package/src/arrow/impl-arrowjs/build.ts +88 -0
  116. package/src/arrow/impl-arrowjs/canonical.ts +509 -0
  117. package/src/arrow/impl-arrowjs/empty.ts +72 -0
  118. package/src/arrow/impl-arrowjs/filter.ts +53 -0
  119. package/src/arrow/impl-arrowjs/index.ts +54 -0
  120. package/src/arrow/impl-arrowjs/ipc.ts +67 -0
  121. package/src/arrow/impl-arrowjs/iterate.ts +159 -0
  122. package/src/arrow/impl-arrowjs/project.ts +73 -0
  123. package/src/arrow/impl-arrowjs/schema.ts +256 -0
  124. package/src/arrow/impl-arrowjs/statistics.ts +185 -0
  125. package/src/arrow/impl-flechette/build.ts +65 -0
  126. package/src/arrow/impl-flechette/canonical.ts +289 -0
  127. package/src/arrow/impl-flechette/empty.ts +20 -0
  128. package/src/arrow/impl-flechette/filter.ts +42 -0
  129. package/src/arrow/impl-flechette/index.ts +54 -0
  130. package/src/arrow/impl-flechette/ipc.ts +110 -0
  131. package/src/arrow/impl-flechette/iterate.ts +121 -0
  132. package/src/arrow/impl-flechette/message-meta.ts +175 -0
  133. package/src/arrow/impl-flechette/normalize-type.ts +99 -0
  134. package/src/arrow/impl-flechette/project.ts +64 -0
  135. package/src/arrow/impl-flechette/schema.ts +202 -0
  136. package/src/arrow/impl-flechette/statistics.ts +198 -0
  137. package/src/arrow/index.ts +129 -0
  138. package/src/arrow/predicates.ts +66 -0
  139. package/src/arrow/repr.test-d.ts +189 -0
  140. package/src/arrow/schema-types.ts +213 -0
  141. package/src/arrow/types.ts +74 -0
  142. package/src/catalog/attach-option.ts +107 -0
  143. package/src/catalog/attach-options.ts +79 -0
  144. package/src/catalog/composite.ts +180 -0
  145. package/src/catalog/descriptors.ts +164 -0
  146. package/src/catalog/interface.ts +721 -0
  147. package/src/catalog/read-only.ts +909 -0
  148. package/src/client/client.ts +1348 -0
  149. package/src/client/errors.ts +69 -0
  150. package/src/client/helpers.ts +56 -0
  151. package/src/client/protocol.ts +33 -0
  152. package/src/client/types.ts +140 -0
  153. package/src/client-entry.ts +112 -0
  154. package/src/codec/asd.ts +147 -0
  155. package/src/crypto.ts +143 -0
  156. package/src/errors.ts +61 -0
  157. package/src/filter-pushdown/collector.ts +147 -0
  158. package/src/filter-pushdown/deserialize.ts +253 -0
  159. package/src/filter-pushdown/evaluate.ts +591 -0
  160. package/src/filter-pushdown/index.ts +28 -0
  161. package/src/filter-pushdown/types.ts +91 -0
  162. package/src/functions/aggregate.ts +384 -0
  163. package/src/functions/copy-from.ts +282 -0
  164. package/src/functions/copy-to.ts +319 -0
  165. package/src/functions/registry.ts +258 -0
  166. package/src/functions/scalar.ts +356 -0
  167. package/src/functions/storage-cf-do.ts +303 -0
  168. package/src/functions/storage.ts +521 -0
  169. package/src/functions/table-buffering.ts +562 -0
  170. package/src/functions/table-in-out.ts +373 -0
  171. package/src/functions/table.ts +521 -0
  172. package/src/functions/types.ts +192 -0
  173. package/src/generated/vgi-client.ts +560 -0
  174. package/src/generated/vgi-protocol-schemas.ts +864 -0
  175. package/src/index.core.ts +267 -0
  176. package/src/index.ts +11 -0
  177. package/src/metadata/resolve.ts +109 -0
  178. package/src/metadata/serialize.ts +242 -0
  179. package/src/metadata/types.ts +60 -0
  180. package/src/protocol/dispatch.ts +52 -0
  181. package/src/protocol/handlers/aggregate.ts +355 -0
  182. package/src/protocol/handlers/catalog/admin.ts +368 -0
  183. package/src/protocol/handlers/catalog/index.ts +25 -0
  184. package/src/protocol/handlers/catalog/index_methods.ts +65 -0
  185. package/src/protocol/handlers/catalog/macro.ts +114 -0
  186. package/src/protocol/handlers/catalog/shared.ts +291 -0
  187. package/src/protocol/handlers/catalog/table.ts +401 -0
  188. package/src/protocol/handlers/catalog/view.ts +119 -0
  189. package/src/protocol/handlers/function.ts +302 -0
  190. package/src/protocol/handlers/shared.ts +80 -0
  191. package/src/protocol/handlers/table-buffering.ts +207 -0
  192. package/src/protocol/serialize.ts +23 -0
  193. package/src/protocol/serializers/arguments.ts +160 -0
  194. package/src/protocol/serializers/bind.ts +212 -0
  195. package/src/protocol/serializers/cardinality.ts +45 -0
  196. package/src/protocol/serializers/init.ts +247 -0
  197. package/src/protocol/serializers/shared.ts +46 -0
  198. package/src/protocol/state-serializer.ts +181 -0
  199. package/src/protocol/types.ts +153 -0
  200. package/src/secrets/helpers.ts +70 -0
  201. package/src/types.ts +71 -0
  202. package/src/util/arrow/index.ts +23 -0
  203. package/src/util/bytes.ts +14 -0
  204. package/src/util/statistics.ts +40 -0
  205. package/src/worker-cf-entry.ts +172 -0
  206. package/src/worker.ts +212 -0
@@ -0,0 +1,180 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // CompositeCatalogInterface — fan one worker out across multiple
3
+ // ReadOnlyCatalogInterface instances, picking which one handles each call by
4
+ // the `name` passed at attach time, then by the `attachOpaqueData` returned for all
5
+ // subsequent calls.
6
+ //
7
+ // This mirrors vgi-python's MetaWorker pattern, where one worker process
8
+ // can serve several distinct catalogs (`example`, `projection_repro`,
9
+ // `schema_reconcile`, …) from a single LOCATION.
10
+
11
+ import type {
12
+ AttachOpaqueData,
13
+ CatalogAttachResult,
14
+ CatalogInfo,
15
+ CopyFromFormatInfo,
16
+ FunctionInfo,
17
+ IndexInfo,
18
+ MacroInfo,
19
+ MacroType,
20
+ SchemaInfo,
21
+ TableInfo,
22
+ TransactionOpaqueData,
23
+ ViewInfo,
24
+ } from "./interface.js";
25
+ import { CatalogInterface } from "./interface.js";
26
+
27
+ function bufferEquals(a: AttachOpaqueData, b: AttachOpaqueData): boolean {
28
+ if (a.length !== b.length) return false;
29
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
30
+ return true;
31
+ }
32
+
33
+ // Subprocess transport spawns a pool of worker processes; DuckDB routes calls
34
+ // across them round-robin. Each worker has its own CompositeCatalog instance,
35
+ // so we can't keep routing state in memory — the attach happens in worker A
36
+ // but later calls land on worker B with an empty route table. To route across
37
+ // workers without a shared store, we encode the backend index in the first
38
+ // byte of attach_opaque_data. Every worker decodes the same byte and routes the same
39
+ // way, so the route is implicit in the attach_opaque_data itself.
40
+ const ROUTE_BYTE = 0;
41
+
42
+ export class CompositeCatalogInterface extends CatalogInterface {
43
+ constructor(private readonly _backends: CatalogInterface[]) {
44
+ super();
45
+ if (_backends.length > 256) {
46
+ throw new Error("CompositeCatalog: at most 256 backends supported");
47
+ }
48
+ }
49
+
50
+ private _route(attachOpaqueData: AttachOpaqueData): CatalogInterface {
51
+ const idx = attachOpaqueData[ROUTE_BYTE];
52
+ const route = this._backends[idx];
53
+ if (!route) {
54
+ throw new Error(`CompositeCatalog: no backend at route-byte index ${idx} (have ${this._backends.length})`);
55
+ }
56
+ return route;
57
+ }
58
+
59
+ catalogs(): string[] {
60
+ const all: string[] = [];
61
+ for (const b of this._backends) all.push(...b.catalogs());
62
+ return all;
63
+ }
64
+
65
+ async catalogsInfo(): Promise<CatalogInfo[]> {
66
+ const all: CatalogInfo[] = [];
67
+ for (const b of this._backends) {
68
+ if (b.catalogsInfo) {
69
+ all.push(...(await b.catalogsInfo()));
70
+ } else {
71
+ for (const name of b.catalogs()) {
72
+ all.push({ name, implementation_version: null, data_version_spec: null, attach_option_specs: [], releases: [] });
73
+ }
74
+ }
75
+ }
76
+ return all;
77
+ }
78
+
79
+ async attach(
80
+ name: string,
81
+ options?: Record<string, unknown>,
82
+ dataVersionSpec?: string | null,
83
+ implementationVersion?: string | null,
84
+ ): Promise<CatalogAttachResult> {
85
+ for (let i = 0; i < this._backends.length; i++) {
86
+ const b = this._backends[i];
87
+ if (b.catalogs().includes(name)) {
88
+ const result = await b.attach(name, options, dataVersionSpec, implementationVersion);
89
+ // Stamp the route-byte so other workers in the pool can decode the
90
+ // backend without needing in-memory state. Mutate in place so the
91
+ // wire returns the rewritten id.
92
+ const stamped = new Uint8Array(result.attach_opaque_data);
93
+ stamped[ROUTE_BYTE] = i;
94
+ result.attach_opaque_data = stamped;
95
+ return result;
96
+ }
97
+ }
98
+ throw new Error(`No worker handles catalog '${name}'`);
99
+ }
100
+
101
+ async detach(attachOpaqueData: AttachOpaqueData): Promise<void> {
102
+ await this._route(attachOpaqueData).detach(attachOpaqueData);
103
+ }
104
+
105
+ async version(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): Promise<number> {
106
+ return await this._route(attachOpaqueData).version(attachOpaqueData, transactionOpaqueData);
107
+ }
108
+
109
+ async schemas(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): Promise<SchemaInfo[]> {
110
+ return await this._route(attachOpaqueData).schemas(attachOpaqueData, transactionOpaqueData);
111
+ }
112
+
113
+ override async schemaGet(attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<SchemaInfo | null> {
114
+ return await this._route(attachOpaqueData).schemaGet(attachOpaqueData, name, transactionOpaqueData);
115
+ }
116
+
117
+ override async schemaContentsTables(attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<TableInfo[]> {
118
+ return await this._route(attachOpaqueData).schemaContentsTables(attachOpaqueData, name, transactionOpaqueData);
119
+ }
120
+
121
+ override async schemaContentsViews(attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<ViewInfo[]> {
122
+ return await this._route(attachOpaqueData).schemaContentsViews(attachOpaqueData, name, transactionOpaqueData);
123
+ }
124
+
125
+ override async schemaContentsFunctions(attachOpaqueData: AttachOpaqueData, name: string, type: string, transactionOpaqueData?: TransactionOpaqueData): Promise<FunctionInfo[]> {
126
+ return await this._route(attachOpaqueData).schemaContentsFunctions(attachOpaqueData, name, type, transactionOpaqueData);
127
+ }
128
+
129
+ override async schemaContentsMacros(attachOpaqueData: AttachOpaqueData, name: string, type: string, transactionOpaqueData?: TransactionOpaqueData): Promise<MacroInfo[]> {
130
+ return await this._route(attachOpaqueData).schemaContentsMacros(attachOpaqueData, name, type, transactionOpaqueData);
131
+ }
132
+
133
+ override async schemaContentsIndexes(attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<IndexInfo[]> {
134
+ return await this._route(attachOpaqueData).schemaContentsIndexes(attachOpaqueData, name, transactionOpaqueData);
135
+ }
136
+
137
+ override async indexGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<IndexInfo | null> {
138
+ return await this._route(attachOpaqueData).indexGet(attachOpaqueData, schemaName, name, transactionOpaqueData);
139
+ }
140
+
141
+ override async tableGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<TableInfo | null> {
142
+ return await this._route(attachOpaqueData).tableGet(attachOpaqueData, schemaName, name, atUnit, atValue, transactionOpaqueData);
143
+ }
144
+
145
+ override async tableScanFunctionGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<any> {
146
+ return await this._route(attachOpaqueData).tableScanFunctionGet(attachOpaqueData, schemaName, name, atUnit, atValue, transactionOpaqueData);
147
+ }
148
+
149
+ override async tableScanBranchesGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<any> {
150
+ return await this._route(attachOpaqueData).tableScanBranchesGet(attachOpaqueData, schemaName, name, atUnit, atValue, transactionOpaqueData);
151
+ }
152
+
153
+ override async tableColumnStatisticsGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<{ bytes: Uint8Array; cacheMaxAgeSeconds: number | null } | null> {
154
+ return await this._route(attachOpaqueData).tableColumnStatisticsGet(attachOpaqueData, schemaName, name, transactionOpaqueData);
155
+ }
156
+
157
+ override async viewGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<ViewInfo | null> {
158
+ return await this._route(attachOpaqueData).viewGet(attachOpaqueData, schemaName, name, transactionOpaqueData);
159
+ }
160
+
161
+ override async macroGet(attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<MacroInfo | null> {
162
+ return await this._route(attachOpaqueData).macroGet(attachOpaqueData, schemaName, name, transactionOpaqueData);
163
+ }
164
+
165
+ override async copyFromFormats(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): Promise<CopyFromFormatInfo[]> {
166
+ return await this._route(attachOpaqueData).copyFromFormats(attachOpaqueData, transactionOpaqueData);
167
+ }
168
+
169
+ override async transactionBegin(attachOpaqueData: AttachOpaqueData): Promise<Uint8Array | null> {
170
+ return await this._route(attachOpaqueData).transactionBegin(attachOpaqueData);
171
+ }
172
+
173
+ override async transactionCommit(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Promise<void> {
174
+ await this._route(attachOpaqueData).transactionCommit(attachOpaqueData, transactionOpaqueData);
175
+ }
176
+
177
+ override async transactionRollback(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Promise<void> {
178
+ await this._route(attachOpaqueData).transactionRollback(attachOpaqueData, transactionOpaqueData);
179
+ }
180
+ }
@@ -0,0 +1,164 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Declarative catalog descriptor types.
3
+
4
+ import type { VgiSchema, VgiDataType } from "../arrow/index.js";
5
+ import type { VgiFunction } from "../functions/types.js";
6
+ import type { Arguments } from "../arguments/arguments.js";
7
+ import type { ColumnStatistics } from "../util/statistics.js";
8
+
9
+ export interface SettingDescriptor {
10
+ name: string;
11
+ description: string;
12
+ type: VgiDataType;
13
+ /** Must be a JS primitive compatible with `type` (string, number, bigint, boolean). */
14
+ defaultValue?: string | number | bigint | boolean;
15
+ }
16
+
17
+ export interface ForeignKeyDef {
18
+ columns: string[];
19
+ referencedTable: string;
20
+ referencedColumns: string[];
21
+ referencedSchema?: string;
22
+ }
23
+
24
+ export type DefaultValue = string | number | boolean | null;
25
+
26
+ export interface TableDescriptor {
27
+ name: string;
28
+ columns?: VgiSchema;
29
+ function?: VgiFunction;
30
+ arguments?: Arguments;
31
+ notNull?: string[];
32
+ unique?: string[][];
33
+ check?: string[];
34
+ primaryKey?: string[][];
35
+ foreignKey?: ForeignKeyDef[];
36
+ defaults?: Record<string, DefaultValue>;
37
+ /** Per-column comment strings, applied as field metadata `comment`. */
38
+ columnComments?: Record<string, string>;
39
+ /**
40
+ * Generated (virtual) columns: map of column name → SQL expression computed
41
+ * from other physical columns. Applied as Arrow field metadata
42
+ * `generated_expression`, which the DuckDB VGI extension reads at table
43
+ * registration. The backing scan function should not return these columns —
44
+ * DuckDB evaluates the expressions client-side.
45
+ */
46
+ generatedColumns?: Record<string, string>;
47
+ /**
48
+ * Per-column statistics for the optimizer. Keys are column names; values
49
+ * are ColumnStatistics records with typed min/max and Arrow type info.
50
+ * DuckDB uses these for plan-time filter elimination and join reordering
51
+ * via the `catalog_table_column_statistics_get` RPC.
52
+ */
53
+ statistics?: Record<string, ColumnStatistics>;
54
+ /**
55
+ * Cache TTL for this table's column statistics. DuckDB caches the result
56
+ * of `catalog_table_column_statistics_get` for up to this many seconds.
57
+ * `undefined`/null means cache indefinitely; `0` means never cache
58
+ * (always re-fetch).
59
+ */
60
+ statisticsCacheMaxAgeSeconds?: number | null;
61
+ /**
62
+ * Dotted-path column references that MUST appear in a WHERE expression for
63
+ * any scan of this table. Top-level names (`"country"`) or struct subfields
64
+ * (`"bbox.xmin"`, `"nested.outer.inner"`). Empty/undefined (default) means
65
+ * no enforcement — the zero-cost fast path for every existing table.
66
+ *
67
+ * Satisfaction is prefix-based: a present filter on a shorter path satisfies
68
+ * any required path it is a prefix of. So a whole-struct filter on `bbox`
69
+ * satisfies all of `bbox.xmin` / `.xmax` / `.ymin` / `.ymax`. The VGI DuckDB
70
+ * extension's optimizer pass consults this list at bind time and throws a
71
+ * `BinderException` listing any unsatisfied paths.
72
+ */
73
+ requiredFieldFilterPaths?: string[];
74
+ supportsTimeTravel?: boolean;
75
+ /**
76
+ * Inline cardinality estimate/max surfaced through TableInfo. When set,
77
+ * the C++ extension uses these directly and skips the per-bind
78
+ * table_function_cardinality RPC. Only meaningful for function-backed
79
+ * tables; static-column tables don't have a function to call.
80
+ */
81
+ inlinedCardinality?: { estimate: bigint; max: bigint };
82
+ comment?: string;
83
+ tags?: Record<string, string>;
84
+ }
85
+
86
+ export interface ViewDescriptor {
87
+ name: string;
88
+ definition: string;
89
+ comment?: string;
90
+ /**
91
+ * Per-column comments keyed by the view's output column name. Unlike tables
92
+ * (whose column comments ride along as Arrow field metadata), a view ships
93
+ * only its SQL `definition`, so column comments need their own channel. The
94
+ * C++ extension aligns these by name against the bound output columns and
95
+ * feeds them into `CreateViewInfo.column_comments_map`; names that don't
96
+ * match a bound column are ignored.
97
+ */
98
+ columnComments?: Record<string, string>;
99
+ tags?: Record<string, string>;
100
+ }
101
+
102
+ export interface MacroDescriptor {
103
+ name: string;
104
+ macroType: "scalar" | "table";
105
+ parameters: string[];
106
+ parameterDefaultValues?: Uint8Array | null;
107
+ /**
108
+ * Optional mapping of parameter name to a human/agent-facing description.
109
+ * Keys must appear in `parameters`. Descriptions flow over the wire via the
110
+ * macro `arguments_schema`'s `vgi_doc` field metadata (the same channel
111
+ * functions use for per-argument docs), so the DuckDB extension's
112
+ * `vgi_function_arguments()` can surface them. Empty/omitted = no docs.
113
+ */
114
+ parameterDocs?: Record<string, string>;
115
+ definition: string;
116
+ comment?: string;
117
+ tags?: Record<string, string>;
118
+ }
119
+
120
+ export interface IndexDescriptor {
121
+ name: string;
122
+ tableName: string;
123
+ expressions: string[];
124
+ /** UNIQUE / PRIMARY / NONE; defaults to NONE. */
125
+ constraintType?: "NONE" | "UNIQUE" | "PRIMARY";
126
+ indexType?: string;
127
+ options?: Record<string, string>;
128
+ comment?: string;
129
+ tags?: Record<string, string>;
130
+ }
131
+
132
+ export interface SchemaDescriptor {
133
+ name: string;
134
+ tables?: TableDescriptor[];
135
+ views?: ViewDescriptor[];
136
+ macros?: MacroDescriptor[];
137
+ functions?: VgiFunction[];
138
+ indexes?: IndexDescriptor[];
139
+ comment?: string;
140
+ tags?: Record<string, string>;
141
+ }
142
+
143
+ export interface SecretTypeDescriptor {
144
+ name: string;
145
+ description: string;
146
+ schema: VgiSchema; // Field metadata {redact: "true"} marks redacted fields
147
+ }
148
+
149
+ export interface CatalogDescriptor {
150
+ name: string;
151
+ defaultSchema?: string;
152
+ schemas: SchemaDescriptor[];
153
+ settings?: SettingDescriptor[];
154
+ secretTypes?: SecretTypeDescriptor[];
155
+ comment?: string;
156
+ tags?: Record<string, string>;
157
+ /**
158
+ * Homepage for this catalog — repo, docs, or dataset landing page. Surfaced
159
+ * through the `catalog_catalogs` discovery record as `CatalogInfo.source_url`,
160
+ * which DuckDB exposes via `duckdb_databases()`. Optional; omitted/`undefined`
161
+ * advertises a null `source_url`.
162
+ */
163
+ sourceUrl?: string;
164
+ }