@query-farm/vgi 0.49.2 → 0.50.1

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 (37) hide show
  1. package/README.md +1 -1
  2. package/dist/catalog/composite.d.ts +1 -1
  3. package/dist/catalog/descriptors.d.ts +34 -2
  4. package/dist/catalog/interface.d.ts +47 -8
  5. package/dist/catalog/read-only.d.ts +48 -1
  6. package/dist/client/client.d.ts +13 -7
  7. package/dist/client-entry.d.ts +1 -1
  8. package/dist/client-entry.js +40 -16
  9. package/dist/client-entry.js.map +6 -6
  10. package/dist/functions/storage.d.ts +7 -0
  11. package/dist/generated/vgi-client.d.ts +4 -0
  12. package/dist/generated/vgi-protocol-schemas.d.ts +2 -2
  13. package/dist/generated/vgi-service.d.ts +7 -26
  14. package/dist/index.core.d.ts +4 -3
  15. package/dist/index.js +265 -170
  16. package/dist/index.js.map +16 -16
  17. package/dist/protocol/dispatch.d.ts +5 -3
  18. package/dist/serve-entry.js +43 -45
  19. package/dist/serve-entry.js.map +9 -9
  20. package/dist/worker-cf-entry.js +221 -154
  21. package/dist/worker-cf-entry.js.map +15 -15
  22. package/dist/write-results.d.ts +8 -1
  23. package/package.json +1 -1
  24. package/src/catalog/composite.ts +2 -2
  25. package/src/catalog/descriptors.ts +35 -2
  26. package/src/catalog/interface.ts +78 -10
  27. package/src/catalog/read-only.ts +297 -175
  28. package/src/client/client.ts +22 -13
  29. package/src/client-entry.ts +4 -0
  30. package/src/functions/storage.ts +44 -3
  31. package/src/generated/vgi-client.ts +6 -1
  32. package/src/generated/vgi-protocol-schemas.ts +8 -12
  33. package/src/generated/vgi-service.ts +9 -48
  34. package/src/index.core.ts +4 -3
  35. package/src/protocol/dispatch.ts +5 -3
  36. package/src/protocol/handlers/catalog/table.ts +14 -21
  37. package/src/write-results.ts +8 -3
package/dist/index.js CHANGED
@@ -2331,12 +2331,34 @@ class FunctionStorageSqlite {
2331
2331
  this.dbPath = dbPath ?? getDefaultDbPath();
2332
2332
  const Db = _loadDatabase();
2333
2333
  this._db = new Db(this.dbPath);
2334
- this._db.exec("PRAGMA journal_mode=WAL");
2334
+ this._db.exec(`PRAGMA busy_timeout=${BUSY_TIMEOUT_MS}`);
2335
+ this._setWal();
2335
2336
  this._db.exec("PRAGMA synchronous=NORMAL");
2336
- this._db.exec("PRAGMA busy_timeout=30000");
2337
2337
  this._db.exec("PRAGMA temp_store=MEMORY");
2338
2338
  this._db.exec("PRAGMA cache_size=-65536");
2339
- this._ensureTables();
2339
+ this._db.exec("BEGIN IMMEDIATE");
2340
+ try {
2341
+ this._ensureTables();
2342
+ this._db.exec("COMMIT");
2343
+ } catch (e) {
2344
+ try {
2345
+ this._db.exec("ROLLBACK");
2346
+ } catch {}
2347
+ throw e;
2348
+ }
2349
+ }
2350
+ _setWal() {
2351
+ const deadline = Date.now() + BUSY_TIMEOUT_MS;
2352
+ for (let delay = 5;; delay = Math.min(delay * 2, 100)) {
2353
+ try {
2354
+ this._db.exec("PRAGMA journal_mode=WAL");
2355
+ return;
2356
+ } catch (e) {
2357
+ if (!String(e?.code ?? "").startsWith("SQLITE_BUSY") || Date.now() >= deadline)
2358
+ throw e;
2359
+ Atomics.wait(_SLEEP_CELL, 0, 0, delay);
2360
+ }
2361
+ }
2340
2362
  }
2341
2363
  close() {
2342
2364
  this._db.close();
@@ -2524,7 +2546,7 @@ function setStorage(impl) {
2524
2546
  function bufferArg(data) {
2525
2547
  return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
2526
2548
  }
2527
- var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD = "node:os", _NODE_PATH_MOD = "node:path", _NODE_FS_MOD = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, _resolved = null, storage;
2549
+ var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD = "node:os", _NODE_PATH_MOD = "node:path", _NODE_FS_MOD = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, BUSY_TIMEOUT_MS = 30000, _SLEEP_CELL, _resolved = null, storage;
2528
2550
  var init_storage = __esm(() => {
2529
2551
  UnknownInvocationError = class UnknownInvocationError extends Error {
2530
2552
  constructor(message) {
@@ -2543,6 +2565,7 @@ var init_storage = __esm(() => {
2543
2565
  STREAMING_FINALIZE: textBytes("_vgi/streaming_finalize")
2544
2566
  };
2545
2567
  NS_WORKER2 = new TextEncoder().encode("worker");
2568
+ _SLEEP_CELL = new Int32Array(new SharedArrayBuffer(4));
2546
2569
  storage = new Proxy({}, {
2547
2570
  get(_t, prop, _r) {
2548
2571
  const inst = getDefaultStorage();
@@ -2698,10 +2721,6 @@ function writeOptions(bindCall) {
2698
2721
  return out;
2699
2722
  if (row.result_mode != null)
2700
2723
  out.resultMode = coerceWriteResultMode(row.result_mode);
2701
- if (row.on_conflict != null)
2702
- out.onConflict = String(row.on_conflict);
2703
- if (row.on_conflict_columns != null)
2704
- out.onConflictColumns = Array.from(row.on_conflict_columns);
2705
2724
  return out;
2706
2725
  }
2707
2726
  // src/secrets/requirements.ts
@@ -8954,7 +8973,7 @@ function decodeASDCollection(schema, bytes) {
8954
8973
 
8955
8974
  // src/generated/vgi-protocol-schemas.ts
8956
8975
  init_arrow();
8957
- var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
8976
+ var VGI_CATALOG_CONTRACT_HASH = "e0965c93219b6ef6574d82c007c600462594a08085db1242b127ed27e193da0f";
8958
8977
  var CatalogInfoSchema = schema2([
8959
8978
  field2("name", utf82(), false),
8960
8979
  field2("implementation_version", utf82(), true),
@@ -9045,7 +9064,8 @@ var FunctionInfoSchema = schema2([
9045
9064
  field2("input_from_args", bool2(), false),
9046
9065
  field2("input_rows_per_call", int642(), true),
9047
9066
  field2("required_settings", list2(field2("item", utf82(), true)), false),
9048
- field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
9067
+ field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false),
9068
+ field2("visibility", utf82(), true)
9049
9069
  ]);
9050
9070
  var MacroInfoSchema = schema2([
9051
9071
  field2("comment", utf82(), true),
@@ -9758,6 +9778,9 @@ var CatalogTableConstraintsApplyResultSchema = schema2([
9758
9778
  field2("definition_revision", binary2(), false),
9759
9779
  field2("constraints", list2(field2("item", binary2(), true)), false)
9760
9780
  ]);
9781
+ var CatalogTableCreateResultSchema = schema2([
9782
+ field2("created", bool2(), false)
9783
+ ]);
9761
9784
  var CatalogTableGetResultSchema = schema2([
9762
9785
  field2("items", list2(field2("item", binary2(), true)), false)
9763
9786
  ]);
@@ -10163,14 +10186,6 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
10163
10186
  field2("transaction_opaque_data", binary2(), true),
10164
10187
  field2("pushdown_filters", binary2(), true)
10165
10188
  ]);
10166
- var CatalogTableScanFunctionGetParamsSchema = schema2([
10167
- field2("attach_opaque_data", binary2(), false),
10168
- field2("schema_path", list2(field2("item", utf82(), true)), false),
10169
- field2("name", utf82(), false),
10170
- field2("at_unit", utf82(), true),
10171
- field2("at_value", utf82(), true),
10172
- field2("transaction_opaque_data", binary2(), true)
10173
- ]);
10174
10189
  var CatalogTableUpdateFunctionGetParamsSchema = schema2([
10175
10190
  field2("attach_opaque_data", binary2(), false),
10176
10191
  field2("schema_path", list2(field2("item", utf82(), true)), false),
@@ -11771,6 +11786,29 @@ function decodeScanFunctionResult(inner) {
11771
11786
  schemaPath: inner.schema_path == null ? null : (Array.isArray(inner.schema_path) ? inner.schema_path : [...inner.schema_path]).filter((value) => value != null).map(String)
11772
11787
  };
11773
11788
  }
11789
+ var stringList = (value) => value == null ? null : (Array.isArray(value) ? value : [...value]).filter((v) => v != null).map(String);
11790
+ function decodeScanBranchesResult(inner) {
11791
+ const raw = inner.branches == null ? [] : Array.isArray(inner.branches) ? inner.branches : [...inner.branches];
11792
+ const branches = raw.map((bytes) => {
11793
+ const batch = deserializeBatch(toUint8Array(bytes));
11794
+ const row = {};
11795
+ for (const f of batch.schema.fields)
11796
+ row[f.name] = batch.getChild(f.name)?.get(0) ?? null;
11797
+ const fn = decodeScanFunctionResult(row);
11798
+ return {
11799
+ ...fn,
11800
+ branchFilter: row.branch_filter == null ? null : String(row.branch_filter),
11801
+ writable: row.writable === true,
11802
+ sourceCatalog: row.source_catalog == null ? null : String(row.source_catalog),
11803
+ sourceSchemaPath: stringList(row.source_schema_path),
11804
+ sourceTable: row.source_table == null ? null : String(row.source_table),
11805
+ formatName: row.format_name == null ? null : String(row.format_name),
11806
+ formatLocations: stringList(row.format_locations),
11807
+ rowCount: row.row_count == null ? null : BigInt(row.row_count)
11808
+ };
11809
+ });
11810
+ return { branches, requiredExtensions: stringList(inner.required_extensions) ?? [] };
11811
+ }
11774
11812
  function singleBranchResult(legacy) {
11775
11813
  return {
11776
11814
  branches: [
@@ -12117,6 +12155,16 @@ function sameBytes2(a, b) {
12117
12155
  return false;
12118
12156
  return true;
12119
12157
  }
12158
+ // src/catalog/descriptors.ts
12159
+ var FUNCTION_VISIBILITY_PUBLIC = "public";
12160
+ var FUNCTION_VISIBILITY_TABLE_ONLY = "table_only";
12161
+ function schemaDescriptorPath(schema) {
12162
+ if (schema.path)
12163
+ return schema.path;
12164
+ if (schema.name)
12165
+ return [schema.name];
12166
+ throw new Error("SchemaDescriptor requires a non-empty path");
12167
+ }
12120
12168
  // src/catalog/scan-planning.ts
12121
12169
  init_arrow();
12122
12170
  var SCAN_PLANNING_BIND = "bind";
@@ -12506,15 +12554,6 @@ function encodeValidatedTableInfo(info) {
12506
12554
  // src/catalog/read-only.ts
12507
12555
  init_arrow();
12508
12556
 
12509
- // src/catalog/descriptors.ts
12510
- function schemaDescriptorPath(schema) {
12511
- if (schema.path)
12512
- return schema.path;
12513
- if (schema.name)
12514
- return [schema.name];
12515
- throw new Error("SchemaDescriptor requires a non-empty path");
12516
- }
12517
-
12518
12557
  // src/metadata/types.ts
12519
12558
  var CatalogFunctionType;
12520
12559
  ((CatalogFunctionType) => {
@@ -12875,6 +12914,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
12875
12914
  _version = 1;
12876
12915
  _functionListings = new Map;
12877
12916
  _functionInfos = new Map;
12917
+ _builtListings;
12878
12918
  constructor(descriptor, registry, options = {}) {
12879
12919
  super();
12880
12920
  if (descriptor.defaultSchema != null && (descriptor.defaultSchema.length === 0 || descriptor.defaultSchema.includes("\x00"))) {
@@ -12903,12 +12943,18 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
12903
12943
  }
12904
12944
  }
12905
12945
  }
12946
+ get _listings() {
12947
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listings;
12948
+ }
12949
+ get _listedIn() {
12950
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listedIn;
12951
+ }
12952
+ functionVisibility(schema, fn) {
12953
+ return this._listings.get(schema)?.get(fn) ?? null;
12954
+ }
12906
12955
  _schemaForFunction(fn) {
12907
- for (const sch of this._descriptor.schemas ?? []) {
12908
- if ((sch.functions ?? []).includes(fn))
12909
- return schemaDescriptorPath(sch);
12910
- }
12911
- return null;
12956
+ const sch = this._listedIn.get(fn);
12957
+ return sch ? schemaDescriptorPath(sch) : null;
12912
12958
  }
12913
12959
  catalogs() {
12914
12960
  return [this._descriptor.name];
@@ -13003,7 +13049,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13003
13049
  }
13004
13050
  _estimatedObjectCount(s) {
13005
13051
  let scalar = 0, aggregate = 0, table = 0;
13006
- for (const f of s.functions ?? []) {
13052
+ for (const f of this._listings.get(s)?.keys() ?? []) {
13007
13053
  if (f.kind === "scalar")
13008
13054
  scalar++;
13009
13055
  else if (f.kind === "aggregate")
@@ -13172,12 +13218,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13172
13218
  }
13173
13219
  schemaContentsFunctions(attachOpaqueData, path, type, transactionOpaqueData) {
13174
13220
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
13175
- if (!schema || !schema.functions)
13221
+ const entries = schema ? this._listings.get(schema) : undefined;
13222
+ if (!schema || !entries || entries.size === 0)
13176
13223
  return [];
13224
+ const listed = [...entries.keys()];
13177
13225
  const kind = functionListingKind(type);
13178
13226
  const canonicalPath = schemaDescriptorPath(schema);
13179
13227
  if (!sameSpelling(path, canonicalPath)) {
13180
- return schema.functions.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path));
13228
+ return listed.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path, entries.get(f)));
13181
13229
  }
13182
13230
  let listings = this._functionListings.get(schema);
13183
13231
  if (!listings) {
@@ -13186,7 +13234,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13186
13234
  }
13187
13235
  let listing = listings.get(kind);
13188
13236
  if (!listing) {
13189
- listing = Object.freeze(schema.functions.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
13237
+ listing = Object.freeze(listed.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
13190
13238
  listings.set(kind, listing);
13191
13239
  }
13192
13240
  return listing.slice();
@@ -13199,106 +13247,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13199
13247
  }
13200
13248
  let info = infos.get(f);
13201
13249
  if (!info) {
13202
- info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema))));
13250
+ const visibility = this.functionVisibility(schema, f) ?? FUNCTION_VISIBILITY_PUBLIC;
13251
+ info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema), visibility)));
13203
13252
  infos.set(f, info);
13204
13253
  }
13205
13254
  return info;
13206
13255
  }
13207
- _functionToInfo(f, path) {
13208
- const meta = resolveMetadata(f);
13209
- const argSchema = argumentSpecsToSchema(f.argumentSpecs);
13210
- const argBytes = serializeSchema(argSchema);
13211
- const defaults = f.meta.parameterDefaultValues ?? null;
13212
- if (defaults) {
13213
- if (defaults.numRows !== 1) {
13214
- throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
13215
- }
13216
- let argumentIndex = 0;
13217
- for (const defaultField of defaults.schema.fields) {
13218
- while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
13219
- argumentIndex++;
13220
- }
13221
- if (argumentIndex === argSchema.fields.length) {
13222
- throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
13223
- }
13224
- const argumentField = argSchema.fields[argumentIndex];
13225
- if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
13226
- throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
13227
- }
13228
- argumentIndex++;
13229
- }
13230
- }
13231
- const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
13232
- const requiredSecrets = meta.requiredSecrets.map((s) => ({
13233
- secret_type: s.secretType,
13234
- scope: s.scope,
13235
- secret_name: s.secretName
13236
- }));
13237
- const derivedTags = {};
13238
- const tags = { ...derivedTags, ...meta.tags ?? {} };
13239
- return {
13240
- comment: null,
13241
- tags,
13242
- name: f.meta.name,
13243
- schema_path: normalizeSchemaPath(path),
13244
- function_type: meta.functionType.toUpperCase(),
13245
- arguments: argBytes,
13246
- output_schema: outputSchemaBytes,
13247
- parameter_default_values: defaults ? serializeBatch(defaults) : null,
13248
- stability: meta.stability,
13249
- null_handling: meta.nullHandling,
13250
- argument_monotonicity: meta.argumentMonotonicity,
13251
- description: meta.description,
13252
- examples: meta.examples.map((e) => ({
13253
- sql: e.sql,
13254
- description: e.description,
13255
- expected_output: null
13256
- })),
13257
- categories: meta.categories,
13258
- projection_pushdown: meta.projectionPushdown,
13259
- filter_pushdown: meta.filterPushdown,
13260
- sampling_pushdown: meta.samplingPushdown,
13261
- late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
13262
- filter_semantic_profiles: meta.filterSemanticProfiles,
13263
- additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
13264
- namespace: value.namespace,
13265
- name: value.name,
13266
- version: BigInt(value.version)
13267
- })),
13268
- runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
13269
- namespace: value.namespace,
13270
- name: value.name,
13271
- version: BigInt(value.version)
13272
- })),
13273
- filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
13274
- profile: value.profile,
13275
- provider_fingerprint: value.providerFingerprint
13276
- })),
13277
- order_preservation: meta.preservesOrder,
13278
- max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
13279
- supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
13280
- supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
13281
- filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
13282
- supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
13283
- split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
13284
- partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
13285
- order_dependent: meta.orderDependent,
13286
- distinct_dependent: meta.distinctDependent,
13287
- supports_window: false,
13288
- streaming_partitioned: false,
13289
- has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
13290
- source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
13291
- sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
13292
- requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
13293
- input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
13294
- input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
13295
- required_settings: meta.requiredSettings,
13296
- required_secrets: requiredSecrets.map((s) => ({
13297
- secret_type: s.secret_type,
13298
- scope: s.scope,
13299
- secret_name: s.secret_name
13300
- }))
13301
- };
13256
+ _functionToInfo(f, path, visibility) {
13257
+ return functionInfoFor(f, path, visibility);
13302
13258
  }
13303
13259
  _globalFunctionInfos() {
13304
13260
  const globals = this._descriptor.globalFunctions ?? [];
@@ -13664,6 +13620,104 @@ function sameSpelling(left, right) {
13664
13620
  const b = normalizeSchemaPath(right);
13665
13621
  return a.length === b.length && a.every((part, i) => part === b[i]);
13666
13622
  }
13623
+ function functionInfoFor(f, schemaPath, visibility = FUNCTION_VISIBILITY_PUBLIC) {
13624
+ const path = schemaPath;
13625
+ const meta = resolveMetadata(f);
13626
+ const argSchema = argumentSpecsToSchema(f.argumentSpecs);
13627
+ const argBytes = serializeSchema(argSchema);
13628
+ const defaults = f.meta.parameterDefaultValues ?? null;
13629
+ if (defaults) {
13630
+ if (defaults.numRows !== 1) {
13631
+ throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
13632
+ }
13633
+ let argumentIndex = 0;
13634
+ for (const defaultField of defaults.schema.fields) {
13635
+ while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
13636
+ argumentIndex++;
13637
+ }
13638
+ if (argumentIndex === argSchema.fields.length) {
13639
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
13640
+ }
13641
+ const argumentField = argSchema.fields[argumentIndex];
13642
+ if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
13643
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
13644
+ }
13645
+ argumentIndex++;
13646
+ }
13647
+ }
13648
+ const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
13649
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
13650
+ secret_type: s.secretType,
13651
+ scope: s.scope,
13652
+ secret_name: s.secretName
13653
+ }));
13654
+ const derivedTags = {};
13655
+ const tags = { ...derivedTags, ...meta.tags ?? {} };
13656
+ return {
13657
+ comment: null,
13658
+ tags,
13659
+ name: f.meta.name,
13660
+ schema_path: normalizeSchemaPath(path),
13661
+ function_type: meta.functionType.toUpperCase(),
13662
+ arguments: argBytes,
13663
+ output_schema: outputSchemaBytes,
13664
+ parameter_default_values: defaults ? serializeBatch(defaults) : null,
13665
+ stability: meta.stability,
13666
+ null_handling: meta.nullHandling,
13667
+ argument_monotonicity: meta.argumentMonotonicity,
13668
+ description: meta.description,
13669
+ examples: meta.examples.map((e) => ({
13670
+ sql: e.sql,
13671
+ description: e.description,
13672
+ expected_output: null
13673
+ })),
13674
+ categories: meta.categories,
13675
+ projection_pushdown: meta.projectionPushdown,
13676
+ filter_pushdown: meta.filterPushdown,
13677
+ sampling_pushdown: meta.samplingPushdown,
13678
+ late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
13679
+ filter_semantic_profiles: meta.filterSemanticProfiles,
13680
+ additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
13681
+ namespace: value.namespace,
13682
+ name: value.name,
13683
+ version: BigInt(value.version)
13684
+ })),
13685
+ runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
13686
+ namespace: value.namespace,
13687
+ name: value.name,
13688
+ version: BigInt(value.version)
13689
+ })),
13690
+ filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
13691
+ profile: value.profile,
13692
+ provider_fingerprint: value.providerFingerprint
13693
+ })),
13694
+ order_preservation: meta.preservesOrder,
13695
+ max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
13696
+ supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
13697
+ supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
13698
+ filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
13699
+ supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
13700
+ split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
13701
+ partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
13702
+ order_dependent: meta.orderDependent,
13703
+ distinct_dependent: meta.distinctDependent,
13704
+ supports_window: false,
13705
+ streaming_partitioned: false,
13706
+ has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
13707
+ source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
13708
+ sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
13709
+ requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
13710
+ input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
13711
+ input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
13712
+ required_settings: meta.requiredSettings,
13713
+ required_secrets: requiredSecrets.map((s) => ({
13714
+ secret_type: s.secret_type,
13715
+ scope: s.scope,
13716
+ secret_name: s.secret_name
13717
+ })),
13718
+ visibility
13719
+ };
13720
+ }
13667
13721
  function writeFunctionOf(table, operation) {
13668
13722
  return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
13669
13723
  }
@@ -13673,7 +13727,59 @@ function validateTableScanPlanning(table) {
13673
13727
  throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
13674
13728
  }
13675
13729
  }
13730
+ function buildFunctionListings(descriptor) {
13731
+ const listings = new Map;
13732
+ const listedIn = new Map;
13733
+ const writeFunctions = new Set;
13734
+ for (const sch of descriptor.schemas ?? []) {
13735
+ for (const tbl of sch.tables ?? []) {
13736
+ for (const op of WRITE_OPERATIONS) {
13737
+ const fn = writeFunctionOf(tbl, op);
13738
+ if (fn)
13739
+ writeFunctions.add(fn);
13740
+ }
13741
+ }
13742
+ }
13743
+ const listingOf = (sch) => {
13744
+ let listing = listings.get(sch);
13745
+ if (!listing)
13746
+ listings.set(sch, listing = new Map);
13747
+ return listing;
13748
+ };
13749
+ for (const sch of descriptor.schemas ?? []) {
13750
+ const listing = listingOf(sch);
13751
+ for (const fn of sch.functions ?? []) {
13752
+ if (!listedIn.has(fn))
13753
+ listedIn.set(fn, sch);
13754
+ listing.set(fn, writeFunctions.has(fn) ? FUNCTION_VISIBILITY_TABLE_ONLY : FUNCTION_VISIBILITY_PUBLIC);
13755
+ }
13756
+ }
13757
+ const declared = new Set(listedIn.keys());
13758
+ for (const sch of descriptor.schemas ?? []) {
13759
+ for (const tbl of sch.tables ?? []) {
13760
+ const named = [
13761
+ [tbl.function, false],
13762
+ ...WRITE_OPERATIONS.map((op) => [writeFunctionOf(tbl, op), true])
13763
+ ];
13764
+ for (const [fn, isWrite] of named) {
13765
+ if (!fn || declared.has(fn))
13766
+ continue;
13767
+ const owner = listedIn.get(fn) ?? sch;
13768
+ if (!listedIn.has(fn))
13769
+ listedIn.set(fn, owner);
13770
+ const listing = listingOf(owner);
13771
+ const visibility = !isWrite && !writeFunctions.has(fn) && tbl.exposeScan === true ? FUNCTION_VISIBILITY_PUBLIC : FUNCTION_VISIBILITY_TABLE_ONLY;
13772
+ if (listing.get(fn) !== FUNCTION_VISIBILITY_PUBLIC)
13773
+ listing.set(fn, visibility);
13774
+ }
13775
+ }
13776
+ }
13777
+ return { listings, listedIn };
13778
+ }
13676
13779
  function validateWritableTable(table) {
13780
+ if (table.exposeScan && !table.function) {
13781
+ throw new Error(`Table '${table.name}': exposeScan requires a scan function (set 'function')`);
13782
+ }
13677
13783
  const modes = validateWriteResultModes(table.writeResultModes ?? {});
13678
13784
  for (const operation of Object.keys(modes)) {
13679
13785
  if (!writeFunctionOf(table, operation)) {
@@ -13832,7 +13938,7 @@ class CompositeCatalogInterface extends CatalogInterface {
13832
13938
  await this._route(args[0]).schemaDrop(...args);
13833
13939
  }
13834
13940
  async tableCreate(...args) {
13835
- await this._route(args[0]).tableCreate(...args);
13941
+ return await this._route(args[0]).tableCreate(...args);
13836
13942
  }
13837
13943
  async tableDrop(...args) {
13838
13944
  await this._route(args[0]).tableDrop(...args);
@@ -14433,7 +14539,7 @@ import {
14433
14539
  Protocol
14434
14540
  } from "@query-farm/vgi-rpc";
14435
14541
  var VGI_PROTOCOL_NAME = "vgi.v3";
14436
- var VGI_PROTOCOL_VERSION = "3.2.0";
14542
+ var VGI_PROTOCOL_VERSION = "3.3.0";
14437
14543
  function exchangeStream(callbacks) {
14438
14544
  return { kind: "exchange", ...callbacks };
14439
14545
  }
@@ -15167,7 +15273,9 @@ var VGI_V3_METHODS = [
15167
15273
  params: schema2([
15168
15274
  field2("request", binary2(), false)
15169
15275
  ]),
15170
- result: schema2([]),
15276
+ result: schema2([
15277
+ field2("result", binary2(), false)
15278
+ ]),
15171
15279
  doc: "Create a new table."
15172
15280
  },
15173
15281
  {
@@ -15311,23 +15419,6 @@ var VGI_V3_METHODS = [
15311
15419
  ]),
15312
15420
  doc: "Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes."
15313
15421
  },
15314
- {
15315
- name: "catalog_table_scan_function_get",
15316
- key: "catalogTableScanFunctionGet",
15317
- type: "unary",
15318
- params: schema2([
15319
- field2("attach_opaque_data", binary2(), false),
15320
- field2("schema_path", list2(field2("item", utf82(), true)), false),
15321
- field2("name", utf82(), false),
15322
- field2("at_unit", utf82(), true),
15323
- field2("at_value", utf82(), true),
15324
- field2("transaction_opaque_data", binary2(), true)
15325
- ]),
15326
- result: schema2([
15327
- field2("result", binary2(), false)
15328
- ]),
15329
- doc: "Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes."
15330
- },
15331
15422
  {
15332
15423
  name: "catalog_table_update_function_get",
15333
15424
  key: "catalogTableUpdateFunctionGet",
@@ -15790,9 +15881,6 @@ var UNIMPLEMENTED_VGI_SERVICE = Object.freeze({
15790
15881
  catalogTableScanBranchesGet: async () => {
15791
15882
  throw notImplemented("catalog_table_scan_branches_get");
15792
15883
  },
15793
- catalogTableScanFunctionGet: async () => {
15794
- throw notImplemented("catalog_table_scan_function_get");
15795
- },
15796
15884
  catalogTableUpdateFunctionGet: async () => {
15797
15885
  throw notImplemented("catalog_table_update_function_get");
15798
15886
  },
@@ -18335,8 +18423,11 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18335
18423
  validateColumnMetadataIpc(toUint8Array(params.columns));
18336
18424
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
18337
18425
  requireCreateColumns(toUint8Array(params.columns), definitions);
18338
- await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18339
- return {};
18426
+ const created = await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18427
+ if (created != null && typeof created !== "boolean") {
18428
+ throw new TypeError(`tableCreate must return a boolean or nothing, got ${typeof created}`);
18429
+ }
18430
+ return wrapResult({ created: created !== false }, CatalogTableCreateResultSchema);
18340
18431
  });
18341
18432
  const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
18342
18433
  const attach = toUint8Array(params.attach_opaque_data);
@@ -18381,11 +18472,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18381
18472
  const stats = await cat.tableColumnStatisticsGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18382
18473
  return { result: stats?.bytes ?? null };
18383
18474
  });
18384
- const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
18385
- const cat = getCatalog();
18386
- const scanResult = await cat.tableScanFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18387
- return wrapResult(scanResult, ScanFunctionResultSchema);
18388
- });
18389
18475
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
18390
18476
  const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
18391
18477
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
@@ -18486,7 +18572,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18486
18572
  catalogTableCreate,
18487
18573
  catalogTableDrop,
18488
18574
  catalogTableColumnStatisticsGet,
18489
- catalogTableScanFunctionGet,
18490
18575
  catalogTableInsertFunctionGet,
18491
18576
  catalogTableUpdateFunctionGet,
18492
18577
  catalogTableDeleteFunctionGet,
@@ -19616,7 +19701,7 @@ class VgiClient {
19616
19701
  return items[0] ?? null;
19617
19702
  }
19618
19703
  async tableCreate(attachOpaqueData, schemaPath, name, columns, onConflict, constraintDefinitions = [], transactionOpaqueData) {
19619
- await this.rpc.call("catalog_table_create", {
19704
+ const result = await this.rpc.call("catalog_table_create", {
19620
19705
  request: encodeASD(TableCreateRequestSchema, {
19621
19706
  attach_opaque_data: attachOpaqueData,
19622
19707
  schema_path: normalizeSchemaPath(schemaPath),
@@ -19627,6 +19712,9 @@ class VgiClient {
19627
19712
  transaction_opaque_data: transactionOpaqueData ?? null
19628
19713
  })
19629
19714
  });
19715
+ if (!result)
19716
+ throw new VgiClientError("table_create returned null");
19717
+ return unwrapResult(result).created === true;
19630
19718
  }
19631
19719
  async tableDrop(attachOpaqueData, schemaPath, name, ignoreNotFound, cascade, transactionOpaqueData) {
19632
19720
  await this.rpc.call("catalog_table_drop", {
@@ -19638,18 +19726,19 @@ class VgiClient {
19638
19726
  transaction_opaque_data: transactionOpaqueData ?? null
19639
19727
  });
19640
19728
  }
19641
- async tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
19642
- const result = await this.rpc.call("catalog_table_scan_function_get", {
19729
+ async tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
19730
+ const result = await this.rpc.call("catalog_table_scan_branches_get", {
19643
19731
  attach_opaque_data: attachOpaqueData,
19644
19732
  schema_path: normalizeSchemaPath(schemaPath),
19645
19733
  name,
19646
19734
  at_unit: atUnit ?? null,
19647
19735
  at_value: atValue ?? null,
19648
- transaction_opaque_data: transactionOpaqueData ?? null
19736
+ transaction_opaque_data: transactionOpaqueData ?? null,
19737
+ pushdown_filters: null
19649
19738
  });
19650
19739
  if (!result)
19651
- throw new VgiClientError("table_scan_function_get returned null");
19652
- return decodeScanFunctionResult(unwrapResult(result));
19740
+ throw new VgiClientError("table_scan_branches_get returned null");
19741
+ return decodeScanBranchesResult(unwrapResult(result));
19653
19742
  }
19654
19743
  async tableCommentSet(attachOpaqueData, schemaPath, name, comment, ignoreNotFound, transactionOpaqueData) {
19655
19744
  await this.rpc.call("catalog_table_comment_set", {
@@ -20397,6 +20486,8 @@ export {
20397
20486
  DateUnit3 as DateUnit,
20398
20487
  DistinctDependence,
20399
20488
  EXCHANGE_STATE_SCHEMA,
20489
+ FUNCTION_VISIBILITY_PUBLIC,
20490
+ FUNCTION_VISIBILITY_TABLE_ONLY,
20400
20491
  FilteringOutputCollector,
20401
20492
  FunctionNotFoundError,
20402
20493
  FunctionRegistry,
@@ -20532,6 +20623,8 @@ export {
20532
20623
  decodeMacroOverload,
20533
20624
  decodeRangeKey,
20534
20625
  decodeRangePartitioning,
20626
+ decodeScanBranchesResult,
20627
+ decodeScanFunctionResult,
20535
20628
  decodeSchemaInfo,
20536
20629
  decodeSqlExpression,
20537
20630
  decodeTableInfo,
@@ -20582,6 +20675,7 @@ export {
20582
20675
  encodeMacroOverload,
20583
20676
  encodeRangeKey,
20584
20677
  encodeRangePartitioning,
20678
+ encodeScanFunctionResult,
20585
20679
  encodeSchemaInfo,
20586
20680
  encodeSqlExpression,
20587
20681
  encodeTableInfo,
@@ -20601,6 +20695,7 @@ export {
20601
20695
  fromBranded,
20602
20696
  fromBrandedBigInt,
20603
20697
  fromBrandedNumber,
20698
+ functionInfoFor,
20604
20699
  storage as functionStorage,
20605
20700
  generatedExpressionMetadata,
20606
20701
  grantKeysFromArgv,
@@ -20723,4 +20818,4 @@ export {
20723
20818
  writeRowsBatch
20724
20819
  };
20725
20820
 
20726
- //# debugId=D575CDBB8B409C9B64756E2164756E21
20821
+ //# debugId=AC96D7597A143B4C64756E2164756E21