@query-farm/vgi 0.50.1 → 0.52.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 (84) hide show
  1. package/README.md +45 -3
  2. package/dist/client-entry.js +833 -775
  3. package/dist/client-entry.js.map +10 -10
  4. package/dist/functions/aggregate.d.ts +25 -21
  5. package/dist/functions/execution-cache.d.ts +11 -0
  6. package/dist/functions/storage-blobs.d.ts +173 -0
  7. package/dist/functions/storage-cf-do.d.ts +50 -0
  8. package/dist/functions/storage-seal.d.ts +27 -0
  9. package/dist/functions/storage.d.ts +71 -1
  10. package/dist/functions/table-buffering.d.ts +30 -0
  11. package/dist/functions/table.d.ts +6 -1
  12. package/dist/generated/vgi-client.d.ts +7 -1
  13. package/dist/generated/vgi-protocol-schemas.d.ts +10 -9
  14. package/dist/generated/vgi-protocol-types.d.ts +244 -2
  15. package/dist/generated/vgi-service.d.ts +1 -1
  16. package/dist/hosted.d.ts +117 -0
  17. package/dist/http/blob-vendor.d.ts +33 -0
  18. package/dist/http/fetch.d.ts +60 -2
  19. package/dist/http/hosted-auth.d.ts +45 -0
  20. package/dist/index.core.d.ts +11 -3
  21. package/dist/index.js +8661 -6677
  22. package/dist/index.js.map +52 -34
  23. package/dist/protocol/arguments-ref.d.ts +107 -0
  24. package/dist/protocol/dispatch.d.ts +12 -2
  25. package/dist/protocol/handlers/aggregate.d.ts +1 -1
  26. package/dist/protocol/handlers/catalog/shared.d.ts +10 -0
  27. package/dist/protocol/handlers/function.d.ts +23 -0
  28. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  29. package/dist/protocol/serialize.d.ts +1 -1
  30. package/dist/protocol/serializers/bind.d.ts +27 -1
  31. package/dist/protocol/serializers/cardinality.d.ts +1 -1
  32. package/dist/protocol/serializers/splits.d.ts +7 -0
  33. package/dist/protocol/state-serializer.d.ts +8 -7
  34. package/dist/protocol/stream-init.d.ts +17 -0
  35. package/dist/protocol/types.d.ts +32 -0
  36. package/dist/secrets/lookups.d.ts +31 -0
  37. package/dist/serve-entry.d.ts +41 -6
  38. package/dist/serve-entry.js +8531 -6302
  39. package/dist/serve-entry.js.map +52 -35
  40. package/dist/worker-cf-entry.d.ts +5 -0
  41. package/dist/worker-cf-entry.js +7191 -4990
  42. package/dist/worker-cf-entry.js.map +59 -41
  43. package/package.json +5 -4
  44. package/src/functions/aggregate.ts +101 -152
  45. package/src/functions/copy-from.ts +2 -2
  46. package/src/functions/execution-cache.ts +59 -0
  47. package/src/functions/storage-blobs.ts +654 -0
  48. package/src/functions/storage-cf-do.ts +176 -22
  49. package/src/functions/storage-seal.ts +208 -0
  50. package/src/functions/storage.ts +174 -8
  51. package/src/functions/table-buffering.ts +104 -18
  52. package/src/functions/table-in-out.ts +3 -1
  53. package/src/functions/table.ts +12 -8
  54. package/src/generated/vgi-client.ts +9 -2
  55. package/src/generated/vgi-protocol-schemas.ts +115 -107
  56. package/src/generated/vgi-protocol-types.ts +640 -3
  57. package/src/generated/vgi-service.ts +2 -2
  58. package/src/hosted.ts +254 -0
  59. package/src/http/blob-vendor.ts +80 -0
  60. package/src/http/fetch.ts +179 -8
  61. package/src/http/hosted-auth.ts +326 -0
  62. package/src/index.core.ts +66 -1
  63. package/src/protocol/arguments-ref.ts +260 -0
  64. package/src/protocol/dispatch.ts +15 -4
  65. package/src/protocol/handlers/aggregate.ts +123 -82
  66. package/src/protocol/handlers/catalog/shared.ts +20 -0
  67. package/src/protocol/handlers/function.ts +135 -59
  68. package/src/protocol/handlers/table-buffering.ts +49 -32
  69. package/src/protocol/serialize.ts +3 -0
  70. package/src/protocol/serializers/bind.ts +96 -69
  71. package/src/protocol/serializers/cardinality.ts +4 -7
  72. package/src/protocol/serializers/init.ts +5 -11
  73. package/src/protocol/serializers/splits.ts +31 -4
  74. package/src/protocol/state-serializer.ts +27 -39
  75. package/src/protocol/stream-init.ts +87 -0
  76. package/src/protocol/types.ts +33 -0
  77. package/src/secrets/lookups.ts +53 -0
  78. package/src/serve-entry.ts +138 -11
  79. package/src/worker-cf-entry.ts +33 -0
  80. package/src/worker.ts +25 -0
  81. package/dist/protocol/carried-init-request.d.ts +0 -28
  82. package/dist/util/zstd-sync.d.ts +0 -7
  83. package/src/protocol/carried-init-request.ts +0 -139
  84. package/src/util/zstd-sync.ts +0 -50
@@ -2086,660 +2086,116 @@ var VGI_DEFAULT_KEY = "vgi_default";
2086
2086
  var VGI_CHOICES_KEY = "vgi_choices";
2087
2087
  var VGI_RANGE_KEY = "vgi_range";
2088
2088
  var VGI_PATTERN_KEY = "vgi_pattern";
2089
- // src/util/bytes.ts
2090
- function toUint8Array(val) {
2091
- if (val instanceof Uint8Array)
2092
- return val;
2093
- if (val instanceof ArrayBuffer)
2094
- return new Uint8Array(val);
2095
- if (typeof Buffer !== "undefined" && Buffer.isBuffer(val))
2096
- return new Uint8Array(val);
2097
- if (val && val.buffer instanceof ArrayBuffer) {
2098
- return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
2099
- }
2100
- return new Uint8Array(0);
2101
- }
2102
-
2103
- // src/codec/conform.ts
2104
- var OPTIONAL_ITEM_FIELDS = new Set(["argument_names"]);
2105
- function children(type) {
2106
- return type.children ?? [];
2107
- }
2108
- function mapValueType(type) {
2109
- const entries = children(type)[0].type;
2110
- return children(entries)[1].type;
2111
- }
2112
- function mapPairs(raw) {
2113
- if (Array.isArray(raw))
2114
- return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
2115
- if (raw instanceof Map)
2116
- return Array.from(raw.entries());
2117
- if (typeof raw[Symbol.iterator] === "function")
2118
- return Array.from(raw);
2119
- return Object.entries(raw);
2120
- }
2121
- function zeroValue(type) {
2122
- if (isDictionary(type))
2123
- return zeroValue(type.dictionary);
2124
- if (isUtf8(type))
2125
- return "";
2126
- if (isBinary(type))
2127
- return new Uint8Array(0);
2128
- if (isBool(type))
2129
- return false;
2130
- if (isInt(type))
2131
- return type.bitWidth === 64 ? 0n : 0;
2132
- if (isFloat(type))
2133
- return 0;
2134
- if (isList(type) || isMap(type))
2135
- return [];
2136
- if (isStruct(type)) {
2137
- const out = {};
2138
- for (const c of children(type))
2139
- out[c.name] = c.nullable ? null : conformValue(c.type, undefined, false, c.name);
2140
- return out;
2141
- }
2142
- return null;
2143
- }
2144
- var HAS_CONTAINER = new WeakMap;
2145
- function hasContainer(type) {
2146
- const cached = HAS_CONTAINER.get(type);
2147
- if (cached !== undefined)
2148
- return cached;
2149
- let has = isList(type) || isMap(type);
2150
- if (!has && isStruct(type))
2151
- has = children(type).some((c) => hasContainer(c.type));
2152
- HAS_CONTAINER.set(type, has);
2153
- return has;
2154
- }
2155
- function conformValue(type, value, nullable, name) {
2156
- if (value == null) {
2157
- if (nullable)
2158
- return value ?? null;
2159
- if (isList(type) || isMap(type))
2160
- return [];
2161
- return value;
2162
- }
2163
- if (!hasContainer(type))
2164
- return value;
2165
- if (isList(type)) {
2166
- const itemType = children(type)[0].type;
2167
- const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
2168
- const items = Array.isArray(value) ? value : Array.from(value);
2169
- let changed = !Array.isArray(value);
2170
- const out = items.map((item) => {
2171
- const next = item == null && !itemsNullable ? zeroValue(itemType) : conformValue(itemType, item, true, name);
2172
- if (next !== item)
2173
- changed = true;
2174
- return next;
2175
- });
2176
- return changed ? out : value;
2177
- }
2178
- if (isMap(type)) {
2179
- const valueType = mapValueType(type);
2180
- const pairs = mapPairs(value);
2181
- let changed = false;
2182
- const out = pairs.map(([k, v]) => {
2183
- const next = v == null ? zeroValue(valueType) : conformValue(valueType, v, true, name);
2184
- if (next !== v)
2185
- changed = true;
2186
- return [k, next];
2187
- });
2188
- return changed ? out : value;
2189
- }
2190
- if (isStruct(type)) {
2191
- let out = null;
2192
- for (const c of children(type)) {
2193
- const v = value[c.name];
2194
- const next = conformValue(c.type, v, c.nullable, c.name);
2195
- if (next !== v) {
2196
- (out ??= { ...value })[c.name] = next;
2197
- }
2198
- }
2199
- return out ?? value;
2200
- }
2201
- return value;
2202
- }
2203
- function conformRecord(schema, obj) {
2204
- let out = null;
2205
- for (const f of schema.fields) {
2206
- const v = obj[f.name];
2207
- const next = conformValue(f.type, v, f.nullable, f.name);
2208
- if (next !== v) {
2209
- (out ??= { ...obj })[f.name] = next;
2210
- }
2211
- }
2212
- return out ?? obj;
2213
- }
2214
-
2215
- // src/protocol/serializers/shared.ts
2216
- function toUint8Array2(val) {
2217
- if (typeof val === "string")
2218
- return new TextEncoder().encode(val);
2219
- const result = toUint8Array(val);
2220
- if (result.length === 0 && val != null) {
2221
- throw new Error(`Cannot convert ${typeof val} to Uint8Array`);
2222
- }
2223
- return result;
2224
- }
2225
- function buildSingleRowBatch(schema, values) {
2226
- const cols = {};
2227
- const row = conformRecord(schema, values);
2228
- for (const f of schema.fields) {
2229
- let val = row[f.name];
2230
- if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
2231
- val = BigInt(val);
2232
- }
2233
- cols[f.name] = [val];
2234
- }
2235
- return batchFromColumns(cols, schema);
2236
- }
2237
2089
 
2238
- // src/protocol/serializers/bind.ts
2239
- var COPY_FROM_STRUCT_TYPE = struct2([
2240
- field2("format", utf82(), false),
2241
- field2("file_path", utf82(), false),
2242
- field2("expected_schema", binary2(), false)
2090
+ // src/generated/vgi-protocol-schemas.ts
2091
+ var CatalogInfoSchema = schema2([
2092
+ field2("name", utf82(), false),
2093
+ field2("implementation_version", utf82(), true),
2094
+ field2("data_version_spec", utf82(), true),
2095
+ field2("attach_option_specs", list2(field2("item", binary2(), true)), false),
2096
+ field2("releases", list2(field2("item", struct2([field2("version", utf82(), false), field2("released_at", timestamp2(TimeUnit2.MICROSECOND, "UTC"), true), field2("summary", utf82(), false), field2("notes_url", utf82(), true)]), true)), false),
2097
+ field2("source_url", utf82(), true)
2243
2098
  ]);
2244
- var COPY_TO_STRUCT_TYPE = struct2([
2245
- field2("format", utf82(), false),
2246
- field2("file_path", utf82(), false)
2099
+ var SchemaInfoSchema = schema2([
2100
+ field2("comment", utf82(), true),
2101
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2102
+ field2("path", list2(field2("item", utf82(), true)), false),
2103
+ field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true),
2104
+ field2("options", binary2(), true)
2247
2105
  ]);
2248
- var BIND_REQUEST_SCHEMA = schema2([
2249
- field2("function_name", utf82(), false),
2250
- field2("arguments", binary2(), false),
2106
+ var TableInfoSchema = schema2([
2107
+ field2("comment", utf82(), true),
2108
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2109
+ field2("name", utf82(), false),
2110
+ field2("schema_path", list2(field2("item", utf82(), true)), false),
2111
+ field2("columns", binary2(), false),
2112
+ field2("constraints", list2(field2("item", binary2(), true)), false),
2113
+ field2("definition_revision", binary2(), true),
2114
+ field2("write_result_modes", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2115
+ field2("supports_column_statistics", bool2(), false),
2116
+ field2("scan_function", binary2(), true),
2117
+ field2("insert_function", binary2(), true),
2118
+ field2("update_function", binary2(), true),
2119
+ field2("delete_function", binary2(), true),
2120
+ field2("cardinality_estimate", int642(), true),
2121
+ field2("cardinality_max", int642(), true),
2122
+ field2("column_statistics", binary2(), true),
2123
+ field2("bind_result", binary2(), true),
2124
+ field2("required_filters", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false),
2125
+ field2("options", binary2(), true),
2126
+ field2("layout", binary2(), true),
2127
+ field2("scan_planning", utf82(), false)
2128
+ ]);
2129
+ var ViewInfoSchema = schema2([
2130
+ field2("comment", utf82(), true),
2131
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2132
+ field2("name", utf82(), false),
2133
+ field2("schema_path", list2(field2("item", utf82(), true)), false),
2134
+ field2("definition", utf82(), false),
2135
+ field2("column_comments", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2136
+ field2("aliases", list2(field2("item", utf82(), true)), false),
2137
+ field2("security", utf82(), false)
2138
+ ]);
2139
+ var FunctionInfoSchema = schema2([
2140
+ field2("comment", utf82(), true),
2141
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2142
+ field2("name", utf82(), false),
2143
+ field2("schema_path", list2(field2("item", utf82(), true)), false),
2251
2144
  field2("function_type", dictionary2(utf82(), int162()), false),
2252
- field2("input_schema", binary2(), true),
2253
- field2("settings", binary2(), true),
2254
- field2("secrets", binary2(), true),
2255
- field2("attach_opaque_data", binary2(), true),
2256
- field2("transaction_opaque_data", binary2(), true),
2257
- field2("resolved_secrets_provided", bool2(), false),
2258
- field2("at_unit", utf82(), true),
2259
- field2("at_value", utf82(), true),
2260
- field2("copy_from", COPY_FROM_STRUCT_TYPE, true),
2261
- field2("copy_to", COPY_TO_STRUCT_TYPE, true),
2262
- field2("schema_path", list2(field2("item", utf82(), true)), true),
2263
- field2("argument_names", list2(field2("item", utf82(), true)), true)
2145
+ field2("arguments", dictionary2(binary2(), int322()), false),
2146
+ field2("output_schema", dictionary2(binary2(), int322()), false),
2147
+ field2("parameter_default_values", dictionary2(binary2(), int322()), true),
2148
+ field2("stability", dictionary2(utf82(), int162()), true),
2149
+ field2("null_handling", dictionary2(utf82(), int162()), true),
2150
+ field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
2151
+ field2("description", utf82(), false),
2152
+ field2("examples", list2(field2("item", struct2([field2("sql", utf82(), false), field2("description", utf82(), false), field2("expected_output", utf82(), true)]), true)), false),
2153
+ field2("categories", list2(field2("item", utf82(), true)), false),
2154
+ field2("projection_pushdown", bool2(), true),
2155
+ field2("filter_pushdown", bool2(), true),
2156
+ field2("sampling_pushdown", bool2(), true),
2157
+ field2("late_materialization", bool2(), true),
2158
+ field2("filter_semantic_profiles", list2(field2("item", utf82(), true)), false),
2159
+ field2("additional_filter_functions", list2(field2("item", struct2([field2("namespace", utf82(), false), field2("name", utf82(), false), field2("version", uint642(), false)]), true)), false),
2160
+ field2("runtime_filter_algorithms", list2(field2("item", struct2([field2("namespace", utf82(), false), field2("name", utf82(), false), field2("version", uint642(), false)]), true)), false),
2161
+ field2("filter_evaluation_contexts", list2(field2("item", struct2([field2("profile", utf82(), false), field2("provider_fingerprint", utf82(), true)]), true)), false),
2162
+ field2("order_preservation", dictionary2(utf82(), int162()), true),
2163
+ field2("max_workers", int322(), true),
2164
+ field2("supports_batch_index", bool2(), false),
2165
+ field2("supports_splits", bool2(), false),
2166
+ field2("filters_exactly_applied", bool2(), false),
2167
+ field2("supports_positions", bool2(), false),
2168
+ field2("split_token_ttl_seconds", int642(), true),
2169
+ field2("partition_kind", dictionary2(utf82(), int162()), false),
2170
+ field2("order_dependent", dictionary2(utf82(), int162()), false),
2171
+ field2("distinct_dependent", dictionary2(utf82(), int162()), false),
2172
+ field2("supports_window", bool2(), false),
2173
+ field2("streaming_partitioned", bool2(), false),
2174
+ field2("has_finalize", bool2(), false),
2175
+ field2("source_order_dependent", bool2(), false),
2176
+ field2("sink_order_dependent", bool2(), false),
2177
+ field2("requires_input_batch_index", bool2(), false),
2178
+ field2("input_from_args", bool2(), false),
2179
+ field2("input_rows_per_call", int642(), true),
2180
+ field2("required_settings", list2(field2("item", utf82(), true)), false),
2181
+ field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false),
2182
+ field2("visibility", utf82(), true)
2264
2183
  ]);
2265
- function serializeBindRequest(req) {
2266
- return buildSingleRowBatch(BIND_REQUEST_SCHEMA, {
2267
- function_name: req.function_name,
2268
- arguments: serializeArguments(req.arguments),
2269
- function_type: req.function_type == null ? req.function_type : String(req.function_type).toUpperCase(),
2270
- input_schema: req.input_schema ? serializeSchema(req.input_schema) : null,
2271
- settings: req.settings ? serializeBatch(req.settings) : null,
2272
- secrets: req.secrets ? serializeBatch(req.secrets) : null,
2273
- attach_opaque_data: req.attach_opaque_data ?? null,
2274
- transaction_opaque_data: req.transaction_opaque_data ?? null,
2275
- resolved_secrets_provided: req.resolved_secrets_provided ?? false,
2276
- at_unit: req.at_unit ?? null,
2277
- at_value: req.at_value ?? null,
2278
- copy_from: req.copy_from ? {
2279
- format: req.copy_from.format,
2280
- file_path: req.copy_from.file_path,
2281
- expected_schema: serializeSchema(req.copy_from.expected_schema)
2282
- } : null,
2283
- copy_to: req.copy_to ? { format: req.copy_to.format, file_path: req.copy_to.file_path } : null,
2284
- schema_path: req.schema_path ?? null,
2285
- argument_names: req.argument_names ?? null
2286
- });
2287
- }
2288
- function parseBindRepeatability(value) {
2289
- if (value !== "UNKNOWN" && value !== "STABLE_WITHIN_QUERY")
2290
- throw new Error("invalid bind repeatability");
2291
- return value;
2292
- }
2293
- function deserializeBindResponse(params) {
2294
- const toStrArray = (val) => {
2295
- if (!val)
2296
- return [];
2297
- const arr = Array.isArray(val) ? val : [...val];
2298
- return arr.filter((v) => v != null).map(String);
2299
- };
2300
- return {
2301
- output_schema: deserializeSchema(toUint8Array2(params.output_schema)),
2302
- projection_expression_profiles: toStrArray(params.projection_expression_profiles),
2303
- opaque_data: params.opaque_data ? toUint8Array2(params.opaque_data) : null,
2304
- lookup_secret_types: toStrArray(params.lookup_secret_types),
2305
- lookup_scopes: toStrArray(params.lookup_scopes),
2306
- lookup_names: toStrArray(params.lookup_names),
2307
- repeatability: parseBindRepeatability(params.repeatability)
2308
- };
2309
- }
2310
- // src/protocol/serializers/init.ts
2311
- var INIT_REQUEST_SCHEMA = schema2([
2312
- field2("bind_call", binary2(), false),
2313
- field2("output_schema", binary2(), false),
2314
- field2("bind_opaque_data", binary2(), true),
2315
- field2("projection_ids", list2(field2("item", int642(), true)), true),
2316
- field2("pushdown_filters", largeBinary2(), true),
2317
- field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
2318
- field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
2319
- field2("row_limit", int642(), true),
2320
- field2("phase", dictionary2(utf82(), int162()), true),
2321
- field2("finalize_state_id", binary2(), true),
2322
- field2("execution_id", binary2(), true),
2323
- field2("init_opaque_data", binary2(), true),
2324
- field2("substream_id", binary2(), true),
2325
- field2("order_by_column_name", utf82(), true),
2326
- field2("order_by_direction", dictionary2(utf82(), int162()), true),
2327
- field2("order_by_null_order", dictionary2(utf82(), int162()), true),
2328
- field2("order_by_limit", int642(), true),
2329
- field2("tablesample_percentage", float642(), true),
2330
- field2("tablesample_seed", int642(), true)
2184
+ var MacroInfoSchema = schema2([
2185
+ field2("comment", utf82(), true),
2186
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2187
+ field2("name", utf82(), false),
2188
+ field2("schema_path", list2(field2("item", utf82(), true)), false),
2189
+ field2("macro_type", dictionary2(utf82(), int162()), false),
2190
+ field2("overloads", list2(field2("item", struct2([field2("parameters", list2(field2("item", struct2([field2("name", utf82(), false), field2("declared_type", binary2(), true), field2("default_value", binary2(), true), field2("default_expression", binary2(), true), field2("documentation", utf82(), true)]), true)), false), field2("definition", utf82(), false), field2("profile", utf82(), false), field2("schema_path", list2(field2("item", utf82(), true)), false), field2("macro_type", utf82(), false), field2("evaluation_context", struct2([field2("timezone", utf82(), false), field2("collation", utf82(), false), field2("default_order", utf82(), false), field2("default_null_order", utf82(), false), field2("preserve_insertion_order", bool2(), false)]), false)]), true)), false)
2331
2191
  ]);
2332
- var GLOBAL_INIT_RESPONSE_SCHEMA = schema2([
2333
- field2("execution_id", binary2(), false),
2334
- field2("opaque_data", binary2(), true),
2335
- field2("max_workers", int642(), false)
2336
- ]);
2337
- function serializeInitRequest(req) {
2338
- const bindCallBatch = serializeBindRequest(req.bind_call);
2339
- const bindCallBytes = serializeBatch(bindCallBatch);
2340
- const row = {
2341
- bind_call: bindCallBytes,
2342
- output_schema: serializeSchema(req.output_schema),
2343
- bind_opaque_data: req.bind_opaque_data ?? null,
2344
- projection_ids: req.projection_ids?.map((n) => BigInt(n)) ?? null,
2345
- pushdown_filters: req.pushdown_filters ? serializeBatch(req.pushdown_filters) : null,
2346
- join_keys: (req.join_keys ?? []).map((b) => serializeBatch(b)),
2347
- split_tokens: req.split_tokens ?? null,
2348
- row_limit: req.row_limit ?? null,
2349
- phase: req.phase ?? null,
2350
- finalize_state_id: req.finalize_state_id ?? null,
2351
- execution_id: req.execution_id ?? null,
2352
- init_opaque_data: req.init_opaque_data ?? null,
2353
- substream_id: req.substream_id ?? null,
2354
- order_by_column_name: req.order_by_column_name ?? null,
2355
- order_by_direction: req.order_by_direction ?? null,
2356
- order_by_null_order: req.order_by_null_order ?? null,
2357
- order_by_limit: req.order_by_limit ?? null,
2358
- tablesample_percentage: req.tablesample_percentage ?? null,
2359
- tablesample_seed: req.tablesample_seed ?? null
2360
- };
2361
- return buildSingleRowBatch(INIT_REQUEST_SCHEMA, row);
2362
- }
2363
- function deserializeGlobalInitResponse(params) {
2364
- return {
2365
- execution_id: toUint8Array2(params.execution_id),
2366
- opaque_data: params.opaque_data ? toUint8Array2(params.opaque_data) : null,
2367
- max_workers: Number(params.max_workers)
2368
- };
2369
- }
2370
- // src/errors.ts
2371
- class VgiError extends Error {
2372
- errorCode;
2373
- constructor(message, code) {
2374
- super(message);
2375
- this.name = "VgiError";
2376
- if (code !== undefined)
2377
- this.errorCode = code;
2378
- }
2379
- }
2380
-
2381
- class RowCountMismatchError extends VgiError {
2382
- constructor(expected, actual) {
2383
- super(`Scalar function output row count (${actual}) does not match ` + `input row count (${expected})`);
2384
- this.name = "RowCountMismatchError";
2385
- }
2386
- }
2387
-
2388
- class FunctionNotFoundError extends VgiError {
2389
- constructor(name, available) {
2390
- super(`Unknown function '${name}'`, "NOT_FOUND");
2391
- this.name = "FunctionNotFoundError";
2392
- }
2393
- }
2394
-
2395
- class CatalogReadOnlyError extends VgiError {
2396
- constructor(operation) {
2397
- super(`catalog is read-only: ${operation} is not supported`, "FAILED_PRECONDITION");
2398
- this.name = "CatalogReadOnlyError";
2399
- }
2400
- }
2401
-
2402
- class CatalogNotFoundError extends VgiError {
2403
- constructor(entity, name) {
2404
- super(`${entity} '${name}' not found`, "NOT_FOUND");
2405
- this.name = "CatalogNotFoundError";
2406
- }
2407
- }
2408
-
2409
- class CatalogAlreadyExistsError extends VgiError {
2410
- constructor(entity, name) {
2411
- super(`${entity} '${name}' already exists`, "ALREADY_EXISTS");
2412
- this.name = "CatalogAlreadyExistsError";
2413
- }
2414
- }
2415
-
2416
- class ArgumentValidationError extends VgiError {
2417
- constructor(message) {
2418
- super(message, "INVALID_ARGUMENT");
2419
- this.name = "ArgumentValidationError";
2420
- }
2421
- }
2422
-
2423
- class NoCatalogError extends VgiError {
2424
- constructor() {
2425
- super("No catalog is configured for this worker", "UNIMPLEMENTED");
2426
- this.name = "NoCatalogError";
2427
- }
2428
- }
2429
-
2430
- // src/schema-path.ts
2431
- function normalizeSchemaPath(path) {
2432
- return typeof path === "string" ? [path] : Array.from(path, String);
2433
- }
2434
-
2435
- // src/codec/asd.ts
2436
- function encodeASD(schema, obj) {
2437
- return serializeBatch(batchFromRows([sortMapsForSchema(schema, conformRecord(schema, obj))], schema));
2438
- }
2439
- function compareCodePoints(a, b) {
2440
- const n = Math.min(a.length, b.length);
2441
- for (let i = 0;i < n; i++) {
2442
- const x = a.charCodeAt(i);
2443
- const y = b.charCodeAt(i);
2444
- if (x === y)
2445
- continue;
2446
- const xs = x >= 55296 && x <= 57343;
2447
- const ys = y >= 55296 && y <= 57343;
2448
- if (xs !== ys)
2449
- return xs ? 1 : -1;
2450
- return x - y;
2451
- }
2452
- return a.length - b.length;
2453
- }
2454
- function mapPairs2(raw) {
2455
- if (Array.isArray(raw))
2456
- return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
2457
- if (raw instanceof Map)
2458
- return Array.from(raw.entries());
2459
- if (typeof raw[Symbol.iterator] === "function")
2460
- return Array.from(raw);
2461
- return Object.entries(raw);
2462
- }
2463
- function compareKeys(a, b) {
2464
- if (typeof a === "string" && typeof b === "string")
2465
- return compareCodePoints(a, b);
2466
- if ((typeof a === "number" || typeof a === "bigint") && (typeof b === "number" || typeof b === "bigint")) {
2467
- return a < b ? -1 : a > b ? 1 : 0;
2468
- }
2469
- return compareCodePoints(String(a), String(b));
2470
- }
2471
- var HAS_MAP = new WeakMap;
2472
- function typeHasMap(type) {
2473
- const cached = HAS_MAP.get(type);
2474
- if (cached !== undefined)
2475
- return cached;
2476
- let has = isMap(type);
2477
- if (!has && (isList(type) || isStruct(type))) {
2478
- has = type.children.some((c) => typeHasMap(c.type));
2479
- }
2480
- HAS_MAP.set(type, has);
2481
- return has;
2482
- }
2483
- function sortMapsForType(type, value) {
2484
- if (value == null || !typeHasMap(type))
2485
- return value;
2486
- if (isMap(type)) {
2487
- const entries = type.children[0].type;
2488
- const valueType = entries.children[1].type;
2489
- return mapPairs2(value).map(([k, v]) => [k, sortMapsForType(valueType, v)]).sort((x, y) => compareKeys(x[0], y[0]));
2490
- }
2491
- if (isList(type)) {
2492
- const child = type.children[0].type;
2493
- return Array.from(value, (v) => sortMapsForType(child, v));
2494
- }
2495
- if (isStruct(type)) {
2496
- const out = { ...value };
2497
- for (const cf of type.children)
2498
- out[cf.name] = sortMapsForType(cf.type, value[cf.name]);
2499
- return out;
2500
- }
2501
- return value;
2502
- }
2503
- function sortMapsForSchema(schema, obj) {
2504
- let out = null;
2505
- for (const f of schema.fields) {
2506
- if (!typeHasMap(f.type))
2507
- continue;
2508
- const v = obj[f.name];
2509
- if (v == null)
2510
- continue;
2511
- out ??= { ...obj };
2512
- out[f.name] = sortMapsForType(f.type, v);
2513
- }
2514
- return out ?? obj;
2515
- }
2516
- function decodeASD(schema, bytes) {
2517
- const batch = deserializeBatch(bytes);
2518
- if (batch.numRows === 0) {
2519
- const names = schema.fields.map((f) => f.name).join(",");
2520
- throw new Error(`decodeASD: empty batch (expected 1 row for ${names})`);
2521
- }
2522
- const out = {};
2523
- for (const field of schema.fields) {
2524
- const col = batch.getChild(field.name);
2525
- const raw = col ? col.get(0) : null;
2526
- out[field.name] = normalizeValue(raw, field.type);
2527
- }
2528
- return out;
2529
- }
2530
- function normalizeValue(raw, type) {
2531
- if (raw == null)
2532
- return null;
2533
- if (isList(type)) {
2534
- const childType = type.children[0].type;
2535
- const out = [];
2536
- for (const item of raw)
2537
- out.push(normalizeValue(item, childType));
2538
- return out;
2539
- }
2540
- if (isMap(type)) {
2541
- const entries = type.children[0].type;
2542
- const valueType = entries.children[1].type;
2543
- const out = {};
2544
- const put = (k, v) => {
2545
- Object.defineProperty(out, String(k), {
2546
- value: normalizeValue(v, valueType),
2547
- enumerable: true,
2548
- writable: true,
2549
- configurable: true
2550
- });
2551
- };
2552
- if (raw[Symbol.iterator]) {
2553
- for (const entry of raw) {
2554
- if (Array.isArray(entry)) {
2555
- put(entry[0], entry[1]);
2556
- } else if (entry && typeof entry === "object") {
2557
- put(entry.key ?? entry[0], entry.value ?? entry[1]);
2558
- }
2559
- }
2560
- } else if (typeof raw === "object") {
2561
- for (const [k, v] of Object.entries(raw))
2562
- put(k, v);
2563
- }
2564
- return out;
2565
- }
2566
- if (isStruct(type)) {
2567
- const childFields = type.children;
2568
- const out = {};
2569
- for (const cf of childFields) {
2570
- out[cf.name] = normalizeValue(raw[cf.name], cf.type);
2571
- }
2572
- return out;
2573
- }
2574
- if (isDictionary(type)) {
2575
- return normalizeValue(raw, type.dictionary);
2576
- }
2577
- if (isBinary(type)) {
2578
- return toUint8Array3(raw);
2579
- }
2580
- if (isInt(type) && type.bitWidth === 64) {
2581
- if (typeof raw === "bigint") {
2582
- if (raw >= BigInt(Number.MIN_SAFE_INTEGER) && raw <= BigInt(Number.MAX_SAFE_INTEGER)) {
2583
- return Number(raw);
2584
- }
2585
- return raw;
2586
- }
2587
- return raw;
2588
- }
2589
- if (isBool(type)) {
2590
- return Boolean(raw);
2591
- }
2592
- return raw;
2593
- }
2594
- function toUint8Array3(val) {
2595
- if (val instanceof Uint8Array)
2596
- return val;
2597
- if (val instanceof ArrayBuffer)
2598
- return new Uint8Array(val);
2599
- if (val && val.buffer instanceof ArrayBuffer) {
2600
- return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
2601
- }
2602
- return new Uint8Array(0);
2603
- }
2604
- function decodeASDCollection(schema, bytes) {
2605
- if (bytes == null)
2606
- return [];
2607
- const output = [];
2608
- const batches = deserializeBatches(bytes);
2609
- const validateSchema = (actualSchema) => {
2610
- if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
2611
- const actual = actualSchema.fields[i];
2612
- return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
2613
- }))
2614
- throw new Error("catalog collection has an incompatible metadata schema");
2615
- };
2616
- if (batches.length === 0)
2617
- validateSchema(deserializeSchema(bytes));
2618
- for (const batch of batches) {
2619
- validateSchema(batch.schema);
2620
- for (let row = 0;row < batch.numRows; row++) {
2621
- const item = {};
2622
- for (const field of schema.fields) {
2623
- const value = batch.getChild(field.name)?.get(row);
2624
- if (value == null && !field.nullable)
2625
- throw new Error(`catalog collection has null ${field.name}`);
2626
- item[field.name] = normalizeValue(value, field.type);
2627
- }
2628
- output.push(item);
2629
- }
2630
- }
2631
- return output;
2632
- }
2633
-
2634
- // src/generated/vgi-protocol-schemas.ts
2635
- var CatalogInfoSchema = schema2([
2636
- field2("name", utf82(), false),
2637
- field2("implementation_version", utf82(), true),
2638
- field2("data_version_spec", utf82(), true),
2639
- field2("attach_option_specs", list2(field2("item", binary2(), true)), false),
2640
- field2("releases", list2(field2("item", struct2([field2("version", utf82(), false), field2("released_at", timestamp2(TimeUnit2.MICROSECOND, "UTC"), true), field2("summary", utf82(), false), field2("notes_url", utf82(), true)]), true)), false),
2641
- field2("source_url", utf82(), true)
2642
- ]);
2643
- var SchemaInfoSchema = schema2([
2644
- field2("comment", utf82(), true),
2645
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2646
- field2("path", list2(field2("item", utf82(), true)), false),
2647
- field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true),
2648
- field2("options", binary2(), true)
2649
- ]);
2650
- var TableInfoSchema = schema2([
2651
- field2("comment", utf82(), true),
2652
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2653
- field2("name", utf82(), false),
2654
- field2("schema_path", list2(field2("item", utf82(), true)), false),
2655
- field2("columns", binary2(), false),
2656
- field2("constraints", list2(field2("item", binary2(), true)), false),
2657
- field2("definition_revision", binary2(), true),
2658
- field2("write_result_modes", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2659
- field2("supports_column_statistics", bool2(), false),
2660
- field2("scan_function", binary2(), true),
2661
- field2("insert_function", binary2(), true),
2662
- field2("update_function", binary2(), true),
2663
- field2("delete_function", binary2(), true),
2664
- field2("cardinality_estimate", int642(), true),
2665
- field2("cardinality_max", int642(), true),
2666
- field2("column_statistics", binary2(), true),
2667
- field2("bind_result", binary2(), true),
2668
- field2("required_filters", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false),
2669
- field2("options", binary2(), true),
2670
- field2("layout", binary2(), true),
2671
- field2("scan_planning", utf82(), false)
2672
- ]);
2673
- var ViewInfoSchema = schema2([
2674
- field2("comment", utf82(), true),
2675
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2676
- field2("name", utf82(), false),
2677
- field2("schema_path", list2(field2("item", utf82(), true)), false),
2678
- field2("definition", utf82(), false),
2679
- field2("column_comments", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2680
- field2("aliases", list2(field2("item", utf82(), true)), false),
2681
- field2("security", utf82(), false)
2682
- ]);
2683
- var FunctionInfoSchema = schema2([
2684
- field2("comment", utf82(), true),
2685
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2686
- field2("name", utf82(), false),
2687
- field2("schema_path", list2(field2("item", utf82(), true)), false),
2688
- field2("function_type", dictionary2(utf82(), int162()), false),
2689
- field2("arguments", dictionary2(binary2(), int322()), false),
2690
- field2("output_schema", dictionary2(binary2(), int322()), false),
2691
- field2("parameter_default_values", dictionary2(binary2(), int322()), true),
2692
- field2("stability", dictionary2(utf82(), int162()), true),
2693
- field2("null_handling", dictionary2(utf82(), int162()), true),
2694
- field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
2695
- field2("description", utf82(), false),
2696
- field2("examples", list2(field2("item", struct2([field2("sql", utf82(), false), field2("description", utf82(), false), field2("expected_output", utf82(), true)]), true)), false),
2697
- field2("categories", list2(field2("item", utf82(), true)), false),
2698
- field2("projection_pushdown", bool2(), true),
2699
- field2("filter_pushdown", bool2(), true),
2700
- field2("sampling_pushdown", bool2(), true),
2701
- field2("late_materialization", bool2(), true),
2702
- field2("filter_semantic_profiles", list2(field2("item", utf82(), true)), false),
2703
- field2("additional_filter_functions", list2(field2("item", struct2([field2("namespace", utf82(), false), field2("name", utf82(), false), field2("version", uint642(), false)]), true)), false),
2704
- field2("runtime_filter_algorithms", list2(field2("item", struct2([field2("namespace", utf82(), false), field2("name", utf82(), false), field2("version", uint642(), false)]), true)), false),
2705
- field2("filter_evaluation_contexts", list2(field2("item", struct2([field2("profile", utf82(), false), field2("provider_fingerprint", utf82(), true)]), true)), false),
2706
- field2("order_preservation", dictionary2(utf82(), int162()), true),
2707
- field2("max_workers", int322(), true),
2708
- field2("supports_batch_index", bool2(), false),
2709
- field2("supports_splits", bool2(), false),
2710
- field2("filters_exactly_applied", bool2(), false),
2711
- field2("supports_positions", bool2(), false),
2712
- field2("split_token_ttl_seconds", int642(), true),
2713
- field2("partition_kind", dictionary2(utf82(), int162()), false),
2714
- field2("order_dependent", dictionary2(utf82(), int162()), false),
2715
- field2("distinct_dependent", dictionary2(utf82(), int162()), false),
2716
- field2("supports_window", bool2(), false),
2717
- field2("streaming_partitioned", bool2(), false),
2718
- field2("has_finalize", bool2(), false),
2719
- field2("source_order_dependent", bool2(), false),
2720
- field2("sink_order_dependent", bool2(), false),
2721
- field2("requires_input_batch_index", bool2(), false),
2722
- field2("input_from_args", bool2(), false),
2723
- field2("input_rows_per_call", int642(), true),
2724
- field2("required_settings", list2(field2("item", utf82(), true)), false),
2725
- field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false),
2726
- field2("visibility", utf82(), true)
2727
- ]);
2728
- var MacroInfoSchema = schema2([
2729
- field2("comment", utf82(), true),
2730
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2731
- field2("name", utf82(), false),
2732
- field2("schema_path", list2(field2("item", utf82(), true)), false),
2733
- field2("macro_type", dictionary2(utf82(), int162()), false),
2734
- field2("overloads", list2(field2("item", struct2([field2("parameters", list2(field2("item", struct2([field2("name", utf82(), false), field2("declared_type", binary2(), true), field2("default_value", binary2(), true), field2("default_expression", binary2(), true), field2("documentation", utf82(), true)]), true)), false), field2("definition", utf82(), false), field2("profile", utf82(), false), field2("schema_path", list2(field2("item", utf82(), true)), false), field2("macro_type", utf82(), false), field2("evaluation_context", struct2([field2("timezone", utf82(), false), field2("collation", utf82(), false), field2("default_order", utf82(), false), field2("default_null_order", utf82(), false), field2("preserve_insertion_order", bool2(), false)]), false)]), true)), false)
2735
- ]);
2736
- var IndexInfoSchema = schema2([
2737
- field2("comment", utf82(), true),
2738
- field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2739
- field2("name", utf82(), false),
2740
- field2("schema_path", list2(field2("item", utf82(), true)), false),
2741
- field2("definition", binary2(), false),
2742
- field2("options", binary2(), false)
2192
+ var IndexInfoSchema = schema2([
2193
+ field2("comment", utf82(), true),
2194
+ field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2195
+ field2("name", utf82(), false),
2196
+ field2("schema_path", list2(field2("item", utf82(), true)), false),
2197
+ field2("definition", binary2(), false),
2198
+ field2("options", binary2(), false)
2743
2199
  ]);
2744
2200
  var CopyFromFormatInfoSchema = schema2([
2745
2201
  field2("comment", utf82(), true),
@@ -2972,33 +2428,127 @@ var OptionStateSchema = schema2([
2972
2428
  var RequiredFilterPathsSchema = schema2([
2973
2429
  field2("groups", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false)
2974
2430
  ]);
2975
- var ScanFunctionResultSchema = schema2([
2976
- field2("function_name", utf82(), false),
2977
- field2("arguments", binary2(), false),
2978
- field2("required_extensions", list2(field2("item", utf82(), true)), false),
2979
- field2("schema_path", list2(field2("item", utf82(), true)), true)
2431
+ var CopyFromContextSchema = schema2([
2432
+ field2("format", utf82(), false),
2433
+ field2("file_path", utf82(), false),
2434
+ field2("expected_schema", binary2(), false)
2980
2435
  ]);
2981
- var ScanBranchesResultSchema = schema2([
2982
- field2("branches", list2(field2("item", binary2(), true)), false),
2983
- field2("required_extensions", list2(field2("item", utf82(), true)), false)
2436
+ var CopyToContextSchema = schema2([
2437
+ field2("format", utf82(), false),
2438
+ field2("file_path", utf82(), false)
2984
2439
  ]);
2985
- var ScanBranchSchema = schema2([
2986
- field2("function_name", utf82(), false),
2987
- field2("arguments", binary2(), false),
2988
- field2("branch_filter", utf82(), true),
2989
- field2("writable", bool2(), false),
2990
- field2("source_catalog", utf82(), true),
2991
- field2("source_schema_path", list2(field2("item", utf82(), true)), true),
2992
- field2("source_table", utf82(), true),
2993
- field2("format_name", utf82(), true),
2994
- field2("format_locations", list2(field2("item", utf82(), true)), true),
2995
- field2("format_options", binary2(), true),
2996
- field2("schema_path", list2(field2("item", utf82(), true)), true),
2997
- field2("row_count", int642(), true),
2998
- field2("column_statistics", binary2(), true)
2440
+ var ArgumentsLocationSchema = schema2([
2441
+ field2("ref", binary2(), false),
2442
+ field2("size", int642(), false),
2443
+ field2("sha256", utf82(), false)
2999
2444
  ]);
3000
- var ScanSplitSchema = schema2([
3001
- field2("payload", binary2(), false),
2445
+ var BindRequestSchema = schema2([
2446
+ field2("function_name", utf82(), false),
2447
+ field2("arguments", binary2(), true),
2448
+ field2("function_type", dictionary2(utf82(), int162()), false),
2449
+ field2("input_schema", binary2(), true),
2450
+ field2("settings", binary2(), true),
2451
+ field2("secrets", binary2(), true),
2452
+ field2("attach_opaque_data", binary2(), true),
2453
+ field2("transaction_opaque_data", binary2(), true),
2454
+ field2("resolved_secrets_provided", bool2(), false),
2455
+ field2("at_unit", utf82(), true),
2456
+ field2("at_value", utf82(), true),
2457
+ field2("copy_from", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false), field2("expected_schema", binary2(), false)]), true),
2458
+ field2("copy_to", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false)]), true),
2459
+ field2("schema_path", list2(field2("item", utf82(), true)), true),
2460
+ field2("argument_names", list2(field2("item", utf82(), true)), true),
2461
+ field2("arguments_location", struct2([field2("ref", binary2(), false), field2("size", int642(), false), field2("sha256", utf82(), false)]), true)
2462
+ ]);
2463
+ var InitRequestSchema = schema2([
2464
+ field2("bind_call", binary2(), false),
2465
+ field2("output_schema", binary2(), false),
2466
+ field2("bind_opaque_data", binary2(), true),
2467
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
2468
+ field2("pushdown_filters", largeBinary2(), true),
2469
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
2470
+ field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
2471
+ field2("row_limit", int642(), true),
2472
+ field2("phase", dictionary2(utf82(), int162()), true),
2473
+ field2("finalize_state_id", binary2(), true),
2474
+ field2("execution_id", binary2(), true),
2475
+ field2("init_opaque_data", binary2(), true),
2476
+ field2("substream_id", binary2(), true),
2477
+ field2("order_by_column_name", utf82(), true),
2478
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
2479
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
2480
+ field2("order_by_limit", int642(), true),
2481
+ field2("tablesample_percentage", float642(), true),
2482
+ field2("tablesample_seed", int642(), true)
2483
+ ]);
2484
+ var TableFunctionCardinalityRequestSchema = schema2([
2485
+ field2("bind_call", binary2(), false),
2486
+ field2("bind_opaque_data", binary2(), true)
2487
+ ]);
2488
+ var TableFunctionStatisticsRequestSchema = schema2([
2489
+ field2("bind_call", binary2(), false),
2490
+ field2("bind_opaque_data", binary2(), true)
2491
+ ]);
2492
+ var TableFunctionDynamicToStringRequestSchema = schema2([
2493
+ field2("bind_call", binary2(), false),
2494
+ field2("bind_opaque_data", binary2(), true),
2495
+ field2("global_execution_id", binary2(), false)
2496
+ ]);
2497
+ var TableFunctionPlanRequestSchema = schema2([
2498
+ field2("bind_call", binary2(), false),
2499
+ field2("bind_opaque_data", binary2(), true),
2500
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
2501
+ field2("pushdown_filters", largeBinary2(), true),
2502
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
2503
+ field2("row_limit", int642(), true),
2504
+ field2("target_split_bytes", int642(), true),
2505
+ field2("min_splits", int642(), true),
2506
+ field2("max_splits_per_response", int642(), true),
2507
+ field2("cursor", binary2(), true),
2508
+ field2("refined_filters", largeBinary2(), true),
2509
+ field2("filters_complete", bool2(), false),
2510
+ field2("start_position", binary2(), true),
2511
+ field2("end_position", binary2(), true),
2512
+ field2("order_by_column_name", utf82(), true),
2513
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
2514
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
2515
+ field2("order_by_limit", int642(), true),
2516
+ field2("tablesample_percentage", float642(), true),
2517
+ field2("tablesample_seed", int642(), true)
2518
+ ]);
2519
+ var TableFunctionProjectionRequestSchema = schema2([
2520
+ field2("bind_call", binary2(), false),
2521
+ field2("bind_result", binary2(), false),
2522
+ field2("expressions", list2(field2("item", largeBinary2(), true)), false),
2523
+ field2("result_schema", binary2(), false)
2524
+ ]);
2525
+ var ScanFunctionResultSchema = schema2([
2526
+ field2("function_name", utf82(), false),
2527
+ field2("arguments", binary2(), false),
2528
+ field2("required_extensions", list2(field2("item", utf82(), true)), false),
2529
+ field2("schema_path", list2(field2("item", utf82(), true)), true)
2530
+ ]);
2531
+ var ScanBranchesResultSchema = schema2([
2532
+ field2("branches", list2(field2("item", binary2(), true)), false),
2533
+ field2("required_extensions", list2(field2("item", utf82(), true)), false)
2534
+ ]);
2535
+ var ScanBranchSchema = schema2([
2536
+ field2("function_name", utf82(), false),
2537
+ field2("arguments", binary2(), false),
2538
+ field2("branch_filter", utf82(), true),
2539
+ field2("writable", bool2(), false),
2540
+ field2("source_catalog", utf82(), true),
2541
+ field2("source_schema_path", list2(field2("item", utf82(), true)), true),
2542
+ field2("source_table", utf82(), true),
2543
+ field2("format_name", utf82(), true),
2544
+ field2("format_locations", list2(field2("item", utf82(), true)), true),
2545
+ field2("format_options", binary2(), true),
2546
+ field2("schema_path", list2(field2("item", utf82(), true)), true),
2547
+ field2("row_count", int642(), true),
2548
+ field2("column_statistics", binary2(), true)
2549
+ ]);
2550
+ var ScanSplitSchema = schema2([
2551
+ field2("payload", binary2(), false),
3002
2552
  field2("token", binary2(), false),
3003
2553
  field2("estimated_rows", int642(), true),
3004
2554
  field2("rows_exact", bool2(), false),
@@ -3145,23 +2695,6 @@ var AggregateWindowRequestSchema = schema2([
3145
2695
  field2("attach_opaque_data", binary2(), true),
3146
2696
  field2("schema_path", list2(field2("item", utf82(), true)), true)
3147
2697
  ]);
3148
- var BindRequestSchema = schema2([
3149
- field2("function_name", utf82(), false),
3150
- field2("arguments", binary2(), false),
3151
- field2("function_type", dictionary2(utf82(), int162()), false),
3152
- field2("input_schema", binary2(), true),
3153
- field2("settings", binary2(), true),
3154
- field2("secrets", binary2(), true),
3155
- field2("attach_opaque_data", binary2(), true),
3156
- field2("transaction_opaque_data", binary2(), true),
3157
- field2("resolved_secrets_provided", bool2(), false),
3158
- field2("at_unit", utf82(), true),
3159
- field2("at_value", utf82(), true),
3160
- field2("copy_from", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false), field2("expected_schema", binary2(), false)]), true),
3161
- field2("copy_to", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false)]), true),
3162
- field2("schema_path", list2(field2("item", utf82(), true)), true),
3163
- field2("argument_names", list2(field2("item", utf82(), true)), true)
3164
- ]);
3165
2698
  var CatalogAttachRequestSchema = schema2([
3166
2699
  field2("name", utf82(), false),
3167
2700
  field2("options", binary2(), true),
@@ -3183,15 +2716,6 @@ var ClientCapabilitiesSchema = schema2([
3183
2716
  field2("catalog", binary2(), true),
3184
2717
  field2("query_pushdown", struct2([field2("encodings", list2(field2("item", utf82(), true)), false), field2("semantic_profiles", list2(field2("item", utf82(), true)), false), field2("engine_version", utf82(), false), field2("max_query_bytes", int642(), false)]), true)
3185
2718
  ]);
3186
- var CopyFromContextSchema = schema2([
3187
- field2("format", utf82(), false),
3188
- field2("file_path", utf82(), false),
3189
- field2("expected_schema", binary2(), false)
3190
- ]);
3191
- var CopyToContextSchema = schema2([
3192
- field2("format", utf82(), false),
3193
- field2("file_path", utf82(), false)
3194
- ]);
3195
2719
  var GlobalInitResponseSchema = schema2([
3196
2720
  field2("execution_id", binary2(), false),
3197
2721
  field2("opaque_data", binary2(), true),
@@ -3205,27 +2729,6 @@ var IndexCreateRequestSchema = schema2([
3205
2729
  field2("on_conflict", dictionary2(utf82(), int162()), false),
3206
2730
  field2("transaction_opaque_data", binary2(), true)
3207
2731
  ]);
3208
- var InitRequestSchema = schema2([
3209
- field2("bind_call", binary2(), false),
3210
- field2("output_schema", binary2(), false),
3211
- field2("bind_opaque_data", binary2(), true),
3212
- field2("projection_ids", list2(field2("item", int642(), true)), true),
3213
- field2("pushdown_filters", largeBinary2(), true),
3214
- field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3215
- field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
3216
- field2("row_limit", int642(), true),
3217
- field2("phase", dictionary2(utf82(), int162()), true),
3218
- field2("finalize_state_id", binary2(), true),
3219
- field2("execution_id", binary2(), true),
3220
- field2("init_opaque_data", binary2(), true),
3221
- field2("substream_id", binary2(), true),
3222
- field2("order_by_column_name", utf82(), true),
3223
- field2("order_by_direction", dictionary2(utf82(), int162()), true),
3224
- field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3225
- field2("order_by_limit", int642(), true),
3226
- field2("tablesample_percentage", float642(), true),
3227
- field2("tablesample_seed", int642(), true)
3228
- ]);
3229
2732
  var MacroCreateRequestSchema = schema2([
3230
2733
  field2("attach_opaque_data", binary2(), false),
3231
2734
  field2("schema_path", list2(field2("item", utf82(), true)), false),
@@ -3272,47 +2775,6 @@ var TableBufferingProcessRequestSchema = schema2([
3272
2775
  field2("batch_index", int642(), true),
3273
2776
  field2("schema_path", list2(field2("item", utf82(), true)), true)
3274
2777
  ]);
3275
- var TableFunctionCardinalityRequestSchema = schema2([
3276
- field2("bind_call", binary2(), false),
3277
- field2("bind_opaque_data", binary2(), true)
3278
- ]);
3279
- var TableFunctionDynamicToStringRequestSchema = schema2([
3280
- field2("bind_call", binary2(), false),
3281
- field2("bind_opaque_data", binary2(), true),
3282
- field2("global_execution_id", binary2(), false)
3283
- ]);
3284
- var TableFunctionPlanRequestSchema = schema2([
3285
- field2("bind_call", binary2(), false),
3286
- field2("bind_opaque_data", binary2(), true),
3287
- field2("projection_ids", list2(field2("item", int642(), true)), true),
3288
- field2("pushdown_filters", largeBinary2(), true),
3289
- field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3290
- field2("row_limit", int642(), true),
3291
- field2("target_split_bytes", int642(), true),
3292
- field2("min_splits", int642(), true),
3293
- field2("max_splits_per_response", int642(), true),
3294
- field2("cursor", binary2(), true),
3295
- field2("refined_filters", largeBinary2(), true),
3296
- field2("filters_complete", bool2(), false),
3297
- field2("start_position", binary2(), true),
3298
- field2("end_position", binary2(), true),
3299
- field2("order_by_column_name", utf82(), true),
3300
- field2("order_by_direction", dictionary2(utf82(), int162()), true),
3301
- field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3302
- field2("order_by_limit", int642(), true),
3303
- field2("tablesample_percentage", float642(), true),
3304
- field2("tablesample_seed", int642(), true)
3305
- ]);
3306
- var TableFunctionProjectionRequestSchema = schema2([
3307
- field2("bind_call", binary2(), false),
3308
- field2("bind_result", binary2(), false),
3309
- field2("expressions", list2(field2("item", largeBinary2(), true)), false),
3310
- field2("result_schema", binary2(), false)
3311
- ]);
3312
- var TableFunctionStatisticsRequestSchema = schema2([
3313
- field2("bind_call", binary2(), false),
3314
- field2("bind_opaque_data", binary2(), true)
3315
- ]);
3316
2778
  var AggregateBindResultSchema = schema2([
3317
2779
  field2("output_schema", binary2(), false),
3318
2780
  field2("execution_id", binary2(), false)
@@ -3945,7 +3407,391 @@ var TableFunctionStatisticsParamsSchema = schema2([
3945
3407
  field2("request", binary2(), false)
3946
3408
  ]);
3947
3409
 
3410
+ // src/codec/conform.ts
3411
+ var OPTIONAL_ITEM_FIELDS = new Set(["argument_names"]);
3412
+ function children(type) {
3413
+ return type.children ?? [];
3414
+ }
3415
+ function mapValueType(type) {
3416
+ const entries = children(type)[0].type;
3417
+ return children(entries)[1].type;
3418
+ }
3419
+ function mapPairs(raw) {
3420
+ if (Array.isArray(raw))
3421
+ return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
3422
+ if (raw instanceof Map)
3423
+ return Array.from(raw.entries());
3424
+ if (typeof raw[Symbol.iterator] === "function")
3425
+ return Array.from(raw);
3426
+ return Object.entries(raw);
3427
+ }
3428
+ function zeroValue(type) {
3429
+ if (isDictionary(type))
3430
+ return zeroValue(type.dictionary);
3431
+ if (isUtf8(type))
3432
+ return "";
3433
+ if (isBinary(type))
3434
+ return new Uint8Array(0);
3435
+ if (isBool(type))
3436
+ return false;
3437
+ if (isInt(type))
3438
+ return type.bitWidth === 64 ? 0n : 0;
3439
+ if (isFloat(type))
3440
+ return 0;
3441
+ if (isList(type) || isMap(type))
3442
+ return [];
3443
+ if (isStruct(type)) {
3444
+ const out = {};
3445
+ for (const c of children(type))
3446
+ out[c.name] = c.nullable ? null : conformValue(c.type, undefined, false, c.name);
3447
+ return out;
3448
+ }
3449
+ return null;
3450
+ }
3451
+ var HAS_CONTAINER = new WeakMap;
3452
+ function hasContainer(type) {
3453
+ const cached = HAS_CONTAINER.get(type);
3454
+ if (cached !== undefined)
3455
+ return cached;
3456
+ let has = isList(type) || isMap(type);
3457
+ if (!has && isStruct(type))
3458
+ has = children(type).some((c) => hasContainer(c.type));
3459
+ HAS_CONTAINER.set(type, has);
3460
+ return has;
3461
+ }
3462
+ function conformValue(type, value, nullable, name) {
3463
+ if (value == null) {
3464
+ if (nullable)
3465
+ return value ?? null;
3466
+ if (isList(type) || isMap(type))
3467
+ return [];
3468
+ return value;
3469
+ }
3470
+ if (!hasContainer(type))
3471
+ return value;
3472
+ if (isList(type)) {
3473
+ const itemType = children(type)[0].type;
3474
+ const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
3475
+ const items = Array.isArray(value) ? value : Array.from(value);
3476
+ let changed = !Array.isArray(value);
3477
+ const out = items.map((item) => {
3478
+ const next = item == null && !itemsNullable ? zeroValue(itemType) : conformValue(itemType, item, true, name);
3479
+ if (next !== item)
3480
+ changed = true;
3481
+ return next;
3482
+ });
3483
+ return changed ? out : value;
3484
+ }
3485
+ if (isMap(type)) {
3486
+ const valueType = mapValueType(type);
3487
+ const pairs = mapPairs(value);
3488
+ let changed = false;
3489
+ const out = pairs.map(([k, v]) => {
3490
+ const next = v == null ? zeroValue(valueType) : conformValue(valueType, v, true, name);
3491
+ if (next !== v)
3492
+ changed = true;
3493
+ return [k, next];
3494
+ });
3495
+ return changed ? out : value;
3496
+ }
3497
+ if (isStruct(type)) {
3498
+ let out = null;
3499
+ for (const c of children(type)) {
3500
+ const v = value[c.name];
3501
+ const next = conformValue(c.type, v, c.nullable, c.name);
3502
+ if (next !== v) {
3503
+ (out ??= { ...value })[c.name] = next;
3504
+ }
3505
+ }
3506
+ return out ?? value;
3507
+ }
3508
+ return value;
3509
+ }
3510
+ function conformRecord(schema, obj) {
3511
+ let out = null;
3512
+ for (const f of schema.fields) {
3513
+ const v = obj[f.name];
3514
+ const next = conformValue(f.type, v, f.nullable, f.name);
3515
+ if (next !== v) {
3516
+ (out ??= { ...obj })[f.name] = next;
3517
+ }
3518
+ }
3519
+ return out ?? obj;
3520
+ }
3521
+
3522
+ // src/codec/asd.ts
3523
+ function encodeASD(schema, obj) {
3524
+ return serializeBatch(batchFromRows([sortMapsForSchema(schema, conformRecord(schema, obj))], schema));
3525
+ }
3526
+ function compareCodePoints(a, b) {
3527
+ const n = Math.min(a.length, b.length);
3528
+ for (let i = 0;i < n; i++) {
3529
+ const x = a.charCodeAt(i);
3530
+ const y = b.charCodeAt(i);
3531
+ if (x === y)
3532
+ continue;
3533
+ const xs = x >= 55296 && x <= 57343;
3534
+ const ys = y >= 55296 && y <= 57343;
3535
+ if (xs !== ys)
3536
+ return xs ? 1 : -1;
3537
+ return x - y;
3538
+ }
3539
+ return a.length - b.length;
3540
+ }
3541
+ function mapPairs2(raw) {
3542
+ if (Array.isArray(raw))
3543
+ return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
3544
+ if (raw instanceof Map)
3545
+ return Array.from(raw.entries());
3546
+ if (typeof raw[Symbol.iterator] === "function")
3547
+ return Array.from(raw);
3548
+ return Object.entries(raw);
3549
+ }
3550
+ function compareKeys(a, b) {
3551
+ if (typeof a === "string" && typeof b === "string")
3552
+ return compareCodePoints(a, b);
3553
+ if ((typeof a === "number" || typeof a === "bigint") && (typeof b === "number" || typeof b === "bigint")) {
3554
+ return a < b ? -1 : a > b ? 1 : 0;
3555
+ }
3556
+ return compareCodePoints(String(a), String(b));
3557
+ }
3558
+ var HAS_MAP = new WeakMap;
3559
+ function typeHasMap(type) {
3560
+ const cached = HAS_MAP.get(type);
3561
+ if (cached !== undefined)
3562
+ return cached;
3563
+ let has = isMap(type);
3564
+ if (!has && (isList(type) || isStruct(type))) {
3565
+ has = type.children.some((c) => typeHasMap(c.type));
3566
+ }
3567
+ HAS_MAP.set(type, has);
3568
+ return has;
3569
+ }
3570
+ function sortMapsForType(type, value) {
3571
+ if (value == null || !typeHasMap(type))
3572
+ return value;
3573
+ if (isMap(type)) {
3574
+ const entries = type.children[0].type;
3575
+ const valueType = entries.children[1].type;
3576
+ return mapPairs2(value).map(([k, v]) => [k, sortMapsForType(valueType, v)]).sort((x, y) => compareKeys(x[0], y[0]));
3577
+ }
3578
+ if (isList(type)) {
3579
+ const child = type.children[0].type;
3580
+ return Array.from(value, (v) => sortMapsForType(child, v));
3581
+ }
3582
+ if (isStruct(type)) {
3583
+ const out = { ...value };
3584
+ for (const cf of type.children)
3585
+ out[cf.name] = sortMapsForType(cf.type, value[cf.name]);
3586
+ return out;
3587
+ }
3588
+ return value;
3589
+ }
3590
+ function sortMapsForSchema(schema, obj) {
3591
+ let out = null;
3592
+ for (const f of schema.fields) {
3593
+ if (!typeHasMap(f.type))
3594
+ continue;
3595
+ const v = obj[f.name];
3596
+ if (v == null)
3597
+ continue;
3598
+ out ??= { ...obj };
3599
+ out[f.name] = sortMapsForType(f.type, v);
3600
+ }
3601
+ return out ?? obj;
3602
+ }
3603
+ function decodeASD(schema, bytes) {
3604
+ const batch = deserializeBatch(bytes);
3605
+ if (batch.numRows === 0) {
3606
+ const names = schema.fields.map((f) => f.name).join(",");
3607
+ throw new Error(`decodeASD: empty batch (expected 1 row for ${names})`);
3608
+ }
3609
+ const out = {};
3610
+ for (const field of schema.fields) {
3611
+ const col = batch.getChild(field.name);
3612
+ const raw = col ? col.get(0) : null;
3613
+ out[field.name] = normalizeValue(raw, field.type);
3614
+ }
3615
+ return out;
3616
+ }
3617
+ function normalizeValue(raw, type) {
3618
+ if (raw == null)
3619
+ return null;
3620
+ if (isList(type)) {
3621
+ const childType = type.children[0].type;
3622
+ const out = [];
3623
+ for (const item of raw)
3624
+ out.push(normalizeValue(item, childType));
3625
+ return out;
3626
+ }
3627
+ if (isMap(type)) {
3628
+ const entries = type.children[0].type;
3629
+ const valueType = entries.children[1].type;
3630
+ const out = {};
3631
+ const put = (k, v) => {
3632
+ Object.defineProperty(out, String(k), {
3633
+ value: normalizeValue(v, valueType),
3634
+ enumerable: true,
3635
+ writable: true,
3636
+ configurable: true
3637
+ });
3638
+ };
3639
+ if (raw[Symbol.iterator]) {
3640
+ for (const entry of raw) {
3641
+ if (Array.isArray(entry)) {
3642
+ put(entry[0], entry[1]);
3643
+ } else if (entry && typeof entry === "object") {
3644
+ put(entry.key ?? entry[0], entry.value ?? entry[1]);
3645
+ }
3646
+ }
3647
+ } else if (typeof raw === "object") {
3648
+ for (const [k, v] of Object.entries(raw))
3649
+ put(k, v);
3650
+ }
3651
+ return out;
3652
+ }
3653
+ if (isStruct(type)) {
3654
+ const childFields = type.children;
3655
+ const out = {};
3656
+ for (const cf of childFields) {
3657
+ out[cf.name] = normalizeValue(raw[cf.name], cf.type);
3658
+ }
3659
+ return out;
3660
+ }
3661
+ if (isDictionary(type)) {
3662
+ return normalizeValue(raw, type.dictionary);
3663
+ }
3664
+ if (isBinary(type)) {
3665
+ return toUint8Array(raw);
3666
+ }
3667
+ if (isInt(type) && type.bitWidth === 64) {
3668
+ if (typeof raw === "bigint") {
3669
+ if (raw >= BigInt(Number.MIN_SAFE_INTEGER) && raw <= BigInt(Number.MAX_SAFE_INTEGER)) {
3670
+ return Number(raw);
3671
+ }
3672
+ return raw;
3673
+ }
3674
+ return raw;
3675
+ }
3676
+ if (isBool(type)) {
3677
+ return Boolean(raw);
3678
+ }
3679
+ return raw;
3680
+ }
3681
+ function toUint8Array(val) {
3682
+ if (val instanceof Uint8Array)
3683
+ return val;
3684
+ if (val instanceof ArrayBuffer)
3685
+ return new Uint8Array(val);
3686
+ if (val && val.buffer instanceof ArrayBuffer) {
3687
+ return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
3688
+ }
3689
+ return new Uint8Array(0);
3690
+ }
3691
+ function decodeASDCollection(schema, bytes) {
3692
+ if (bytes == null)
3693
+ return [];
3694
+ const output = [];
3695
+ const batches = deserializeBatches(bytes);
3696
+ const validateSchema = (actualSchema) => {
3697
+ if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
3698
+ const actual = actualSchema.fields[i];
3699
+ return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
3700
+ }))
3701
+ throw new Error("catalog collection has an incompatible metadata schema");
3702
+ };
3703
+ if (batches.length === 0)
3704
+ validateSchema(deserializeSchema(bytes));
3705
+ for (const batch of batches) {
3706
+ validateSchema(batch.schema);
3707
+ for (let row = 0;row < batch.numRows; row++) {
3708
+ const item = {};
3709
+ for (const field of schema.fields) {
3710
+ const value = batch.getChild(field.name)?.get(row);
3711
+ if (value == null && !field.nullable)
3712
+ throw new Error(`catalog collection has null ${field.name}`);
3713
+ item[field.name] = normalizeValue(value, field.type);
3714
+ }
3715
+ output.push(item);
3716
+ }
3717
+ }
3718
+ return output;
3719
+ }
3720
+
3948
3721
  // src/generated/vgi-protocol-types.ts
3722
+ function deepFreeze(value) {
3723
+ if (value !== null && typeof value === "object" && !ArrayBuffer.isView(value) && !Object.isFrozen(value)) {
3724
+ for (const key of Object.keys(value))
3725
+ deepFreeze(value[key]);
3726
+ Object.freeze(value);
3727
+ }
3728
+ return value;
3729
+ }
3730
+ function sameBytes(a, b) {
3731
+ if (a.byteLength !== b.byteLength)
3732
+ return false;
3733
+ for (let i = 0;i < a.byteLength; i++)
3734
+ if (a[i] !== b[i])
3735
+ return false;
3736
+ return true;
3737
+ }
3738
+
3739
+ class Nested {
3740
+ #bytes;
3741
+ #decode;
3742
+ #path;
3743
+ #state;
3744
+ constructor(bytes, decode, path) {
3745
+ this.#bytes = bytes;
3746
+ this.#decode = decode;
3747
+ this.#path = path;
3748
+ }
3749
+ static fromBytes(bytes, decode, path = "nested record") {
3750
+ return new Nested(bytes.slice(), decode, path);
3751
+ }
3752
+ static of(record, encode, decode, path = "nested record") {
3753
+ return new Nested(encode(record).slice(), decode, path);
3754
+ }
3755
+ get bytes() {
3756
+ return this.#bytes;
3757
+ }
3758
+ get byteLength() {
3759
+ return this.#bytes.byteLength;
3760
+ }
3761
+ get path() {
3762
+ return this.#path;
3763
+ }
3764
+ get() {
3765
+ if (this.#state === undefined) {
3766
+ try {
3767
+ if (this.#bytes.byteLength === 0)
3768
+ throw new Error("empty nested record");
3769
+ this.#state = { ok: true, value: deepFreeze(this.#decode(this.#bytes.slice())) };
3770
+ } catch (cause) {
3771
+ const message = cause instanceof Error ? cause.message : String(cause);
3772
+ this.#state = { ok: false, error: new Error(`${this.#path}: ${message}`, { cause }) };
3773
+ }
3774
+ }
3775
+ if (!this.#state.ok)
3776
+ throw this.#state.error;
3777
+ return this.#state.value;
3778
+ }
3779
+ get value() {
3780
+ return this.get();
3781
+ }
3782
+ equals(other) {
3783
+ return other != null && sameBytes(this.#bytes, other.#bytes);
3784
+ }
3785
+ toJSON() {
3786
+ return { nested: this.#path, byteLength: this.#bytes.byteLength };
3787
+ }
3788
+ toString() {
3789
+ return `Nested(${this.#path}, ${this.#bytes.byteLength} bytes)`;
3790
+ }
3791
+ [Symbol.for("nodejs.util.inspect.custom")]() {
3792
+ return this.toString();
3793
+ }
3794
+ }
3949
3795
  function buildMacroOverload(init) {
3950
3796
  return {
3951
3797
  parameters: init.parameters,
@@ -4008,6 +3854,218 @@ var encodeIndexDefinition = (v) => encodeASD(IndexDefinitionSchema, v);
4008
3854
  var decodeIndexDefinition = (b) => decodeASD(IndexDefinitionSchema, b);
4009
3855
  var decodeCatalogContentsResponse = (b) => decodeASD(CatalogContentsResultSchema, b);
4010
3856
 
3857
+ // src/util/bytes.ts
3858
+ function toUint8Array2(val) {
3859
+ if (val instanceof Uint8Array)
3860
+ return val;
3861
+ if (val instanceof ArrayBuffer)
3862
+ return new Uint8Array(val);
3863
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(val))
3864
+ return new Uint8Array(val);
3865
+ if (val && val.buffer instanceof ArrayBuffer) {
3866
+ return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
3867
+ }
3868
+ return new Uint8Array(0);
3869
+ }
3870
+ // src/protocol/serializers/shared.ts
3871
+ function toUint8Array3(val) {
3872
+ if (typeof val === "string")
3873
+ return new TextEncoder().encode(val);
3874
+ const result = toUint8Array2(val);
3875
+ if (result.length === 0 && val != null) {
3876
+ throw new Error(`Cannot convert ${typeof val} to Uint8Array`);
3877
+ }
3878
+ return result;
3879
+ }
3880
+ function buildSingleRowBatch(schema, values) {
3881
+ const cols = {};
3882
+ const row = conformRecord(schema, values);
3883
+ for (const f of schema.fields) {
3884
+ let val = row[f.name];
3885
+ if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
3886
+ val = BigInt(val);
3887
+ }
3888
+ cols[f.name] = [val];
3889
+ }
3890
+ return batchFromColumns(cols, schema);
3891
+ }
3892
+
3893
+ // src/protocol/serializers/bind.ts
3894
+ var BIND_REQUEST_SCHEMA = BindRequestSchema;
3895
+ var receivedBindCalls = new WeakMap;
3896
+ function bindCallBytes(bindCall) {
3897
+ return receivedBindCalls.get(bindCall)?.bytes ?? serializeBatch(serializeBindRequest(bindCall));
3898
+ }
3899
+ function serializeBindRequest(req) {
3900
+ const location = req.arguments_location ?? null;
3901
+ return buildSingleRowBatch(BIND_REQUEST_SCHEMA, {
3902
+ function_name: req.function_name,
3903
+ arguments: location ? null : serializeArguments(req.arguments),
3904
+ function_type: req.function_type == null ? req.function_type : String(req.function_type).toUpperCase(),
3905
+ input_schema: req.input_schema ? serializeSchema(req.input_schema) : null,
3906
+ settings: req.settings ? serializeBatch(req.settings) : null,
3907
+ secrets: req.secrets ? serializeBatch(req.secrets) : null,
3908
+ attach_opaque_data: req.attach_opaque_data ?? null,
3909
+ transaction_opaque_data: req.transaction_opaque_data ?? null,
3910
+ resolved_secrets_provided: req.resolved_secrets_provided ?? false,
3911
+ at_unit: req.at_unit ?? null,
3912
+ at_value: req.at_value ?? null,
3913
+ copy_from: req.copy_from ? {
3914
+ format: req.copy_from.format,
3915
+ file_path: req.copy_from.file_path,
3916
+ expected_schema: serializeSchema(req.copy_from.expected_schema)
3917
+ } : null,
3918
+ copy_to: req.copy_to ? { format: req.copy_to.format, file_path: req.copy_to.file_path } : null,
3919
+ schema_path: req.schema_path ?? null,
3920
+ argument_names: req.argument_names ?? null,
3921
+ arguments_location: location ? { ref: location.ref, size: BigInt(location.size), sha256: location.sha256 } : null
3922
+ });
3923
+ }
3924
+ function parseBindRepeatability(value) {
3925
+ if (value !== "UNKNOWN" && value !== "STABLE_WITHIN_QUERY")
3926
+ throw new Error("invalid bind repeatability");
3927
+ return value;
3928
+ }
3929
+ function deserializeBindResponse(params) {
3930
+ const toStrArray = (val) => {
3931
+ if (!val)
3932
+ return [];
3933
+ const arr = Array.isArray(val) ? val : [...val];
3934
+ return arr.filter((v) => v != null).map(String);
3935
+ };
3936
+ return {
3937
+ output_schema: deserializeSchema(toUint8Array3(params.output_schema)),
3938
+ projection_expression_profiles: toStrArray(params.projection_expression_profiles),
3939
+ opaque_data: params.opaque_data ? toUint8Array3(params.opaque_data) : null,
3940
+ lookup_secret_types: toStrArray(params.lookup_secret_types),
3941
+ lookup_scopes: toStrArray(params.lookup_scopes),
3942
+ lookup_names: toStrArray(params.lookup_names),
3943
+ repeatability: parseBindRepeatability(params.repeatability)
3944
+ };
3945
+ }
3946
+ // src/protocol/serializers/init.ts
3947
+ var INIT_REQUEST_SCHEMA = schema2([
3948
+ field2("bind_call", binary2(), false),
3949
+ field2("output_schema", binary2(), false),
3950
+ field2("bind_opaque_data", binary2(), true),
3951
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
3952
+ field2("pushdown_filters", largeBinary2(), true),
3953
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3954
+ field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
3955
+ field2("row_limit", int642(), true),
3956
+ field2("phase", dictionary2(utf82(), int162()), true),
3957
+ field2("finalize_state_id", binary2(), true),
3958
+ field2("execution_id", binary2(), true),
3959
+ field2("init_opaque_data", binary2(), true),
3960
+ field2("substream_id", binary2(), true),
3961
+ field2("order_by_column_name", utf82(), true),
3962
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
3963
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3964
+ field2("order_by_limit", int642(), true),
3965
+ field2("tablesample_percentage", float642(), true),
3966
+ field2("tablesample_seed", int642(), true)
3967
+ ]);
3968
+ var GLOBAL_INIT_RESPONSE_SCHEMA = schema2([
3969
+ field2("execution_id", binary2(), false),
3970
+ field2("opaque_data", binary2(), true),
3971
+ field2("max_workers", int642(), false)
3972
+ ]);
3973
+ function serializeInitRequest(req) {
3974
+ const row = {
3975
+ bind_call: bindCallBytes(req.bind_call),
3976
+ output_schema: serializeSchema(req.output_schema),
3977
+ bind_opaque_data: req.bind_opaque_data ?? null,
3978
+ projection_ids: req.projection_ids?.map((n) => BigInt(n)) ?? null,
3979
+ pushdown_filters: req.pushdown_filters ? serializeBatch(req.pushdown_filters) : null,
3980
+ join_keys: (req.join_keys ?? []).map((b) => serializeBatch(b)),
3981
+ split_tokens: req.split_tokens ?? null,
3982
+ row_limit: req.row_limit ?? null,
3983
+ phase: req.phase ?? null,
3984
+ finalize_state_id: req.finalize_state_id ?? null,
3985
+ execution_id: req.execution_id ?? null,
3986
+ init_opaque_data: req.init_opaque_data ?? null,
3987
+ substream_id: req.substream_id ?? null,
3988
+ order_by_column_name: req.order_by_column_name ?? null,
3989
+ order_by_direction: req.order_by_direction ?? null,
3990
+ order_by_null_order: req.order_by_null_order ?? null,
3991
+ order_by_limit: req.order_by_limit ?? null,
3992
+ tablesample_percentage: req.tablesample_percentage ?? null,
3993
+ tablesample_seed: req.tablesample_seed ?? null
3994
+ };
3995
+ return buildSingleRowBatch(INIT_REQUEST_SCHEMA, row);
3996
+ }
3997
+ function deserializeGlobalInitResponse(params) {
3998
+ return {
3999
+ execution_id: toUint8Array3(params.execution_id),
4000
+ opaque_data: params.opaque_data ? toUint8Array3(params.opaque_data) : null,
4001
+ max_workers: Number(params.max_workers)
4002
+ };
4003
+ }
4004
+ // src/errors.ts
4005
+ class VgiError extends Error {
4006
+ errorCode;
4007
+ constructor(message, code) {
4008
+ super(message);
4009
+ this.name = "VgiError";
4010
+ if (code !== undefined)
4011
+ this.errorCode = code;
4012
+ }
4013
+ }
4014
+
4015
+ class RowCountMismatchError extends VgiError {
4016
+ constructor(expected, actual) {
4017
+ super(`Scalar function output row count (${actual}) does not match ` + `input row count (${expected})`);
4018
+ this.name = "RowCountMismatchError";
4019
+ }
4020
+ }
4021
+
4022
+ class FunctionNotFoundError extends VgiError {
4023
+ constructor(name, available) {
4024
+ super(`Unknown function '${name}'`, "NOT_FOUND");
4025
+ this.name = "FunctionNotFoundError";
4026
+ }
4027
+ }
4028
+
4029
+ class CatalogReadOnlyError extends VgiError {
4030
+ constructor(operation) {
4031
+ super(`catalog is read-only: ${operation} is not supported`, "FAILED_PRECONDITION");
4032
+ this.name = "CatalogReadOnlyError";
4033
+ }
4034
+ }
4035
+
4036
+ class CatalogNotFoundError extends VgiError {
4037
+ constructor(entity, name) {
4038
+ super(`${entity} '${name}' not found`, "NOT_FOUND");
4039
+ this.name = "CatalogNotFoundError";
4040
+ }
4041
+ }
4042
+
4043
+ class CatalogAlreadyExistsError extends VgiError {
4044
+ constructor(entity, name) {
4045
+ super(`${entity} '${name}' already exists`, "ALREADY_EXISTS");
4046
+ this.name = "CatalogAlreadyExistsError";
4047
+ }
4048
+ }
4049
+
4050
+ class ArgumentValidationError extends VgiError {
4051
+ constructor(message) {
4052
+ super(message, "INVALID_ARGUMENT");
4053
+ this.name = "ArgumentValidationError";
4054
+ }
4055
+ }
4056
+
4057
+ class NoCatalogError extends VgiError {
4058
+ constructor() {
4059
+ super("No catalog is configured for this worker", "UNIMPLEMENTED");
4060
+ this.name = "NoCatalogError";
4061
+ }
4062
+ }
4063
+
4064
+ // src/schema-path.ts
4065
+ function normalizeSchemaPath(path) {
4066
+ return typeof path === "string" ? [path] : Array.from(path, String);
4067
+ }
4068
+
4011
4069
  // src/catalog/sql-grammar.ts
4012
4070
  class GrammarError extends Error {
4013
4071
  }
@@ -5297,7 +5355,7 @@ function decodeScanFunctionResult(inner) {
5297
5355
  const positionalArguments = [];
5298
5356
  const namedArguments = {};
5299
5357
  if (argsBytes != null) {
5300
- const batch = deserializeBatch(toUint8Array(argsBytes));
5358
+ const batch = deserializeBatch(toUint8Array2(argsBytes));
5301
5359
  for (const field of batch.schema.fields) {
5302
5360
  const col = batch.getChild(field.name);
5303
5361
  const value = col ? col.get(0) : null;
@@ -5325,7 +5383,7 @@ var stringList = (value) => value == null ? null : (Array.isArray(value) ? value
5325
5383
  function decodeScanBranchesResult(inner) {
5326
5384
  const raw = inner.branches == null ? [] : Array.isArray(inner.branches) ? inner.branches : [...inner.branches];
5327
5385
  const branches = raw.map((bytes) => {
5328
- const batch = deserializeBatch(toUint8Array(bytes));
5386
+ const batch = deserializeBatch(toUint8Array2(bytes));
5329
5387
  const row = {};
5330
5388
  for (const f of batch.schema.fields)
5331
5389
  row[f.name] = batch.getChild(f.name)?.get(0) ?? null;
@@ -5350,7 +5408,7 @@ function wrapRequest(batch) {
5350
5408
  return { request: serializeBatch(batch) };
5351
5409
  }
5352
5410
  function unwrapResult(result) {
5353
- const resultBytes = toUint8Array(result.result);
5411
+ const resultBytes = toUint8Array2(result.result);
5354
5412
  const innerBatch = deserializeBatch(resultBytes);
5355
5413
  return batchToScalarDict(innerBatch);
5356
5414
  }
@@ -5702,7 +5760,7 @@ function deserializeInfoList(items, deserializeFn) {
5702
5760
  if (!items)
5703
5761
  return [];
5704
5762
  const arr = Array.isArray(items) ? items : [...items];
5705
- return arr.filter((b) => b != null).map((b) => deserializeFn(toUint8Array(b)));
5763
+ return arr.filter((b) => b != null).map((b) => deserializeFn(toUint8Array2(b)));
5706
5764
  }
5707
5765
  function deserializeTags(mapVal) {
5708
5766
  const tags = {};
@@ -6098,20 +6156,20 @@ class VgiClient {
6098
6156
  throw new VgiClientError("catalog_attach returned null");
6099
6157
  const inner = unwrapResult(result);
6100
6158
  return {
6101
- attach_opaque_data: toUint8Array(inner.attach_opaque_data),
6159
+ attach_opaque_data: toUint8Array2(inner.attach_opaque_data),
6102
6160
  supports_transactions: inner.supports_transactions ?? false,
6103
6161
  supports_time_travel: inner.supports_time_travel ?? false,
6104
6162
  catalog_version_frozen: inner.catalog_version_frozen ?? false,
6105
6163
  catalog_version: Number(inner.catalog_version ?? 0),
6106
6164
  attach_opaque_data_required: inner.attach_opaque_data_required ?? true,
6107
6165
  default_schema: inner.default_schema ?? null,
6108
- settings: inner.settings ? (Array.isArray(inner.settings) ? inner.settings : [...inner.settings]).map(toUint8Array) : [],
6109
- secret_types: inner.secret_types ? (Array.isArray(inner.secret_types) ? inner.secret_types : [...inner.secret_types]).map(toUint8Array) : [],
6110
- attach_catalogs: inner.attach_catalogs ? (Array.isArray(inner.attach_catalogs) ? inner.attach_catalogs : [...inner.attach_catalogs]).map(toUint8Array) : [],
6166
+ settings: inner.settings ? (Array.isArray(inner.settings) ? inner.settings : [...inner.settings]).map(toUint8Array2) : [],
6167
+ secret_types: inner.secret_types ? (Array.isArray(inner.secret_types) ? inner.secret_types : [...inner.secret_types]).map(toUint8Array2) : [],
6168
+ attach_catalogs: inner.attach_catalogs ? (Array.isArray(inner.attach_catalogs) ? inner.attach_catalogs : [...inner.attach_catalogs]).map(toUint8Array2) : [],
6111
6169
  comment: inner.comment ?? null,
6112
6170
  tags: deserializeTags(inner.tags),
6113
6171
  supports_column_statistics: inner.supports_column_statistics ?? false,
6114
- global_functions: inner.global_functions ? (Array.isArray(inner.global_functions) ? inner.global_functions : [...inner.global_functions]).map(toUint8Array) : [],
6172
+ global_functions: inner.global_functions ? (Array.isArray(inner.global_functions) ? inner.global_functions : [...inner.global_functions]).map(toUint8Array2) : [],
6115
6173
  global_function_prefix: inner.global_function_prefix ?? "",
6116
6174
  resolved_data_version: inner.resolved_data_version ?? null,
6117
6175
  resolved_implementation_version: inner.resolved_implementation_version ?? null,
@@ -6125,7 +6183,7 @@ class VgiClient {
6125
6183
  });
6126
6184
  if (!result)
6127
6185
  throw new VgiClientError("catalog_contents returned null");
6128
- const response = decodeCatalogContentsResponse(toUint8Array(result.result));
6186
+ const response = decodeCatalogContentsResponse(toUint8Array2(result.result));
6129
6187
  const schemas = decodeCatalogStreams(response, ifNoneMatch);
6130
6188
  return {
6131
6189
  catalog_version: Number(response.catalog_version ?? 0),
@@ -6260,7 +6318,7 @@ class VgiClient {
6260
6318
  if (!inner.transaction_opaque_data) {
6261
6319
  throw new VgiClientError("transaction_begin returned no transaction_opaque_data");
6262
6320
  }
6263
- return toUint8Array(inner.transaction_opaque_data);
6321
+ return toUint8Array2(inner.transaction_opaque_data);
6264
6322
  }
6265
6323
  async transactionCommit(attachOpaqueData, transactionOpaqueData) {
6266
6324
  await this.rpc.call("catalog_transaction_commit", {
@@ -6778,12 +6836,12 @@ function deserializeAttachOptionSpec(bytes) {
6778
6836
  if (row === undefined) {
6779
6837
  throw new Error("Cannot deserialize AttachOptionSpec from an empty batch");
6780
6838
  }
6781
- const typeSchema = deserializeSchema(toUint8Array(row.type));
6839
+ const typeSchema = deserializeSchema(toUint8Array2(row.type));
6782
6840
  const type = typeSchema.fields[0].type;
6783
6841
  let value;
6784
6842
  const defaultBytes = row.default_value;
6785
6843
  if (defaultBytes != null) {
6786
- const asBytes = toUint8Array(defaultBytes);
6844
+ const asBytes = toUint8Array2(defaultBytes);
6787
6845
  if (asBytes.length > 0) {
6788
6846
  const defaultRow = [...iterRows(deserializeBatch(asBytes))][0];
6789
6847
  value = defaultRow?.value;
@@ -6900,7 +6958,7 @@ export {
6900
6958
  servedTableInfo,
6901
6959
  servedTableSchema,
6902
6960
  sqlExpression,
6903
- toUint8Array,
6961
+ toUint8Array2 as toUint8Array,
6904
6962
  typeSignature,
6905
6963
  validateColumnExpressionSql,
6906
6964
  validateConstraintNullability,
@@ -6909,4 +6967,4 @@ export {
6909
6967
  validateTableConstraints
6910
6968
  };
6911
6969
 
6912
- //# debugId=DFB6060E5EBBB9FD64756E2164756E21
6970
+ //# debugId=26F4308C14E0381064756E2164756E21