@reifydb/core 0.0.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 ADDED
@@ -0,0 +1,3107 @@
1
+ // src/constant.ts
2
+ var UNDEFINED_VALUE = "\u27EAundefined\u27EB";
3
+
4
+ // src/value/blob.ts
5
+ var BlobValue = class _BlobValue {
6
+ constructor(value) {
7
+ this.type = "Blob";
8
+ if (value !== void 0) {
9
+ if (value instanceof Uint8Array) {
10
+ this.bytes = new Uint8Array(value);
11
+ } else if (value instanceof ArrayBuffer) {
12
+ this.bytes = new Uint8Array(value);
13
+ } else if (typeof value === "string") {
14
+ const parsed = _BlobValue.parseString(value);
15
+ if (parsed === null) {
16
+ throw new Error(`Invalid blob string: ${value}`);
17
+ }
18
+ this.bytes = parsed;
19
+ } else if (Array.isArray(value)) {
20
+ for (const byte of value) {
21
+ if (!Number.isInteger(byte) || byte < 0 || byte > 255) {
22
+ throw new Error(`Invalid byte value: ${byte}`);
23
+ }
24
+ }
25
+ this.bytes = new Uint8Array(value);
26
+ } else {
27
+ throw new Error(`Blob value must be a Uint8Array, ArrayBuffer, string, or number[], got ${typeof value}`);
28
+ }
29
+ } else {
30
+ this.bytes = void 0;
31
+ }
32
+ }
33
+ /**
34
+ * Create a new BLOB from raw bytes
35
+ */
36
+ static new(bytes) {
37
+ return new _BlobValue(bytes);
38
+ }
39
+ /**
40
+ * Create an empty BLOB
41
+ */
42
+ static empty() {
43
+ return new _BlobValue(new Uint8Array(0));
44
+ }
45
+ /**
46
+ * Create a BLOB from a byte array
47
+ */
48
+ static fromBytes(bytes) {
49
+ return new _BlobValue(bytes);
50
+ }
51
+ /**
52
+ * Create a BLOB from a hex string
53
+ */
54
+ static fromHex(hex) {
55
+ const cleanHex = hex.startsWith("0x") || hex.startsWith("0X") ? hex.substring(2) : hex;
56
+ if (cleanHex.length % 2 !== 0) {
57
+ throw new Error(`Invalid hex string: odd length`);
58
+ }
59
+ const bytes = new Uint8Array(cleanHex.length / 2);
60
+ for (let i = 0; i < cleanHex.length; i += 2) {
61
+ const byte = parseInt(cleanHex.substring(i, i + 2), 16);
62
+ if (isNaN(byte)) {
63
+ throw new Error(`Invalid hex string: ${hex}`);
64
+ }
65
+ bytes[i / 2] = byte;
66
+ }
67
+ return new _BlobValue(bytes);
68
+ }
69
+ /**
70
+ * Create a BLOB from a base64 string
71
+ */
72
+ static fromBase64(base64) {
73
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64)) {
74
+ throw new Error(`Invalid base64 string: ${base64}`);
75
+ }
76
+ try {
77
+ if (typeof Buffer !== "undefined") {
78
+ const buffer = Buffer.from(base64, "base64");
79
+ return new _BlobValue(new Uint8Array(buffer));
80
+ } else {
81
+ const binaryString = atob(base64);
82
+ const bytes = new Uint8Array(binaryString.length);
83
+ for (let i = 0; i < binaryString.length; i++) {
84
+ bytes[i] = binaryString.charCodeAt(i);
85
+ }
86
+ return new _BlobValue(bytes);
87
+ }
88
+ } catch (e) {
89
+ throw new Error(`Invalid base64 string: ${base64}`);
90
+ }
91
+ }
92
+ /**
93
+ * Create a BLOB from a UTF-8 string
94
+ */
95
+ static fromUtf8(str) {
96
+ const encoder = new TextEncoder();
97
+ return new _BlobValue(encoder.encode(str));
98
+ }
99
+ /**
100
+ * Parse a blob string (hex or undefined)
101
+ */
102
+ static parse(str) {
103
+ const trimmed = str.trim();
104
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
105
+ return new _BlobValue(void 0);
106
+ }
107
+ const parsed = _BlobValue.parseString(trimmed);
108
+ if (parsed === null) {
109
+ throw new Error(`Cannot parse "${str}" as Blob`);
110
+ }
111
+ return new _BlobValue(parsed);
112
+ }
113
+ /**
114
+ * Get the raw bytes
115
+ */
116
+ asBytes() {
117
+ return this.bytes ? new Uint8Array(this.bytes) : void 0;
118
+ }
119
+ /**
120
+ * Get the length in bytes
121
+ */
122
+ length() {
123
+ return this.bytes?.length ?? 0;
124
+ }
125
+ /**
126
+ * Check if the BLOB is empty
127
+ */
128
+ isEmpty() {
129
+ return this.bytes?.length === 0;
130
+ }
131
+ /**
132
+ * Convert to hex string with 0x prefix
133
+ */
134
+ toHex() {
135
+ if (this.bytes === void 0) return void 0;
136
+ const hex = Array.from(this.bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
137
+ return "0x" + hex;
138
+ }
139
+ /**
140
+ * Convert to base64 string
141
+ */
142
+ toBase64() {
143
+ if (this.bytes === void 0) return void 0;
144
+ if (typeof Buffer !== "undefined") {
145
+ return Buffer.from(this.bytes).toString("base64");
146
+ } else {
147
+ const binaryString = Array.from(this.bytes).map((byte) => String.fromCharCode(byte)).join("");
148
+ return btoa(binaryString);
149
+ }
150
+ }
151
+ /**
152
+ * Convert to UTF-8 string
153
+ */
154
+ toUtf8() {
155
+ if (this.bytes === void 0) return void 0;
156
+ const decoder = new TextDecoder();
157
+ return decoder.decode(this.bytes);
158
+ }
159
+ /**
160
+ * Format as hex string with 0x prefix
161
+ */
162
+ toString() {
163
+ if (this.bytes === void 0) {
164
+ return "undefined";
165
+ }
166
+ return this.toHex();
167
+ }
168
+ valueOf() {
169
+ return this.bytes ? new Uint8Array(this.bytes) : void 0;
170
+ }
171
+ /**
172
+ * Get the internal representation
173
+ */
174
+ get value() {
175
+ return this.valueOf();
176
+ }
177
+ /**
178
+ * Compare two blobs for equality
179
+ */
180
+ equals(other) {
181
+ if (other.type !== this.type) {
182
+ return false;
183
+ }
184
+ const otherBlob = other;
185
+ if (this.bytes === void 0 || otherBlob.bytes === void 0) {
186
+ return this.bytes === otherBlob.bytes;
187
+ }
188
+ if (this.bytes.length !== otherBlob.bytes.length) {
189
+ return false;
190
+ }
191
+ for (let i = 0; i < this.bytes.length; i++) {
192
+ if (this.bytes[i] !== otherBlob.bytes[i]) {
193
+ return false;
194
+ }
195
+ }
196
+ return true;
197
+ }
198
+ /**
199
+ * Helper to parse a string as hex
200
+ */
201
+ static parseString(str) {
202
+ if (str.startsWith("0x") || str.startsWith("0X")) {
203
+ try {
204
+ return _BlobValue.fromHex(str).bytes;
205
+ } catch {
206
+ return null;
207
+ }
208
+ }
209
+ if (/^[0-9a-fA-F]+$/.test(str) && str.length % 2 === 0) {
210
+ try {
211
+ return _BlobValue.fromHex(str).bytes;
212
+ } catch {
213
+ return null;
214
+ }
215
+ }
216
+ return null;
217
+ }
218
+ encode() {
219
+ return {
220
+ type: this.type,
221
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
222
+ };
223
+ }
224
+ };
225
+
226
+ // src/value/bool.ts
227
+ var BoolValue = class _BoolValue {
228
+ constructor(value) {
229
+ this.type = "Bool";
230
+ if (value !== void 0) {
231
+ if (typeof value !== "boolean") {
232
+ throw new Error(`Bool value must be a boolean, got ${typeof value}`);
233
+ }
234
+ this.value = value;
235
+ } else {
236
+ this.value = void 0;
237
+ }
238
+ }
239
+ static parse(str) {
240
+ const trimmed = str.trim().toLowerCase();
241
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
242
+ return new _BoolValue(void 0);
243
+ }
244
+ if (trimmed === "true") {
245
+ return new _BoolValue(true);
246
+ }
247
+ if (trimmed === "false") {
248
+ return new _BoolValue(false);
249
+ }
250
+ throw new Error(`Cannot parse "${str}" as Bool`);
251
+ }
252
+ valueOf() {
253
+ return this.value;
254
+ }
255
+ toString() {
256
+ return this.value === void 0 ? "undefined" : this.value.toString();
257
+ }
258
+ /**
259
+ * Compare two boolean values for equality
260
+ */
261
+ equals(other) {
262
+ if (other.type !== this.type) {
263
+ return false;
264
+ }
265
+ const otherBool = other;
266
+ return this.value === otherBool.value;
267
+ }
268
+ encode() {
269
+ return {
270
+ type: this.type,
271
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
272
+ };
273
+ }
274
+ };
275
+
276
+ // src/value/date.ts
277
+ var DateValue = class _DateValue {
278
+ // day of month (1-31)
279
+ constructor(value) {
280
+ this.type = "Date";
281
+ if (value !== void 0) {
282
+ if (value instanceof Date) {
283
+ const year = value.getUTCFullYear();
284
+ const month = value.getUTCMonth() + 1;
285
+ const day = value.getUTCDate();
286
+ this.months = year * 12 + (month - 1);
287
+ this.days = day;
288
+ } else if (typeof value === "string") {
289
+ const parsed = _DateValue.parseDate(value);
290
+ if (!parsed) {
291
+ throw new Error(`Invalid date string: ${value}`);
292
+ }
293
+ this.months = parsed.months;
294
+ this.days = parsed.days;
295
+ } else if (typeof value === "number") {
296
+ const date = _DateValue.fromDaysSinceEpochToComponents(value);
297
+ if (!date) {
298
+ throw new Error(`Invalid days since epoch: ${value}`);
299
+ }
300
+ this.months = date.months;
301
+ this.days = date.days;
302
+ } else {
303
+ throw new Error(`Date value must be a Date, string, or number, got ${typeof value}`);
304
+ }
305
+ } else {
306
+ this.months = void 0;
307
+ this.days = void 0;
308
+ }
309
+ }
310
+ /**
311
+ * Create a DateValue from year, month (1-12), and day (1-31)
312
+ */
313
+ static fromYMD(year, month, day) {
314
+ if (!_DateValue.isValidDate(year, month, day)) {
315
+ throw new Error(`Invalid date: ${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`);
316
+ }
317
+ const result = new _DateValue(void 0);
318
+ result.months = year * 12 + (month - 1);
319
+ result.days = day;
320
+ return result;
321
+ }
322
+ /**
323
+ * Get today's date (in UTC)
324
+ */
325
+ static today() {
326
+ const now = /* @__PURE__ */ new Date();
327
+ return _DateValue.fromYMD(
328
+ now.getUTCFullYear(),
329
+ now.getUTCMonth() + 1,
330
+ now.getUTCDate()
331
+ );
332
+ }
333
+ /**
334
+ * Parse a date string in YYYY-MM-DD format
335
+ */
336
+ static parse(str) {
337
+ const trimmed = str.trim();
338
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
339
+ return new _DateValue(void 0);
340
+ }
341
+ const parsed = _DateValue.parseDate(trimmed);
342
+ if (!parsed) {
343
+ throw new Error(`Cannot parse "${str}" as Date`);
344
+ }
345
+ const result = new _DateValue(void 0);
346
+ result.months = parsed.months;
347
+ result.days = parsed.days;
348
+ return result;
349
+ }
350
+ /**
351
+ * Convert to days since Unix epoch (1970-01-01) for storage
352
+ */
353
+ toDaysSinceEpoch() {
354
+ if (this.months === void 0 || this.days === void 0) {
355
+ return void 0;
356
+ }
357
+ const year = Math.floor(this.months / 12);
358
+ let m = this.months % 12;
359
+ if (m < 0) m += 12;
360
+ const month = m + 1;
361
+ let date;
362
+ if (year >= 0 && year < 100) {
363
+ date = new Date(Date.UTC(2e3, month - 1, this.days));
364
+ date.setUTCFullYear(year);
365
+ } else {
366
+ date = new Date(Date.UTC(year, month - 1, this.days));
367
+ }
368
+ const epoch = new Date(Date.UTC(1970, 0, 1));
369
+ const diffMs = date.getTime() - epoch.getTime();
370
+ return Math.floor(diffMs / (1e3 * 60 * 60 * 24));
371
+ }
372
+ /**
373
+ * Create from days since Unix epoch
374
+ */
375
+ static fromDaysSinceEpochToComponents(days) {
376
+ const epoch = new Date(Date.UTC(1970, 0, 1));
377
+ const ms = days * 24 * 60 * 60 * 1e3;
378
+ const date = new Date(epoch.getTime() + ms);
379
+ if (!isFinite(date.getTime())) {
380
+ return null;
381
+ }
382
+ const year = date.getUTCFullYear();
383
+ const month = date.getUTCMonth() + 1;
384
+ const day = date.getUTCDate();
385
+ return {
386
+ months: year * 12 + (month - 1),
387
+ days: day
388
+ };
389
+ }
390
+ /**
391
+ * Get the year component
392
+ */
393
+ year() {
394
+ if (this.months === void 0) return void 0;
395
+ return Math.floor(this.months / 12);
396
+ }
397
+ /**
398
+ * Get the month component (1-12)
399
+ */
400
+ month() {
401
+ if (this.months === void 0) return void 0;
402
+ let m = this.months % 12;
403
+ if (m < 0) m += 12;
404
+ return m + 1;
405
+ }
406
+ /**
407
+ * Get the day component (1-31)
408
+ */
409
+ day() {
410
+ return this.days;
411
+ }
412
+ /**
413
+ * Format as YYYY-MM-DD string
414
+ */
415
+ toString() {
416
+ if (this.months === void 0 || this.days === void 0) {
417
+ return "undefined";
418
+ }
419
+ const year = Math.floor(this.months / 12);
420
+ let m = this.months % 12;
421
+ if (m < 0) m += 12;
422
+ const month = String(m + 1).padStart(2, "0");
423
+ const day = String(this.days).padStart(2, "0");
424
+ if (year < 0) {
425
+ const absYear = Math.abs(year);
426
+ return `-${String(absYear).padStart(4, "0")}-${month}-${day}`;
427
+ } else {
428
+ return `${String(year).padStart(4, "0")}-${month}-${day}`;
429
+ }
430
+ }
431
+ valueOf() {
432
+ if (this.months === void 0 || this.days === void 0) {
433
+ return void 0;
434
+ }
435
+ const year = Math.floor(this.months / 12);
436
+ let m = this.months % 12;
437
+ if (m < 0) m += 12;
438
+ const month = m + 1;
439
+ let date;
440
+ if (year >= 0 && year < 100) {
441
+ date = new Date(Date.UTC(2e3, month - 1, this.days));
442
+ date.setUTCFullYear(year);
443
+ } else {
444
+ date = new Date(Date.UTC(year, month - 1, this.days));
445
+ }
446
+ return date;
447
+ }
448
+ /**
449
+ * Get the internal representation
450
+ */
451
+ get value() {
452
+ return this.valueOf();
453
+ }
454
+ /**
455
+ * Helper to parse YYYY-MM-DD format
456
+ */
457
+ static parseDate(str) {
458
+ const match = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})$/);
459
+ if (!match) {
460
+ return null;
461
+ }
462
+ const year = parseInt(match[1], 10);
463
+ const month = parseInt(match[2], 10);
464
+ const day = parseInt(match[3], 10);
465
+ if (month < 1 || month > 12) {
466
+ return null;
467
+ }
468
+ if (day < 1 || day > 31) {
469
+ return null;
470
+ }
471
+ if (!_DateValue.isValidDate(year, month, day)) {
472
+ return null;
473
+ }
474
+ return {
475
+ months: year * 12 + (month - 1),
476
+ days: day
477
+ };
478
+ }
479
+ /**
480
+ * Helper to validate a date
481
+ */
482
+ static isValidDate(year, month, day) {
483
+ let date;
484
+ if (year >= 0 && year < 100) {
485
+ date = new Date(Date.UTC(2e3, month - 1, day));
486
+ date.setUTCFullYear(year);
487
+ } else {
488
+ date = new Date(Date.UTC(year, month - 1, day));
489
+ }
490
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
491
+ }
492
+ /**
493
+ * Compare two dates for equality
494
+ */
495
+ equals(other) {
496
+ if (other.type !== this.type) {
497
+ return false;
498
+ }
499
+ const otherDate = other;
500
+ if (this.months === void 0 || otherDate.months === void 0) {
501
+ return this.months === otherDate.months && this.days === otherDate.days;
502
+ }
503
+ return this.months === otherDate.months && this.days === otherDate.days;
504
+ }
505
+ encode() {
506
+ return {
507
+ type: this.type,
508
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
509
+ };
510
+ }
511
+ };
512
+
513
+ // src/value/time.ts
514
+ var _TimeValue = class _TimeValue {
515
+ constructor(value) {
516
+ this.type = "Time";
517
+ if (value !== void 0) {
518
+ if (typeof value === "bigint") {
519
+ if (value < 0n || value >= _TimeValue.NANOS_PER_DAY) {
520
+ throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
521
+ }
522
+ this.value = value;
523
+ } else if (typeof value === "string") {
524
+ const parsed = _TimeValue.parseTime(value);
525
+ if (parsed === null) {
526
+ throw new Error(`Invalid time string: ${value}`);
527
+ }
528
+ this.value = parsed;
529
+ } else if (typeof value === "number") {
530
+ const bigintValue = BigInt(Math.floor(value));
531
+ if (bigintValue < 0n || bigintValue >= _TimeValue.NANOS_PER_DAY) {
532
+ throw new Error(`Time value must be between 0 and ${_TimeValue.NANOS_PER_DAY - 1n} nanoseconds`);
533
+ }
534
+ this.value = bigintValue;
535
+ } else {
536
+ throw new Error(`Time value must be a bigint, string, or number, got ${typeof value}`);
537
+ }
538
+ } else {
539
+ this.value = void 0;
540
+ }
541
+ }
542
+ /**
543
+ * Create a TimeValue from hour, minute, second, and nanosecond
544
+ */
545
+ static fromHMSN(hour, minute, second, nano = 0) {
546
+ if (hour < 0 || hour > 23) {
547
+ throw new Error(`Invalid hour: ${hour}`);
548
+ }
549
+ if (minute < 0 || minute > 59) {
550
+ throw new Error(`Invalid minute: ${minute}`);
551
+ }
552
+ if (second < 0 || second > 59) {
553
+ throw new Error(`Invalid second: ${second}`);
554
+ }
555
+ if (nano < 0 || nano > 999999999) {
556
+ throw new Error(`Invalid nanosecond: ${nano}`);
557
+ }
558
+ const nanos = BigInt(hour) * _TimeValue.NANOS_PER_HOUR + BigInt(minute) * _TimeValue.NANOS_PER_MINUTE + BigInt(second) * _TimeValue.NANOS_PER_SECOND + BigInt(nano);
559
+ return new _TimeValue(nanos);
560
+ }
561
+ /**
562
+ * Create a TimeValue from hour, minute, and second (no fractional seconds)
563
+ */
564
+ static fromHMS(hour, minute, second) {
565
+ return _TimeValue.fromHMSN(hour, minute, second, 0);
566
+ }
567
+ /**
568
+ * Create midnight (00:00:00.000000000)
569
+ */
570
+ static midnight() {
571
+ return new _TimeValue(0n);
572
+ }
573
+ /**
574
+ * Create noon (12:00:00.000000000)
575
+ */
576
+ static noon() {
577
+ return new _TimeValue(12n * _TimeValue.NANOS_PER_HOUR);
578
+ }
579
+ /**
580
+ * Parse a time string in HH:MM:SS[.nnnnnnnnn] format
581
+ */
582
+ static parse(str) {
583
+ const trimmed = str.trim();
584
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
585
+ return new _TimeValue(void 0);
586
+ }
587
+ const parsed = _TimeValue.parseTime(trimmed);
588
+ if (parsed === null) {
589
+ throw new Error(`Cannot parse "${str}" as Time`);
590
+ }
591
+ return new _TimeValue(parsed);
592
+ }
593
+ /**
594
+ * Get the hour component (0-23)
595
+ */
596
+ hour() {
597
+ if (this.value === void 0) return void 0;
598
+ return Number(this.value / _TimeValue.NANOS_PER_HOUR);
599
+ }
600
+ /**
601
+ * Get the minute component (0-59)
602
+ */
603
+ minute() {
604
+ if (this.value === void 0) return void 0;
605
+ const remainingAfterHours = this.value % _TimeValue.NANOS_PER_HOUR;
606
+ return Number(remainingAfterHours / _TimeValue.NANOS_PER_MINUTE);
607
+ }
608
+ /**
609
+ * Get the second component (0-59)
610
+ */
611
+ second() {
612
+ if (this.value === void 0) return void 0;
613
+ const remainingAfterHours = this.value % _TimeValue.NANOS_PER_HOUR;
614
+ const remainingAfterMinutes = remainingAfterHours % _TimeValue.NANOS_PER_MINUTE;
615
+ return Number(remainingAfterMinutes / _TimeValue.NANOS_PER_SECOND);
616
+ }
617
+ /**
618
+ * Get the nanosecond component (0-999999999)
619
+ */
620
+ nanosecond() {
621
+ if (this.value === void 0) return void 0;
622
+ return Number(this.value % _TimeValue.NANOS_PER_SECOND);
623
+ }
624
+ /**
625
+ * Convert to nanoseconds since midnight for storage
626
+ */
627
+ toNanosSinceMidnight() {
628
+ return this.value;
629
+ }
630
+ /**
631
+ * Create from nanoseconds since midnight
632
+ */
633
+ static fromNanosSinceMidnight(nanos) {
634
+ return new _TimeValue(typeof nanos === "number" ? BigInt(nanos) : nanos);
635
+ }
636
+ /**
637
+ * Format as HH:MM:SS.nnnnnnnnn string
638
+ */
639
+ toString() {
640
+ if (this.value === void 0) {
641
+ return "undefined";
642
+ }
643
+ const hour = this.hour();
644
+ const minute = this.minute();
645
+ const second = this.second();
646
+ const nano = this.nanosecond();
647
+ const hourStr = String(hour).padStart(2, "0");
648
+ const minuteStr = String(minute).padStart(2, "0");
649
+ const secondStr = String(second).padStart(2, "0");
650
+ const nanoStr = String(nano).padStart(9, "0");
651
+ return `${hourStr}:${minuteStr}:${secondStr}.${nanoStr}`;
652
+ }
653
+ valueOf() {
654
+ return this.value;
655
+ }
656
+ /**
657
+ * Helper to parse HH:MM:SS[.nnnnnnnnn] format
658
+ */
659
+ static parseTime(str) {
660
+ const match = str.match(/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?$/);
661
+ if (!match) {
662
+ return null;
663
+ }
664
+ const hour = parseInt(match[1], 10);
665
+ const minute = parseInt(match[2], 10);
666
+ const second = parseInt(match[3], 10);
667
+ let nano = 0;
668
+ if (match[4]) {
669
+ const fracStr = match[4].padEnd(9, "0").substring(0, 9);
670
+ nano = parseInt(fracStr, 10);
671
+ }
672
+ if (hour < 0 || hour > 23) {
673
+ return null;
674
+ }
675
+ if (minute < 0 || minute > 59) {
676
+ return null;
677
+ }
678
+ if (second < 0 || second > 59) {
679
+ return null;
680
+ }
681
+ const nanos = BigInt(hour) * _TimeValue.NANOS_PER_HOUR + BigInt(minute) * _TimeValue.NANOS_PER_MINUTE + BigInt(second) * _TimeValue.NANOS_PER_SECOND + BigInt(nano);
682
+ return nanos;
683
+ }
684
+ /**
685
+ * Compare two Time values for equality
686
+ */
687
+ equals(other) {
688
+ if (other.type !== this.type) {
689
+ return false;
690
+ }
691
+ const otherTime = other;
692
+ return this.value === otherTime.value;
693
+ }
694
+ encode() {
695
+ return {
696
+ type: this.type,
697
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
698
+ };
699
+ }
700
+ };
701
+ // nanoseconds since midnight
702
+ _TimeValue.NANOS_PER_SECOND = 1000000000n;
703
+ _TimeValue.NANOS_PER_MINUTE = 60000000000n;
704
+ _TimeValue.NANOS_PER_HOUR = 3600000000000n;
705
+ _TimeValue.NANOS_PER_DAY = 86400000000000n;
706
+ var TimeValue = _TimeValue;
707
+
708
+ // src/value/datetime.ts
709
+ var DateTimeValue = class _DateTimeValue {
710
+ // nanoseconds since midnight
711
+ constructor(value) {
712
+ this.type = "DateTime";
713
+ if (value !== void 0) {
714
+ if (value instanceof Date) {
715
+ const year = value.getUTCFullYear();
716
+ const month = value.getUTCMonth() + 1;
717
+ const day = value.getUTCDate();
718
+ const hour = value.getUTCHours();
719
+ const minute = value.getUTCMinutes();
720
+ const second = value.getUTCSeconds();
721
+ const millis = value.getUTCMilliseconds();
722
+ this.months = year * 12 + (month - 1);
723
+ this.days = day;
724
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
725
+ } else if (typeof value === "string") {
726
+ const parsed = _DateTimeValue.parseDateTime(value);
727
+ if (!parsed) {
728
+ throw new Error(`Invalid datetime string: ${value}`);
729
+ }
730
+ this.months = parsed.months;
731
+ this.days = parsed.days;
732
+ this.nanos = parsed.nanos;
733
+ } else if (typeof value === "number") {
734
+ const date = new Date(value);
735
+ const year = date.getUTCFullYear();
736
+ const month = date.getUTCMonth() + 1;
737
+ const day = date.getUTCDate();
738
+ const hour = date.getUTCHours();
739
+ const minute = date.getUTCMinutes();
740
+ const second = date.getUTCSeconds();
741
+ const millis = date.getUTCMilliseconds();
742
+ this.months = year * 12 + (month - 1);
743
+ this.days = day;
744
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(millis) * 1000000n;
745
+ } else if (typeof value === "bigint") {
746
+ const millis = Number(value / 1000000n);
747
+ const extraNanos = value % 1000000n;
748
+ const date = new Date(millis);
749
+ const year = date.getUTCFullYear();
750
+ const month = date.getUTCMonth() + 1;
751
+ const day = date.getUTCDate();
752
+ const hour = date.getUTCHours();
753
+ const minute = date.getUTCMinutes();
754
+ const second = date.getUTCSeconds();
755
+ const dateMillis = date.getUTCMilliseconds();
756
+ this.months = year * 12 + (month - 1);
757
+ this.days = day;
758
+ this.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(dateMillis) * 1000000n + extraNanos;
759
+ } else {
760
+ throw new Error(`DateTime value must be a Date, string, number, or bigint, got ${typeof value}`);
761
+ }
762
+ } else {
763
+ this.months = void 0;
764
+ this.days = void 0;
765
+ this.nanos = void 0;
766
+ }
767
+ }
768
+ /**
769
+ * Create a DateTimeValue from year, month, day, hour, minute, second, nanosecond
770
+ */
771
+ static fromYMDHMSN(year, month, day, hour, minute, second, nano = 0) {
772
+ if (hour < 0 || hour > 23) {
773
+ throw new Error(`Invalid hour: ${hour}`);
774
+ }
775
+ if (minute < 0 || minute > 59) {
776
+ throw new Error(`Invalid minute: ${minute}`);
777
+ }
778
+ if (second < 0 || second > 59) {
779
+ throw new Error(`Invalid second: ${second}`);
780
+ }
781
+ if (nano < 0 || nano > 999999999) {
782
+ throw new Error(`Invalid nanosecond: ${nano}`);
783
+ }
784
+ if (!_DateTimeValue.isValidDate(year, month, day)) {
785
+ 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")}`);
786
+ }
787
+ const result = new _DateTimeValue(void 0);
788
+ result.months = year * 12 + (month - 1);
789
+ result.days = day;
790
+ result.nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + BigInt(nano);
791
+ return result;
792
+ }
793
+ /**
794
+ * Create a DateTimeValue from year, month, day, hour, minute, second (no fractional)
795
+ */
796
+ static fromYMDHMS(year, month, day, hour, minute, second) {
797
+ return _DateTimeValue.fromYMDHMSN(year, month, day, hour, minute, second, 0);
798
+ }
799
+ /**
800
+ * Create from Unix timestamp in seconds
801
+ */
802
+ static fromTimestamp(seconds) {
803
+ return new _DateTimeValue(seconds * 1e3);
804
+ }
805
+ /**
806
+ * Create from Unix timestamp in milliseconds
807
+ */
808
+ static fromTimestampMillis(millis) {
809
+ return new _DateTimeValue(millis);
810
+ }
811
+ /**
812
+ * Create from nanoseconds since Unix epoch
813
+ */
814
+ static fromNanosSinceEpoch(nanos) {
815
+ return new _DateTimeValue(nanos);
816
+ }
817
+ /**
818
+ * Create from separate seconds and nanoseconds
819
+ */
820
+ static fromParts(seconds, nanos) {
821
+ if (nanos < 0 || nanos > 999999999) {
822
+ throw new Error(`Invalid nanoseconds: ${nanos}`);
823
+ }
824
+ const millis = seconds * 1e3 + Math.floor(nanos / 1e6);
825
+ const extraNanos = nanos % 1e6;
826
+ const result = new _DateTimeValue(millis);
827
+ if (result.nanos !== void 0) {
828
+ result.nanos = result.nanos + BigInt(extraNanos);
829
+ }
830
+ return result;
831
+ }
832
+ /**
833
+ * Get current datetime
834
+ */
835
+ static now() {
836
+ return new _DateTimeValue(/* @__PURE__ */ new Date());
837
+ }
838
+ /**
839
+ * Get default datetime (Unix epoch)
840
+ */
841
+ static default() {
842
+ return _DateTimeValue.fromYMDHMS(1970, 1, 1, 0, 0, 0);
843
+ }
844
+ /**
845
+ * Parse a datetime string in ISO 8601 format
846
+ */
847
+ static parse(str) {
848
+ const trimmed = str.trim();
849
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
850
+ return new _DateTimeValue(void 0);
851
+ }
852
+ const parsed = _DateTimeValue.parseDateTime(trimmed);
853
+ if (!parsed) {
854
+ throw new Error(`Cannot parse "${str}" as DateTime`);
855
+ }
856
+ const result = new _DateTimeValue(void 0);
857
+ result.months = parsed.months;
858
+ result.days = parsed.days;
859
+ result.nanos = parsed.nanos;
860
+ return result;
861
+ }
862
+ /**
863
+ * Get Unix timestamp in seconds
864
+ */
865
+ timestamp() {
866
+ const date = this.valueOf();
867
+ if (date === void 0) return void 0;
868
+ return Math.floor(date.getTime() / 1e3);
869
+ }
870
+ /**
871
+ * Get Unix timestamp in nanoseconds
872
+ */
873
+ timestampNanos() {
874
+ const date = this.valueOf();
875
+ if (date === void 0 || this.nanos === void 0) return void 0;
876
+ const epochNanos = BigInt(date.getTime()) * 1000000n;
877
+ const subMillisNanos = this.nanos % 1000000n;
878
+ return epochNanos + subMillisNanos;
879
+ }
880
+ /**
881
+ * Convert to nanoseconds since Unix epoch for storage
882
+ */
883
+ toNanosSinceEpoch() {
884
+ return this.timestampNanos();
885
+ }
886
+ /**
887
+ * Get separate seconds and nanoseconds for storage
888
+ */
889
+ toParts() {
890
+ const date = this.valueOf();
891
+ if (date === void 0 || this.nanos === void 0) return void 0;
892
+ const seconds = Math.floor(date.getTime() / 1e3);
893
+ const millis = date.getTime() % 1e3;
894
+ const subMillisNanos = Number(this.nanos % 1000000n);
895
+ const nanos = millis * 1e6 + subMillisNanos;
896
+ return [seconds, nanos];
897
+ }
898
+ /**
899
+ * Get the date component
900
+ */
901
+ date() {
902
+ if (this.months === void 0 || this.days === void 0) return void 0;
903
+ const year = Math.floor(this.months / 12);
904
+ let m = this.months % 12;
905
+ if (m < 0) m += 12;
906
+ const month = m + 1;
907
+ return DateValue.fromYMD(year, month, this.days);
908
+ }
909
+ /**
910
+ * Get the time component
911
+ */
912
+ time() {
913
+ if (this.nanos === void 0) return void 0;
914
+ return new TimeValue(this.nanos);
915
+ }
916
+ /**
917
+ * Format as ISO 8601 string with nanosecond precision and Z suffix
918
+ */
919
+ toString() {
920
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
921
+ return "undefined";
922
+ }
923
+ const year = Math.floor(this.months / 12);
924
+ let m = this.months % 12;
925
+ if (m < 0) m += 12;
926
+ const month = String(m + 1).padStart(2, "0");
927
+ const day = String(this.days).padStart(2, "0");
928
+ const totalNanos = this.nanos;
929
+ const hours = totalNanos / 3600000000000n;
930
+ const remainingAfterHours = totalNanos % 3600000000000n;
931
+ const minutes = remainingAfterHours / 60000000000n;
932
+ const remainingAfterMinutes = remainingAfterHours % 60000000000n;
933
+ const seconds = remainingAfterMinutes / 1000000000n;
934
+ const nanosFraction = remainingAfterMinutes % 1000000000n;
935
+ const hour = String(Number(hours)).padStart(2, "0");
936
+ const minute = String(Number(minutes)).padStart(2, "0");
937
+ const second = String(Number(seconds)).padStart(2, "0");
938
+ const nanoStr = String(Number(nanosFraction)).padStart(9, "0");
939
+ let yearStr;
940
+ if (year < 0) {
941
+ const absYear = Math.abs(year);
942
+ yearStr = `-${String(absYear).padStart(4, "0")}`;
943
+ } else {
944
+ yearStr = String(year).padStart(4, "0");
945
+ }
946
+ return `${yearStr}-${month}-${day}T${hour}:${minute}:${second}.${nanoStr}Z`;
947
+ }
948
+ valueOf() {
949
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
950
+ return void 0;
951
+ }
952
+ const year = Math.floor(this.months / 12);
953
+ let m = this.months % 12;
954
+ if (m < 0) m += 12;
955
+ const month = m + 1;
956
+ const totalNanos = this.nanos;
957
+ const hours = Number(totalNanos / 3600000000000n);
958
+ const remainingAfterHours = totalNanos % 3600000000000n;
959
+ const minutes = Number(remainingAfterHours / 60000000000n);
960
+ const remainingAfterMinutes = remainingAfterHours % 60000000000n;
961
+ const seconds = Number(remainingAfterMinutes / 1000000000n);
962
+ const nanosFraction = remainingAfterMinutes % 1000000000n;
963
+ const millis = Number(nanosFraction / 1000000n);
964
+ let date;
965
+ if (year >= 0 && year < 100) {
966
+ date = new Date(Date.UTC(2e3, month - 1, this.days, hours, minutes, seconds, millis));
967
+ date.setUTCFullYear(year);
968
+ } else {
969
+ date = new Date(Date.UTC(year, month - 1, this.days, hours, minutes, seconds, millis));
970
+ }
971
+ return date;
972
+ }
973
+ /**
974
+ * Get the internal representation as a Date
975
+ */
976
+ get value() {
977
+ return this.valueOf();
978
+ }
979
+ /**
980
+ * Helper to parse ISO 8601 datetime format
981
+ */
982
+ static parseDateTime(str) {
983
+ const match = str.match(/^(-?\d{1,4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?Z$/);
984
+ if (!match) {
985
+ return null;
986
+ }
987
+ const year = parseInt(match[1], 10);
988
+ const month = parseInt(match[2], 10);
989
+ const day = parseInt(match[3], 10);
990
+ const hour = parseInt(match[4], 10);
991
+ const minute = parseInt(match[5], 10);
992
+ const second = parseInt(match[6], 10);
993
+ let nanosFraction = 0n;
994
+ if (match[7]) {
995
+ const fracStr = match[7].padEnd(9, "0").substring(0, 9);
996
+ nanosFraction = BigInt(fracStr);
997
+ }
998
+ if (month < 1 || month > 12) {
999
+ return null;
1000
+ }
1001
+ if (day < 1 || day > 31) {
1002
+ return null;
1003
+ }
1004
+ if (hour < 0 || hour > 23) {
1005
+ return null;
1006
+ }
1007
+ if (minute < 0 || minute > 59) {
1008
+ return null;
1009
+ }
1010
+ if (second < 0 || second > 59) {
1011
+ return null;
1012
+ }
1013
+ if (!_DateTimeValue.isValidDate(year, month, day)) {
1014
+ return null;
1015
+ }
1016
+ const months = year * 12 + (month - 1);
1017
+ const nanos = BigInt(hour) * 3600000000000n + BigInt(minute) * 60000000000n + BigInt(second) * 1000000000n + nanosFraction;
1018
+ return { months, days: day, nanos };
1019
+ }
1020
+ /**
1021
+ * Helper to validate a date
1022
+ */
1023
+ static isValidDate(year, month, day) {
1024
+ let date;
1025
+ if (year >= 0 && year < 100) {
1026
+ date = new Date(Date.UTC(2e3, month - 1, day));
1027
+ date.setUTCFullYear(year);
1028
+ } else {
1029
+ date = new Date(Date.UTC(year, month - 1, day));
1030
+ }
1031
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
1032
+ }
1033
+ /**
1034
+ * Compare two datetimes for equality
1035
+ */
1036
+ equals(other) {
1037
+ if (other.type !== this.type) {
1038
+ return false;
1039
+ }
1040
+ const otherDateTime = other;
1041
+ if (this.months === void 0 || otherDateTime.months === void 0) {
1042
+ return this.months === otherDateTime.months && this.days === otherDateTime.days && this.nanos === otherDateTime.nanos;
1043
+ }
1044
+ return this.months === otherDateTime.months && this.days === otherDateTime.days && this.nanos === otherDateTime.nanos;
1045
+ }
1046
+ encode() {
1047
+ return {
1048
+ type: this.type,
1049
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1050
+ };
1051
+ }
1052
+ };
1053
+
1054
+ // src/value/float4.ts
1055
+ var _Float4Value = class _Float4Value {
1056
+ constructor(value) {
1057
+ this.type = "Float4";
1058
+ if (value !== void 0) {
1059
+ if (typeof value !== "number") {
1060
+ throw new Error(`Float4 value must be a number, got ${typeof value}`);
1061
+ }
1062
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
1063
+ this.value = void 0;
1064
+ } else {
1065
+ if (value !== 0 && Math.abs(value) < _Float4Value.MIN_POSITIVE) {
1066
+ this.value = 0;
1067
+ } else if (value > _Float4Value.MAX_VALUE) {
1068
+ throw new Error(`Float4 overflow: value ${value} exceeds maximum ${_Float4Value.MAX_VALUE}`);
1069
+ } else if (value < _Float4Value.MIN_VALUE) {
1070
+ throw new Error(`Float4 underflow: value ${value} exceeds minimum ${_Float4Value.MIN_VALUE}`);
1071
+ } else {
1072
+ const float32Array = new Float32Array(1);
1073
+ float32Array[0] = value;
1074
+ this.value = float32Array[0];
1075
+ }
1076
+ }
1077
+ } else {
1078
+ this.value = void 0;
1079
+ }
1080
+ }
1081
+ static parse(str) {
1082
+ const trimmed = str.trim();
1083
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1084
+ return new _Float4Value(void 0);
1085
+ }
1086
+ const num = Number(trimmed);
1087
+ if (Number.isNaN(num) && trimmed.toLowerCase() !== "nan") {
1088
+ throw new Error(`Cannot parse "${str}" as Float4`);
1089
+ }
1090
+ return new _Float4Value(num);
1091
+ }
1092
+ valueOf() {
1093
+ return this.value;
1094
+ }
1095
+ toString() {
1096
+ return this.value === void 0 ? "undefined" : this.value.toString();
1097
+ }
1098
+ /**
1099
+ * Compare two Float4 values for equality with limited precision
1100
+ */
1101
+ equals(other) {
1102
+ if (other.type !== this.type) {
1103
+ return false;
1104
+ }
1105
+ const otherFloat = other;
1106
+ if (this.value === void 0 || otherFloat.value === void 0) {
1107
+ return this.value === otherFloat.value;
1108
+ }
1109
+ const epsilon = 1e-6;
1110
+ return Math.abs(this.value - otherFloat.value) <= epsilon;
1111
+ }
1112
+ encode() {
1113
+ return {
1114
+ type: this.type,
1115
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1116
+ };
1117
+ }
1118
+ };
1119
+ _Float4Value.MAX_VALUE = 34028235e31;
1120
+ _Float4Value.MIN_VALUE = -34028235e31;
1121
+ _Float4Value.MIN_POSITIVE = 1175494e-44;
1122
+ var Float4Value = _Float4Value;
1123
+
1124
+ // src/value/float8.ts
1125
+ var Float8Value = class _Float8Value {
1126
+ constructor(value) {
1127
+ this.type = "Float8";
1128
+ if (value !== void 0) {
1129
+ if (typeof value !== "number") {
1130
+ throw new Error(`Float8 value must be a number, got ${typeof value}`);
1131
+ }
1132
+ this.value = value;
1133
+ } else {
1134
+ this.value = void 0;
1135
+ }
1136
+ }
1137
+ static parse(str) {
1138
+ const trimmed = str.trim();
1139
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1140
+ return new _Float8Value(void 0);
1141
+ }
1142
+ const num = Number(trimmed);
1143
+ if (Number.isNaN(num) && trimmed.toLowerCase() !== "nan") {
1144
+ throw new Error(`Cannot parse "${str}" as Float8`);
1145
+ }
1146
+ return new _Float8Value(num);
1147
+ }
1148
+ valueOf() {
1149
+ return this.value;
1150
+ }
1151
+ toString() {
1152
+ return this.value === void 0 ? "undefined" : this.value.toString();
1153
+ }
1154
+ /**
1155
+ * Compare two Float8 values for equality
1156
+ */
1157
+ equals(other) {
1158
+ if (other.type !== this.type) {
1159
+ return false;
1160
+ }
1161
+ const otherFloat = other;
1162
+ return this.value === otherFloat.value;
1163
+ }
1164
+ encode() {
1165
+ return {
1166
+ type: this.type,
1167
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1168
+ };
1169
+ }
1170
+ };
1171
+
1172
+ // src/value/int1.ts
1173
+ var _Int1Value = class _Int1Value {
1174
+ constructor(value) {
1175
+ this.type = "Int1";
1176
+ if (value !== void 0) {
1177
+ if (!Number.isInteger(value)) {
1178
+ throw new Error(`Int1 value must be an integer, got ${value}`);
1179
+ }
1180
+ if (value < _Int1Value.MIN_VALUE || value > _Int1Value.MAX_VALUE) {
1181
+ throw new Error(`Int1 value must be between ${_Int1Value.MIN_VALUE} and ${_Int1Value.MAX_VALUE}, got ${value}`);
1182
+ }
1183
+ }
1184
+ this.value = value;
1185
+ }
1186
+ static parse(str) {
1187
+ const trimmed = str.trim();
1188
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1189
+ return new _Int1Value(void 0);
1190
+ }
1191
+ const num = Number(trimmed);
1192
+ if (isNaN(num)) {
1193
+ throw new Error(`Cannot parse "${str}" as Int1`);
1194
+ }
1195
+ return new _Int1Value(num);
1196
+ }
1197
+ valueOf() {
1198
+ return this.value;
1199
+ }
1200
+ toString() {
1201
+ return this.value === void 0 ? "undefined" : this.value.toString();
1202
+ }
1203
+ /**
1204
+ * Compare two Int1 values for equality
1205
+ */
1206
+ equals(other) {
1207
+ if (other.type !== this.type) {
1208
+ return false;
1209
+ }
1210
+ const otherInt = other;
1211
+ return this.value === otherInt.value;
1212
+ }
1213
+ encode() {
1214
+ return {
1215
+ type: this.type,
1216
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1217
+ };
1218
+ }
1219
+ };
1220
+ _Int1Value.MIN_VALUE = -128;
1221
+ _Int1Value.MAX_VALUE = 127;
1222
+ var Int1Value = _Int1Value;
1223
+
1224
+ // src/value/int2.ts
1225
+ var _Int2Value = class _Int2Value {
1226
+ constructor(value) {
1227
+ this.type = "Int2";
1228
+ if (value !== void 0) {
1229
+ if (!Number.isInteger(value)) {
1230
+ throw new Error(`Int2 value must be an integer, got ${value}`);
1231
+ }
1232
+ if (value < _Int2Value.MIN_VALUE || value > _Int2Value.MAX_VALUE) {
1233
+ throw new Error(`Int2 value must be between ${_Int2Value.MIN_VALUE} and ${_Int2Value.MAX_VALUE}, got ${value}`);
1234
+ }
1235
+ }
1236
+ this.value = value;
1237
+ }
1238
+ static parse(str) {
1239
+ const trimmed = str.trim();
1240
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1241
+ return new _Int2Value(void 0);
1242
+ }
1243
+ const num = Number(trimmed);
1244
+ if (isNaN(num)) {
1245
+ throw new Error(`Cannot parse "${str}" as Int2`);
1246
+ }
1247
+ return new _Int2Value(num);
1248
+ }
1249
+ valueOf() {
1250
+ return this.value;
1251
+ }
1252
+ toString() {
1253
+ return this.value === void 0 ? "undefined" : this.value.toString();
1254
+ }
1255
+ /**
1256
+ * Compare two Int2 values for equality
1257
+ */
1258
+ equals(other) {
1259
+ if (other.type !== this.type) {
1260
+ return false;
1261
+ }
1262
+ const otherInt = other;
1263
+ return this.value === otherInt.value;
1264
+ }
1265
+ encode() {
1266
+ return {
1267
+ type: this.type,
1268
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1269
+ };
1270
+ }
1271
+ };
1272
+ _Int2Value.MIN_VALUE = -32768;
1273
+ _Int2Value.MAX_VALUE = 32767;
1274
+ var Int2Value = _Int2Value;
1275
+
1276
+ // src/value/int4.ts
1277
+ var _Int4Value = class _Int4Value {
1278
+ constructor(value) {
1279
+ this.type = "Int4";
1280
+ if (value !== void 0) {
1281
+ if (!Number.isInteger(value)) {
1282
+ throw new Error(`Int4 value must be an integer, got ${value}`);
1283
+ }
1284
+ if (value < _Int4Value.MIN_VALUE || value > _Int4Value.MAX_VALUE) {
1285
+ throw new Error(`Int4 value must be between ${_Int4Value.MIN_VALUE} and ${_Int4Value.MAX_VALUE}, got ${value}`);
1286
+ }
1287
+ }
1288
+ this.value = value;
1289
+ }
1290
+ static parse(str) {
1291
+ const trimmed = str.trim();
1292
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1293
+ return new _Int4Value(void 0);
1294
+ }
1295
+ const num = Number(trimmed);
1296
+ if (isNaN(num)) {
1297
+ throw new Error(`Cannot parse "${str}" as Int4`);
1298
+ }
1299
+ return new _Int4Value(num);
1300
+ }
1301
+ valueOf() {
1302
+ return this.value;
1303
+ }
1304
+ toString() {
1305
+ return this.value === void 0 ? "undefined" : this.value.toString();
1306
+ }
1307
+ /**
1308
+ * Compare two Int4 values for equality
1309
+ */
1310
+ equals(other) {
1311
+ if (other.type !== this.type) {
1312
+ return false;
1313
+ }
1314
+ const otherInt = other;
1315
+ return this.value === otherInt.value;
1316
+ }
1317
+ encode() {
1318
+ return {
1319
+ type: this.type,
1320
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1321
+ };
1322
+ }
1323
+ };
1324
+ _Int4Value.MIN_VALUE = -2147483648;
1325
+ _Int4Value.MAX_VALUE = 2147483647;
1326
+ var Int4Value = _Int4Value;
1327
+
1328
+ // src/value/int8.ts
1329
+ var _Int8Value = class _Int8Value {
1330
+ constructor(value) {
1331
+ this.type = "Int8";
1332
+ if (value !== void 0) {
1333
+ const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
1334
+ if (bigintValue < _Int8Value.MIN_VALUE || bigintValue > _Int8Value.MAX_VALUE) {
1335
+ throw new Error(`Int8 value must be between ${_Int8Value.MIN_VALUE} and ${_Int8Value.MAX_VALUE}, got ${bigintValue}`);
1336
+ }
1337
+ this.value = bigintValue;
1338
+ } else {
1339
+ this.value = void 0;
1340
+ }
1341
+ }
1342
+ static parse(str) {
1343
+ const trimmed = str.trim();
1344
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1345
+ return new _Int8Value(void 0);
1346
+ }
1347
+ let value;
1348
+ try {
1349
+ value = BigInt(trimmed);
1350
+ } catch (e) {
1351
+ throw new Error(`Cannot parse "${str}" as Int8`);
1352
+ }
1353
+ if (value < _Int8Value.MIN_VALUE || value > _Int8Value.MAX_VALUE) {
1354
+ throw new Error(`Int8 value must be between ${_Int8Value.MIN_VALUE} and ${_Int8Value.MAX_VALUE}, got ${value}`);
1355
+ }
1356
+ return new _Int8Value(value);
1357
+ }
1358
+ valueOf() {
1359
+ return this.value;
1360
+ }
1361
+ toString() {
1362
+ return this.value === void 0 ? "undefined" : this.value.toString();
1363
+ }
1364
+ /**
1365
+ * Compare two Int8 values for equality
1366
+ */
1367
+ equals(other) {
1368
+ if (other.type !== this.type) {
1369
+ return false;
1370
+ }
1371
+ const otherInt = other;
1372
+ return this.value === otherInt.value;
1373
+ }
1374
+ encode() {
1375
+ return {
1376
+ type: this.type,
1377
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1378
+ };
1379
+ }
1380
+ };
1381
+ _Int8Value.MIN_VALUE = BigInt("-9223372036854775808");
1382
+ _Int8Value.MAX_VALUE = BigInt("9223372036854775807");
1383
+ var Int8Value = _Int8Value;
1384
+
1385
+ // src/value/int16.ts
1386
+ var _Int16Value = class _Int16Value {
1387
+ constructor(value) {
1388
+ this.type = "Int16";
1389
+ if (value !== void 0) {
1390
+ let bigintValue;
1391
+ if (typeof value === "string") {
1392
+ try {
1393
+ bigintValue = BigInt(value);
1394
+ } catch (e) {
1395
+ throw new Error(`Int16 value must be a valid integer, got ${value}`);
1396
+ }
1397
+ } else if (typeof value === "number") {
1398
+ bigintValue = BigInt(Math.trunc(value));
1399
+ } else {
1400
+ bigintValue = value;
1401
+ }
1402
+ if (bigintValue < _Int16Value.MIN_VALUE || bigintValue > _Int16Value.MAX_VALUE) {
1403
+ throw new Error(`Int16 value must be between ${_Int16Value.MIN_VALUE} and ${_Int16Value.MAX_VALUE}, got ${bigintValue}`);
1404
+ }
1405
+ this.value = bigintValue;
1406
+ } else {
1407
+ this.value = void 0;
1408
+ }
1409
+ }
1410
+ static parse(str) {
1411
+ const trimmed = str.trim();
1412
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1413
+ return new _Int16Value(void 0);
1414
+ }
1415
+ let value;
1416
+ try {
1417
+ value = BigInt(trimmed);
1418
+ } catch (e) {
1419
+ throw new Error(`Cannot parse "${str}" as Int16`);
1420
+ }
1421
+ if (value < _Int16Value.MIN_VALUE || value > _Int16Value.MAX_VALUE) {
1422
+ throw new Error(`Int16 value must be between ${_Int16Value.MIN_VALUE} and ${_Int16Value.MAX_VALUE}, got ${value}`);
1423
+ }
1424
+ return new _Int16Value(value);
1425
+ }
1426
+ valueOf() {
1427
+ return this.value;
1428
+ }
1429
+ toString() {
1430
+ return this.value === void 0 ? "undefined" : this.value.toString();
1431
+ }
1432
+ /**
1433
+ * Compare two Int16 values for equality
1434
+ */
1435
+ equals(other) {
1436
+ if (other.type !== this.type) {
1437
+ return false;
1438
+ }
1439
+ const otherInt = other;
1440
+ return this.value === otherInt.value;
1441
+ }
1442
+ encode() {
1443
+ return {
1444
+ type: this.type,
1445
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1446
+ };
1447
+ }
1448
+ };
1449
+ _Int16Value.MIN_VALUE = BigInt("-170141183460469231731687303715884105728");
1450
+ _Int16Value.MAX_VALUE = BigInt("170141183460469231731687303715884105727");
1451
+ var Int16Value = _Int16Value;
1452
+
1453
+ // src/value/interval.ts
1454
+ var IntervalValue = class _IntervalValue {
1455
+ // all time components as nanoseconds
1456
+ constructor(value) {
1457
+ this.type = "Interval";
1458
+ if (value !== void 0) {
1459
+ if (typeof value === "string") {
1460
+ const parsed = _IntervalValue.parseDuration(value);
1461
+ if (!parsed) {
1462
+ throw new Error(`Invalid interval string: ${value}`);
1463
+ }
1464
+ this.months = parsed.months;
1465
+ this.days = parsed.days;
1466
+ this.nanos = parsed.nanos;
1467
+ } else if (typeof value === "object" && value !== null) {
1468
+ this.months = value.months;
1469
+ this.days = value.days;
1470
+ this.nanos = value.nanos;
1471
+ } else {
1472
+ throw new Error(`Interval value must be an object or string, got ${typeof value}`);
1473
+ }
1474
+ } else {
1475
+ this.months = void 0;
1476
+ this.days = void 0;
1477
+ this.nanos = void 0;
1478
+ }
1479
+ }
1480
+ /**
1481
+ * Create a new interval from months, days, and nanoseconds
1482
+ */
1483
+ static new(months, days, nanos) {
1484
+ return new _IntervalValue({ months, days, nanos });
1485
+ }
1486
+ /**
1487
+ * Create an interval from seconds
1488
+ */
1489
+ static fromSeconds(seconds) {
1490
+ return new _IntervalValue({ months: 0, days: 0, nanos: BigInt(seconds) * 1000000000n });
1491
+ }
1492
+ /**
1493
+ * Create an interval from milliseconds
1494
+ */
1495
+ static fromMilliseconds(milliseconds) {
1496
+ return new _IntervalValue({ months: 0, days: 0, nanos: BigInt(milliseconds) * 1000000n });
1497
+ }
1498
+ /**
1499
+ * Create an interval from microseconds
1500
+ */
1501
+ static fromMicroseconds(microseconds) {
1502
+ return new _IntervalValue({ months: 0, days: 0, nanos: BigInt(microseconds) * 1000n });
1503
+ }
1504
+ /**
1505
+ * Create an interval from nanoseconds
1506
+ */
1507
+ static fromNanoseconds(nanoseconds) {
1508
+ return new _IntervalValue({ months: 0, days: 0, nanos: nanoseconds });
1509
+ }
1510
+ /**
1511
+ * Create an interval from minutes
1512
+ */
1513
+ static fromMinutes(minutes) {
1514
+ return new _IntervalValue({ months: 0, days: 0, nanos: BigInt(minutes) * 60n * 1000000000n });
1515
+ }
1516
+ /**
1517
+ * Create an interval from hours
1518
+ */
1519
+ static fromHours(hours) {
1520
+ return new _IntervalValue({ months: 0, days: 0, nanos: BigInt(hours) * 60n * 60n * 1000000000n });
1521
+ }
1522
+ /**
1523
+ * Create an interval from days
1524
+ */
1525
+ static fromDays(days) {
1526
+ return new _IntervalValue({ months: 0, days, nanos: 0n });
1527
+ }
1528
+ /**
1529
+ * Create an interval from weeks
1530
+ */
1531
+ static fromWeeks(weeks) {
1532
+ return new _IntervalValue({ months: 0, days: weeks * 7, nanos: 0n });
1533
+ }
1534
+ /**
1535
+ * Create an interval from months
1536
+ */
1537
+ static fromMonths(months) {
1538
+ return new _IntervalValue({ months, days: 0, nanos: 0n });
1539
+ }
1540
+ /**
1541
+ * Create an interval from years
1542
+ */
1543
+ static fromYears(years) {
1544
+ return new _IntervalValue({ months: years * 12, days: 0, nanos: 0n });
1545
+ }
1546
+ /**
1547
+ * Create a zero interval
1548
+ */
1549
+ static zero() {
1550
+ return new _IntervalValue({ months: 0, days: 0, nanos: 0n });
1551
+ }
1552
+ /**
1553
+ * Get default interval (zero)
1554
+ */
1555
+ static default() {
1556
+ return _IntervalValue.zero();
1557
+ }
1558
+ /**
1559
+ * Parse an interval string in ISO 8601 duration format
1560
+ */
1561
+ static parse(str) {
1562
+ const trimmed = str.trim();
1563
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1564
+ return new _IntervalValue(void 0);
1565
+ }
1566
+ const parsed = _IntervalValue.parseDuration(trimmed);
1567
+ if (!parsed) {
1568
+ throw new Error(`Cannot parse "${str}" as Interval`);
1569
+ }
1570
+ return new _IntervalValue({ months: parsed.months, days: parsed.days, nanos: parsed.nanos });
1571
+ }
1572
+ /**
1573
+ * Get total seconds (truncated)
1574
+ */
1575
+ seconds() {
1576
+ if (this.nanos === void 0) return void 0;
1577
+ return this.nanos / 1000000000n;
1578
+ }
1579
+ /**
1580
+ * Get total milliseconds (truncated)
1581
+ */
1582
+ milliseconds() {
1583
+ if (this.nanos === void 0) return void 0;
1584
+ return this.nanos / 1000000n;
1585
+ }
1586
+ /**
1587
+ * Get total microseconds (truncated)
1588
+ */
1589
+ microseconds() {
1590
+ if (this.nanos === void 0) return void 0;
1591
+ return this.nanos / 1000n;
1592
+ }
1593
+ /**
1594
+ * Get total nanoseconds
1595
+ */
1596
+ nanoseconds() {
1597
+ return this.nanos;
1598
+ }
1599
+ /**
1600
+ * Get months component
1601
+ */
1602
+ getMonths() {
1603
+ return this.months;
1604
+ }
1605
+ /**
1606
+ * Get days component
1607
+ */
1608
+ getDays() {
1609
+ return this.days;
1610
+ }
1611
+ /**
1612
+ * Get nanoseconds component
1613
+ */
1614
+ getNanos() {
1615
+ return this.nanos;
1616
+ }
1617
+ /**
1618
+ * Check if interval is positive (any component > 0)
1619
+ */
1620
+ isPositive() {
1621
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1622
+ return false;
1623
+ }
1624
+ return this.months > 0 || this.days > 0 || this.nanos > 0n;
1625
+ }
1626
+ /**
1627
+ * Check if interval is negative (any component < 0)
1628
+ */
1629
+ isNegative() {
1630
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1631
+ return false;
1632
+ }
1633
+ return this.months < 0 || this.days < 0 || this.nanos < 0n;
1634
+ }
1635
+ /**
1636
+ * Get absolute value of interval
1637
+ */
1638
+ abs() {
1639
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1640
+ return new _IntervalValue(void 0);
1641
+ }
1642
+ return new _IntervalValue({
1643
+ months: Math.abs(this.months),
1644
+ days: Math.abs(this.days),
1645
+ nanos: this.nanos < 0n ? -this.nanos : this.nanos
1646
+ });
1647
+ }
1648
+ /**
1649
+ * Negate the interval
1650
+ */
1651
+ negate() {
1652
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1653
+ return new _IntervalValue(void 0);
1654
+ }
1655
+ return new _IntervalValue({
1656
+ months: -this.months,
1657
+ days: -this.days,
1658
+ nanos: -this.nanos
1659
+ });
1660
+ }
1661
+ /**
1662
+ * Format as ISO 8601 duration string
1663
+ */
1664
+ toString() {
1665
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1666
+ return "undefined";
1667
+ }
1668
+ if (this.months === 0 && this.days === 0 && this.nanos === 0n) {
1669
+ return "PT0S";
1670
+ }
1671
+ let result = "P";
1672
+ const years = Math.floor(this.months / 12);
1673
+ const months = this.months % 12;
1674
+ if (years !== 0) {
1675
+ result += `${years}Y`;
1676
+ }
1677
+ if (months !== 0) {
1678
+ result += `${months}M`;
1679
+ }
1680
+ const totalSeconds = this.nanos / 1000000000n;
1681
+ const remainingNanos = this.nanos % 1000000000n;
1682
+ const extraDays = totalSeconds / 86400n;
1683
+ const remainingSeconds = totalSeconds % 86400n;
1684
+ const displayDays = this.days + Number(extraDays);
1685
+ const hours = remainingSeconds / 3600n;
1686
+ const minutes = remainingSeconds % 3600n / 60n;
1687
+ const seconds = remainingSeconds % 60n;
1688
+ if (displayDays !== 0) {
1689
+ result += `${displayDays}D`;
1690
+ }
1691
+ if (hours !== 0n || minutes !== 0n || seconds !== 0n || remainingNanos !== 0n) {
1692
+ result += "T";
1693
+ if (hours !== 0n) {
1694
+ result += `${hours}H`;
1695
+ }
1696
+ if (minutes !== 0n) {
1697
+ result += `${minutes}M`;
1698
+ }
1699
+ if (seconds !== 0n || remainingNanos !== 0n) {
1700
+ if (remainingNanos !== 0n) {
1701
+ const fractional = Number(remainingNanos) / 1e9;
1702
+ const totalSecondsFloat = Number(seconds) + fractional;
1703
+ const formatted = totalSecondsFloat.toFixed(9).replace(/0+$/, "").replace(/\.$/, "");
1704
+ result += `${formatted}S`;
1705
+ } else {
1706
+ result += `${seconds}S`;
1707
+ }
1708
+ }
1709
+ }
1710
+ return result;
1711
+ }
1712
+ valueOf() {
1713
+ if (this.months === void 0 || this.days === void 0 || this.nanos === void 0) {
1714
+ return void 0;
1715
+ }
1716
+ return { months: this.months, days: this.days, nanos: this.nanos };
1717
+ }
1718
+ /**
1719
+ * Get the internal representation
1720
+ */
1721
+ get value() {
1722
+ return this.valueOf();
1723
+ }
1724
+ /**
1725
+ * Helper to parse ISO 8601 duration format
1726
+ */
1727
+ static parseDuration(str) {
1728
+ const negative = str.startsWith("-");
1729
+ const cleanStr = negative ? str.substring(1) : str;
1730
+ if (!cleanStr.startsWith("P")) {
1731
+ return null;
1732
+ }
1733
+ const match = cleanStr.match(/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/);
1734
+ if (!match) {
1735
+ return null;
1736
+ }
1737
+ if (!match[1] && !match[2] && !match[3] && !match[4] && !match[5] && !match[6]) {
1738
+ return null;
1739
+ }
1740
+ const years = parseInt(match[1] || "0", 10);
1741
+ const months = parseInt(match[2] || "0", 10);
1742
+ const days = parseInt(match[3] || "0", 10);
1743
+ const hours = parseInt(match[4] || "0", 10);
1744
+ const minutes = parseInt(match[5] || "0", 10);
1745
+ const secondsStr = match[6] || "0";
1746
+ const secondsParts = secondsStr.split(".");
1747
+ const wholeSeconds = parseInt(secondsParts[0] || "0", 10);
1748
+ let fracNanos = 0n;
1749
+ if (secondsParts.length > 1) {
1750
+ const fracStr = secondsParts[1].padEnd(9, "0").substring(0, 9);
1751
+ fracNanos = BigInt(fracStr);
1752
+ }
1753
+ const totalNanos = BigInt(hours) * 3600n * 1000000000n + BigInt(minutes) * 60n * 1000000000n + BigInt(wholeSeconds) * 1000000000n + fracNanos;
1754
+ const totalMonths = years * 12 + months;
1755
+ if (negative) {
1756
+ return {
1757
+ months: -totalMonths,
1758
+ days: -days,
1759
+ nanos: -totalNanos
1760
+ };
1761
+ } else {
1762
+ return {
1763
+ months: totalMonths,
1764
+ days,
1765
+ nanos: totalNanos
1766
+ };
1767
+ }
1768
+ }
1769
+ /**
1770
+ * Compare two intervals for equality
1771
+ */
1772
+ equals(other) {
1773
+ if (other.type !== this.type) {
1774
+ return false;
1775
+ }
1776
+ const otherInterval = other;
1777
+ if (this.months === void 0 || otherInterval.months === void 0) {
1778
+ return this.months === otherInterval.months && this.days === otherInterval.days && this.nanos === otherInterval.nanos;
1779
+ }
1780
+ return this.months === otherInterval.months && this.days === otherInterval.days && this.nanos === otherInterval.nanos;
1781
+ }
1782
+ encode() {
1783
+ return {
1784
+ type: this.type,
1785
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1786
+ };
1787
+ }
1788
+ };
1789
+
1790
+ // src/value/uint1.ts
1791
+ var _Uint1Value = class _Uint1Value {
1792
+ constructor(value) {
1793
+ this.type = "Uint1";
1794
+ if (value !== void 0) {
1795
+ if (!Number.isInteger(value)) {
1796
+ throw new Error(`Uint1 value must be an integer, got ${value}`);
1797
+ }
1798
+ if (value < _Uint1Value.MIN_VALUE || value > _Uint1Value.MAX_VALUE) {
1799
+ throw new Error(`Uint1 value must be between ${_Uint1Value.MIN_VALUE} and ${_Uint1Value.MAX_VALUE}, got ${value}`);
1800
+ }
1801
+ }
1802
+ this.value = value;
1803
+ }
1804
+ static parse(str) {
1805
+ const trimmed = str.trim();
1806
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1807
+ return new _Uint1Value(void 0);
1808
+ }
1809
+ const num = Number(trimmed);
1810
+ if (isNaN(num)) {
1811
+ throw new Error(`Cannot parse "${str}" as Uint1`);
1812
+ }
1813
+ return new _Uint1Value(num);
1814
+ }
1815
+ valueOf() {
1816
+ return this.value;
1817
+ }
1818
+ toString() {
1819
+ return this.value === void 0 ? "undefined" : this.value.toString();
1820
+ }
1821
+ /**
1822
+ * Compare two Uint1 values for equality
1823
+ */
1824
+ equals(other) {
1825
+ if (other.type !== this.type) {
1826
+ return false;
1827
+ }
1828
+ const otherUint = other;
1829
+ return this.value === otherUint.value;
1830
+ }
1831
+ encode() {
1832
+ return {
1833
+ type: this.type,
1834
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1835
+ };
1836
+ }
1837
+ };
1838
+ _Uint1Value.MIN_VALUE = 0;
1839
+ _Uint1Value.MAX_VALUE = 255;
1840
+ var Uint1Value = _Uint1Value;
1841
+
1842
+ // src/value/uint2.ts
1843
+ var _Uint2Value = class _Uint2Value {
1844
+ constructor(value) {
1845
+ this.type = "Uint2";
1846
+ if (value !== void 0) {
1847
+ if (!Number.isInteger(value)) {
1848
+ throw new Error(`Uint2 value must be an integer, got ${value}`);
1849
+ }
1850
+ if (value < _Uint2Value.MIN_VALUE || value > _Uint2Value.MAX_VALUE) {
1851
+ throw new Error(`Uint2 value must be between ${_Uint2Value.MIN_VALUE} and ${_Uint2Value.MAX_VALUE}, got ${value}`);
1852
+ }
1853
+ }
1854
+ this.value = value;
1855
+ }
1856
+ static parse(str) {
1857
+ const trimmed = str.trim();
1858
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1859
+ return new _Uint2Value(void 0);
1860
+ }
1861
+ const num = Number(trimmed);
1862
+ if (isNaN(num)) {
1863
+ throw new Error(`Cannot parse "${str}" as Uint2`);
1864
+ }
1865
+ return new _Uint2Value(num);
1866
+ }
1867
+ valueOf() {
1868
+ return this.value;
1869
+ }
1870
+ toString() {
1871
+ return this.value === void 0 ? "undefined" : this.value.toString();
1872
+ }
1873
+ /**
1874
+ * Compare two Uint2 values for equality
1875
+ */
1876
+ equals(other) {
1877
+ if (other.type !== this.type) {
1878
+ return false;
1879
+ }
1880
+ const otherUint = other;
1881
+ return this.value === otherUint.value;
1882
+ }
1883
+ encode() {
1884
+ return {
1885
+ type: this.type,
1886
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1887
+ };
1888
+ }
1889
+ };
1890
+ _Uint2Value.MIN_VALUE = 0;
1891
+ _Uint2Value.MAX_VALUE = 65535;
1892
+ var Uint2Value = _Uint2Value;
1893
+
1894
+ // src/value/uint4.ts
1895
+ var _Uint4Value = class _Uint4Value {
1896
+ constructor(value) {
1897
+ this.type = "Uint4";
1898
+ if (value !== void 0) {
1899
+ if (!Number.isInteger(value)) {
1900
+ throw new Error(`Uint4 value must be an integer, got ${value}`);
1901
+ }
1902
+ if (value < _Uint4Value.MIN_VALUE || value > _Uint4Value.MAX_VALUE) {
1903
+ throw new Error(`Uint4 value must be between ${_Uint4Value.MIN_VALUE} and ${_Uint4Value.MAX_VALUE}, got ${value}`);
1904
+ }
1905
+ }
1906
+ this.value = value;
1907
+ }
1908
+ static parse(str) {
1909
+ const trimmed = str.trim();
1910
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1911
+ return new _Uint4Value(void 0);
1912
+ }
1913
+ const num = Number(trimmed);
1914
+ if (isNaN(num)) {
1915
+ throw new Error(`Cannot parse "${str}" as Uint4`);
1916
+ }
1917
+ return new _Uint4Value(num);
1918
+ }
1919
+ valueOf() {
1920
+ return this.value;
1921
+ }
1922
+ toString() {
1923
+ return this.value === void 0 ? "undefined" : this.value.toString();
1924
+ }
1925
+ /**
1926
+ * Compare two Uint4 values for equality
1927
+ */
1928
+ equals(other) {
1929
+ if (other.type !== this.type) {
1930
+ return false;
1931
+ }
1932
+ const otherUint = other;
1933
+ return this.value === otherUint.value;
1934
+ }
1935
+ encode() {
1936
+ return {
1937
+ type: this.type,
1938
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
1939
+ };
1940
+ }
1941
+ };
1942
+ _Uint4Value.MIN_VALUE = 0;
1943
+ _Uint4Value.MAX_VALUE = 4294967295;
1944
+ var Uint4Value = _Uint4Value;
1945
+
1946
+ // src/value/uint8.ts
1947
+ var _Uint8Value = class _Uint8Value {
1948
+ constructor(value) {
1949
+ this.type = "Uint8";
1950
+ if (value !== void 0) {
1951
+ const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
1952
+ if (bigintValue < _Uint8Value.MIN_VALUE || bigintValue > _Uint8Value.MAX_VALUE) {
1953
+ throw new Error(`Uint8 value must be between ${_Uint8Value.MIN_VALUE} and ${_Uint8Value.MAX_VALUE}, got ${bigintValue}`);
1954
+ }
1955
+ this.value = bigintValue;
1956
+ } else {
1957
+ this.value = void 0;
1958
+ }
1959
+ }
1960
+ static parse(str) {
1961
+ const trimmed = str.trim();
1962
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
1963
+ return new _Uint8Value(void 0);
1964
+ }
1965
+ let value;
1966
+ try {
1967
+ value = BigInt(trimmed);
1968
+ } catch (e) {
1969
+ throw new Error(`Cannot parse "${str}" as Uint8`);
1970
+ }
1971
+ if (value < _Uint8Value.MIN_VALUE || value > _Uint8Value.MAX_VALUE) {
1972
+ throw new Error(`Uint8 value must be between ${_Uint8Value.MIN_VALUE} and ${_Uint8Value.MAX_VALUE}, got ${value}`);
1973
+ }
1974
+ return new _Uint8Value(value);
1975
+ }
1976
+ valueOf() {
1977
+ return this.value;
1978
+ }
1979
+ toNumber() {
1980
+ if (this.value === void 0) return void 0;
1981
+ return Number(this.value);
1982
+ }
1983
+ toString() {
1984
+ return this.value === void 0 ? "undefined" : this.value.toString();
1985
+ }
1986
+ /**
1987
+ * Compare two Uint8 values for equality
1988
+ */
1989
+ equals(other) {
1990
+ if (other.type !== this.type) {
1991
+ return false;
1992
+ }
1993
+ const otherUint = other;
1994
+ return this.value === otherUint.value;
1995
+ }
1996
+ encode() {
1997
+ return {
1998
+ type: this.type,
1999
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2000
+ };
2001
+ }
2002
+ };
2003
+ _Uint8Value.MIN_VALUE = BigInt(0);
2004
+ _Uint8Value.MAX_VALUE = BigInt("18446744073709551615");
2005
+ var Uint8Value = _Uint8Value;
2006
+
2007
+ // src/value/uint16.ts
2008
+ var _Uint16Value = class _Uint16Value {
2009
+ constructor(value) {
2010
+ this.type = "Uint16";
2011
+ if (value !== void 0) {
2012
+ let bigintValue;
2013
+ if (typeof value === "string") {
2014
+ try {
2015
+ bigintValue = BigInt(value);
2016
+ } catch (e) {
2017
+ throw new Error(`Uint16 value must be a valid integer, got ${value}`);
2018
+ }
2019
+ } else if (typeof value === "number") {
2020
+ bigintValue = BigInt(Math.trunc(value));
2021
+ } else {
2022
+ bigintValue = value;
2023
+ }
2024
+ if (bigintValue < _Uint16Value.MIN_VALUE || bigintValue > _Uint16Value.MAX_VALUE) {
2025
+ throw new Error(`Uint16 value must be between ${_Uint16Value.MIN_VALUE} and ${_Uint16Value.MAX_VALUE}, got ${bigintValue}`);
2026
+ }
2027
+ this.value = bigintValue;
2028
+ } else {
2029
+ this.value = void 0;
2030
+ }
2031
+ }
2032
+ static parse(str) {
2033
+ const trimmed = str.trim();
2034
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
2035
+ return new _Uint16Value(void 0);
2036
+ }
2037
+ let value;
2038
+ try {
2039
+ value = BigInt(trimmed);
2040
+ } catch (e) {
2041
+ throw new Error(`Cannot parse "${str}" as Uint16`);
2042
+ }
2043
+ if (value < _Uint16Value.MIN_VALUE || value > _Uint16Value.MAX_VALUE) {
2044
+ throw new Error(`Uint16 value must be between ${_Uint16Value.MIN_VALUE} and ${_Uint16Value.MAX_VALUE}, got ${value}`);
2045
+ }
2046
+ return new _Uint16Value(value);
2047
+ }
2048
+ valueOf() {
2049
+ return this.value;
2050
+ }
2051
+ toString() {
2052
+ return this.value === void 0 ? "undefined" : this.value.toString();
2053
+ }
2054
+ /**
2055
+ * Compare two Uint16 values for equality
2056
+ */
2057
+ equals(other) {
2058
+ if (other.type !== this.type) {
2059
+ return false;
2060
+ }
2061
+ const otherUint = other;
2062
+ return this.value === otherUint.value;
2063
+ }
2064
+ encode() {
2065
+ return {
2066
+ type: this.type,
2067
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2068
+ };
2069
+ }
2070
+ };
2071
+ _Uint16Value.MIN_VALUE = BigInt(0);
2072
+ _Uint16Value.MAX_VALUE = BigInt("340282366920938463463374607431768211455");
2073
+ var Uint16Value = _Uint16Value;
2074
+
2075
+ // src/value/rownumber.ts
2076
+ var _RowNumberValue = class _RowNumberValue {
2077
+ constructor(value) {
2078
+ this.type = "RowNumber";
2079
+ if (value !== void 0) {
2080
+ const bigintValue = typeof value === "number" ? BigInt(Math.trunc(value)) : value;
2081
+ if (bigintValue < _RowNumberValue.MIN_VALUE || bigintValue > _RowNumberValue.MAX_VALUE) {
2082
+ throw new Error(`RowNumber value must be between ${_RowNumberValue.MIN_VALUE} and ${_RowNumberValue.MAX_VALUE}, got ${bigintValue}`);
2083
+ }
2084
+ this.value = bigintValue;
2085
+ } else {
2086
+ this.value = void 0;
2087
+ }
2088
+ }
2089
+ static parse(str) {
2090
+ const trimmed = str.trim();
2091
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
2092
+ return new _RowNumberValue(void 0);
2093
+ }
2094
+ let value;
2095
+ try {
2096
+ value = BigInt(trimmed);
2097
+ } catch (e) {
2098
+ throw new Error(`Cannot parse "${str}" as RowNumber`);
2099
+ }
2100
+ if (value < _RowNumberValue.MIN_VALUE || value > _RowNumberValue.MAX_VALUE) {
2101
+ throw new Error(`RowNumber value must be between ${_RowNumberValue.MIN_VALUE} and ${_RowNumberValue.MAX_VALUE}, got ${value}`);
2102
+ }
2103
+ return new _RowNumberValue(value);
2104
+ }
2105
+ valueOf() {
2106
+ return this.value;
2107
+ }
2108
+ toString() {
2109
+ return this.value === void 0 ? "undefined" : this.value.toString();
2110
+ }
2111
+ /**
2112
+ * Compare two RowNumber values for equality
2113
+ */
2114
+ equals(other) {
2115
+ if (other.type !== this.type) {
2116
+ return false;
2117
+ }
2118
+ const otherRowNumber = other;
2119
+ return this.value === otherRowNumber.value;
2120
+ }
2121
+ encode() {
2122
+ return {
2123
+ type: this.type,
2124
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2125
+ };
2126
+ }
2127
+ };
2128
+ _RowNumberValue.MIN_VALUE = BigInt(0);
2129
+ _RowNumberValue.MAX_VALUE = BigInt("18446744073709551615");
2130
+ var RowNumberValue = _RowNumberValue;
2131
+
2132
+ // src/value/undefined.ts
2133
+ var UndefinedValue = class _UndefinedValue {
2134
+ constructor() {
2135
+ this.type = "Undefined";
2136
+ }
2137
+ /**
2138
+ * Create a new UndefinedValue
2139
+ */
2140
+ static new() {
2141
+ return new _UndefinedValue();
2142
+ }
2143
+ /**
2144
+ * Get default UndefinedValue
2145
+ */
2146
+ static default() {
2147
+ return new _UndefinedValue();
2148
+ }
2149
+ /**
2150
+ * Parse a string as undefined
2151
+ */
2152
+ static parse(str) {
2153
+ const trimmed = str.trim();
2154
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE || trimmed === "undefined") {
2155
+ return new _UndefinedValue();
2156
+ }
2157
+ throw new Error(`Cannot parse "${str}" as Undefined`);
2158
+ }
2159
+ /**
2160
+ * Check if this value is undefined (always true)
2161
+ */
2162
+ isUndefined() {
2163
+ return true;
2164
+ }
2165
+ /**
2166
+ * Format as string
2167
+ */
2168
+ toString() {
2169
+ return "undefined";
2170
+ }
2171
+ valueOf() {
2172
+ return void 0;
2173
+ }
2174
+ /**
2175
+ * Get the internal representation (always undefined)
2176
+ */
2177
+ get value() {
2178
+ return void 0;
2179
+ }
2180
+ /**
2181
+ * Compare two undefined values (always equal)
2182
+ */
2183
+ equals(other) {
2184
+ if (other.type !== this.type) {
2185
+ return false;
2186
+ }
2187
+ return true;
2188
+ }
2189
+ /**
2190
+ * Compare two undefined values for ordering (always equal)
2191
+ */
2192
+ compare(other) {
2193
+ return 0;
2194
+ }
2195
+ encode() {
2196
+ return {
2197
+ type: this.type,
2198
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2199
+ };
2200
+ }
2201
+ };
2202
+
2203
+ // src/value/utf8.ts
2204
+ var Utf8Value = class _Utf8Value {
2205
+ constructor(value) {
2206
+ this.type = "Utf8";
2207
+ if (value !== void 0) {
2208
+ if (typeof value !== "string") {
2209
+ throw new Error(`Utf8 value must be a string, got ${typeof value}`);
2210
+ }
2211
+ this.value = value;
2212
+ } else {
2213
+ this.value = void 0;
2214
+ }
2215
+ }
2216
+ static parse(str) {
2217
+ if (str === UNDEFINED_VALUE) {
2218
+ return new _Utf8Value(void 0);
2219
+ }
2220
+ return new _Utf8Value(str);
2221
+ }
2222
+ valueOf() {
2223
+ return this.value;
2224
+ }
2225
+ toString() {
2226
+ return this.value === void 0 ? "undefined" : this.value;
2227
+ }
2228
+ /**
2229
+ * Compare two Utf8 values for equality
2230
+ */
2231
+ equals(other) {
2232
+ if (other.type !== this.type) {
2233
+ return false;
2234
+ }
2235
+ const otherUtf8 = other;
2236
+ return this.value === otherUtf8.value;
2237
+ }
2238
+ encode() {
2239
+ return {
2240
+ type: this.type,
2241
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2242
+ };
2243
+ }
2244
+ };
2245
+
2246
+ // src/value/uuid4.ts
2247
+ import { v4 as uuidv4, NIL as NIL_UUID, validate, version } from "uuid";
2248
+ var Uuid4Value = class _Uuid4Value {
2249
+ constructor(value) {
2250
+ this.type = "Uuid4";
2251
+ if (value !== void 0) {
2252
+ if (typeof value !== "string") {
2253
+ throw new Error(`Uuid4 value must be a string, got ${typeof value}`);
2254
+ }
2255
+ if (!validate(value)) {
2256
+ throw new Error(`Invalid UUID format: ${value}`);
2257
+ }
2258
+ const ver = version(value);
2259
+ if (value !== NIL_UUID && ver !== 4) {
2260
+ throw new Error(`Invalid UUID version for Uuid4: expected v4, got v${ver}`);
2261
+ }
2262
+ this.uuid = value.toLowerCase();
2263
+ } else {
2264
+ this.uuid = void 0;
2265
+ }
2266
+ }
2267
+ /**
2268
+ * Generate a new random UUID v4
2269
+ */
2270
+ static generate() {
2271
+ return new _Uuid4Value(uuidv4());
2272
+ }
2273
+ /**
2274
+ * Create a new Uuid4Value from a string
2275
+ */
2276
+ static new(uuid) {
2277
+ return new _Uuid4Value(uuid);
2278
+ }
2279
+ /**
2280
+ * Get the nil UUID (all zeros)
2281
+ */
2282
+ static nil() {
2283
+ return new _Uuid4Value(NIL_UUID);
2284
+ }
2285
+ /**
2286
+ * Get default Uuid4Value (nil UUID)
2287
+ */
2288
+ static default() {
2289
+ return _Uuid4Value.nil();
2290
+ }
2291
+ /**
2292
+ * Parse a UUID string
2293
+ */
2294
+ static parse(str) {
2295
+ const trimmed = str.trim();
2296
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
2297
+ return new _Uuid4Value(void 0);
2298
+ }
2299
+ if (!validate(trimmed)) {
2300
+ throw new Error(`Cannot parse "${str}" as Uuid4`);
2301
+ }
2302
+ const ver = version(trimmed);
2303
+ if (trimmed !== NIL_UUID && ver !== 4) {
2304
+ throw new Error(`Cannot parse "${str}" as Uuid4: wrong version (v${ver})`);
2305
+ }
2306
+ return new _Uuid4Value(trimmed);
2307
+ }
2308
+ /**
2309
+ * Get the UUID string
2310
+ */
2311
+ asString() {
2312
+ return this.uuid;
2313
+ }
2314
+ /**
2315
+ * Get the UUID as bytes (16-byte array)
2316
+ */
2317
+ asBytes() {
2318
+ if (this.uuid === void 0) return void 0;
2319
+ const hex = this.uuid.replace(/-/g, "");
2320
+ const bytes = new Uint8Array(16);
2321
+ for (let i = 0; i < 16; i++) {
2322
+ bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
2323
+ }
2324
+ return bytes;
2325
+ }
2326
+ /**
2327
+ * Check if this is the nil UUID
2328
+ */
2329
+ isNil() {
2330
+ return this.uuid === NIL_UUID;
2331
+ }
2332
+ /**
2333
+ * Get the UUID version
2334
+ */
2335
+ getVersion() {
2336
+ if (this.uuid === void 0) return void 0;
2337
+ return version(this.uuid);
2338
+ }
2339
+ /**
2340
+ * Format as string
2341
+ */
2342
+ toString() {
2343
+ if (this.uuid === void 0) {
2344
+ return "undefined";
2345
+ }
2346
+ return this.uuid;
2347
+ }
2348
+ valueOf() {
2349
+ return this.uuid;
2350
+ }
2351
+ /**
2352
+ * Get the internal representation
2353
+ */
2354
+ get value() {
2355
+ return this.valueOf();
2356
+ }
2357
+ /**
2358
+ * Compare two UUID4 values for equality
2359
+ */
2360
+ equals(other) {
2361
+ if (other.type !== this.type) {
2362
+ return false;
2363
+ }
2364
+ const otherUuid = other;
2365
+ return this.uuid === otherUuid.uuid;
2366
+ }
2367
+ /**
2368
+ * Compare two UUID4 values (for ordering)
2369
+ */
2370
+ compare(other) {
2371
+ if (this.uuid === void 0 || other.uuid === void 0) {
2372
+ if (this.uuid === other.uuid) return 0;
2373
+ if (this.uuid === void 0) return -1;
2374
+ return 1;
2375
+ }
2376
+ const thisBytes = this.asBytes();
2377
+ const otherBytes = other.asBytes();
2378
+ for (let i = 0; i < 16; i++) {
2379
+ if (thisBytes[i] < otherBytes[i]) return -1;
2380
+ if (thisBytes[i] > otherBytes[i]) return 1;
2381
+ }
2382
+ return 0;
2383
+ }
2384
+ encode() {
2385
+ return {
2386
+ type: this.type,
2387
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2388
+ };
2389
+ }
2390
+ };
2391
+
2392
+ // src/value/uuid7.ts
2393
+ import { v7 as uuidv7, NIL as NIL_UUID2, validate as validate2, version as version2 } from "uuid";
2394
+ var Uuid7Value = class _Uuid7Value {
2395
+ constructor(value) {
2396
+ this.type = "Uuid7";
2397
+ if (value !== void 0) {
2398
+ if (typeof value !== "string") {
2399
+ throw new Error(`Uuid7 value must be a string, got ${typeof value}`);
2400
+ }
2401
+ if (!validate2(value)) {
2402
+ throw new Error(`Invalid UUID format: ${value}`);
2403
+ }
2404
+ const ver = version2(value);
2405
+ if (value !== NIL_UUID2 && ver !== 7) {
2406
+ throw new Error(`Invalid UUID version for Uuid7: expected v7, got v${ver}`);
2407
+ }
2408
+ this.uuid = value.toLowerCase();
2409
+ } else {
2410
+ this.uuid = void 0;
2411
+ }
2412
+ }
2413
+ /**
2414
+ * Generate a new timestamp-based UUID v7
2415
+ */
2416
+ static generate() {
2417
+ return new _Uuid7Value(uuidv7());
2418
+ }
2419
+ /**
2420
+ * Create a new Uuid7Value from a string
2421
+ */
2422
+ static new(uuid) {
2423
+ return new _Uuid7Value(uuid);
2424
+ }
2425
+ /**
2426
+ * Get the nil UUID (all zeros)
2427
+ */
2428
+ static nil() {
2429
+ return new _Uuid7Value(NIL_UUID2);
2430
+ }
2431
+ /**
2432
+ * Get default Uuid7Value (nil UUID)
2433
+ */
2434
+ static default() {
2435
+ return _Uuid7Value.nil();
2436
+ }
2437
+ /**
2438
+ * Parse a UUID string
2439
+ */
2440
+ static parse(str) {
2441
+ const trimmed = str.trim();
2442
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
2443
+ return new _Uuid7Value(void 0);
2444
+ }
2445
+ if (!validate2(trimmed)) {
2446
+ throw new Error(`Cannot parse "${str}" as Uuid7`);
2447
+ }
2448
+ const ver = version2(trimmed);
2449
+ if (trimmed !== NIL_UUID2 && ver !== 7) {
2450
+ throw new Error(`Cannot parse "${str}" as Uuid7: wrong version (v${ver})`);
2451
+ }
2452
+ return new _Uuid7Value(trimmed);
2453
+ }
2454
+ /**
2455
+ * Get the UUID string
2456
+ */
2457
+ asString() {
2458
+ return this.uuid;
2459
+ }
2460
+ /**
2461
+ * Get the UUID as bytes (16-byte array)
2462
+ */
2463
+ asBytes() {
2464
+ if (this.uuid === void 0) return void 0;
2465
+ const hex = this.uuid.replace(/-/g, "");
2466
+ const bytes = new Uint8Array(16);
2467
+ for (let i = 0; i < 16; i++) {
2468
+ bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
2469
+ }
2470
+ return bytes;
2471
+ }
2472
+ /**
2473
+ * Extract the timestamp from UUID v7 (milliseconds since Unix epoch)
2474
+ */
2475
+ getTimestamp() {
2476
+ if (this.uuid === void 0 || this.uuid === NIL_UUID2) return void 0;
2477
+ const hex = this.uuid.replace(/-/g, "");
2478
+ const timestampHex = hex.substring(0, 12);
2479
+ const timestamp = parseInt(timestampHex, 16);
2480
+ return timestamp;
2481
+ }
2482
+ /**
2483
+ * Check if this is the nil UUID
2484
+ */
2485
+ isNil() {
2486
+ return this.uuid === NIL_UUID2;
2487
+ }
2488
+ /**
2489
+ * Get the UUID version
2490
+ */
2491
+ getVersion() {
2492
+ if (this.uuid === void 0) return void 0;
2493
+ return version2(this.uuid);
2494
+ }
2495
+ /**
2496
+ * Format as string
2497
+ */
2498
+ toString() {
2499
+ if (this.uuid === void 0) {
2500
+ return "undefined";
2501
+ }
2502
+ return this.uuid;
2503
+ }
2504
+ valueOf() {
2505
+ return this.uuid;
2506
+ }
2507
+ /**
2508
+ * Get the internal representation
2509
+ */
2510
+ get value() {
2511
+ return this.valueOf();
2512
+ }
2513
+ /**
2514
+ * Compare two UUID7 values for equality
2515
+ */
2516
+ equals(other) {
2517
+ if (other.type !== this.type) {
2518
+ return false;
2519
+ }
2520
+ const otherUuid = other;
2521
+ return this.uuid === otherUuid.uuid;
2522
+ }
2523
+ /**
2524
+ * Compare two UUID7 values (for ordering)
2525
+ * UUID v7 has timestamp-based ordering for UUIDs generated close in time
2526
+ */
2527
+ compare(other) {
2528
+ if (this.uuid === void 0 || other.uuid === void 0) {
2529
+ if (this.uuid === other.uuid) return 0;
2530
+ if (this.uuid === void 0) return -1;
2531
+ return 1;
2532
+ }
2533
+ const thisBytes = this.asBytes();
2534
+ const otherBytes = other.asBytes();
2535
+ for (let i = 0; i < 16; i++) {
2536
+ if (thisBytes[i] < otherBytes[i]) return -1;
2537
+ if (thisBytes[i] > otherBytes[i]) return 1;
2538
+ }
2539
+ return 0;
2540
+ }
2541
+ encode() {
2542
+ return {
2543
+ type: this.type,
2544
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2545
+ };
2546
+ }
2547
+ };
2548
+
2549
+ // src/value/identityid.ts
2550
+ import { v7 as uuidv72, NIL as NIL_UUID3, validate as validate3, version as version3 } from "uuid";
2551
+ var IdentityIdValue = class _IdentityIdValue {
2552
+ constructor(value) {
2553
+ this.type = "IdentityId";
2554
+ if (value !== void 0) {
2555
+ if (typeof value !== "string") {
2556
+ throw new Error(`IdentityId value must be a string, got ${typeof value}`);
2557
+ }
2558
+ if (!validate3(value)) {
2559
+ throw new Error(`Invalid UUID format for IdentityId: ${value}`);
2560
+ }
2561
+ const ver = version3(value);
2562
+ if (value !== NIL_UUID3 && ver !== 7) {
2563
+ throw new Error(`Invalid UUID version for IdentityId: expected v7, got v${ver}`);
2564
+ }
2565
+ this.value = value.toLowerCase();
2566
+ } else {
2567
+ this.value = void 0;
2568
+ }
2569
+ }
2570
+ /**
2571
+ * Generate a new IdentityId with a UUID v7
2572
+ */
2573
+ static generate() {
2574
+ return new _IdentityIdValue(uuidv72());
2575
+ }
2576
+ /**
2577
+ * Get the nil IdentityId (all zeros)
2578
+ */
2579
+ static nil() {
2580
+ return new _IdentityIdValue(NIL_UUID3);
2581
+ }
2582
+ /**
2583
+ * Parse a string as an IdentityId
2584
+ */
2585
+ static parse(str) {
2586
+ const trimmed = str.trim();
2587
+ if (trimmed === "" || trimmed === UNDEFINED_VALUE) {
2588
+ return new _IdentityIdValue(void 0);
2589
+ }
2590
+ if (!validate3(trimmed)) {
2591
+ throw new Error(`Cannot parse "${str}" as IdentityId`);
2592
+ }
2593
+ const ver = version3(trimmed);
2594
+ if (trimmed !== NIL_UUID3 && ver !== 7) {
2595
+ throw new Error(`Cannot parse "${str}" as IdentityId: wrong UUID version (v${ver})`);
2596
+ }
2597
+ return new _IdentityIdValue(trimmed);
2598
+ }
2599
+ /**
2600
+ * Get the UUID string value
2601
+ */
2602
+ valueOf() {
2603
+ return this.value;
2604
+ }
2605
+ /**
2606
+ * Format as string
2607
+ */
2608
+ toString() {
2609
+ return this.value === void 0 ? "undefined" : this.value;
2610
+ }
2611
+ /**
2612
+ * Extract the timestamp from the UUID v7 (milliseconds since Unix epoch)
2613
+ */
2614
+ getTimestamp() {
2615
+ if (this.value === void 0 || this.value === NIL_UUID3) return void 0;
2616
+ const hex = this.value.replace(/-/g, "");
2617
+ const timestampHex = hex.substring(0, 12);
2618
+ const timestamp = parseInt(timestampHex, 16);
2619
+ return timestamp;
2620
+ }
2621
+ /**
2622
+ * Check if this is the nil UUID
2623
+ */
2624
+ isNil() {
2625
+ return this.value === NIL_UUID3;
2626
+ }
2627
+ /**
2628
+ * Compare two IdentityId values for equality
2629
+ */
2630
+ equals(other) {
2631
+ if (other.type !== this.type) {
2632
+ return false;
2633
+ }
2634
+ const otherIdentityId = other;
2635
+ return this.value === otherIdentityId.value;
2636
+ }
2637
+ encode() {
2638
+ return {
2639
+ type: this.type,
2640
+ value: this.value === void 0 ? UNDEFINED_VALUE : this.toString()
2641
+ };
2642
+ }
2643
+ };
2644
+
2645
+ // src/value/index.ts
2646
+ var Value = class {
2647
+ };
2648
+
2649
+ // src/decoder.ts
2650
+ function decode(pair) {
2651
+ switch (pair.type) {
2652
+ case "Blob":
2653
+ return BlobValue.parse(pair.value);
2654
+ case "Bool":
2655
+ return BoolValue.parse(pair.value);
2656
+ case "Date":
2657
+ return DateValue.parse(pair.value);
2658
+ case "DateTime":
2659
+ return DateTimeValue.parse(pair.value);
2660
+ case "Float4":
2661
+ return Float4Value.parse(pair.value);
2662
+ case "Float8":
2663
+ return Float8Value.parse(pair.value);
2664
+ case "Int1":
2665
+ return Int1Value.parse(pair.value);
2666
+ case "Int2":
2667
+ return Int2Value.parse(pair.value);
2668
+ case "Int4":
2669
+ return Int4Value.parse(pair.value);
2670
+ case "Int8":
2671
+ return Int8Value.parse(pair.value);
2672
+ case "Int16":
2673
+ return Int16Value.parse(pair.value);
2674
+ case "Interval":
2675
+ return IntervalValue.parse(pair.value);
2676
+ case "RowNumber":
2677
+ return RowNumberValue.parse(pair.value);
2678
+ case "Time":
2679
+ return TimeValue.parse(pair.value);
2680
+ case "Uint1":
2681
+ return Uint1Value.parse(pair.value);
2682
+ case "Uint2":
2683
+ return Uint2Value.parse(pair.value);
2684
+ case "Uint4":
2685
+ return Uint4Value.parse(pair.value);
2686
+ case "Uint8":
2687
+ return Uint8Value.parse(pair.value);
2688
+ case "Uint16":
2689
+ return Uint16Value.parse(pair.value);
2690
+ case "Undefined":
2691
+ return UndefinedValue.parse(pair.value);
2692
+ case "Utf8":
2693
+ return Utf8Value.parse(pair.value);
2694
+ case "Uuid4":
2695
+ return Uuid4Value.parse(pair.value);
2696
+ case "Uuid7":
2697
+ return Uuid7Value.parse(pair.value);
2698
+ case "IdentityId":
2699
+ return IdentityIdValue.parse(pair.value);
2700
+ default:
2701
+ throw new Error(`Unsupported type: ${pair.type}`);
2702
+ }
2703
+ }
2704
+
2705
+ // src/schema/builder.ts
2706
+ var SchemaBuilder = class {
2707
+ static blob() {
2708
+ return { kind: "primitive", type: "Blob" };
2709
+ }
2710
+ static bool() {
2711
+ return { kind: "primitive", type: "Bool" };
2712
+ }
2713
+ static boolean() {
2714
+ return { kind: "primitive", type: "Bool" };
2715
+ }
2716
+ static float4() {
2717
+ return { kind: "primitive", type: "Float4" };
2718
+ }
2719
+ static float8() {
2720
+ return { kind: "primitive", type: "Float8" };
2721
+ }
2722
+ static float() {
2723
+ return { kind: "primitive", type: "Float8" };
2724
+ }
2725
+ static double() {
2726
+ return { kind: "primitive", type: "Float8" };
2727
+ }
2728
+ static int1() {
2729
+ return { kind: "primitive", type: "Int1" };
2730
+ }
2731
+ static int2() {
2732
+ return { kind: "primitive", type: "Int2" };
2733
+ }
2734
+ static int4() {
2735
+ return { kind: "primitive", type: "Int4" };
2736
+ }
2737
+ static int8() {
2738
+ return { kind: "primitive", type: "Int8" };
2739
+ }
2740
+ static int16() {
2741
+ return { kind: "primitive", type: "Int16" };
2742
+ }
2743
+ static int() {
2744
+ return { kind: "primitive", type: "Int4" };
2745
+ }
2746
+ static bigint() {
2747
+ return { kind: "primitive", type: "Int8" };
2748
+ }
2749
+ static uint1() {
2750
+ return { kind: "primitive", type: "Uint1" };
2751
+ }
2752
+ static uint2() {
2753
+ return { kind: "primitive", type: "Uint2" };
2754
+ }
2755
+ static uint4() {
2756
+ return { kind: "primitive", type: "Uint4" };
2757
+ }
2758
+ static uint8() {
2759
+ return { kind: "primitive", type: "Uint8" };
2760
+ }
2761
+ static uint16() {
2762
+ return { kind: "primitive", type: "Uint16" };
2763
+ }
2764
+ static utf8() {
2765
+ return { kind: "primitive", type: "Utf8" };
2766
+ }
2767
+ static string() {
2768
+ return { kind: "primitive", type: "Utf8" };
2769
+ }
2770
+ static date() {
2771
+ return { kind: "primitive", type: "Date" };
2772
+ }
2773
+ static datetime() {
2774
+ return { kind: "primitive", type: "DateTime" };
2775
+ }
2776
+ static time() {
2777
+ return { kind: "primitive", type: "Time" };
2778
+ }
2779
+ static interval() {
2780
+ return { kind: "primitive", type: "Interval" };
2781
+ }
2782
+ static uuid4() {
2783
+ return { kind: "primitive", type: "Uuid4" };
2784
+ }
2785
+ static uuid7() {
2786
+ return { kind: "primitive", type: "Uuid7" };
2787
+ }
2788
+ static uuid() {
2789
+ return { kind: "primitive", type: "Uuid7" };
2790
+ }
2791
+ static undefined() {
2792
+ return { kind: "primitive", type: "Undefined" };
2793
+ }
2794
+ static rownumber() {
2795
+ return { kind: "primitive", type: "RowNumber" };
2796
+ }
2797
+ static identityid() {
2798
+ return { kind: "primitive", type: "IdentityId" };
2799
+ }
2800
+ static object(properties) {
2801
+ return { kind: "object", properties };
2802
+ }
2803
+ static array(items) {
2804
+ return { kind: "array", items };
2805
+ }
2806
+ static optional(schema) {
2807
+ return { kind: "optional", schema };
2808
+ }
2809
+ static number() {
2810
+ return { kind: "primitive", type: "Float8" };
2811
+ }
2812
+ static boolValue() {
2813
+ return { kind: "value", type: "Bool" };
2814
+ }
2815
+ static int1Value() {
2816
+ return { kind: "value", type: "Int1" };
2817
+ }
2818
+ static int2Value() {
2819
+ return { kind: "value", type: "Int2" };
2820
+ }
2821
+ static int4Value() {
2822
+ return { kind: "value", type: "Int4" };
2823
+ }
2824
+ static int8Value() {
2825
+ return { kind: "value", type: "Int8" };
2826
+ }
2827
+ static int16Value() {
2828
+ return { kind: "value", type: "Int16" };
2829
+ }
2830
+ static uint1Value() {
2831
+ return { kind: "value", type: "Uint1" };
2832
+ }
2833
+ static uint2Value() {
2834
+ return { kind: "value", type: "Uint2" };
2835
+ }
2836
+ static uint4Value() {
2837
+ return { kind: "value", type: "Uint4" };
2838
+ }
2839
+ static uint8Value() {
2840
+ return { kind: "value", type: "Uint8" };
2841
+ }
2842
+ static uint16Value() {
2843
+ return { kind: "value", type: "Uint16" };
2844
+ }
2845
+ static float4Value() {
2846
+ return { kind: "value", type: "Float4" };
2847
+ }
2848
+ static float8Value() {
2849
+ return { kind: "value", type: "Float8" };
2850
+ }
2851
+ static utf8Value() {
2852
+ return { kind: "value", type: "Utf8" };
2853
+ }
2854
+ static dateValue() {
2855
+ return { kind: "value", type: "Date" };
2856
+ }
2857
+ static dateTimeValue() {
2858
+ return { kind: "value", type: "DateTime" };
2859
+ }
2860
+ static timeValue() {
2861
+ return { kind: "value", type: "Time" };
2862
+ }
2863
+ static intervalValue() {
2864
+ return { kind: "value", type: "Interval" };
2865
+ }
2866
+ static uuid4Value() {
2867
+ return { kind: "value", type: "Uuid4" };
2868
+ }
2869
+ static uuid7Value() {
2870
+ return { kind: "value", type: "Uuid7" };
2871
+ }
2872
+ static undefinedValue() {
2873
+ return { kind: "value", type: "Undefined" };
2874
+ }
2875
+ static blobValue() {
2876
+ return { kind: "value", type: "Blob" };
2877
+ }
2878
+ static rowIdValue() {
2879
+ return { kind: "value", type: "RowNumber" };
2880
+ }
2881
+ static identityIdValue() {
2882
+ return { kind: "value", type: "IdentityId" };
2883
+ }
2884
+ };
2885
+ var Schema = SchemaBuilder;
2886
+
2887
+ // src/schema/parser.ts
2888
+ function createValueInstance(type, value) {
2889
+ switch (type) {
2890
+ case "Blob":
2891
+ return new BlobValue(value);
2892
+ case "Bool":
2893
+ return new BoolValue(value);
2894
+ case "Float4":
2895
+ return new Float4Value(value);
2896
+ case "Float8":
2897
+ return new Float8Value(value);
2898
+ case "Int1":
2899
+ return new Int1Value(value);
2900
+ case "Int2":
2901
+ return new Int2Value(value);
2902
+ case "Int4":
2903
+ return new Int4Value(value);
2904
+ case "Int8":
2905
+ return new Int8Value(value);
2906
+ case "Int16":
2907
+ return new Int16Value(value);
2908
+ case "Uint1":
2909
+ return new Uint1Value(value);
2910
+ case "Uint2":
2911
+ return new Uint2Value(value);
2912
+ case "Uint4":
2913
+ return new Uint4Value(value);
2914
+ case "Uint8":
2915
+ return new Uint8Value(value);
2916
+ case "Uint16":
2917
+ return new Uint16Value(value);
2918
+ case "Utf8":
2919
+ return new Utf8Value(value);
2920
+ case "Date":
2921
+ return new DateValue(value);
2922
+ case "DateTime":
2923
+ return new DateTimeValue(value);
2924
+ case "Time":
2925
+ return new TimeValue(value);
2926
+ case "Interval":
2927
+ return new IntervalValue(value);
2928
+ case "Uuid4":
2929
+ return new Uuid4Value(value);
2930
+ case "Uuid7":
2931
+ return new Uuid7Value(value);
2932
+ case "Undefined":
2933
+ return new UndefinedValue();
2934
+ case "RowNumber":
2935
+ return new RowNumberValue(value);
2936
+ default:
2937
+ throw new Error(`Unknown type: ${type}`);
2938
+ }
2939
+ }
2940
+ function parseValue(schema, value) {
2941
+ if (schema.kind === "primitive") {
2942
+ if (value === null || value === void 0) {
2943
+ return void 0;
2944
+ }
2945
+ return createValueInstance(schema.type, value);
2946
+ }
2947
+ if (schema.kind === "object") {
2948
+ if (value === null || value === void 0) {
2949
+ return void 0;
2950
+ }
2951
+ const result = {};
2952
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
2953
+ result[key] = parseValue(propSchema, value[key]);
2954
+ }
2955
+ return result;
2956
+ }
2957
+ if (schema.kind === "array") {
2958
+ if (!Array.isArray(value)) {
2959
+ return [];
2960
+ }
2961
+ return value.map((item) => parseValue(schema.items, item));
2962
+ }
2963
+ if (schema.kind === "optional") {
2964
+ if (value === void 0) {
2965
+ return void 0;
2966
+ }
2967
+ return parseValue(schema.schema, value);
2968
+ }
2969
+ throw new Error(`Unknown schema kind: ${schema.kind}`);
2970
+ }
2971
+
2972
+ // src/schema/validator.ts
2973
+ function validateSchema(schema, value) {
2974
+ if (schema.kind === "primitive") {
2975
+ const schemaType = schema.type;
2976
+ if (value === null || value === void 0) {
2977
+ return schemaType === "Undefined";
2978
+ }
2979
+ switch (schemaType) {
2980
+ case "Bool":
2981
+ return typeof value === "boolean";
2982
+ case "Float4":
2983
+ case "Float8":
2984
+ case "Int1":
2985
+ case "Int2":
2986
+ case "Int4":
2987
+ return typeof value === "number";
2988
+ case "Int8":
2989
+ case "Int16":
2990
+ case "Uint8":
2991
+ case "Uint16":
2992
+ return typeof value === "bigint" || typeof value === "number";
2993
+ case "Uint1":
2994
+ case "Uint2":
2995
+ case "Uint4":
2996
+ return typeof value === "number" && value >= 0;
2997
+ case "Utf8":
2998
+ case "Time":
2999
+ case "Interval":
3000
+ case "Uuid4":
3001
+ case "Uuid7":
3002
+ case "RowNumber":
3003
+ return typeof value === "string";
3004
+ case "Date":
3005
+ case "DateTime":
3006
+ return value instanceof Date || typeof value === "string";
3007
+ case "Blob":
3008
+ return value instanceof Uint8Array || value instanceof ArrayBuffer;
3009
+ case "Undefined":
3010
+ return value === void 0;
3011
+ default:
3012
+ return false;
3013
+ }
3014
+ }
3015
+ if (schema.kind === "object") {
3016
+ if (typeof value !== "object" || value === null) {
3017
+ return false;
3018
+ }
3019
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
3020
+ if (!validateSchema(propSchema, value[key])) {
3021
+ return false;
3022
+ }
3023
+ }
3024
+ return true;
3025
+ }
3026
+ if (schema.kind === "array") {
3027
+ if (!Array.isArray(value)) {
3028
+ return false;
3029
+ }
3030
+ return value.every((item) => validateSchema(schema.items, item));
3031
+ }
3032
+ if (schema.kind === "optional") {
3033
+ if (value === void 0) {
3034
+ return true;
3035
+ }
3036
+ return validateSchema(schema.schema, value);
3037
+ }
3038
+ return false;
3039
+ }
3040
+
3041
+ // src/types.ts
3042
+ var ReifyError = class extends Error {
3043
+ constructor(response) {
3044
+ const diagnostic = response.payload.diagnostic;
3045
+ const message = `[${diagnostic.code}] ${diagnostic.message}` + (diagnostic.label ? ` \u2014 ${diagnostic.label}` : "");
3046
+ super(message);
3047
+ this.name = "ReifyError";
3048
+ this.code = diagnostic.code;
3049
+ this.statement = diagnostic.statement;
3050
+ this.column = diagnostic.column;
3051
+ this.span = diagnostic.span;
3052
+ this.label = diagnostic.label;
3053
+ this.help = diagnostic.help;
3054
+ this.notes = diagnostic.notes ?? [];
3055
+ this.cause = diagnostic.cause;
3056
+ Object.setPrototypeOf(this, new.target.prototype);
3057
+ }
3058
+ toString() {
3059
+ const position = this.span ? `line ${this.span.line}, offset ${this.span.offset}` : "unknown position";
3060
+ const notes = this.notes.length ? `
3061
+ Notes:
3062
+ - ${this.notes.join("\n- ")}` : "";
3063
+ const help = this.help ? `
3064
+ Help: ${this.help}` : "";
3065
+ return `${this.name}: ${this.message}
3066
+ At ${position}${help}${notes}`;
3067
+ }
3068
+ };
3069
+ function asFrameResults(results) {
3070
+ return results;
3071
+ }
3072
+ export {
3073
+ BlobValue,
3074
+ BoolValue,
3075
+ DateTimeValue,
3076
+ DateValue,
3077
+ Float4Value,
3078
+ Float8Value,
3079
+ IdentityIdValue,
3080
+ Int16Value,
3081
+ Int1Value,
3082
+ Int2Value,
3083
+ Int4Value,
3084
+ Int8Value,
3085
+ IntervalValue,
3086
+ ReifyError,
3087
+ RowNumberValue,
3088
+ Schema,
3089
+ SchemaBuilder,
3090
+ TimeValue,
3091
+ UNDEFINED_VALUE,
3092
+ Uint16Value,
3093
+ Uint1Value,
3094
+ Uint2Value,
3095
+ Uint4Value,
3096
+ Uint8Value,
3097
+ UndefinedValue,
3098
+ Utf8Value,
3099
+ Uuid4Value,
3100
+ Uuid7Value,
3101
+ Value,
3102
+ asFrameResults,
3103
+ decode,
3104
+ parseValue,
3105
+ validateSchema
3106
+ };
3107
+ //# sourceMappingURL=index.js.map