@reifydb/core 0.9.3 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -21,29 +21,28 @@ var ROW_NUMBER_KEY = "#rownum";
21
21
  var BlobValue = class _BlobValue {
22
22
  constructor(value) {
23
23
  this.type = "Blob";
24
- if (value !== void 0) {
25
- if (value instanceof Uint8Array) {
26
- this.bytes = new Uint8Array(value);
27
- } else if (value instanceof ArrayBuffer) {
28
- this.bytes = new Uint8Array(value);
29
- } else if (typeof value === "string") {
30
- const parsed = _BlobValue.parseString(value);
31
- if (parsed === null) {
32
- throw new Error(`Invalid blob string: ${value}`);
33
- }
34
- this.bytes = parsed;
35
- } else if (Array.isArray(value)) {
36
- for (const byte of value) {
37
- if (!Number.isInteger(byte) || byte < 0 || byte > 255) {
38
- throw new Error(`Invalid byte value: ${byte}`);
39
- }
24
+ if (value === void 0) {
25
+ throw new Error(`Blob value must be defined, a none is carried by NoneValue`);
26
+ }
27
+ if (value instanceof Uint8Array) {
28
+ this.bytes = new Uint8Array(value);
29
+ } else if (value instanceof ArrayBuffer) {
30
+ this.bytes = new Uint8Array(value);
31
+ } else if (typeof value === "string") {
32
+ const parsed = _BlobValue.parseString(value);
33
+ if (parsed === null) {
34
+ throw new Error(`Invalid blob string: ${value}`);
35
+ }
36
+ this.bytes = parsed;
37
+ } else if (Array.isArray(value)) {
38
+ for (const byte of value) {
39
+ if (!Number.isInteger(byte) || byte < 0 || byte > 255) {
40
+ throw new Error(`Invalid byte value: ${byte}`);
40
41
  }
41
- this.bytes = new Uint8Array(value);
42
- } else {
43
- throw new Error(`Blob value must be a Uint8Array, ArrayBuffer, string, or number[], got ${typeof value}`);
44
42
  }
43
+ this.bytes = new Uint8Array(value);
45
44
  } else {
46
- this.bytes = void 0;
45
+ throw new Error(`Blob value must be a Uint8Array, ArrayBuffer, string, or number[], got ${typeof value}`);
47
46
  }
48
47
  }
49
48
  /**
@@ -67,8 +66,8 @@ var BlobValue = class _BlobValue {
67
66
  /**
68
67
  * Create a BLOB from a hex string
69
68
  */
70
- static fromHex(hex) {
71
- const cleanHex = hex.startsWith("0x") || hex.startsWith("0X") ? hex.substring(2) : hex;
69
+ static fromHex(hex2) {
70
+ const cleanHex = hex2.startsWith("0x") || hex2.startsWith("0X") ? hex2.substring(2) : hex2;
72
71
  if (cleanHex.length % 2 !== 0) {
73
72
  throw new Error(`Invalid hex string: odd length`);
74
73
  }
@@ -76,7 +75,7 @@ var BlobValue = class _BlobValue {
76
75
  for (let i = 0; i < cleanHex.length; i += 2) {
77
76
  const byte = parseInt(cleanHex.substring(i, i + 2), 16);
78
77
  if (isNaN(byte)) {
79
- throw new Error(`Invalid hex string: ${hex}`);
78
+ throw new Error(`Invalid hex string: ${hex2}`);
80
79
  }
81
80
  bytes[i / 2] = byte;
82
81
  }
@@ -118,7 +117,7 @@ var BlobValue = class _BlobValue {
118
117
  static parse(str) {
119
118
  const trimmed = str.trim();
120
119
  if (trimmed === "" || trimmed === NONE_VALUE) {
121
- return new _BlobValue(void 0);
120
+ throw new Error(`Cannot parse "${str}" as Blob`);
122
121
  }
123
122
  const parsed = _BlobValue.parseString(trimmed);
124
123
  if (parsed === null) {
@@ -149,8 +148,8 @@ var BlobValue = class _BlobValue {
149
148
  */
150
149
  toHex() {
151
150
  if (this.bytes === void 0) return void 0;
152
- const hex = Array.from(this.bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
153
- return "0x" + hex;
151
+ const hex2 = Array.from(this.bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
152
+ return "0x" + hex2;
154
153
  }
155
154
  /**
156
155
  * Convert to base64 string
@@ -176,13 +175,10 @@ var BlobValue = class _BlobValue {
176
175
  * Format as hex string with 0x prefix
177
176
  */
178
177
  toString() {
179
- if (this.bytes === void 0) {
180
- return "none";
181
- }
182
178
  return this.toHex();
183
179
  }
184
180
  valueOf() {
185
- return this.bytes ? new Uint8Array(this.bytes) : void 0;
181
+ return new Uint8Array(this.bytes);
186
182
  }
187
183
  /**
188
184
  * Get the internal representation
@@ -232,12 +228,12 @@ var BlobValue = class _BlobValue {
232
228
  return null;
233
229
  }
234
230
  toJSON() {
235
- return this.bytes === void 0 ? null : this.toHex();
231
+ return this.toHex();
236
232
  }
237
233
  encode() {
238
234
  return {
239
235
  type: this.type,
240
- value: this.value === void 0 ? NONE_VALUE : this.toString()
236
+ value: this.toString()
241
237
  };
242
238
  }
243
239
  };
@@ -246,19 +242,18 @@ var BlobValue = class _BlobValue {
246
242
  var BooleanValue = class _BooleanValue {
247
243
  constructor(value) {
248
244
  this.type = "Boolean";
249
- if (value !== void 0) {
250
- if (typeof value !== "boolean") {
251
- throw new Error(`Boolean value must be a boolean, got ${typeof value}`);
252
- }
253
- this.value = value;
254
- } else {
255
- this.value = void 0;
245
+ if (value === void 0) {
246
+ throw new Error(`Boolean value must be defined, a none is carried by NoneValue`);
247
+ }
248
+ if (typeof value !== "boolean") {
249
+ throw new Error(`Boolean value must be a boolean, got ${typeof value}`);
256
250
  }
251
+ this.value = value;
257
252
  }
258
253
  static parse(str) {
259
254
  const trimmed = str.trim().toLowerCase();
260
255
  if (trimmed === "" || trimmed === NONE_VALUE) {
261
- return new _BooleanValue(void 0);
256
+ throw new Error(`Cannot parse "${str}" as Boolean`);
262
257
  }
263
258
  if (trimmed === "true") {
264
259
  return new _BooleanValue(true);
@@ -272,7 +267,7 @@ var BooleanValue = class _BooleanValue {
272
267
  return this.value;
273
268
  }
274
269
  toString() {
275
- return this.value === void 0 ? "none" : this.value.toString();
270
+ return this.value.toString();
276
271
  }
277
272
  /**
278
273
  * Compare two boolean values for equality
@@ -290,43 +285,43 @@ var BooleanValue = class _BooleanValue {
290
285
  encode() {
291
286
  return {
292
287
  type: this.type,
293
- value: this.value === void 0 ? NONE_VALUE : this.toString()
288
+ value: this.toString()
294
289
  };
295
290
  }
296
291
  };
297
292
 
298
293
  // src/value/date.ts
299
294
  var DateValue = class _DateValue {
300
- // day of month (1-31)
301
295
  constructor(value) {
302
296
  this.type = "Date";
303
- if (value !== void 0) {
304
- if (value instanceof Date) {
305
- const year = value.getUTCFullYear();
306
- const month = value.getUTCMonth() + 1;
307
- const day = value.getUTCDate();
308
- this.months = year * 12 + (month - 1);
309
- this.days = day;
310
- } else if (typeof value === "string") {
311
- const parsed = _DateValue.parseDate(value);
312
- if (!parsed) {
313
- throw new Error(`Invalid date string: ${value}`);
314
- }
315
- this.months = parsed.months;
316
- this.days = parsed.days;
317
- } else if (typeof value === "number") {
318
- const date = _DateValue.fromDaysSinceEpochToComponents(value);
319
- if (!date) {
320
- throw new Error(`Invalid days since epoch: ${value}`);
321
- }
322
- this.months = date.months;
323
- this.days = date.days;
324
- } else {
325
- throw new Error(`Date value must be a Date, string, or number, got ${typeof value}`);
297
+ if (value === void 0) {
298
+ throw new Error(`Date value must be defined, a none is carried by NoneValue`);
299
+ }
300
+ if (value instanceof Date) {
301
+ const year = value.getUTCFullYear();
302
+ const month = value.getUTCMonth() + 1;
303
+ const day = value.getUTCDate();
304
+ this.months = year * 12 + (month - 1);
305
+ this.days = day;
306
+ } else if (typeof value === "string") {
307
+ const parsed = _DateValue.parseDate(value);
308
+ if (!parsed) {
309
+ throw new Error(`Invalid date string: ${value}`);
326
310
  }
311
+ this.months = parsed.months;
312
+ this.days = parsed.days;
313
+ } else if (typeof value === "number") {
314
+ const date = _DateValue.fromDaysSinceEpochToComponents(value);
315
+ if (!date) {
316
+ throw new Error(`Invalid days since epoch: ${value}`);
317
+ }
318
+ this.months = date.months;
319
+ this.days = date.days;
320
+ } else if (typeof value === "object" && "months" in value && "days" in value) {
321
+ this.months = value.months;
322
+ this.days = value.days;
327
323
  } else {
328
- this.months = void 0;
329
- this.days = void 0;
324
+ throw new Error(`Date value must be a Date, string, or number, got ${typeof value}`);
330
325
  }
331
326
  }
332
327
  /**
@@ -336,10 +331,7 @@ var DateValue = class _DateValue {
336
331
  if (!_DateValue.isValidDate(year, month, day)) {
337
332
  throw new Error(`Invalid date: ${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`);
338
333
  }
339
- const result = new _DateValue(void 0);
340
- result.months = year * 12 + (month - 1);
341
- result.days = day;
342
- return result;
334
+ return new _DateValue({ months: year * 12 + (month - 1), days: day });
343
335
  }
344
336
  /**
345
337
  * Get today's date (in UTC)
@@ -358,16 +350,13 @@ var DateValue = class _DateValue {
358
350
  static parse(str) {
359
351
  const trimmed = str.trim();
360
352
  if (trimmed === "" || trimmed === NONE_VALUE) {
361
- return new _DateValue(void 0);
353
+ throw new Error(`Cannot parse "${str}" as Date`);
362
354
  }
363
355
  const parsed = _DateValue.parseDate(trimmed);
364
356
  if (!parsed) {
365
357
  throw new Error(`Cannot parse "${str}" as Date`);
366
358
  }
367
- const result = new _DateValue(void 0);
368
- result.months = parsed.months;
369
- result.days = parsed.days;
370
- return result;
359
+ return new _DateValue(parsed);
371
360
  }
372
361
  /**
373
362
  * Convert to days since Unix epoch (1970-01-01) for storage
@@ -542,29 +531,28 @@ var DateValue = class _DateValue {
542
531
  var _TimeValue = class _TimeValue {
543
532
  constructor(value) {
544
533
  this.type = "Time";
545
- if (value !== void 0) {
546
- if (typeof value === "bigint") {
547
- if (value < 0n || value >= _TimeValue.NANOS_PER_DAY) {
548
- throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
549
- }
550
- this.value = value;
551
- } else if (typeof value === "string") {
552
- const parsed = _TimeValue.parseTime(value);
553
- if (parsed === null) {
554
- throw new Error(`Invalid time string: ${value}`);
555
- }
556
- this.value = parsed;
557
- } else if (typeof value === "number") {
558
- const bigintValue = BigInt(Math.floor(value));
559
- if (bigintValue < 0n || bigintValue >= _TimeValue.NANOS_PER_DAY) {
560
- throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
561
- }
562
- this.value = bigintValue;
563
- } else {
564
- throw new Error(`Time value must be a bigint, string, or number, got ${typeof value}`);
534
+ if (value === void 0) {
535
+ throw new Error(`Time value must be defined, a none is carried by NoneValue`);
536
+ }
537
+ if (typeof value === "bigint") {
538
+ if (value < 0n || value >= _TimeValue.NANOS_PER_DAY) {
539
+ throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
565
540
  }
541
+ this.value = value;
542
+ } else if (typeof value === "string") {
543
+ const parsed = _TimeValue.parseTime(value);
544
+ if (parsed === null) {
545
+ throw new Error(`Invalid time string: ${value}`);
546
+ }
547
+ this.value = parsed;
548
+ } else if (typeof value === "number") {
549
+ const bigintValue = BigInt(Math.floor(value));
550
+ if (bigintValue < 0n || bigintValue >= _TimeValue.NANOS_PER_DAY) {
551
+ throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
552
+ }
553
+ this.value = bigintValue;
566
554
  } else {
567
- this.value = void 0;
555
+ throw new Error(`Time value must be a bigint, string, or number, got ${typeof value}`);
568
556
  }
569
557
  }
570
558
  /**
@@ -610,7 +598,7 @@ var _TimeValue = class _TimeValue {
610
598
  static parse(str) {
611
599
  const trimmed = str.trim();
612
600
  if (trimmed === "" || trimmed === NONE_VALUE) {
613
- return new _TimeValue(void 0);
601
+ throw new Error(`Cannot parse "${str}" as Time`);
614
602
  }
615
603
  const parsed = _TimeValue.parseTime(trimmed);
616
604
  if (parsed === null) {
@@ -665,9 +653,6 @@ var _TimeValue = class _TimeValue {
665
653
  * Format as HH:MM:SS.nnnnnnnnn string
666
654
  */
667
655
  toString() {
668
- if (this.value === void 0) {
669
- return "none";
670
- }
671
656
  const hour = this.hour();
672
657
  const minute = this.minute();
673
658
  const second = this.second();
@@ -720,12 +705,12 @@ var _TimeValue = class _TimeValue {
720
705
  return this.value === otherTime.value;
721
706
  }
722
707
  toJSON() {
723
- return this.value === void 0 ? null : this.toString();
708
+ return this.toString();
724
709
  }
725
710
  encode() {
726
711
  return {
727
712
  type: this.type,
728
- value: this.value === void 0 ? NONE_VALUE : this.toString()
713
+ value: this.toString()
729
714
  };
730
715
  }
731
716
  };
@@ -741,59 +726,60 @@ var DateTimeValue = class _DateTimeValue {
741
726
  // nanoseconds since midnight
742
727
  constructor(value) {
743
728
  this.type = "DateTime";
744
- if (value !== void 0) {
745
- if (value instanceof Date) {
746
- const year = value.getUTCFullYear();
747
- const month = value.getUTCMonth() + 1;
748
- const day = value.getUTCDate();
749
- const hour = value.getUTCHours();
750
- const minute = value.getUTCMinutes();
751
- const second = value.getUTCSeconds();
752
- const millis = value.getUTCMilliseconds();
753
- this.months = year * 12 + (month - 1);
754
- this.days = day;
755
- this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
756
- } else if (typeof value === "string") {
757
- const parsed = _DateTimeValue.parseDateTime(value);
758
- if (!parsed) {
759
- throw new Error(`Invalid datetime string: ${value}`);
760
- }
761
- this.months = parsed.months;
762
- this.days = parsed.days;
763
- this.nanos = parsed.nanos;
764
- } else if (typeof value === "number") {
765
- const date = new Date(value);
766
- const year = date.getUTCFullYear();
767
- const month = date.getUTCMonth() + 1;
768
- const day = date.getUTCDate();
769
- const hour = date.getUTCHours();
770
- const minute = date.getUTCMinutes();
771
- const second = date.getUTCSeconds();
772
- const millis = date.getUTCMilliseconds();
773
- this.months = year * 12 + (month - 1);
774
- this.days = day;
775
- this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
776
- } else if (typeof value === "bigint") {
777
- const millis = Number(value / 1000000n);
778
- const extraNanos = value % 1000000n;
779
- const date = new Date(millis);
780
- const year = date.getUTCFullYear();
781
- const month = date.getUTCMonth() + 1;
782
- const day = date.getUTCDate();
783
- const hour = date.getUTCHours();
784
- const minute = date.getUTCMinutes();
785
- const second = date.getUTCSeconds();
786
- const dateMillis = date.getUTCMilliseconds();
787
- this.months = year * 12 + (month - 1);
788
- this.days = day;
789
- this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(dateMillis) * 1000000n + extraNanos;
790
- } else {
791
- throw new Error(`DateTime value must be a Date, string, number, or bigint, got ${typeof value}`);
729
+ if (value === void 0) {
730
+ throw new Error(`DateTime value must be defined, a none is carried by NoneValue`);
731
+ }
732
+ if (value instanceof Date) {
733
+ const year = value.getUTCFullYear();
734
+ const month = value.getUTCMonth() + 1;
735
+ const day = value.getUTCDate();
736
+ const hour = value.getUTCHours();
737
+ const minute = value.getUTCMinutes();
738
+ const second = value.getUTCSeconds();
739
+ const millis = value.getUTCMilliseconds();
740
+ this.months = year * 12 + (month - 1);
741
+ this.days = day;
742
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
743
+ } else if (typeof value === "string") {
744
+ const parsed = _DateTimeValue.parseDateTime(value);
745
+ if (!parsed) {
746
+ throw new Error(`Invalid datetime string: ${value}`);
792
747
  }
748
+ this.months = parsed.months;
749
+ this.days = parsed.days;
750
+ this.nanos = parsed.nanos;
751
+ } else if (typeof value === "number") {
752
+ const date = new Date(value);
753
+ const year = date.getUTCFullYear();
754
+ const month = date.getUTCMonth() + 1;
755
+ const day = date.getUTCDate();
756
+ const hour = date.getUTCHours();
757
+ const minute = date.getUTCMinutes();
758
+ const second = date.getUTCSeconds();
759
+ const millis = date.getUTCMilliseconds();
760
+ this.months = year * 12 + (month - 1);
761
+ this.days = day;
762
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
763
+ } else if (typeof value === "bigint") {
764
+ const millis = Number(value / 1000000n);
765
+ const extraNanos = value % 1000000n;
766
+ const date = new Date(millis);
767
+ const year = date.getUTCFullYear();
768
+ const month = date.getUTCMonth() + 1;
769
+ const day = date.getUTCDate();
770
+ const hour = date.getUTCHours();
771
+ const minute = date.getUTCMinutes();
772
+ const second = date.getUTCSeconds();
773
+ const dateMillis = date.getUTCMilliseconds();
774
+ this.months = year * 12 + (month - 1);
775
+ this.days = day;
776
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(dateMillis) * 1000000n + extraNanos;
777
+ } else if (typeof value === "object" && "months" in value && "days" in value && "nanos" in value) {
778
+ this.months = value.months;
779
+ this.days = value.days;
780
+ this.nanos = value.nanos;
793
781
  } else {
794
- this.months = void 0;
795
- this.days = void 0;
796
- this.nanos = void 0;
782
+ throw new Error(`DateTime value must be a Date, string, number, or bigint, got ${typeof value}`);
797
783
  }
798
784
  }
799
785
  /**
@@ -815,11 +801,11 @@ var DateTimeValue = class _DateTimeValue {
815
801
  if (!_DateTimeValue.isValidDate(year, month, day)) {
816
802
  throw new Error(`Invalid datetime: ${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")} ${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}:${String(second).padStart(2, "0")}`);
817
803
  }
818
- const result = new _DateTimeValue(void 0);
819
- result.months = year * 12 + (month - 1);
820
- result.days = day;
821
- result.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(nano);
822
- return result;
804
+ return new _DateTimeValue({
805
+ months: year * 12 + (month - 1),
806
+ days: day,
807
+ nanos: BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(nano)
808
+ });
823
809
  }
824
810
  /**
825
811
  * Create a DateTimeValue from year, month, day, hour, minute, second (no fractional)
@@ -855,10 +841,11 @@ var DateTimeValue = class _DateTimeValue {
855
841
  const millis = seconds * 1e3 + Math.floor(nanos / 1e6);
856
842
  const extraNanos = nanos % 1e6;
857
843
  const result = new _DateTimeValue(millis);
858
- if (result.nanos !== void 0) {
859
- result.nanos = result.nanos + BigInt(extraNanos);
860
- }
861
- return result;
844
+ return new _DateTimeValue({
845
+ months: result.months,
846
+ days: result.days,
847
+ nanos: result.nanos + BigInt(extraNanos)
848
+ });
862
849
  }
863
850
  /**
864
851
  * Get current datetime
@@ -878,17 +865,13 @@ var DateTimeValue = class _DateTimeValue {
878
865
  static parse(str) {
879
866
  const trimmed = str.trim();
880
867
  if (trimmed === "" || trimmed === NONE_VALUE) {
881
- return new _DateTimeValue(void 0);
868
+ throw new Error(`Cannot parse "${str}" as DateTime`);
882
869
  }
883
870
  const parsed = _DateTimeValue.parseDateTime(trimmed);
884
871
  if (!parsed) {
885
872
  throw new Error(`Cannot parse "${str}" as DateTime`);
886
873
  }
887
- const result = new _DateTimeValue(void 0);
888
- result.months = parsed.months;
889
- result.days = parsed.days;
890
- result.nanos = parsed.nanos;
891
- return result;
874
+ return new _DateTimeValue(parsed);
892
875
  }
893
876
  /**
894
877
  * Get Unix timestamp in seconds
@@ -977,9 +960,6 @@ var DateTimeValue = class _DateTimeValue {
977
960
  return `${yearStr}-${month}-${day}T${hour}:${minute}:${second}.${nanoStr}Z`;
978
961
  }
979
962
  valueOf() {
980
- if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
981
- return void 0;
982
- }
983
963
  const year = Math.floor(this.months / 12);
984
964
  let m = this.months % 12;
985
965
  if (m < 0) m += 12;
@@ -1075,35 +1055,32 @@ var DateTimeValue = class _DateTimeValue {
1075
1055
  return this.months === otherDateTime.months && this.days === otherDateTime.days && this.nanos === otherDateTime.nanos;
1076
1056
  }
1077
1057
  toJSON() {
1078
- if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1079
- return null;
1080
- }
1081
1058
  return this.toString();
1082
1059
  }
1083
1060
  encode() {
1084
1061
  return {
1085
1062
  type: this.type,
1086
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1063
+ value: this.toString()
1087
1064
  };
1088
1065
  }
1089
1066
  };
1090
1067
 
1091
1068
  // src/value/decimal.ts
1069
+ var DECIMAL_PATTERN = /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;
1092
1070
  var DecimalValue = class _DecimalValue {
1093
1071
  constructor(value) {
1094
1072
  this.type = "Decimal";
1095
- if (value !== void 0) {
1096
- if (typeof value !== "string") {
1097
- throw new Error(`Decimal value must be a string, got ${typeof value}`);
1098
- }
1099
- this.value = value;
1100
- } else {
1101
- this.value = void 0;
1073
+ if (value === void 0) {
1074
+ throw new Error(`Decimal value must be defined, a none is carried by NoneValue`);
1102
1075
  }
1076
+ if (typeof value !== "string") {
1077
+ throw new Error(`Decimal value must be a string, got ${typeof value}`);
1078
+ }
1079
+ this.value = value;
1103
1080
  }
1104
1081
  static parse(str) {
1105
- if (str === NONE_VALUE) {
1106
- return new _DecimalValue(void 0);
1082
+ if (!DECIMAL_PATTERN.test(str)) {
1083
+ throw new Error(`Cannot parse "${str}" as Decimal`);
1107
1084
  }
1108
1085
  return new _DecimalValue(str);
1109
1086
  }
@@ -1111,7 +1088,7 @@ var DecimalValue = class _DecimalValue {
1111
1088
  return this.value;
1112
1089
  }
1113
1090
  toString() {
1114
- return this.value === void 0 ? "none" : this.value;
1091
+ return this.value;
1115
1092
  }
1116
1093
  equals(other) {
1117
1094
  if (other.type !== this.type) {
@@ -1126,45 +1103,314 @@ var DecimalValue = class _DecimalValue {
1126
1103
  encode() {
1127
1104
  return {
1128
1105
  type: this.type,
1129
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1106
+ value: this.toString()
1130
1107
  };
1131
1108
  }
1132
1109
  };
1133
1110
 
1134
- // src/value/float4.ts
1135
- var _Float4Value = class _Float4Value {
1136
- constructor(value) {
1137
- this.type = "Float4";
1138
- if (value !== void 0) {
1139
- if (typeof value !== "number") {
1140
- throw new Error(`Float4 value must be a number, got ${typeof value}`);
1111
+ // src/type-code.ts
1112
+ var TYPE_CODE = {
1113
+ None: 0,
1114
+ Boolean: 1,
1115
+ Float4: 2,
1116
+ Float8: 3,
1117
+ Int1: 4,
1118
+ Int2: 5,
1119
+ Int4: 6,
1120
+ Int8: 7,
1121
+ Int16: 8,
1122
+ Utf8: 9,
1123
+ Uint1: 10,
1124
+ Uint2: 11,
1125
+ Uint4: 12,
1126
+ Uint8: 13,
1127
+ Uint16: 14,
1128
+ Date: 15,
1129
+ DateTime: 16,
1130
+ Time: 17,
1131
+ Duration: 18,
1132
+ IdentityId: 19,
1133
+ Uuid4: 20,
1134
+ Uuid7: 21,
1135
+ Blob: 22,
1136
+ Decimal: 23,
1137
+ Any: 24,
1138
+ DictionaryId: 25,
1139
+ Type: 26,
1140
+ List: 27,
1141
+ Record: 28,
1142
+ Tuple: 29,
1143
+ Digest: 30
1144
+ };
1145
+ var CODE_TO_NAME = Object.fromEntries(
1146
+ Object.entries(TYPE_CODE).map(([k, v]) => [v, k])
1147
+ );
1148
+ function typeNameFromCode(code) {
1149
+ const name = CODE_TO_NAME[code];
1150
+ if (!name) throw new Error(`Unknown type code: ${code}`);
1151
+ return name;
1152
+ }
1153
+
1154
+ // src/value/digest.ts
1155
+ var VERSION = 1n;
1156
+ var MIN_ACCURACY = 1e3;
1157
+ var MAX_ACCURACY = 1e5;
1158
+ var U32_MAX = 0xffffffffn;
1159
+ var U64_MAX = 0xffffffffffffffffn;
1160
+ var I32_MAX = 0x7fffffffn;
1161
+ var INNER_TYPES = [
1162
+ "Float4",
1163
+ "Float8",
1164
+ "Int1",
1165
+ "Int2",
1166
+ "Int4",
1167
+ "Int8",
1168
+ "Int16",
1169
+ "Uint1",
1170
+ "Uint2",
1171
+ "Uint4",
1172
+ "Uint8",
1173
+ "Uint16",
1174
+ "Duration"
1175
+ ];
1176
+ function digestType(inner, accuracy) {
1177
+ const supported = INNER_TYPES.find((name) => name === inner);
1178
+ if (supported === void 0) {
1179
+ throw new Error(`digest does not support ${inner} input`);
1180
+ }
1181
+ if (!Number.isInteger(accuracy) || accuracy < MIN_ACCURACY || accuracy > MAX_ACCURACY) {
1182
+ throw new Error(`digest accuracy must be a whole number of ppm between ${MIN_ACCURACY} and ${MAX_ACCURACY}, got ${accuracy}`);
1183
+ }
1184
+ return { Digest: { inner: supported, accuracy } };
1185
+ }
1186
+ function digestTypeName(type) {
1187
+ const { inner, accuracy } = type.Digest;
1188
+ const whole = Math.floor(accuracy / 1e6);
1189
+ const fraction = accuracy % 1e6;
1190
+ const text = fraction === 0 ? `${whole}` : `${whole}.${String(fraction).padStart(6, "0").replace(/0+$/, "")}`;
1191
+ return `Digest(${inner}, ${text})`;
1192
+ }
1193
+ var DigestValue = class _DigestValue {
1194
+ constructor(bytes) {
1195
+ const reader = new DigestReader(bytes);
1196
+ const decoded = reader.digest();
1197
+ this.bytes = new Uint8Array(bytes);
1198
+ this.type = decoded.type;
1199
+ this.inner = decoded.type.Digest.inner;
1200
+ this.accuracy = decoded.type.Digest.accuracy;
1201
+ this.count = decoded.count;
1202
+ }
1203
+ static parse(str, type) {
1204
+ if (!/^0x([0-9a-fA-F]{2})*$/.test(str)) {
1205
+ throw new Error(`Cannot parse "${str}" as ${digestTypeName(type)}`);
1206
+ }
1207
+ const bytes = new Uint8Array((str.length - 2) / 2);
1208
+ for (let i = 0; i < bytes.length; i++) {
1209
+ bytes[i] = parseInt(str.substring(2 + i * 2, 4 + i * 2), 16);
1210
+ }
1211
+ const digest = new _DigestValue(bytes);
1212
+ if (digest.inner !== type.Digest.inner || digest.accuracy !== type.Digest.accuracy) {
1213
+ throw new Error(`digest is ${digestTypeName(digest.type)} but the type is ${digestTypeName(type)}`);
1214
+ }
1215
+ return digest;
1216
+ }
1217
+ asBytes() {
1218
+ return new Uint8Array(this.bytes);
1219
+ }
1220
+ toString() {
1221
+ return `digest(n: ${this.count})`;
1222
+ }
1223
+ equals(other) {
1224
+ if (!(other instanceof _DigestValue) || other.bytes.length !== this.bytes.length) {
1225
+ return false;
1226
+ }
1227
+ return this.bytes.every((byte, i) => byte === other.bytes[i]);
1228
+ }
1229
+ toJSON() {
1230
+ return hex(this.bytes);
1231
+ }
1232
+ encode() {
1233
+ return {
1234
+ type: this.type,
1235
+ value: hex(this.bytes)
1236
+ };
1237
+ }
1238
+ };
1239
+ function hex(bytes) {
1240
+ return "0x" + Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1241
+ }
1242
+ var DigestReader = class {
1243
+ constructor(bytes) {
1244
+ this.bytes = bytes;
1245
+ this.position = 0;
1246
+ }
1247
+ digest() {
1248
+ const version4 = this.varint();
1249
+ if (version4 !== VERSION) {
1250
+ throw new Error(`digest encoding version ${version4} is unknown`);
1251
+ }
1252
+ const tag = this.varint();
1253
+ const inner = INNER_TYPES.find((name) => BigInt(TYPE_CODE[name]) === tag);
1254
+ if (inner === void 0) {
1255
+ throw new Error(`digest encoding has unknown inner type tag ${tag}`);
1256
+ }
1257
+ const accuracy = this.varint();
1258
+ if (accuracy > U32_MAX) {
1259
+ throw new Error(`digest accuracy must be a whole number of ppm between ${MIN_ACCURACY} and ${MAX_ACCURACY}, got ${accuracy}`);
1260
+ }
1261
+ const type = digestType(inner, Number(accuracy));
1262
+ const zero = this.varint();
1263
+ const negativeInfinity = this.varint();
1264
+ const positiveInfinity = this.varint();
1265
+ const negative = this.store();
1266
+ const positive = this.store();
1267
+ if (this.position !== this.bytes.length) {
1268
+ throw new Error(`digest encoding has ${this.bytes.length - this.position} trailing bytes`);
1269
+ }
1270
+ if (inner === "Duration" && (negativeInfinity !== 0n || positiveInfinity !== 0n)) {
1271
+ throw new Error("digest of duration cannot hold infinity");
1272
+ }
1273
+ const count = zero + negativeInfinity + positiveInfinity + negative + positive;
1274
+ if (count > U64_MAX) {
1275
+ throw new Error("digest encoding counts overflow u64");
1276
+ }
1277
+ return { type, count };
1278
+ }
1279
+ varint() {
1280
+ let value = 0n;
1281
+ let shift = 0n;
1282
+ for (; ; ) {
1283
+ if (this.position >= this.bytes.length) {
1284
+ throw new Error("digest encoding ends early");
1285
+ }
1286
+ const byte = this.bytes[this.position];
1287
+ this.position += 1;
1288
+ const low = BigInt(byte & 127);
1289
+ if (shift === 63n && low > 1n) {
1290
+ throw new Error("digest encoding has a varint above u64");
1291
+ }
1292
+ value |= low << shift;
1293
+ if ((byte & 128) === 0) {
1294
+ if (byte === 0 && shift > 0n) {
1295
+ throw new Error("digest encoding has a varint that is not minimal");
1296
+ }
1297
+ return value;
1141
1298
  }
1142
- if (Number.isNaN(value) || !Number.isFinite(value)) {
1143
- this.value = void 0;
1299
+ shift += 7n;
1300
+ if (shift > 63n) {
1301
+ throw new Error("digest encoding has a varint above u64");
1302
+ }
1303
+ }
1304
+ }
1305
+ store() {
1306
+ const len = this.varint();
1307
+ let total = 0n;
1308
+ let previous;
1309
+ for (let i = 0n; i < len; i++) {
1310
+ let index;
1311
+ if (previous === void 0) {
1312
+ const encoded = this.varint();
1313
+ if (encoded > U32_MAX) {
1314
+ throw new Error("digest encoding has a bucket index outside i32");
1315
+ }
1316
+ index = encoded >> 1n ^ -(encoded & 1n);
1144
1317
  } else {
1145
- if (value !== 0 && Math.abs(value) < _Float4Value.MIN_POSITIVE) {
1146
- this.value = 0;
1147
- } else if (value > _Float4Value.MAX_VALUE) {
1148
- throw new Error(`Float4 overflow: value ${value} exceeds maximum ${_Float4Value.MAX_VALUE}`);
1149
- } else if (value < _Float4Value.MIN_VALUE) {
1150
- throw new Error(`Float4 underflow: value ${value} exceeds minimum ${_Float4Value.MIN_VALUE}`);
1151
- } else {
1152
- const float32Array = new Float32Array(1);
1153
- float32Array[0] = value;
1154
- this.value = float32Array[0];
1318
+ const delta = this.varint();
1319
+ if (delta === 0n) {
1320
+ throw new Error(`digest encoding repeats bucket index ${previous}`);
1321
+ }
1322
+ index = previous + delta;
1323
+ if (index > I32_MAX) {
1324
+ throw new Error("digest encoding has a bucket index outside i32");
1155
1325
  }
1156
1326
  }
1327
+ const count = this.varint();
1328
+ if (count === 0n) {
1329
+ throw new Error(`digest encoding has a zero count at bucket ${index}`);
1330
+ }
1331
+ total += count;
1332
+ previous = index;
1333
+ }
1334
+ return total;
1335
+ }
1336
+ };
1337
+
1338
+ // src/value/fixed-point.ts
1339
+ var FIXED_POINT_MAX_PRECISION = 76;
1340
+ var FIXED_POINT_NARROW_PRECISION = 38;
1341
+ var DECIMAL_DEFAULT_SCALE = 10;
1342
+ function checkPrecision(kind, precision) {
1343
+ if (!Number.isInteger(precision) || precision < 1 || precision > FIXED_POINT_MAX_PRECISION) {
1344
+ throw new Error(`${kind} precision must be a whole number between 1 and ${FIXED_POINT_MAX_PRECISION}, got ${precision}`);
1345
+ }
1346
+ }
1347
+ function decimalType(precision = FIXED_POINT_MAX_PRECISION, scale = DECIMAL_DEFAULT_SCALE) {
1348
+ checkPrecision("Decimal", precision);
1349
+ if (!Number.isInteger(scale) || scale < 0 || scale > precision) {
1350
+ throw new Error(`Decimal scale must be a whole number between 0 and the precision ${precision}, got ${scale}`);
1351
+ }
1352
+ return { Decimal: { precision, scale } };
1353
+ }
1354
+ function fixedPointType(kind, precision, scale) {
1355
+ switch (kind) {
1356
+ case "Decimal":
1357
+ return decimalType(precision, scale);
1358
+ }
1359
+ }
1360
+ function isFixedPointType(t) {
1361
+ return typeof t === "object" && t !== null && "Decimal" in t;
1362
+ }
1363
+ function fixedPointKind(t) {
1364
+ return "Decimal";
1365
+ }
1366
+ function fixedPointPrecision(t) {
1367
+ return t.Decimal.precision;
1368
+ }
1369
+ function fixedPointScale(t) {
1370
+ return "Decimal" in t ? t.Decimal.scale : 0;
1371
+ }
1372
+ function fixedPointTypeName(t) {
1373
+ const kind = fixedPointKind(t);
1374
+ const precision = fixedPointPrecision(t);
1375
+ if (kind === "Decimal") {
1376
+ const scale = fixedPointScale(t);
1377
+ return precision === FIXED_POINT_MAX_PRECISION && scale === DECIMAL_DEFAULT_SCALE ? kind : `${kind}(${precision}, ${scale})`;
1378
+ }
1379
+ return precision === FIXED_POINT_MAX_PRECISION ? kind : `${kind}(${precision})`;
1380
+ }
1381
+
1382
+ // src/value/float4.ts
1383
+ var _Float4Value = class _Float4Value {
1384
+ constructor(value) {
1385
+ this.type = "Float4";
1386
+ if (value === void 0) {
1387
+ throw new Error(`Float4 value must be defined, a none is carried by NoneValue`);
1388
+ }
1389
+ if (typeof value !== "number") {
1390
+ throw new Error(`Float4 value must be a number, got ${typeof value}`);
1391
+ }
1392
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
1393
+ throw new Error(`Float4 value must be finite, got ${value}`);
1394
+ }
1395
+ if (value !== 0 && Math.abs(value) < _Float4Value.MIN_POSITIVE) {
1396
+ this.value = 0;
1397
+ } else if (value > _Float4Value.MAX_VALUE) {
1398
+ throw new Error(`Float4 overflow: value ${value} exceeds maximum ${_Float4Value.MAX_VALUE}`);
1399
+ } else if (value < _Float4Value.MIN_VALUE) {
1400
+ throw new Error(`Float4 underflow: value ${value} exceeds minimum ${_Float4Value.MIN_VALUE}`);
1157
1401
  } else {
1158
- this.value = void 0;
1402
+ const float32Array = new Float32Array(1);
1403
+ float32Array[0] = value;
1404
+ this.value = float32Array[0];
1159
1405
  }
1160
1406
  }
1161
1407
  static parse(str) {
1162
1408
  const trimmed = str.trim();
1163
1409
  if (trimmed === "" || trimmed === NONE_VALUE) {
1164
- return new _Float4Value(void 0);
1410
+ throw new Error(`Cannot parse "${str}" as Float4`);
1165
1411
  }
1166
1412
  const num = Number(trimmed);
1167
- if (Number.isNaN(num) && trimmed.toLowerCase() !== "nan") {
1413
+ if (Number.isNaN(num)) {
1168
1414
  throw new Error(`Cannot parse "${str}" as Float4`);
1169
1415
  }
1170
1416
  return new _Float4Value(num);
@@ -1173,7 +1419,7 @@ var _Float4Value = class _Float4Value {
1173
1419
  return this.value;
1174
1420
  }
1175
1421
  toString() {
1176
- return this.value === void 0 ? "none" : this.value.toString();
1422
+ return this.value.toString();
1177
1423
  }
1178
1424
  /**
1179
1425
  * Compare two Float4 values for equality with limited precision
@@ -1190,12 +1436,12 @@ var _Float4Value = class _Float4Value {
1190
1436
  return Math.abs(this.value - otherFloat.value) <= epsilon;
1191
1437
  }
1192
1438
  toJSON() {
1193
- return this.value === void 0 ? null : this.value.toString();
1439
+ return this.value.toString();
1194
1440
  }
1195
1441
  encode() {
1196
1442
  return {
1197
1443
  type: this.type,
1198
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1444
+ value: this.toString()
1199
1445
  };
1200
1446
  }
1201
1447
  };
@@ -1208,22 +1454,24 @@ var Float4Value = _Float4Value;
1208
1454
  var Float8Value = class _Float8Value {
1209
1455
  constructor(value) {
1210
1456
  this.type = "Float8";
1211
- if (value !== void 0) {
1212
- if (typeof value !== "number") {
1213
- throw new Error(`Float8 value must be a number, got ${typeof value}`);
1214
- }
1215
- this.value = value;
1216
- } else {
1217
- this.value = void 0;
1457
+ if (value === void 0) {
1458
+ throw new Error(`Float8 value must be defined, a none is carried by NoneValue`);
1218
1459
  }
1460
+ if (typeof value !== "number") {
1461
+ throw new Error(`Float8 value must be a number, got ${typeof value}`);
1462
+ }
1463
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
1464
+ throw new Error(`Float8 value must be finite, got ${value}`);
1465
+ }
1466
+ this.value = value;
1219
1467
  }
1220
1468
  static parse(str) {
1221
1469
  const trimmed = str.trim();
1222
1470
  if (trimmed === "" || trimmed === NONE_VALUE) {
1223
- return new _Float8Value(void 0);
1471
+ throw new Error(`Cannot parse "${str}" as Float8`);
1224
1472
  }
1225
1473
  const num = Number(trimmed);
1226
- if (Number.isNaN(num) && trimmed.toLowerCase() !== "nan") {
1474
+ if (Number.isNaN(num)) {
1227
1475
  throw new Error(`Cannot parse "${str}" as Float8`);
1228
1476
  }
1229
1477
  return new _Float8Value(num);
@@ -1232,7 +1480,7 @@ var Float8Value = class _Float8Value {
1232
1480
  return this.value;
1233
1481
  }
1234
1482
  toString() {
1235
- return this.value === void 0 ? "none" : this.value.toString();
1483
+ return this.value.toString();
1236
1484
  }
1237
1485
  /**
1238
1486
  * Compare two Float8 values for equality
@@ -1249,12 +1497,12 @@ var Float8Value = class _Float8Value {
1249
1497
  return Math.abs(this.value - otherFloat.value) <= epsilon;
1250
1498
  }
1251
1499
  toJSON() {
1252
- return this.value === void 0 ? null : this.value.toString();
1500
+ return this.value.toString();
1253
1501
  }
1254
1502
  encode() {
1255
1503
  return {
1256
1504
  type: this.type,
1257
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1505
+ value: this.toString()
1258
1506
  };
1259
1507
  }
1260
1508
  };
@@ -1263,20 +1511,21 @@ var Float8Value = class _Float8Value {
1263
1511
  var _Int1Value = class _Int1Value {
1264
1512
  constructor(value) {
1265
1513
  this.type = "Int1";
1266
- if (value !== void 0) {
1267
- if (!Number.isInteger(value)) {
1268
- throw new Error(`Int1 value must be an integer, got ${value}`);
1269
- }
1270
- if (value < _Int1Value.MIN_VALUE || value > _Int1Value.MAX_VALUE) {
1271
- throw new Error(`Int1 value must be between ${_Int1Value.MIN_VALUE} and ${_Int1Value.MAX_VALUE}, got ${value}`);
1272
- }
1514
+ if (value === void 0) {
1515
+ throw new Error(`Int1 value must be defined, a none is carried by NoneValue`);
1516
+ }
1517
+ if (!Number.isInteger(value)) {
1518
+ throw new Error(`Int1 value must be an integer, got ${value}`);
1519
+ }
1520
+ if (value < _Int1Value.MIN_VALUE || value > _Int1Value.MAX_VALUE) {
1521
+ throw new Error(`Int1 value must be between ${_Int1Value.MIN_VALUE} and ${_Int1Value.MAX_VALUE}, got ${value}`);
1273
1522
  }
1274
1523
  this.value = value;
1275
1524
  }
1276
1525
  static parse(str) {
1277
1526
  const trimmed = str.trim();
1278
1527
  if (trimmed === "" || trimmed === NONE_VALUE) {
1279
- return new _Int1Value(void 0);
1528
+ throw new Error(`Cannot parse "${str}" as Int1`);
1280
1529
  }
1281
1530
  const num = Number(trimmed);
1282
1531
  if (isNaN(num)) {
@@ -1288,7 +1537,7 @@ var _Int1Value = class _Int1Value {
1288
1537
  return this.value;
1289
1538
  }
1290
1539
  toString() {
1291
- return this.value === void 0 ? "none" : this.value.toString();
1540
+ return this.value.toString();
1292
1541
  }
1293
1542
  /**
1294
1543
  * Compare two Int1 values for equality
@@ -1301,12 +1550,12 @@ var _Int1Value = class _Int1Value {
1301
1550
  return this.value === otherInt.value;
1302
1551
  }
1303
1552
  toJSON() {
1304
- return this.value === void 0 ? null : this.value.toString();
1553
+ return this.value.toString();
1305
1554
  }
1306
1555
  encode() {
1307
1556
  return {
1308
1557
  type: this.type,
1309
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1558
+ value: this.toString()
1310
1559
  };
1311
1560
  }
1312
1561
  };
@@ -1318,20 +1567,21 @@ var Int1Value = _Int1Value;
1318
1567
  var _Int2Value = class _Int2Value {
1319
1568
  constructor(value) {
1320
1569
  this.type = "Int2";
1321
- if (value !== void 0) {
1322
- if (!Number.isInteger(value)) {
1323
- throw new Error(`Int2 value must be an integer, got ${value}`);
1324
- }
1325
- if (value < _Int2Value.MIN_VALUE || value > _Int2Value.MAX_VALUE) {
1326
- throw new Error(`Int2 value must be between ${_Int2Value.MIN_VALUE} and ${_Int2Value.MAX_VALUE}, got ${value}`);
1327
- }
1570
+ if (value === void 0) {
1571
+ throw new Error(`Int2 value must be defined, a none is carried by NoneValue`);
1572
+ }
1573
+ if (!Number.isInteger(value)) {
1574
+ throw new Error(`Int2 value must be an integer, got ${value}`);
1575
+ }
1576
+ if (value < _Int2Value.MIN_VALUE || value > _Int2Value.MAX_VALUE) {
1577
+ throw new Error(`Int2 value must be between ${_Int2Value.MIN_VALUE} and ${_Int2Value.MAX_VALUE}, got ${value}`);
1328
1578
  }
1329
1579
  this.value = value;
1330
1580
  }
1331
1581
  static parse(str) {
1332
1582
  const trimmed = str.trim();
1333
1583
  if (trimmed === "" || trimmed === NONE_VALUE) {
1334
- return new _Int2Value(void 0);
1584
+ throw new Error(`Cannot parse "${str}" as Int2`);
1335
1585
  }
1336
1586
  const num = Number(trimmed);
1337
1587
  if (isNaN(num)) {
@@ -1343,7 +1593,7 @@ var _Int2Value = class _Int2Value {
1343
1593
  return this.value;
1344
1594
  }
1345
1595
  toString() {
1346
- return this.value === void 0 ? "none" : this.value.toString();
1596
+ return this.value.toString();
1347
1597
  }
1348
1598
  /**
1349
1599
  * Compare two Int2 values for equality
@@ -1356,12 +1606,12 @@ var _Int2Value = class _Int2Value {
1356
1606
  return this.value === otherInt.value;
1357
1607
  }
1358
1608
  toJSON() {
1359
- return this.value === void 0 ? null : this.value.toString();
1609
+ return this.value.toString();
1360
1610
  }
1361
1611
  encode() {
1362
1612
  return {
1363
1613
  type: this.type,
1364
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1614
+ value: this.toString()
1365
1615
  };
1366
1616
  }
1367
1617
  };
@@ -1373,20 +1623,21 @@ var Int2Value = _Int2Value;
1373
1623
  var _Int4Value = class _Int4Value {
1374
1624
  constructor(value) {
1375
1625
  this.type = "Int4";
1376
- if (value !== void 0) {
1377
- if (!Number.isInteger(value)) {
1378
- throw new Error(`Int4 value must be an integer, got ${value}`);
1379
- }
1380
- if (value < _Int4Value.MIN_VALUE || value > _Int4Value.MAX_VALUE) {
1381
- throw new Error(`Int4 value must be between ${_Int4Value.MIN_VALUE} and ${_Int4Value.MAX_VALUE}, got ${value}`);
1382
- }
1626
+ if (value === void 0) {
1627
+ throw new Error(`Int4 value must be defined, a none is carried by NoneValue`);
1628
+ }
1629
+ if (!Number.isInteger(value)) {
1630
+ throw new Error(`Int4 value must be an integer, got ${value}`);
1631
+ }
1632
+ if (value < _Int4Value.MIN_VALUE || value > _Int4Value.MAX_VALUE) {
1633
+ throw new Error(`Int4 value must be between ${_Int4Value.MIN_VALUE} and ${_Int4Value.MAX_VALUE}, got ${value}`);
1383
1634
  }
1384
1635
  this.value = value;
1385
1636
  }
1386
1637
  static parse(str) {
1387
1638
  const trimmed = str.trim();
1388
1639
  if (trimmed === "" || trimmed === NONE_VALUE) {
1389
- return new _Int4Value(void 0);
1640
+ throw new Error(`Cannot parse "${str}" as Int4`);
1390
1641
  }
1391
1642
  const num = Number(trimmed);
1392
1643
  if (isNaN(num)) {
@@ -1398,7 +1649,7 @@ var _Int4Value = class _Int4Value {
1398
1649
  return this.value;
1399
1650
  }
1400
1651
  toString() {
1401
- return this.value === void 0 ? "none" : this.value.toString();
1652
+ return this.value.toString();
1402
1653
  }
1403
1654
  /**
1404
1655
  * Compare two Int4 values for equality
@@ -1411,12 +1662,12 @@ var _Int4Value = class _Int4Value {
1411
1662
  return this.value === otherInt.value;
1412
1663
  }
1413
1664
  toJSON() {
1414
- return this.value === void 0 ? null : this.value.toString();
1665
+ return this.value.toString();
1415
1666
  }
1416
1667
  encode() {
1417
1668
  return {
1418
1669
  type: this.type,
1419
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1670
+ value: this.toString()
1420
1671
  };
1421
1672
  }
1422
1673
  };
@@ -1428,20 +1679,19 @@ var Int4Value = _Int4Value;
1428
1679
  var _Int8Value = class _Int8Value {
1429
1680
  constructor(value) {
1430
1681
  this.type = "Int8";
1431
- if (value !== void 0) {
1432
- const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
1433
- if (bigintValue < _Int8Value.MIN_VALUE || bigintValue > _Int8Value.MAX_VALUE) {
1434
- throw new Error(`Int8 value must be between ${_Int8Value.MIN_VALUE} and ${_Int8Value.MAX_VALUE}, got ${bigintValue}`);
1435
- }
1436
- this.value = bigintValue;
1437
- } else {
1438
- this.value = void 0;
1682
+ if (value === void 0) {
1683
+ throw new Error(`Int8 value must be defined, a none is carried by NoneValue`);
1684
+ }
1685
+ const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
1686
+ if (bigintValue < _Int8Value.MIN_VALUE || bigintValue > _Int8Value.MAX_VALUE) {
1687
+ throw new Error(`Int8 value must be between ${_Int8Value.MIN_VALUE} and ${_Int8Value.MAX_VALUE}, got ${bigintValue}`);
1439
1688
  }
1689
+ this.value = bigintValue;
1440
1690
  }
1441
1691
  static parse(str) {
1442
1692
  const trimmed = str.trim();
1443
1693
  if (trimmed === "" || trimmed === NONE_VALUE) {
1444
- return new _Int8Value(void 0);
1694
+ throw new Error(`Cannot parse "${str}" as Int8`);
1445
1695
  }
1446
1696
  let value;
1447
1697
  try {
@@ -1458,7 +1708,7 @@ var _Int8Value = class _Int8Value {
1458
1708
  return this.value;
1459
1709
  }
1460
1710
  toString() {
1461
- return this.value === void 0 ? "none" : this.value.toString();
1711
+ return this.value.toString();
1462
1712
  }
1463
1713
  /**
1464
1714
  * Compare two Int8 values for equality
@@ -1471,12 +1721,12 @@ var _Int8Value = class _Int8Value {
1471
1721
  return this.value === otherInt.value;
1472
1722
  }
1473
1723
  toJSON() {
1474
- return this.value === void 0 ? null : this.value.toString();
1724
+ return this.value.toString();
1475
1725
  }
1476
1726
  encode() {
1477
1727
  return {
1478
1728
  type: this.type,
1479
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1729
+ value: this.toString()
1480
1730
  };
1481
1731
  }
1482
1732
  };
@@ -1488,31 +1738,30 @@ var Int8Value = _Int8Value;
1488
1738
  var _Int16Value = class _Int16Value {
1489
1739
  constructor(value) {
1490
1740
  this.type = "Int16";
1491
- if (value !== void 0) {
1492
- let bigintValue;
1493
- if (typeof value === "string") {
1494
- try {
1495
- bigintValue = BigInt(value);
1496
- } catch (e) {
1497
- throw new Error(`Int16 value must be a valid integer, got ${value}`);
1498
- }
1499
- } else if (typeof value === "number") {
1500
- bigintValue = BigInt(Math.trunc(value));
1501
- } else {
1502
- bigintValue = value;
1503
- }
1504
- if (bigintValue < _Int16Value.MIN_VALUE || bigintValue > _Int16Value.MAX_VALUE) {
1505
- throw new Error(`Int16 value must be between ${_Int16Value.MIN_VALUE} and ${_Int16Value.MAX_VALUE}, got ${bigintValue}`);
1741
+ if (value === void 0) {
1742
+ throw new Error(`Int16 value must be defined, a none is carried by NoneValue`);
1743
+ }
1744
+ let bigintValue;
1745
+ if (typeof value === "string") {
1746
+ try {
1747
+ bigintValue = BigInt(value);
1748
+ } catch (e) {
1749
+ throw new Error(`Int16 value must be a valid integer, got ${value}`);
1506
1750
  }
1507
- this.value = bigintValue;
1751
+ } else if (typeof value === "number") {
1752
+ bigintValue = BigInt(Math.trunc(value));
1508
1753
  } else {
1509
- this.value = void 0;
1754
+ bigintValue = value;
1510
1755
  }
1756
+ if (bigintValue < _Int16Value.MIN_VALUE || bigintValue > _Int16Value.MAX_VALUE) {
1757
+ throw new Error(`Int16 value must be between ${_Int16Value.MIN_VALUE} and ${_Int16Value.MAX_VALUE}, got ${bigintValue}`);
1758
+ }
1759
+ this.value = bigintValue;
1511
1760
  }
1512
1761
  static parse(str) {
1513
1762
  const trimmed = str.trim();
1514
1763
  if (trimmed === "" || trimmed === NONE_VALUE) {
1515
- return new _Int16Value(void 0);
1764
+ throw new Error(`Cannot parse "${str}" as Int16`);
1516
1765
  }
1517
1766
  let value;
1518
1767
  try {
@@ -1529,7 +1778,7 @@ var _Int16Value = class _Int16Value {
1529
1778
  return this.value;
1530
1779
  }
1531
1780
  toString() {
1532
- return this.value === void 0 ? "none" : this.value.toString();
1781
+ return this.value.toString();
1533
1782
  }
1534
1783
  /**
1535
1784
  * Compare two Int16 values for equality
@@ -1542,12 +1791,12 @@ var _Int16Value = class _Int16Value {
1542
1791
  return this.value === otherInt.value;
1543
1792
  }
1544
1793
  toJSON() {
1545
- return this.value === void 0 ? null : this.value.toString();
1794
+ return this.value.toString();
1546
1795
  }
1547
1796
  encode() {
1548
1797
  return {
1549
1798
  type: this.type,
1550
- value: this.value === void 0 ? NONE_VALUE : this.toString()
1799
+ value: this.toString()
1551
1800
  };
1552
1801
  }
1553
1802
  };
@@ -1560,26 +1809,23 @@ var DurationValue = class _DurationValue {
1560
1809
  // all time components as nanoseconds
1561
1810
  constructor(value) {
1562
1811
  this.type = "Duration";
1563
- if (value !== void 0) {
1564
- if (typeof value === "string") {
1565
- const parsed = _DurationValue.parseDuration(value);
1566
- if (!parsed) {
1567
- throw new Error(`Invalid duration string: ${value}`);
1568
- }
1569
- this.months = parsed.months;
1570
- this.days = parsed.days;
1571
- this.nanos = parsed.nanos;
1572
- } else if (typeof value === "object" && value !== null) {
1573
- this.months = value.months;
1574
- this.days = value.days;
1575
- this.nanos = value.nanos;
1576
- } else {
1577
- throw new Error(`Duration value must be an object or string, got ${typeof value}`);
1812
+ if (value === void 0) {
1813
+ throw new Error(`Duration value must be defined, a none is carried by NoneValue`);
1814
+ }
1815
+ if (typeof value === "string") {
1816
+ const parsed = _DurationValue.parseDuration(value);
1817
+ if (!parsed) {
1818
+ throw new Error(`Invalid duration string: ${value}`);
1578
1819
  }
1820
+ this.months = parsed.months;
1821
+ this.days = parsed.days;
1822
+ this.nanos = parsed.nanos;
1823
+ } else if (typeof value === "object" && value !== null) {
1824
+ this.months = value.months;
1825
+ this.days = value.days;
1826
+ this.nanos = value.nanos;
1579
1827
  } else {
1580
- this.months = void 0;
1581
- this.days = void 0;
1582
- this.nanos = void 0;
1828
+ throw new Error(`Duration value must be an object or string, got ${typeof value}`);
1583
1829
  }
1584
1830
  }
1585
1831
  /**
@@ -1666,7 +1912,7 @@ var DurationValue = class _DurationValue {
1666
1912
  static parse(str) {
1667
1913
  const trimmed = str.trim();
1668
1914
  if (trimmed === "" || trimmed === NONE_VALUE) {
1669
- return new _DurationValue(void 0);
1915
+ throw new Error(`Cannot parse "${str}" as Duration`);
1670
1916
  }
1671
1917
  const parsed = _DurationValue.parseDuration(trimmed);
1672
1918
  if (!parsed) {
@@ -1741,9 +1987,6 @@ var DurationValue = class _DurationValue {
1741
1987
  * Get absolute value of duration
1742
1988
  */
1743
1989
  abs() {
1744
- if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1745
- return new _DurationValue(void 0);
1746
- }
1747
1990
  return new _DurationValue({
1748
1991
  months: Math.abs(this.months),
1749
1992
  days: Math.abs(this.days),
@@ -1754,9 +1997,6 @@ var DurationValue = class _DurationValue {
1754
1997
  * Negate the duration
1755
1998
  */
1756
1999
  negate() {
1757
- if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1758
- return new _DurationValue(void 0);
1759
- }
1760
2000
  return new _DurationValue({
1761
2001
  months: -this.months,
1762
2002
  days: -this.days,
@@ -1952,7 +2192,7 @@ var DurationValue = class _DurationValue {
1952
2192
  return this.months === otherDuration.months && this.days === otherDuration.days && this.nanos === otherDuration.nanos;
1953
2193
  }
1954
2194
  toJSON() {
1955
- return this.months === void 0 ? null : this.toIsoString();
2195
+ return this.toIsoString();
1956
2196
  }
1957
2197
  encode() {
1958
2198
  return {
@@ -1966,20 +2206,21 @@ var DurationValue = class _DurationValue {
1966
2206
  var _Uint1Value = class _Uint1Value {
1967
2207
  constructor(value) {
1968
2208
  this.type = "Uint1";
1969
- if (value !== void 0) {
1970
- if (!Number.isInteger(value)) {
1971
- throw new Error(`Uint1 value must be an integer, got ${value}`);
1972
- }
1973
- if (value < _Uint1Value.MIN_VALUE || value > _Uint1Value.MAX_VALUE) {
1974
- throw new Error(`Uint1 value must be between ${_Uint1Value.MIN_VALUE} and ${_Uint1Value.MAX_VALUE}, got ${value}`);
1975
- }
2209
+ if (value === void 0) {
2210
+ throw new Error(`Uint1 value must be defined, a none is carried by NoneValue`);
2211
+ }
2212
+ if (!Number.isInteger(value)) {
2213
+ throw new Error(`Uint1 value must be an integer, got ${value}`);
2214
+ }
2215
+ if (value < _Uint1Value.MIN_VALUE || value > _Uint1Value.MAX_VALUE) {
2216
+ throw new Error(`Uint1 value must be between ${_Uint1Value.MIN_VALUE} and ${_Uint1Value.MAX_VALUE}, got ${value}`);
1976
2217
  }
1977
2218
  this.value = value;
1978
2219
  }
1979
2220
  static parse(str) {
1980
2221
  const trimmed = str.trim();
1981
2222
  if (trimmed === "" || trimmed === NONE_VALUE) {
1982
- return new _Uint1Value(void 0);
2223
+ throw new Error(`Cannot parse "${str}" as Uint1`);
1983
2224
  }
1984
2225
  const num = Number(trimmed);
1985
2226
  if (isNaN(num)) {
@@ -1991,7 +2232,7 @@ var _Uint1Value = class _Uint1Value {
1991
2232
  return this.value;
1992
2233
  }
1993
2234
  toString() {
1994
- return this.value === void 0 ? "none" : this.value.toString();
2235
+ return this.value.toString();
1995
2236
  }
1996
2237
  /**
1997
2238
  * Compare two Uint1 values for equality
@@ -2004,12 +2245,12 @@ var _Uint1Value = class _Uint1Value {
2004
2245
  return this.value === otherUint.value;
2005
2246
  }
2006
2247
  toJSON() {
2007
- return this.value === void 0 ? null : this.value.toString();
2248
+ return this.value.toString();
2008
2249
  }
2009
2250
  encode() {
2010
2251
  return {
2011
2252
  type: this.type,
2012
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2253
+ value: this.toString()
2013
2254
  };
2014
2255
  }
2015
2256
  };
@@ -2021,20 +2262,21 @@ var Uint1Value = _Uint1Value;
2021
2262
  var _Uint2Value = class _Uint2Value {
2022
2263
  constructor(value) {
2023
2264
  this.type = "Uint2";
2024
- if (value !== void 0) {
2025
- if (!Number.isInteger(value)) {
2026
- throw new Error(`Uint2 value must be an integer, got ${value}`);
2027
- }
2028
- if (value < _Uint2Value.MIN_VALUE || value > _Uint2Value.MAX_VALUE) {
2029
- throw new Error(`Uint2 value must be between ${_Uint2Value.MIN_VALUE} and ${_Uint2Value.MAX_VALUE}, got ${value}`);
2030
- }
2265
+ if (value === void 0) {
2266
+ throw new Error(`Uint2 value must be defined, a none is carried by NoneValue`);
2267
+ }
2268
+ if (!Number.isInteger(value)) {
2269
+ throw new Error(`Uint2 value must be an integer, got ${value}`);
2270
+ }
2271
+ if (value < _Uint2Value.MIN_VALUE || value > _Uint2Value.MAX_VALUE) {
2272
+ throw new Error(`Uint2 value must be between ${_Uint2Value.MIN_VALUE} and ${_Uint2Value.MAX_VALUE}, got ${value}`);
2031
2273
  }
2032
2274
  this.value = value;
2033
2275
  }
2034
2276
  static parse(str) {
2035
2277
  const trimmed = str.trim();
2036
2278
  if (trimmed === "" || trimmed === NONE_VALUE) {
2037
- return new _Uint2Value(void 0);
2279
+ throw new Error(`Cannot parse "${str}" as Uint2`);
2038
2280
  }
2039
2281
  const num = Number(trimmed);
2040
2282
  if (isNaN(num)) {
@@ -2046,7 +2288,7 @@ var _Uint2Value = class _Uint2Value {
2046
2288
  return this.value;
2047
2289
  }
2048
2290
  toString() {
2049
- return this.value === void 0 ? "none" : this.value.toString();
2291
+ return this.value.toString();
2050
2292
  }
2051
2293
  /**
2052
2294
  * Compare two Uint2 values for equality
@@ -2059,12 +2301,12 @@ var _Uint2Value = class _Uint2Value {
2059
2301
  return this.value === otherUint.value;
2060
2302
  }
2061
2303
  toJSON() {
2062
- return this.value === void 0 ? null : this.value.toString();
2304
+ return this.value.toString();
2063
2305
  }
2064
2306
  encode() {
2065
2307
  return {
2066
2308
  type: this.type,
2067
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2309
+ value: this.toString()
2068
2310
  };
2069
2311
  }
2070
2312
  };
@@ -2076,20 +2318,21 @@ var Uint2Value = _Uint2Value;
2076
2318
  var _Uint4Value = class _Uint4Value {
2077
2319
  constructor(value) {
2078
2320
  this.type = "Uint4";
2079
- if (value !== void 0) {
2080
- if (!Number.isInteger(value)) {
2081
- throw new Error(`Uint4 value must be an integer, got ${value}`);
2082
- }
2083
- if (value < _Uint4Value.MIN_VALUE || value > _Uint4Value.MAX_VALUE) {
2084
- throw new Error(`Uint4 value must be between ${_Uint4Value.MIN_VALUE} and ${_Uint4Value.MAX_VALUE}, got ${value}`);
2085
- }
2321
+ if (value === void 0) {
2322
+ throw new Error(`Uint4 value must be defined, a none is carried by NoneValue`);
2323
+ }
2324
+ if (!Number.isInteger(value)) {
2325
+ throw new Error(`Uint4 value must be an integer, got ${value}`);
2326
+ }
2327
+ if (value < _Uint4Value.MIN_VALUE || value > _Uint4Value.MAX_VALUE) {
2328
+ throw new Error(`Uint4 value must be between ${_Uint4Value.MIN_VALUE} and ${_Uint4Value.MAX_VALUE}, got ${value}`);
2086
2329
  }
2087
2330
  this.value = value;
2088
2331
  }
2089
2332
  static parse(str) {
2090
2333
  const trimmed = str.trim();
2091
2334
  if (trimmed === "" || trimmed === NONE_VALUE) {
2092
- return new _Uint4Value(void 0);
2335
+ throw new Error(`Cannot parse "${str}" as Uint4`);
2093
2336
  }
2094
2337
  const num = Number(trimmed);
2095
2338
  if (isNaN(num)) {
@@ -2101,7 +2344,7 @@ var _Uint4Value = class _Uint4Value {
2101
2344
  return this.value;
2102
2345
  }
2103
2346
  toString() {
2104
- return this.value === void 0 ? "none" : this.value.toString();
2347
+ return this.value.toString();
2105
2348
  }
2106
2349
  /**
2107
2350
  * Compare two Uint4 values for equality
@@ -2114,12 +2357,12 @@ var _Uint4Value = class _Uint4Value {
2114
2357
  return this.value === otherUint.value;
2115
2358
  }
2116
2359
  toJSON() {
2117
- return this.value === void 0 ? null : this.value.toString();
2360
+ return this.value.toString();
2118
2361
  }
2119
2362
  encode() {
2120
2363
  return {
2121
2364
  type: this.type,
2122
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2365
+ value: this.toString()
2123
2366
  };
2124
2367
  }
2125
2368
  };
@@ -2131,20 +2374,19 @@ var Uint4Value = _Uint4Value;
2131
2374
  var _Uint8Value = class _Uint8Value {
2132
2375
  constructor(value) {
2133
2376
  this.type = "Uint8";
2134
- if (value !== void 0) {
2135
- const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
2136
- if (bigintValue < _Uint8Value.MIN_VALUE || bigintValue > _Uint8Value.MAX_VALUE) {
2137
- throw new Error(`Uint8 value must be between ${_Uint8Value.MIN_VALUE} and ${_Uint8Value.MAX_VALUE}, got ${bigintValue}`);
2138
- }
2139
- this.value = bigintValue;
2140
- } else {
2141
- this.value = void 0;
2377
+ if (value === void 0) {
2378
+ throw new Error(`Uint8 value must be defined, a none is carried by NoneValue`);
2379
+ }
2380
+ const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
2381
+ if (bigintValue < _Uint8Value.MIN_VALUE || bigintValue > _Uint8Value.MAX_VALUE) {
2382
+ throw new Error(`Uint8 value must be between ${_Uint8Value.MIN_VALUE} and ${_Uint8Value.MAX_VALUE}, got ${bigintValue}`);
2142
2383
  }
2384
+ this.value = bigintValue;
2143
2385
  }
2144
2386
  static parse(str) {
2145
2387
  const trimmed = str.trim();
2146
2388
  if (trimmed === "" || trimmed === NONE_VALUE) {
2147
- return new _Uint8Value(void 0);
2389
+ throw new Error(`Cannot parse "${str}" as Uint8`);
2148
2390
  }
2149
2391
  let value;
2150
2392
  try {
@@ -2165,7 +2407,7 @@ var _Uint8Value = class _Uint8Value {
2165
2407
  return Number(this.value);
2166
2408
  }
2167
2409
  toString() {
2168
- return this.value === void 0 ? "none" : this.value.toString();
2410
+ return this.value.toString();
2169
2411
  }
2170
2412
  /**
2171
2413
  * Compare two Uint8 values for equality
@@ -2178,12 +2420,12 @@ var _Uint8Value = class _Uint8Value {
2178
2420
  return this.value === otherUint.value;
2179
2421
  }
2180
2422
  toJSON() {
2181
- return this.value === void 0 ? null : this.value.toString();
2423
+ return this.value.toString();
2182
2424
  }
2183
2425
  encode() {
2184
2426
  return {
2185
2427
  type: this.type,
2186
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2428
+ value: this.toString()
2187
2429
  };
2188
2430
  }
2189
2431
  };
@@ -2195,31 +2437,30 @@ var Uint8Value = _Uint8Value;
2195
2437
  var _Uint16Value = class _Uint16Value {
2196
2438
  constructor(value) {
2197
2439
  this.type = "Uint16";
2198
- if (value !== void 0) {
2199
- let bigintValue;
2200
- if (typeof value === "string") {
2201
- try {
2202
- bigintValue = BigInt(value);
2203
- } catch (e) {
2204
- throw new Error(`Uint16 value must be a valid integer, got ${value}`);
2205
- }
2206
- } else if (typeof value === "number") {
2207
- bigintValue = BigInt(Math.trunc(value));
2208
- } else {
2209
- bigintValue = value;
2210
- }
2211
- if (bigintValue < _Uint16Value.MIN_VALUE || bigintValue > _Uint16Value.MAX_VALUE) {
2212
- throw new Error(`Uint16 value must be between ${_Uint16Value.MIN_VALUE} and ${_Uint16Value.MAX_VALUE}, got ${bigintValue}`);
2440
+ if (value === void 0) {
2441
+ throw new Error(`Uint16 value must be defined, a none is carried by NoneValue`);
2442
+ }
2443
+ let bigintValue;
2444
+ if (typeof value === "string") {
2445
+ try {
2446
+ bigintValue = BigInt(value);
2447
+ } catch (e) {
2448
+ throw new Error(`Uint16 value must be a valid integer, got ${value}`);
2213
2449
  }
2214
- this.value = bigintValue;
2450
+ } else if (typeof value === "number") {
2451
+ bigintValue = BigInt(Math.trunc(value));
2215
2452
  } else {
2216
- this.value = void 0;
2453
+ bigintValue = value;
2454
+ }
2455
+ if (bigintValue < _Uint16Value.MIN_VALUE || bigintValue > _Uint16Value.MAX_VALUE) {
2456
+ throw new Error(`Uint16 value must be between ${_Uint16Value.MIN_VALUE} and ${_Uint16Value.MAX_VALUE}, got ${bigintValue}`);
2217
2457
  }
2458
+ this.value = bigintValue;
2218
2459
  }
2219
2460
  static parse(str) {
2220
2461
  const trimmed = str.trim();
2221
2462
  if (trimmed === "" || trimmed === NONE_VALUE) {
2222
- return new _Uint16Value(void 0);
2463
+ throw new Error(`Cannot parse "${str}" as Uint16`);
2223
2464
  }
2224
2465
  let value;
2225
2466
  try {
@@ -2236,7 +2477,7 @@ var _Uint16Value = class _Uint16Value {
2236
2477
  return this.value;
2237
2478
  }
2238
2479
  toString() {
2239
- return this.value === void 0 ? "none" : this.value.toString();
2480
+ return this.value.toString();
2240
2481
  }
2241
2482
  /**
2242
2483
  * Compare two Uint16 values for equality
@@ -2249,12 +2490,12 @@ var _Uint16Value = class _Uint16Value {
2249
2490
  return this.value === otherUint.value;
2250
2491
  }
2251
2492
  toJSON() {
2252
- return this.value === void 0 ? null : this.value.toString();
2493
+ return this.value.toString();
2253
2494
  }
2254
2495
  encode() {
2255
2496
  return {
2256
2497
  type: this.type,
2257
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2498
+ value: this.toString()
2258
2499
  };
2259
2500
  }
2260
2501
  };
@@ -2383,7 +2624,22 @@ function formatValue(value) {
2383
2624
 
2384
2625
  // src/value/option.ts
2385
2626
  function describeType(t) {
2386
- return isOptionType(t) ? `Option(${describeType(t.Option)})` : t;
2627
+ if (isDigestType(t)) {
2628
+ return digestTypeName(t);
2629
+ }
2630
+ if (isFixedPointType(t)) {
2631
+ return fixedPointTypeName(t);
2632
+ }
2633
+ if (isOptionType(t)) {
2634
+ return `Option(${describeType(t.Option)})`;
2635
+ }
2636
+ if (isListType(t)) {
2637
+ return `List(${describeType(t.List)})`;
2638
+ }
2639
+ if (isRecordType(t)) {
2640
+ return `Record(${t.Record.map((field) => `${field.name}: ${describeType(field.type)}`).join(", ")})`;
2641
+ }
2642
+ return t;
2387
2643
  }
2388
2644
  function hasType(value) {
2389
2645
  return typeof value === "object" && value !== null && "type" in value;
@@ -2451,18 +2707,17 @@ var Option = _Option;
2451
2707
  var Utf8Value = class _Utf8Value {
2452
2708
  constructor(value) {
2453
2709
  this.type = "Utf8";
2454
- if (value !== void 0) {
2455
- if (typeof value !== "string") {
2456
- throw new Error(`Utf8 value must be a string, got ${typeof value}`);
2457
- }
2458
- this.value = value;
2459
- } else {
2460
- this.value = void 0;
2710
+ if (value === void 0) {
2711
+ throw new Error(`Utf8 value must be defined, a none is carried by NoneValue`);
2712
+ }
2713
+ if (typeof value !== "string") {
2714
+ throw new Error(`Utf8 value must be a string, got ${typeof value}`);
2461
2715
  }
2716
+ this.value = value;
2462
2717
  }
2463
2718
  static parse(str) {
2464
2719
  if (str === NONE_VALUE) {
2465
- return new _Utf8Value(void 0);
2720
+ throw new Error(`Cannot parse "${str}" as Utf8`);
2466
2721
  }
2467
2722
  return new _Utf8Value(str);
2468
2723
  }
@@ -2470,7 +2725,7 @@ var Utf8Value = class _Utf8Value {
2470
2725
  return this.value;
2471
2726
  }
2472
2727
  toString() {
2473
- return this.value === void 0 ? "none" : this.value;
2728
+ return this.value;
2474
2729
  }
2475
2730
  /**
2476
2731
  * Compare two Utf8 values for equality
@@ -2488,7 +2743,7 @@ var Utf8Value = class _Utf8Value {
2488
2743
  encode() {
2489
2744
  return {
2490
2745
  type: this.type,
2491
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2746
+ value: this.toString()
2492
2747
  };
2493
2748
  }
2494
2749
  };
@@ -2498,21 +2753,20 @@ import { v4 as uuidv4, NIL as NIL_UUID, validate, version } from "uuid";
2498
2753
  var Uuid4Value = class _Uuid4Value {
2499
2754
  constructor(value) {
2500
2755
  this.type = "Uuid4";
2501
- if (value !== void 0) {
2502
- if (typeof value !== "string") {
2503
- throw new Error(`Uuid4 value must be a string, got ${typeof value}`);
2504
- }
2505
- if (!validate(value)) {
2506
- throw new Error(`Invalid UUID format: ${value}`);
2507
- }
2508
- const ver = version(value);
2509
- if (value !== NIL_UUID && ver !== 4) {
2510
- throw new Error(`Invalid UUID version for Uuid4: expected v4, got v${ver}`);
2511
- }
2512
- this.uuid = value.toLowerCase();
2513
- } else {
2514
- this.uuid = void 0;
2756
+ if (value === void 0) {
2757
+ throw new Error(`Uuid4 value must be defined, a none is carried by NoneValue`);
2758
+ }
2759
+ if (typeof value !== "string") {
2760
+ throw new Error(`Uuid4 value must be a string, got ${typeof value}`);
2761
+ }
2762
+ if (!validate(value)) {
2763
+ throw new Error(`Invalid UUID format: ${value}`);
2764
+ }
2765
+ const ver = version(value);
2766
+ if (value !== NIL_UUID && ver !== 4) {
2767
+ throw new Error(`Invalid UUID version for Uuid4: expected v4, got v${ver}`);
2515
2768
  }
2769
+ this.uuid = value.toLowerCase();
2516
2770
  }
2517
2771
  /**
2518
2772
  * Generate a new random UUID v4
@@ -2544,7 +2798,7 @@ var Uuid4Value = class _Uuid4Value {
2544
2798
  static parse(str) {
2545
2799
  const trimmed = str.trim();
2546
2800
  if (trimmed === "" || trimmed === NONE_VALUE) {
2547
- return new _Uuid4Value(void 0);
2801
+ throw new Error(`Cannot parse "${str}" as Uuid4`);
2548
2802
  }
2549
2803
  if (!validate(trimmed)) {
2550
2804
  throw new Error(`Cannot parse "${str}" as Uuid4`);
@@ -2566,10 +2820,10 @@ var Uuid4Value = class _Uuid4Value {
2566
2820
  */
2567
2821
  asBytes() {
2568
2822
  if (this.uuid === void 0) return void 0;
2569
- const hex = this.uuid.replace(/-/g, "");
2823
+ const hex2 = this.uuid.replace(/-/g, "");
2570
2824
  const bytes = new Uint8Array(16);
2571
2825
  for (let i = 0; i < 16; i++) {
2572
- bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
2826
+ bytes[i] = parseInt(hex2.substring(i * 2, i * 2 + 2), 16);
2573
2827
  }
2574
2828
  return bytes;
2575
2829
  }
@@ -2637,7 +2891,7 @@ var Uuid4Value = class _Uuid4Value {
2637
2891
  encode() {
2638
2892
  return {
2639
2893
  type: this.type,
2640
- value: this.value === void 0 ? NONE_VALUE : this.toString()
2894
+ value: this.toString()
2641
2895
  };
2642
2896
  }
2643
2897
  };
@@ -2647,21 +2901,20 @@ import { v7 as uuidv7, NIL as NIL_UUID2, validate as validate2, version as versi
2647
2901
  var Uuid7Value = class _Uuid7Value {
2648
2902
  constructor(value) {
2649
2903
  this.type = "Uuid7";
2650
- if (value !== void 0) {
2651
- if (typeof value !== "string") {
2652
- throw new Error(`Uuid7 value must be a string, got ${typeof value}`);
2653
- }
2654
- if (!validate2(value)) {
2655
- throw new Error(`Invalid UUID format: ${value}`);
2656
- }
2657
- const ver = version2(value);
2658
- if (value !== NIL_UUID2 && ver !== 7) {
2659
- throw new Error(`Invalid UUID version for Uuid7: expected v7, got v${ver}`);
2660
- }
2661
- this.uuid = value.toLowerCase();
2662
- } else {
2663
- this.uuid = void 0;
2904
+ if (value === void 0) {
2905
+ throw new Error(`Uuid7 value must be defined, a none is carried by NoneValue`);
2664
2906
  }
2907
+ if (typeof value !== "string") {
2908
+ throw new Error(`Uuid7 value must be a string, got ${typeof value}`);
2909
+ }
2910
+ if (!validate2(value)) {
2911
+ throw new Error(`Invalid UUID format: ${value}`);
2912
+ }
2913
+ const ver = version2(value);
2914
+ if (value !== NIL_UUID2 && ver !== 7) {
2915
+ throw new Error(`Invalid UUID version for Uuid7: expected v7, got v${ver}`);
2916
+ }
2917
+ this.uuid = value.toLowerCase();
2665
2918
  }
2666
2919
  /**
2667
2920
  * Generate a new timestamp-based UUID v7
@@ -2693,7 +2946,7 @@ var Uuid7Value = class _Uuid7Value {
2693
2946
  static parse(str) {
2694
2947
  const trimmed = str.trim();
2695
2948
  if (trimmed === "" || trimmed === NONE_VALUE) {
2696
- return new _Uuid7Value(void 0);
2949
+ throw new Error(`Cannot parse "${str}" as Uuid7`);
2697
2950
  }
2698
2951
  if (!validate2(trimmed)) {
2699
2952
  throw new Error(`Cannot parse "${str}" as Uuid7`);
@@ -2715,10 +2968,10 @@ var Uuid7Value = class _Uuid7Value {
2715
2968
  */
2716
2969
  asBytes() {
2717
2970
  if (this.uuid === void 0) return void 0;
2718
- const hex = this.uuid.replace(/-/g, "");
2971
+ const hex2 = this.uuid.replace(/-/g, "");
2719
2972
  const bytes = new Uint8Array(16);
2720
2973
  for (let i = 0; i < 16; i++) {
2721
- bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
2974
+ bytes[i] = parseInt(hex2.substring(i * 2, i * 2 + 2), 16);
2722
2975
  }
2723
2976
  return bytes;
2724
2977
  }
@@ -2727,8 +2980,8 @@ var Uuid7Value = class _Uuid7Value {
2727
2980
  */
2728
2981
  getTimestamp() {
2729
2982
  if (this.uuid === void 0 || this.uuid === NIL_UUID2) return void 0;
2730
- const hex = this.uuid.replace(/-/g, "");
2731
- const timestampHex = hex.substring(0, 12);
2983
+ const hex2 = this.uuid.replace(/-/g, "");
2984
+ const timestampHex = hex2.substring(0, 12);
2732
2985
  const timestamp = parseInt(timestampHex, 16);
2733
2986
  return timestamp;
2734
2987
  }
@@ -2797,7 +3050,7 @@ var Uuid7Value = class _Uuid7Value {
2797
3050
  encode() {
2798
3051
  return {
2799
3052
  type: this.type,
2800
- value: this.value === void 0 ? NONE_VALUE : this.toString()
3053
+ value: this.toString()
2801
3054
  };
2802
3055
  }
2803
3056
  };
@@ -2807,21 +3060,20 @@ import { v7 as uuidv72, NIL as NIL_UUID3, validate as validate3, version as vers
2807
3060
  var IdentityIdValue = class _IdentityIdValue {
2808
3061
  constructor(value) {
2809
3062
  this.type = "IdentityId";
2810
- if (value !== void 0) {
2811
- if (typeof value !== "string") {
2812
- throw new Error(`IdentityId value must be a string, got ${typeof value}`);
2813
- }
2814
- if (!validate3(value)) {
2815
- throw new Error(`Invalid UUID format for IdentityId: ${value}`);
2816
- }
2817
- const ver = version3(value);
2818
- if (value !== NIL_UUID3 && ver !== 7) {
2819
- throw new Error(`Invalid UUID version for IdentityId: expected v7, got v${ver}`);
2820
- }
2821
- this.value = value.toLowerCase();
2822
- } else {
2823
- this.value = void 0;
3063
+ if (value === void 0) {
3064
+ throw new Error(`IdentityId value must be defined, a none is carried by NoneValue`);
3065
+ }
3066
+ if (typeof value !== "string") {
3067
+ throw new Error(`IdentityId value must be a string, got ${typeof value}`);
3068
+ }
3069
+ if (!validate3(value)) {
3070
+ throw new Error(`Invalid UUID format for IdentityId: ${value}`);
2824
3071
  }
3072
+ const ver = version3(value);
3073
+ if (value !== NIL_UUID3 && ver !== 7) {
3074
+ throw new Error(`Invalid UUID version for IdentityId: expected v7, got v${ver}`);
3075
+ }
3076
+ this.value = value.toLowerCase();
2825
3077
  }
2826
3078
  /**
2827
3079
  * Generate a new IdentityId with a UUID v7
@@ -2841,7 +3093,7 @@ var IdentityIdValue = class _IdentityIdValue {
2841
3093
  static parse(str) {
2842
3094
  const trimmed = str.trim();
2843
3095
  if (trimmed === "" || trimmed === NONE_VALUE) {
2844
- return new _IdentityIdValue(void 0);
3096
+ throw new Error(`Cannot parse "${str}" as IdentityId`);
2845
3097
  }
2846
3098
  if (!validate3(trimmed)) {
2847
3099
  throw new Error(`Cannot parse "${str}" as IdentityId`);
@@ -2862,15 +3114,15 @@ var IdentityIdValue = class _IdentityIdValue {
2862
3114
  * Format as string
2863
3115
  */
2864
3116
  toString() {
2865
- return this.value === void 0 ? "none" : this.value;
3117
+ return this.value;
2866
3118
  }
2867
3119
  /**
2868
3120
  * Extract the timestamp from the UUID v7 (milliseconds since Unix epoch)
2869
3121
  */
2870
3122
  getTimestamp() {
2871
3123
  if (this.value === void 0 || this.value === NIL_UUID3) return void 0;
2872
- const hex = this.value.replace(/-/g, "");
2873
- const timestampHex = hex.substring(0, 12);
3124
+ const hex2 = this.value.replace(/-/g, "");
3125
+ const timestampHex = hex2.substring(0, 12);
2874
3126
  const timestamp = parseInt(timestampHex, 16);
2875
3127
  return timestamp;
2876
3128
  }
@@ -2896,58 +3148,235 @@ var IdentityIdValue = class _IdentityIdValue {
2896
3148
  encode() {
2897
3149
  return {
2898
3150
  type: this.type,
2899
- value: this.value === void 0 ? NONE_VALUE : this.toString()
3151
+ value: this.toString()
3152
+ };
3153
+ }
3154
+ };
3155
+
3156
+ // src/value/list.ts
3157
+ function hasToJSON2(value) {
3158
+ return typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function";
3159
+ }
3160
+ var ListValue = class _ListValue {
3161
+ constructor(items, elementType) {
3162
+ if (!Array.isArray(items)) {
3163
+ throw new Error(`List value must be an array, got ${typeof items}`);
3164
+ }
3165
+ if (items.length === 0 && elementType === void 0) {
3166
+ throw new Error("An empty List has no element type to infer, pass it explicitly: new ListValue([], elementType)");
3167
+ }
3168
+ this.items = items;
3169
+ this.elementType = elementType;
3170
+ }
3171
+ get type() {
3172
+ return { List: this.elementType ?? this.items[0].type };
3173
+ }
3174
+ equals(other) {
3175
+ if (!(other instanceof _ListValue) || this.items.length !== other.items.length) {
3176
+ return false;
3177
+ }
3178
+ return this.items.every((item, i) => item.equals(other.items[i]));
3179
+ }
3180
+ toString() {
3181
+ return `[${this.items.map((item) => item.toString()).join(", ")}]`;
3182
+ }
3183
+ toJSON() {
3184
+ return this.items.map((item) => hasToJSON2(item) ? item.toJSON() : item);
3185
+ }
3186
+ encode() {
3187
+ const elementType = this.elementType ?? this.items[0].type;
3188
+ return {
3189
+ type: { List: elementType },
3190
+ value: this.items.map((item) => item.encode().value)
2900
3191
  };
2901
3192
  }
2902
3193
  };
2903
3194
 
3195
+ // src/value/record.ts
3196
+ function hasToJSON3(value) {
3197
+ return typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function";
3198
+ }
3199
+ var RecordValue = class _RecordValue {
3200
+ constructor(fields) {
3201
+ if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
3202
+ throw new Error(`Record value must be a plain object of fields, got ${typeof fields}`);
3203
+ }
3204
+ this.fields = fields;
3205
+ }
3206
+ get type() {
3207
+ return { Record: Object.entries(this.fields).map(([name, value]) => ({ name, type: value.encode().type })) };
3208
+ }
3209
+ equals(other) {
3210
+ if (!(other instanceof _RecordValue)) {
3211
+ return false;
3212
+ }
3213
+ const names = Object.keys(this.fields);
3214
+ const otherNames = Object.keys(other.fields);
3215
+ if (names.length !== otherNames.length || names.some((name, i) => name !== otherNames[i])) {
3216
+ return false;
3217
+ }
3218
+ return names.every((name) => this.fields[name].equals(other.fields[name]));
3219
+ }
3220
+ toString() {
3221
+ return `{${Object.entries(this.fields).map(([name, value]) => `${name}: ${value.toString()}`).join(", ")}}`;
3222
+ }
3223
+ toJSON() {
3224
+ return Object.fromEntries(Object.entries(this.fields).map(([name, value]) => [name, hasToJSON3(value) ? value.toJSON() : value]));
3225
+ }
3226
+ encode() {
3227
+ const fields = this.type.Record;
3228
+ const value = {};
3229
+ for (const [name, field] of Object.entries(this.fields)) {
3230
+ value[name] = field.encode().value;
3231
+ }
3232
+ return { type: { Record: fields }, value };
3233
+ }
3234
+ };
3235
+
2904
3236
  // src/value/wire-type.ts
3237
+ function peelOption(type) {
3238
+ return isOptionType(type) ? peelOption(type.Option) : type;
3239
+ }
2905
3240
  function typeToWire(type) {
2906
- return isOptionType(type) ? { id: "Option", underlying: typeToWire(type.Option) } : { id: type };
3241
+ if (isOptionType(type)) {
3242
+ return { id: "Option", underlying: typeToWire(type.Option) };
3243
+ }
3244
+ if (isDigestType(type)) {
3245
+ return { id: "Digest", underlying: { id: type.Digest.inner }, accuracy: type.Digest.accuracy };
3246
+ }
3247
+ if (isFixedPointType(type)) {
3248
+ const kind = fixedPointKind(type);
3249
+ const wire = { id: kind, precision: fixedPointPrecision(type) };
3250
+ if (kind === "Decimal") wire.scale = fixedPointScale(type);
3251
+ return wire;
3252
+ }
3253
+ if (isListType(type)) {
3254
+ return { id: "List", underlying: typeToWire(type.List) };
3255
+ }
3256
+ if (isRecordType(type)) {
3257
+ return { id: "Record", underlying: type.Record.map((field) => ({ name: field.name, type: typeToWire(field.type) })) };
3258
+ }
3259
+ return { id: type };
2907
3260
  }
2908
3261
  function typeFromWire(wire) {
2909
3262
  if (!wire || typeof wire !== "object" || typeof wire.id !== "string") {
2910
3263
  throw new Error(`Expected a type descriptor object, got ${JSON.stringify(wire)}`);
2911
3264
  }
2912
3265
  if (wire.id === "Option") {
2913
- if (!wire.underlying) {
3266
+ if (!wire.underlying || Array.isArray(wire.underlying)) {
2914
3267
  throw new Error("Option type descriptor is missing its underlying type");
2915
3268
  }
2916
3269
  return { Option: typeFromWire(wire.underlying) };
2917
3270
  }
3271
+ if (wire.id === "Digest") {
3272
+ const inner = !Array.isArray(wire.underlying) ? wire.underlying?.id : void 0;
3273
+ if (typeof inner !== "string" || typeof wire.accuracy !== "number") {
3274
+ throw new Error(`Digest type descriptor needs an underlying type and a numeric accuracy, got ${JSON.stringify(wire)}`);
3275
+ }
3276
+ return digestType(inner, wire.accuracy);
3277
+ }
3278
+ if (wire.id === "Decimal") {
3279
+ const precision = wire.precision ?? FIXED_POINT_MAX_PRECISION;
3280
+ return decimalType(precision, wire.scale ?? DECIMAL_DEFAULT_SCALE);
3281
+ }
3282
+ if (wire.id === "List") {
3283
+ if (!wire.underlying || Array.isArray(wire.underlying)) {
3284
+ throw new Error("List type descriptor is missing its underlying type");
3285
+ }
3286
+ return { List: typeFromWire(wire.underlying) };
3287
+ }
3288
+ if (wire.id === "Record") {
3289
+ if (!Array.isArray(wire.underlying)) {
3290
+ throw new Error("Record type descriptor needs an underlying array of fields");
3291
+ }
3292
+ return { Record: wire.underlying.map((field) => ({ name: field.name, type: typeFromWire(field.type) })) };
3293
+ }
2918
3294
  return wire.id;
2919
3295
  }
2920
3296
  function columnsFromWire(columns) {
2921
3297
  return columns.map((column) => ({ ...column, type: typeFromWire(column.type) }));
2922
3298
  }
3299
+ var LEGACY_FRAME_KEYS = ["row_numbers", "created_at", "updated_at", "time"];
2923
3300
  function framesFromWire(frames) {
2924
- return frames.map(
2925
- (frame) => frame && frame.columns ? { ...frame, columns: columnsFromWire(frame.columns) } : frame
2926
- );
3301
+ return frames.map((frame) => {
3302
+ for (const key of LEGACY_FRAME_KEYS) {
3303
+ if (Array.isArray(frame?.[key]) && frame[key].length > 0) {
3304
+ throw new Error(`frame key ${key} is not supported, system columns travel as # columns`);
3305
+ }
3306
+ }
3307
+ return frame && frame.columns ? { ...frame, columns: columnsFromWire(frame.columns) } : frame;
3308
+ });
2927
3309
  }
2928
3310
  function envelopeToColumns(envelope) {
2929
- const types = envelope?.types ?? {};
3311
+ const types = envelope?.types;
2930
3312
  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
- }));
3313
+ if (!types || typeof types !== "object") {
3314
+ if (rows.length > 0) {
3315
+ throw new Error(`Frame envelope carries rows but no column types, got ${JSON.stringify(envelope)}`);
3316
+ }
3317
+ return [];
3318
+ }
3319
+ return Object.keys(types).map((name) => {
3320
+ const type = typeFromWire(types[name]);
3321
+ return {
3322
+ name,
3323
+ type,
3324
+ payload: rows.map((row) => payloadOf(row, name, type))
3325
+ };
3326
+ });
2936
3327
  }
2937
3328
  function envelopesToFrames(envelopes) {
2938
- return Array.isArray(envelopes) ? envelopes.map((envelope) => ({ columns: envelopeToColumns(envelope) })) : [];
3329
+ if (!Array.isArray(envelopes)) {
3330
+ throw new Error(`Expected a list of frame envelopes, got ${JSON.stringify(envelopes)}`);
3331
+ }
3332
+ return envelopes.map((envelope) => {
3333
+ const rows = envelope?.rows ?? [];
3334
+ return {
3335
+ columns: envelopeToColumns(envelope),
3336
+ row_numbers: rows.length > 0 && ROW_NUMBER_KEY in rows[0] ? rows.map((row) => row[ROW_NUMBER_KEY]) : void 0
3337
+ };
3338
+ });
2939
3339
  }
2940
- function payloadOf(value) {
3340
+ function payloadOf(row, name, type) {
3341
+ if (!row || typeof row !== "object" || !(name in row)) {
3342
+ throw new Error(`Row is missing a cell for column ${name}`);
3343
+ }
3344
+ const value = row[name];
2941
3345
  if (value === null || value === void 0) {
3346
+ if (!isOptionType(type)) {
3347
+ throw new Error(`A none cell cannot fit the non-option column ${name}`);
3348
+ }
2942
3349
  return NONE_VALUE;
2943
3350
  }
2944
- return typeof value === "string" ? value : String(value);
3351
+ const base = peelOption(type);
3352
+ if (isListType(base) || isRecordType(base)) {
3353
+ return value;
3354
+ }
3355
+ if (base === "Boolean") {
3356
+ if (typeof value !== "boolean") {
3357
+ throw new Error(`Cell for column ${name} must arrive as a boolean, got ${typeof value}`);
3358
+ }
3359
+ return value;
3360
+ }
3361
+ if (typeof value !== "string") {
3362
+ throw new Error(`Cell for column ${name} must arrive as text, got ${typeof value}`);
3363
+ }
3364
+ return value;
2945
3365
  }
2946
3366
 
2947
3367
  // src/value/index.ts
2948
3368
  function isOptionType(t) {
2949
3369
  return typeof t === "object" && t !== null && "Option" in t;
2950
3370
  }
3371
+ function isDigestType(t) {
3372
+ return typeof t === "object" && t !== null && "Digest" in t;
3373
+ }
3374
+ function isListType(t) {
3375
+ return typeof t === "object" && t !== null && "List" in t;
3376
+ }
3377
+ function isRecordType(t) {
3378
+ return typeof t === "object" && t !== null && "Record" in t;
3379
+ }
2951
3380
  function unwrapOptionType(t) {
2952
3381
  if (isOptionType(t)) return unwrapOptionType(t.Option);
2953
3382
  return t;
@@ -2967,7 +3396,7 @@ function stripOptionLayers(type, layers) {
2967
3396
  }
2968
3397
  function decode(pair) {
2969
3398
  if (isOptionType(pair.type)) {
2970
- const noneAt = noneMarkerDepth(pair.value);
3399
+ const noneAt = typeof pair.value === "string" ? noneMarkerDepth(pair.value) : void 0;
2971
3400
  if (noneAt === void 0) {
2972
3401
  return decode({ type: unwrapOptionType(pair.type), value: pair.value });
2973
3402
  }
@@ -2977,65 +3406,127 @@ function decode(pair) {
2977
3406
  }
2978
3407
  return new NoneValue(stripOptionLayers(pair.type, noneAt + 1));
2979
3408
  }
3409
+ if (isDigestType(pair.type)) {
3410
+ return DigestValue.parse(pair.value, pair.type);
3411
+ }
3412
+ if (isFixedPointType(pair.type)) {
3413
+ if (typeof pair.value !== "string") {
3414
+ throw new Error(`Cell for type ${fixedPointTypeName(pair.type)} must be a JSON string, got ${typeof pair.value}`);
3415
+ }
3416
+ return DecimalValue.parse(pair.value);
3417
+ }
3418
+ if (isListType(pair.type)) {
3419
+ if (!Array.isArray(pair.value)) {
3420
+ throw new Error(`List value must be a JSON array, got ${typeof pair.value}`);
3421
+ }
3422
+ const elementType = pair.type.List;
3423
+ return new ListValue(pair.value.map((item) => decode({ type: elementType, value: item })), elementType);
3424
+ }
3425
+ if (isRecordType(pair.type)) {
3426
+ if (typeof pair.value !== "object" || pair.value === null || Array.isArray(pair.value)) {
3427
+ throw new Error(`Record value must be a JSON object, got ${typeof pair.value}`);
3428
+ }
3429
+ const obj = pair.value;
3430
+ const fields = {};
3431
+ for (const field of pair.type.Record) {
3432
+ if (!(field.name in obj)) {
3433
+ throw new Error(`record is missing field '${field.name}'`);
3434
+ }
3435
+ fields[field.name] = decode({ type: field.type, value: obj[field.name] });
3436
+ }
3437
+ return new RecordValue(fields);
3438
+ }
3439
+ if (pair.type === "Boolean" && typeof pair.value === "boolean") {
3440
+ return new BooleanValue(pair.value);
3441
+ }
3442
+ if (typeof pair.value !== "string") {
3443
+ throw new Error(`Cell for type ${pair.type} must be a JSON string, got ${typeof pair.value}`);
3444
+ }
3445
+ const value = pair.value;
2980
3446
  switch (pair.type) {
2981
3447
  case "Blob":
2982
- return BlobValue.parse(pair.value);
3448
+ return BlobValue.parse(value);
2983
3449
  case "Boolean":
2984
- return BooleanValue.parse(pair.value);
3450
+ return BooleanValue.parse(value);
2985
3451
  case "Date":
2986
- return DateValue.parse(pair.value);
3452
+ return DateValue.parse(value);
2987
3453
  case "DateTime":
2988
- return DateTimeValue.parse(pair.value);
3454
+ return DateTimeValue.parse(value);
2989
3455
  case "Decimal":
2990
- return DecimalValue.parse(pair.value);
3456
+ return DecimalValue.parse(value);
2991
3457
  case "Float4":
2992
- return Float4Value.parse(pair.value);
3458
+ return Float4Value.parse(value);
2993
3459
  case "Float8":
2994
- return Float8Value.parse(pair.value);
3460
+ return Float8Value.parse(value);
2995
3461
  case "Int1":
2996
- return Int1Value.parse(pair.value);
3462
+ return Int1Value.parse(value);
2997
3463
  case "Int2":
2998
- return Int2Value.parse(pair.value);
3464
+ return Int2Value.parse(value);
2999
3465
  case "Int4":
3000
- return Int4Value.parse(pair.value);
3466
+ return Int4Value.parse(value);
3001
3467
  case "Int8":
3002
- return Int8Value.parse(pair.value);
3468
+ return Int8Value.parse(value);
3003
3469
  case "Int16":
3004
- return Int16Value.parse(pair.value);
3470
+ return Int16Value.parse(value);
3005
3471
  case "Duration":
3006
- return DurationValue.parse(pair.value);
3472
+ return DurationValue.parse(value);
3007
3473
  case "Time":
3008
- return TimeValue.parse(pair.value);
3474
+ return TimeValue.parse(value);
3009
3475
  case "Uint1":
3010
- return Uint1Value.parse(pair.value);
3476
+ return Uint1Value.parse(value);
3011
3477
  case "Uint2":
3012
- return Uint2Value.parse(pair.value);
3478
+ return Uint2Value.parse(value);
3013
3479
  case "Uint4":
3014
- return Uint4Value.parse(pair.value);
3480
+ return Uint4Value.parse(value);
3015
3481
  case "Uint8":
3016
- return Uint8Value.parse(pair.value);
3482
+ return Uint8Value.parse(value);
3017
3483
  case "Uint16":
3018
- return Uint16Value.parse(pair.value);
3484
+ return Uint16Value.parse(value);
3019
3485
  case "None":
3020
- return NoneValue.parse(pair.value);
3486
+ return NoneValue.parse(value);
3021
3487
  case "Utf8":
3022
- return Utf8Value.parse(pair.value);
3488
+ return Utf8Value.parse(value);
3023
3489
  case "Uuid4":
3024
- return Uuid4Value.parse(pair.value);
3490
+ return Uuid4Value.parse(value);
3025
3491
  case "Uuid7":
3026
- return Uuid7Value.parse(pair.value);
3492
+ return Uuid7Value.parse(value);
3027
3493
  case "IdentityId":
3028
- return IdentityIdValue.parse(pair.value);
3494
+ return IdentityIdValue.parse(value);
3029
3495
  default:
3030
3496
  throw new Error(`Unsupported type: ${pair.type}`);
3031
3497
  }
3032
3498
  }
3033
- function columnsToRows(columns) {
3499
+ function rowNumberOf(cell) {
3500
+ const rowNumber = Number(cell);
3501
+ if (!Number.isFinite(rowNumber)) {
3502
+ throw new Error(`row number ${JSON.stringify(cell)} is not a number`);
3503
+ }
3504
+ return rowNumber;
3505
+ }
3506
+ function columnsToRows(columns, rowNumbers) {
3034
3507
  const rowCount = columns[0]?.payload.length ?? 0;
3508
+ for (const column of columns) {
3509
+ if (column.payload.length !== rowCount) {
3510
+ throw new Error(
3511
+ `column ${column.name} carries ${column.payload.length} cells where ${columns[0].name} carries ${rowCount}`
3512
+ );
3513
+ }
3514
+ }
3515
+ const hasRowNumbers = rowNumbers !== void 0 && rowNumbers.length > 0;
3516
+ if (hasRowNumbers && rowNumbers.length !== rowCount) {
3517
+ throw new Error(`row numbers cover ${rowNumbers.length} of ${rowCount} rows`);
3518
+ }
3035
3519
  return Array.from({ length: rowCount }, (_, i) => {
3036
3520
  const row = {};
3037
3521
  for (const col of columns) {
3038
- row[col.name] = decode({ type: col.type, value: col.payload[i] });
3522
+ if (col.name === ROW_NUMBER_KEY) {
3523
+ row[ROW_NUMBER_KEY] = rowNumberOf(col.payload[i]);
3524
+ } else {
3525
+ row[col.name] = decode({ type: col.type, value: col.payload[i] });
3526
+ }
3527
+ }
3528
+ if (hasRowNumbers) {
3529
+ row[ROW_NUMBER_KEY] = Number(rowNumbers[i]);
3039
3530
  }
3040
3531
  return row;
3041
3532
  });
@@ -3054,7 +3545,7 @@ function encodeValue(value, name = "$1") {
3054
3545
  return { type: value.type, value: NONE_VALUE };
3055
3546
  }
3056
3547
  const inner = encodeValue(value.unwrap(), name);
3057
- const noneAt = noneMarkerDepth(inner.value);
3548
+ const noneAt = typeof inner.value === "string" ? noneMarkerDepth(inner.value) : void 0;
3058
3549
  return {
3059
3550
  type: { Option: inner.type },
3060
3551
  value: noneAt === void 0 ? inner.value : noneMarker(noneAt + 1)
@@ -3063,6 +3554,16 @@ function encodeValue(value, name = "$1") {
3063
3554
  if (value && typeof value === "object" && "encode" in value && typeof value.encode === "function") {
3064
3555
  return value.encode();
3065
3556
  }
3557
+ if (Array.isArray(value)) {
3558
+ if (value.length === 0) {
3559
+ throw new Error(`parameter ${name} is an empty array with no element type to infer, use new ListValue([], elementType)`);
3560
+ }
3561
+ const items = value.map((item, i) => encodeValue(item, `${name}[${i}]`));
3562
+ return {
3563
+ type: { List: items[0].type },
3564
+ value: items.map((item) => item.value)
3565
+ };
3566
+ }
3066
3567
  if (typeof value === "boolean") {
3067
3568
  return { type: "Boolean", value: value.toString() };
3068
3569
  }
@@ -3117,13 +3618,27 @@ function encodeValue(value, name = "$1") {
3117
3618
  return { type: "DateTime", value: value.toISOString() };
3118
3619
  }
3119
3620
  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 };
3621
+ const hex2 = Array.from(value).map((b) => b.toString(16).padStart(2, "0")).join("");
3622
+ return { type: "Blob", value: "0x" + hex2 };
3122
3623
  }
3123
3624
  if (value instanceof ArrayBuffer) {
3124
3625
  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 };
3626
+ const hex2 = Array.from(uint8Array).map((b) => b.toString(16).padStart(2, "0")).join("");
3627
+ return { type: "Blob", value: "0x" + hex2 };
3628
+ }
3629
+ if (typeof value === "object" && value.constructor === Object) {
3630
+ const rawEntries = Object.entries(value);
3631
+ if (rawEntries.length > 0 && rawEntries.every(([, v]) => typeof v !== "function")) {
3632
+ const entries = rawEntries.map(([key, v]) => [key, encodeValue(v, `${name}.${key}`)]);
3633
+ const fields = {};
3634
+ for (const [key, pair] of entries) {
3635
+ fields[key] = pair.value;
3636
+ }
3637
+ return {
3638
+ type: { Record: entries.map(([key, pair]) => ({ name: key, type: pair.type })) },
3639
+ value: fields
3640
+ };
3641
+ }
3127
3642
  }
3128
3643
  throw new Error(`Cannot encode value of type ${typeof value}: ${value}`);
3129
3644
  }
@@ -3146,50 +3661,6 @@ function encodeParams(params) {
3146
3661
  throw new Error(`Invalid parameters type: expected array or object, got ${typeof params}`);
3147
3662
  }
3148
3663
 
3149
- // src/type-code.ts
3150
- var TYPE_CODE = {
3151
- None: 0,
3152
- Boolean: 1,
3153
- Float4: 2,
3154
- Float8: 3,
3155
- Int1: 4,
3156
- Int2: 5,
3157
- Int4: 6,
3158
- Int8: 7,
3159
- Int16: 8,
3160
- Utf8: 9,
3161
- Uint1: 10,
3162
- Uint2: 11,
3163
- Uint4: 12,
3164
- Uint8: 13,
3165
- Uint16: 14,
3166
- Date: 15,
3167
- DateTime: 16,
3168
- Time: 17,
3169
- Duration: 18,
3170
- IdentityId: 19,
3171
- Uuid4: 20,
3172
- Uuid7: 21,
3173
- Blob: 22,
3174
- Int: 23,
3175
- Uint: 24,
3176
- Decimal: 25,
3177
- Any: 26,
3178
- DictionaryId: 27,
3179
- Type: 28,
3180
- List: 29,
3181
- Record: 30,
3182
- Tuple: 31
3183
- };
3184
- var CODE_TO_NAME = Object.fromEntries(
3185
- Object.entries(TYPE_CODE).map(([k, v]) => [v, k])
3186
- );
3187
- function typeNameFromCode(code) {
3188
- const name = CODE_TO_NAME[code];
3189
- if (!name) throw new Error(`Unknown type code: ${code}`);
3190
- return name;
3191
- }
3192
-
3193
3664
  // src/shape/builder.ts
3194
3665
  var ShapeBuilder = class {
3195
3666
  static blob() {
@@ -3561,7 +4032,7 @@ var NUMERIC = {
3561
4032
  Float8: { kind: "float", bits: 64 }
3562
4033
  };
3563
4034
  function widens(target, actual) {
3564
- if (isOptionType(actual)) {
4035
+ if (typeof actual !== "string") {
3565
4036
  return false;
3566
4037
  }
3567
4038
  const t = NUMERIC[target];
@@ -3635,12 +4106,18 @@ function familyOf(type) {
3635
4106
  return FAMILIES.find((family) => family.includes(type)) ?? [type];
3636
4107
  }
3637
4108
  function matches(shape, type) {
4109
+ if (isFixedPointType(type)) {
4110
+ const kind = fixedPointKind(type);
4111
+ if (shape.kind === "primitive") return familyOf(shape.type).includes(kind);
4112
+ if (shape.kind === "value") return shape.type === kind;
4113
+ return false;
4114
+ }
3638
4115
  switch (shape.kind) {
3639
4116
  case "primitive":
3640
4117
  if (shape.type === "None") {
3641
4118
  return type === "None" || isOptionType(type);
3642
4119
  }
3643
- return !isOptionType(type) && familyOf(shape.type).includes(type);
4120
+ return typeof type === "string" && familyOf(shape.type).includes(type);
3644
4121
  case "value":
3645
4122
  if (shape.type === "None") {
3646
4123
  return type === "None" || isOptionType(type);
@@ -3666,7 +4143,22 @@ function describe(shape) {
3666
4143
  }
3667
4144
  }
3668
4145
  function typeName2(type) {
3669
- return isOptionType(type) ? `Option(${typeName2(type.Option)})` : type;
4146
+ if (isDigestType(type)) {
4147
+ return digestTypeName(type);
4148
+ }
4149
+ if (isFixedPointType(type)) {
4150
+ return fixedPointTypeName(type);
4151
+ }
4152
+ if (isOptionType(type)) {
4153
+ return `Option(${typeName2(type.Option)})`;
4154
+ }
4155
+ if (isListType(type)) {
4156
+ return `List(${typeName2(type.List)})`;
4157
+ }
4158
+ if (isRecordType(type)) {
4159
+ return `Record(${type.Record.map((field) => `${field.name}: ${typeName2(field.type)}`).join(", ")})`;
4160
+ }
4161
+ return type;
3670
4162
  }
3671
4163
 
3672
4164
  // src/shape/transform.ts
@@ -4325,10 +4817,14 @@ function asFrameResults(results) {
4325
4817
  export {
4326
4818
  BlobValue,
4327
4819
  BooleanValue,
4820
+ DECIMAL_DEFAULT_SCALE,
4328
4821
  DateTimeValue,
4329
4822
  DateValue,
4330
4823
  DecimalValue,
4824
+ DigestValue,
4331
4825
  DurationValue,
4826
+ FIXED_POINT_MAX_PRECISION,
4827
+ FIXED_POINT_NARROW_PRECISION,
4332
4828
  Float4Value,
4333
4829
  Float8Value,
4334
4830
  IdentityIdValue,
@@ -4337,6 +4833,7 @@ export {
4337
4833
  Int2Value,
4338
4834
  Int4Value,
4339
4835
  Int8Value,
4836
+ ListValue,
4340
4837
  NONE_PRESENTATION,
4341
4838
  NONE_VALUE,
4342
4839
  NoneValue,
@@ -4347,6 +4844,7 @@ export {
4347
4844
  RQL_OPERATORS,
4348
4845
  RQL_SYSTEM_COLUMNS,
4349
4846
  RQL_TYPES,
4847
+ RecordValue,
4350
4848
  ReifyError,
4351
4849
  Shape,
4352
4850
  ShapeBuilder,
@@ -4368,19 +4866,31 @@ export {
4368
4866
  checkFrames,
4369
4867
  columnsFromWire,
4370
4868
  columnsToRows,
4869
+ decimalType,
4371
4870
  decode,
4871
+ digestType,
4872
+ digestTypeName,
4372
4873
  displayWidth,
4373
4874
  encodeParams,
4374
4875
  encodeValue,
4375
4876
  envelopeToColumns,
4376
4877
  envelopesToFrames,
4878
+ fixedPointKind,
4879
+ fixedPointPrecision,
4880
+ fixedPointScale,
4881
+ fixedPointType,
4882
+ fixedPointTypeName,
4377
4883
  formatValue,
4378
4884
  framesFromWire,
4379
4885
  graphemeWidth,
4380
4886
  inferColumns,
4381
4887
  innerOfOption,
4888
+ isDigestType,
4889
+ isFixedPointType,
4890
+ isListType,
4382
4891
  isOption,
4383
4892
  isOptionType,
4893
+ isRecordType,
4384
4894
  noneDepth,
4385
4895
  noneMarker,
4386
4896
  noneMarkerDepth,