{
  "version": 3,
  "sources": ["../../src/index.ts", "../../src/IAsyncMessageStore.ts", "../../src/MessageBuffer.ts", "../../src/uuidv4.ts"],
  "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"],
  "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;AAA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