fixparser-common 9.4.5 → 9.4.6

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.
@@ -21,10 +21,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  MessageBuffer: () => MessageBuffer,
24
+ isAsyncMessageStore: () => isAsyncMessageStore,
24
25
  uuidv4: () => uuidv4
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
 
29
+ // src/IAsyncMessageStore.ts
30
+ function isAsyncMessageStore(store) {
31
+ return typeof store.getByMsgSequenceAsync === "function" && typeof store.getAllAsync === "function";
32
+ }
33
+
28
34
  // src/MessageBuffer.ts
29
35
  var MessageBuffer = class {
30
36
  /**
@@ -198,6 +204,7 @@ var uuidv4 = () => {
198
204
  // Annotate the CommonJS export names for ESM import in node:
199
205
  0 && (module.exports = {
200
206
  MessageBuffer,
207
+ isAsyncMessageStore,
201
208
  uuidv4
202
209
  });
203
210
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts", "../../src/MessageBuffer.ts", "../../src/uuidv4.ts"],
4
- "sourcesContent": ["export { ILogTransporter } from './ILogTransporter.ts';\nexport type { IMessage } from './IMessage.ts';\nexport type { IMessageStore } from './IMessageStore.ts';\nexport type { IPlugin } from './IPlugin.ts';\nexport { Level } from './Level.ts';\nexport { LogMessage } from './LogMessage.ts';\nexport { MessageBuffer } from './MessageBuffer.ts';\nexport { uuidv4 } from './uuidv4.ts';\n", "import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * A buffer that stores items of type `T` up to a specified maximum size.\n * Implements the IMessageStore interface for generic types.\n */\nexport class MessageBuffer<T> implements IMessageStore<T> {\n /**\n * A number representing the next expected message sequence number.\n * @private\n */\n private nextMsgSeqNum = 1;\n\n /**\n * An array holding the items in the buffer.\n * @private\n */\n private buffer: T[] = [];\n\n /**\n * The maximum capacity of the buffer.\n * @private\n */\n private maxBufferSize: number;\n\n constructor(maxBufferSize = 2500) {\n this.maxBufferSize = maxBufferSize;\n }\n\n /**\n * Adds a new item to the buffer.\n * If the buffer is full, the oldest item is removed to make space for the new one.\n *\n * @param {T} item - The item to add to the buffer.\n * @returns {void}\n */\n public add(item: T): void {\n if (this.buffer.length === this.maxBufferSize) {\n this.buffer.pop();\n }\n this.buffer.unshift(item);\n }\n\n /**\n * Retrieves an item from the buffer by its sequence number (or any other identifier).\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n * @returns {T | undefined} The item if found, or `undefined` if not found.\n */\n public getByMsgSequence(msgSequence: number): T | undefined {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n return this.buffer[index];\n }\n return undefined;\n }\n\n /**\n * Removes an item from the buffer by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n * @returns {void}\n */\n public remove(msgSequence: number): void {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n this.buffer.splice(index, 1);\n }\n }\n\n /**\n * Updates an item in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to update.\n * @param {T} item - The updated item.\n * @returns {boolean} - Returns `true` if the item was updated successfully, `false` otherwise.\n */\n public update(msgSequence: number, item: T): boolean {\n const index: number = this.buffer.findIndex(\n (existingItem: any) => existingItem.messageSequence === msgSequence,\n );\n if (index > -1) {\n this.buffer[index] = item;\n return true;\n }\n return false;\n }\n\n /**\n * Retrieves all items from the buffer.\n *\n * @returns {T[]} - An array of all items in the buffer.\n */\n public getAll(): T[] {\n return this.buffer;\n }\n\n /**\n * Checks if an item with a given sequence number exists in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {boolean} - `true` if the item exists, `false` otherwise.\n */\n public exists(msgSequence: number): boolean {\n return this.buffer.some((item: any) => item.messageSequence === msgSequence);\n }\n\n /**\n * Gets the current size of the buffer (the number of items it contains).\n *\n * @returns {number} The number of items currently in the buffer.\n */\n public size(): number {\n return this.buffer.length;\n }\n\n /**\n * Resizes the buffer's capacity.\n *\n * @param {number} newCapacity - The new maximum capacity for the buffer.\n * @returns {void}\n */\n public resize(newCapacity: number): void {\n this.maxBufferSize = newCapacity;\n // If the buffer is larger than the new capacity, trim it.\n if (this.buffer.length > this.maxBufferSize) {\n this.buffer = this.buffer.slice(0, this.maxBufferSize);\n }\n }\n\n /**\n * Clears all items from the buffer.\n *\n * @returns {void}\n */\n public clear(): void {\n this.buffer = [];\n }\n\n /**\n * Gets the maximum capacity of the buffer.\n *\n * @returns {number} The maximum number of items the buffer can hold.\n */\n public getCapacity(): number {\n return this.maxBufferSize;\n }\n\n /**\n * Set the next message sequence number.\n *\n * @param nextMsgSeqNum - The next message sequence number.\n * @returns {number} - The next message sequence number.\n */\n public setNextMsgSeqNum(nextMsgSeqNum: number): number {\n if (nextMsgSeqNum <= 0) {\n throw new Error('Message sequence number must be positive.');\n }\n this.nextMsgSeqNum = nextMsgSeqNum;\n return this.nextMsgSeqNum;\n }\n\n /**\n * Get the next message sequence number.\n *\n * @returns {number} - The next message sequence number.\n */\n public getNextMsgSeqNum(): number {\n return this.nextMsgSeqNum;\n }\n}\n", "let randomIterator = 0;\nconst timeBasedRandom = (min: number, max: number): number => {\n const timeNow = Date.now() % 1000;\n randomIterator++;\n let x = timeNow ^ randomIterator;\n x ^= x << 21;\n x ^= x >>> 35;\n x ^= x << 4;\n const timeBasedRandom = Math.abs(x % (max - min + 1));\n return min + timeBasedRandom;\n};\n\nexport const uuidv4 = (): string => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = timeBasedRandom(0, 15);\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA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AM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACxB,CAAC;AACL;",
3
+ "sources": ["../../src/index.ts", "../../src/IAsyncMessageStore.ts", "../../src/MessageBuffer.ts", "../../src/uuidv4.ts"],
4
+ "sourcesContent": ["export type { IAsyncMessageStore } from './IAsyncMessageStore.ts';\nexport { isAsyncMessageStore } from './IAsyncMessageStore.ts';\nexport { ILogTransporter } from './ILogTransporter.ts';\nexport type { IMessage } from './IMessage.ts';\nexport type { IMessageStore } from './IMessageStore.ts';\nexport type { IPlugin } from './IPlugin.ts';\nexport { Level } from './Level.ts';\nexport { LogMessage } from './LogMessage.ts';\nexport { MessageBuffer } from './MessageBuffer.ts';\nexport { uuidv4 } from './uuidv4.ts';\n", "import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * The `IAsyncMessageStore` interface extends `IMessageStore` with asynchronous variants\n * for methods that may need to interact with persistent storage (databases, file systems,\n * remote stores).\n *\n * Implementations MUST provide synchronous methods (inherited from `IMessageStore`) for\n * hot-path operations (`getNextMsgSeqNum`, `setNextMsgSeqNum`, `add`) that work against\n * an in-memory cache. The async methods provide access to the full persistent store.\n *\n * @interface IAsyncMessageStore\n */\nexport interface IAsyncMessageStore<T> extends IMessageStore<T> {\n /**\n * Asynchronously retrieves an item of type `T` from the persistent store by its\n * sequence number. Falls back to persistent storage when the item is not in the\n * in-memory cache.\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n *\n * @returns {Promise<T | undefined>} - The item if found, otherwise `undefined`.\n */\n getByMsgSequenceAsync(msgSequence: number): Promise<T | undefined>;\n\n /**\n * Asynchronously retrieves all items of type `T` from the persistent store.\n *\n * @returns {Promise<T[]>} - An array of all items in the store.\n */\n getAllAsync(): Promise<T[]>;\n\n /**\n * Asynchronously checks if an item with a given sequence number exists in the\n * persistent store.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {Promise<boolean>} - `true` if the item exists, `false` otherwise.\n */\n existsAsync?(msgSequence: number): Promise<boolean>;\n\n /**\n * Asynchronously removes an item from the persistent store by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n *\n * @returns {Promise<void>}\n */\n removeAsync?(msgSequence: number): Promise<void>;\n\n /**\n * Asynchronously clears all items from the persistent store.\n *\n * @returns {Promise<void>}\n */\n clearAsync?(): Promise<void>;\n\n /**\n * Flushes any pending writes from the in-memory cache to the persistent store.\n *\n * @returns {Promise<void>}\n */\n flushAsync?(): Promise<void>;\n}\n\n/**\n * Type guard to check if a message store supports async operations.\n *\n * @param {IMessageStore<T>} store - The message store to check.\n * @returns {boolean} - `true` if the store implements `IAsyncMessageStore`, `false` otherwise.\n */\nexport function isAsyncMessageStore<T>(store: IMessageStore<T>): store is IAsyncMessageStore<T> {\n return (\n typeof (store as IAsyncMessageStore<T>).getByMsgSequenceAsync === 'function' &&\n typeof (store as IAsyncMessageStore<T>).getAllAsync === 'function'\n );\n}\n", "import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * A buffer that stores items of type `T` up to a specified maximum size.\n * Implements the IMessageStore interface for generic types.\n */\nexport class MessageBuffer<T> implements IMessageStore<T> {\n /**\n * A number representing the next expected message sequence number.\n * @private\n */\n private nextMsgSeqNum = 1;\n\n /**\n * An array holding the items in the buffer.\n * @private\n */\n private buffer: T[] = [];\n\n /**\n * The maximum capacity of the buffer.\n * @private\n */\n private maxBufferSize: number;\n\n constructor(maxBufferSize = 2500) {\n this.maxBufferSize = maxBufferSize;\n }\n\n /**\n * Adds a new item to the buffer.\n * If the buffer is full, the oldest item is removed to make space for the new one.\n *\n * @param {T} item - The item to add to the buffer.\n * @returns {void}\n */\n public add(item: T): void {\n if (this.buffer.length === this.maxBufferSize) {\n this.buffer.pop();\n }\n this.buffer.unshift(item);\n }\n\n /**\n * Retrieves an item from the buffer by its sequence number (or any other identifier).\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n * @returns {T | undefined} The item if found, or `undefined` if not found.\n */\n public getByMsgSequence(msgSequence: number): T | undefined {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n return this.buffer[index];\n }\n return undefined;\n }\n\n /**\n * Removes an item from the buffer by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n * @returns {void}\n */\n public remove(msgSequence: number): void {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n this.buffer.splice(index, 1);\n }\n }\n\n /**\n * Updates an item in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to update.\n * @param {T} item - The updated item.\n * @returns {boolean} - Returns `true` if the item was updated successfully, `false` otherwise.\n */\n public update(msgSequence: number, item: T): boolean {\n const index: number = this.buffer.findIndex(\n (existingItem: any) => existingItem.messageSequence === msgSequence,\n );\n if (index > -1) {\n this.buffer[index] = item;\n return true;\n }\n return false;\n }\n\n /**\n * Retrieves all items from the buffer.\n *\n * @returns {T[]} - An array of all items in the buffer.\n */\n public getAll(): T[] {\n return this.buffer;\n }\n\n /**\n * Checks if an item with a given sequence number exists in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {boolean} - `true` if the item exists, `false` otherwise.\n */\n public exists(msgSequence: number): boolean {\n return this.buffer.some((item: any) => item.messageSequence === msgSequence);\n }\n\n /**\n * Gets the current size of the buffer (the number of items it contains).\n *\n * @returns {number} The number of items currently in the buffer.\n */\n public size(): number {\n return this.buffer.length;\n }\n\n /**\n * Resizes the buffer's capacity.\n *\n * @param {number} newCapacity - The new maximum capacity for the buffer.\n * @returns {void}\n */\n public resize(newCapacity: number): void {\n this.maxBufferSize = newCapacity;\n // If the buffer is larger than the new capacity, trim it.\n if (this.buffer.length > this.maxBufferSize) {\n this.buffer = this.buffer.slice(0, this.maxBufferSize);\n }\n }\n\n /**\n * Clears all items from the buffer.\n *\n * @returns {void}\n */\n public clear(): void {\n this.buffer = [];\n }\n\n /**\n * Gets the maximum capacity of the buffer.\n *\n * @returns {number} The maximum number of items the buffer can hold.\n */\n public getCapacity(): number {\n return this.maxBufferSize;\n }\n\n /**\n * Set the next message sequence number.\n *\n * @param nextMsgSeqNum - The next message sequence number.\n * @returns {number} - The next message sequence number.\n */\n public setNextMsgSeqNum(nextMsgSeqNum: number): number {\n if (nextMsgSeqNum <= 0) {\n throw new Error('Message sequence number must be positive.');\n }\n this.nextMsgSeqNum = nextMsgSeqNum;\n return this.nextMsgSeqNum;\n }\n\n /**\n * Get the next message sequence number.\n *\n * @returns {number} - The next message sequence number.\n */\n public getNextMsgSeqNum(): number {\n return this.nextMsgSeqNum;\n }\n}\n", "let randomIterator = 0;\nconst timeBasedRandom = (min: number, max: number): number => {\n const timeNow = Date.now() % 1000;\n randomIterator++;\n let x = timeNow ^ randomIterator;\n x ^= x << 21;\n x ^= x >>> 35;\n x ^= x << 4;\n const timeBasedRandom = Math.abs(x % (max - min + 1));\n return min + timeBasedRandom;\n};\n\nexport const uuidv4 = (): string => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = timeBasedRandom(0, 15);\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuEO,SAAS,oBAAuB,OAAyD;AAC5F,SACI,OAAQ,MAAgC,0BAA0B,cAClE,OAAQ,MAAgC,gBAAgB;AAEhE;;;ACtEO,IAAM,gBAAN,MAAmD;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9C,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhB,SAAc,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMf;AAAA,EAER,YAAY,gBAAgB,MAAM;AAC9B,SAAK,gBAAgB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAI,MAAe;AACtB,QAAI,KAAK,O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zC,WAAK,SAAS,KAAK,OAAO,MAAM,GAAG,KAAK,aAAa;AAAA,IACzD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAc;AACjB,SAAK,SAAS,CAAC;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,cAAsB;AACzB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,iBAAiB,eAA+B;AACnD,QAAI,iBAAiB,GAAG;AACpB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC/D;AACA,SAAK,gBAAgB;AACrB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,mBAA2B;AAC9B,WAAO,KAAK;AAAA,EAChB;AACJ;;;AC1KA,IAAI,iBAAiB;AACrB,IAAM,kBAAkB,CAAC,KAAa,QAAwB;AAC1D,QAAM,UAAU,KAAK,IAAI,IAAI;AAC7B;AACA,MAAI,IAAI,UAAU;AAClB,OAAK,KAAK;AACV,OAAK,MAAM;AACX,OAAK,KAAK;AACV,QAAMA,mBAAkB,KAAK,IAAI,KAAK,MAAM,MAAM,EAAE;AACpD,SAAO,MAAMA;AACjB;AAEO,IAAM,SAAS,MAAc;AAChC,SAAO,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAClE,UAAM,IAAI,gBAAgB,GAAG,EAAE;AAC/B,UAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACxB,CAAC;AACL;",
6
6
  "names": ["timeBasedRandom"]
7
7
  }
@@ -1,3 +1,8 @@
1
+ // src/IAsyncMessageStore.ts
2
+ function isAsyncMessageStore(store) {
3
+ return typeof store.getByMsgSequenceAsync === "function" && typeof store.getAllAsync === "function";
4
+ }
5
+
1
6
  // src/MessageBuffer.ts
2
7
  var MessageBuffer = class {
3
8
  /**
@@ -170,6 +175,7 @@ var uuidv4 = () => {
170
175
  };
171
176
  export {
172
177
  MessageBuffer,
178
+ isAsyncMessageStore,
173
179
  uuidv4
174
180
  };
175
181
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/MessageBuffer.ts", "../../src/uuidv4.ts"],
4
- "sourcesContent": ["import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * A buffer that stores items of type `T` up to a specified maximum size.\n * Implements the IMessageStore interface for generic types.\n */\nexport class MessageBuffer<T> implements IMessageStore<T> {\n /**\n * A number representing the next expected message sequence number.\n * @private\n */\n private nextMsgSeqNum = 1;\n\n /**\n * An array holding the items in the buffer.\n * @private\n */\n private buffer: T[] = [];\n\n /**\n * The maximum capacity of the buffer.\n * @private\n */\n private maxBufferSize: number;\n\n constructor(maxBufferSize = 2500) {\n this.maxBufferSize = maxBufferSize;\n }\n\n /**\n * Adds a new item to the buffer.\n * If the buffer is full, the oldest item is removed to make space for the new one.\n *\n * @param {T} item - The item to add to the buffer.\n * @returns {void}\n */\n public add(item: T): void {\n if (this.buffer.length === this.maxBufferSize) {\n this.buffer.pop();\n }\n this.buffer.unshift(item);\n }\n\n /**\n * Retrieves an item from the buffer by its sequence number (or any other identifier).\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n * @returns {T | undefined} The item if found, or `undefined` if not found.\n */\n public getByMsgSequence(msgSequence: number): T | undefined {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n return this.buffer[index];\n }\n return undefined;\n }\n\n /**\n * Removes an item from the buffer by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n * @returns {void}\n */\n public remove(msgSequence: number): void {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n this.buffer.splice(index, 1);\n }\n }\n\n /**\n * Updates an item in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to update.\n * @param {T} item - The updated item.\n * @returns {boolean} - Returns `true` if the item was updated successfully, `false` otherwise.\n */\n public update(msgSequence: number, item: T): boolean {\n const index: number = this.buffer.findIndex(\n (existingItem: any) => existingItem.messageSequence === msgSequence,\n );\n if (index > -1) {\n this.buffer[index] = item;\n return true;\n }\n return false;\n }\n\n /**\n * Retrieves all items from the buffer.\n *\n * @returns {T[]} - An array of all items in the buffer.\n */\n public getAll(): T[] {\n return this.buffer;\n }\n\n /**\n * Checks if an item with a given sequence number exists in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {boolean} - `true` if the item exists, `false` otherwise.\n */\n public exists(msgSequence: number): boolean {\n return this.buffer.some((item: any) => item.messageSequence === msgSequence);\n }\n\n /**\n * Gets the current size of the buffer (the number of items it contains).\n *\n * @returns {number} The number of items currently in the buffer.\n */\n public size(): number {\n return this.buffer.length;\n }\n\n /**\n * Resizes the buffer's capacity.\n *\n * @param {number} newCapacity - The new maximum capacity for the buffer.\n * @returns {void}\n */\n public resize(newCapacity: number): void {\n this.maxBufferSize = newCapacity;\n // If the buffer is larger than the new capacity, trim it.\n if (this.buffer.length > this.maxBufferSize) {\n this.buffer = this.buffer.slice(0, this.maxBufferSize);\n }\n }\n\n /**\n * Clears all items from the buffer.\n *\n * @returns {void}\n */\n public clear(): void {\n this.buffer = [];\n }\n\n /**\n * Gets the maximum capacity of the buffer.\n *\n * @returns {number} The maximum number of items the buffer can hold.\n */\n public getCapacity(): number {\n return this.maxBufferSize;\n }\n\n /**\n * Set the next message sequence number.\n *\n * @param nextMsgSeqNum - The next message sequence number.\n * @returns {number} - The next message sequence number.\n */\n public setNextMsgSeqNum(nextMsgSeqNum: number): number {\n if (nextMsgSeqNum <= 0) {\n throw new Error('Message sequence number must be positive.');\n }\n this.nextMsgSeqNum = nextMsgSeqNum;\n return this.nextMsgSeqNum;\n }\n\n /**\n * Get the next message sequence number.\n *\n * @returns {number} - The next message sequence number.\n */\n public getNextMsgSeqNum(): number {\n return this.nextMsgSeqNum;\n }\n}\n", "let randomIterator = 0;\nconst timeBasedRandom = (min: number, max: number): number => {\n const timeNow = Date.now() % 1000;\n randomIterator++;\n let x = timeNow ^ randomIterator;\n x ^= x << 21;\n x ^= x >>> 35;\n x ^= x << 4;\n const timeBasedRandom = Math.abs(x % (max - min + 1));\n return min + timeBasedRandom;\n};\n\nexport const uuidv4 = (): string => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = timeBasedRandom(0, 15);\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"],
5
- "mappings": ";AAMO,IAAM,gBAAN,MAAmD;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9C,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhB,SAAc,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMf;AAAA,EAER,YAAY,gBAAgB,MAAM;AAC9B,SAAK,gBAAgB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAI,MAAe;AACtB,QAAI,KAAK,OAAO,WAAW,KAAK,eAAe;AAC3C,WAAK,OAAO,IAAI;AAAA,IACpB;AACA,SAAK,OAAO,QAAQ,IAAI;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,iBAAiB,aAAoC;AACxD,UAAM,QAAgB,KAAK,OAAO,UAAU,CAAC,SAAc,KAAK,oBAAoB,WAAW;AAC/F,QAAI,QAAQ,IAAI;AACZ,aAAO,KAAK,OAAO,KAAK;AAAA,IAC5B;AACA,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,OAAO,aAA2B;AACrC,UAAM,QAAgB,KAAK,OAAO,UAAU,CAAC,SAAc,KAAK,oBAAoB,WAAW;AAC/F,QAAI,QAAQ,IAAI;AACZ,WAAK,OAAO,OAAO,OAAO,CAAC;AAAA,IAC/B;AA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ACrB,IAAM,kBAAkB,CAAC,KAAa,QAAwB;AAC1D,QAAM,UAAU,KAAK,IAAI,IAAI;AAC7B;AACA,MAAI,IAAI,UAAU;AAClB,OAAK,KAAK;AACV,OAAK,MAAM;AACX,OAAK,KAAK;AACV,QAAMA,mBAAkB,KAAK,IAAI,KAAK,MAAM,MAAM,EAAE;AACpD,SAAO,MAAMA;AACjB;AAEO,IAAM,SAAS,MAAc;AAChC,SAAO,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAClE,UAAM,IAAI,gBAAgB,GAAG,EAAE;AAC/B,UAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACxB,CAAC;AACL;",
3
+ "sources": ["../../src/IAsyncMessageStore.ts", "../../src/MessageBuffer.ts", "../../src/uuidv4.ts"],
4
+ "sourcesContent": ["import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * The `IAsyncMessageStore` interface extends `IMessageStore` with asynchronous variants\n * for methods that may need to interact with persistent storage (databases, file systems,\n * remote stores).\n *\n * Implementations MUST provide synchronous methods (inherited from `IMessageStore`) for\n * hot-path operations (`getNextMsgSeqNum`, `setNextMsgSeqNum`, `add`) that work against\n * an in-memory cache. The async methods provide access to the full persistent store.\n *\n * @interface IAsyncMessageStore\n */\nexport interface IAsyncMessageStore<T> extends IMessageStore<T> {\n /**\n * Asynchronously retrieves an item of type `T` from the persistent store by its\n * sequence number. Falls back to persistent storage when the item is not in the\n * in-memory cache.\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n *\n * @returns {Promise<T | undefined>} - The item if found, otherwise `undefined`.\n */\n getByMsgSequenceAsync(msgSequence: number): Promise<T | undefined>;\n\n /**\n * Asynchronously retrieves all items of type `T` from the persistent store.\n *\n * @returns {Promise<T[]>} - An array of all items in the store.\n */\n getAllAsync(): Promise<T[]>;\n\n /**\n * Asynchronously checks if an item with a given sequence number exists in the\n * persistent store.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {Promise<boolean>} - `true` if the item exists, `false` otherwise.\n */\n existsAsync?(msgSequence: number): Promise<boolean>;\n\n /**\n * Asynchronously removes an item from the persistent store by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n *\n * @returns {Promise<void>}\n */\n removeAsync?(msgSequence: number): Promise<void>;\n\n /**\n * Asynchronously clears all items from the persistent store.\n *\n * @returns {Promise<void>}\n */\n clearAsync?(): Promise<void>;\n\n /**\n * Flushes any pending writes from the in-memory cache to the persistent store.\n *\n * @returns {Promise<void>}\n */\n flushAsync?(): Promise<void>;\n}\n\n/**\n * Type guard to check if a message store supports async operations.\n *\n * @param {IMessageStore<T>} store - The message store to check.\n * @returns {boolean} - `true` if the store implements `IAsyncMessageStore`, `false` otherwise.\n */\nexport function isAsyncMessageStore<T>(store: IMessageStore<T>): store is IAsyncMessageStore<T> {\n return (\n typeof (store as IAsyncMessageStore<T>).getByMsgSequenceAsync === 'function' &&\n typeof (store as IAsyncMessageStore<T>).getAllAsync === 'function'\n );\n}\n", "import type { IMessageStore } from './IMessageStore.ts';\n\n/**\n * A buffer that stores items of type `T` up to a specified maximum size.\n * Implements the IMessageStore interface for generic types.\n */\nexport class MessageBuffer<T> implements IMessageStore<T> {\n /**\n * A number representing the next expected message sequence number.\n * @private\n */\n private nextMsgSeqNum = 1;\n\n /**\n * An array holding the items in the buffer.\n * @private\n */\n private buffer: T[] = [];\n\n /**\n * The maximum capacity of the buffer.\n * @private\n */\n private maxBufferSize: number;\n\n constructor(maxBufferSize = 2500) {\n this.maxBufferSize = maxBufferSize;\n }\n\n /**\n * Adds a new item to the buffer.\n * If the buffer is full, the oldest item is removed to make space for the new one.\n *\n * @param {T} item - The item to add to the buffer.\n * @returns {void}\n */\n public add(item: T): void {\n if (this.buffer.length === this.maxBufferSize) {\n this.buffer.pop();\n }\n this.buffer.unshift(item);\n }\n\n /**\n * Retrieves an item from the buffer by its sequence number (or any other identifier).\n *\n * @param {number} msgSequence - The sequence number of the item to retrieve.\n * @returns {T | undefined} The item if found, or `undefined` if not found.\n */\n public getByMsgSequence(msgSequence: number): T | undefined {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n return this.buffer[index];\n }\n return undefined;\n }\n\n /**\n * Removes an item from the buffer by its sequence number.\n *\n * @param {number} msgSequence - The sequence number of the item to remove.\n * @returns {void}\n */\n public remove(msgSequence: number): void {\n const index: number = this.buffer.findIndex((item: any) => item.messageSequence === msgSequence);\n if (index > -1) {\n this.buffer.splice(index, 1);\n }\n }\n\n /**\n * Updates an item in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to update.\n * @param {T} item - The updated item.\n * @returns {boolean} - Returns `true` if the item was updated successfully, `false` otherwise.\n */\n public update(msgSequence: number, item: T): boolean {\n const index: number = this.buffer.findIndex(\n (existingItem: any) => existingItem.messageSequence === msgSequence,\n );\n if (index > -1) {\n this.buffer[index] = item;\n return true;\n }\n return false;\n }\n\n /**\n * Retrieves all items from the buffer.\n *\n * @returns {T[]} - An array of all items in the buffer.\n */\n public getAll(): T[] {\n return this.buffer;\n }\n\n /**\n * Checks if an item with a given sequence number exists in the buffer.\n *\n * @param {number} msgSequence - The sequence number of the item to check.\n * @returns {boolean} - `true` if the item exists, `false` otherwise.\n */\n public exists(msgSequence: number): boolean {\n return this.buffer.some((item: any) => item.messageSequence === msgSequence);\n }\n\n /**\n * Gets the current size of the buffer (the number of items it contains).\n *\n * @returns {number} The number of items currently in the buffer.\n */\n public size(): number {\n return this.buffer.length;\n }\n\n /**\n * Resizes the buffer's capacity.\n *\n * @param {number} newCapacity - The new maximum capacity for the buffer.\n * @returns {void}\n */\n public resize(newCapacity: number): void {\n this.maxBufferSize = newCapacity;\n // If the buffer is larger than the new capacity, trim it.\n if (this.buffer.length > this.maxBufferSize) {\n this.buffer = this.buffer.slice(0, this.maxBufferSize);\n }\n }\n\n /**\n * Clears all items from the buffer.\n *\n * @returns {void}\n */\n public clear(): void {\n this.buffer = [];\n }\n\n /**\n * Gets the maximum capacity of the buffer.\n *\n * @returns {number} The maximum number of items the buffer can hold.\n */\n public getCapacity(): number {\n return this.maxBufferSize;\n }\n\n /**\n * Set the next message sequence number.\n *\n * @param nextMsgSeqNum - The next message sequence number.\n * @returns {number} - The next message sequence number.\n */\n public setNextMsgSeqNum(nextMsgSeqNum: number): number {\n if (nextMsgSeqNum <= 0) {\n throw new Error('Message sequence number must be positive.');\n }\n this.nextMsgSeqNum = nextMsgSeqNum;\n return this.nextMsgSeqNum;\n }\n\n /**\n * Get the next message sequence number.\n *\n * @returns {number} - The next message sequence number.\n */\n public getNextMsgSeqNum(): number {\n return this.nextMsgSeqNum;\n }\n}\n", "let randomIterator = 0;\nconst timeBasedRandom = (min: number, max: number): number => {\n const timeNow = Date.now() % 1000;\n randomIterator++;\n let x = timeNow ^ randomIterator;\n x ^= x << 21;\n x ^= x >>> 35;\n x ^= x << 4;\n const timeBasedRandom = Math.abs(x % (max - min + 1));\n return min + timeBasedRandom;\n};\n\nexport const uuidv4 = (): string => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = timeBasedRandom(0, 15);\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"],
5
+ "mappings": ";AAuEO,SAAS,oBAAuB,OAAyD;AAC5F,SACI,OAAQ,MAAgC,0BAA0B,cAClE,OAAQ,MAAgC,gBAAgB;AAEhE;;;ACtEO,IAAM,gBAAN,MAAmD;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9C,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhB,SAAc,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMf;AAAA,EAER,YAAY,gBAAgB,MAAM;AAC9B,SAAK,gBAAgB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAI,MAAe;AACtB,QAAI,KAAK,OAA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,WAAK,SAAS,KAAK,OAAO,MAAM,GAAG,KAAK,aAAa;AAAA,IACzD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAc;AACjB,SAAK,SAAS,CAAC;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,cAAsB;AACzB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,iBAAiB,eAA+B;AACnD,QAAI,iBAAiB,GAAG;AACpB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC/D;AACA,SAAK,gBAAgB;AACrB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,mBAA2B;AAC9B,WAAO,KAAK;AAAA,EAChB;AACJ;;;AC1KA,IAAI,iBAAiB;AACrB,IAAM,kBAAkB,CAAC,KAAa,QAAwB;AAC1D,QAAM,UAAU,KAAK,IAAI,IAAI;AAC7B;AACA,MAAI,IAAI,UAAU;AAClB,OAAK,KAAK;AACV,OAAK,MAAM;AACX,OAAK,KAAK;AACV,QAAMA,mBAAkB,KAAK,IAAI,KAAK,MAAM,MAAM,EAAE;AACpD,SAAO,MAAMA;AACjB;AAEO,IAAM,SAAS,MAAc;AAChC,SAAO,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAClE,UAAM,IAAI,gBAAgB,GAAG,EAAE;AAC/B,UAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,WAAO,EAAE,SAAS,EAAE;AAAA,EACxB,CAAC;AACL;",
6
6
  "names": ["timeBasedRandom"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fixparser-common",
3
- "version": "9.4.5",
3
+ "version": "9.4.6",
4
4
  "description": "FIXParser shared codebase",
5
5
  "files": [
6
6
  "./build/",
@@ -0,0 +1,65 @@
1
+ import type { IMessageStore } from './IMessageStore.ts';
2
+ /**
3
+ * The `IAsyncMessageStore` interface extends `IMessageStore` with asynchronous variants
4
+ * for methods that may need to interact with persistent storage (databases, file systems,
5
+ * remote stores).
6
+ *
7
+ * Implementations MUST provide synchronous methods (inherited from `IMessageStore`) for
8
+ * hot-path operations (`getNextMsgSeqNum`, `setNextMsgSeqNum`, `add`) that work against
9
+ * an in-memory cache. The async methods provide access to the full persistent store.
10
+ *
11
+ * @interface IAsyncMessageStore
12
+ */
13
+ export interface IAsyncMessageStore<T> extends IMessageStore<T> {
14
+ /**
15
+ * Asynchronously retrieves an item of type `T` from the persistent store by its
16
+ * sequence number. Falls back to persistent storage when the item is not in the
17
+ * in-memory cache.
18
+ *
19
+ * @param {number} msgSequence - The sequence number of the item to retrieve.
20
+ *
21
+ * @returns {Promise<T | undefined>} - The item if found, otherwise `undefined`.
22
+ */
23
+ getByMsgSequenceAsync(msgSequence: number): Promise<T | undefined>;
24
+ /**
25
+ * Asynchronously retrieves all items of type `T` from the persistent store.
26
+ *
27
+ * @returns {Promise<T[]>} - An array of all items in the store.
28
+ */
29
+ getAllAsync(): Promise<T[]>;
30
+ /**
31
+ * Asynchronously checks if an item with a given sequence number exists in the
32
+ * persistent store.
33
+ *
34
+ * @param {number} msgSequence - The sequence number of the item to check.
35
+ * @returns {Promise<boolean>} - `true` if the item exists, `false` otherwise.
36
+ */
37
+ existsAsync?(msgSequence: number): Promise<boolean>;
38
+ /**
39
+ * Asynchronously removes an item from the persistent store by its sequence number.
40
+ *
41
+ * @param {number} msgSequence - The sequence number of the item to remove.
42
+ *
43
+ * @returns {Promise<void>}
44
+ */
45
+ removeAsync?(msgSequence: number): Promise<void>;
46
+ /**
47
+ * Asynchronously clears all items from the persistent store.
48
+ *
49
+ * @returns {Promise<void>}
50
+ */
51
+ clearAsync?(): Promise<void>;
52
+ /**
53
+ * Flushes any pending writes from the in-memory cache to the persistent store.
54
+ *
55
+ * @returns {Promise<void>}
56
+ */
57
+ flushAsync?(): Promise<void>;
58
+ }
59
+ /**
60
+ * Type guard to check if a message store supports async operations.
61
+ *
62
+ * @param {IMessageStore<T>} store - The message store to check.
63
+ * @returns {boolean} - `true` if the store implements `IAsyncMessageStore`, `false` otherwise.
64
+ */
65
+ export declare function isAsyncMessageStore<T>(store: IMessageStore<T>): store is IAsyncMessageStore<T>;
package/types/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type { IAsyncMessageStore } from './IAsyncMessageStore.ts';
2
+ export { isAsyncMessageStore } from './IAsyncMessageStore.ts';
1
3
  export { ILogTransporter } from './ILogTransporter.ts';
2
4
  export type { IMessage } from './IMessage.ts';
3
5
  export type { IMessageStore } from './IMessageStore.ts';