@query-farm/vgi 0.28.0 → 0.29.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 (83) hide show
  1. package/README.md +26 -7
  2. package/dist/arguments/argument-spec.d.ts +53 -0
  3. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  4. package/dist/arrow/impl-arrowjs/iterate.d.ts +10 -1
  5. package/dist/arrow/impl-arrowjs/schema.d.ts +2 -0
  6. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  7. package/dist/arrow/impl-flechette/iterate.d.ts +10 -1
  8. package/dist/arrow/impl-flechette/schema.d.ts +2 -0
  9. package/dist/arrow/index.d.ts +1 -1
  10. package/dist/arrow/schema-types.d.ts +3 -1
  11. package/dist/arrow/types.d.ts +39 -3
  12. package/dist/catalog/interface.d.ts +43 -0
  13. package/dist/client/client.d.ts +1 -1
  14. package/dist/client-entry.js +360 -178
  15. package/dist/client-entry.js.map +14 -14
  16. package/dist/functions/table.d.ts +63 -0
  17. package/dist/functions/types.d.ts +38 -0
  18. package/dist/generated/vgi-client.d.ts +59 -0
  19. package/dist/generated/vgi-protocol-schemas.d.ts +19 -0
  20. package/dist/http/fetch.d.ts +10 -0
  21. package/dist/index.core.d.ts +2 -2
  22. package/dist/index.js +1203 -834
  23. package/dist/index.js.map +40 -37
  24. package/dist/protocol/handlers/catalog/shared.d.ts +0 -8
  25. package/dist/protocol/handlers/function.d.ts +11 -0
  26. package/dist/protocol/serializers/bind.d.ts +1 -2
  27. package/dist/protocol/serializers/cardinality.d.ts +1 -2
  28. package/dist/protocol/serializers/splits.d.ts +126 -0
  29. package/dist/protocol/types.d.ts +27 -0
  30. package/dist/request-auth.d.ts +28 -0
  31. package/dist/serve-entry.d.ts +4 -0
  32. package/dist/serve-entry.js +745 -359
  33. package/dist/serve-entry.js.map +32 -29
  34. package/dist/split-token.d.ts +88 -0
  35. package/dist/worker-cf-entry.js +1029 -619
  36. package/dist/worker-cf-entry.js.map +37 -34
  37. package/package.json +3 -3
  38. package/src/arguments/argument-spec.ts +81 -0
  39. package/src/arguments/arguments.ts +0 -1
  40. package/src/arrow/impl-arrowjs/index.ts +1 -1
  41. package/src/arrow/impl-arrowjs/iterate.ts +21 -0
  42. package/src/arrow/impl-arrowjs/schema.ts +4 -0
  43. package/src/arrow/impl-flechette/index.ts +1 -1
  44. package/src/arrow/impl-flechette/iterate.ts +24 -1
  45. package/src/arrow/impl-flechette/schema.ts +4 -0
  46. package/src/arrow/index.ts +1 -1
  47. package/src/arrow/schema-types.ts +4 -0
  48. package/src/arrow/types.ts +39 -3
  49. package/src/catalog/interface.ts +124 -29
  50. package/src/catalog/read-only.ts +18 -18
  51. package/src/client/client.ts +6 -2
  52. package/src/functions/aggregate.ts +3 -0
  53. package/src/functions/copy-from.ts +2 -1
  54. package/src/functions/copy-to.ts +2 -1
  55. package/src/functions/scalar.ts +11 -0
  56. package/src/functions/table-buffering.ts +3 -0
  57. package/src/functions/table-in-out.ts +8 -4
  58. package/src/functions/table.ts +129 -2
  59. package/src/functions/types.ts +40 -0
  60. package/src/generated/vgi-client.ts +63 -1
  61. package/src/generated/vgi-protocol-schemas.ts +240 -14
  62. package/src/http/fetch.ts +117 -2
  63. package/src/index.core.ts +2 -2
  64. package/src/protocol/handlers/aggregate.ts +10 -5
  65. package/src/protocol/handlers/catalog/admin.ts +41 -48
  66. package/src/protocol/handlers/catalog/index_methods.ts +4 -11
  67. package/src/protocol/handlers/catalog/macro.ts +8 -16
  68. package/src/protocol/handlers/catalog/shared.ts +10 -57
  69. package/src/protocol/handlers/catalog/table.ts +33 -96
  70. package/src/protocol/handlers/catalog/view.ts +13 -17
  71. package/src/protocol/handlers/function.ts +311 -18
  72. package/src/protocol/handlers/table-buffering.ts +7 -4
  73. package/src/protocol/serializers/bind.ts +56 -63
  74. package/src/protocol/serializers/cardinality.ts +7 -7
  75. package/src/protocol/serializers/init.ts +52 -10
  76. package/src/protocol/serializers/splits.ts +219 -0
  77. package/src/protocol/state-serializer.ts +55 -1
  78. package/src/protocol/types.ts +27 -0
  79. package/src/request-auth.ts +73 -0
  80. package/src/serve-entry.ts +5 -0
  81. package/src/split-token.ts +297 -0
  82. package/src/worker-cf-entry.ts +2 -1
  83. package/src/worker.ts +30 -10
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -36,6 +37,7 @@ var __export = (target, all) => {
36
37
  });
37
38
  };
38
39
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
40
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
39
41
 
40
42
  // src/arrow/predicates.ts
41
43
  function isNull(t) {
@@ -179,7 +181,9 @@ import {
179
181
  Float32 as A_Float32,
180
182
  Float64 as A_Float64,
181
183
  Utf8 as A_Utf8,
184
+ LargeUtf8 as A_LargeUtf8,
182
185
  Binary as A_Binary,
186
+ LargeBinary as A_LargeBinary,
183
187
  Decimal as A_Decimal,
184
188
  Date_ as A_Date,
185
189
  Time as A_Time,
@@ -267,7 +271,7 @@ function union(mode, children, typeIds) {
267
271
  function isField(x) {
268
272
  return typeof x.name === "string" && x.type != null;
269
273
  }
270
- var TimeUnit, DateUnit, IntervalUnit, UnionMode, nullType = () => new A_Null, bool = () => new A_Bool, int8 = () => new A_Int8, int16 = () => new A_Int16, int32 = () => new A_Int32, int64 = () => new A_Int64, uint8 = () => new A_Uint8, uint16 = () => new A_Uint16, uint32 = () => new A_Uint32, uint64 = () => new A_Uint64, float16 = () => new A_Float16, float32 = () => new A_Float32, float64 = () => new A_Float64, utf8 = () => new A_Utf8, binary = () => new A_Binary, fixedSizeBinary = (byteWidth) => new A_FixedSizeBinary(byteWidth), decimal128 = (precision, scale) => decimal(precision, scale, 128), decimal256 = (precision, scale) => decimal(precision, scale, 256), date = (unit = A_DateUnit.MILLISECOND) => new A_Date(unit), dateDay = () => date(A_DateUnit.DAY), dateMillisecond = () => date(A_DateUnit.MILLISECOND), timeSecond = () => time(A_TimeUnit.SECOND, 32), timeMillisecond = () => time(A_TimeUnit.MILLISECOND, 32), timeMicrosecond = () => time(A_TimeUnit.MICROSECOND, 64), timeNanosecond = () => time(A_TimeUnit.NANOSECOND, 64), timestamp = (unit = A_TimeUnit.MILLISECOND, timezone = null) => new A_Timestamp(unit, timezone), duration = (unit = A_TimeUnit.MILLISECOND) => new A_Duration(unit), interval = (unit = A_IntervalUnit.MONTH_DAY_NANO) => new A_Interval(unit), sparseUnion = (children, typeIds) => union(A_UnionMode.Sparse, children, typeIds), denseUnion = (children, typeIds) => union(A_UnionMode.Dense, children, typeIds);
274
+ var TimeUnit, DateUnit, IntervalUnit, UnionMode, nullType = () => new A_Null, bool = () => new A_Bool, int8 = () => new A_Int8, int16 = () => new A_Int16, int32 = () => new A_Int32, int64 = () => new A_Int64, uint8 = () => new A_Uint8, uint16 = () => new A_Uint16, uint32 = () => new A_Uint32, uint64 = () => new A_Uint64, float16 = () => new A_Float16, float32 = () => new A_Float32, float64 = () => new A_Float64, utf8 = () => new A_Utf8, largeUtf8 = () => new A_LargeUtf8, binary = () => new A_Binary, largeBinary = () => new A_LargeBinary, fixedSizeBinary = (byteWidth) => new A_FixedSizeBinary(byteWidth), decimal128 = (precision, scale) => decimal(precision, scale, 128), decimal256 = (precision, scale) => decimal(precision, scale, 256), date = (unit = A_DateUnit.MILLISECOND) => new A_Date(unit), dateDay = () => date(A_DateUnit.DAY), dateMillisecond = () => date(A_DateUnit.MILLISECOND), timeSecond = () => time(A_TimeUnit.SECOND, 32), timeMillisecond = () => time(A_TimeUnit.MILLISECOND, 32), timeMicrosecond = () => time(A_TimeUnit.MICROSECOND, 64), timeNanosecond = () => time(A_TimeUnit.NANOSECOND, 64), timestamp = (unit = A_TimeUnit.MILLISECOND, timezone = null) => new A_Timestamp(unit, timezone), duration = (unit = A_TimeUnit.MILLISECOND) => new A_Duration(unit), interval = (unit = A_IntervalUnit.MONTH_DAY_NANO) => new A_Interval(unit), sparseUnion = (children, typeIds) => union(A_UnionMode.Sparse, children, typeIds), denseUnion = (children, typeIds) => union(A_UnionMode.Dense, children, typeIds);
271
275
  var init_schema = __esm(() => {
272
276
  TimeUnit = {
273
277
  SECOND: A_TimeUnit.SECOND,
@@ -1529,13 +1533,19 @@ function batchToSecretDict(batch) {
1529
1533
  }
1530
1534
  function safeNumber(value) {
1531
1535
  if (typeof value === "bigint") {
1536
+ if (value > MAX_SAFE || value < MIN_SAFE) {
1537
+ throw new RangeError(`${value} cannot be represented exactly as a JS number ` + `(|value| > Number.MAX_SAFE_INTEGER). Keep it as a bigint.`);
1538
+ }
1532
1539
  return Number(value);
1533
1540
  }
1534
1541
  return value;
1535
1542
  }
1543
+ var MAX_SAFE, MIN_SAFE;
1536
1544
  var init_iterate = __esm(() => {
1537
1545
  init_registry();
1538
1546
  init_canonical();
1547
+ MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
1548
+ MIN_SAFE = -MAX_SAFE;
1539
1549
  });
1540
1550
 
1541
1551
  // src/arrow/impl-arrowjs/filter.ts
@@ -1800,72 +1810,74 @@ var init_statistics = __esm(() => {
1800
1810
  // src/arrow/impl-arrowjs/index.ts
1801
1811
  var exports_impl_arrowjs = {};
1802
1812
  __export(exports_impl_arrowjs, {
1803
- withBatchMetadata: () => withBatchMetadata,
1804
- utf8: () => utf8,
1805
- union: () => union,
1806
- uint8: () => uint8,
1807
- uint64: () => uint64,
1808
- uint32: () => uint32,
1809
- uint16: () => uint16,
1810
- timestamp: () => timestamp,
1811
- timeSecond: () => timeSecond,
1812
- timeNanosecond: () => timeNanosecond,
1813
- timeMillisecond: () => timeMillisecond,
1814
- timeMicrosecond: () => timeMicrosecond,
1815
- time: () => time,
1816
- struct: () => struct,
1817
- sparseUnion: () => sparseUnion,
1818
- serializeSchema: () => serializeSchema,
1819
- serializeBatch: () => serializeBatch,
1820
- schema: () => schema,
1821
- safeNumber: () => safeNumber,
1822
- readCanonicalValue: () => readCanonicalValue,
1823
- projectSchema: () => projectSchema,
1824
- projectBatch: () => projectBatch,
1825
- nullType: () => nullType,
1826
- map: () => map,
1827
- list: () => list,
1828
- iterRows: () => iterRows,
1829
- interval: () => interval,
1830
- int8: () => int8,
1831
- int64: () => int64,
1832
- int32: () => int32,
1833
- int16: () => int16,
1834
- int: () => int,
1835
- float64: () => float64,
1836
- float32: () => float32,
1837
- float16: () => float16,
1838
- fixedSizeList: () => fixedSizeList,
1839
- fixedSizeBinary: () => fixedSizeBinary,
1840
- filterBatch: () => filterBatch,
1841
- field: () => field,
1842
- emptyBatch: () => emptyBatch,
1843
- duration: () => duration,
1844
- dictionary: () => dictionary,
1845
- deserializeSchema: () => deserializeSchema,
1846
- deserializeBatch: () => deserializeBatch,
1847
- denseUnion: () => denseUnion,
1848
- decodeDictValue: () => decodeDictValue,
1849
- decimal256: () => decimal256,
1850
- decimal128: () => decimal128,
1851
- decimal: () => decimal,
1852
- dateMillisecond: () => dateMillisecond,
1853
- dateDay: () => dateDay,
1854
- date: () => date,
1855
- columnFromArray: () => columnFromArray,
1856
- buildStatisticsBatch: () => buildStatisticsBatch,
1857
- bool: () => bool,
1858
- binary: () => binary,
1859
- batchToSecretDict: () => batchToSecretDict,
1860
- batchToScalarDict: () => batchToScalarDict,
1861
- batchFromRows: () => batchFromRows,
1862
- batchFromColumns: () => batchFromColumns,
1863
- backend: () => backend,
1864
- adoptArrowJsShape: () => adoptArrowJsShape,
1865
- UnionMode: () => UnionMode,
1866
- TimeUnit: () => TimeUnit,
1813
+ DateUnit: () => DateUnit,
1867
1814
  IntervalUnit: () => IntervalUnit,
1868
- DateUnit: () => DateUnit
1815
+ TimeUnit: () => TimeUnit,
1816
+ UnionMode: () => UnionMode,
1817
+ adoptArrowJsShape: () => adoptArrowJsShape,
1818
+ backend: () => backend,
1819
+ batchFromColumns: () => batchFromColumns,
1820
+ batchFromRows: () => batchFromRows,
1821
+ batchToScalarDict: () => batchToScalarDict,
1822
+ batchToSecretDict: () => batchToSecretDict,
1823
+ binary: () => binary,
1824
+ bool: () => bool,
1825
+ buildStatisticsBatch: () => buildStatisticsBatch,
1826
+ columnFromArray: () => columnFromArray,
1827
+ date: () => date,
1828
+ dateDay: () => dateDay,
1829
+ dateMillisecond: () => dateMillisecond,
1830
+ decimal: () => decimal,
1831
+ decimal128: () => decimal128,
1832
+ decimal256: () => decimal256,
1833
+ decodeDictValue: () => decodeDictValue,
1834
+ denseUnion: () => denseUnion,
1835
+ deserializeBatch: () => deserializeBatch,
1836
+ deserializeSchema: () => deserializeSchema,
1837
+ dictionary: () => dictionary,
1838
+ duration: () => duration,
1839
+ emptyBatch: () => emptyBatch,
1840
+ field: () => field,
1841
+ filterBatch: () => filterBatch,
1842
+ fixedSizeBinary: () => fixedSizeBinary,
1843
+ fixedSizeList: () => fixedSizeList,
1844
+ float16: () => float16,
1845
+ float32: () => float32,
1846
+ float64: () => float64,
1847
+ int: () => int,
1848
+ int16: () => int16,
1849
+ int32: () => int32,
1850
+ int64: () => int64,
1851
+ int8: () => int8,
1852
+ interval: () => interval,
1853
+ iterRows: () => iterRows,
1854
+ largeBinary: () => largeBinary,
1855
+ largeUtf8: () => largeUtf8,
1856
+ list: () => list,
1857
+ map: () => map,
1858
+ nullType: () => nullType,
1859
+ projectBatch: () => projectBatch,
1860
+ projectSchema: () => projectSchema,
1861
+ readCanonicalValue: () => readCanonicalValue,
1862
+ safeNumber: () => safeNumber,
1863
+ schema: () => schema,
1864
+ serializeBatch: () => serializeBatch,
1865
+ serializeSchema: () => serializeSchema,
1866
+ sparseUnion: () => sparseUnion,
1867
+ struct: () => struct,
1868
+ time: () => time,
1869
+ timeMicrosecond: () => timeMicrosecond,
1870
+ timeMillisecond: () => timeMillisecond,
1871
+ timeNanosecond: () => timeNanosecond,
1872
+ timeSecond: () => timeSecond,
1873
+ timestamp: () => timestamp,
1874
+ uint16: () => uint16,
1875
+ uint32: () => uint32,
1876
+ uint64: () => uint64,
1877
+ uint8: () => uint8,
1878
+ union: () => union,
1879
+ utf8: () => utf8,
1880
+ withBatchMetadata: () => withBatchMetadata
1869
1881
  });
1870
1882
  function adoptArrowJsShape(batch) {
1871
1883
  return batch;
@@ -1919,7 +1931,7 @@ function dictionary2(valueType, indexType, ordered, id) {
1919
1931
  function union2(mode, children, typeIds) {
1920
1932
  return union(mode, children, typeIds);
1921
1933
  }
1922
- var TimeUnit2, DateUnit3, IntervalUnit2, UnionMode2, schema2, nullType2 = () => nullType(), bool2 = () => bool(), int82 = () => int8(), int162 = () => int16(), int322 = () => int32(), int642 = () => int64(), uint82 = () => uint8(), uint162 = () => uint16(), uint322 = () => uint32(), uint642 = () => uint64(), float162 = () => float16(), float322 = () => float32(), float642 = () => float64(), utf82 = () => utf8(), binary2 = () => binary(), fixedSizeBinary2 = (byteWidth) => fixedSizeBinary(byteWidth), decimal2 = (precision, scale, bitWidth) => decimal(precision, scale, bitWidth), decimal1282 = (precision, scale) => decimal128(precision, scale), decimal2562 = (precision, scale) => decimal256(precision, scale), date2 = (unit) => date(unit), dateDay2 = () => dateDay(), dateMillisecond2 = () => dateMillisecond(), timeSecond2 = () => timeSecond(), timeMillisecond2 = () => timeMillisecond(), timeMicrosecond2 = () => timeMicrosecond(), timeNanosecond2 = () => timeNanosecond(), UNIT_TO_TAG, timestampSeconds = (timezone) => timestamp(TimeUnit.SECOND, timezone ?? null), timestampMillis = (timezone) => timestamp(TimeUnit.MILLISECOND, timezone ?? null), timestampMicros = (timezone) => timestamp(TimeUnit.MICROSECOND, timezone ?? null), timestampNanos = (timezone) => timestamp(TimeUnit.NANOSECOND, timezone ?? null), durationSeconds = () => duration(TimeUnit.SECOND), durationMillis = () => duration(TimeUnit.MILLISECOND), durationMicros = () => duration(TimeUnit.MICROSECOND), durationNanos = () => duration(TimeUnit.NANOSECOND), interval2 = (unit) => interval(unit), sparseUnion2 = (children, typeIds) => sparseUnion(children, typeIds), denseUnion2 = (children, typeIds) => denseUnion(children, typeIds);
1934
+ var TimeUnit2, DateUnit3, IntervalUnit2, UnionMode2, schema2, nullType2 = () => nullType(), bool2 = () => bool(), int82 = () => int8(), int162 = () => int16(), int322 = () => int32(), int642 = () => int64(), uint82 = () => uint8(), uint162 = () => uint16(), uint322 = () => uint32(), uint642 = () => uint64(), float162 = () => float16(), float322 = () => float32(), float642 = () => float64(), utf82 = () => utf8(), largeUtf82 = () => largeUtf8(), binary2 = () => binary(), largeBinary2 = () => largeBinary(), fixedSizeBinary2 = (byteWidth) => fixedSizeBinary(byteWidth), decimal2 = (precision, scale, bitWidth) => decimal(precision, scale, bitWidth), decimal1282 = (precision, scale) => decimal128(precision, scale), decimal2562 = (precision, scale) => decimal256(precision, scale), date2 = (unit) => date(unit), dateDay2 = () => dateDay(), dateMillisecond2 = () => dateMillisecond(), timeSecond2 = () => timeSecond(), timeMillisecond2 = () => timeMillisecond(), timeMicrosecond2 = () => timeMicrosecond(), timeNanosecond2 = () => timeNanosecond(), UNIT_TO_TAG, timestampSeconds = (timezone) => timestamp(TimeUnit.SECOND, timezone ?? null), timestampMillis = (timezone) => timestamp(TimeUnit.MILLISECOND, timezone ?? null), timestampMicros = (timezone) => timestamp(TimeUnit.MICROSECOND, timezone ?? null), timestampNanos = (timezone) => timestamp(TimeUnit.NANOSECOND, timezone ?? null), durationSeconds = () => duration(TimeUnit.SECOND), durationMillis = () => duration(TimeUnit.MILLISECOND), durationMicros = () => duration(TimeUnit.MICROSECOND), durationNanos = () => duration(TimeUnit.NANOSECOND), interval2 = (unit) => interval(unit), sparseUnion2 = (children, typeIds) => sparseUnion(children, typeIds), denseUnion2 = (children, typeIds) => denseUnion(children, typeIds);
1923
1935
  var init_schema_types = __esm(() => {
1924
1936
  init_impl_arrowjs();
1925
1937
  ({ TimeUnit: TimeUnit2, DateUnit: DateUnit3, IntervalUnit: IntervalUnit2, UnionMode: UnionMode2, schema: schema2 } = exports_impl_arrowjs);
@@ -1978,123 +1990,125 @@ var init_branded = __esm(() => {
1978
1990
  // src/arrow/index.ts
1979
1991
  var exports_arrow = {};
1980
1992
  __export(exports_arrow, {
1981
- withBatchMetadata: () => withBatchMetadata,
1982
- utf8: () => utf82,
1983
- union: () => union2,
1984
- uint8: () => uint82,
1985
- uint64: () => uint642,
1986
- uint32: () => uint322,
1987
- uint16: () => uint162,
1988
- typeSignature: () => typeSignature,
1989
- timestampSeconds: () => timestampSeconds,
1990
- timestampNanos: () => timestampNanos,
1991
- timestampMillis: () => timestampMillis,
1992
- timestampMicros: () => timestampMicros,
1993
- timestamp: () => timestamp2,
1994
- timeSecond: () => timeSecond2,
1995
- timeNanosecond: () => timeNanosecond2,
1996
- timeMillisecond: () => timeMillisecond2,
1997
- timeMicrosecond: () => timeMicrosecond2,
1998
- time: () => time2,
1999
- struct: () => struct2,
2000
- sparseUnion: () => sparseUnion2,
2001
- serializeSchema: () => serializeSchema,
2002
- serializeBatch: () => serializeBatch,
2003
- schema: () => schema2,
2004
- safeNumber: () => safeNumber,
2005
- readCanonicalValue: () => readCanonicalValue,
2006
- projectSchema: () => projectSchema,
2007
- projectBatch: () => projectBatch,
2008
- nullType: () => nullType2,
2009
- map: () => map2,
2010
- list: () => list2,
2011
- iterRows: () => iterRows,
2012
- isUtf8: () => isUtf8,
2013
- isUnion: () => isUnion,
2014
- isTimestamp: () => isTimestamp,
2015
- isTime: () => isTime,
2016
- isStruct: () => isStruct,
2017
- isNull: () => isNull,
2018
- isMap: () => isMap,
2019
- isList: () => isList,
2020
- isInterval: () => isInterval,
2021
- isInt: () => isInt,
2022
- isFloat: () => isFloat,
2023
- isFixedSizeList: () => isFixedSizeList,
2024
- isFixedSizeBinary: () => isFixedSizeBinary,
2025
- isDuration: () => isDuration,
2026
- isDictionary: () => isDictionary,
2027
- isDecimal: () => isDecimal,
2028
- isDate: () => isDate,
2029
- isBool: () => isBool,
2030
- isBinary: () => isBinary,
2031
- isBatch: () => isBatch,
2032
- interval: () => interval2,
2033
- int8: () => int82,
2034
- int64: () => int642,
2035
- int32: () => int322,
2036
- int16: () => int162,
2037
- int: () => int2,
2038
- fromBrandedNumber: () => fromBrandedNumber,
2039
- fromBrandedBigInt: () => fromBrandedBigInt,
2040
- fromBranded: () => fromBranded,
2041
- float64: () => float642,
2042
- float32: () => float322,
2043
- float16: () => float162,
2044
- fixedSizeList: () => fixedSizeList2,
2045
- fixedSizeBinary: () => fixedSizeBinary2,
2046
- filterBatch: () => filterBatch,
2047
- field: () => field2,
2048
- emptyBatch: () => emptyBatch,
2049
- durationSeconds: () => durationSeconds,
2050
- durationNanos: () => durationNanos,
2051
- durationMillis: () => durationMillis,
2052
- durationMicros: () => durationMicros,
2053
- duration: () => duration2,
2054
- dictionary: () => dictionary2,
2055
- deserializeSchema: () => deserializeSchema,
2056
- deserializeBatch: () => deserializeBatch,
2057
- denseUnion: () => denseUnion2,
2058
- decodeDictValue: () => decodeDictValue,
2059
- decimal256: () => decimal2562,
2060
- decimal128: () => decimal1282,
2061
- decimal: () => decimal2,
2062
- dateMillisecond: () => dateMillisecond2,
2063
- dateDay: () => dateDay2,
2064
- date: () => date2,
2065
- columnFromArray: () => columnFromArray,
2066
- codecFor: () => codecFor,
2067
- buildStatisticsBatch: () => buildStatisticsBatch,
2068
- bool: () => bool2,
2069
- binary: () => binary2,
2070
- batchToSecretDict: () => batchToSecretDict,
2071
- batchToScalarDict: () => batchToScalarDict,
2072
- batchFromRows: () => batchFromRows,
2073
- batchFromColumns: () => batchFromColumns,
2074
- backend: () => backend,
2075
- asUnscaledDecimal: () => asUnscaledDecimal,
2076
- asUint64: () => asUint64,
2077
- asTimestampSeconds: () => asTimestampSeconds,
2078
- asTimestampNanos: () => asTimestampNanos,
2079
- asTimestampMillis: () => asTimestampMillis,
2080
- asTimestampMicros: () => asTimestampMicros,
2081
- asTime64Us: () => asTime64Us,
2082
- asTime64Ns: () => asTime64Ns,
2083
- asTime32S: () => asTime32S,
2084
- asTime32Ms: () => asTime32Ms,
2085
- asInt64: () => asInt64,
2086
- asDurationSeconds: () => asDurationSeconds,
2087
- asDurationNanos: () => asDurationNanos,
2088
- asDurationMillis: () => asDurationMillis,
2089
- asDurationMicros: () => asDurationMicros,
2090
- asDate64Ms: () => asDate64Ms,
2091
- asDate32: () => asDate32,
2092
- adoptArrowJsShape: () => adoptArrowJsShape,
2093
- UnionMode: () => UnionMode2,
2094
- TypeId: () => TypeId,
2095
- TimeUnit: () => TimeUnit2,
1993
+ DateUnit: () => DateUnit3,
2096
1994
  IntervalUnit: () => IntervalUnit2,
2097
- DateUnit: () => DateUnit3
1995
+ TimeUnit: () => TimeUnit2,
1996
+ TypeId: () => TypeId,
1997
+ UnionMode: () => UnionMode2,
1998
+ adoptArrowJsShape: () => adoptArrowJsShape,
1999
+ asDate32: () => asDate32,
2000
+ asDate64Ms: () => asDate64Ms,
2001
+ asDurationMicros: () => asDurationMicros,
2002
+ asDurationMillis: () => asDurationMillis,
2003
+ asDurationNanos: () => asDurationNanos,
2004
+ asDurationSeconds: () => asDurationSeconds,
2005
+ asInt64: () => asInt64,
2006
+ asTime32Ms: () => asTime32Ms,
2007
+ asTime32S: () => asTime32S,
2008
+ asTime64Ns: () => asTime64Ns,
2009
+ asTime64Us: () => asTime64Us,
2010
+ asTimestampMicros: () => asTimestampMicros,
2011
+ asTimestampMillis: () => asTimestampMillis,
2012
+ asTimestampNanos: () => asTimestampNanos,
2013
+ asTimestampSeconds: () => asTimestampSeconds,
2014
+ asUint64: () => asUint64,
2015
+ asUnscaledDecimal: () => asUnscaledDecimal,
2016
+ backend: () => backend,
2017
+ batchFromColumns: () => batchFromColumns,
2018
+ batchFromRows: () => batchFromRows,
2019
+ batchToScalarDict: () => batchToScalarDict,
2020
+ batchToSecretDict: () => batchToSecretDict,
2021
+ binary: () => binary2,
2022
+ bool: () => bool2,
2023
+ buildStatisticsBatch: () => buildStatisticsBatch,
2024
+ codecFor: () => codecFor,
2025
+ columnFromArray: () => columnFromArray,
2026
+ date: () => date2,
2027
+ dateDay: () => dateDay2,
2028
+ dateMillisecond: () => dateMillisecond2,
2029
+ decimal: () => decimal2,
2030
+ decimal128: () => decimal1282,
2031
+ decimal256: () => decimal2562,
2032
+ decodeDictValue: () => decodeDictValue,
2033
+ denseUnion: () => denseUnion2,
2034
+ deserializeBatch: () => deserializeBatch,
2035
+ deserializeSchema: () => deserializeSchema,
2036
+ dictionary: () => dictionary2,
2037
+ duration: () => duration2,
2038
+ durationMicros: () => durationMicros,
2039
+ durationMillis: () => durationMillis,
2040
+ durationNanos: () => durationNanos,
2041
+ durationSeconds: () => durationSeconds,
2042
+ emptyBatch: () => emptyBatch,
2043
+ field: () => field2,
2044
+ filterBatch: () => filterBatch,
2045
+ fixedSizeBinary: () => fixedSizeBinary2,
2046
+ fixedSizeList: () => fixedSizeList2,
2047
+ float16: () => float162,
2048
+ float32: () => float322,
2049
+ float64: () => float642,
2050
+ fromBranded: () => fromBranded,
2051
+ fromBrandedBigInt: () => fromBrandedBigInt,
2052
+ fromBrandedNumber: () => fromBrandedNumber,
2053
+ int: () => int2,
2054
+ int16: () => int162,
2055
+ int32: () => int322,
2056
+ int64: () => int642,
2057
+ int8: () => int82,
2058
+ interval: () => interval2,
2059
+ isBatch: () => isBatch,
2060
+ isBinary: () => isBinary,
2061
+ isBool: () => isBool,
2062
+ isDate: () => isDate,
2063
+ isDecimal: () => isDecimal,
2064
+ isDictionary: () => isDictionary,
2065
+ isDuration: () => isDuration,
2066
+ isFixedSizeBinary: () => isFixedSizeBinary,
2067
+ isFixedSizeList: () => isFixedSizeList,
2068
+ isFloat: () => isFloat,
2069
+ isInt: () => isInt,
2070
+ isInterval: () => isInterval,
2071
+ isList: () => isList,
2072
+ isMap: () => isMap,
2073
+ isNull: () => isNull,
2074
+ isStruct: () => isStruct,
2075
+ isTime: () => isTime,
2076
+ isTimestamp: () => isTimestamp,
2077
+ isUnion: () => isUnion,
2078
+ isUtf8: () => isUtf8,
2079
+ iterRows: () => iterRows,
2080
+ largeBinary: () => largeBinary2,
2081
+ largeUtf8: () => largeUtf82,
2082
+ list: () => list2,
2083
+ map: () => map2,
2084
+ nullType: () => nullType2,
2085
+ projectBatch: () => projectBatch,
2086
+ projectSchema: () => projectSchema,
2087
+ readCanonicalValue: () => readCanonicalValue,
2088
+ safeNumber: () => safeNumber,
2089
+ schema: () => schema2,
2090
+ serializeBatch: () => serializeBatch,
2091
+ serializeSchema: () => serializeSchema,
2092
+ sparseUnion: () => sparseUnion2,
2093
+ struct: () => struct2,
2094
+ time: () => time2,
2095
+ timeMicrosecond: () => timeMicrosecond2,
2096
+ timeMillisecond: () => timeMillisecond2,
2097
+ timeNanosecond: () => timeNanosecond2,
2098
+ timeSecond: () => timeSecond2,
2099
+ timestamp: () => timestamp2,
2100
+ timestampMicros: () => timestampMicros,
2101
+ timestampMillis: () => timestampMillis,
2102
+ timestampNanos: () => timestampNanos,
2103
+ timestampSeconds: () => timestampSeconds,
2104
+ typeSignature: () => typeSignature,
2105
+ uint16: () => uint162,
2106
+ uint32: () => uint322,
2107
+ uint64: () => uint642,
2108
+ uint8: () => uint82,
2109
+ union: () => union2,
2110
+ utf8: () => utf82,
2111
+ withBatchMetadata: () => withBatchMetadata
2098
2112
  });
2099
2113
  var init_arrow = __esm(() => {
2100
2114
  init_predicates();
@@ -2597,7 +2611,11 @@ var init_storage = __esm(() => {
2597
2611
  });
2598
2612
 
2599
2613
  // src/http/fetch.ts
2600
- import { createHttpHandler, unpackStateToken } from "@query-farm/vgi-rpc";
2614
+ import {
2615
+ AuthContext,
2616
+ createHttpHandler,
2617
+ unpackStateToken
2618
+ } from "@query-farm/vgi-rpc";
2601
2619
 
2602
2620
  // src/protocol/state-serializer.ts
2603
2621
  init_arrow();
@@ -2629,6 +2647,27 @@ var EXCHANGE_STATE_SCHEMA = schema2([
2629
2647
  ]);
2630
2648
  var TEXT_ENCODER = new TextEncoder;
2631
2649
  var TEXT_DECODER = new TextDecoder;
2650
+ var LIST_CHILD_NAME = "item";
2651
+ var emptyListElementType = () => utf82();
2652
+ function inferElementType(values) {
2653
+ let elementType = null;
2654
+ let elementSig = "";
2655
+ for (const v of values) {
2656
+ if (v === null || v === undefined)
2657
+ continue;
2658
+ const t = inferFieldType(v);
2659
+ const sig = typeSignature(t);
2660
+ if (elementType === null) {
2661
+ elementType = t;
2662
+ elementSig = sig;
2663
+ continue;
2664
+ }
2665
+ if (sig !== elementSig) {
2666
+ throw new Error(`inferFieldType: arrays in userState must be homogeneous; ` + `found both '${elementSig}' and '${sig}' in the same array ` + `(split the values into separate fields, or normalize them to one type)`);
2667
+ }
2668
+ }
2669
+ return elementType ?? emptyListElementType();
2670
+ }
2632
2671
  function inferFieldType(value) {
2633
2672
  if (value === null || value === undefined)
2634
2673
  return nullType2();
@@ -2647,7 +2686,7 @@ function inferFieldType(value) {
2647
2686
  if (ArrayBuffer.isView(value))
2648
2687
  return binary2();
2649
2688
  if (Array.isArray(value)) {
2650
- throw new Error(`inferFieldType: arrays are not supported in userState (convert to a serializable form first)`);
2689
+ return list2(field2(LIST_CHILD_NAME, inferElementType(value), true));
2651
2690
  }
2652
2691
  if (value instanceof Map) {
2653
2692
  throw new Error(`inferFieldType: Map is not supported in userState (use a plain object instead)`);
@@ -2925,10 +2964,19 @@ function toUint8Array2(val) {
2925
2964
  }
2926
2965
 
2927
2966
  // src/protocol/serializers/bind.ts
2967
+ var COPY_FROM_STRUCT_TYPE = struct2([
2968
+ field2("format", utf82(), false),
2969
+ field2("file_path", utf82(), false),
2970
+ field2("expected_schema", binary2(), false)
2971
+ ]);
2972
+ var COPY_TO_STRUCT_TYPE = struct2([
2973
+ field2("format", utf82(), false),
2974
+ field2("file_path", utf82(), false)
2975
+ ]);
2928
2976
  var BIND_REQUEST_SCHEMA = schema2([
2929
2977
  field2("function_name", utf82(), false),
2930
2978
  field2("arguments", binary2(), false),
2931
- field2("function_type", utf82(), false),
2979
+ field2("function_type", dictionary2(utf82(), int162()), false),
2932
2980
  field2("input_schema", binary2(), true),
2933
2981
  field2("settings", binary2(), true),
2934
2982
  field2("secrets", binary2(), true),
@@ -2937,26 +2985,10 @@ var BIND_REQUEST_SCHEMA = schema2([
2937
2985
  field2("resolved_secrets_provided", bool2(), false),
2938
2986
  field2("at_unit", utf82(), true),
2939
2987
  field2("at_value", utf82(), true),
2988
+ field2("copy_from", COPY_FROM_STRUCT_TYPE, true),
2989
+ field2("copy_to", COPY_TO_STRUCT_TYPE, true),
2940
2990
  field2("schema_name", utf82(), true)
2941
2991
  ]);
2942
- var COPY_FROM_STRUCT_TYPE = struct2([
2943
- field2("format", utf82(), false),
2944
- field2("file_path", utf82(), false),
2945
- field2("expected_schema", binary2(), false)
2946
- ]);
2947
- var COPY_FROM_FIELD = field2("copy_from", COPY_FROM_STRUCT_TYPE, true);
2948
- var COPY_TO_STRUCT_TYPE = struct2([
2949
- field2("format", utf82(), false),
2950
- field2("file_path", utf82(), false)
2951
- ]);
2952
- var COPY_TO_FIELD = field2("copy_to", COPY_TO_STRUCT_TYPE, true);
2953
- var BIND_RESPONSE_SCHEMA = schema2([
2954
- field2("output_schema", binary2(), false),
2955
- field2("opaque_data", binary2(), true),
2956
- field2("lookup_secret_types", list2(field2("item", utf82(), true)), false),
2957
- field2("lookup_scopes", list2(field2("item", utf82(), true)), false),
2958
- field2("lookup_names", list2(field2("item", utf82(), true)), false)
2959
- ]);
2960
2992
  function parseCopyFromContext(raw) {
2961
2993
  if (raw == null)
2962
2994
  return null;
@@ -3027,20 +3059,22 @@ var INIT_REQUEST_SCHEMA = schema2([
3027
3059
  field2("bind_call", binary2(), false),
3028
3060
  field2("output_schema", binary2(), false),
3029
3061
  field2("bind_opaque_data", binary2(), true),
3030
- field2("projection_ids", list2(field2("item", int642(), false)), true),
3031
- field2("pushdown_filters", binary2(), true),
3032
- field2("join_keys", list2(field2("item", binary2(), true)), false),
3033
- field2("phase", utf82(), true),
3062
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
3063
+ field2("pushdown_filters", largeBinary2(), true),
3064
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3065
+ field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
3066
+ field2("row_limit", int642(), true),
3067
+ field2("phase", dictionary2(utf82(), int162()), true),
3068
+ field2("finalize_state_id", binary2(), true),
3034
3069
  field2("execution_id", binary2(), true),
3035
3070
  field2("init_opaque_data", binary2(), true),
3036
3071
  field2("substream_id", binary2(), true),
3037
3072
  field2("order_by_column_name", utf82(), true),
3038
- field2("order_by_direction", utf82(), true),
3039
- field2("order_by_null_order", utf82(), true),
3073
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
3074
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3040
3075
  field2("order_by_limit", int642(), true),
3041
3076
  field2("tablesample_percentage", float642(), true),
3042
- field2("tablesample_seed", int642(), true),
3043
- field2("finalize_state_id", binary2(), true)
3077
+ field2("tablesample_seed", int642(), true)
3044
3078
  ]);
3045
3079
  var GLOBAL_INIT_RESPONSE_SCHEMA = schema2([
3046
3080
  field2("execution_id", binary2(), false),
@@ -3092,10 +3126,19 @@ function deserializeInitRequest(params) {
3092
3126
  output_schema: deserializeSchema(toUint8Array2(params.output_schema)),
3093
3127
  bind_opaque_data: params.bind_opaque_data ? toUint8Array2(params.bind_opaque_data) : null,
3094
3128
  projection_ids: projectionIds,
3129
+ row_limit: params.row_limit == null ? null : Number(params.row_limit),
3095
3130
  pushdown_filters: params.pushdown_filters ? deserializeBatch(toUint8Array2(params.pushdown_filters)) : null,
3096
3131
  join_keys: joinKeys,
3097
3132
  phase,
3098
3133
  finalize_state_id: params.finalize_state_id ? toUint8Array2(params.finalize_state_id) : null,
3134
+ split_tokens: (() => {
3135
+ const raw = params.split_tokens;
3136
+ if (raw == null)
3137
+ return null;
3138
+ const iter = Array.isArray(raw) ? raw : typeof raw[Symbol.iterator] === "function" ? raw : [];
3139
+ const tokens = [...iter].filter((e) => e != null).map((e) => toUint8Array2(e));
3140
+ return tokens.length > 0 ? tokens : null;
3141
+ })(),
3099
3142
  execution_id: params.execution_id ? toUint8Array2(params.execution_id) : null,
3100
3143
  init_opaque_data: params.init_opaque_data ? toUint8Array2(params.init_opaque_data) : null,
3101
3144
  substream_id: params.substream_id ? toUint8Array2(params.substream_id) : null,
@@ -3164,10 +3207,6 @@ function serializeGlobalInitResponse(resp) {
3164
3207
  }
3165
3208
  // src/protocol/serializers/cardinality.ts
3166
3209
  init_arrow();
3167
- var TABLE_CARDINALITY_SCHEMA = schema2([
3168
- field2("estimate", int642(), true),
3169
- field2("max", int642(), true)
3170
- ]);
3171
3210
  var TABLE_FUNCTION_CARDINALITY_REQUEST_SCHEMA = schema2([
3172
3211
  field2("bind_call", binary2(), false),
3173
3212
  field2("bind_opaque_data", binary2(), true)
@@ -3201,7 +3240,7 @@ var CatalogInfoSchema = schema2([
3201
3240
  field2("implementation_version", utf82(), true),
3202
3241
  field2("data_version_spec", utf82(), true),
3203
3242
  field2("attach_option_specs", list2(field2("item", binary2(), true)), false),
3204
- field2("releases", list2(field2("item", struct2([field2("version", utf82(), false), field2("released_at", timestamp2(TimeUnit2.MICROSECOND, "UTC"), false), field2("summary", utf82(), false), field2("notes_url", utf82(), true)]), true)), false),
3243
+ 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),
3205
3244
  field2("source_url", utf82(), true)
3206
3245
  ]);
3207
3246
  var SchemaInfoSchema = schema2([
@@ -3227,14 +3266,14 @@ var TableInfoSchema = schema2([
3227
3266
  field2("supports_delete", bool2(), false),
3228
3267
  field2("supports_returning", bool2(), false),
3229
3268
  field2("supports_column_statistics", bool2(), false),
3230
- field2("scan_function", binary2(), false),
3231
- field2("insert_function", binary2(), false),
3232
- field2("update_function", binary2(), false),
3233
- field2("delete_function", binary2(), false),
3234
- field2("cardinality_estimate", int642(), false),
3235
- field2("cardinality_max", int642(), false),
3236
- field2("column_statistics", binary2(), false),
3237
- field2("bind_result", binary2(), false),
3269
+ field2("scan_function", binary2(), true),
3270
+ field2("insert_function", binary2(), true),
3271
+ field2("update_function", binary2(), true),
3272
+ field2("delete_function", binary2(), true),
3273
+ field2("cardinality_estimate", int642(), true),
3274
+ field2("cardinality_max", int642(), true),
3275
+ field2("column_statistics", binary2(), true),
3276
+ field2("bind_result", binary2(), true),
3238
3277
  field2("required_filters", list2(field2("item", list2(field2("item", utf82(), true)), true)), false)
3239
3278
  ]);
3240
3279
  var ViewInfoSchema = schema2([
@@ -3264,8 +3303,12 @@ var FunctionInfoSchema = schema2([
3264
3303
  field2("late_materialization", bool2(), true),
3265
3304
  field2("supported_expression_filters", list2(field2("item", utf82(), true)), false),
3266
3305
  field2("order_preservation", dictionary2(utf82(), int162()), true),
3267
- field2("max_workers", int322(), false),
3306
+ field2("max_workers", int322(), true),
3268
3307
  field2("supports_batch_index", bool2(), false),
3308
+ field2("supports_splits", bool2(), false),
3309
+ field2("filters_exactly_applied", bool2(), false),
3310
+ field2("supports_positions", bool2(), false),
3311
+ field2("split_token_ttl_seconds", int642(), true),
3269
3312
  field2("partition_kind", dictionary2(utf82(), int162()), false),
3270
3313
  field2("order_dependent", dictionary2(utf82(), int162()), false),
3271
3314
  field2("distinct_dependent", dictionary2(utf82(), int162()), false),
@@ -3286,9 +3329,9 @@ var MacroInfoSchema = schema2([
3286
3329
  field2("schema_name", utf82(), false),
3287
3330
  field2("macro_type", dictionary2(utf82(), int162()), false),
3288
3331
  field2("parameters", list2(field2("item", utf82(), true)), false),
3289
- field2("parameter_default_values", binary2(), false),
3332
+ field2("parameter_default_values", binary2(), true),
3290
3333
  field2("definition", utf82(), false),
3291
- field2("arguments_schema", binary2(), false)
3334
+ field2("arguments_schema", binary2(), true)
3292
3335
  ]);
3293
3336
  var IndexInfoSchema = schema2([
3294
3337
  field2("comment", utf82(), true),
@@ -3327,7 +3370,22 @@ var ScanBranchSchema = schema2([
3327
3370
  field2("writable", bool2(), false),
3328
3371
  field2("source_catalog", utf82(), true),
3329
3372
  field2("source_schema", utf82(), true),
3330
- field2("source_table", utf82(), true)
3373
+ field2("source_table", utf82(), true),
3374
+ field2("format_name", utf82(), true),
3375
+ field2("format_locations", list2(field2("item", utf82(), true)), true),
3376
+ field2("format_options", binary2(), true)
3377
+ ]);
3378
+ var ScanSplitSchema = schema2([
3379
+ field2("payload", binary2(), false),
3380
+ field2("token", binary2(), false),
3381
+ field2("estimated_rows", int642(), true),
3382
+ field2("rows_exact", bool2(), false),
3383
+ field2("estimated_bytes", int642(), true),
3384
+ field2("partition_bounds", binary2(), true),
3385
+ field2("column_statistics", binary2(), true),
3386
+ field2("location_ids", list2(field2("item", int642(), true)), true),
3387
+ field2("start_position", binary2(), true),
3388
+ field2("end_position", binary2(), true)
3331
3389
  ]);
3332
3390
  var AttachCatalogInfoSchema = schema2([
3333
3391
  field2("alias", utf82(), false),
@@ -3338,6 +3396,152 @@ var AttachCatalogInfoSchema = schema2([
3338
3396
  field2("required", bool2(), false),
3339
3397
  field2("secret_ref", utf82(), false)
3340
3398
  ]);
3399
+ var AggregateBindRequestSchema = schema2([
3400
+ field2("function_name", utf82(), false),
3401
+ field2("arguments", binary2(), false),
3402
+ field2("input_schema", binary2(), true),
3403
+ field2("settings", binary2(), true),
3404
+ field2("secrets", binary2(), true),
3405
+ field2("attach_opaque_data", binary2(), true),
3406
+ field2("schema_name", utf82(), true)
3407
+ ]);
3408
+ var AggregateCombineRequestSchema = schema2([
3409
+ field2("function_name", utf82(), false),
3410
+ field2("execution_id", binary2(), false),
3411
+ field2("merge_batch", binary2(), false),
3412
+ field2("attach_opaque_data", binary2(), true),
3413
+ field2("schema_name", utf82(), true)
3414
+ ]);
3415
+ var AggregateDestructorRequestSchema = schema2([
3416
+ field2("function_name", utf82(), false),
3417
+ field2("execution_id", binary2(), false),
3418
+ field2("group_ids_batch", binary2(), false),
3419
+ field2("attach_opaque_data", binary2(), true),
3420
+ field2("schema_name", utf82(), true)
3421
+ ]);
3422
+ var AggregateFinalizeRequestSchema = schema2([
3423
+ field2("function_name", utf82(), false),
3424
+ field2("execution_id", binary2(), false),
3425
+ field2("group_ids_batch", binary2(), false),
3426
+ field2("output_schema", binary2(), false),
3427
+ field2("attach_opaque_data", binary2(), true),
3428
+ field2("schema_name", utf82(), true)
3429
+ ]);
3430
+ var AggregateUpdateRequestSchema = schema2([
3431
+ field2("function_name", utf82(), false),
3432
+ field2("execution_id", binary2(), false),
3433
+ field2("input_batch", binary2(), false),
3434
+ field2("attach_opaque_data", binary2(), true),
3435
+ field2("schema_name", utf82(), true)
3436
+ ]);
3437
+ var BindRequestSchema = schema2([
3438
+ field2("function_name", utf82(), false),
3439
+ field2("arguments", binary2(), false),
3440
+ field2("function_type", dictionary2(utf82(), int162()), false),
3441
+ field2("input_schema", binary2(), true),
3442
+ field2("settings", binary2(), true),
3443
+ field2("secrets", binary2(), true),
3444
+ field2("attach_opaque_data", binary2(), true),
3445
+ field2("transaction_opaque_data", binary2(), true),
3446
+ field2("resolved_secrets_provided", bool2(), false),
3447
+ field2("at_unit", utf82(), true),
3448
+ field2("at_value", utf82(), true),
3449
+ field2("copy_from", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false), field2("expected_schema", binary2(), false)]), true),
3450
+ field2("copy_to", struct2([field2("format", utf82(), false), field2("file_path", utf82(), false)]), true),
3451
+ field2("schema_name", utf82(), true)
3452
+ ]);
3453
+ var CatalogAttachRequestSchema = schema2([
3454
+ field2("name", utf82(), false),
3455
+ field2("options", binary2(), true),
3456
+ field2("data_version_spec", utf82(), true),
3457
+ field2("implementation_version", utf82(), true),
3458
+ field2("client_capabilities", binary2(), true)
3459
+ ]);
3460
+ var CopyFromContextSchema = schema2([
3461
+ field2("format", utf82(), false),
3462
+ field2("file_path", utf82(), false),
3463
+ field2("expected_schema", binary2(), false)
3464
+ ]);
3465
+ var CopyToContextSchema = schema2([
3466
+ field2("format", utf82(), false),
3467
+ field2("file_path", utf82(), false)
3468
+ ]);
3469
+ var GlobalInitResponseSchema = schema2([
3470
+ field2("execution_id", binary2(), false),
3471
+ field2("opaque_data", binary2(), true),
3472
+ field2("max_workers", int642(), false)
3473
+ ]);
3474
+ var InitRequestSchema = schema2([
3475
+ field2("bind_call", binary2(), false),
3476
+ field2("output_schema", binary2(), false),
3477
+ field2("bind_opaque_data", binary2(), true),
3478
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
3479
+ field2("pushdown_filters", largeBinary2(), true),
3480
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3481
+ field2("split_tokens", list2(field2("item", largeBinary2(), true)), true),
3482
+ field2("row_limit", int642(), true),
3483
+ field2("phase", dictionary2(utf82(), int162()), true),
3484
+ field2("finalize_state_id", binary2(), true),
3485
+ field2("execution_id", binary2(), true),
3486
+ field2("init_opaque_data", binary2(), true),
3487
+ field2("substream_id", binary2(), true),
3488
+ field2("order_by_column_name", utf82(), true),
3489
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
3490
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3491
+ field2("order_by_limit", int642(), true),
3492
+ field2("tablesample_percentage", float642(), true),
3493
+ field2("tablesample_seed", int642(), true)
3494
+ ]);
3495
+ var TableBufferingCombineRequestSchema = schema2([
3496
+ field2("function_name", utf82(), false),
3497
+ field2("execution_id", binary2(), false),
3498
+ field2("state_ids", list2(field2("item", binary2(), true)), false),
3499
+ field2("attach_opaque_data", binary2(), true),
3500
+ field2("transaction_id", binary2(), true),
3501
+ field2("schema_name", utf82(), true)
3502
+ ]);
3503
+ var TableBufferingDestructorRequestSchema = schema2([
3504
+ field2("function_name", utf82(), false),
3505
+ field2("execution_id", binary2(), false),
3506
+ field2("attach_opaque_data", binary2(), true),
3507
+ field2("transaction_id", binary2(), true),
3508
+ field2("schema_name", utf82(), true)
3509
+ ]);
3510
+ var TableBufferingProcessRequestSchema = schema2([
3511
+ field2("function_name", utf82(), false),
3512
+ field2("execution_id", binary2(), false),
3513
+ field2("input_batch", binary2(), false),
3514
+ field2("attach_opaque_data", binary2(), true),
3515
+ field2("transaction_id", binary2(), true),
3516
+ field2("batch_index", int642(), true),
3517
+ field2("schema_name", utf82(), true)
3518
+ ]);
3519
+ var TableFunctionCardinalityRequestSchema = schema2([
3520
+ field2("bind_call", binary2(), false),
3521
+ field2("bind_opaque_data", binary2(), true)
3522
+ ]);
3523
+ var TableFunctionPlanRequestSchema = schema2([
3524
+ field2("bind_call", binary2(), false),
3525
+ field2("bind_opaque_data", binary2(), true),
3526
+ field2("projection_ids", list2(field2("item", int642(), true)), true),
3527
+ field2("pushdown_filters", largeBinary2(), true),
3528
+ field2("join_keys", list2(field2("item", largeBinary2(), true)), true),
3529
+ field2("row_limit", int642(), true),
3530
+ field2("target_split_bytes", int642(), true),
3531
+ field2("min_splits", int642(), true),
3532
+ field2("max_splits_per_response", int642(), true),
3533
+ field2("cursor", binary2(), true),
3534
+ field2("refined_filters", largeBinary2(), true),
3535
+ field2("filters_complete", bool2(), false),
3536
+ field2("start_position", binary2(), true),
3537
+ field2("end_position", binary2(), true),
3538
+ field2("order_by_column_name", utf82(), true),
3539
+ field2("order_by_direction", dictionary2(utf82(), int162()), true),
3540
+ field2("order_by_null_order", dictionary2(utf82(), int162()), true),
3541
+ field2("order_by_limit", int642(), true),
3542
+ field2("tablesample_percentage", float642(), true),
3543
+ field2("tablesample_seed", int642(), true)
3544
+ ]);
3341
3545
  var AggregateBindResultSchema = schema2([
3342
3546
  field2("output_schema", binary2(), false),
3343
3547
  field2("execution_id", binary2(), false)
@@ -3365,7 +3569,7 @@ var AggregateWindowDestructorResultSchema = schema2([]);
3365
3569
  var AggregateWindowInitResultSchema = schema2([]);
3366
3570
  var BindResultSchema = schema2([
3367
3571
  field2("output_schema", binary2(), false),
3368
- field2("opaque_data", binary2(), false),
3572
+ field2("opaque_data", binary2(), true),
3369
3573
  field2("lookup_secret_types", list2(field2("item", utf82(), true)), false),
3370
3574
  field2("lookup_scopes", list2(field2("item", utf82(), true)), false),
3371
3575
  field2("lookup_names", list2(field2("item", utf82(), true)), false)
@@ -3449,6 +3653,24 @@ var TableFunctionDynamicToStringResultSchema = schema2([
3449
3653
  field2("keys", list2(field2("item", utf82(), true)), false),
3450
3654
  field2("values", list2(field2("item", utf82(), true)), false)
3451
3655
  ]);
3656
+ var TableFunctionPlanResultSchema = schema2([
3657
+ field2("splits", list2(field2("item", binary2(), true)), false),
3658
+ field2("next_cursors", list2(field2("item", binary2(), true)), true),
3659
+ field2("execution_id", binary2(), true),
3660
+ field2("init_opaque_data", binary2(), true),
3661
+ field2("max_workers", int642(), true),
3662
+ field2("estimated_total_splits", int642(), true),
3663
+ field2("estimated_total_rows", int642(), true),
3664
+ field2("estimated_total_bytes", int642(), true),
3665
+ field2("catalog_version", int642(), true),
3666
+ field2("scope", utf82(), false),
3667
+ field2("locations", list2(field2("item", utf82(), true)), true),
3668
+ field2("partitioning", list2(field2("item", binary2(), true)), true),
3669
+ field2("sort_order", list2(field2("item", binary2(), true)), true),
3670
+ field2("cache_max_age_seconds", int642(), true),
3671
+ field2("start_position", binary2(), true),
3672
+ field2("end_position", binary2(), true)
3673
+ ]);
3452
3674
  var AggregateBindParamsSchema = schema2([
3453
3675
  field2("request", binary2(), false)
3454
3676
  ]);
@@ -3815,6 +4037,9 @@ var TableFunctionCardinalityParamsSchema = schema2([
3815
4037
  var TableFunctionDynamicToStringParamsSchema = schema2([
3816
4038
  field2("request", binary2(), false)
3817
4039
  ]);
4040
+ var TableFunctionPlanParamsSchema = schema2([
4041
+ field2("request", binary2(), false)
4042
+ ]);
3818
4043
  var TableFunctionStatisticsParamsSchema = schema2([
3819
4044
  field2("request", binary2(), false)
3820
4045
  ]);
@@ -4770,57 +4995,235 @@ function decodeOptionsBatch(bytes) {
4770
4995
  return row ?? {};
4771
4996
  }
4772
4997
  var emptyResultSchema = schema2([]);
4773
- var attachOpaqueDataParam = schema2([
4774
- field2("attach_opaque_data", binary2(), true)
4775
- ]);
4776
- var attachOpaqueDataTxnParams = schema2([
4777
- field2("attach_opaque_data", binary2(), true),
4778
- field2("transaction_opaque_data", binary2(), true)
4779
- ]);
4780
- var attachOpaqueDataNameTxnParams = schema2([
4781
- field2("attach_opaque_data", binary2(), true),
4782
- field2("name", utf82(), false),
4783
- field2("transaction_opaque_data", binary2(), true)
4784
- ]);
4785
- var attachOpaqueDataSchemaNameTxnParams = schema2([
4786
- field2("attach_opaque_data", binary2(), true),
4787
- field2("schema_name", utf82(), false),
4788
- field2("name", utf82(), false),
4789
- field2("transaction_opaque_data", binary2(), true)
4790
- ]);
4791
- var schemaNameIgnoreNotFoundTxnParams = schema2([
4792
- field2("attach_opaque_data", binary2(), true),
4793
- field2("schema_name", utf82(), false),
4794
- field2("name", utf82(), false),
4795
- field2("ignore_not_found", bool2(), true),
4796
- field2("transaction_opaque_data", binary2(), true)
4797
- ]);
4798
- var schemaNameCommentParams = schema2([
4799
- field2("attach_opaque_data", binary2(), true),
4800
- field2("schema_name", utf82(), false),
4801
- field2("name", utf82(), false),
4802
- field2("comment", utf82(), true),
4803
- field2("ignore_not_found", bool2(), true),
4804
- field2("transaction_opaque_data", binary2(), true)
4805
- ]);
4806
- var schemaNameRenameParams = schema2([
4807
- field2("attach_opaque_data", binary2(), true),
4808
- field2("schema_name", utf82(), false),
4809
- field2("name", utf82(), false),
4810
- field2("new_name", utf82(), false),
4811
- field2("ignore_not_found", bool2(), true),
4812
- field2("transaction_opaque_data", binary2(), true)
4813
- ]);
4814
- var columnOpParams = schema2([
4815
- field2("attach_opaque_data", binary2(), true),
4816
- field2("schema_name", utf82(), false),
4817
- field2("name", utf82(), false),
4818
- field2("column_name", utf82(), false),
4819
- field2("ignore_not_found", bool2(), true),
4820
- field2("transaction_opaque_data", binary2(), true)
4821
- ]);
4998
+
4999
+ // src/request-auth.ts
5000
+ var scope;
5001
+ function setRequestAuthScope(next) {
5002
+ scope = next;
5003
+ }
5004
+ function currentRequestAuth() {
5005
+ return scope?.getStore()?.auth;
5006
+ }
5007
+
5008
+ // src/protocol/serializers/splits.ts
5009
+ var SCAN_SPLIT_SCHEMA = ScanSplitSchema;
5010
+ var PLAN_RESPONSE_SCHEMA = TableFunctionPlanResultSchema;
5011
+ function deserializePlanRequest(params) {
5012
+ const bindCallBytes = toUint8Array2(params.bind_call);
5013
+ const bindCall = deserializeBindRequest(batchToScalarDict(deserializeBatch(bindCallBytes)));
5014
+ let projectionIds = null;
5015
+ if (params.projection_ids != null) {
5016
+ const raw = params.projection_ids;
5017
+ if (Array.isArray(raw))
5018
+ projectionIds = raw.map(Number);
5019
+ else if (raw && typeof raw[Symbol.iterator] === "function")
5020
+ projectionIds = [...raw].map(Number);
5021
+ }
5022
+ const asBigInt = (v) => v == null ? null : typeof v === "bigint" ? v : BigInt(Number(v));
5023
+ return {
5024
+ bind_call: bindCall,
5025
+ bind_opaque_data: params.bind_opaque_data ? toUint8Array2(params.bind_opaque_data) : null,
5026
+ projection_ids: projectionIds,
5027
+ pushdown_filters: params.pushdown_filters ? toUint8Array2(params.pushdown_filters) : null,
5028
+ target_split_bytes: asBigInt(params.target_split_bytes),
5029
+ min_splits: asBigInt(params.min_splits),
5030
+ cursor: params.cursor ? toUint8Array2(params.cursor) : null
5031
+ };
5032
+ }
5033
+ function fingerprintInputs(bindCallBytes) {
5034
+ const dict = batchToScalarDict(deserializeBatch(bindCallBytes));
5035
+ return {
5036
+ schemaName: dict.schema_name == null ? "" : String(dict.schema_name),
5037
+ functionName: String(dict.function_name ?? ""),
5038
+ args: dict.arguments ? toUint8Array2(dict.arguments) : new Uint8Array(0),
5039
+ settings: dict.settings ? toUint8Array2(dict.settings) : new Uint8Array(0)
5040
+ };
5041
+ }
5042
+ function scanSplitRow(split, token) {
5043
+ const asBigInt = (v) => v == null ? null : typeof v === "bigint" ? v : BigInt(v);
5044
+ return {
5045
+ payload: new Uint8Array(0),
5046
+ token,
5047
+ estimated_rows: asBigInt(split.estimatedRows),
5048
+ rows_exact: split.rowsExact === true,
5049
+ estimated_bytes: asBigInt(split.estimatedBytes),
5050
+ partition_bounds: split.partitionBounds ?? null,
5051
+ column_statistics: split.columnStatistics ?? null,
5052
+ location_ids: split.locationIds ?? null,
5053
+ start_position: split.startPosition ?? null,
5054
+ end_position: split.endPosition ?? null
5055
+ };
5056
+ }
5057
+ function planResponseRow(result, splitBlobs) {
5058
+ const asBigInt = (v) => v == null ? null : typeof v === "bigint" ? v : BigInt(v);
5059
+ return {
5060
+ splits: splitBlobs,
5061
+ next_cursors: result.nextCursors ?? [],
5062
+ execution_id: null,
5063
+ init_opaque_data: new Uint8Array(0),
5064
+ max_workers: asBigInt(result.maxWorkers),
5065
+ estimated_total_splits: asBigInt(result.estimatedTotalSplits),
5066
+ estimated_total_rows: asBigInt(result.estimatedTotalRows),
5067
+ estimated_total_bytes: asBigInt(result.estimatedTotalBytes),
5068
+ catalog_version: asBigInt(result.catalogVersion),
5069
+ scope: result.scope ?? "catalog",
5070
+ locations: null,
5071
+ partitioning: [],
5072
+ sort_order: [],
5073
+ cache_max_age_seconds: asBigInt(result.cacheMaxAgeSeconds),
5074
+ start_position: new Uint8Array(0),
5075
+ end_position: new Uint8Array(0)
5076
+ };
5077
+ }
5078
+
5079
+ // src/split-token.ts
5080
+ var SPLIT_TOKEN_FORMAT_VERSION = 1;
5081
+ var FLAG_PAYLOAD_SEALED = 1;
5082
+ var RESERVED_FLAGS_MASK = 254;
5083
+ var FINGERPRINT_LEN = 16;
5084
+ var HEADER_LEN = 4 + FINGERPRINT_LEN;
5085
+ var SEAL_VERSION = 1;
5086
+ var AAD_PREFIX = new TextEncoder().encode("vgi.split_token.v1\x00");
5087
+ var SPLIT_TOKEN_INVALID = "SPLIT_TOKEN_INVALID";
5088
+ var SPLIT_SNAPSHOT_EXPIRED = "SPLIT_SNAPSHOT_EXPIRED";
5089
+ class SplitTokenError extends Error {
5090
+ kind;
5091
+ constructor(kind, message) {
5092
+ super(`[${kind}] ${message}`);
5093
+ this.name = "SplitTokenError";
5094
+ this.kind = kind;
5095
+ }
5096
+ }
5097
+ function concat2(...parts) {
5098
+ const total = parts.reduce((n, p) => n + p.length, 0);
5099
+ const out = new Uint8Array(total);
5100
+ let at = 0;
5101
+ for (const p of parts) {
5102
+ out.set(p, at);
5103
+ at += p.length;
5104
+ }
5105
+ return out;
5106
+ }
5107
+ function equalBytes2(a, b) {
5108
+ if (a.length !== b.length)
5109
+ return false;
5110
+ let diff = 0;
5111
+ for (let i = 0;i < a.length; i++)
5112
+ diff |= a[i] ^ b[i];
5113
+ return diff === 0;
5114
+ }
5115
+ async function bindFingerprint(schemaName, functionName, args, settings, projection) {
5116
+ const enc = new TextEncoder;
5117
+ const zero = Uint8Array.of(0);
5118
+ const field3 = (label, value) => concat2(enc.encode(label), zero, value, zero);
5119
+ const message = concat2(AAD_PREFIX, field3("schema_name", enc.encode(schemaName)), field3("function_name", enc.encode(functionName)), field3("arguments", args), field3("settings", settings), field3("projection_ids", projection));
5120
+ const digest = await crypto.subtle.digest("SHA-256", message);
5121
+ return new Uint8Array(digest).slice(0, FINGERPRINT_LEN);
5122
+ }
5123
+ function splitTokenAad(header, auth) {
5124
+ return concat2(header, identityTail(auth));
5125
+ }
5126
+ function splitAnchor(catalogVersion) {
5127
+ const out = new Uint8Array(8);
5128
+ new DataView(out.buffer).setBigInt64(0, BigInt(catalogVersion), true);
5129
+ return out;
5130
+ }
5131
+ async function buildSplitToken(opts) {
5132
+ const { payload, fingerprint, anchor, signingKey, auth } = opts;
5133
+ if (fingerprint.length !== FINGERPRINT_LEN) {
5134
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `bind_fingerprint must be ${FINGERPRINT_LEN} bytes, got ${fingerprint.length}`);
5135
+ }
5136
+ if (anchor.length > 65535) {
5137
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `consistency_anchor too long: ${anchor.length} bytes exceeds u16`);
5138
+ }
5139
+ const head = new Uint8Array(4);
5140
+ head[0] = SPLIT_TOKEN_FORMAT_VERSION;
5141
+ head[1] = signingKey ? FLAG_PAYLOAD_SEALED : 0;
5142
+ new DataView(head.buffer).setUint16(2, anchor.length, true);
5143
+ const body = concat2(head, fingerprint, anchor);
5144
+ if (!signingKey)
5145
+ return concat2(body, payload);
5146
+ const sealed = await sealBytes(payload, signingKey, splitTokenAad(body, auth), SEAL_VERSION);
5147
+ return concat2(body, sealed);
5148
+ }
5149
+ async function openSplitToken(token, opts = {}) {
5150
+ const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
5151
+ if (token.length < HEADER_LEN) {
5152
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `split token too short: ${token.length} bytes, need at least ${HEADER_LEN}`);
5153
+ }
5154
+ const version = token[0];
5155
+ const flags = token[1];
5156
+ const view = new DataView(token.buffer, token.byteOffset, token.byteLength);
5157
+ const anchorLen = view.getUint16(2, true);
5158
+ if (version !== SPLIT_TOKEN_FORMAT_VERSION) {
5159
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `unsupported split-token format_version ${version}; this worker speaks ` + `${SPLIT_TOKEN_FORMAT_VERSION}`);
5160
+ }
5161
+ if (flags & RESERVED_FLAGS_MASK) {
5162
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `split token sets reserved flag bits (flags=0x${flags.toString(16).padStart(2, "0")})`);
5163
+ }
5164
+ const sealed = (flags & FLAG_PAYLOAD_SEALED) !== 0;
5165
+ if (signingKey && !sealed) {
5166
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, "split token is unsealed but this worker holds a signing key; refusing. An unsealed " + "token cannot be authenticated, so accepting one here would let any caller forge a " + "split (alg:none).");
5167
+ }
5168
+ if (!signingKey && sealed) {
5169
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, "split token is sealed but this worker holds no signing key; cannot open it");
5170
+ }
5171
+ const endOfAnchor = HEADER_LEN + anchorLen;
5172
+ if (token.length < endOfAnchor) {
5173
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `split token truncated: anchor_len=${anchorLen} exceeds token length ${token.length}`);
5174
+ }
5175
+ const fingerprint = token.subarray(4, HEADER_LEN);
5176
+ const anchor = token.subarray(HEADER_LEN, endOfAnchor);
5177
+ const body = token.subarray(0, endOfAnchor);
5178
+ const rest = token.subarray(endOfAnchor);
5179
+ if (expectedFingerprint && !equalBytes2(fingerprint, expectedFingerprint)) {
5180
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, "split token was minted for a different bind (fingerprint mismatch)");
5181
+ }
5182
+ if (currentAnchor && !equalBytes2(anchor, currentAnchor)) {
5183
+ throw new SplitTokenError(SPLIT_SNAPSHOT_EXPIRED, "split snapshot expired; re-run the query");
5184
+ }
5185
+ if (!sealed)
5186
+ return new Uint8Array(rest);
5187
+ try {
5188
+ return await openBytes(rest, signingKey, splitTokenAad(body, auth), SEAL_VERSION, "split token");
5189
+ } catch (err2) {
5190
+ throw new SplitTokenError(SPLIT_TOKEN_INVALID, `split token failed authentication: ${err2 instanceof Error ? err2.message : String(err2)}`);
5191
+ }
5192
+ }
4822
5193
 
4823
5194
  // src/protocol/handlers/function.ts
5195
+ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
5196
+ if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
5197
+ return;
5198
+ const raw = toUint8Array(bindCall.attach_opaque_data);
5199
+ const txn = bindCall.transaction_opaque_data ? toUint8Array(bindCall.transaction_opaque_data) : undefined;
5200
+ const forms = [
5201
+ async () => raw,
5202
+ async () => openAttach(raw, auth, signingKey)
5203
+ ];
5204
+ for (const form of forms) {
5205
+ try {
5206
+ return splitAnchor(await catalogInterface.version(await form(), txn));
5207
+ } catch {}
5208
+ }
5209
+ return;
5210
+ }
5211
+ async function resolveSplitPayloads(request, innerParams, opts) {
5212
+ if (!request.split_tokens)
5213
+ return;
5214
+ const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
5215
+ const expected = await bindFingerprint(fp.schemaName, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
5216
+ const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey) : undefined;
5217
+ request.split_payloads = [];
5218
+ for (const token of request.split_tokens) {
5219
+ request.split_payloads.push(await openSplitToken(token, {
5220
+ signingKey: opts.signingKey,
5221
+ auth: opts.auth,
5222
+ expectedFingerprint: expected,
5223
+ currentAnchor
5224
+ }));
5225
+ }
5226
+ }
4824
5227
  function registerFunctionMethods(protocol, config) {
4825
5228
  const { registry, signingKey, catalogInterface } = config;
4826
5229
  async function stripAttach(attach, ctx) {
@@ -4829,7 +5232,7 @@ function registerFunctionMethods(protocol, config) {
4829
5232
  const env = toUint8Array(attach);
4830
5233
  if (env.length === 0)
4831
5234
  return env;
4832
- return openAttach(env, ctx?.auth, signingKey);
5235
+ return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
4833
5236
  }
4834
5237
  async function strippedContext(bindCall, ctx) {
4835
5238
  let attach = null;
@@ -4840,17 +5243,13 @@ function registerFunctionMethods(protocol, config) {
4840
5243
  }
4841
5244
  return overloadContext({ ...bindCall, attach_opaque_data: attach }, catalogInterface);
4842
5245
  }
4843
- const initHeaderSchema = schema2([
4844
- field2("execution_id", binary2(), false),
4845
- field2("opaque_data", binary2(), true),
4846
- field2("max_workers", int642(), false)
4847
- ]);
5246
+ const initHeaderSchema = GLOBAL_INIT_RESPONSE_SCHEMA;
4848
5247
  const emptySchema = schema2([]);
4849
5248
  const dummyInputSchema = schema2([
4850
5249
  field2("_tick", binary2(), true)
4851
5250
  ]);
4852
5251
  protocol.unary("bind", {
4853
- params: REQUEST_PARAMS_SCHEMA,
5252
+ params: BindParamsSchema,
4854
5253
  result: RESULT_BINARY_SCHEMA,
4855
5254
  handler: async (params, ctx) => {
4856
5255
  const innerParams = unwrapRequest(params.request);
@@ -4863,14 +5262,21 @@ function registerFunctionMethods(protocol, config) {
4863
5262
  }
4864
5263
  });
4865
5264
  protocol.exchange("init", {
4866
- params: REQUEST_PARAMS_SCHEMA,
5265
+ params: InitParamsSchema,
4867
5266
  inputSchema: dummyInputSchema,
4868
5267
  outputSchema: emptySchema,
4869
- init: async (params) => {
5268
+ init: async (params, ctx) => {
4870
5269
  const requestIpcBytes = toUint8Array(params.request);
4871
5270
  const innerParams = unwrapRequest(params.request);
4872
5271
  const request = deserializeInitRequest(innerParams);
4873
- request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
5272
+ const auth = ctx?.auth ?? currentRequestAuth();
5273
+ request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, ctx);
5274
+ await resolveSplitPayloads(request, innerParams, {
5275
+ auth,
5276
+ signingKey,
5277
+ catalogInterface,
5278
+ checkAnchor: true
5279
+ });
4874
5280
  const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call, catalogInterface));
4875
5281
  const initResponse = await func.globalInit(request);
4876
5282
  const accumulatedState = recoverFinalizeState(request, config.recoverExchangeState);
@@ -4911,6 +5317,12 @@ function registerFunctionMethods(protocol, config) {
4911
5317
  const initRequestBatch = deserializeBatch(state.initRequestIpc);
4912
5318
  const initRequestDict = batchToScalarDict(initRequestBatch);
4913
5319
  const request = deserializeInitRequest(initRequestDict);
5320
+ await resolveSplitPayloads(request, { bind_call: initRequestDict.bind_call }, {
5321
+ auth: currentRequestAuth(),
5322
+ signingKey,
5323
+ catalogInterface,
5324
+ checkAnchor: false
5325
+ });
4914
5326
  const func = registry.get(state.functionName, await strippedContext(request.bind_call));
4915
5327
  const executionId = state.executionId;
4916
5328
  const opaqueData = state.opaqueData ?? null;
@@ -4954,7 +5366,7 @@ function registerFunctionMethods(protocol, config) {
4954
5366
  }
4955
5367
  });
4956
5368
  protocol.unary("table_function_cardinality", {
4957
- params: REQUEST_PARAMS_SCHEMA,
5369
+ params: TableFunctionCardinalityParamsSchema,
4958
5370
  result: RESULT_BINARY_SCHEMA,
4959
5371
  handler: async (params) => {
4960
5372
  const innerParams = unwrapRequest(params.request);
@@ -4969,8 +5381,36 @@ function registerFunctionMethods(protocol, config) {
4969
5381
  return wrapResult(cardResult, TableFunctionCardinalityResultSchema);
4970
5382
  }
4971
5383
  });
5384
+ protocol.unary("table_function_plan", {
5385
+ params: TableFunctionPlanParamsSchema,
5386
+ result: RESULT_BINARY_SCHEMA,
5387
+ handler: async (params, ctx) => {
5388
+ const innerParams = unwrapRequest(params.request);
5389
+ const request = deserializePlanRequest(innerParams);
5390
+ const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
5391
+ const plan = func.plan ? await func.plan(request) : { splits: [{ payload: new Uint8Array(0) }] };
5392
+ const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
5393
+ const fingerprint = await bindFingerprint(fp.schemaName, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
5394
+ const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey) ?? splitAnchor(0);
5395
+ const blobs = [];
5396
+ for (const split of plan.splits) {
5397
+ const token = await buildSplitToken({
5398
+ payload: split.payload,
5399
+ fingerprint,
5400
+ anchor,
5401
+ signingKey,
5402
+ auth: ctx?.auth
5403
+ });
5404
+ blobs.push(serializeBatch(batchFromColumns(Object.fromEntries(SCAN_SPLIT_SCHEMA.fields.map((f) => [
5405
+ f.name,
5406
+ [scanSplitRow(split, token)[f.name] ?? null]
5407
+ ])), SCAN_SPLIT_SCHEMA)));
5408
+ }
5409
+ return wrapResult(planResponseRow(plan, blobs), PLAN_RESPONSE_SCHEMA);
5410
+ }
5411
+ });
4972
5412
  protocol.unary("table_function_statistics", {
4973
- params: REQUEST_PARAMS_SCHEMA,
5413
+ params: TableFunctionStatisticsParamsSchema,
4974
5414
  result: RESULT_BINARY_NULLABLE_SCHEMA,
4975
5415
  handler: async (params) => {
4976
5416
  const innerParams = unwrapRequest(params.request);
@@ -4985,7 +5425,7 @@ function registerFunctionMethods(protocol, config) {
4985
5425
  }
4986
5426
  });
4987
5427
  protocol.unary("table_function_dynamic_to_string", {
4988
- params: REQUEST_PARAMS_SCHEMA,
5428
+ params: TableFunctionDynamicToStringParamsSchema,
4989
5429
  result: RESULT_BINARY_SCHEMA,
4990
5430
  handler: async (params) => {
4991
5431
  const innerParams = unwrapRequest(params.request);
@@ -5078,6 +5518,26 @@ function choiceEquals(choice, value) {
5078
5518
  return cn === vn;
5079
5519
  return choice === value;
5080
5520
  }
5521
+ function narrowArgValue(value) {
5522
+ return typeof value === "bigint" ? Number(value) : value;
5523
+ }
5524
+ function assertArrowType(value, where) {
5525
+ if (typeof value === "function") {
5526
+ const name = value.name;
5527
+ const call = name ? `${name}()` : "the factory";
5528
+ throw new ArgumentValidationError(`${where} is a type factory, not an Arrow type — call it: ${call}. ` + `(Note that int, int32, float32 and bool are ready-made types on ` + `@query-farm/vgi but factories on @query-farm/vgi/worker-cf, so the ` + `same name may need parentheses on one entry point and not the other. ` + `int64(), float64(), utf8() and the rest are factories everywhere.)`);
5529
+ }
5530
+ if (value === null || value === undefined) {
5531
+ throw new ArgumentValidationError(`${where} is ${String(value)}, not an Arrow type.`);
5532
+ }
5533
+ }
5534
+ function assertArrowTypes(types, where) {
5535
+ if (!types)
5536
+ return;
5537
+ for (const [name, type] of Object.entries(types)) {
5538
+ assertArrowType(type, `${where}.${name}`);
5539
+ }
5540
+ }
5081
5541
  function validateConstConstraints(name, constraints, value) {
5082
5542
  if (value === null || value === undefined)
5083
5543
  return;
@@ -5305,6 +5765,7 @@ function persistGroupStates(executionId, gids) {
5305
5765
  }
5306
5766
  }
5307
5767
  function defineAggregate(config) {
5768
+ assertArrowTypes(config.args, `defineAggregate("${config.name}"): args`);
5308
5769
  const specs = [];
5309
5770
  let posIdx = 0;
5310
5771
  const varargsSet = new Set(config.varargs ?? []);
@@ -5369,7 +5830,7 @@ function registerAggregateMethods(protocol, registry) {
5369
5830
  return func.aggregateConfig;
5370
5831
  }
5371
5832
  protocol.unary("aggregate_bind", {
5372
- params: REQUEST_PARAMS_SCHEMA,
5833
+ params: AggregateBindParamsSchema,
5373
5834
  result: RESULT_BINARY_SCHEMA,
5374
5835
  handler: async (params) => {
5375
5836
  const innerParams = unwrapRequest(params.request);
@@ -5401,7 +5862,7 @@ function registerAggregateMethods(protocol, registry) {
5401
5862
  }
5402
5863
  });
5403
5864
  protocol.unary("aggregate_update", {
5404
- params: REQUEST_PARAMS_SCHEMA,
5865
+ params: AggregateUpdateParamsSchema,
5405
5866
  result: RESULT_BINARY_SCHEMA,
5406
5867
  handler: (params) => {
5407
5868
  const innerParams = unwrapRequest(params.request);
@@ -5454,7 +5915,7 @@ function registerAggregateMethods(protocol, registry) {
5454
5915
  }
5455
5916
  });
5456
5917
  protocol.unary("aggregate_combine", {
5457
- params: REQUEST_PARAMS_SCHEMA,
5918
+ params: AggregateCombineParamsSchema,
5458
5919
  result: RESULT_BINARY_SCHEMA,
5459
5920
  handler: (params) => {
5460
5921
  const innerParams = unwrapRequest(params.request);
@@ -5499,7 +5960,7 @@ function registerAggregateMethods(protocol, registry) {
5499
5960
  }
5500
5961
  });
5501
5962
  protocol.unary("aggregate_finalize", {
5502
- params: REQUEST_PARAMS_SCHEMA,
5963
+ params: AggregateFinalizeParamsSchema,
5503
5964
  result: RESULT_BINARY_SCHEMA,
5504
5965
  handler: (params) => {
5505
5966
  const innerParams = unwrapRequest(params.request);
@@ -5537,7 +5998,7 @@ function registerAggregateMethods(protocol, registry) {
5537
5998
  }
5538
5999
  });
5539
6000
  protocol.unary("aggregate_destructor", {
5540
- params: REQUEST_PARAMS_SCHEMA,
6001
+ params: AggregateDestructorParamsSchema,
5541
6002
  result: RESULT_BINARY_SCHEMA,
5542
6003
  handler: (params) => {
5543
6004
  const innerParams = unwrapRequest(params.request);
@@ -6353,7 +6814,7 @@ function registerTableBufferingMethods(protocol, registry, signingKey) {
6353
6814
  return { func, params };
6354
6815
  }
6355
6816
  protocol.unary("table_buffering_process", {
6356
- params: REQUEST_PARAMS_SCHEMA,
6817
+ params: TableBufferingProcessParamsSchema,
6357
6818
  result: RESULT_BINARY_SCHEMA,
6358
6819
  handler: async (rpcParams, ctx) => {
6359
6820
  const inner = unwrapRequest(rpcParams.request);
@@ -6371,7 +6832,7 @@ function registerTableBufferingMethods(protocol, registry, signingKey) {
6371
6832
  }
6372
6833
  });
6373
6834
  protocol.unary("table_buffering_combine", {
6374
- params: REQUEST_PARAMS_SCHEMA,
6835
+ params: TableBufferingCombineParamsSchema,
6375
6836
  result: RESULT_BINARY_SCHEMA,
6376
6837
  handler: async (rpcParams, ctx) => {
6377
6838
  const inner = unwrapRequest(rpcParams.request);
@@ -6389,7 +6850,7 @@ function registerTableBufferingMethods(protocol, registry, signingKey) {
6389
6850
  }
6390
6851
  });
6391
6852
  protocol.unary("table_buffering_destructor", {
6392
- params: REQUEST_PARAMS_SCHEMA,
6853
+ params: TableBufferingDestructorParamsSchema,
6393
6854
  result: RESULT_BINARY_SCHEMA,
6394
6855
  handler: async (rpcParams) => {
6395
6856
  try {
@@ -6424,9 +6885,6 @@ function hex(buf) {
6424
6885
  return Array.from(buf, (b) => b.toString(16).padStart(2, "0")).join("");
6425
6886
  }
6426
6887
 
6427
- // src/protocol/handlers/catalog/admin.ts
6428
- init_arrow();
6429
-
6430
6888
  // src/codec/asd.ts
6431
6889
  init_arrow();
6432
6890
  function encodeASD(schema3, obj) {
@@ -6461,21 +6919,35 @@ var encodeAttachCatalogInfo = (v) => encodeASD(AttachCatalogInfoSchema, {
6461
6919
  required: v.required ?? false,
6462
6920
  secret_ref: v.secret_ref ?? ""
6463
6921
  });
6922
+ function encodeScanFunctionResult(functionName, argumentsBytes, requiredExtensions = []) {
6923
+ return serializeBatch(batchFromColumns({
6924
+ function_name: [functionName],
6925
+ arguments: [argumentsBytes],
6926
+ required_extensions: [requiredExtensions]
6927
+ }, ScanFunctionResultSchema));
6928
+ }
6464
6929
  function singleBranchResult(legacy) {
6465
- const branchBatch = batchFromColumns({
6466
- function_name: [legacy.function_name],
6467
- arguments: [toUint8Array(legacy.arguments)],
6468
- branch_filter: [null],
6469
- writable: [false],
6470
- source_catalog: [null],
6471
- source_schema: [null],
6472
- source_table: [null]
6473
- }, ScanBranchSchema);
6474
6930
  return {
6475
- branches: [serializeBatch(branchBatch)],
6931
+ branches: [
6932
+ encodeScanBranch({ function_name: legacy.function_name, arguments: toUint8Array(legacy.arguments) })
6933
+ ],
6476
6934
  required_extensions: legacy.required_extensions ?? []
6477
6935
  };
6478
6936
  }
6937
+ function encodeScanBranch(cols) {
6938
+ return serializeBatch(batchFromColumns({
6939
+ function_name: [cols.function_name],
6940
+ arguments: [cols.arguments],
6941
+ branch_filter: [cols.branch_filter ?? null],
6942
+ writable: [cols.writable ?? false],
6943
+ source_catalog: [cols.source_catalog ?? null],
6944
+ source_schema: [cols.source_schema ?? null],
6945
+ source_table: [cols.source_table ?? null],
6946
+ format_name: [cols.format_name ?? null],
6947
+ format_locations: [cols.format_locations ?? null],
6948
+ format_options: [cols.format_options ?? null]
6949
+ }, ScanBranchSchema));
6950
+ }
6479
6951
  function isPromise(v) {
6480
6952
  return v != null && typeof v.then === "function";
6481
6953
  }
@@ -6608,7 +7080,7 @@ class CatalogInterface {
6608
7080
  // src/protocol/handlers/catalog/admin.ts
6609
7081
  function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6610
7082
  catalogUnary(protocol, signingKey, "catalog_catalogs", {
6611
- params: emptyResultSchema,
7083
+ params: CatalogCatalogsParamsSchema,
6612
7084
  result: RESULT_BINARY_SCHEMA,
6613
7085
  handler: async () => {
6614
7086
  const cat = getCatalog();
@@ -6624,7 +7096,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6624
7096
  }
6625
7097
  });
6626
7098
  protocol.unary("catalog_attach", {
6627
- params: REQUEST_PARAMS_SCHEMA,
7099
+ params: CatalogAttachParamsSchema,
6628
7100
  result: RESULT_BINARY_SCHEMA,
6629
7101
  handler: async (params, ctx) => {
6630
7102
  const innerParams = unwrapRequest(params.request);
@@ -6654,7 +7126,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6654
7126
  }
6655
7127
  });
6656
7128
  catalogUnary(protocol, signingKey, "catalog_detach", {
6657
- params: attachOpaqueDataParam,
7129
+ params: CatalogDetachParamsSchema,
6658
7130
  result: emptyResultSchema,
6659
7131
  handler: async (params) => {
6660
7132
  const cat = getCatalog();
@@ -6663,11 +7135,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6663
7135
  }
6664
7136
  });
6665
7137
  catalogUnary(protocol, signingKey, "catalog_create", {
6666
- params: schema2([
6667
- field2("name", utf82(), false),
6668
- field2("on_conflict", utf82(), false),
6669
- field2("options", binary2(), true)
6670
- ]),
7138
+ params: CatalogCreateParamsSchema,
6671
7139
  result: emptyResultSchema,
6672
7140
  handler: async (params) => {
6673
7141
  const cat = getCatalog();
@@ -6676,7 +7144,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6676
7144
  }
6677
7145
  });
6678
7146
  catalogUnary(protocol, signingKey, "catalog_drop", {
6679
- params: schema2([field2("name", utf82(), false)]),
7147
+ params: CatalogDropParamsSchema,
6680
7148
  result: emptyResultSchema,
6681
7149
  handler: async (params) => {
6682
7150
  const cat = getCatalog();
@@ -6685,7 +7153,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6685
7153
  }
6686
7154
  });
6687
7155
  catalogUnary(protocol, signingKey, "catalog_version", {
6688
- params: attachOpaqueDataTxnParams,
7156
+ params: CatalogVersionParamsSchema,
6689
7157
  result: RESULT_BINARY_SCHEMA,
6690
7158
  handler: async (params) => {
6691
7159
  const cat = getCatalog();
@@ -6694,7 +7162,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6694
7162
  }
6695
7163
  });
6696
7164
  protocol.unary("catalog_transaction_begin", {
6697
- params: attachOpaqueDataParam,
7165
+ params: CatalogTransactionBeginParamsSchema,
6698
7166
  result: RESULT_BINARY_SCHEMA,
6699
7167
  handler: async (params, ctx) => {
6700
7168
  const auth = ctx?.auth;
@@ -6707,7 +7175,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6707
7175
  }
6708
7176
  });
6709
7177
  catalogUnary(protocol, signingKey, "catalog_transaction_commit", {
6710
- params: attachOpaqueDataTxnParams,
7178
+ params: CatalogTransactionCommitParamsSchema,
6711
7179
  result: emptyResultSchema,
6712
7180
  handler: async (params) => {
6713
7181
  const cat = getCatalog();
@@ -6716,7 +7184,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6716
7184
  }
6717
7185
  });
6718
7186
  catalogUnary(protocol, signingKey, "catalog_transaction_rollback", {
6719
- params: attachOpaqueDataTxnParams,
7187
+ params: CatalogTransactionRollbackParamsSchema,
6720
7188
  result: emptyResultSchema,
6721
7189
  handler: async (params) => {
6722
7190
  const cat = getCatalog();
@@ -6725,7 +7193,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6725
7193
  }
6726
7194
  });
6727
7195
  catalogUnary(protocol, signingKey, "catalog_schemas", {
6728
- params: attachOpaqueDataTxnParams,
7196
+ params: CatalogSchemasParamsSchema,
6729
7197
  result: RESULT_BINARY_SCHEMA,
6730
7198
  handler: async (params) => {
6731
7199
  const cat = getCatalog();
@@ -6736,7 +7204,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6736
7204
  }
6737
7205
  });
6738
7206
  catalogUnary(protocol, signingKey, "catalog_copy_from_formats", {
6739
- params: attachOpaqueDataTxnParams,
7207
+ params: CatalogCopyFromFormatsParamsSchema,
6740
7208
  result: RESULT_BINARY_SCHEMA,
6741
7209
  handler: async (params) => {
6742
7210
  const cat = getCatalog();
@@ -6747,7 +7215,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6747
7215
  }
6748
7216
  });
6749
7217
  catalogUnary(protocol, signingKey, "catalog_schema_get", {
6750
- params: attachOpaqueDataNameTxnParams,
7218
+ params: CatalogSchemaGetParamsSchema,
6751
7219
  result: RESULT_BINARY_SCHEMA,
6752
7220
  handler: async (params) => {
6753
7221
  const cat = getCatalog();
@@ -6758,13 +7226,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6758
7226
  }
6759
7227
  });
6760
7228
  catalogUnary(protocol, signingKey, "catalog_schema_create", {
6761
- params: schema2([
6762
- field2("attach_opaque_data", binary2(), true),
6763
- field2("name", utf82(), false),
6764
- field2("comment", utf82(), true),
6765
- field2("tags", binary2(), true),
6766
- field2("transaction_opaque_data", binary2(), true)
6767
- ]),
7229
+ params: CatalogSchemaCreateParamsSchema,
6768
7230
  result: emptyResultSchema,
6769
7231
  handler: async (params) => {
6770
7232
  const cat = getCatalog();
@@ -6773,13 +7235,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6773
7235
  }
6774
7236
  });
6775
7237
  catalogUnary(protocol, signingKey, "catalog_schema_drop", {
6776
- params: schema2([
6777
- field2("attach_opaque_data", binary2(), true),
6778
- field2("name", utf82(), false),
6779
- field2("ignore_not_found", bool2(), true),
6780
- field2("cascade", bool2(), true),
6781
- field2("transaction_opaque_data", binary2(), true)
6782
- ]),
7238
+ params: CatalogSchemaDropParamsSchema,
6783
7239
  result: emptyResultSchema,
6784
7240
  handler: async (params) => {
6785
7241
  const cat = getCatalog();
@@ -6788,7 +7244,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6788
7244
  }
6789
7245
  });
6790
7246
  catalogUnary(protocol, signingKey, "catalog_schema_contents_tables", {
6791
- params: attachOpaqueDataNameTxnParams,
7247
+ params: CatalogSchemaContentsTablesParamsSchema,
6792
7248
  result: RESULT_BINARY_SCHEMA,
6793
7249
  handler: async (params) => {
6794
7250
  const cat = getCatalog();
@@ -6799,7 +7255,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6799
7255
  }
6800
7256
  });
6801
7257
  catalogUnary(protocol, signingKey, "catalog_schema_contents_views", {
6802
- params: attachOpaqueDataNameTxnParams,
7258
+ params: CatalogSchemaContentsViewsParamsSchema,
6803
7259
  result: RESULT_BINARY_SCHEMA,
6804
7260
  handler: async (params) => {
6805
7261
  const cat = getCatalog();
@@ -6810,12 +7266,7 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6810
7266
  }
6811
7267
  });
6812
7268
  catalogUnary(protocol, signingKey, "catalog_schema_contents_functions", {
6813
- params: schema2([
6814
- field2("attach_opaque_data", binary2(), true),
6815
- field2("name", utf82(), false),
6816
- field2("type", utf82(), false),
6817
- field2("transaction_opaque_data", binary2(), true)
6818
- ]),
7269
+ params: CatalogSchemaContentsFunctionsParamsSchema,
6819
7270
  result: RESULT_BINARY_SCHEMA,
6820
7271
  handler: async (params) => {
6821
7272
  const cat = getCatalog();
@@ -6828,17 +7279,9 @@ function registerCatalogAdminMethods(protocol, getCatalog, signingKey) {
6828
7279
  }
6829
7280
 
6830
7281
  // src/protocol/handlers/catalog/table.ts
6831
- init_arrow();
6832
7282
  function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6833
7283
  catalogUnary(protocol, signingKey, "catalog_table_get", {
6834
- params: schema2([
6835
- field2("attach_opaque_data", binary2(), true),
6836
- field2("schema_name", utf82(), false),
6837
- field2("name", utf82(), false),
6838
- field2("at_unit", utf82(), true),
6839
- field2("at_value", utf82(), true),
6840
- field2("transaction_opaque_data", binary2(), true)
6841
- ]),
7284
+ params: CatalogTableGetParamsSchema,
6842
7285
  result: RESULT_BINARY_SCHEMA,
6843
7286
  handler: async (params) => {
6844
7287
  const cat = getCatalog();
@@ -6849,17 +7292,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6849
7292
  }
6850
7293
  });
6851
7294
  catalogUnary(protocol, signingKey, "catalog_table_create", {
6852
- params: schema2([
6853
- field2("attach_opaque_data", binary2(), true),
6854
- field2("schema_name", utf82(), false),
6855
- field2("name", utf82(), false),
6856
- field2("columns", binary2(), false),
6857
- field2("on_conflict", utf82(), false),
6858
- field2("not_null_constraints", list2(field2("item", int322(), false)), true),
6859
- field2("unique_constraints", list2(field2("item", list2(field2("item", int322(), false)), false)), true),
6860
- field2("check_constraints", list2(field2("item", utf82(), false)), true),
6861
- field2("transaction_opaque_data", binary2(), true)
6862
- ]),
7295
+ params: CatalogTableCreateParamsSchema,
6863
7296
  result: emptyResultSchema,
6864
7297
  handler: async (params) => {
6865
7298
  const cat = getCatalog();
@@ -6868,13 +7301,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6868
7301
  }
6869
7302
  });
6870
7303
  catalogUnary(protocol, signingKey, "catalog_table_drop", {
6871
- params: schema2([
6872
- field2("attach_opaque_data", binary2(), true),
6873
- field2("schema_name", utf82(), false),
6874
- field2("name", utf82(), false),
6875
- field2("ignore_not_found", bool2(), true),
6876
- field2("transaction_opaque_data", binary2(), true)
6877
- ]),
7304
+ params: CatalogTableDropParamsSchema,
6878
7305
  result: emptyResultSchema,
6879
7306
  handler: async (params) => {
6880
7307
  const cat = getCatalog();
@@ -6883,12 +7310,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6883
7310
  }
6884
7311
  });
6885
7312
  catalogUnary(protocol, signingKey, "catalog_table_column_statistics_get", {
6886
- params: schema2([
6887
- field2("attach_opaque_data", binary2(), true),
6888
- field2("schema_name", utf82(), false),
6889
- field2("name", utf82(), false),
6890
- field2("transaction_opaque_data", binary2(), true)
6891
- ]),
7313
+ params: CatalogTableColumnStatisticsGetParamsSchema,
6892
7314
  result: RESULT_BINARY_NULLABLE_SCHEMA,
6893
7315
  handler: async (params) => {
6894
7316
  const cat = getCatalog();
@@ -6897,14 +7319,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6897
7319
  }
6898
7320
  });
6899
7321
  catalogUnary(protocol, signingKey, "catalog_table_scan_function_get", {
6900
- params: schema2([
6901
- field2("attach_opaque_data", binary2(), true),
6902
- field2("schema_name", utf82(), false),
6903
- field2("name", utf82(), false),
6904
- field2("at_unit", utf82(), true),
6905
- field2("at_value", utf82(), true),
6906
- field2("transaction_opaque_data", binary2(), true)
6907
- ]),
7322
+ params: CatalogTableScanFunctionGetParamsSchema,
6908
7323
  result: RESULT_BINARY_SCHEMA,
6909
7324
  handler: async (params) => {
6910
7325
  const cat = getCatalog();
@@ -6913,14 +7328,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6913
7328
  }
6914
7329
  });
6915
7330
  catalogUnary(protocol, signingKey, "catalog_table_scan_branches_get", {
6916
- params: schema2([
6917
- field2("attach_opaque_data", binary2(), true),
6918
- field2("schema_name", utf82(), false),
6919
- field2("name", utf82(), false),
6920
- field2("at_unit", utf82(), true),
6921
- field2("at_value", utf82(), true),
6922
- field2("transaction_opaque_data", binary2(), true)
6923
- ]),
7331
+ params: CatalogTableScanBranchesGetParamsSchema,
6924
7332
  result: RESULT_BINARY_SCHEMA,
6925
7333
  handler: async (params) => {
6926
7334
  const cat = getCatalog();
@@ -6929,7 +7337,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6929
7337
  }
6930
7338
  });
6931
7339
  catalogUnary(protocol, signingKey, "catalog_table_comment_set", {
6932
- params: schemaNameCommentParams,
7340
+ params: CatalogTableCommentSetParamsSchema,
6933
7341
  result: emptyResultSchema,
6934
7342
  handler: async (params) => {
6935
7343
  const cat = getCatalog();
@@ -6938,7 +7346,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6938
7346
  }
6939
7347
  });
6940
7348
  catalogUnary(protocol, signingKey, "catalog_table_rename", {
6941
- params: schemaNameRenameParams,
7349
+ params: CatalogTableRenameParamsSchema,
6942
7350
  result: emptyResultSchema,
6943
7351
  handler: async (params) => {
6944
7352
  const cat = getCatalog();
@@ -6947,16 +7355,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6947
7355
  }
6948
7356
  });
6949
7357
  catalogUnary(protocol, signingKey, "catalog_table_column_add", {
6950
- params: schema2([
6951
- field2("attach_opaque_data", binary2(), true),
6952
- field2("schema_name", utf82(), false),
6953
- field2("name", utf82(), false),
6954
- field2("column_name", utf82(), false),
6955
- field2("column_type", utf82(), false),
6956
- field2("default_value", utf82(), true),
6957
- field2("ignore_not_found", bool2(), true),
6958
- field2("transaction_opaque_data", binary2(), true)
6959
- ]),
7358
+ params: CatalogTableColumnAddParamsSchema,
6960
7359
  result: emptyResultSchema,
6961
7360
  handler: async (params) => {
6962
7361
  const cat = getCatalog();
@@ -6965,7 +7364,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6965
7364
  }
6966
7365
  });
6967
7366
  catalogUnary(protocol, signingKey, "catalog_table_column_drop", {
6968
- params: columnOpParams,
7367
+ params: CatalogTableColumnDropParamsSchema,
6969
7368
  result: emptyResultSchema,
6970
7369
  handler: async (params) => {
6971
7370
  const cat = getCatalog();
@@ -6974,15 +7373,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6974
7373
  }
6975
7374
  });
6976
7375
  catalogUnary(protocol, signingKey, "catalog_table_column_rename", {
6977
- params: schema2([
6978
- field2("attach_opaque_data", binary2(), true),
6979
- field2("schema_name", utf82(), false),
6980
- field2("name", utf82(), false),
6981
- field2("column_name", utf82(), false),
6982
- field2("new_name", utf82(), false),
6983
- field2("ignore_not_found", bool2(), true),
6984
- field2("transaction_opaque_data", binary2(), true)
6985
- ]),
7376
+ params: CatalogTableColumnRenameParamsSchema,
6986
7377
  result: emptyResultSchema,
6987
7378
  handler: async (params) => {
6988
7379
  const cat = getCatalog();
@@ -6991,15 +7382,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
6991
7382
  }
6992
7383
  });
6993
7384
  catalogUnary(protocol, signingKey, "catalog_table_column_default_set", {
6994
- params: schema2([
6995
- field2("attach_opaque_data", binary2(), true),
6996
- field2("schema_name", utf82(), false),
6997
- field2("name", utf82(), false),
6998
- field2("column_name", utf82(), false),
6999
- field2("default_value", utf82(), false),
7000
- field2("ignore_not_found", bool2(), true),
7001
- field2("transaction_opaque_data", binary2(), true)
7002
- ]),
7385
+ params: CatalogTableColumnDefaultSetParamsSchema,
7003
7386
  result: emptyResultSchema,
7004
7387
  handler: async (params) => {
7005
7388
  const cat = getCatalog();
@@ -7008,7 +7391,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
7008
7391
  }
7009
7392
  });
7010
7393
  catalogUnary(protocol, signingKey, "catalog_table_column_default_drop", {
7011
- params: columnOpParams,
7394
+ params: CatalogTableColumnDefaultDropParamsSchema,
7012
7395
  result: emptyResultSchema,
7013
7396
  handler: async (params) => {
7014
7397
  const cat = getCatalog();
@@ -7017,15 +7400,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
7017
7400
  }
7018
7401
  });
7019
7402
  catalogUnary(protocol, signingKey, "catalog_table_column_type_change", {
7020
- params: schema2([
7021
- field2("attach_opaque_data", binary2(), true),
7022
- field2("schema_name", utf82(), false),
7023
- field2("name", utf82(), false),
7024
- field2("column_name", utf82(), false),
7025
- field2("new_type", utf82(), false),
7026
- field2("ignore_not_found", bool2(), true),
7027
- field2("transaction_opaque_data", binary2(), true)
7028
- ]),
7403
+ params: CatalogTableColumnTypeChangeParamsSchema,
7029
7404
  result: emptyResultSchema,
7030
7405
  handler: async (params) => {
7031
7406
  const cat = getCatalog();
@@ -7034,7 +7409,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
7034
7409
  }
7035
7410
  });
7036
7411
  catalogUnary(protocol, signingKey, "catalog_table_not_null_set", {
7037
- params: columnOpParams,
7412
+ params: CatalogTableNotNullSetParamsSchema,
7038
7413
  result: emptyResultSchema,
7039
7414
  handler: async (params) => {
7040
7415
  const cat = getCatalog();
@@ -7043,7 +7418,7 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
7043
7418
  }
7044
7419
  });
7045
7420
  catalogUnary(protocol, signingKey, "catalog_table_not_null_drop", {
7046
- params: columnOpParams,
7421
+ params: CatalogTableNotNullDropParamsSchema,
7047
7422
  result: emptyResultSchema,
7048
7423
  handler: async (params) => {
7049
7424
  const cat = getCatalog();
@@ -7054,10 +7429,9 @@ function registerCatalogTableMethods(protocol, getCatalog, signingKey) {
7054
7429
  }
7055
7430
 
7056
7431
  // src/protocol/handlers/catalog/view.ts
7057
- init_arrow();
7058
7432
  function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7059
7433
  catalogUnary(protocol, signingKey, "catalog_view_get", {
7060
- params: attachOpaqueDataSchemaNameTxnParams,
7434
+ params: CatalogViewGetParamsSchema,
7061
7435
  result: RESULT_BINARY_SCHEMA,
7062
7436
  handler: async (params) => {
7063
7437
  const cat = getCatalog();
@@ -7068,14 +7442,7 @@ function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7068
7442
  }
7069
7443
  });
7070
7444
  catalogUnary(protocol, signingKey, "catalog_view_create", {
7071
- params: schema2([
7072
- field2("attach_opaque_data", binary2(), true),
7073
- field2("schema_name", utf82(), false),
7074
- field2("name", utf82(), false),
7075
- field2("definition", utf82(), false),
7076
- field2("on_conflict", utf82(), false),
7077
- field2("transaction_opaque_data", binary2(), true)
7078
- ]),
7445
+ params: CatalogViewCreateParamsSchema,
7079
7446
  result: emptyResultSchema,
7080
7447
  handler: async (params) => {
7081
7448
  const cat = getCatalog();
@@ -7084,7 +7451,7 @@ function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7084
7451
  }
7085
7452
  });
7086
7453
  catalogUnary(protocol, signingKey, "catalog_view_drop", {
7087
- params: schemaNameIgnoreNotFoundTxnParams,
7454
+ params: CatalogViewDropParamsSchema,
7088
7455
  result: emptyResultSchema,
7089
7456
  handler: async (params) => {
7090
7457
  const cat = getCatalog();
@@ -7093,7 +7460,7 @@ function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7093
7460
  }
7094
7461
  });
7095
7462
  catalogUnary(protocol, signingKey, "catalog_view_rename", {
7096
- params: schemaNameRenameParams,
7463
+ params: CatalogViewRenameParamsSchema,
7097
7464
  result: emptyResultSchema,
7098
7465
  handler: async (params) => {
7099
7466
  const cat = getCatalog();
@@ -7102,7 +7469,7 @@ function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7102
7469
  }
7103
7470
  });
7104
7471
  catalogUnary(protocol, signingKey, "catalog_view_comment_set", {
7105
- params: schemaNameCommentParams,
7472
+ params: CatalogViewCommentSetParamsSchema,
7106
7473
  result: emptyResultSchema,
7107
7474
  handler: async (params) => {
7108
7475
  const cat = getCatalog();
@@ -7113,10 +7480,9 @@ function registerCatalogViewMethods(protocol, getCatalog, signingKey) {
7113
7480
  }
7114
7481
 
7115
7482
  // src/protocol/handlers/catalog/macro.ts
7116
- init_arrow();
7117
7483
  function registerCatalogMacroMethods(protocol, getCatalog, signingKey) {
7118
7484
  catalogUnary(protocol, signingKey, "catalog_macro_get", {
7119
- params: attachOpaqueDataSchemaNameTxnParams,
7485
+ params: CatalogMacroGetParamsSchema,
7120
7486
  result: RESULT_BINARY_SCHEMA,
7121
7487
  handler: async (params) => {
7122
7488
  const cat = getCatalog();
@@ -7127,7 +7493,7 @@ function registerCatalogMacroMethods(protocol, getCatalog, signingKey) {
7127
7493
  }
7128
7494
  });
7129
7495
  catalogUnary(protocol, signingKey, "catalog_macro_create", {
7130
- params: REQUEST_PARAMS_SCHEMA,
7496
+ params: CatalogMacroCreateParamsSchema,
7131
7497
  result: emptyResultSchema,
7132
7498
  handler: async (params) => {
7133
7499
  const cat = getCatalog();
@@ -7137,13 +7503,7 @@ function registerCatalogMacroMethods(protocol, getCatalog, signingKey) {
7137
7503
  }
7138
7504
  });
7139
7505
  catalogUnary(protocol, signingKey, "catalog_macro_drop", {
7140
- params: schema2([
7141
- field2("attach_opaque_data", binary2(), true),
7142
- field2("schema_name", utf82(), false),
7143
- field2("name", utf82(), false),
7144
- field2("ignore_not_found", bool2(), true),
7145
- field2("transaction_opaque_data", binary2(), true)
7146
- ]),
7506
+ params: CatalogMacroDropParamsSchema,
7147
7507
  result: emptyResultSchema,
7148
7508
  handler: async (params) => {
7149
7509
  const cat = getCatalog();
@@ -7152,12 +7512,7 @@ function registerCatalogMacroMethods(protocol, getCatalog, signingKey) {
7152
7512
  }
7153
7513
  });
7154
7514
  catalogUnary(protocol, signingKey, "catalog_schema_contents_macros", {
7155
- params: schema2([
7156
- field2("attach_opaque_data", binary2(), true),
7157
- field2("name", utf82(), false),
7158
- field2("type", utf82(), false),
7159
- field2("transaction_opaque_data", binary2(), true)
7160
- ]),
7515
+ params: CatalogSchemaContentsMacrosParamsSchema,
7161
7516
  result: RESULT_BINARY_SCHEMA,
7162
7517
  handler: async (params) => {
7163
7518
  const cat = getCatalog();
@@ -7170,14 +7525,9 @@ function registerCatalogMacroMethods(protocol, getCatalog, signingKey) {
7170
7525
  }
7171
7526
 
7172
7527
  // src/protocol/handlers/catalog/index_methods.ts
7173
- init_arrow();
7174
7528
  function registerCatalogIndexMethods(protocol, getCatalog, signingKey) {
7175
7529
  catalogUnary(protocol, signingKey, "catalog_schema_contents_indexes", {
7176
- params: schema2([
7177
- field2("attach_opaque_data", binary2(), true),
7178
- field2("name", utf82(), false),
7179
- field2("transaction_opaque_data", binary2(), true)
7180
- ]),
7530
+ params: CatalogSchemaContentsIndexesParamsSchema,
7181
7531
  result: RESULT_BINARY_SCHEMA,
7182
7532
  handler: async (params) => {
7183
7533
  const cat = getCatalog();
@@ -7188,12 +7538,7 @@ function registerCatalogIndexMethods(protocol, getCatalog, signingKey) {
7188
7538
  }
7189
7539
  });
7190
7540
  catalogUnary(protocol, signingKey, "catalog_index_get", {
7191
- params: schema2([
7192
- field2("attach_opaque_data", binary2(), true),
7193
- field2("schema_name", utf82(), false),
7194
- field2("name", utf82(), false),
7195
- field2("transaction_opaque_data", binary2(), true)
7196
- ]),
7541
+ params: CatalogIndexGetParamsSchema,
7197
7542
  result: RESULT_BINARY_SCHEMA,
7198
7543
  handler: async (params) => {
7199
7544
  const cat = getCatalog();
@@ -7334,9 +7679,35 @@ function createLandingRoutes(info) {
7334
7679
  }
7335
7680
 
7336
7681
  // src/http/fetch.ts
7682
+ var requestAuthStorage;
7683
+ var requestAuthStoragePending;
7684
+ function ensureRequestAuthStorage() {
7685
+ if (requestAuthStorage !== undefined)
7686
+ return Promise.resolve(requestAuthStorage);
7687
+ requestAuthStoragePending ??= import("node:async_hooks").then((mod) => {
7688
+ const storage2 = new mod.AsyncLocalStorage;
7689
+ requestAuthStorage = storage2;
7690
+ setRequestAuthScope(storage2);
7691
+ return storage2;
7692
+ }).catch(() => {
7693
+ requestAuthStorage = null;
7694
+ return null;
7695
+ });
7696
+ return requestAuthStoragePending;
7697
+ }
7698
+ var REQUEST_AUTH_DISPATCH_HOOK = {
7699
+ onDispatchStart(info) {
7700
+ const holder = requestAuthStorage?.getStore();
7701
+ if (holder) {
7702
+ holder.auth = info.authenticated ? new AuthContext(info.authDomain ?? "", true, info.principal ?? "", info.claims ?? {}) : AuthContext.anonymous();
7703
+ }
7704
+ return;
7705
+ },
7706
+ onDispatchEnd() {}
7707
+ };
7337
7708
  function createVgiFetch(opts) {
7338
7709
  if (!opts.landingInfo) {
7339
- throw new Error("createVgiFetch requires `landingInfo` ({ name, doc, version }). Without it " + "GET / serves vgi-rpc's generic placeholder instead of the VGI landing page " + "and GET /vgi-client.js 404s.");
7710
+ throw new Error("createVgiFetch requires `landingInfo` ({ name, doc, version }). Without it GET / serves vgi-rpc's generic placeholder instead of the VGI landing page and GET /vgi-client.js 404s.");
7340
7711
  }
7341
7712
  const tokenTtl = opts.tokenTtl ?? 3600;
7342
7713
  const prefix = opts.prefix ?? "/vgi";
@@ -7356,12 +7727,19 @@ function createVgiFetch(opts) {
7356
7727
  tokenKey: opts.signingKey,
7357
7728
  tokenTtl,
7358
7729
  stateSerializer: arrowStateSerializer,
7730
+ dispatchHook: REQUEST_AUTH_DISPATCH_HOOK,
7731
+ authenticate: opts.authenticate,
7359
7732
  corsOrigins: opts.corsOrigins === null ? undefined : opts.corsOrigins ?? "*",
7360
7733
  repositoryUrl: opts.repositoryUrl,
7361
7734
  extraRoutes: createLandingRoutes(opts.landingInfo),
7362
7735
  enableLandingPage: false
7363
7736
  });
7364
- return async (req) => handler(req);
7737
+ return async (req) => {
7738
+ const storage2 = await ensureRequestAuthStorage();
7739
+ if (!storage2)
7740
+ return handler(req);
7741
+ return storage2.run({}, () => handler(req));
7742
+ };
7365
7743
  }
7366
7744
  // src/cache-control.ts
7367
7745
  var CACHE_TTL_KEY = "vgi.cache.ttl";
@@ -7382,9 +7760,9 @@ var CACHE_SCOPE_CATALOG = "catalog";
7382
7760
  var CACHE_SCOPE_TRANSACTION = "transaction";
7383
7761
  var VALID_SCOPES = [CACHE_SCOPE_CATALOG, CACHE_SCOPE_TRANSACTION];
7384
7762
  function cacheControlMetadata(cc, extra) {
7385
- const scope = cc.scope ?? CACHE_SCOPE_CATALOG;
7386
- if (!VALID_SCOPES.includes(scope)) {
7387
- throw new Error(`CacheControl.scope must be one of ${VALID_SCOPES.join(", ")}, got ${JSON.stringify(scope)}`);
7763
+ const scope2 = cc.scope ?? CACHE_SCOPE_CATALOG;
7764
+ if (!VALID_SCOPES.includes(scope2)) {
7765
+ throw new Error(`CacheControl.scope must be one of ${VALID_SCOPES.join(", ")}, got ${JSON.stringify(scope2)}`);
7388
7766
  }
7389
7767
  for (const name of ["ttl", "staleWhileRevalidate", "staleIfError"]) {
7390
7768
  const value = cc[name];
@@ -7399,7 +7777,7 @@ function cacheControlMetadata(cc, extra) {
7399
7777
  md.set(CACHE_EXPIRES_KEY, cc.expires);
7400
7778
  if (cc.noStore)
7401
7779
  md.set(CACHE_NO_STORE_KEY, "1");
7402
- md.set(CACHE_SCOPE_KEY, scope);
7780
+ md.set(CACHE_SCOPE_KEY, scope2);
7403
7781
  if (cc.etag !== undefined)
7404
7782
  md.set(CACHE_ETAG_KEY, cc.etag);
7405
7783
  if (cc.lastModified !== undefined)
@@ -7421,6 +7799,14 @@ function cacheControlMetadata(cc, extra) {
7421
7799
  // src/functions/scalar.ts
7422
7800
  init_arrow();
7423
7801
  function defineScalarFunction(config) {
7802
+ assertArrowTypes(config.params, `defineScalarFunction("${config.name}"): params`);
7803
+ assertArrowTypes(config.constParams, `defineScalarFunction("${config.name}"): constParams`);
7804
+ if (config.returns !== undefined) {
7805
+ assertArrowType(config.returns, `defineScalarFunction("${config.name}"): returns`);
7806
+ }
7807
+ for (const p of config.parameters ?? []) {
7808
+ assertArrowType(p.type, `defineScalarFunction("${config.name}"): parameters["${p.name}"].type`);
7809
+ }
7424
7810
  const repr = config.repr ?? "rich";
7425
7811
  const specs = [];
7426
7812
  if (config.parameters) {
@@ -7636,6 +8022,7 @@ function makeProjectingCollector(inner, targetSchema) {
7636
8022
  });
7637
8023
  }
7638
8024
  function defineTableFunction(config) {
8025
+ assertArrowTypes(config.args, `defineTableFunction("${config.name}"): args`);
7639
8026
  const specs = [];
7640
8027
  let posIdx = 0;
7641
8028
  if (config.args) {
@@ -7675,7 +8062,9 @@ function defineTableFunction(config) {
7675
8062
  orderDependent: config.orderDependent,
7676
8063
  distinctDependent: config.distinctDependent,
7677
8064
  supportsBatchIndex: config.supportsBatchIndex,
7678
- partitionKind: config.partitionKind
8065
+ partitionKind: config.partitionKind,
8066
+ supportsSplits: config.supportsSplits,
8067
+ splitTokenTtlSeconds: config.splitTokenTtlSeconds
7679
8068
  };
7680
8069
  function extractArgs(request) {
7681
8070
  const args = {};
@@ -7687,8 +8076,7 @@ function defineTableFunction(config) {
7687
8076
  } catch {
7688
8077
  val = request.arguments.get(spec.name, defaultVal);
7689
8078
  }
7690
- if (typeof val === "bigint")
7691
- val = safeNumber(val);
8079
+ val = narrowArgValue(val);
7692
8080
  const constraints = config.argConstraints?.[spec.name];
7693
8081
  if (constraints)
7694
8082
  validateConstConstraints(spec.name, constraints, val);
@@ -7722,6 +8110,22 @@ function defineTableFunction(config) {
7722
8110
  async globalInit(request) {
7723
8111
  const executionId = new Uint8Array(16);
7724
8112
  crypto.getRandomValues(executionId);
8113
+ if (request.split_payloads) {
8114
+ if (config.onSplit) {
8115
+ await config.onSplit(request.split_payloads, {
8116
+ args: extractArgs(request.bind_call),
8117
+ bindCall: request.bind_call,
8118
+ settings: batchToScalarDict(request.bind_call.settings),
8119
+ secrets: batchToSecretDict(request.bind_call.secrets),
8120
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
8121
+ });
8122
+ }
8123
+ return {
8124
+ max_workers: config.maxWorkers ?? 1,
8125
+ execution_id: request.execution_id ?? executionId,
8126
+ opaque_data: null
8127
+ };
8128
+ }
7725
8129
  if (request.execution_id) {
7726
8130
  return {
7727
8131
  max_workers: config.maxWorkers ?? 1,
@@ -7763,6 +8167,7 @@ function defineTableFunction(config) {
7763
8167
  settings,
7764
8168
  secrets,
7765
8169
  pushdownFilters,
8170
+ splitPayloads: request.split_payloads ?? undefined,
7766
8171
  storage: boundStorage,
7767
8172
  atUnit: request.bind_call.at_unit ?? undefined,
7768
8173
  atValue: request.bind_call.at_value ?? undefined
@@ -7814,6 +8219,18 @@ function defineTableFunction(config) {
7814
8219
  resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
7815
8220
  });
7816
8221
  } : undefined,
8222
+ plan: config.plan ? (request) => {
8223
+ const args = extractArgs(request.bind_call);
8224
+ const settings = batchToScalarDict(request.bind_call.settings);
8225
+ const secrets = batchToSecretDict(request.bind_call.secrets);
8226
+ return config.plan({
8227
+ args,
8228
+ bindCall: request.bind_call,
8229
+ settings,
8230
+ secrets,
8231
+ resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false
8232
+ }, request);
8233
+ } : undefined,
7817
8234
  statistics: config.statistics ? (request) => {
7818
8235
  const args = extractArgs(request.bind_call);
7819
8236
  const settings = batchToScalarDict(request.bind_call.settings);
@@ -7845,6 +8262,7 @@ function defineTableFunction(config) {
7845
8262
  init_arrow();
7846
8263
  init_storage();
7847
8264
  function defineTableInOutFunction(config) {
8265
+ assertArrowTypes(config.args, `defineTableInOutFunction("${config.name}"): args`);
7848
8266
  const specs = [];
7849
8267
  let posIdx = 0;
7850
8268
  if (config.args) {
@@ -7893,8 +8311,7 @@ function defineTableInOutFunction(config) {
7893
8311
  continue;
7894
8312
  const defaultVal = config.argDefaults?.[spec.name] !== undefined ? config.argDefaults[spec.name] : undefined;
7895
8313
  let val = request.arguments.get(spec.position, defaultVal);
7896
- if (typeof val === "bigint")
7897
- val = Number(val);
8314
+ val = narrowArgValue(val);
7898
8315
  args[spec.name] = val;
7899
8316
  }
7900
8317
  return args;
@@ -8171,8 +8588,7 @@ function defineRowTransformFunction(config) {
8171
8588
  continue;
8172
8589
  const defaultVal = config.argDefaults?.[spec.name] !== undefined ? config.argDefaults[spec.name] : undefined;
8173
8590
  let val = request.arguments.get(spec.position, defaultVal ?? null);
8174
- if (typeof val === "bigint")
8175
- val = Number(val);
8591
+ val = narrowArgValue(val);
8176
8592
  args[spec.name] = val;
8177
8593
  }
8178
8594
  return args;
@@ -8680,6 +9096,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
8680
9096
  order_preservation: meta.preservesOrder,
8681
9097
  max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
8682
9098
  supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
9099
+ supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
9100
+ filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
9101
+ supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
9102
+ split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
8683
9103
  partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
8684
9104
  order_dependent: meta.orderDependent,
8685
9105
  distinct_dependent: meta.distinctDependent,
@@ -9030,17 +9450,7 @@ function inferScalarType(val) {
9030
9450
  function inlineScanFunction(func, args) {
9031
9451
  const argSchema = argumentSpecsToSchema(func.argumentSpecs);
9032
9452
  const argBytes = serializeArgsBatch(args ?? new Arguments, argSchema);
9033
- const scanSchema = schema2([
9034
- field2("function_name", utf82(), false),
9035
- field2("arguments", binary2(), false),
9036
- field2("required_extensions", list2(field2("item", utf82(), true)), false)
9037
- ]);
9038
- const batch = batchFromColumns({
9039
- function_name: [func.meta.name],
9040
- arguments: [argBytes],
9041
- required_extensions: [[]]
9042
- }, scanSchema);
9043
- return serializeBatch(batch);
9453
+ return encodeScanFunctionResult(func.meta.name, argBytes);
9044
9454
  }
9045
9455
  // src/catalog/composite.ts
9046
9456
  var ROUTE_BYTE = 0;
@@ -9447,118 +9857,118 @@ class FunctionRegistry {
9447
9857
  }
9448
9858
  // src/worker-cf-entry.ts
9449
9859
  init_arrow();
9450
- import { OutputCollector as OutputCollector2, AuthContext as AuthContext2 } from "@query-farm/vgi-rpc";
9860
+ import { OutputCollector as OutputCollector2, AuthContext as AuthContext3 } from "@query-farm/vgi-rpc";
9451
9861
  export {
9452
- utf82 as utf8,
9453
- union2 as union,
9454
- uint82 as uint8,
9455
- uint642 as uint64,
9456
- uint322 as uint32,
9457
- uint162 as uint16,
9458
- timestamp2 as timestamp,
9459
- timeSecond2 as timeSecond,
9460
- timeNanosecond2 as timeNanosecond,
9461
- timeMillisecond2 as timeMillisecond,
9462
- timeMicrosecond2 as timeMicrosecond,
9463
- time2 as time,
9464
- struct2 as struct,
9465
- sparseUnion2 as sparseUnion,
9466
- serializeSchema,
9467
- serializeColumnStatistics,
9468
- serializeBatch,
9469
- serializeAttachOptionSpecs,
9470
- serializeAttachOptionSpec,
9471
- schema2 as schema,
9472
- safeNumber,
9473
- projectSchema,
9474
- projectBatch,
9475
- parentRowsMetadata,
9476
- nullType2 as nullType,
9477
- map2 as map,
9478
- list2 as list,
9479
- iterRows,
9480
- isUtf8,
9481
- isUnion,
9482
- isTimestamp,
9483
- isTime,
9484
- isStruct,
9485
- isNull,
9486
- isMap,
9487
- isList,
9488
- isInterval,
9489
- isInt,
9490
- isFloat,
9491
- isFixedSizeList,
9492
- isFixedSizeBinary,
9493
- isDuration,
9494
- isDictionary,
9495
- isDecimal,
9496
- isDate,
9497
- isBool,
9498
- isBinary,
9499
- isBatch,
9500
- interval2 as interval,
9501
- int82 as int8,
9502
- int642 as int64,
9503
- int322 as int32,
9504
- int162 as int16,
9505
- int2 as int,
9506
- float642 as float64,
9507
- float322 as float32,
9508
- float162 as float16,
9509
- fixedSizeList2 as fixedSizeList,
9510
- fixedSizeBinary2 as fixedSizeBinary,
9511
- filterBatch,
9512
- field2 as field,
9513
- emptyBatch,
9514
- duration2 as duration,
9515
- dictionary2 as dictionary,
9516
- deserializeSchema,
9517
- deserializeBatch,
9518
- denseUnion2 as denseUnion,
9519
- defineTableInOutFunction,
9520
- defineTableFunction,
9521
- defineScalarFunction,
9522
- defineRowTransformFunction,
9523
- defineAggregate,
9524
- decodeDictValue,
9525
- decimal2562 as decimal256,
9526
- decimal1282 as decimal128,
9527
- decimal2 as decimal,
9528
- dateMillisecond2 as dateMillisecond,
9529
- dateDay2 as dateDay,
9530
- date2 as date,
9531
- createVgiFetch,
9532
- createLandingRoutes,
9533
- constraintSpecFields,
9534
- columnFromArray,
9535
- cacheControlMetadata,
9536
- buildStatisticsBatch,
9537
- bool2 as bool,
9538
- binary2 as binary,
9539
- batchToSecretDict,
9540
- batchToScalarDict,
9541
- batchFromRows,
9542
- batchFromColumns,
9543
- backend,
9544
- arrowStateSerializer,
9545
- UnionMode2 as UnionMode,
9546
- TypeId,
9547
- TimeUnit2 as TimeUnit,
9548
- ScanFunctionResultSchema,
9549
- ReadOnlyCatalogInterface,
9550
- PARENT_ROW_METADATA_KEY,
9551
- OutputCollector2 as OutputCollector,
9552
- IntervalUnit2 as IntervalUnit,
9553
- FunctionType,
9554
- FunctionRegistry,
9555
- EXCHANGE_STATE_SCHEMA,
9556
- DateUnit3 as DateUnit,
9557
- CompositeCatalogInterface,
9558
- CatalogInterface,
9862
+ Arguments,
9863
+ AuthContext3 as AuthContext,
9559
9864
  BindResultSchema,
9560
- AuthContext2 as AuthContext,
9561
- Arguments
9865
+ CatalogInterface,
9866
+ CompositeCatalogInterface,
9867
+ DateUnit3 as DateUnit,
9868
+ EXCHANGE_STATE_SCHEMA,
9869
+ FunctionRegistry,
9870
+ FunctionType,
9871
+ IntervalUnit2 as IntervalUnit,
9872
+ OutputCollector2 as OutputCollector,
9873
+ PARENT_ROW_METADATA_KEY,
9874
+ ReadOnlyCatalogInterface,
9875
+ ScanFunctionResultSchema,
9876
+ TimeUnit2 as TimeUnit,
9877
+ TypeId,
9878
+ UnionMode2 as UnionMode,
9879
+ arrowStateSerializer,
9880
+ backend,
9881
+ batchFromColumns,
9882
+ batchFromRows,
9883
+ batchToScalarDict,
9884
+ batchToSecretDict,
9885
+ binary2 as binary,
9886
+ bool2 as bool,
9887
+ buildStatisticsBatch,
9888
+ cacheControlMetadata,
9889
+ columnFromArray,
9890
+ constraintSpecFields,
9891
+ createLandingRoutes,
9892
+ createVgiFetch,
9893
+ date2 as date,
9894
+ dateDay2 as dateDay,
9895
+ dateMillisecond2 as dateMillisecond,
9896
+ decimal2 as decimal,
9897
+ decimal1282 as decimal128,
9898
+ decimal2562 as decimal256,
9899
+ decodeDictValue,
9900
+ defineAggregate,
9901
+ defineRowTransformFunction,
9902
+ defineScalarFunction,
9903
+ defineTableFunction,
9904
+ defineTableInOutFunction,
9905
+ denseUnion2 as denseUnion,
9906
+ deserializeBatch,
9907
+ deserializeSchema,
9908
+ dictionary2 as dictionary,
9909
+ duration2 as duration,
9910
+ emptyBatch,
9911
+ field2 as field,
9912
+ filterBatch,
9913
+ fixedSizeBinary2 as fixedSizeBinary,
9914
+ fixedSizeList2 as fixedSizeList,
9915
+ float162 as float16,
9916
+ float322 as float32,
9917
+ float642 as float64,
9918
+ int2 as int,
9919
+ int162 as int16,
9920
+ int322 as int32,
9921
+ int642 as int64,
9922
+ int82 as int8,
9923
+ interval2 as interval,
9924
+ isBatch,
9925
+ isBinary,
9926
+ isBool,
9927
+ isDate,
9928
+ isDecimal,
9929
+ isDictionary,
9930
+ isDuration,
9931
+ isFixedSizeBinary,
9932
+ isFixedSizeList,
9933
+ isFloat,
9934
+ isInt,
9935
+ isInterval,
9936
+ isList,
9937
+ isMap,
9938
+ isNull,
9939
+ isStruct,
9940
+ isTime,
9941
+ isTimestamp,
9942
+ isUnion,
9943
+ isUtf8,
9944
+ iterRows,
9945
+ list2 as list,
9946
+ map2 as map,
9947
+ nullType2 as nullType,
9948
+ parentRowsMetadata,
9949
+ projectBatch,
9950
+ projectSchema,
9951
+ safeNumber,
9952
+ schema2 as schema,
9953
+ serializeAttachOptionSpec,
9954
+ serializeAttachOptionSpecs,
9955
+ serializeBatch,
9956
+ serializeColumnStatistics,
9957
+ serializeSchema,
9958
+ sparseUnion2 as sparseUnion,
9959
+ struct2 as struct,
9960
+ time2 as time,
9961
+ timeMicrosecond2 as timeMicrosecond,
9962
+ timeMillisecond2 as timeMillisecond,
9963
+ timeNanosecond2 as timeNanosecond,
9964
+ timeSecond2 as timeSecond,
9965
+ timestamp2 as timestamp,
9966
+ uint162 as uint16,
9967
+ uint322 as uint32,
9968
+ uint642 as uint64,
9969
+ uint82 as uint8,
9970
+ union2 as union,
9971
+ utf82 as utf8
9562
9972
  };
9563
9973
 
9564
- //# debugId=A753E54332CCB1AB64756E2164756E21
9974
+ //# debugId=38EE66E6303DF6BF64756E2164756E21