@reifydb/core 0.9.0 → 0.9.2

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.
package/dist/index.js CHANGED
@@ -1,5 +1,21 @@
1
1
  // src/constant.ts
2
2
  var NONE_VALUE = "\u27EAnone\u27EB";
3
+ var NONE_MARKER_OPEN = NONE_VALUE.slice(0, -1);
4
+ var NONE_MARKER_CLOSE = NONE_VALUE.slice(-1);
5
+ function noneMarker(depth) {
6
+ return depth === 0 ? NONE_VALUE : `${NONE_MARKER_OPEN}:${depth}${NONE_MARKER_CLOSE}`;
7
+ }
8
+ function noneMarkerDepth(payload) {
9
+ if (payload === NONE_VALUE) {
10
+ return 0;
11
+ }
12
+ if (!payload.startsWith(`${NONE_MARKER_OPEN}:`) || !payload.endsWith(NONE_MARKER_CLOSE)) {
13
+ return void 0;
14
+ }
15
+ const digits = payload.slice(NONE_MARKER_OPEN.length + 1, -NONE_MARKER_CLOSE.length);
16
+ return /^[1-9][0-9]*$/.test(digits) ? Number(digits) : void 0;
17
+ }
18
+ var ROW_NUMBER_KEY = "#rownum";
3
19
 
4
20
  // src/value/blob.ts
5
21
  var BlobValue = class _BlobValue {
@@ -461,13 +477,13 @@ var DateValue = class _DateValue {
461
477
  * Helper to parse YYYY-MM-DD format
462
478
  */
463
479
  static parseDate(str) {
464
- const match = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})$/);
465
- if (!match) {
480
+ const match2 = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})$/);
481
+ if (!match2) {
466
482
  return null;
467
483
  }
468
- const year = parseInt(match[1], 10);
469
- const month = parseInt(match[2], 10);
470
- const day = parseInt(match[3], 10);
484
+ const year = parseInt(match2[1], 10);
485
+ const month = parseInt(match2[2], 10);
486
+ const day = parseInt(match2[3], 10);
471
487
  if (month < 1 || month > 12) {
472
488
  return null;
473
489
  }
@@ -669,16 +685,16 @@ var _TimeValue = class _TimeValue {
669
685
  * Helper to parse HH:MM:SS[.nnnnnnnnn] format
670
686
  */
671
687
  static parseTime(str) {
672
- const match = str.match(/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?$/);
673
- if (!match) {
688
+ const match2 = str.match(/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?$/);
689
+ if (!match2) {
674
690
  return null;
675
691
  }
676
- const hour = parseInt(match[1], 10);
677
- const minute = parseInt(match[2], 10);
678
- const second = parseInt(match[3], 10);
692
+ const hour = parseInt(match2[1], 10);
693
+ const minute = parseInt(match2[2], 10);
694
+ const second = parseInt(match2[3], 10);
679
695
  let nano = 0;
680
- if (match[4]) {
681
- const fracStr = match[4].padEnd(9, "0").substring(0, 9);
696
+ if (match2[4]) {
697
+ const fracStr = match2[4].padEnd(9, "0").substring(0, 9);
682
698
  nano = parseInt(fracStr, 10);
683
699
  }
684
700
  if (hour < 0 || hour > 23) {
@@ -877,7 +893,7 @@ var DateTimeValue = class _DateTimeValue {
877
893
  /**
878
894
  * Get Unix timestamp in seconds
879
895
  */
880
- to_epoch_secs() {
896
+ toEpochSecs() {
881
897
  const date = this.valueOf();
882
898
  if (date === void 0) return void 0;
883
899
  return Math.floor(date.getTime() / 1e3);
@@ -995,19 +1011,19 @@ var DateTimeValue = class _DateTimeValue {
995
1011
  * Helper to parse ISO 8601 datetime format
996
1012
  */
997
1013
  static parseDateTime(str) {
998
- const match = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?Z$/);
999
- if (!match) {
1014
+ const match2 = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?Z$/);
1015
+ if (!match2) {
1000
1016
  return null;
1001
1017
  }
1002
- const year = parseInt(match[1], 10);
1003
- const month = parseInt(match[2], 10);
1004
- const day = parseInt(match[3], 10);
1005
- const hour = parseInt(match[4], 10);
1006
- const minute = parseInt(match[5], 10);
1007
- const second = parseInt(match[6], 10);
1018
+ const year = parseInt(match2[1], 10);
1019
+ const month = parseInt(match2[2], 10);
1020
+ const day = parseInt(match2[3], 10);
1021
+ const hour = parseInt(match2[4], 10);
1022
+ const minute = parseInt(match2[5], 10);
1023
+ const second = parseInt(match2[6], 10);
1008
1024
  let nanosFraction = 0n;
1009
- if (match[7]) {
1010
- const fracStr = match[7].padEnd(9, "0").substring(0, 9);
1025
+ if (match2[7]) {
1026
+ const fracStr = match2[7].padEnd(9, "0").substring(0, 9);
1011
1027
  nanosFraction = BigInt(fracStr);
1012
1028
  }
1013
1029
  if (month < 1 || month > 12) {
@@ -1867,19 +1883,19 @@ var DurationValue = class _DurationValue {
1867
1883
  * Parse ISO 8601 duration format: P[n]Y[n]M[n]DT[n]H[n]M[n.n]S
1868
1884
  */
1869
1885
  static parseIsoDuration(str, negative) {
1870
- const match = str.match(/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/);
1871
- if (!match) {
1886
+ const match2 = str.match(/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/);
1887
+ if (!match2) {
1872
1888
  return null;
1873
1889
  }
1874
- if (!match[1] && !match[2] && !match[3] && !match[4] && !match[5] && !match[6]) {
1890
+ if (!match2[1] && !match2[2] && !match2[3] && !match2[4] && !match2[5] && !match2[6]) {
1875
1891
  return null;
1876
1892
  }
1877
- const years = parseInt(match[1] || "0", 10);
1878
- const months = parseInt(match[2] || "0", 10);
1879
- const days = parseInt(match[3] || "0", 10);
1880
- const hours = parseInt(match[4] || "0", 10);
1881
- const minutes = parseInt(match[5] || "0", 10);
1882
- const secondsStr = match[6] || "0";
1893
+ const years = parseInt(match2[1] || "0", 10);
1894
+ const months = parseInt(match2[2] || "0", 10);
1895
+ const days = parseInt(match2[3] || "0", 10);
1896
+ const hours = parseInt(match2[4] || "0", 10);
1897
+ const minutes = parseInt(match2[5] || "0", 10);
1898
+ const secondsStr = match2[6] || "0";
1883
1899
  const secondsParts = secondsStr.split(".");
1884
1900
  const wholeSeconds = parseInt(secondsParts[0] || "0", 10);
1885
1901
  let fracNanos = 0n;
@@ -1899,22 +1915,22 @@ var DurationValue = class _DurationValue {
1899
1915
  */
1900
1916
  static parseHumanDuration(str, negative) {
1901
1917
  const pattern = /^(?:(\d+)y)?(?:(\d+)mo)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m(?!s|o))?(?:(\d+)s(?!$)?)?(?:(\d+)ms)?(?:(\d+)us)?(?:(\d+)ns)?$/;
1902
- const match = str.match(pattern);
1903
- if (!match) {
1918
+ const match2 = str.match(pattern);
1919
+ if (!match2) {
1904
1920
  return null;
1905
1921
  }
1906
- if (!match[1] && !match[2] && !match[3] && !match[4] && !match[5] && !match[6] && !match[7] && !match[8] && !match[9]) {
1922
+ if (!match2[1] && !match2[2] && !match2[3] && !match2[4] && !match2[5] && !match2[6] && !match2[7] && !match2[8] && !match2[9]) {
1907
1923
  return null;
1908
1924
  }
1909
- const years = parseInt(match[1] || "0", 10);
1910
- const months = parseInt(match[2] || "0", 10);
1911
- const days = parseInt(match[3] || "0", 10);
1912
- const hours = parseInt(match[4] || "0", 10);
1913
- const minutes = parseInt(match[5] || "0", 10);
1914
- const seconds = parseInt(match[6] || "0", 10);
1915
- const ms = parseInt(match[7] || "0", 10);
1916
- const us = parseInt(match[8] || "0", 10);
1917
- const ns = parseInt(match[9] || "0", 10);
1925
+ const years = parseInt(match2[1] || "0", 10);
1926
+ const months = parseInt(match2[2] || "0", 10);
1927
+ const days = parseInt(match2[3] || "0", 10);
1928
+ const hours = parseInt(match2[4] || "0", 10);
1929
+ const minutes = parseInt(match2[5] || "0", 10);
1930
+ const seconds = parseInt(match2[6] || "0", 10);
1931
+ const ms = parseInt(match2[7] || "0", 10);
1932
+ const us = parseInt(match2[8] || "0", 10);
1933
+ const ns = parseInt(match2[9] || "0", 10);
1918
1934
  const totalNanos = BigInt(hours) * 3600n * 1000000000n + BigInt(minutes) * 60n * 1000000000n + BigInt(seconds) * 1000000000n + BigInt(ms) * 1000000n + BigInt(us) * 1000n + BigInt(ns);
1919
1935
  const totalMonths = years * 12 + months;
1920
1936
  if (negative) {
@@ -2285,11 +2301,151 @@ var NoneValue = class _NoneValue {
2285
2301
  }
2286
2302
  encode() {
2287
2303
  return {
2288
- type: "None",
2304
+ type: { Option: this.innerType },
2289
2305
  value: NONE_VALUE
2290
2306
  };
2291
2307
  }
2292
2308
  };
2309
+ function noneDepth(v) {
2310
+ return optionDepth(v.innerType) + 1;
2311
+ }
2312
+
2313
+ // src/present/value.ts
2314
+ var NONE_PRESENTATION = {
2315
+ text: "none",
2316
+ italic: true,
2317
+ muted: true
2318
+ };
2319
+ var ROLE_BY_TYPE = {
2320
+ None: "none",
2321
+ Boolean: "boolean",
2322
+ Int1: "number",
2323
+ Int2: "number",
2324
+ Int4: "number",
2325
+ Int8: "number",
2326
+ Int16: "number",
2327
+ Uint1: "number",
2328
+ Uint2: "number",
2329
+ Uint4: "number",
2330
+ Uint8: "number",
2331
+ Uint16: "number",
2332
+ Float4: "number",
2333
+ Float8: "number",
2334
+ Decimal: "number",
2335
+ Date: "temporal",
2336
+ DateTime: "temporal",
2337
+ Time: "temporal",
2338
+ Duration: "temporal",
2339
+ Uuid4: "uuid",
2340
+ Uuid7: "uuid",
2341
+ IdentityId: "uuid",
2342
+ Utf8: "string",
2343
+ Blob: "blob"
2344
+ };
2345
+ function typeName(value) {
2346
+ if (value === null || typeof value !== "object") return void 0;
2347
+ const candidate = value.type;
2348
+ return typeof candidate === "string" ? candidate : void 0;
2349
+ }
2350
+ function valueTypeName(value) {
2351
+ if (value === null || value === void 0) return "None";
2352
+ return typeName(value);
2353
+ }
2354
+ function valueRole(value) {
2355
+ if (value === null || value === void 0) return "none";
2356
+ const name = typeName(value);
2357
+ if (name !== void 0) {
2358
+ return ROLE_BY_TYPE[name] ?? "unknown";
2359
+ }
2360
+ switch (typeof value) {
2361
+ case "number":
2362
+ case "bigint":
2363
+ return "number";
2364
+ case "boolean":
2365
+ return "boolean";
2366
+ case "string":
2367
+ return "string";
2368
+ default:
2369
+ return "unknown";
2370
+ }
2371
+ }
2372
+ function formatValue(value) {
2373
+ if (value === null || value === void 0) return NONE_PRESENTATION.text;
2374
+ if (typeof value === "bigint") return value.toString();
2375
+ if (typeof value === "object") {
2376
+ const name = typeName(value);
2377
+ if (name === "None") return NONE_PRESENTATION.text;
2378
+ if (name !== void 0) return String(value);
2379
+ return JSON.stringify(value) ?? String(value);
2380
+ }
2381
+ return String(value);
2382
+ }
2383
+
2384
+ // src/value/option.ts
2385
+ function describeType(t) {
2386
+ return isOptionType(t) ? `Option(${describeType(t.Option)})` : t;
2387
+ }
2388
+ function hasType(value) {
2389
+ return typeof value === "object" && value !== null && "type" in value;
2390
+ }
2391
+ function hasToJSON(value) {
2392
+ return typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function";
2393
+ }
2394
+ var OPTION_BRAND = /* @__PURE__ */ Symbol.for("reifydb.option");
2395
+ function isOption(value) {
2396
+ return typeof value === "object" && value !== null && value[OPTION_BRAND] === true;
2397
+ }
2398
+ var _a;
2399
+ _a = OPTION_BRAND;
2400
+ var _Option = class _Option {
2401
+ constructor(state) {
2402
+ this.state = state;
2403
+ this[_a] = true;
2404
+ }
2405
+ static some(value) {
2406
+ return new _Option({ some: true, value });
2407
+ }
2408
+ static none(inner) {
2409
+ return new _Option({ some: false, inner });
2410
+ }
2411
+ isSome() {
2412
+ return this.state.some;
2413
+ }
2414
+ isNone() {
2415
+ return !this.state.some;
2416
+ }
2417
+ unwrap() {
2418
+ if (this.state.some) {
2419
+ return this.state.value;
2420
+ }
2421
+ throw new Error(`unwrap on a None of type ${describeType(this.state.inner)}`);
2422
+ }
2423
+ unwrapOr(fallback) {
2424
+ return this.state.some ? this.state.value : fallback;
2425
+ }
2426
+ map(fn) {
2427
+ return this.state.some ? _Option.some(fn(this.state.value)) : _Option.none(this.state.inner);
2428
+ }
2429
+ get type() {
2430
+ if (!this.state.some) {
2431
+ return { Option: this.state.inner };
2432
+ }
2433
+ if (hasType(this.state.value)) {
2434
+ return { Option: this.state.value.type };
2435
+ }
2436
+ throw new Error(`Option.some over a raw ${typeof this.state.value} has no wire type`);
2437
+ }
2438
+ toString() {
2439
+ return this.state.some ? String(this.state.value) : NONE_PRESENTATION.text;
2440
+ }
2441
+ toJSON() {
2442
+ if (!this.state.some) {
2443
+ return null;
2444
+ }
2445
+ return hasToJSON(this.state.value) ? this.state.value.toJSON() : this.state.value;
2446
+ }
2447
+ };
2448
+ var Option = _Option;
2293
2449
 
2294
2450
  // src/value/utf8.ts
2295
2451
  var Utf8Value = class _Utf8Value {
@@ -2745,6 +2901,49 @@ var IdentityIdValue = class _IdentityIdValue {
2745
2901
  }
2746
2902
  };
2747
2903
 
2904
+ // src/value/wire-type.ts
2905
+ function typeToWire(type) {
2906
+ return isOptionType(type) ? { id: "Option", underlying: typeToWire(type.Option) } : { id: type };
2907
+ }
2908
+ function typeFromWire(wire) {
2909
+ if (!wire || typeof wire !== "object" || typeof wire.id !== "string") {
2910
+ throw new Error(`Expected a type descriptor object, got ${JSON.stringify(wire)}`);
2911
+ }
2912
+ if (wire.id === "Option") {
2913
+ if (!wire.underlying) {
2914
+ throw new Error("Option type descriptor is missing its underlying type");
2915
+ }
2916
+ return { Option: typeFromWire(wire.underlying) };
2917
+ }
2918
+ return wire.id;
2919
+ }
2920
+ function columnsFromWire(columns) {
2921
+ return columns.map((column) => ({ ...column, type: typeFromWire(column.type) }));
2922
+ }
2923
+ function framesFromWire(frames) {
2924
+ return frames.map(
2925
+ (frame) => frame && frame.columns ? { ...frame, columns: columnsFromWire(frame.columns) } : frame
2926
+ );
2927
+ }
2928
+ function envelopeToColumns(envelope) {
2929
+ const types = envelope?.types ?? {};
2930
+ const rows = envelope?.rows ?? [];
2931
+ return Object.keys(types).map((name) => ({
2932
+ name,
2933
+ type: typeFromWire(types[name]),
2934
+ payload: rows.map((row) => payloadOf(row?.[name]))
2935
+ }));
2936
+ }
2937
+ function envelopesToFrames(envelopes) {
2938
+ return Array.isArray(envelopes) ? envelopes.map((envelope) => ({ columns: envelopeToColumns(envelope) })) : [];
2939
+ }
2940
+ function payloadOf(value) {
2941
+ if (value === null || value === void 0) {
2942
+ return NONE_VALUE;
2943
+ }
2944
+ return typeof value === "string" ? value : String(value);
2945
+ }
2946
+
2748
2947
  // src/value/index.ts
2749
2948
  function isOptionType(t) {
2750
2949
  return typeof t === "object" && t !== null && "Option" in t;
@@ -2753,17 +2952,30 @@ function unwrapOptionType(t) {
2753
2952
  if (isOptionType(t)) return unwrapOptionType(t.Option);
2754
2953
  return t;
2755
2954
  }
2756
- var Value = class {
2955
+ function optionDepth(t) {
2956
+ return isOptionType(t) ? optionDepth(t.Option) + 1 : 0;
2957
+ }
2958
+ function innerOfOption(t) {
2959
+ return t.Option;
2960
+ }
2961
+ var Value2 = class {
2757
2962
  };
2758
2963
 
2759
2964
  // src/decoder.ts
2965
+ function stripOptionLayers(type, layers) {
2966
+ return layers === 0 || !isOptionType(type) ? type : stripOptionLayers(innerOfOption(type), layers - 1);
2967
+ }
2760
2968
  function decode(pair) {
2761
2969
  if (isOptionType(pair.type)) {
2762
- const innerType = unwrapOptionType(pair.type);
2763
- if (pair.value === NONE_VALUE || pair.value === "") {
2764
- return new NoneValue(innerType);
2970
+ const noneAt = noneMarkerDepth(pair.value);
2971
+ if (noneAt === void 0) {
2972
+ return decode({ type: unwrapOptionType(pair.type), value: pair.value });
2973
+ }
2974
+ const depth = optionDepth(pair.type);
2975
+ if (noneAt >= depth) {
2976
+ throw new Error(`none under ${noneAt} Some layers cannot fit an option of depth ${depth}`);
2765
2977
  }
2766
- return decode({ type: innerType, value: pair.value });
2978
+ return new NoneValue(stripOptionLayers(pair.type, noneAt + 1));
2767
2979
  }
2768
2980
  switch (pair.type) {
2769
2981
  case "Blob":
@@ -2818,6 +3030,121 @@ function decode(pair) {
2818
3030
  throw new Error(`Unsupported type: ${pair.type}`);
2819
3031
  }
2820
3032
  }
3033
+ function columnsToRows(columns) {
3034
+ const rowCount = columns[0]?.payload.length ?? 0;
3035
+ return Array.from({ length: rowCount }, (_, i) => {
3036
+ const row = {};
3037
+ for (const col of columns) {
3038
+ row[col.name] = decode({ type: col.type, value: col.payload[i] });
3039
+ }
3040
+ return row;
3041
+ });
3042
+ }
3043
+
3044
+ // src/encoder.ts
3045
+ function encodeValue(value, name = "$1") {
3046
+ if (value === null || value === void 0) {
3047
+ throw new Error(`parameter ${name} is null or undefined, use Option.none(inner)`);
3048
+ }
3049
+ if (value instanceof NoneValue && value.innerType === "None") {
3050
+ throw new Error(`parameter ${name} is a NoneValue without an inner type, use Option.none(inner)`);
3051
+ }
3052
+ if (isOption(value)) {
3053
+ if (value.isNone()) {
3054
+ return { type: value.type, value: NONE_VALUE };
3055
+ }
3056
+ const inner = encodeValue(value.unwrap(), name);
3057
+ const noneAt = noneMarkerDepth(inner.value);
3058
+ return {
3059
+ type: { Option: inner.type },
3060
+ value: noneAt === void 0 ? inner.value : noneMarker(noneAt + 1)
3061
+ };
3062
+ }
3063
+ if (value && typeof value === "object" && "encode" in value && typeof value.encode === "function") {
3064
+ return value.encode();
3065
+ }
3066
+ if (typeof value === "boolean") {
3067
+ return { type: "Boolean", value: value.toString() };
3068
+ }
3069
+ if (typeof value === "number") {
3070
+ if (Number.isInteger(value)) {
3071
+ if (value >= -128 && value <= 127) {
3072
+ return { type: "Int1", value: value.toString() };
3073
+ } else if (value >= -32768 && value <= 32767) {
3074
+ return { type: "Int2", value: value.toString() };
3075
+ } else if (value >= -2147483648 && value <= 2147483647) {
3076
+ return { type: "Int4", value: value.toString() };
3077
+ } else {
3078
+ return { type: "Int8", value: value.toString() };
3079
+ }
3080
+ } else {
3081
+ return { type: "Float8", value: value.toString() };
3082
+ }
3083
+ }
3084
+ if (typeof value === "string") {
3085
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[47][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {
3086
+ const version4 = value[14];
3087
+ if (version4 === "4") {
3088
+ return { type: "Uuid4", value };
3089
+ } else if (version4 === "7") {
3090
+ return { type: "Uuid7", value };
3091
+ }
3092
+ }
3093
+ return { type: "Utf8", value };
3094
+ }
3095
+ if (typeof value === "bigint") {
3096
+ if (value >= BigInt(0)) {
3097
+ if (value <= BigInt(255)) {
3098
+ return { type: "Uint1", value: value.toString() };
3099
+ } else if (value <= BigInt(65535)) {
3100
+ return { type: "Uint2", value: value.toString() };
3101
+ } else if (value <= BigInt(4294967295)) {
3102
+ return { type: "Uint4", value: value.toString() };
3103
+ } else if (value <= BigInt("18446744073709551615")) {
3104
+ return { type: "Uint8", value: value.toString() };
3105
+ } else {
3106
+ return { type: "Uint16", value: value.toString() };
3107
+ }
3108
+ } else {
3109
+ if (value >= BigInt("-9223372036854775808")) {
3110
+ return { type: "Int8", value: value.toString() };
3111
+ } else {
3112
+ return { type: "Int16", value: value.toString() };
3113
+ }
3114
+ }
3115
+ }
3116
+ if (value instanceof Date) {
3117
+ return { type: "DateTime", value: value.toISOString() };
3118
+ }
3119
+ if (value instanceof Uint8Array) {
3120
+ const hex = Array.from(value).map((b) => b.toString(16).padStart(2, "0")).join("");
3121
+ return { type: "Blob", value: "0x" + hex };
3122
+ }
3123
+ if (value instanceof ArrayBuffer) {
3124
+ const uint8Array = new Uint8Array(value);
3125
+ const hex = Array.from(uint8Array).map((b) => b.toString(16).padStart(2, "0")).join("");
3126
+ return { type: "Blob", value: "0x" + hex };
3127
+ }
3128
+ throw new Error(`Cannot encode value of type ${typeof value}: ${value}`);
3129
+ }
3130
+ function toWire(pair) {
3131
+ return { type: typeToWire(pair.type), value: pair.value };
3132
+ }
3133
+ function encodeParams(params) {
3134
+ if (params === void 0 || params === null) {
3135
+ return [];
3136
+ }
3137
+ if (Array.isArray(params)) {
3138
+ return params.map((param, i) => toWire(encodeValue(param, `$${i + 1}`)));
3139
+ } else if (typeof params === "object") {
3140
+ const encoded = {};
3141
+ for (const [key, value] of Object.entries(params)) {
3142
+ encoded[key] = toWire(encodeValue(value, `$${key}`));
3143
+ }
3144
+ return encoded;
3145
+ }
3146
+ throw new Error(`Invalid parameters type: expected array or object, got ${typeof params}`);
3147
+ }
2821
3148
 
2822
3149
  // src/type-code.ts
2823
3150
  var TYPE_CODE = {
@@ -2857,7 +3184,7 @@ var TYPE_CODE = {
2857
3184
  var CODE_TO_NAME = Object.fromEntries(
2858
3185
  Object.entries(TYPE_CODE).map(([k, v]) => [v, k])
2859
3186
  );
2860
- function type_name_from_code(code) {
3187
+ function typeNameFromCode(code) {
2861
3188
  const name = CODE_TO_NAME[code];
2862
3189
  if (!name) throw new Error(`Unknown type code: ${code}`);
2863
3190
  return name;
@@ -2964,8 +3291,8 @@ var ShapeBuilder = class {
2964
3291
  static array(items) {
2965
3292
  return { kind: "array", items };
2966
3293
  }
2967
- static optional(shape) {
2968
- return { kind: "optional", shape };
3294
+ static option(inner) {
3295
+ return { kind: "option", inner };
2969
3296
  }
2970
3297
  static number() {
2971
3298
  return { kind: "primitive", type: "Float8" };
@@ -3123,11 +3450,14 @@ function parseValue(shape, value) {
3123
3450
  }
3124
3451
  return value.map((item) => parseValue(shape.items, item));
3125
3452
  }
3126
- if (shape.kind === "optional") {
3127
- if (value === void 0) {
3453
+ if (shape.kind === "option") {
3454
+ if (value === null || value === void 0) {
3128
3455
  return void 0;
3129
3456
  }
3130
- return parseValue(shape.shape, value);
3457
+ if (isOption(value)) {
3458
+ return value.map((item) => parseValue(shape.inner, item));
3459
+ }
3460
+ return Option.some(parseValue(shape.inner, value));
3131
3461
  }
3132
3462
  if (shape.kind === "value") {
3133
3463
  if (value === null || value === void 0) {
@@ -3141,11 +3471,11 @@ function parseValue(shape, value) {
3141
3471
  // src/shape/validator.ts
3142
3472
  function validateShape(shape, value) {
3143
3473
  if (shape.kind === "primitive") {
3144
- const object_type = shape.type;
3474
+ const objectType = shape.type;
3145
3475
  if (value === null || value === void 0) {
3146
- return object_type === "None";
3476
+ return objectType === "None";
3147
3477
  }
3148
- switch (object_type) {
3478
+ switch (objectType) {
3149
3479
  case "Boolean":
3150
3480
  return typeof value === "boolean";
3151
3481
  case "Float4":
@@ -3197,11 +3527,11 @@ function validateShape(shape, value) {
3197
3527
  }
3198
3528
  return value.every((item) => validateShape(shape.items, item));
3199
3529
  }
3200
- if (shape.kind === "optional") {
3201
- if (value === void 0) {
3202
- return true;
3530
+ if (shape.kind === "option") {
3531
+ if (!isOption(value)) {
3532
+ return false;
3203
3533
  }
3204
- return validateShape(shape.shape, value);
3534
+ return value.isNone() || validateShape(shape.inner, value.unwrap());
3205
3535
  }
3206
3536
  if (shape.kind === "value") {
3207
3537
  if (value === null || value === void 0) {
@@ -3215,6 +3545,752 @@ function validateShape(shape, value) {
3215
3545
  return false;
3216
3546
  }
3217
3547
 
3548
+ // src/shape/widen.ts
3549
+ var NUMERIC = {
3550
+ Int1: { kind: "int", bits: 8 },
3551
+ Int2: { kind: "int", bits: 16 },
3552
+ Int4: { kind: "int", bits: 32 },
3553
+ Int8: { kind: "int", bits: 64 },
3554
+ Int16: { kind: "int", bits: 128 },
3555
+ Uint1: { kind: "uint", bits: 8 },
3556
+ Uint2: { kind: "uint", bits: 16 },
3557
+ Uint4: { kind: "uint", bits: 32 },
3558
+ Uint8: { kind: "uint", bits: 64 },
3559
+ Uint16: { kind: "uint", bits: 128 },
3560
+ Float4: { kind: "float", bits: 32 },
3561
+ Float8: { kind: "float", bits: 64 }
3562
+ };
3563
+ function widens(target, actual) {
3564
+ if (isOptionType(actual)) {
3565
+ return false;
3566
+ }
3567
+ const t = NUMERIC[target];
3568
+ const a = NUMERIC[actual];
3569
+ if (!t || !a) {
3570
+ return target === actual;
3571
+ }
3572
+ if (t.kind === "float" || a.kind === "float") {
3573
+ return t.kind === "float" && a.kind === "float" && t.bits >= a.bits;
3574
+ }
3575
+ if (t.kind === "uint") {
3576
+ return a.kind === "uint" && t.bits >= a.bits;
3577
+ }
3578
+ return a.kind === "int" ? t.bits >= a.bits : t.bits > a.bits;
3579
+ }
3580
+ function widen(value, target) {
3581
+ if (!value || typeof value !== "object" || typeof value.type !== "string") {
3582
+ return value;
3583
+ }
3584
+ const actual = value.type;
3585
+ if (actual === target || !widens(target, actual)) {
3586
+ return value;
3587
+ }
3588
+ const inner = value.value;
3589
+ if (inner === void 0 || inner === null) {
3590
+ return value;
3591
+ }
3592
+ return decode({ type: target, value: String(inner) });
3593
+ }
3594
+
3595
+ // src/shape/check.ts
3596
+ var ShapeMismatch = class extends Error {
3597
+ constructor(message) {
3598
+ super(message);
3599
+ this.name = "ShapeMismatch";
3600
+ Object.setPrototypeOf(this, new.target.prototype);
3601
+ }
3602
+ };
3603
+ function checkFrames(frames, shapes) {
3604
+ if (shapes.length === 0) {
3605
+ return;
3606
+ }
3607
+ if (frames.length !== shapes.length) {
3608
+ throw new ShapeMismatch(`expected ${shapes.length} frames for ${shapes.length} shapes, got ${frames.length}`);
3609
+ }
3610
+ frames.forEach((frame, i) => checkFrame(frame.columns, shapes[i]));
3611
+ }
3612
+ function checkFrame(columns, shape) {
3613
+ if (shape.kind !== "object") {
3614
+ throw new ShapeMismatch(`a frame needs an object shape, got ${shape.kind}`);
3615
+ }
3616
+ for (const [name, propertyShape] of Object.entries(shape.properties)) {
3617
+ const column = columns.find((c) => c.name === name);
3618
+ if (!column) {
3619
+ throw new ShapeMismatch(`column "${name}": expected ${describe(propertyShape)}, missing from frame`);
3620
+ }
3621
+ if (!matches(propertyShape, column.type)) {
3622
+ throw new ShapeMismatch(`column "${name}": expected ${describe(propertyShape)}, got ${typeName2(column.type)}`);
3623
+ }
3624
+ }
3625
+ }
3626
+ var FAMILIES = [
3627
+ ["Boolean"],
3628
+ ["Int1", "Int2", "Int4", "Int8", "Int16", "Uint1", "Uint2", "Uint4", "Uint8", "Uint16", "Float4", "Float8"],
3629
+ ["Utf8", "Decimal", "Duration", "Uuid4", "Uuid7", "IdentityId"],
3630
+ ["Date", "DateTime", "Time"],
3631
+ ["Blob"],
3632
+ ["None"]
3633
+ ];
3634
+ function familyOf(type) {
3635
+ return FAMILIES.find((family) => family.includes(type)) ?? [type];
3636
+ }
3637
+ function matches(shape, type) {
3638
+ switch (shape.kind) {
3639
+ case "primitive":
3640
+ if (shape.type === "None") {
3641
+ return type === "None" || isOptionType(type);
3642
+ }
3643
+ return !isOptionType(type) && familyOf(shape.type).includes(type);
3644
+ case "value":
3645
+ if (shape.type === "None") {
3646
+ return type === "None" || isOptionType(type);
3647
+ }
3648
+ return type === shape.type || widens(shape.type, type);
3649
+ case "option":
3650
+ return isOptionType(type) && matches(shape.inner, type.Option);
3651
+ case "object":
3652
+ case "array":
3653
+ return false;
3654
+ }
3655
+ }
3656
+ function describe(shape) {
3657
+ switch (shape.kind) {
3658
+ case "primitive":
3659
+ case "value":
3660
+ return shape.type;
3661
+ case "option":
3662
+ return `Option(${describe(shape.inner)})`;
3663
+ case "object":
3664
+ case "array":
3665
+ return shape.kind;
3666
+ }
3667
+ }
3668
+ function typeName2(type) {
3669
+ return isOptionType(type) ? `Option(${typeName2(type.Option)})` : type;
3670
+ }
3671
+
3672
+ // src/shape/transform.ts
3673
+ function snakeToCamel(key) {
3674
+ return key.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
3675
+ }
3676
+ function transformFrames(frames, shapes) {
3677
+ const transformed = frames.map((frame, frameIndex) => {
3678
+ const frameShape = shapes[frameIndex];
3679
+ if (!frameShape) {
3680
+ return frame;
3681
+ }
3682
+ return frame.map((row) => transformResult(row, frameShape));
3683
+ });
3684
+ return transformed;
3685
+ }
3686
+ function transformResult(row, resultShape) {
3687
+ if (resultShape && resultShape.kind === "object" && resultShape.properties) {
3688
+ const transformedRow = {};
3689
+ for (const [key, value] of Object.entries(row)) {
3690
+ const propertyShape = resultShape.properties[key];
3691
+ const outputKey = snakeToCamel(key);
3692
+ if (propertyShape && propertyShape.kind === "primitive") {
3693
+ if (value && typeof value === "object" && typeof value.valueOf === "function") {
3694
+ const rawValue = value.valueOf();
3695
+ transformedRow[outputKey] = coerceToPrimitiveType(rawValue, propertyShape.type);
3696
+ } else {
3697
+ transformedRow[outputKey] = coerceToPrimitiveType(value, propertyShape.type);
3698
+ }
3699
+ } else if (propertyShape && propertyShape.kind === "value") {
3700
+ transformedRow[outputKey] = widen(value, propertyShape.type);
3701
+ } else {
3702
+ transformedRow[outputKey] = propertyShape ? transformResult(value, propertyShape) : value;
3703
+ }
3704
+ }
3705
+ return transformedRow;
3706
+ }
3707
+ if (resultShape && resultShape.kind === "primitive") {
3708
+ if (row && typeof row === "object" && typeof row.valueOf === "function") {
3709
+ return coerceToPrimitiveType(row.valueOf(), resultShape.type);
3710
+ }
3711
+ return coerceToPrimitiveType(row, resultShape.type);
3712
+ }
3713
+ if (resultShape && resultShape.kind === "value") {
3714
+ return widen(row, resultShape.type);
3715
+ }
3716
+ if (resultShape && resultShape.kind === "array") {
3717
+ if (Array.isArray(row)) {
3718
+ return row.map((item) => transformResult(item, resultShape.items));
3719
+ }
3720
+ return row;
3721
+ }
3722
+ if (resultShape && resultShape.kind === "option") {
3723
+ if (row instanceof NoneValue) {
3724
+ const remaining = optionLayers(resultShape);
3725
+ const depth = noneDepth(row);
3726
+ if (depth > remaining) {
3727
+ throw new ShapeMismatch(`a none ${depth} layers deep does not fit a shape with ${remaining} option layers`);
3728
+ }
3729
+ if (depth === remaining) {
3730
+ return Option.none(row.innerType);
3731
+ }
3732
+ }
3733
+ return Option.some(transformResult(row, resultShape.inner));
3734
+ }
3735
+ return row;
3736
+ }
3737
+ function optionLayers(shape) {
3738
+ return shape.kind === "option" ? optionLayers(shape.inner) + 1 : 0;
3739
+ }
3740
+ function coerceToPrimitiveType(value, valueType) {
3741
+ if (value === void 0 || value === null) {
3742
+ return value;
3743
+ }
3744
+ const bigintTypes = ["Int8", "Int16", "Uint8", "Uint16"];
3745
+ if (bigintTypes.includes(valueType)) {
3746
+ if (typeof value === "bigint") {
3747
+ return value;
3748
+ }
3749
+ if (typeof value === "number") {
3750
+ return BigInt(Math.trunc(value));
3751
+ }
3752
+ if (typeof value === "string") {
3753
+ return BigInt(value);
3754
+ }
3755
+ }
3756
+ return value;
3757
+ }
3758
+
3759
+ // src/present/width.ts
3760
+ var ZERO_WIDTH = [
3761
+ [768, 879],
3762
+ [1155, 1161],
3763
+ [1425, 1469],
3764
+ [1552, 1562],
3765
+ [1611, 1631],
3766
+ [3633, 3633],
3767
+ [3636, 3642],
3768
+ [3761, 3761],
3769
+ [3764, 3769],
3770
+ [8203, 8207],
3771
+ [8400, 8447],
3772
+ [65024, 65039],
3773
+ [65056, 65071],
3774
+ [65279, 65279]
3775
+ ];
3776
+ var WIDE = [
3777
+ [4352, 4447],
3778
+ [9001, 9002],
3779
+ [11904, 12350],
3780
+ [12353, 13311],
3781
+ [13312, 19903],
3782
+ [19968, 40959],
3783
+ [40960, 42191],
3784
+ [43360, 43391],
3785
+ [44032, 55203],
3786
+ [63744, 64255],
3787
+ [65040, 65049],
3788
+ [65072, 65135],
3789
+ [65280, 65376],
3790
+ [65504, 65510],
3791
+ [127744, 129535],
3792
+ [129648, 129791],
3793
+ [131072, 262141]
3794
+ ];
3795
+ function inRanges(code, ranges) {
3796
+ let low = 0;
3797
+ let high = ranges.length - 1;
3798
+ while (low <= high) {
3799
+ const middle = low + high >> 1;
3800
+ const [start, end] = ranges[middle];
3801
+ if (code < start) high = middle - 1;
3802
+ else if (code > end) low = middle + 1;
3803
+ else return true;
3804
+ }
3805
+ return false;
3806
+ }
3807
+ function codePointWidth(code) {
3808
+ if (code === 0) return 0;
3809
+ if (code < 32 || code >= 127 && code < 160) return 0;
3810
+ if (inRanges(code, ZERO_WIDTH)) return 0;
3811
+ if (inRanges(code, WIDE)) return 2;
3812
+ return 1;
3813
+ }
3814
+ function createSegmenter() {
3815
+ if (typeof Intl === "undefined") return null;
3816
+ const factory = Intl.Segmenter;
3817
+ if (typeof factory !== "function") return null;
3818
+ return new factory(void 0, { granularity: "grapheme" });
3819
+ }
3820
+ var segmenter = createSegmenter();
3821
+ function graphemes(text) {
3822
+ if (segmenter !== null) {
3823
+ return Array.from(segmenter.segment(text), (entry) => entry.segment);
3824
+ }
3825
+ return Array.from(text);
3826
+ }
3827
+ function graphemeWidth(grapheme) {
3828
+ let width = 0;
3829
+ for (const character of grapheme) {
3830
+ width += codePointWidth(character.codePointAt(0) ?? 0);
3831
+ }
3832
+ return Math.min(width, 2);
3833
+ }
3834
+ function displayWidth(text) {
3835
+ let width = 0;
3836
+ for (const grapheme of graphemes(text)) {
3837
+ width += graphemeWidth(grapheme);
3838
+ }
3839
+ return width;
3840
+ }
3841
+ function truncateToWidth(text, width, ellipsis = "\u2026") {
3842
+ if (width <= 0) return "";
3843
+ if (displayWidth(text) <= width) return text;
3844
+ const markerWidth = displayWidth(ellipsis);
3845
+ if (width <= markerWidth) return ellipsis.slice(0, width);
3846
+ const budget = width - markerWidth;
3847
+ let used = 0;
3848
+ let result = "";
3849
+ for (const grapheme of graphemes(text)) {
3850
+ const next = graphemeWidth(grapheme);
3851
+ if (used + next > budget) break;
3852
+ result += grapheme;
3853
+ used += next;
3854
+ }
3855
+ return result + ellipsis;
3856
+ }
3857
+ function padToWidth(text, width, align) {
3858
+ const padding = width - displayWidth(text);
3859
+ if (padding <= 0) return text;
3860
+ if (align === "right") return " ".repeat(padding) + text;
3861
+ if (align === "left") return text + " ".repeat(padding);
3862
+ const left = Math.floor(padding / 2);
3863
+ return " ".repeat(left) + text + " ".repeat(padding - left);
3864
+ }
3865
+
3866
+ // src/present/table.ts
3867
+ var DEFAULT_MAX_COLUMN_WIDTH = 40;
3868
+ var DEFAULT_COLUMN_OVERHEAD = 3;
3869
+ var DEFAULT_TABLE_OVERHEAD = 1;
3870
+ function inferColumns(rows) {
3871
+ const names = [];
3872
+ const seen = /* @__PURE__ */ new Set();
3873
+ for (const row of rows) {
3874
+ for (const name of Object.keys(row)) {
3875
+ if (seen.has(name)) continue;
3876
+ seen.add(name);
3877
+ names.push(name);
3878
+ }
3879
+ }
3880
+ return names.map((name) => {
3881
+ let role = "unknown";
3882
+ let type;
3883
+ for (const row of rows) {
3884
+ const value = row[name];
3885
+ const candidate = valueRole(value);
3886
+ if (candidate === "none" || candidate === "unknown") continue;
3887
+ role = candidate;
3888
+ type = valueTypeName(value);
3889
+ break;
3890
+ }
3891
+ return { name, type, role, align: role === "number" ? "right" : "left" };
3892
+ });
3893
+ }
3894
+ function planTable(rows, columns, options = {}) {
3895
+ const maxColumnWidth = options.maxColumnWidth ?? DEFAULT_MAX_COLUMN_WIDTH;
3896
+ const columnOverhead = options.columnOverhead ?? DEFAULT_COLUMN_OVERHEAD;
3897
+ const tableOverhead = options.tableOverhead ?? DEFAULT_TABLE_OVERHEAD;
3898
+ const sample = options.sample ?? rows.length;
3899
+ const measured = rows.slice(0, Math.max(sample, 0));
3900
+ let truncated = false;
3901
+ const natural = columns.map((column) => {
3902
+ let width = displayWidth(column.name);
3903
+ for (const row of measured) {
3904
+ width = Math.max(width, displayWidth(formatValue(row[column.name])));
3905
+ }
3906
+ if (width > maxColumnWidth) truncated = true;
3907
+ return { column, width: Math.min(width, maxColumnWidth) };
3908
+ });
3909
+ if (options.width === void 0) {
3910
+ return { columns: natural, dropped: [], truncated };
3911
+ }
3912
+ const planned = [];
3913
+ const dropped = [];
3914
+ let used = tableOverhead;
3915
+ for (const entry of natural) {
3916
+ const required = entry.width + columnOverhead;
3917
+ if (planned.length > 0 && used + required > options.width) {
3918
+ dropped.push(entry.column);
3919
+ continue;
3920
+ }
3921
+ if (planned.length === 0 && used + required > options.width) {
3922
+ const available = options.width - used - columnOverhead;
3923
+ const width = Math.max(available, 1);
3924
+ if (width < entry.width) truncated = true;
3925
+ planned.push({ column: entry.column, width });
3926
+ used += width + columnOverhead;
3927
+ continue;
3928
+ }
3929
+ planned.push(entry);
3930
+ used += required;
3931
+ }
3932
+ return { columns: planned, dropped, truncated };
3933
+ }
3934
+ function cellText(value, width) {
3935
+ return truncateToWidth(formatValue(value), width);
3936
+ }
3937
+
3938
+ // src/syntax/keyword.ts
3939
+ var QUERY_TRANSFORMS = [
3940
+ "map",
3941
+ "extend",
3942
+ "by",
3943
+ "from",
3944
+ "where",
3945
+ "aggregate",
3946
+ "having",
3947
+ "sort",
3948
+ "distinct",
3949
+ "take",
3950
+ "offset"
3951
+ ];
3952
+ var JOINS_AND_SET_OPERATIONS = [
3953
+ "left",
3954
+ "inner",
3955
+ "natural",
3956
+ "join",
3957
+ "on",
3958
+ "using",
3959
+ "intersect",
3960
+ "except"
3961
+ ];
3962
+ var DML = ["insert", "into", "update", "set", "delete"];
3963
+ var CONTROL_FLOW = [
3964
+ "let",
3965
+ "if",
3966
+ "else",
3967
+ "end",
3968
+ "loop",
3969
+ "while",
3970
+ "break",
3971
+ "continue",
3972
+ "return"
3973
+ ];
3974
+ var FUNCTIONS_AND_CASTING = ["fun", "call", "apply", "cast"];
3975
+ var DDL_AND_SHAPE = [
3976
+ "describe",
3977
+ "show",
3978
+ "create",
3979
+ "alter",
3980
+ "drop",
3981
+ "filter",
3982
+ "gate",
3983
+ "flow",
3984
+ "window",
3985
+ "returning"
3986
+ ];
3987
+ var OPERATOR_KEYWORDS = ["in", "between", "like", "is", "with"];
3988
+ var OBJECT_TYPES = [
3989
+ "namespace",
3990
+ "sequence",
3991
+ "series",
3992
+ "subscription",
3993
+ "table",
3994
+ "ringbuffer",
3995
+ "column",
3996
+ "policy",
3997
+ "property",
3998
+ "view",
3999
+ "deferred",
4000
+ "transactional"
4001
+ ];
4002
+ var INDEX_AND_CONSTRAINTS = [
4003
+ "index",
4004
+ "unique",
4005
+ "primary",
4006
+ "key",
4007
+ "asc",
4008
+ "desc",
4009
+ "auto",
4010
+ "increment",
4011
+ "value"
4012
+ ];
4013
+ var MISC_OPERATIONS = [
4014
+ "exists",
4015
+ "replace",
4016
+ "cascade",
4017
+ "restrict",
4018
+ "to",
4019
+ "pause",
4020
+ "resume",
4021
+ "query",
4022
+ "rename",
4023
+ "rownum",
4024
+ "dictionary",
4025
+ "for",
4026
+ "output",
4027
+ "append",
4028
+ "assert",
4029
+ "patch"
4030
+ ];
4031
+ var ENUMS_AND_PATTERN_MATCHING = ["enum", "match"];
4032
+ var PROCEDURES_AND_EVENTS = ["procedure", "event", "handler", "dispatch", "tag"];
4033
+ var TESTING = ["test", "tests", "run"];
4034
+ var ACCESS_CONTROL = [
4035
+ "user",
4036
+ "role",
4037
+ "grant",
4038
+ "revoke",
4039
+ "password",
4040
+ "require",
4041
+ "execute",
4042
+ "access",
4043
+ "subscribe",
4044
+ "enable",
4045
+ "disable"
4046
+ ];
4047
+ var SYSTEM_OBJECTS = ["function", "session", "feature"];
4048
+ var MIGRATIONS = [
4049
+ "add",
4050
+ "migration",
4051
+ "migrate",
4052
+ "rollback",
4053
+ "diff",
4054
+ "version",
4055
+ "current",
4056
+ "pending"
4057
+ ];
4058
+ var MISC = ["authentication", "contains", "remote", "error"];
4059
+ var ADDITIONAL_CONSTRUCTS = ["derive", "group", "union", "as"];
4060
+ var WORD_OPERATORS = ["and", "or", "not", "xor"];
4061
+ var RQL_KEYWORDS = [
4062
+ ...QUERY_TRANSFORMS,
4063
+ ...JOINS_AND_SET_OPERATIONS,
4064
+ ...DML,
4065
+ ...CONTROL_FLOW,
4066
+ ...FUNCTIONS_AND_CASTING,
4067
+ ...DDL_AND_SHAPE,
4068
+ ...OPERATOR_KEYWORDS,
4069
+ ...OBJECT_TYPES,
4070
+ ...INDEX_AND_CONSTRAINTS,
4071
+ ...MISC_OPERATIONS,
4072
+ ...ENUMS_AND_PATTERN_MATCHING,
4073
+ ...PROCEDURES_AND_EVENTS,
4074
+ ...TESTING,
4075
+ ...ACCESS_CONTROL,
4076
+ ...SYSTEM_OBJECTS,
4077
+ ...MIGRATIONS,
4078
+ ...MISC,
4079
+ ...ADDITIONAL_CONSTRUCTS,
4080
+ ...WORD_OPERATORS
4081
+ ];
4082
+ var RQL_LITERALS = ["none", "true", "false"];
4083
+ var SIGNED_INTEGERS = ["int1", "int2", "int4", "int8", "int16", "int"];
4084
+ var UNSIGNED_INTEGERS = ["uint1", "uint2", "uint4", "uint8", "uint16", "uint"];
4085
+ var FLOATING_POINT = ["float4", "float8"];
4086
+ var TEXT_AND_BINARY = ["utf8", "blob", "text"];
4087
+ var BOOLEAN = ["bool", "boolean"];
4088
+ var NUMERIC2 = ["decimal"];
4089
+ var TEMPORAL = ["date", "datetime", "time", "duration", "interval"];
4090
+ var IDENTIFIERS_AND_UUIDS = [
4091
+ "uuid4",
4092
+ "uuid7",
4093
+ "identityid",
4094
+ "identity_id",
4095
+ "dictionaryid",
4096
+ "dictionary_id"
4097
+ ];
4098
+ var CONTAINERS = ["Option", "List", "Record", "Tuple"];
4099
+ var RQL_TYPES = [
4100
+ ...SIGNED_INTEGERS,
4101
+ ...UNSIGNED_INTEGERS,
4102
+ ...FLOATING_POINT,
4103
+ ...TEXT_AND_BINARY,
4104
+ ...BOOLEAN,
4105
+ ...NUMERIC2,
4106
+ ...TEMPORAL,
4107
+ ...IDENTIFIERS_AND_UUIDS,
4108
+ ...CONTAINERS,
4109
+ "any"
4110
+ ];
4111
+ var RQL_OPERATORS = [
4112
+ "+",
4113
+ "-",
4114
+ "*",
4115
+ "/",
4116
+ "//",
4117
+ "%",
4118
+ "=",
4119
+ "==",
4120
+ "!=",
4121
+ "->",
4122
+ "=>",
4123
+ ">",
4124
+ "<",
4125
+ ">=",
4126
+ "<=",
4127
+ "~=",
4128
+ "&&",
4129
+ "||",
4130
+ "??"
4131
+ ];
4132
+ var RQL_SYSTEM_COLUMNS = ["rownum", "created_at", "updated_at"];
4133
+
4134
+ // src/syntax/tokenizer.ts
4135
+ var KEYWORD_SET = new Set(RQL_KEYWORDS.map((entry) => entry.toLowerCase()));
4136
+ var LITERAL_SET = new Set(RQL_LITERALS.map((entry) => entry.toLowerCase()));
4137
+ var TYPE_SET = new Set(RQL_TYPES.map((entry) => entry.toLowerCase()));
4138
+ var SYSTEM_COLUMN = /#(?:rownum|created_at|updated_at)\b/y;
4139
+ var COMMENT = /#.*/y;
4140
+ var NAMESPACE_HEAD = /[a-zA-Z_][\w$]*(?=\s*::)/y;
4141
+ var NAMESPACE_SEPARATOR = /::/y;
4142
+ var NAMED_ARGUMENT = /\w+\s*:(?!:)/y;
4143
+ var VARIABLE = /\$[\w$]+/y;
4144
+ var CALL_NAME = /[a-zA-Z_][\w$]*(?=\s*\()/y;
4145
+ var WORD = /[a-zA-Z_][\w$]*/y;
4146
+ var WHITESPACE = /[ \t\r\n]+/y;
4147
+ var BRACKET = /[{}()[\]]/y;
4148
+ var NUMBER = /[+-]?(?:[\d_]+(?:\.[\d_]+)?|\.[\d_]+)(?:[eE][+-]?\d+)?/y;
4149
+ var OPERATOR = /<<|>>|\.\.|==|!=|->|=>|>=|<=|~=|:=|&&|\|\||\?\?|\/\/|[+\-*/%|.=<>!&^?]/y;
4150
+ var DELIMITER = /[;,]/y;
4151
+ function match(pattern, source, position) {
4152
+ pattern.lastIndex = position;
4153
+ const result = pattern.exec(source);
4154
+ return result === null ? null : result[0];
4155
+ }
4156
+ function classifyWord(word) {
4157
+ const lowered = word.toLowerCase();
4158
+ if (KEYWORD_SET.has(lowered)) return "keyword";
4159
+ if (LITERAL_SET.has(lowered)) return "constant";
4160
+ if (TYPE_SET.has(lowered)) return "type";
4161
+ return "identifier";
4162
+ }
4163
+ function classifyCall(word) {
4164
+ const lowered = word.toLowerCase();
4165
+ if (KEYWORD_SET.has(lowered)) return "keyword";
4166
+ if (TYPE_SET.has(lowered)) return "type";
4167
+ return "function";
4168
+ }
4169
+ function scanString(source, position) {
4170
+ const quote = source[position];
4171
+ let index = position + 1;
4172
+ while (index < source.length) {
4173
+ const char = source[index];
4174
+ if (char === "\\") {
4175
+ index += 2;
4176
+ continue;
4177
+ }
4178
+ index++;
4179
+ if (char === quote) break;
4180
+ }
4181
+ return Math.min(index, source.length);
4182
+ }
4183
+ function tokenizeRql(source) {
4184
+ const tokens = [];
4185
+ let position = 0;
4186
+ let afterSeparator = false;
4187
+ const push = (kind, end) => {
4188
+ tokens.push({ kind, start: position, end });
4189
+ position = end;
4190
+ };
4191
+ while (position < source.length) {
4192
+ if (afterSeparator) {
4193
+ const white2 = match(WHITESPACE, source, position);
4194
+ if (white2 !== null) {
4195
+ push("white", position + white2.length);
4196
+ continue;
4197
+ }
4198
+ const chained = match(NAMESPACE_HEAD, source, position);
4199
+ if (chained !== null) {
4200
+ afterSeparator = false;
4201
+ push("namespace", position + chained.length);
4202
+ continue;
4203
+ }
4204
+ const called = match(CALL_NAME, source, position);
4205
+ if (called !== null) {
4206
+ afterSeparator = false;
4207
+ push("function", position + called.length);
4208
+ continue;
4209
+ }
4210
+ const leaf = match(WORD, source, position);
4211
+ if (leaf !== null) {
4212
+ afterSeparator = false;
4213
+ push("entity", position + leaf.length);
4214
+ continue;
4215
+ }
4216
+ afterSeparator = false;
4217
+ }
4218
+ const systemColumn = match(SYSTEM_COLUMN, source, position);
4219
+ if (systemColumn !== null) {
4220
+ push("variable.predefined", position + systemColumn.length);
4221
+ continue;
4222
+ }
4223
+ const comment = match(COMMENT, source, position);
4224
+ if (comment !== null) {
4225
+ push("comment", position + comment.length);
4226
+ continue;
4227
+ }
4228
+ const namespace = match(NAMESPACE_HEAD, source, position);
4229
+ if (namespace !== null) {
4230
+ push("namespace", position + namespace.length);
4231
+ continue;
4232
+ }
4233
+ const separator = match(NAMESPACE_SEPARATOR, source, position);
4234
+ if (separator !== null) {
4235
+ afterSeparator = true;
4236
+ push("operator", position + separator.length);
4237
+ continue;
4238
+ }
4239
+ const namedArgument = match(NAMED_ARGUMENT, source, position);
4240
+ if (namedArgument !== null) {
4241
+ push("key", position + namedArgument.length);
4242
+ continue;
4243
+ }
4244
+ const variable = match(VARIABLE, source, position);
4245
+ if (variable !== null) {
4246
+ push("variable", position + variable.length);
4247
+ continue;
4248
+ }
4249
+ const call = match(CALL_NAME, source, position);
4250
+ if (call !== null) {
4251
+ push(classifyCall(call), position + call.length);
4252
+ continue;
4253
+ }
4254
+ const word = match(WORD, source, position);
4255
+ if (word !== null) {
4256
+ push(classifyWord(word), position + word.length);
4257
+ continue;
4258
+ }
4259
+ const white = match(WHITESPACE, source, position);
4260
+ if (white !== null) {
4261
+ push("white", position + white.length);
4262
+ continue;
4263
+ }
4264
+ const bracket = match(BRACKET, source, position);
4265
+ if (bracket !== null) {
4266
+ push("bracket", position + bracket.length);
4267
+ continue;
4268
+ }
4269
+ const number = match(NUMBER, source, position);
4270
+ if (number !== null) {
4271
+ push("number", position + number.length);
4272
+ continue;
4273
+ }
4274
+ const char = source[position];
4275
+ if (char === '"' || char === "'") {
4276
+ push("string", scanString(source, position));
4277
+ continue;
4278
+ }
4279
+ const operator = match(OPERATOR, source, position);
4280
+ if (operator !== null) {
4281
+ push("operator", position + operator.length);
4282
+ continue;
4283
+ }
4284
+ const delimiter = match(DELIMITER, source, position);
4285
+ if (delimiter !== null) {
4286
+ push("delimiter", position + delimiter.length);
4287
+ continue;
4288
+ }
4289
+ push("identifier", position + 1);
4290
+ }
4291
+ return tokens;
4292
+ }
4293
+
3218
4294
  // src/types.ts
3219
4295
  var ReifyError = class extends Error {
3220
4296
  constructor(response) {
@@ -3261,11 +4337,20 @@ export {
3261
4337
  Int2Value,
3262
4338
  Int4Value,
3263
4339
  Int8Value,
4340
+ NONE_PRESENTATION,
3264
4341
  NONE_VALUE,
3265
4342
  NoneValue,
4343
+ Option,
4344
+ ROW_NUMBER_KEY,
4345
+ RQL_KEYWORDS,
4346
+ RQL_LITERALS,
4347
+ RQL_OPERATORS,
4348
+ RQL_SYSTEM_COLUMNS,
4349
+ RQL_TYPES,
3266
4350
  ReifyError,
3267
4351
  Shape,
3268
4352
  ShapeBuilder,
4353
+ ShapeMismatch,
3269
4354
  TYPE_CODE,
3270
4355
  TimeValue,
3271
4356
  Uint16Value,
@@ -3276,13 +4361,43 @@ export {
3276
4361
  Utf8Value,
3277
4362
  Uuid4Value,
3278
4363
  Uuid7Value,
3279
- Value,
4364
+ Value2 as Value,
3280
4365
  asFrameResults,
4366
+ cellText,
4367
+ checkFrame,
4368
+ checkFrames,
4369
+ columnsFromWire,
4370
+ columnsToRows,
3281
4371
  decode,
4372
+ displayWidth,
4373
+ encodeParams,
4374
+ encodeValue,
4375
+ envelopeToColumns,
4376
+ envelopesToFrames,
4377
+ formatValue,
4378
+ framesFromWire,
4379
+ graphemeWidth,
4380
+ inferColumns,
4381
+ innerOfOption,
4382
+ isOption,
3282
4383
  isOptionType,
4384
+ noneDepth,
4385
+ noneMarker,
4386
+ noneMarkerDepth,
4387
+ optionDepth,
4388
+ padToWidth,
3283
4389
  parseValue,
3284
- type_name_from_code,
4390
+ planTable,
4391
+ tokenizeRql,
4392
+ transformFrames,
4393
+ transformResult,
4394
+ truncateToWidth,
4395
+ typeFromWire,
4396
+ typeNameFromCode,
4397
+ typeToWire,
3285
4398
  unwrapOptionType,
3286
- validateShape
4399
+ validateShape,
4400
+ valueRole,
4401
+ valueTypeName
3287
4402
  };
3288
4403
  //# sourceMappingURL=index.js.map