{"version":3,"sources":["../../src/consts.ts","../../src/utils/isFunction.ts","../../src/pipes/queue.ts","../../src/utils/delay.ts","../../src/pipes/retry.ts","../../src/pipes/timeout.ts","../../src/pipes/debounce.ts","../../src/pipes/throttle.ts","../../src/pipes/memorize.ts"],"names":["FastEventError","message","TimeoutError","QueueOverflowError","isFunction","fn","queue","options","lifetime","size","overflow","maxExpandSize","expandOverflow","onPush","onDrop","onPop","buffer","currentSize","isHandling","hasNewMessage","pushMessage","handleOverflow","msg","listener","args","nextMessage","enterTime","dropping","sliding","expanding","delay","ms","resolve","retry","retries","interval","drop","retryCount","lastError","error","timeout","defaultValue","timeoutId","timeoutPromise","reject","listenerPromise","debounce","isBlocked","result","throttle","lastExecutionTime","now","memorize","predicate","lastResult","hasResult","lastPayload","hasPredicate"],"mappings":"AAEO,IAAMA,EAAN,cAA6B,KAAM,CACtC,WAAA,CAAYC,EAAkB,CAC1B,KAAA,CAAMA,CAAO,EACjB,CACJ,CAEaC,CAAAA,CAAAA,CAAN,cAA2BF,CAAe,EAK1C,CAAA,IAAMG,CAAN,CAAA,cAAiCH,CAAe,EAAC,CCbjD,SAASI,CAAAA,CAAWC,EAAyB,CAChD,OAAOA,CAAM,EAAA,OAAQA,GAAO,UAChC,KCsCaC,CAASC,CAAAA,CAAAA,EAAyD,CAC3E,GAAM,CAAE,QAAAC,CAAAA,CAAAA,CAAU,KAAAC,CAAM,CAAA,QAAA,CAAAC,CAAU,CAAA,aAAA,CAAAC,EAAe,cAAAC,CAAAA,CAAAA,CAAgB,MAAAC,CAAAA,CAAAA,CAAQ,OAAAC,CAAQ,CAAA,KAAA,CAAAC,CAAM,CAAA,CACnF,OAAO,MACH,CAAA,CACI,IAAM,CAAA,EAAA,CACN,cAAe,GACf,CAAA,QAAA,CAAU,QACV,CAAA,cAAA,CAAgB,QAChB,QAAU,CAAA,CACd,CACAR,CAAAA,CACJ,EAEAS,CAA4C,CAAA,GAC5CC,CAAcR,CAAAA,CAAAA,CACdS,EAAa,K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CAAAA,CAAI,CAClD,CACJ,EC5BG,SAAS4B,CAAAA,CACZC,EAIgB,CAChB,IAAIC,CACAC,CAAAA,CAAAA,CAAY,MACZC,CACAC,CAAAA,CAAAA,CAAe,OAAOJ,CAAAA,EAAc,WACxC,OAAO,SAAU9B,EAA0D,CACvE,OAAO,eAAgBtB,CAAgCuB,CAAAA,CAAAA,CAA6B,CAChF,GAAI+B,GAEA,GAAI,OAAOF,CAAc,EAAA,UAAA,CAAA,CACrB,GAAI,MAAMA,CAAAA,CAAUpD,CAASuB,CAAAA,CAAI,EAC7B,OAAO8B,CAAAA,CAAAA,KAAAA,GAIPrD,EAAQ,OAAYuD,GAAAA,CAAAA,CACpB,OAAOF,CAKnB,CAAA,IAAMN,CAAS,CAAA,MAAMzB,EAAS,IAAK,CAAA,IAAA,CAAMtB,CAASuB,CAAAA,CAAI,EACtD,OAAA8B,CAAAA,CAAaN,CACRS,CAAAA,CAAAA,GAAcD,EAAcvD,CAAQ,CAAA,OAAA,CAAA,CACzCsD,EAAY,IACLP,CAAAA,CACX,CACJ,CACJ","file":"index.mjs","sourcesContent":["export const __FastEvent__ = Symbol.for(\"__FastEvent__\");\nexport const __FastEventScope__ = Symbol.for(\"__FastEventScope__\");\nexport class FastEventError extends Error {\n    constructor(message?: string) {\n        super(message);\n    }\n}\n\nexport class TimeoutError extends FastEventError {}\n// 当Scope没有绑定到了Emitter时提示这个错误\nexport class UnboundError extends FastEventError {}\nexport class AbortError extends FastEventError {}\nexport class CancelError extends FastEventError {}\nexport class QueueOverflowError extends FastEventError {}\n","export function isFunction(fn: any): fn is Function {\n    return fn && typeof (fn) == \"function\"\n}","import { QueueOverflowError } from \"../consts\";\nimport { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerPipe } from \"./types\";\n\nexport interface FastEventListenerDecorators {\n    queue: string;\n}\nexport type FastQueuePriority = \"none\";\n\nexport type FastQueueOverflows =\n    | \"drop\" // 当缓冲区满时,丢弃新消息\n    | \"expand\" // 当缓冲区满时,扩展缓冲区，每次扩展size，直到缓冲区大小达到maxSize\n    | \"slide\" // 当缓冲区满时,将缓冲区中的消息向前移动,丢弃旧的消息\n    | \"throw\"; // 当缓冲区满时,抛出异常\n\nexport type QueueListenerPipeOptions = {\n    size?: number; // 缓冲区默认大小\n    maxExpandSize?: number; //  缓冲区扩展到到多大时不再扩展\n    expandOverflow?: Omit<FastQueueOverflows, \"expand\">;\n    overflow?: FastQueueOverflows;\n    // =0不启用此机制，当消息在队列中的时间到达lifetime（ms）后，自动丢弃\n    lifetime?: number;\n    // 当新消息到达时触发此回调，可以用来处理新消息，转让默认是采用push操作\n    onPush?: (\n        newMessage: TypedFastEventMessage,\n        messages: [TypedFastEventMessage, number][],\n    ) => void;\n    // 当消息被弹出时触发此回调，可以在此消息队列进行排序等操作\n    // hasNew: 自上次pop弹出消息后，是否有新的消息入列\n    onPop?: (\n        messages: [TypedFastEventMessage, number][],\n        hasNew: boolean,\n    ) => [TypedFastEventMessage, number] | undefined;\n    // 当消息被丢弃时触发此回调\n    onDrop?: (message: TypedFastEventMessage) => void;\n};\n\nexport const queue = (options?: QueueListenerPipeOptions): FastListenerPipe => {\n    const { lifetime, size, overflow, maxExpandSize, expandOverflow, onPush, onDrop, onPop } =\n        Object.assign(\n            {\n                size: 10,\n                maxExpandSize: 100,\n                overflow: \"expand\",\n                expandOverflow: \"slide\",\n                lifetime: 0,\n            },\n            options,\n        );\n\n    let buffer: [TypedFastEventMessage, number][] = [];\n    let currentSize = size; // 当前缓冲区大小\n    let isHandling = false; // 是否正在处理缓冲区中的消息\n    let hasNewMessage: boolean = false;\n\n    const pushMessage = (message: TypedFastEventMessage) => {\n        if (isFunction(onPush)) {\n            onPush(message, buffer);\n        } else {\n            buffer.push(lifetime > 0 ? [message, Date.now()] : [message, 0]);\n        }\n    };\n\n    const handleOverflow = (message: TypedFastEventMessage): boolean => {\n        // 如果已达到最大大小且当前策略为expand，使用expandOverflow策略\n        const strategy =\n            buffer.length >= maxExpandSize && overflow === \"expand\" ? expandOverflow : overflow;\n        switch (strategy) {\n            case \"drop\":\n                if (isFunction(onDrop)) onDrop(message);\n                return false;\n            case \"expand\":\n                currentSize = Math.min(currentSize + size, maxExpandSize);\n                pushMessage(message);\n                return true;\n            case \"slide\":\n                const msg = buffer.shift(); // 移除最旧的消息\n                if (isFunction(onDrop) && msg) onDrop(msg[0]);\n                pushMessage(message);\n                return true;\n            case \"throw\":\n                if (isFunction(onDrop)) onDrop(message);\n                throw new QueueOverflowError();\n            default:\n                return false;\n        }\n    };\n    return (listener: TypedFastEventListener): TypedFastEventListener => {\n        return async function (message: TypedFastEventMessage<any>, args: FastEventListenerArgs) {\n            hasNewMessage = true;\n            if (isHandling) {\n                // 如果正在处理消息，尝试将新消息添加到缓冲区\n                if (buffer.length < currentSize) {\n                    pushMessage(message);\n                } else {\n                    handleOverflow(message);\n                }\n                return;\n            }\n            // 如果没有正在处理的消息，先处理当前消息\n            isHandling = true;\n            try {\n                await listener.call(this, message, args);\n                // 处理缓冲区中的消息\n                while (buffer.length > 0) {\n                    let nextMessage, enterTime;\n                    // 从队列中弹出消息进行处理\n                    if (hasNewMessage && isFunction(onPop)) {\n                        [nextMessage, enterTime] = onPop(buffer, hasNewMessage) || [undefined, 0];\n                        hasNewMessage = false;\n                    } else {\n                        [nextMessage, enterTime] = buffer.shift() || [undefined, 0];\n                    }\n                    if (nextMessage) {\n                        // 如果消息在缓冲区中停留的时间超过lifetime，丢弃该消息\n                        if (lifetime > 0 && Date.now() - enterTime > lifetime) {\n                            if (isFunction(onDrop)) onDrop(nextMessage);\n                            continue;\n                        }\n                        await listener.call(this, nextMessage, args);\n                    }\n                }\n            } finally {\n                isHandling = false;\n            }\n        };\n    };\n};\n\nexport const dropping = (size: number = 10) => queue({ size, overflow: \"drop\" });\nexport const sliding = (size: number = 10) => queue({ size, overflow: \"slide\" });\nexport const expanding = (options?: Omit<QueueListenerPipeOptions, \"overflow\">) =>\n    queue(\n        Object.assign({}, options, { overflow: \"expand\" as QueueListenerPipeOptions[\"overflow\"] }),\n    );\n","export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerPipe } from \"./types\";\nimport { delay } from \"../utils/delay\";\n\nexport interface RetryListenerPipeOptions {\n    retries?: number; // 重试次数\n    interval?: number | ((retryCount: number) => number); // 重试间隔，默认1000ms\n    drop?: (message: TypedFastEventMessage, error: Error) => void; // 所有重试失败后的回调\n}\n\n/**\n * 创建一个重试管道，在监听器执行失败时自动重试\n * @param retries 最大重试次数\n * @param options 配置选项\n * @returns FastListenerPipe\n */\n\nexport function retry(options?: RetryListenerPipeOptions): FastListenerPipe {\n    const { retries, interval, drop } = Object.assign(\n        {\n            retries: 1,\n            interval: 100,\n        },\n        options,\n    );\n\n    return (listener: TypedFastEventListener): TypedFastEventListener => {\n        return async function (message: TypedFastEventMessage, args: FastEventListenerArgs) {\n            let retryCount = 0;\n            let lastError: Error | undefined;\n            while (retryCount <= retries) {\n                try {\n                    return await listener.call(this, message, args);\n                } catch (error) {\n                    lastError = error as Error;\n                    retryCount++;\n                    if (retryCount <= retries) {\n                        await delay(isFunction(interval) ? interval(retryCount) : interval);\n                    } else {\n                        // 所有重试失败，调用drop回调\n                        if (isFunction(drop)) {\n                            drop(message, lastError);\n                        }\n                        throw lastError;\n                    }\n                }\n            }\n        };\n    };\n}\n","import { TimeoutError } from \"../consts\";\nimport { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { FastListenerPipe } from \"./types\";\n\n/**\n * 创建一个超时装饰器，限制监听器函数的执行时间\n * @param ms 超时时间（毫秒）\n * @param defaultValue 可选的默认返回值，如果提供则超时时返回此值，否则抛出TimeoutError\n * @returns 装饰器函数\n */\nexport const timeout = <T = any>(ms: number, defaultValue?: T): FastListenerPipe => {\n    return (listener: TypedFastEventListener): TypedFastEventListener => {\n        return async function (message: TypedFastEventMessage, args: FastEventListenerArgs) {\n            let timeoutId: any;\n\n            const timeoutPromise = new Promise((resolve, reject) => {\n                timeoutId = setTimeout(() => {\n                    if (defaultValue !== undefined) {\n                        resolve(defaultValue);\n                    } else {\n                        reject(new TimeoutError());\n                    }\n                }, ms);\n            });\n\n            const listenerPromise = Promise.resolve(listener.call(this, message, args));\n\n            try {\n                return await Promise.race([listenerPromise, timeoutPromise]);\n            } finally {\n                clearTimeout(timeoutId!);\n            }\n        };\n    };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { FastListenerPipe } from \"./types\";\n\nexport interface DebounceOptions {\n    /**\n     * 当消息被丢弃时的回调函数\n     */\n    drop?: (message: TypedFastEventMessage) => void;\n}\n\n/**\n * 创建一个防抖动装饰器，限制监听器函数的执行频率\n * @param ms 防抖动时间（毫秒）\n * @param options 可选的配置项\n * @returns 装饰器函数\n */\nexport const debounce = (ms: number, options?: DebounceOptions): FastListenerPipe => {\n    return (listener: TypedFastEventListener): TypedFastEventListener => {\n        let isBlocked = false;\n        let timeoutId: any = null;\n\n        return async function (message: TypedFastEventMessage, args: FastEventListenerArgs) {\n            // 如果当前处于防抖动时间内，丢弃消息\n            if (isBlocked) {\n                if (options?.drop) {\n                    options.drop(message);\n                }\n                return;\n            }\n\n            try {\n                // 设置阻塞标志\n                isBlocked = true;\n\n                // 执行监听器\n                const result = await listener.call(this, message, args);\n\n                // 设置定时器，在ms毫秒后解除阻塞\n                timeoutId = setTimeout(() => {\n                    isBlocked = false;\n                    timeoutId = null;\n                }, ms);\n\n                return result;\n            } catch (error) {\n                isBlocked = false;\n                if (timeoutId) {\n                    clearTimeout(timeoutId);\n                    timeoutId = null;\n                }\n                throw error;\n            }\n        };\n    };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { FastListenerPipe } from \"./types\";\n\nexport interface ThrottleOptions {\n    /**\n     * 当消息被丢弃时的回调函数\n     */\n    drop?: (message: TypedFastEventMessage) => void;\n}\n\n/**\n * 创建一个节流装饰器，限制监听器函数的执行频率\n * @param interval 节流时间间隔（毫秒）\n * @param options 可选的配置项\n * @returns 装饰器函数\n */\nexport const throttle = (interval: number, options?: ThrottleOptions): FastListenerPipe => {\n    return (listener: TypedFastEventListener): TypedFastEventListener => {\n        let lastExecutionTime = 0;\n\n        return async function (message: TypedFastEventMessage, args: FastEventListenerArgs) {\n            const now = Date.now();\n            const timeSinceLastExecution = now - lastExecutionTime;\n\n            // 如果在节流时间内，则丢弃消息\n            if (timeSinceLastExecution < interval) {\n                if (options?.drop) {\n                    options.drop(message);\n                }\n                return;\n            }\n\n            // 更新最后执行时间并执行监听器\n            lastExecutionTime = now;\n            return await listener.call(this, message, args);\n        };\n    };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport type { FastListenerPipe } from \"./types\";\n\n/**\n * 创建一个memorize pipe，用于缓存上一次的返回值\n * @param predicate 可选的判断函数，用于决定是否使用缓存\n * @returns FastListenerPipe\n */\nexport function memorize(\n    predicate?: (\n        message: TypedFastEventMessage,\n        args: FastEventListenerArgs,\n    ) => boolean | Promise<boolean>,\n): FastListenerPipe {\n    let lastResult: any = undefined;\n    let hasResult = false;\n    let lastPayload: any = undefined;\n    let hasPredicate = typeof predicate === \"function\";\n    return function (listener: TypedFastEventListener): TypedFastEventListener {\n        return async function (message: TypedFastEventMessage, args: FastEventListenerArgs) {\n            if (hasResult) {\n                // 如果有自定义判断函数，使用它来决定是否使用缓存\n                if (typeof predicate === \"function\") {\n                    if (await predicate(message, args)) {\n                        return lastResult;\n                    }\n                } else {\n                    // 默认根据message.payload判断\n                    if (message.payload === lastPayload) {\n                        return lastResult;\n                    }\n                }\n            }\n            // 执行原始监听器并缓存结果\n            const result = await listener.call(this, message, args);\n            lastResult = result;\n            if (!hasPredicate) lastPayload = message.payload;\n            hasResult = true;\n            return result;\n        };\n    };\n}\n"]}