@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,267 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // VGI TypeScript - Public API (runtime-agnostic core)
3
+ //
4
+ // Everything exported from the package EXCEPT the node-only `Worker` (which
5
+ // imports the AF_UNIX launcher's `serveUnix` from @query-farm/vgi-rpc). This
6
+ // module must stay free of static node-only value imports so it can be bundled
7
+ // for Cloudflare Workers / browsers via worker-cf-entry.ts. The node/bun barrel
8
+ // (`./index.ts`) re-exports this plus `Worker`.
9
+
10
+ // Function factories (primary API)
11
+ export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarParameterDef } from "./functions/scalar.js";
12
+ export { defineTableFunction, type TableFunctionConfig, type TableBindParams, type TableProcessParams } from "./functions/table.js";
13
+ export {
14
+ defineAggregate,
15
+ GROUP_COLUMN_NAME,
16
+ type AggregateFunctionConfig,
17
+ type AggregateBindParams,
18
+ type AggregateUpdateParams,
19
+ type AggregateFinalizeParams,
20
+ } from "./functions/aggregate.js";
21
+ export { defineTableInOutFunction, type TableInOutConfig, type TableInOutBindParams, type TableInOutProcessParams } from "./functions/table-in-out.js";
22
+ export {
23
+ defineTableBufferingFunction,
24
+ type TableBufferingConfig,
25
+ type TableBufferingBindParams,
26
+ type TableBufferingParams,
27
+ type TableBufferingVgiFunction,
28
+ } from "./functions/table-buffering.js";
29
+ export {
30
+ defineCopyFromFunction,
31
+ type CopyFromFunctionConfig,
32
+ type CopyFromOption,
33
+ type CopyFromReadParams,
34
+ } from "./functions/copy-from.js";
35
+ export {
36
+ defineCopyToFunction,
37
+ type CopyToFunctionConfig,
38
+ type CopyToOption,
39
+ type CopyToWriteParams,
40
+ type CopyToCloseParams,
41
+ } from "./functions/copy-to.js";
42
+
43
+ // Function types
44
+ export type { VgiFunction, FunctionMeta, StreamHandlers, FunctionExample, HandlerState } from "./functions/types.js";
45
+
46
+ // Catalog
47
+ export { CatalogInterface, type CatalogAttachResult, type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type CatalogInfo, encodeCatalogInfo, decodeCatalogInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type FunctionInfoOptions, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type MacroType, type CopyFromFormatInfo, encodeCopyFromFormatInfo, type AttachOpaqueData, type TransactionOpaqueData, buildScanBranchesResult, type ScanBranchInput } from "./catalog/interface.js";
48
+ export type { CatalogDescriptor, SchemaDescriptor, TableDescriptor, ViewDescriptor, MacroDescriptor, SettingDescriptor, SecretTypeDescriptor, ForeignKeyDef, DefaultValue } from "./catalog/descriptors.js";
49
+ export { ReadOnlyCatalogInterface } from "./catalog/read-only.js";
50
+ export { CompositeCatalogInterface } from "./catalog/composite.js";
51
+ export { FunctionRegistry } from "./functions/registry.js";
52
+
53
+ // Core types
54
+ export {
55
+ FunctionType,
56
+ FunctionStability,
57
+ NullHandling,
58
+ OrderPreservation,
59
+ OrderDependence,
60
+ DistinctDependence,
61
+ TableInOutPhase,
62
+ DEFAULT_MAX_WORKERS,
63
+ } from "./types.js";
64
+
65
+ // Protocol types
66
+ export type {
67
+ BindRequest,
68
+ BindResponse,
69
+ CopyFromContext,
70
+ CopyToContext,
71
+ InitRequest,
72
+ GlobalInitResponse,
73
+ TableCardinality,
74
+ } from "./protocol/types.js";
75
+
76
+ // Arguments
77
+ export { Arguments } from "./arguments/arguments.js";
78
+ export { type ArgumentSpec, argumentSpecsToSchema, schemaToArgumentSpecs, macroArgumentsSchema, macroParameterDocsFromSchema } from "./arguments/argument-spec.js";
79
+
80
+ // Errors
81
+ export {
82
+ VgiError,
83
+ RowCountMismatchError,
84
+ FunctionNotFoundError,
85
+ CatalogReadOnlyError,
86
+ CatalogNotFoundError,
87
+ CatalogAlreadyExistsError,
88
+ ArgumentValidationError,
89
+ NoCatalogError,
90
+ } from "./errors.js";
91
+
92
+ // Metadata
93
+ export type { ResolvedMetadata, ParameterInfo } from "./metadata/types.js";
94
+ export { CatalogFunctionType } from "./metadata/types.js";
95
+ export { resolveMetadata } from "./metadata/resolve.js";
96
+ export { metadatasToArrow, arrowToMetadatas } from "./metadata/serialize.js";
97
+
98
+ // Filter pushdown
99
+ export {
100
+ PushdownFilters,
101
+ FilteringOutputCollector,
102
+ deserializeFilters,
103
+ buildJoinKeysLookup,
104
+ ComparisonOp,
105
+ type Filter,
106
+ type ConstantFilter,
107
+ type IsNullFilter,
108
+ type IsNotNullFilter,
109
+ type InFilter,
110
+ type AndFilter,
111
+ type OrFilter,
112
+ type StructFilter,
113
+ formatPushedFilters,
114
+ reprPushedFilters,
115
+ } from "./filter-pushdown/index.js";
116
+
117
+ // State serializer
118
+ export { arrowStateSerializer, EXCHANGE_STATE_SCHEMA, serializeUserState, deserializeUserState } from "./protocol/state-serializer.js";
119
+
120
+ // Protocol assembly (for embedding the worker dispatcher in a custom HTTP server).
121
+ export { buildVgiProtocol, type ProtocolConfig } from "./protocol/dispatch.js";
122
+
123
+ // Wire schemas — needed by workers that synthesize TableInfo.bind_result /
124
+ // TableInfo.scan_function bytes to short-circuit per-scan RPCs.
125
+ export { BindResultSchema, ScanFunctionResultSchema } from "./generated/vgi-protocol-schemas.js";
126
+
127
+ // Attach-option specs (for catalogs that advertise typed ATTACH options).
128
+ export { type AttachOptionSpec, serializeAttachOptionSpec, serializeAttachOptionSpecs } from "./catalog/attach-option.js";
129
+
130
+ // Column statistics (for inlining on TableInfo.column_statistics).
131
+ export { type ColumnStatistics, serializeColumnStatistics } from "./util/statistics.js";
132
+
133
+ // Byte utilities
134
+ export { toUint8Array } from "./util/bytes.js";
135
+
136
+ // Arrow utilities
137
+ export {
138
+ iterRows,
139
+ batchFromRows,
140
+ batchFromColumns,
141
+ emptyBatch,
142
+ filterBatch,
143
+ projectSchema,
144
+ projectBatch,
145
+ batchToScalarDict,
146
+ batchToSecretDict,
147
+ safeNumber,
148
+ } from "./util/arrow/index.js";
149
+
150
+ export {
151
+ type SecretFields,
152
+ type SecretsDict,
153
+ secretType,
154
+ secretsOfType,
155
+ secretForScope,
156
+ secretForScopeOfType,
157
+ } from "./secrets/helpers.js";
158
+
159
+ export {
160
+ serializeSchema,
161
+ deserializeSchema,
162
+ serializeBatch,
163
+ deserializeBatch,
164
+ } from "./util/arrow/index.js";
165
+
166
+ // Arrow type system (phase 3): typed factories, precise descriptors, the
167
+ // rich/raw value mapping, the codec registry, and branded raw scalar types
168
+ // with their validating constructors. This is the statically-typed author API.
169
+ // NOTE: the arrow factory names `int`, `int32`, `float32`, `bool` are NOT
170
+ // re-exported here because the package root already exports vgi-rpc argument
171
+ // builders of the same names. Authors needing those specific arrow factories
172
+ // (and the full typed factory set) import them from the arrow facade module
173
+ // (`@query-farm/vgi` -> "./src/arrow/index.js"). The non-colliding and
174
+ // unit-precise factories below cover the common phase-3 typed/raw-mode cases.
175
+ export {
176
+ // typed type factories (non-colliding subset)
177
+ schema, field,
178
+ nullType,
179
+ int8, int16, int64,
180
+ uint8, uint16, uint32, uint64,
181
+ float16, float64,
182
+ utf8, binary, fixedSizeBinary,
183
+ decimal, decimal128, decimal256,
184
+ date, dateDay, dateMillisecond,
185
+ time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond,
186
+ timestamp, duration, interval,
187
+ timestampSeconds, timestampMillis, timestampMicros, timestampNanos,
188
+ durationSeconds, durationMillis, durationMicros, durationNanos,
189
+ list, fixedSizeList, struct, map,
190
+ dictionary, union, sparseUnion, denseUnion,
191
+ TimeUnit, DateUnit, IntervalUnit, UnionMode,
192
+ // codec registry
193
+ codecFor,
194
+ // branded raw constructors / unwrappers
195
+ asDate32, asDate64Ms,
196
+ asTime32S, asTime32Ms, asTime64Us, asTime64Ns,
197
+ asTimestampSeconds, asTimestampMillis, asTimestampMicros, asTimestampNanos,
198
+ asDurationSeconds, asDurationMillis, asDurationMicros, asDurationNanos,
199
+ asUnscaledDecimal, asInt64, asUint64,
200
+ fromBranded, fromBrandedNumber, fromBrandedBigInt,
201
+ // backend-agnostic predicates + ids
202
+ TypeId,
203
+ isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate,
204
+ isTime, isTimestamp, isInterval, isList, isStruct, isUnion,
205
+ isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch,
206
+ readCanonicalValue, columnFromArray, decodeDictValue, backend,
207
+ } from "./arrow/index.js";
208
+
209
+ export type {
210
+ // backend-agnostic Arrow types
211
+ VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnData,
212
+ VgiBatch, VgiBackendInfo, TaggedUnion,
213
+ // precise nominal descriptors
214
+ NullDescriptor, BoolType,
215
+ IntType, Int8Type, Int16Type, Int32Type, Int64Type,
216
+ Uint8Type, Uint16Type, Uint32Type, Uint64Type,
217
+ FloatType, Utf8Type, LargeUtf8Type, BinaryType, LargeBinaryType,
218
+ FixedSizeBinaryType, DecimalType,
219
+ Date32Type, Date64Type, Time32Type, Time64Type,
220
+ TimestampType, DurationType, IntervalType,
221
+ ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType,
222
+ TypedField, TUnit,
223
+ // rich/raw mapping
224
+ RichValue, RawValue, ValueFor, Repr,
225
+ // codec
226
+ Codec,
227
+ // branded scalar aliases
228
+ Branded,
229
+ Date32, Date64Ms,
230
+ Time32S, Time32Ms, Time64Us, Time64Ns,
231
+ TimestampSeconds, TimestampMillis, TimestampMicros, TimestampNanos,
232
+ DurationSeconds, DurationMillis, DurationMicros, DurationNanos,
233
+ UnscaledDecimal, Int64Raw, Uint64Raw,
234
+ } from "./arrow/index.js";
235
+
236
+ // Typed scalar compute helper types (phase 3).
237
+ export type { ScalarComputeRow, ScalarOutputValue, ScalarComputeResult } from "./functions/scalar.js";
238
+
239
+ // Storage
240
+ export {
241
+ type FunctionStorage,
242
+ FunctionStorageSqlite,
243
+ BoundStorage,
244
+ UnknownInvocationError,
245
+ resolveStorageFromEnv,
246
+ setStorage,
247
+ storage as functionStorage,
248
+ } from "./functions/storage.js";
249
+ export { FunctionStorageCfDo, type FetchLike } from "./functions/storage-cf-do.js";
250
+
251
+ // Client
252
+ export { VgiClient, VgiClientError } from "./client/client.js";
253
+ export type {
254
+ VgiClientOptions,
255
+ TableFunctionOptions,
256
+ ScalarFunctionOptions,
257
+ TableInOutFunctionOptions,
258
+ OnCreateConflict,
259
+ CatalogFunctionType as ClientCatalogFunctionType,
260
+ CatalogAttachOptions,
261
+ AttachOptionValue,
262
+ } from "./client/types.js";
263
+
264
+ // Re-export from vgi-rpc for convenience
265
+ export { str, bytes, int, int32, float, float32, bool, toSchema, OutputCollector, AuthContext } from "@query-farm/vgi-rpc";
266
+ export { subprocessConnect, httpConnect, tcpConnect } from "@query-farm/vgi-rpc";
267
+ export type { RpcClient, StreamSession, LogMessage } from "@query-farm/vgi-rpc";
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // VGI TypeScript - Public API (node/bun barrel)
3
+ //
4
+ // The runtime-agnostic core plus the node-only `Worker` (stdio + AF_UNIX
5
+ // launcher transport). Cloudflare Worker / browser code imports from
6
+ // `./index.core.js` (via worker-cf-entry.ts) instead, which omits `Worker` so
7
+ // the launcher's `serveUnix` (node:net) never enters the bundle.
8
+ export * from "./index.core.js";
9
+
10
+ // Worker (node/bun only — stdio + AF_UNIX launcher transport)
11
+ export { Worker, type WorkerConfig } from "./worker.js";
@@ -0,0 +1,109 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Extract metadata from VgiFunction configs.
3
+
4
+ import {
5
+ FunctionStability,
6
+ NullHandling,
7
+ OrderPreservation,
8
+ OrderDependence,
9
+ DistinctDependence,
10
+ DEFAULT_MAX_WORKERS,
11
+ } from "../types.js";
12
+ import type { VgiFunction } from "../functions/types.js";
13
+ import type { ArgumentSpec } from "../arguments/argument-spec.js";
14
+ import {
15
+ CatalogFunctionType,
16
+ type ResolvedMetadata,
17
+ type ParameterInfo,
18
+ type FunctionExample,
19
+ } from "./types.js";
20
+ import { type VgiDataType, TypeId, isUtf8, isBinary, isBool, isNull, isFloat, isInt } from "../arrow/index.js";
21
+ function arrowTypeToName(type: VgiDataType): string | null {
22
+ if (isNull(type)) return null;
23
+ if (isUtf8(type)) return "VARCHAR";
24
+ if (isBinary(type)) return "BLOB";
25
+ if (isBool(type)) return "BOOLEAN";
26
+ if (isInt(type)) {
27
+ const bw = (type as any).bitWidth ?? 32;
28
+ return bw === 64 ? "BIGINT" : "INTEGER";
29
+ }
30
+ if (isFloat(type)) {
31
+ // arrow-js: Float.precision === 0/1/2 (HALF/SINGLE/DOUBLE).
32
+ // flechette: same precision values.
33
+ const precision = (type as any).precision ?? 2;
34
+ return precision === 1 ? "FLOAT" : "DOUBLE";
35
+ }
36
+ return String((type as any).toString?.() ?? type.typeId);
37
+ }
38
+
39
+ function specToParameterInfo(spec: ArgumentSpec): ParameterInfo {
40
+ return {
41
+ name: spec.name,
42
+ position: typeof spec.position === "number" ? spec.position : null,
43
+ positionName: typeof spec.position === "string" ? spec.position : null,
44
+ typeName: arrowTypeToName(spec.arrowType),
45
+ description: "",
46
+ required: true,
47
+ default: null,
48
+ constraints: null,
49
+ isTableInput: spec.isTableInput ?? false,
50
+ isVarargs: spec.isVarargs ?? false,
51
+ isConst: spec.isConst ?? false,
52
+ };
53
+ }
54
+
55
+ export function resolveMetadata(func: VgiFunction): ResolvedMetadata {
56
+ const meta = func.meta;
57
+
58
+ let functionType: CatalogFunctionType;
59
+ switch (func.kind) {
60
+ case "scalar":
61
+ functionType = CatalogFunctionType.SCALAR;
62
+ break;
63
+ case "table":
64
+ case "table_in_out":
65
+ functionType = CatalogFunctionType.TABLE;
66
+ break;
67
+ case "table_buffering" as any:
68
+ functionType = CatalogFunctionType.TABLE_BUFFERING;
69
+ break;
70
+ case "aggregate" as any:
71
+ functionType = CatalogFunctionType.AGGREGATE;
72
+ break;
73
+ default:
74
+ functionType = CatalogFunctionType.TABLE;
75
+ }
76
+
77
+ const parameters: ParameterInfo[] = func.argumentSpecs.map(specToParameterInfo);
78
+
79
+ const examples: FunctionExample[] = (meta.examples ?? []).map((e) => ({
80
+ sql: e.sql,
81
+ description: e.description,
82
+ expectedOutput: e.expectedOutput ?? null,
83
+ }));
84
+
85
+ const maxWorkers = meta.maxWorkers ?? DEFAULT_MAX_WORKERS;
86
+
87
+ return {
88
+ name: meta.name,
89
+ className: meta.name, // In TS, no class name distinction
90
+ functionType,
91
+ description: meta.description ?? "",
92
+ examples,
93
+ categories: meta.categories ?? [],
94
+ tags: meta.tags ?? {},
95
+ parameters,
96
+ stability: meta.stability ?? FunctionStability.CONSISTENT,
97
+ nullHandling: meta.nullHandling ?? NullHandling.DEFAULT,
98
+ requiredSettings: meta.requiredSettings ?? [],
99
+ requiredSecrets: meta.requiredSecrets ?? [],
100
+ projectionPushdown: meta.projectionPushdown ?? false,
101
+ filterPushdown: meta.filterPushdown ?? false,
102
+ samplingPushdown: meta.samplingPushdown ?? false,
103
+ supportedExpressionFilters: meta.supportedExpressionFilters ?? [],
104
+ preservesOrder: meta.preservesOrder ?? OrderPreservation.NO_ORDER_GUARANTEE,
105
+ maxWorkers: maxWorkers === DEFAULT_MAX_WORKERS ? null : maxWorkers,
106
+ orderDependent: meta.orderDependent ?? OrderDependence.NOT_ORDER_DEPENDENT,
107
+ distinctDependent: meta.distinctDependent ?? DistinctDependence.NOT_DISTINCT_DEPENDENT,
108
+ };
109
+ }
@@ -0,0 +1,242 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Metadata -> Arrow batch serialization.
3
+ // Must produce batches matching Python's _METADATA_SCHEMA exactly.
4
+
5
+ import {
6
+ type VgiBatch,
7
+ schema as makeSchema,
8
+ field,
9
+ utf8,
10
+ int32,
11
+ bool,
12
+ list,
13
+ struct as makeStruct,
14
+ map as makeMap,
15
+ batchFromColumns,
16
+ emptyBatch,
17
+ } from "../arrow/index.js";
18
+ import type { ResolvedMetadata, ParameterInfo, FunctionExample } from "./types.js";
19
+
20
+ // ============================================================================
21
+ // Schema definitions matching Python's _METADATA_SCHEMA exactly
22
+ // ============================================================================
23
+
24
+ const EXAMPLE_STRUCT = makeStruct([
25
+ field("sql", utf8(), false),
26
+ field("description", utf8(), false),
27
+ field("expected_output", utf8(), true),
28
+ ]);
29
+
30
+ const PARAMETER_STRUCT = makeStruct([
31
+ field("name", utf8(), false),
32
+ field("position", int32(), true),
33
+ field("position_name", utf8(), true),
34
+ field("type_name", utf8(), true),
35
+ field("description", utf8(), false),
36
+ field("required", bool(), false),
37
+ field("default", utf8(), true),
38
+ field("constraints", utf8(), true),
39
+ field("is_table_input", bool(), false),
40
+ field("is_varargs", bool(), false),
41
+ field("is_const", bool(), false),
42
+ ]);
43
+
44
+ const METADATA_SCHEMA = makeSchema([
45
+ field("name", utf8(), false),
46
+ field("class_name", utf8(), false),
47
+ field("function_type", utf8(), false),
48
+ field("description", utf8(), false),
49
+ field("examples", list(field("item", EXAMPLE_STRUCT, true)), false),
50
+ field("categories", list(field("item", utf8(), true)), false),
51
+ field("tags", makeMap(field("key", utf8(), false), field("value", utf8(), true), false), false),
52
+ field("parameters", list(field("item", PARAMETER_STRUCT, true)), false),
53
+ field("stability", utf8(), false),
54
+ field("null_handling", utf8(), false),
55
+ field("required_settings", list(field("item", utf8(), true)), false),
56
+ field("required_secrets", list(field("item", utf8(), true)), false),
57
+ field("projection_pushdown", bool(), false),
58
+ field("filter_pushdown", bool(), false),
59
+ field("preserves_order", utf8(), false),
60
+ field("max_workers", int32(), true),
61
+ field("order_dependent", utf8(), false),
62
+ field("distinct_dependent", utf8(), false),
63
+ ]);
64
+
65
+ export { METADATA_SCHEMA };
66
+
67
+ // ============================================================================
68
+ // Serialization
69
+ // ============================================================================
70
+
71
+ function metadataToRow(m: ResolvedMetadata): Record<string, any> {
72
+ return {
73
+ name: m.name,
74
+ class_name: m.className,
75
+ function_type: m.functionType,
76
+ description: m.description,
77
+ examples: m.examples.map((e) => ({
78
+ sql: e.sql,
79
+ description: e.description,
80
+ expected_output: e.expectedOutput,
81
+ })),
82
+ categories: m.categories,
83
+ tags: Object.entries(m.tags).map(([k, v]) => [k, v]),
84
+ parameters: m.parameters.map((p) => ({
85
+ name: p.name,
86
+ position: p.position,
87
+ position_name: p.positionName,
88
+ type_name: p.typeName,
89
+ description: p.description,
90
+ required: p.required,
91
+ default: p.default,
92
+ constraints: p.constraints,
93
+ is_table_input: p.isTableInput,
94
+ is_varargs: p.isVarargs,
95
+ is_const: p.isConst,
96
+ })),
97
+ stability: m.stability,
98
+ null_handling: m.nullHandling,
99
+ required_settings: m.requiredSettings,
100
+ required_secrets: m.requiredSecrets,
101
+ projection_pushdown: m.projectionPushdown,
102
+ filter_pushdown: m.filterPushdown,
103
+ sampling_pushdown: m.samplingPushdown,
104
+ supported_expression_filters: m.supportedExpressionFilters,
105
+ preserves_order: m.preservesOrder,
106
+ max_workers: m.maxWorkers,
107
+ order_dependent: m.orderDependent,
108
+ distinct_dependent: m.distinctDependent,
109
+ };
110
+ }
111
+
112
+ /**
113
+ * Serialize multiple ResolvedMetadata to a single Arrow RecordBatch.
114
+ */
115
+ export function metadatasToArrow(metadatas: ResolvedMetadata[]): VgiBatch {
116
+ if (metadatas.length === 0) {
117
+ return emptyBatch(METADATA_SCHEMA);
118
+ }
119
+
120
+ const rows = metadatas.map(metadataToRow);
121
+
122
+ // Pivot rows -> columns keyed by field name; the facade handles complex
123
+ // type construction (List<Struct>, Map, etc.) uniformly.
124
+ const columns: Record<string, any[]> = {};
125
+ for (const f of METADATA_SCHEMA.fields) {
126
+ columns[f.name] = rows.map((r) => r[f.name]);
127
+ }
128
+
129
+ return batchFromColumns(columns, METADATA_SCHEMA);
130
+ }
131
+
132
+ /**
133
+ * Deserialize Arrow RecordBatch to ResolvedMetadata array.
134
+ */
135
+ export function arrowToMetadatas(batch: VgiBatch): ResolvedMetadata[] {
136
+ const results: ResolvedMetadata[] = [];
137
+
138
+ for (let i = 0; i < batch.numRows; i++) {
139
+ const get = (name: string) => {
140
+ const col = batch.getChild(name);
141
+ return col ? col.get(i) : null;
142
+ };
143
+
144
+ // Parse examples
145
+ const rawExamples = get("examples") as any ?? [];
146
+ const examples: FunctionExample[] = [];
147
+ if (rawExamples && typeof rawExamples[Symbol.iterator] === "function") {
148
+ for (const e of rawExamples) {
149
+ if (e) {
150
+ examples.push({
151
+ sql: e.sql ?? "",
152
+ description: e.description ?? "",
153
+ expectedOutput: e.expected_output ?? null,
154
+ });
155
+ }
156
+ }
157
+ }
158
+
159
+ // Parse parameters
160
+ const rawParams = get("parameters") as any ?? [];
161
+ const parameters: ParameterInfo[] = [];
162
+ if (rawParams && typeof rawParams[Symbol.iterator] === "function") {
163
+ for (const p of rawParams) {
164
+ if (p) {
165
+ parameters.push({
166
+ name: p.name ?? "",
167
+ position: p.position ?? null,
168
+ positionName: p.position_name ?? null,
169
+ typeName: p.type_name ?? null,
170
+ description: p.description ?? "",
171
+ required: p.required ?? true,
172
+ default: p.default ?? null,
173
+ constraints: p.constraints ?? null,
174
+ isTableInput: p.is_table_input ?? false,
175
+ isVarargs: p.is_varargs ?? false,
176
+ isConst: p.is_const ?? false,
177
+ });
178
+ }
179
+ }
180
+ }
181
+
182
+ // Parse categories
183
+ const rawCategories = get("categories") as any ?? [];
184
+ const categories: string[] = rawCategories
185
+ ? [...rawCategories].filter((c: any) => c != null)
186
+ : [];
187
+
188
+ // Parse tags (Map). arrow-js MapRow is iterable of {key,value}; flechette
189
+ // returns [[k,v],...] arrays. Handle both.
190
+ const rawTags = get("tags") as any;
191
+ const tags: Record<string, string> = {};
192
+ if (rawTags) {
193
+ if (typeof rawTags[Symbol.iterator] === "function") {
194
+ for (const entry of rawTags) {
195
+ if (Array.isArray(entry)) {
196
+ tags[String(entry[0])] = String(entry[1] ?? "");
197
+ } else if (entry && entry.key != null) {
198
+ tags[String(entry.key)] = String(entry.value ?? "");
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ const rawRequiredSettings = get("required_settings") as any ?? [];
205
+ const requiredSettings: string[] = rawRequiredSettings
206
+ ? [...rawRequiredSettings].filter((s: any) => s != null)
207
+ : [];
208
+
209
+ const rawRequiredSecrets = get("required_secrets") as any ?? [];
210
+ const requiredSecrets: string[] = rawRequiredSecrets
211
+ ? [...rawRequiredSecrets].filter((s: any) => s != null)
212
+ : [];
213
+
214
+ results.push({
215
+ name: (get("name") as string) ?? "",
216
+ className: (get("class_name") as string) ?? "",
217
+ functionType: (get("function_type") as any) ?? "TABLE",
218
+ description: (get("description") as string) ?? "",
219
+ examples,
220
+ categories,
221
+ tags,
222
+ parameters,
223
+ stability: (get("stability") as any) ?? "CONSISTENT",
224
+ nullHandling: (get("null_handling") as any) ?? "DEFAULT",
225
+ requiredSettings,
226
+ requiredSecrets,
227
+ projectionPushdown: (get("projection_pushdown") as boolean) ?? false,
228
+ filterPushdown: (get("filter_pushdown") as boolean) ?? false,
229
+ samplingPushdown: (get("sampling_pushdown") as boolean) ?? false,
230
+ supportedExpressionFilters: (() => {
231
+ const raw = get("supported_expression_filters") as any ?? [];
232
+ return raw ? [...raw].filter((s: any) => s != null).map(String) : [];
233
+ })(),
234
+ preservesOrder: (get("preserves_order") as any) ?? "NO_ORDER_GUARANTEE",
235
+ maxWorkers: (get("max_workers") as number | null) ?? null,
236
+ orderDependent: (get("order_dependent") as any) ?? "NOT_ORDER_DEPENDENT",
237
+ distinctDependent: (get("distinct_dependent") as any) ?? "NOT_DISTINCT_DEPENDENT",
238
+ });
239
+ }
240
+
241
+ return results;
242
+ }
@@ -0,0 +1,60 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Metadata types for function introspection and DuckDB registration.
3
+
4
+ import {
5
+ FunctionStability,
6
+ NullHandling,
7
+ OrderPreservation,
8
+ OrderDependence,
9
+ DistinctDependence,
10
+ } from "../types.js";
11
+
12
+ export enum CatalogFunctionType {
13
+ SCALAR = "SCALAR",
14
+ TABLE = "TABLE",
15
+ TABLE_BUFFERING = "TABLE_BUFFERING",
16
+ AGGREGATE = "AGGREGATE",
17
+ }
18
+
19
+ export interface ParameterInfo {
20
+ name: string;
21
+ position: number | null;
22
+ positionName: string | null;
23
+ typeName: string | null;
24
+ description: string;
25
+ required: boolean;
26
+ default: string | null;
27
+ constraints: string | null;
28
+ isTableInput: boolean;
29
+ isVarargs: boolean;
30
+ isConst: boolean;
31
+ }
32
+
33
+ export interface FunctionExample {
34
+ sql: string;
35
+ description: string;
36
+ expectedOutput: string | null;
37
+ }
38
+
39
+ export interface ResolvedMetadata {
40
+ name: string;
41
+ className: string;
42
+ functionType: CatalogFunctionType;
43
+ description: string;
44
+ examples: FunctionExample[];
45
+ categories: string[];
46
+ tags: Record<string, string>;
47
+ parameters: ParameterInfo[];
48
+ stability: FunctionStability;
49
+ nullHandling: NullHandling;
50
+ requiredSettings: string[];
51
+ requiredSecrets: string[];
52
+ projectionPushdown: boolean;
53
+ filterPushdown: boolean;
54
+ samplingPushdown: boolean;
55
+ supportedExpressionFilters: string[];
56
+ preservesOrder: OrderPreservation;
57
+ maxWorkers: number | null;
58
+ orderDependent: OrderDependence;
59
+ distinctDependent: DistinctDependence;
60
+ }