fixparser-plugin-messagestore-kdb 9.1.6 → 9.1.7-af630b11
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.
|
@@ -3636,174 +3636,8 @@ var require_websocket_server = __commonJS({
|
|
|
3636
3636
|
}
|
|
3637
3637
|
});
|
|
3638
3638
|
|
|
3639
|
-
//
|
|
3640
|
-
|
|
3641
|
-
/**
|
|
3642
|
-
* A number representing the next expected message sequence number.
|
|
3643
|
-
* @private
|
|
3644
|
-
*/
|
|
3645
|
-
nextMsgSeqNum = 1;
|
|
3646
|
-
/**
|
|
3647
|
-
* An array holding the items in the buffer.
|
|
3648
|
-
* @private
|
|
3649
|
-
*/
|
|
3650
|
-
buffer = [];
|
|
3651
|
-
/**
|
|
3652
|
-
* The maximum capacity of the buffer.
|
|
3653
|
-
* @private
|
|
3654
|
-
*/
|
|
3655
|
-
maxBufferSize;
|
|
3656
|
-
constructor(maxBufferSize = 2500) {
|
|
3657
|
-
this.maxBufferSize = maxBufferSize;
|
|
3658
|
-
}
|
|
3659
|
-
/**
|
|
3660
|
-
* Adds a new item to the buffer.
|
|
3661
|
-
* If the buffer is full, the oldest item is removed to make space for the new one.
|
|
3662
|
-
*
|
|
3663
|
-
* @param {T} item - The item to add to the buffer.
|
|
3664
|
-
* @returns {void}
|
|
3665
|
-
*/
|
|
3666
|
-
add(item) {
|
|
3667
|
-
if (this.buffer.length === this.maxBufferSize) {
|
|
3668
|
-
this.buffer.pop();
|
|
3669
|
-
}
|
|
3670
|
-
this.buffer.unshift(item);
|
|
3671
|
-
}
|
|
3672
|
-
/**
|
|
3673
|
-
* Retrieves an item from the buffer by its sequence number (or any other identifier).
|
|
3674
|
-
*
|
|
3675
|
-
* @param {number} msgSequence - The sequence number of the item to retrieve.
|
|
3676
|
-
* @returns {T | undefined} The item if found, or `undefined` if not found.
|
|
3677
|
-
*/
|
|
3678
|
-
getByMsgSequence(msgSequence) {
|
|
3679
|
-
const index = this.buffer.findIndex((item) => item.messageSequence === msgSequence);
|
|
3680
|
-
if (index > -1) {
|
|
3681
|
-
return this.buffer[index];
|
|
3682
|
-
}
|
|
3683
|
-
return void 0;
|
|
3684
|
-
}
|
|
3685
|
-
/**
|
|
3686
|
-
* Removes an item from the buffer by its sequence number.
|
|
3687
|
-
*
|
|
3688
|
-
* @param {number} msgSequence - The sequence number of the item to remove.
|
|
3689
|
-
* @returns {void}
|
|
3690
|
-
*/
|
|
3691
|
-
remove(msgSequence) {
|
|
3692
|
-
const index = this.buffer.findIndex((item) => item.messageSequence === msgSequence);
|
|
3693
|
-
if (index > -1) {
|
|
3694
|
-
this.buffer.splice(index, 1);
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
/**
|
|
3698
|
-
* Updates an item in the buffer.
|
|
3699
|
-
*
|
|
3700
|
-
* @param {number} msgSequence - The sequence number of the item to update.
|
|
3701
|
-
* @param {T} item - The updated item.
|
|
3702
|
-
* @returns {boolean} - Returns `true` if the item was updated successfully, `false` otherwise.
|
|
3703
|
-
*/
|
|
3704
|
-
update(msgSequence, item) {
|
|
3705
|
-
const index = this.buffer.findIndex(
|
|
3706
|
-
(existingItem) => existingItem.messageSequence === msgSequence
|
|
3707
|
-
);
|
|
3708
|
-
if (index > -1) {
|
|
3709
|
-
this.buffer[index] = item;
|
|
3710
|
-
return true;
|
|
3711
|
-
}
|
|
3712
|
-
return false;
|
|
3713
|
-
}
|
|
3714
|
-
/**
|
|
3715
|
-
* Retrieves all items from the buffer.
|
|
3716
|
-
*
|
|
3717
|
-
* @returns {T[]} - An array of all items in the buffer.
|
|
3718
|
-
*/
|
|
3719
|
-
getAll() {
|
|
3720
|
-
return this.buffer;
|
|
3721
|
-
}
|
|
3722
|
-
/**
|
|
3723
|
-
* Checks if an item with a given sequence number exists in the buffer.
|
|
3724
|
-
*
|
|
3725
|
-
* @param {number} msgSequence - The sequence number of the item to check.
|
|
3726
|
-
* @returns {boolean} - `true` if the item exists, `false` otherwise.
|
|
3727
|
-
*/
|
|
3728
|
-
exists(msgSequence) {
|
|
3729
|
-
return this.buffer.some((item) => item.messageSequence === msgSequence);
|
|
3730
|
-
}
|
|
3731
|
-
/**
|
|
3732
|
-
* Gets the current size of the buffer (the number of items it contains).
|
|
3733
|
-
*
|
|
3734
|
-
* @returns {number} The number of items currently in the buffer.
|
|
3735
|
-
*/
|
|
3736
|
-
size() {
|
|
3737
|
-
return this.buffer.length;
|
|
3738
|
-
}
|
|
3739
|
-
/**
|
|
3740
|
-
* Resizes the buffer's capacity.
|
|
3741
|
-
*
|
|
3742
|
-
* @param {number} newCapacity - The new maximum capacity for the buffer.
|
|
3743
|
-
* @returns {void}
|
|
3744
|
-
*/
|
|
3745
|
-
resize(newCapacity) {
|
|
3746
|
-
this.maxBufferSize = newCapacity;
|
|
3747
|
-
if (this.buffer.length > this.maxBufferSize) {
|
|
3748
|
-
this.buffer = this.buffer.slice(0, this.maxBufferSize);
|
|
3749
|
-
}
|
|
3750
|
-
}
|
|
3751
|
-
/**
|
|
3752
|
-
* Clears all items from the buffer.
|
|
3753
|
-
*
|
|
3754
|
-
* @returns {void}
|
|
3755
|
-
*/
|
|
3756
|
-
clear() {
|
|
3757
|
-
this.buffer = [];
|
|
3758
|
-
}
|
|
3759
|
-
/**
|
|
3760
|
-
* Gets the maximum capacity of the buffer.
|
|
3761
|
-
*
|
|
3762
|
-
* @returns {number} The maximum number of items the buffer can hold.
|
|
3763
|
-
*/
|
|
3764
|
-
getCapacity() {
|
|
3765
|
-
return this.maxBufferSize;
|
|
3766
|
-
}
|
|
3767
|
-
/**
|
|
3768
|
-
* Set the next message sequence number.
|
|
3769
|
-
*
|
|
3770
|
-
* @param nextMsgSeqNum - The next message sequence number.
|
|
3771
|
-
* @returns {number} - The next message sequence number.
|
|
3772
|
-
*/
|
|
3773
|
-
setNextMsgSeqNum(nextMsgSeqNum) {
|
|
3774
|
-
if (nextMsgSeqNum <= 0) {
|
|
3775
|
-
throw new Error("Message sequence number must be positive.");
|
|
3776
|
-
}
|
|
3777
|
-
this.nextMsgSeqNum = nextMsgSeqNum;
|
|
3778
|
-
return this.nextMsgSeqNum;
|
|
3779
|
-
}
|
|
3780
|
-
/**
|
|
3781
|
-
* Get the next message sequence number.
|
|
3782
|
-
*
|
|
3783
|
-
* @returns {number} - The next message sequence number.
|
|
3784
|
-
*/
|
|
3785
|
-
getNextMsgSeqNum() {
|
|
3786
|
-
return this.nextMsgSeqNum;
|
|
3787
|
-
}
|
|
3788
|
-
};
|
|
3789
|
-
var randomIterator = 0;
|
|
3790
|
-
var timeBasedRandom = (min, max) => {
|
|
3791
|
-
const timeNow = Date.now() % 1e3;
|
|
3792
|
-
randomIterator++;
|
|
3793
|
-
let x = timeNow ^ randomIterator;
|
|
3794
|
-
x ^= x << 21;
|
|
3795
|
-
x ^= x >>> 35;
|
|
3796
|
-
x ^= x << 4;
|
|
3797
|
-
const timeBasedRandom2 = Math.abs(x % (max - min + 1));
|
|
3798
|
-
return min + timeBasedRandom2;
|
|
3799
|
-
};
|
|
3800
|
-
var uuidv4 = () => {
|
|
3801
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
3802
|
-
const r = timeBasedRandom(0, 15);
|
|
3803
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
3804
|
-
return v.toString(16);
|
|
3805
|
-
});
|
|
3806
|
-
};
|
|
3639
|
+
// src/MessageStoreKDB.ts
|
|
3640
|
+
import { MessageBuffer, uuidv4 } from "fixparser-common";
|
|
3807
3641
|
|
|
3808
3642
|
// ../../node_modules/ws/wrapper.mjs
|
|
3809
3643
|
var import_stream = __toESM(require_stream(), 1);
|