@topgunbuild/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -403,29 +403,59 @@ declare function hashORMapRecord<V>(record: ORMapRecord<V>): number;
403
403
  declare function compareTimestamps(a: Timestamp, b: Timestamp): number;
404
404
 
405
405
  /**
406
- * FNV-1a Hash implementation for strings.
407
- * Fast, non-cryptographic, synchronous.
408
- * Good enough for data synchronization checks.
406
+ * Hash utilities for TopGun
407
+ *
408
+ * Uses native xxHash64 when available (via @topgunbuild/native),
409
+ * falls back to FNV-1a for JS-only environments.
410
+ *
411
+ * Phase 3.05: Native Hash Integration
412
+ */
413
+ /**
414
+ * Hash a string to a 32-bit unsigned integer.
415
+ *
416
+ * Uses native xxHash64 (truncated to 32 bits) when available,
417
+ * otherwise falls back to FNV-1a.
418
+ *
419
+ * @param str - String to hash
420
+ * @returns 32-bit unsigned integer hash
409
421
  */
410
422
  declare function hashString(str: string): number;
411
423
  /**
412
424
  * Combines multiple hash numbers into one order-independent hash.
413
- * Used for combining bucket hashes.
414
- * XOR is simple and effective for order-independent combination,
415
- * but for Merkle trees we usually want position dependence if it's a Trie,
416
- * or order-independence if it's a Set.
417
- * Here we simply sum or XOR.
425
+ * Used for combining bucket hashes in Merkle trees.
426
+ *
427
+ * Uses simple sum (with overflow handling) for order-independence.
428
+ *
429
+ * @param hashes - Array of hash values to combine
430
+ * @returns Combined hash as 32-bit unsigned integer
418
431
  */
419
432
  declare function combineHashes(hashes: number[]): number;
433
+ /**
434
+ * Check if native hash module is being used.
435
+ * Useful for diagnostics and testing.
436
+ */
437
+ declare function isUsingNativeHash(): boolean;
438
+ /**
439
+ * Force use of FNV-1a hash (for testing/compatibility).
440
+ * After calling this, hashString will always use FNV-1a.
441
+ */
442
+ declare function disableNativeHash(): void;
443
+ /**
444
+ * Re-enable native hash loading (for testing).
445
+ * Resets the load state so native module can be loaded again.
446
+ */
447
+ declare function resetNativeHash(): void;
420
448
 
421
449
  /**
422
450
  * Serializes a JavaScript object to MessagePack binary format.
451
+ * Uses msgpackr for 2-5x faster serialization compared to @msgpack/msgpack.
423
452
  * @param data The data to serialize.
424
453
  * @returns A Uint8Array containing the serialized data.
425
454
  */
426
455
  declare function serialize(data: unknown): Uint8Array;
427
456
  /**
428
457
  * Deserializes MessagePack binary data to a JavaScript object.
458
+ * Uses msgpackr for 2-5x faster deserialization compared to @msgpack/msgpack.
429
459
  * @param data The binary data to deserialize (Uint8Array or ArrayBuffer).
430
460
  * @returns The deserialized object.
431
461
  */
@@ -467,16 +497,27 @@ interface Principal {
467
497
  [key: string]: any;
468
498
  }
469
499
 
500
+ /**
501
+ * Write Concern schema - defines when an operation is considered acknowledged.
502
+ */
503
+ declare const WriteConcernSchema: z.ZodEnum<{
504
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
505
+ MEMORY: "MEMORY";
506
+ APPLIED: "APPLIED";
507
+ REPLICATED: "REPLICATED";
508
+ PERSISTED: "PERSISTED";
509
+ }>;
510
+ type WriteConcernValue = z.infer<typeof WriteConcernSchema>;
470
511
  declare const TimestampSchema: z.ZodObject<{
471
- millis: z.ZodNumber;
472
- counter: z.ZodNumber;
512
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
513
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
473
514
  nodeId: z.ZodString;
474
515
  }, z.core.$strip>;
475
516
  declare const LWWRecordSchema: z.ZodObject<{
476
517
  value: z.ZodNullable<z.ZodAny>;
477
518
  timestamp: z.ZodObject<{
478
- millis: z.ZodNumber;
479
- counter: z.ZodNumber;
519
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
520
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
480
521
  nodeId: z.ZodString;
481
522
  }, z.core.$strip>;
482
523
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -484,8 +525,8 @@ declare const LWWRecordSchema: z.ZodObject<{
484
525
  declare const ORMapRecordSchema: z.ZodObject<{
485
526
  value: z.ZodAny;
486
527
  timestamp: z.ZodObject<{
487
- millis: z.ZodNumber;
488
- counter: z.ZodNumber;
528
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
529
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
489
530
  nodeId: z.ZodString;
490
531
  }, z.core.$strip>;
491
532
  tag: z.ZodString;
@@ -523,8 +564,8 @@ declare const ClientOpSchema: z.ZodObject<{
523
564
  record: z.ZodOptional<z.ZodNullable<z.ZodObject<{
524
565
  value: z.ZodNullable<z.ZodAny>;
525
566
  timestamp: z.ZodObject<{
526
- millis: z.ZodNumber;
527
- counter: z.ZodNumber;
567
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
568
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
528
569
  nodeId: z.ZodString;
529
570
  }, z.core.$strip>;
530
571
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -532,14 +573,22 @@ declare const ClientOpSchema: z.ZodObject<{
532
573
  orRecord: z.ZodOptional<z.ZodNullable<z.ZodObject<{
533
574
  value: z.ZodAny;
534
575
  timestamp: z.ZodObject<{
535
- millis: z.ZodNumber;
536
- counter: z.ZodNumber;
576
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
577
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
537
578
  nodeId: z.ZodString;
538
579
  }, z.core.$strip>;
539
580
  tag: z.ZodString;
540
581
  ttlMs: z.ZodOptional<z.ZodNumber>;
541
582
  }, z.core.$strip>>>;
542
583
  orTag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
584
+ writeConcern: z.ZodOptional<z.ZodEnum<{
585
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
586
+ MEMORY: "MEMORY";
587
+ APPLIED: "APPLIED";
588
+ REPLICATED: "REPLICATED";
589
+ PERSISTED: "PERSISTED";
590
+ }>>;
591
+ timeout: z.ZodOptional<z.ZodNumber>;
543
592
  }, z.core.$strip>;
544
593
  declare const AuthMessageSchema: z.ZodObject<{
545
594
  type: z.ZodLiteral<"AUTH">;
@@ -578,8 +627,8 @@ declare const ClientOpMessageSchema: z.ZodObject<{
578
627
  record: z.ZodOptional<z.ZodNullable<z.ZodObject<{
579
628
  value: z.ZodNullable<z.ZodAny>;
580
629
  timestamp: z.ZodObject<{
581
- millis: z.ZodNumber;
582
- counter: z.ZodNumber;
630
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
631
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
583
632
  nodeId: z.ZodString;
584
633
  }, z.core.$strip>;
585
634
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -587,14 +636,22 @@ declare const ClientOpMessageSchema: z.ZodObject<{
587
636
  orRecord: z.ZodOptional<z.ZodNullable<z.ZodObject<{
588
637
  value: z.ZodAny;
589
638
  timestamp: z.ZodObject<{
590
- millis: z.ZodNumber;
591
- counter: z.ZodNumber;
639
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
640
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
592
641
  nodeId: z.ZodString;
593
642
  }, z.core.$strip>;
594
643
  tag: z.ZodString;
595
644
  ttlMs: z.ZodOptional<z.ZodNumber>;
596
645
  }, z.core.$strip>>>;
597
646
  orTag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
647
+ writeConcern: z.ZodOptional<z.ZodEnum<{
648
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
649
+ MEMORY: "MEMORY";
650
+ APPLIED: "APPLIED";
651
+ REPLICATED: "REPLICATED";
652
+ PERSISTED: "PERSISTED";
653
+ }>>;
654
+ timeout: z.ZodOptional<z.ZodNumber>;
598
655
  }, z.core.$strip>;
599
656
  }, z.core.$strip>;
600
657
  declare const OpBatchMessageSchema: z.ZodObject<{
@@ -608,8 +665,8 @@ declare const OpBatchMessageSchema: z.ZodObject<{
608
665
  record: z.ZodOptional<z.ZodNullable<z.ZodObject<{
609
666
  value: z.ZodNullable<z.ZodAny>;
610
667
  timestamp: z.ZodObject<{
611
- millis: z.ZodNumber;
612
- counter: z.ZodNumber;
668
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
669
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
613
670
  nodeId: z.ZodString;
614
671
  }, z.core.$strip>;
615
672
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -617,15 +674,31 @@ declare const OpBatchMessageSchema: z.ZodObject<{
617
674
  orRecord: z.ZodOptional<z.ZodNullable<z.ZodObject<{
618
675
  value: z.ZodAny;
619
676
  timestamp: z.ZodObject<{
620
- millis: z.ZodNumber;
621
- counter: z.ZodNumber;
677
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
678
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
622
679
  nodeId: z.ZodString;
623
680
  }, z.core.$strip>;
624
681
  tag: z.ZodString;
625
682
  ttlMs: z.ZodOptional<z.ZodNumber>;
626
683
  }, z.core.$strip>>>;
627
684
  orTag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
685
+ writeConcern: z.ZodOptional<z.ZodEnum<{
686
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
687
+ MEMORY: "MEMORY";
688
+ APPLIED: "APPLIED";
689
+ REPLICATED: "REPLICATED";
690
+ PERSISTED: "PERSISTED";
691
+ }>>;
692
+ timeout: z.ZodOptional<z.ZodNumber>;
628
693
  }, z.core.$strip>>;
694
+ writeConcern: z.ZodOptional<z.ZodEnum<{
695
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
696
+ MEMORY: "MEMORY";
697
+ APPLIED: "APPLIED";
698
+ REPLICATED: "REPLICATED";
699
+ PERSISTED: "PERSISTED";
700
+ }>>;
701
+ timeout: z.ZodOptional<z.ZodNumber>;
629
702
  }, z.core.$strip>;
630
703
  }, z.core.$strip>;
631
704
  declare const SyncInitMessageSchema: z.ZodObject<{
@@ -639,8 +712,8 @@ declare const SyncRespRootMessageSchema: z.ZodObject<{
639
712
  mapName: z.ZodString;
640
713
  rootHash: z.ZodNumber;
641
714
  timestamp: z.ZodObject<{
642
- millis: z.ZodNumber;
643
- counter: z.ZodNumber;
715
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
716
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
644
717
  nodeId: z.ZodString;
645
718
  }, z.core.$strip>;
646
719
  }, z.core.$strip>;
@@ -663,8 +736,8 @@ declare const SyncRespLeafMessageSchema: z.ZodObject<{
663
736
  record: z.ZodObject<{
664
737
  value: z.ZodNullable<z.ZodAny>;
665
738
  timestamp: z.ZodObject<{
666
- millis: z.ZodNumber;
667
- counter: z.ZodNumber;
739
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
740
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
668
741
  nodeId: z.ZodString;
669
742
  }, z.core.$strip>;
670
743
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -732,6 +805,16 @@ declare const PongMessageSchema: z.ZodObject<{
732
805
  timestamp: z.ZodNumber;
733
806
  serverTime: z.ZodNumber;
734
807
  }, z.core.$strip>;
808
+ /**
809
+ * BATCH: Server sends multiple messages batched together.
810
+ * Uses length-prefixed binary format for efficiency.
811
+ * Format: [4 bytes: count][4 bytes: len1][msg1][4 bytes: len2][msg2]...
812
+ */
813
+ declare const BatchMessageSchema: z.ZodObject<{
814
+ type: z.ZodLiteral<"BATCH">;
815
+ count: z.ZodNumber;
816
+ data: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
817
+ }, z.core.$strip>;
735
818
  /**
736
819
  * ORMAP_SYNC_INIT: Client initiates ORMap sync
737
820
  * Sends root hash and bucket hashes to server
@@ -752,8 +835,8 @@ declare const ORMapSyncRespRootSchema: z.ZodObject<{
752
835
  mapName: z.ZodString;
753
836
  rootHash: z.ZodNumber;
754
837
  timestamp: z.ZodObject<{
755
- millis: z.ZodNumber;
756
- counter: z.ZodNumber;
838
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
839
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
757
840
  nodeId: z.ZodString;
758
841
  }, z.core.$strip>;
759
842
  }, z.core.$strip>;
@@ -792,8 +875,8 @@ declare const ORMapSyncRespLeafSchema: z.ZodObject<{
792
875
  records: z.ZodArray<z.ZodObject<{
793
876
  value: z.ZodAny;
794
877
  timestamp: z.ZodObject<{
795
- millis: z.ZodNumber;
796
- counter: z.ZodNumber;
878
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
879
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
797
880
  nodeId: z.ZodString;
798
881
  }, z.core.$strip>;
799
882
  tag: z.ZodString;
@@ -825,8 +908,8 @@ declare const ORMapDiffResponseSchema: z.ZodObject<{
825
908
  records: z.ZodArray<z.ZodObject<{
826
909
  value: z.ZodAny;
827
910
  timestamp: z.ZodObject<{
828
- millis: z.ZodNumber;
829
- counter: z.ZodNumber;
911
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
912
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
830
913
  nodeId: z.ZodString;
831
914
  }, z.core.$strip>;
832
915
  tag: z.ZodString;
@@ -848,8 +931,8 @@ declare const ORMapPushDiffSchema: z.ZodObject<{
848
931
  records: z.ZodArray<z.ZodObject<{
849
932
  value: z.ZodAny;
850
933
  timestamp: z.ZodObject<{
851
- millis: z.ZodNumber;
852
- counter: z.ZodNumber;
934
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
935
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
853
936
  nodeId: z.ZodString;
854
937
  }, z.core.$strip>;
855
938
  tag: z.ZodString;
@@ -859,6 +942,70 @@ declare const ORMapPushDiffSchema: z.ZodObject<{
859
942
  }, z.core.$strip>>;
860
943
  }, z.core.$strip>;
861
944
  }, z.core.$strip>;
945
+ /**
946
+ * PARTITION_MAP_REQUEST: Client requests current partition map
947
+ */
948
+ declare const PartitionMapRequestSchema: z.ZodObject<{
949
+ type: z.ZodLiteral<"PARTITION_MAP_REQUEST">;
950
+ payload: z.ZodOptional<z.ZodObject<{
951
+ currentVersion: z.ZodOptional<z.ZodNumber>;
952
+ }, z.core.$strip>>;
953
+ }, z.core.$strip>;
954
+ /**
955
+ * Individual operation result within a batch ACK
956
+ */
957
+ declare const OpResultSchema: z.ZodObject<{
958
+ opId: z.ZodString;
959
+ success: z.ZodBoolean;
960
+ achievedLevel: z.ZodEnum<{
961
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
962
+ MEMORY: "MEMORY";
963
+ APPLIED: "APPLIED";
964
+ REPLICATED: "REPLICATED";
965
+ PERSISTED: "PERSISTED";
966
+ }>;
967
+ error: z.ZodOptional<z.ZodString>;
968
+ }, z.core.$strip>;
969
+ /**
970
+ * OP_ACK: Server acknowledges write operations
971
+ * Extended to support Write Concern levels
972
+ */
973
+ declare const OpAckMessageSchema: z.ZodObject<{
974
+ type: z.ZodLiteral<"OP_ACK">;
975
+ payload: z.ZodObject<{
976
+ lastId: z.ZodString;
977
+ achievedLevel: z.ZodOptional<z.ZodEnum<{
978
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
979
+ MEMORY: "MEMORY";
980
+ APPLIED: "APPLIED";
981
+ REPLICATED: "REPLICATED";
982
+ PERSISTED: "PERSISTED";
983
+ }>>;
984
+ results: z.ZodOptional<z.ZodArray<z.ZodObject<{
985
+ opId: z.ZodString;
986
+ success: z.ZodBoolean;
987
+ achievedLevel: z.ZodEnum<{
988
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
989
+ MEMORY: "MEMORY";
990
+ APPLIED: "APPLIED";
991
+ REPLICATED: "REPLICATED";
992
+ PERSISTED: "PERSISTED";
993
+ }>;
994
+ error: z.ZodOptional<z.ZodString>;
995
+ }, z.core.$strip>>>;
996
+ }, z.core.$strip>;
997
+ }, z.core.$strip>;
998
+ /**
999
+ * OP_REJECTED: Server rejects a write operation
1000
+ */
1001
+ declare const OpRejectedMessageSchema: z.ZodObject<{
1002
+ type: z.ZodLiteral<"OP_REJECTED">;
1003
+ payload: z.ZodObject<{
1004
+ opId: z.ZodString;
1005
+ reason: z.ZodString;
1006
+ code: z.ZodOptional<z.ZodNumber>;
1007
+ }, z.core.$strip>;
1008
+ }, z.core.$strip>;
862
1009
  declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
863
1010
  type: z.ZodLiteral<"AUTH">;
864
1011
  token: z.ZodString;
@@ -893,8 +1040,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
893
1040
  record: z.ZodOptional<z.ZodNullable<z.ZodObject<{
894
1041
  value: z.ZodNullable<z.ZodAny>;
895
1042
  timestamp: z.ZodObject<{
896
- millis: z.ZodNumber;
897
- counter: z.ZodNumber;
1043
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1044
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
898
1045
  nodeId: z.ZodString;
899
1046
  }, z.core.$strip>;
900
1047
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -902,14 +1049,22 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
902
1049
  orRecord: z.ZodOptional<z.ZodNullable<z.ZodObject<{
903
1050
  value: z.ZodAny;
904
1051
  timestamp: z.ZodObject<{
905
- millis: z.ZodNumber;
906
- counter: z.ZodNumber;
1052
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1053
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
907
1054
  nodeId: z.ZodString;
908
1055
  }, z.core.$strip>;
909
1056
  tag: z.ZodString;
910
1057
  ttlMs: z.ZodOptional<z.ZodNumber>;
911
1058
  }, z.core.$strip>>>;
912
1059
  orTag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1060
+ writeConcern: z.ZodOptional<z.ZodEnum<{
1061
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
1062
+ MEMORY: "MEMORY";
1063
+ APPLIED: "APPLIED";
1064
+ REPLICATED: "REPLICATED";
1065
+ PERSISTED: "PERSISTED";
1066
+ }>>;
1067
+ timeout: z.ZodOptional<z.ZodNumber>;
913
1068
  }, z.core.$strip>;
914
1069
  }, z.core.$strip>, z.ZodObject<{
915
1070
  type: z.ZodLiteral<"OP_BATCH">;
@@ -922,8 +1077,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
922
1077
  record: z.ZodOptional<z.ZodNullable<z.ZodObject<{
923
1078
  value: z.ZodNullable<z.ZodAny>;
924
1079
  timestamp: z.ZodObject<{
925
- millis: z.ZodNumber;
926
- counter: z.ZodNumber;
1080
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1081
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
927
1082
  nodeId: z.ZodString;
928
1083
  }, z.core.$strip>;
929
1084
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -931,15 +1086,31 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
931
1086
  orRecord: z.ZodOptional<z.ZodNullable<z.ZodObject<{
932
1087
  value: z.ZodAny;
933
1088
  timestamp: z.ZodObject<{
934
- millis: z.ZodNumber;
935
- counter: z.ZodNumber;
1089
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1090
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
936
1091
  nodeId: z.ZodString;
937
1092
  }, z.core.$strip>;
938
1093
  tag: z.ZodString;
939
1094
  ttlMs: z.ZodOptional<z.ZodNumber>;
940
1095
  }, z.core.$strip>>>;
941
1096
  orTag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1097
+ writeConcern: z.ZodOptional<z.ZodEnum<{
1098
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
1099
+ MEMORY: "MEMORY";
1100
+ APPLIED: "APPLIED";
1101
+ REPLICATED: "REPLICATED";
1102
+ PERSISTED: "PERSISTED";
1103
+ }>>;
1104
+ timeout: z.ZodOptional<z.ZodNumber>;
942
1105
  }, z.core.$strip>>;
1106
+ writeConcern: z.ZodOptional<z.ZodEnum<{
1107
+ FIRE_AND_FORGET: "FIRE_AND_FORGET";
1108
+ MEMORY: "MEMORY";
1109
+ APPLIED: "APPLIED";
1110
+ REPLICATED: "REPLICATED";
1111
+ PERSISTED: "PERSISTED";
1112
+ }>>;
1113
+ timeout: z.ZodOptional<z.ZodNumber>;
943
1114
  }, z.core.$strip>;
944
1115
  }, z.core.$strip>, z.ZodObject<{
945
1116
  type: z.ZodLiteral<"SYNC_INIT">;
@@ -951,8 +1122,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
951
1122
  mapName: z.ZodString;
952
1123
  rootHash: z.ZodNumber;
953
1124
  timestamp: z.ZodObject<{
954
- millis: z.ZodNumber;
955
- counter: z.ZodNumber;
1125
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1126
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
956
1127
  nodeId: z.ZodString;
957
1128
  }, z.core.$strip>;
958
1129
  }, z.core.$strip>;
@@ -973,8 +1144,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
973
1144
  record: z.ZodObject<{
974
1145
  value: z.ZodNullable<z.ZodAny>;
975
1146
  timestamp: z.ZodObject<{
976
- millis: z.ZodNumber;
977
- counter: z.ZodNumber;
1147
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1148
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
978
1149
  nodeId: z.ZodString;
979
1150
  }, z.core.$strip>;
980
1151
  ttlMs: z.ZodOptional<z.ZodNumber>;
@@ -1036,8 +1207,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1036
1207
  mapName: z.ZodString;
1037
1208
  rootHash: z.ZodNumber;
1038
1209
  timestamp: z.ZodObject<{
1039
- millis: z.ZodNumber;
1040
- counter: z.ZodNumber;
1210
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1211
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1041
1212
  nodeId: z.ZodString;
1042
1213
  }, z.core.$strip>;
1043
1214
  }, z.core.$strip>;
@@ -1064,8 +1235,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1064
1235
  records: z.ZodArray<z.ZodObject<{
1065
1236
  value: z.ZodAny;
1066
1237
  timestamp: z.ZodObject<{
1067
- millis: z.ZodNumber;
1068
- counter: z.ZodNumber;
1238
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1239
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1069
1240
  nodeId: z.ZodString;
1070
1241
  }, z.core.$strip>;
1071
1242
  tag: z.ZodString;
@@ -1089,8 +1260,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1089
1260
  records: z.ZodArray<z.ZodObject<{
1090
1261
  value: z.ZodAny;
1091
1262
  timestamp: z.ZodObject<{
1092
- millis: z.ZodNumber;
1093
- counter: z.ZodNumber;
1263
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1264
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1094
1265
  nodeId: z.ZodString;
1095
1266
  }, z.core.$strip>;
1096
1267
  tag: z.ZodString;
@@ -1108,8 +1279,8 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1108
1279
  records: z.ZodArray<z.ZodObject<{
1109
1280
  value: z.ZodAny;
1110
1281
  timestamp: z.ZodObject<{
1111
- millis: z.ZodNumber;
1112
- counter: z.ZodNumber;
1282
+ millis: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1283
+ counter: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>, z.ZodTransform<number, number | bigint>>;
1113
1284
  nodeId: z.ZodString;
1114
1285
  }, z.core.$strip>;
1115
1286
  tag: z.ZodString;
@@ -1118,11 +1289,488 @@ declare const MessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1118
1289
  tombstones: z.ZodArray<z.ZodString>;
1119
1290
  }, z.core.$strip>>;
1120
1291
  }, z.core.$strip>;
1292
+ }, z.core.$strip>, z.ZodObject<{
1293
+ type: z.ZodLiteral<"PARTITION_MAP_REQUEST">;
1294
+ payload: z.ZodOptional<z.ZodObject<{
1295
+ currentVersion: z.ZodOptional<z.ZodNumber>;
1296
+ }, z.core.$strip>>;
1121
1297
  }, z.core.$strip>], "type">;
1122
1298
  type Query = z.infer<typeof QuerySchema>;
1123
1299
  type ClientOp = z.infer<typeof ClientOpSchema>;
1124
1300
  type Message = z.infer<typeof MessageSchema>;
1125
1301
  type PingMessage = z.infer<typeof PingMessageSchema>;
1126
1302
  type PongMessage = z.infer<typeof PongMessageSchema>;
1303
+ type BatchMessage = z.infer<typeof BatchMessageSchema>;
1304
+ type OpAckMessage = z.infer<typeof OpAckMessageSchema>;
1305
+ type OpRejectedMessage = z.infer<typeof OpRejectedMessageSchema>;
1306
+ type OpResult = z.infer<typeof OpResultSchema>;
1307
+
1308
+ /**
1309
+ * Write Concern - Configurable Acknowledgment Levels
1310
+ *
1311
+ * Write Concern defines when a write operation is considered successful.
1312
+ * Similar to MongoDB's writeConcern, Kafka's acks, and Cassandra's consistency levels.
1313
+ */
1314
+ /**
1315
+ * Write Concern levels - determines when an operation is acknowledged.
1316
+ *
1317
+ * Levels are ordered by durability guarantee (lowest to highest):
1318
+ * FIRE_AND_FORGET < MEMORY < APPLIED < REPLICATED < PERSISTED
1319
+ */
1320
+ declare enum WriteConcern {
1321
+ /**
1322
+ * FIRE_AND_FORGET (acks=0)
1323
+ * - ACK sent immediately after server receives the message
1324
+ * - Operation may be lost if server crashes before processing
1325
+ * - Maximum throughput, minimum latency
1326
+ * - Use case: metrics, logs, non-critical data
1327
+ */
1328
+ FIRE_AND_FORGET = "FIRE_AND_FORGET",
1329
+ /**
1330
+ * MEMORY (acks=1, default) - current Early ACK behavior
1331
+ * - ACK sent after validation and queuing for processing
1332
+ * - Operation is in memory but not yet applied to CRDT
1333
+ * - Use case: most operations, real-time updates
1334
+ */
1335
+ MEMORY = "MEMORY",
1336
+ /**
1337
+ * APPLIED
1338
+ * - ACK sent after operation is applied to CRDT in memory
1339
+ * - Data is readable on this node immediately after ACK
1340
+ * - Use case: operations requiring immediate consistency on the node
1341
+ */
1342
+ APPLIED = "APPLIED",
1343
+ /**
1344
+ * REPLICATED
1345
+ * - ACK sent after operation is broadcast to cluster (CLUSTER_EVENT sent)
1346
+ * - Data survives primary node failure
1347
+ * - Use case: important data requiring cluster durability
1348
+ */
1349
+ REPLICATED = "REPLICATED",
1350
+ /**
1351
+ * PERSISTED
1352
+ * - ACK sent after operation is written to storage on primary node
1353
+ * - Data survives node restart
1354
+ * - Use case: critical data (financial transactions, audit logs)
1355
+ */
1356
+ PERSISTED = "PERSISTED"
1357
+ }
1358
+ /**
1359
+ * Default timeout for Write Concern acknowledgments (ms)
1360
+ */
1361
+ declare const DEFAULT_WRITE_CONCERN_TIMEOUT = 5000;
1362
+ /**
1363
+ * Write options for PUT/REMOVE operations
1364
+ */
1365
+ interface WriteOptions$1 {
1366
+ /**
1367
+ * Write acknowledgment level.
1368
+ * @default WriteConcern.MEMORY
1369
+ */
1370
+ writeConcern?: WriteConcern;
1371
+ /**
1372
+ * Timeout for waiting for acknowledgment (ms).
1373
+ * Applies to APPLIED, REPLICATED, PERSISTED levels.
1374
+ * @default 5000
1375
+ */
1376
+ timeout?: number;
1377
+ }
1378
+ /**
1379
+ * Result of a write operation
1380
+ */
1381
+ interface WriteResult {
1382
+ /** Whether the operation achieved the requested Write Concern level */
1383
+ success: boolean;
1384
+ /** Operation ID */
1385
+ opId: string;
1386
+ /** The Write Concern level actually achieved */
1387
+ achievedLevel: WriteConcern;
1388
+ /** Time taken to achieve the level (ms) */
1389
+ latencyMs: number;
1390
+ /** Error message if success=false */
1391
+ error?: string;
1392
+ }
1393
+ /**
1394
+ * Internal structure for tracking pending write acknowledgments
1395
+ */
1396
+ interface PendingWrite {
1397
+ /** Operation ID */
1398
+ opId: string;
1399
+ /** Target Write Concern level */
1400
+ writeConcern: WriteConcern;
1401
+ /** Timestamp when operation was registered */
1402
+ timestamp: number;
1403
+ /** Timeout duration (ms) */
1404
+ timeout: number;
1405
+ /** Promise resolve callback */
1406
+ resolve: (result: WriteResult) => void;
1407
+ /** Promise reject callback */
1408
+ reject: (error: Error) => void;
1409
+ /** Timeout handle for cleanup */
1410
+ timeoutHandle?: ReturnType<typeof setTimeout>;
1411
+ /** Set of levels that have been achieved */
1412
+ achievedLevels: Set<WriteConcern>;
1413
+ }
1414
+ /**
1415
+ * Ordered list of Write Concern levels (lowest to highest)
1416
+ */
1417
+ declare const WRITE_CONCERN_ORDER: readonly WriteConcern[];
1418
+ /**
1419
+ * Check if a target Write Concern level is achieved based on achieved levels.
1420
+ *
1421
+ * @param achieved - Set of achieved Write Concern levels
1422
+ * @param target - Target Write Concern level to check
1423
+ * @returns true if target level (or higher) is achieved
1424
+ */
1425
+ declare function isWriteConcernAchieved(achieved: Set<WriteConcern>, target: WriteConcern): boolean;
1426
+ /**
1427
+ * Get the highest achieved Write Concern level from a set of achieved levels.
1428
+ *
1429
+ * @param achieved - Set of achieved Write Concern levels
1430
+ * @returns The highest achieved level
1431
+ */
1432
+ declare function getHighestWriteConcernLevel(achieved: Set<WriteConcern>): WriteConcern;
1433
+
1434
+ /**
1435
+ * Cluster types for Phase 4: Clustering Improvements
1436
+ *
1437
+ * These types are shared between client and server packages
1438
+ * for partition-aware routing and cluster communication.
1439
+ */
1440
+ type NodeStatus = 'ACTIVE' | 'JOINING' | 'LEAVING' | 'SUSPECTED' | 'FAILED';
1441
+ interface NodeInfo {
1442
+ nodeId: string;
1443
+ endpoints: {
1444
+ websocket: string;
1445
+ http?: string;
1446
+ };
1447
+ status: NodeStatus;
1448
+ }
1449
+ interface PartitionInfo {
1450
+ partitionId: number;
1451
+ ownerNodeId: string;
1452
+ backupNodeIds: string[];
1453
+ }
1454
+ interface PartitionMap {
1455
+ version: number;
1456
+ partitionCount: number;
1457
+ nodes: NodeInfo[];
1458
+ partitions: PartitionInfo[];
1459
+ generatedAt: number;
1460
+ }
1461
+ interface PartitionMapMessage {
1462
+ type: 'PARTITION_MAP';
1463
+ payload: PartitionMap;
1464
+ }
1465
+ interface PartitionMapRequestMessage {
1466
+ type: 'PARTITION_MAP_REQUEST';
1467
+ payload?: {
1468
+ currentVersion?: number;
1469
+ };
1470
+ }
1471
+ interface PartitionChange {
1472
+ partitionId: number;
1473
+ previousOwner: string;
1474
+ newOwner: string;
1475
+ reason: 'REBALANCE' | 'FAILOVER' | 'JOIN' | 'LEAVE';
1476
+ }
1477
+ interface PartitionMapDeltaMessage {
1478
+ type: 'PARTITION_MAP_DELTA';
1479
+ payload: {
1480
+ version: number;
1481
+ previousVersion: number;
1482
+ changes: PartitionChange[];
1483
+ timestamp: number;
1484
+ };
1485
+ }
1486
+ interface NotOwnerError {
1487
+ code: 'NOT_OWNER';
1488
+ message: string;
1489
+ hint: {
1490
+ partitionId: number;
1491
+ currentOwner: string;
1492
+ mapVersion: number;
1493
+ };
1494
+ }
1495
+ interface StaleMapError {
1496
+ code: 'STALE_MAP';
1497
+ message: string;
1498
+ hint: {
1499
+ clientVersion: number;
1500
+ serverVersion: number;
1501
+ };
1502
+ }
1503
+ type RoutingError = NotOwnerError | StaleMapError;
1504
+ interface ConnectionPoolConfig {
1505
+ /** Maximum connections per node (default: 1) */
1506
+ maxConnectionsPerNode: number;
1507
+ /** Connection timeout in ms (default: 5000) */
1508
+ connectionTimeoutMs: number;
1509
+ /** Health check interval in ms (default: 10000) */
1510
+ healthCheckIntervalMs: number;
1511
+ /** Reconnect delay base in ms (default: 1000) */
1512
+ reconnectDelayMs: number;
1513
+ /** Maximum reconnect delay in ms (default: 30000) */
1514
+ maxReconnectDelayMs: number;
1515
+ /** Maximum reconnect attempts before marking unhealthy (default: 5) */
1516
+ maxReconnectAttempts: number;
1517
+ }
1518
+ declare const DEFAULT_CONNECTION_POOL_CONFIG: ConnectionPoolConfig;
1519
+ interface PartitionRouterConfig {
1520
+ /** Fallback mode when routing fails: 'forward' uses primary, 'error' throws */
1521
+ fallbackMode: 'forward' | 'error';
1522
+ /** How often to refresh stale partition map in ms (default: 30000) */
1523
+ mapRefreshIntervalMs: number;
1524
+ /** Max staleness before forcing refresh in ms (default: 60000) */
1525
+ maxMapStalenessMs: number;
1526
+ }
1527
+ declare const DEFAULT_PARTITION_ROUTER_CONFIG: PartitionRouterConfig;
1528
+ /**
1529
+ * Circuit breaker configuration.
1530
+ */
1531
+ interface CircuitBreakerConfig {
1532
+ /** Number of failures before opening circuit (default: 5) */
1533
+ failureThreshold: number;
1534
+ /** Time in ms before attempting to close circuit (default: 30000) */
1535
+ resetTimeoutMs: number;
1536
+ }
1537
+ declare const DEFAULT_CIRCUIT_BREAKER_CONFIG: CircuitBreakerConfig;
1538
+ interface ClusterClientConfig {
1539
+ /** Enable cluster mode */
1540
+ enabled: boolean;
1541
+ /** Initial seed nodes to connect to */
1542
+ seedNodes: string[];
1543
+ /** Routing mode: 'direct' routes to owner, 'forward' uses server forwarding */
1544
+ routingMode: 'direct' | 'forward';
1545
+ /** Connection pool configuration */
1546
+ connectionPool?: Partial<ConnectionPoolConfig>;
1547
+ /** Partition router configuration */
1548
+ routing?: Partial<PartitionRouterConfig>;
1549
+ /** Circuit breaker configuration */
1550
+ circuitBreaker?: Partial<CircuitBreakerConfig>;
1551
+ }
1552
+ type ConnectionState = 'DISCONNECTED' | 'CONNECTING' | 'CONNECTED' | 'AUTHENTICATED' | 'RECONNECTING' | 'FAILED';
1553
+ interface NodeHealth {
1554
+ nodeId: string;
1555
+ state: ConnectionState;
1556
+ lastSeen: number;
1557
+ latencyMs: number;
1558
+ reconnectAttempts: number;
1559
+ }
1560
+ interface ClusterEvents {
1561
+ 'node:connected': {
1562
+ nodeId: string;
1563
+ };
1564
+ 'node:disconnected': {
1565
+ nodeId: string;
1566
+ reason: string;
1567
+ };
1568
+ 'node:healthy': {
1569
+ nodeId: string;
1570
+ };
1571
+ 'node:unhealthy': {
1572
+ nodeId: string;
1573
+ reason: string;
1574
+ };
1575
+ 'partitionMap:updated': {
1576
+ version: number;
1577
+ changesCount: number;
1578
+ };
1579
+ 'partitionMap:stale': {
1580
+ currentVersion: number;
1581
+ lastRefresh: number;
1582
+ };
1583
+ 'routing:miss': {
1584
+ key: string;
1585
+ expectedOwner: string;
1586
+ actualOwner: string;
1587
+ };
1588
+ }
1589
+ declare enum PartitionState {
1590
+ STABLE = "STABLE",// Normal operation
1591
+ MIGRATING = "MIGRATING",// Data being transferred
1592
+ SYNC = "SYNC",// Verifying consistency
1593
+ FAILED = "FAILED"
1594
+ }
1595
+ interface PartitionMigration {
1596
+ partitionId: number;
1597
+ state: PartitionState;
1598
+ sourceNode: string;
1599
+ targetNode: string;
1600
+ startTime: number;
1601
+ bytesTransferred: number;
1602
+ totalBytes: number;
1603
+ retryCount: number;
1604
+ }
1605
+ interface MigrationConfig {
1606
+ /** Partitions per batch (default: 10) */
1607
+ batchSize: number;
1608
+ /** Delay between batches in ms (default: 5000) */
1609
+ batchIntervalMs: number;
1610
+ /** Bytes per chunk (default: 64KB) */
1611
+ transferChunkSize: number;
1612
+ /** Retries per partition (default: 3) */
1613
+ maxRetries: number;
1614
+ /** Sync phase timeout in ms (default: 30000) */
1615
+ syncTimeoutMs: number;
1616
+ /** Concurrent transfers (default: 4) */
1617
+ parallelTransfers: number;
1618
+ }
1619
+ declare const DEFAULT_MIGRATION_CONFIG: MigrationConfig;
1620
+ interface MigrationStatus {
1621
+ inProgress: boolean;
1622
+ active: PartitionMigration[];
1623
+ queued: number;
1624
+ completed: number;
1625
+ failed: number;
1626
+ estimatedTimeRemainingMs: number;
1627
+ }
1628
+ interface MigrationMetrics {
1629
+ migrationsStarted: number;
1630
+ migrationsCompleted: number;
1631
+ migrationsFailed: number;
1632
+ chunksTransferred: number;
1633
+ bytesTransferred: number;
1634
+ activeMigrations: number;
1635
+ queuedMigrations: number;
1636
+ }
1637
+ interface MigrationStartMessage {
1638
+ type: 'MIGRATION_START';
1639
+ payload: {
1640
+ partitionId: number;
1641
+ sourceNode: string;
1642
+ estimatedSize: number;
1643
+ };
1644
+ }
1645
+ interface MigrationChunkMessage {
1646
+ type: 'MIGRATION_CHUNK';
1647
+ payload: {
1648
+ partitionId: number;
1649
+ chunkIndex: number;
1650
+ totalChunks: number;
1651
+ data: Uint8Array;
1652
+ checksum: string;
1653
+ };
1654
+ }
1655
+ interface MigrationChunkAckMessage {
1656
+ type: 'MIGRATION_CHUNK_ACK';
1657
+ payload: {
1658
+ partitionId: number;
1659
+ chunkIndex: number;
1660
+ success: boolean;
1661
+ };
1662
+ }
1663
+ interface MigrationCompleteMessage {
1664
+ type: 'MIGRATION_COMPLETE';
1665
+ payload: {
1666
+ partitionId: number;
1667
+ totalRecords: number;
1668
+ checksum: string;
1669
+ };
1670
+ }
1671
+ interface MigrationVerifyMessage {
1672
+ type: 'MIGRATION_VERIFY';
1673
+ payload: {
1674
+ partitionId: number;
1675
+ success: boolean;
1676
+ checksumMatch: boolean;
1677
+ };
1678
+ }
1679
+ type MigrationMessage = MigrationStartMessage | MigrationChunkMessage | MigrationChunkAckMessage | MigrationCompleteMessage | MigrationVerifyMessage;
1680
+ declare enum ConsistencyLevel {
1681
+ /** Wait for all replicas (owner + all backups) */
1682
+ STRONG = "STRONG",
1683
+ /** Wait for majority (owner + N/2 backups) */
1684
+ QUORUM = "QUORUM",
1685
+ /** Acknowledge after owner write only, background replication */
1686
+ EVENTUAL = "EVENTUAL"
1687
+ }
1688
+ interface WriteOptions {
1689
+ consistency?: ConsistencyLevel;
1690
+ /** Replication timeout in ms */
1691
+ timeout?: number;
1692
+ }
1693
+ interface ReadOptions {
1694
+ consistency?: ConsistencyLevel;
1695
+ /** Read from backup if owner unavailable */
1696
+ allowStale?: boolean;
1697
+ /** Max acceptable lag in ms */
1698
+ maxStaleness?: number;
1699
+ }
1700
+ interface ReplicationConfig {
1701
+ defaultConsistency: ConsistencyLevel;
1702
+ /** Max queued operations (default: 10000) */
1703
+ queueSizeLimit: number;
1704
+ /** Operations per batch (default: 100) */
1705
+ batchSize: number;
1706
+ /** Batch flush interval in ms (default: 50) */
1707
+ batchIntervalMs: number;
1708
+ /** Ack timeout in ms (default: 5000) */
1709
+ ackTimeoutMs: number;
1710
+ /** Retries before marking node unhealthy (default: 3) */
1711
+ maxRetries: number;
1712
+ }
1713
+ declare const DEFAULT_REPLICATION_CONFIG: ReplicationConfig;
1714
+ interface ReplicationTask {
1715
+ opId: string;
1716
+ operation: unknown;
1717
+ consistency: ConsistencyLevel;
1718
+ timestamp: number;
1719
+ retryCount: number;
1720
+ }
1721
+ interface ReplicationLag {
1722
+ /** Current lag in ms */
1723
+ current: number;
1724
+ /** Average lag */
1725
+ avg: number;
1726
+ /** Maximum observed lag */
1727
+ max: number;
1728
+ /** 99th percentile lag */
1729
+ percentile99: number;
1730
+ }
1731
+ interface ReplicationHealth {
1732
+ healthy: boolean;
1733
+ unhealthyNodes: string[];
1734
+ laggyNodes: string[];
1735
+ avgLagMs: number;
1736
+ }
1737
+ interface ReplicationResult {
1738
+ success: boolean;
1739
+ ackedBy: string[];
1740
+ }
1741
+ interface ReplicationMessage {
1742
+ type: 'REPLICATION';
1743
+ payload: {
1744
+ opId: string;
1745
+ operation: unknown;
1746
+ consistency: ConsistencyLevel;
1747
+ };
1748
+ }
1749
+ interface ReplicationBatchMessage {
1750
+ type: 'REPLICATION_BATCH';
1751
+ payload: {
1752
+ operations: unknown[];
1753
+ opIds: string[];
1754
+ };
1755
+ }
1756
+ interface ReplicationAckMessage {
1757
+ type: 'REPLICATION_ACK';
1758
+ payload: {
1759
+ opId: string;
1760
+ success: boolean;
1761
+ timestamp: number;
1762
+ };
1763
+ }
1764
+ interface ReplicationBatchAckMessage {
1765
+ type: 'REPLICATION_BATCH_ACK';
1766
+ payload: {
1767
+ opIds: string[];
1768
+ success: boolean;
1769
+ timestamp: number;
1770
+ };
1771
+ }
1772
+ type ReplicationProtocolMessage = ReplicationMessage | ReplicationBatchMessage | ReplicationAckMessage | ReplicationBatchAckMessage;
1773
+ declare const PARTITION_COUNT = 271;
1774
+ declare const DEFAULT_BACKUP_COUNT = 1;
1127
1775
 
1128
- export { AuthMessageSchema, type ClientOp, ClientOpMessageSchema, ClientOpSchema, HLC, LWWMap, type LWWRecord, LWWRecordSchema, LockReleaseSchema, LockRequestSchema, type MergeKeyResult, MerkleReqBucketMessageSchema, MerkleTree, type Message, MessageSchema, ORMap, ORMapDiffRequestSchema, ORMapDiffResponseSchema, type ORMapMerkleNode, ORMapMerkleReqBucketSchema, ORMapMerkleTree, ORMapPushDiffSchema, type ORMapRecord, ORMapRecordSchema, type ORMapSnapshot, ORMapSyncInitSchema, ORMapSyncRespBucketsSchema, ORMapSyncRespLeafSchema, ORMapSyncRespRootSchema, OpBatchMessageSchema, type PermissionPolicy, type PermissionType, type PingMessage, PingMessageSchema, type PongMessage, PongMessageSchema, type PredicateNode, PredicateNodeSchema, type PredicateOp, PredicateOpSchema, Predicates, type Principal, type Query, QuerySchema, QuerySubMessageSchema, QueryUnsubMessageSchema, SyncInitMessageSchema, SyncRespBucketsMessageSchema, SyncRespLeafMessageSchema, SyncRespRootMessageSchema, type Timestamp, TimestampSchema, TopicMessageEventSchema, TopicPubSchema, TopicSubSchema, TopicUnsubSchema, combineHashes, compareTimestamps, deserialize, evaluatePredicate, hashORMapEntry, hashORMapRecord, hashString, serialize, timestampToString };
1776
+ export { AuthMessageSchema, type BatchMessage, BatchMessageSchema, type CircuitBreakerConfig, type ClientOp, ClientOpMessageSchema, ClientOpSchema, type ClusterClientConfig, type ClusterEvents, type ReadOptions as ClusterReadOptions, type WriteOptions as ClusterWriteOptions, type ConnectionPoolConfig, type ConnectionState, ConsistencyLevel, DEFAULT_BACKUP_COUNT, DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_MIGRATION_CONFIG, DEFAULT_PARTITION_ROUTER_CONFIG, DEFAULT_REPLICATION_CONFIG, DEFAULT_WRITE_CONCERN_TIMEOUT, HLC, LWWMap, type LWWRecord, LWWRecordSchema, LockReleaseSchema, LockRequestSchema, type MergeKeyResult, MerkleReqBucketMessageSchema, MerkleTree, type Message, MessageSchema, type MigrationChunkAckMessage, type MigrationChunkMessage, type MigrationCompleteMessage, type MigrationConfig, type MigrationMessage, type MigrationMetrics, type MigrationStartMessage, type MigrationStatus, type MigrationVerifyMessage, type NodeHealth, type NodeInfo, type NodeStatus, type NotOwnerError, ORMap, ORMapDiffRequestSchema, ORMapDiffResponseSchema, type ORMapMerkleNode, ORMapMerkleReqBucketSchema, ORMapMerkleTree, ORMapPushDiffSchema, type ORMapRecord, ORMapRecordSchema, type ORMapSnapshot, ORMapSyncInitSchema, ORMapSyncRespBucketsSchema, ORMapSyncRespLeafSchema, ORMapSyncRespRootSchema, type OpAckMessage, OpAckMessageSchema, OpBatchMessageSchema, type OpRejectedMessage, OpRejectedMessageSchema, type OpResult, OpResultSchema, PARTITION_COUNT, type PartitionChange, type PartitionInfo, type PartitionMap, type PartitionMapDeltaMessage, type PartitionMapMessage, type PartitionMapRequestMessage, PartitionMapRequestSchema, type PartitionMigration, type PartitionRouterConfig, PartitionState, type PendingWrite, type PermissionPolicy, type PermissionType, type PingMessage, PingMessageSchema, type PongMessage, PongMessageSchema, type PredicateNode, PredicateNodeSchema, type PredicateOp, PredicateOpSchema, Predicates, type Principal, type Query, QuerySchema, QuerySubMessageSchema, QueryUnsubMessageSchema, type ReplicationAckMessage, type ReplicationBatchAckMessage, type ReplicationBatchMessage, type ReplicationConfig, type ReplicationHealth, type ReplicationLag, type ReplicationMessage, type ReplicationProtocolMessage, type ReplicationResult, type ReplicationTask, type RoutingError, type StaleMapError, SyncInitMessageSchema, SyncRespBucketsMessageSchema, SyncRespLeafMessageSchema, SyncRespRootMessageSchema, type Timestamp, TimestampSchema, TopicMessageEventSchema, TopicPubSchema, TopicSubSchema, TopicUnsubSchema, WRITE_CONCERN_ORDER, WriteConcern, WriteConcernSchema, type WriteConcernValue, type WriteOptions$1 as WriteOptions, type WriteResult, combineHashes, compareTimestamps, deserialize, disableNativeHash, evaluatePredicate, getHighestWriteConcernLevel, hashORMapEntry, hashORMapRecord, hashString, isUsingNativeHash, isWriteConcernAchieved, resetNativeHash, serialize, timestampToString };