{"version":3,"file":"statemanjs.mjs","sources":["../../src/statemanjs/service/debugService.ts","../../src/statemanjs/shared/utility.ts","../../src/statemanjs/shared/computedScheduler.ts","../../src/statemanjs/shared/updateGeneration.ts","../../src/statemanjs/service/statemanjsBaseService.ts","../../src/statemanjs/service/statemanjsService.ts","../../src/statemanjs/service/transactionService.ts","../../src/statemanjs/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nimport { DebugAPI } from \"../api/debugAPI\";\nimport { TransactionAPI } from \"../api/transactionAPI\";\n\nexport class DebugService<T> implements DebugAPI<T> {\n    constructor(transactionService: TransactionAPI<T>) {\n        this.transactionService = transactionService;\n    }\n\n    transactionService: TransactionAPI<T>;\n}\n","/* istanbul ignore file */\n/**\n * Makes the error message clear and beautiful.\n * @param description Description of where the error occurred\n * (for example - 'an error occurred while setting the new state').\n * @param error Error object.\n * @returns Nice error message 🌸.\n */\nfunction formatError(description: string, error: unknown): string {\n    return `${description}: ${getErrorMessage(error)}`;\n}\n\nfunction getErrorMessage(error: unknown): string {\n    return (error as Error).message;\n}\n\nfunction deepClone<T>(obj: T): T {\n    if (typeof structuredClone !== \"undefined\") {\n        return structuredClone(obj);\n    }\n    // Fallback for older environments\n    return JSON.parse(JSON.stringify(obj));\n}\n\nexport { formatError, getErrorMessage, deepClone };\n","type FlushCallback = () => void;\n\nconst pending = new Set<FlushCallback>();\nlet isFlushing = false;\n\nexport function scheduleComputedRecompute(callback: FlushCallback): void {\n    pending.add(callback);\n}\n\nexport function flushScheduledComputed(): void {\n    if (isFlushing) {\n        return;\n    }\n\n    isFlushing = true;\n    try {\n        while (pending.size > 0) {\n            const callbacks = Array.from(pending);\n            pending.clear();\n\n            for (const callback of callbacks) {\n                callback();\n            }\n        }\n    } finally {\n        isFlushing = false;\n    }\n}\n","/**\n * Global update generation counter for batching computed state updates.\n * This prevents diamond problem where a computed state might be recalculated\n * multiple times in a single synchronous update cycle.\n */\nexport class UpdateGeneration {\n    static #generation = 0;\n\n    static get current(): number {\n        return this.#generation;\n    }\n\n    static increment(): number {\n        return ++this.#generation;\n    }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { StatemanjsBaseAPI } from \"../api/statemanjsBaseAPI\";\nimport {\n    StatemanjsStateWrapper,\n    ActionKind,\n    Subscriber,\n    UpdateCb,\n    SubscriptionCb,\n    SubscriptionOptions,\n    UnsubscribeCb,\n    CustomComparator,\n    DefaultComparator,\n    BaseSetOptions,\n} from \"../shared/entities\";\nimport { deepClone, formatError, getErrorMessage } from \"../shared/utility\";\nimport { flushScheduledComputed } from \"../shared/computedScheduler\";\nimport { UpdateGeneration } from \"../shared/updateGeneration\";\n\nexport class StatemanjsBaseService<T> implements StatemanjsBaseAPI<T> {\n    /**\n     * The proxied state object, wrapped to intercept access and modifications.\n     * This is the core state being managed by Statemanjs.\n     */\n    #proxiedState: StatemanjsStateWrapper<T>;\n\n    /**\n     * A map of active subscribers identified by a unique symbol.\n     */\n    #activeSubscribers: Record<symbol, Subscriber> = {};\n\n    /**\n     * FinalizationRegistry for automatic cleanup of garbage-collected subscribers.\n     * When a subscriber callback is garbage collected, this automatically removes it.\n     */\n    #subscriberRegistry?: FinalizationRegistry<symbol>;\n\n    /**\n     * Map of subscriber IDs to their callback functions for FinalizationRegistry.\n     */\n    #subscriberCallbacks: Map<symbol, Function> = new Map();\n\n    /**\n     * Indicates if properties should be checked for changes.\n     */\n    #isNeedToCheckProperties = false;\n\n    /**\n     * The kind of action currently being performed (e.g., 'set' or 'update').\n     */\n    #actionKind: ActionKind = \"none\";\n\n    /**\n     * Controls whether access to the state is allowed. Prevents unauthorized access.\n     */\n    #isAccessToStateAllowed = false;\n\n    /**\n     * Controls whether the state can be unwrapped, which might bypass proxies.\n     */\n    #isUnwrapAllowed = false;\n\n    /**\n     * Flag indicating whether any part of the state was changed during the last operation.\n     */\n    #wasChanged = false;\n\n    /**\n     * Stores the path to the property that was changed in the state.\n     */\n    #pathToChangedProperty: Set<string> = new Set();\n\n    /**\n     * If set to true, skips state comparison during updates.\n     */\n    #skipComparison = false;\n\n    /**\n     * Cache for storing previously created proxies for properties in the state.\n     * Uses WeakMap for automatic garbage collection when objects are no longer referenced.\n     */\n    #proxyCache: WeakMap<object, any>;\n\n    /**\n     * Flag indicating if the state is a primitive type (fast-path optimization).\n     */\n    #isPrimitiveState = false;\n\n    /**\n     * Direct storage for primitive values (bypasses Proxy).\n     */\n    #primitiveValue?: T;\n\n    /**\n     * Precompiled comparator function (avoids switch in hot path).\n     */\n    #compareFn: (a: any, b: any) => boolean;\n\n    /**\n     * Flag indicating if batching is enabled for subscriber notifications.\n     */\n    #batchingEnabled = false;\n\n    /**\n     * Flag indicating if a notification is pending in the microtask queue.\n     */\n    #pendingNotification = false;\n\n    /**\n     * Set of method names considered dangerous, which should be guarded during state modifications.\n     */\n    readonly #dangerMethods: Set<string> = new Set([\n        \"clear\", // (Map; Set)\n        \"delete\", // (Map; WeakSet; Set)\n        \"set\", // (Map)\n        \"add\", // (WeakSet; Set)\n        \"fill\", // (Array; TypedArray)\n        \"reverse\", // (Array; TypedArray)\n        \"sort\", // (Array; TypedArray)\n        \"unscopables\", // (Symbol)\n        \"pop\", // (Array)\n        \"push\", // (Array)\n        \"shift\", // (Array)\n        \"unshift\", // (Array)\n        \"splice\", // (Array)\n    ]);\n\n    /**\n     * Set of array methods that return elements which need to be proxied.\n     * These are non-mutating methods that access array elements.\n     */\n    readonly #arrayAccessorMethods: Set<string> = new Set([\n        \"find\", // Returns single element\n        \"filter\", // Returns array of elements\n        \"map\", // Returns array of transformed elements\n        \"flatMap\", // Returns flattened array\n        \"slice\", // Returns array slice\n        \"concat\", // Returns concatenated array\n        \"reduce\", // Can return elements during iteration\n        \"reduceRight\", // Can return elements during iteration\n        \"at\", // Returns single element by index\n    ]);\n\n    readonly customComparator: CustomComparator<T> | undefined;\n\n    readonly defaultComparator: DefaultComparator;\n\n    constructor(\n        element: T,\n        options: {\n            customComparator?: CustomComparator<T>;\n            defaultComparator?: DefaultComparator;\n            batch?: boolean;\n        },\n    ) {\n        // Bindings\n        this.get = this.get.bind(this);\n        this.set = this.set.bind(this);\n        this.update = this.update.bind(this);\n        this.subscribe = this.subscribe.bind(this);\n        this.unsubscribeById = this.unsubscribeById.bind(this);\n        this.unsubscribeByIds = this.unsubscribeByIds.bind(this);\n        this.getActiveSubscribersCount =\n            this.getActiveSubscribersCount.bind(this);\n        this.unsubscribeAll = this.unsubscribeAll.bind(this);\n        this.unwrap = this.unwrap.bind(this);\n        this.getPathToChangedProperty =\n            this.getPathToChangedProperty.bind(this);\n\n        // Initialize custom comparator\n        this.customComparator = options.customComparator;\n\n        // Initialize default comparator\n        this.defaultComparator = options.defaultComparator || \"ref\";\n\n        // Initialize batching mode\n        this.#batchingEnabled = options.batch || false;\n\n        // Initialize FinalizationRegistry for automatic subscriber cleanup\n        if (typeof FinalizationRegistry !== \"undefined\") {\n            this.#subscriberRegistry = new FinalizationRegistry(\n                (subscriberId: symbol) => {\n                    // Automatically remove subscriber when callback is garbage collected\n                    if (this.#activeSubscribers[subscriberId]) {\n                        delete this.#activeSubscribers[subscriberId];\n                    }\n                },\n            );\n        }\n\n        // Precompile comparator function (avoid switch in hot path)\n        switch (this.defaultComparator) {\n            case \"ref\":\n                this.#compareFn = (a: any, b: any) => a !== b;\n                break;\n            case \"shallow\":\n                this.#compareFn = (a: any, b: any) =>\n                    !this.#isEqualShallow(a, b);\n                break;\n            case \"custom\":\n                if (!this.customComparator) {\n                    throw new Error(\"Custom comparator is not provided.\");\n                }\n                this.#compareFn = (a: any, b: any) =>\n                    !this.customComparator!(a, b);\n                break;\n            case \"none\":\n            default:\n                this.#compareFn = () => true;\n                break;\n        }\n\n        // Check if state is primitive (fast-path optimization)\n        if (this.#isPrimitive(element)) {\n            this.#isPrimitiveState = true;\n            this.#primitiveValue = element;\n            // Skip Proxy creation for primitives\n            this.#proxyCache = new WeakMap();\n            this.#proxiedState = {} as any; // Dummy value, never accessed\n            return;\n        }\n\n        // Initialize cache for proxies (WeakMap for automatic GC)\n        this.#proxyCache = new WeakMap();\n\n        // Wrap and proxy the state (start with empty path string)\n        this.#proxiedState = new Proxy<StatemanjsStateWrapper<T>>(\n            { __STATEMANJS_STATE__: element } as StatemanjsStateWrapper<T>,\n            this.#createHandler(\"\"),\n        );\n    }\n\n    #isPrimitive(value: unknown): boolean {\n        return (\n            value === null ||\n            typeof value === \"undefined\" ||\n            typeof value === \"boolean\" ||\n            typeof value === \"number\" ||\n            typeof value === \"string\" ||\n            typeof value === \"symbol\" ||\n            typeof value === \"bigint\"\n        );\n    }\n\n    #addPathToChangedProperty(path: string): void {\n        this.#pathToChangedProperty.add(path);\n    }\n\n    #resetPathToChangedProperty(): void {\n        this.#pathToChangedProperty = new Set();\n    }\n\n    /**\n     * Converts a property key to string, handling symbols correctly.\n     *\n     * @param {string | symbol} prop - The property key.\n     * @returns {string} The stringified property.\n     */\n    #propToString(prop: string | symbol): string {\n        return typeof prop === \"symbol\" ? prop.toString() : String(prop);\n    }\n\n    /**\n     * Checks the access kind (function, object, etc.) and returns appropriate proxies or values.\n     * Optimized with fast-path for primitives (single typeof check).\n     * Uses string path representation - faster than arrays!\n     * Skips \"__STATEMANJS_STATE__\" wrapper in path for zero-overhead tracking!\n     *\n     * @param {any} target - The target object.\n     * @param {any} prop - The property to access.\n     * @param {string} path - The dot-separated path to the property.\n     * @returns {any} The accessed value or a proxy of it.\n     */\n    #checkAccessKind(target: any, prop: any, path: string): any {\n        const targetProp = target[prop];\n        const propType = typeof targetProp;\n\n        // FAST-PATH: Primitives (99% cases on flat objects) - only ONE typeof check!\n        if (propType !== \"object\" && propType !== \"function\") {\n            return targetProp;\n        }\n\n        // null is typeof \"object\", so check it separately\n        if (targetProp === null) {\n            return targetProp;\n        }\n\n        const isFunc = propType === \"function\";\n\n        // Skip wrapper property in path to avoid prefix removal overhead!\n        // This way paths are clean from the start: \"a.b.c\" instead of \"__STATEMANJS_STATE__.a.b.c\"\n        const propStr = this.#propToString(prop);\n        const newPath =\n            propStr === \"__STATEMANJS_STATE__\"\n                ? path // Don't change path for wrapper property\n                : path\n                  ? `${path}.${propStr}`\n                  : propStr; // Normal concatenation for real properties\n\n        if (isFunc) {\n            if (\n                this.#dangerMethods.has(prop) &&\n                !this.#isAccessToStateAllowed\n            ) {\n                throw new Error(\n                    \"Access is denied. Use 'update' method to do this.\",\n                );\n            }\n\n            if (this.#dangerMethods.has(prop)) {\n                this.#wasChanged = true;\n            }\n\n            // Handle array accessor methods (find, filter, map, etc.)\n            // These methods return elements that need to be proxied\n            if (Array.isArray(target) && this.#arrayAccessorMethods.has(prop)) {\n                const originalMethod = targetProp.bind(target);\n                return (...args: any[]) => {\n                    const result = originalMethod(...args);\n\n                    // Wrap result(s) in proxy if needed\n                    if (result === null || result === undefined) {\n                        return result;\n                    }\n\n                    // For methods that return arrays (filter, map, slice, etc.)\n                    if (Array.isArray(result)) {\n                        return result.map((item: any) => {\n                            if (\n                                item &&\n                                typeof item === \"object\" &&\n                                !this.#isPrimitive(item)\n                            ) {\n                                // Check if this item is from our proxied array\n                                if (!this.#proxyCache.has(item)) {\n                                    const itemProxy = new Proxy(\n                                        item,\n                                        this.#createHandler(newPath),\n                                    );\n                                    this.#proxyCache.set(item, itemProxy);\n                                }\n                                return this.#proxyCache.get(item);\n                            }\n                            return item;\n                        });\n                    }\n\n                    // For methods that return single element (find, at, reduce)\n                    if (\n                        result &&\n                        typeof result === \"object\" &&\n                        !this.#isPrimitive(result)\n                    ) {\n                        if (!this.#proxyCache.has(result)) {\n                            const resultProxy = new Proxy(\n                                result,\n                                this.#createHandler(newPath),\n                            );\n                            this.#proxyCache.set(result, resultProxy);\n                        }\n                        return this.#proxyCache.get(result);\n                    }\n\n                    return result;\n                };\n            }\n\n            // Bind function directly without extra #saveSlots call\n            const boundFunc = targetProp.bind(target);\n            return new Proxy(boundFunc, this.#createHandler(newPath));\n        }\n\n        // Here we know it's an object (not null, not primitive, not function)\n        if (!this.#isUnwrapAllowed) {\n            // Use the object itself as WeakMap key (automatic GC)\n            if (!this.#proxyCache.has(targetProp)) {\n                const newProxy = new Proxy(\n                    targetProp,\n                    this.#createHandler(newPath),\n                );\n                this.#proxyCache.set(targetProp, newProxy);\n            }\n\n            return this.#proxyCache.get(targetProp);\n        }\n\n        // For objects in unwrap mode, return directly\n        return targetProp;\n    }\n\n    #isEqualShallow(a: any, b: any): boolean {\n        if (this.#isPrimitive(a) || this.#isPrimitive(b)) {\n            return a === b;\n        }\n\n        if (Object.keys(a).length !== Object.keys(b).length) {\n            return false;\n        }\n\n        for (const key in a) {\n            if (a[key] !== b[key]) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    /**\n     * Updates a property in the state and marks the state as changed.\n     * No prefix removal needed! Path is already clean thanks to #checkAccessKind.\n     *\n     * @param {any} target - The target object.\n     * @param {any} prop - The property to update.\n     * @param {any} val - The new value to set.\n     * @param {string} newPath - The dot-separated path to the property being updated.\n     */\n    #updateProperty(target: any, prop: any, val: any, newPath: string): void {\n        target[prop] = val;\n        this.#wasChanged = true;\n\n        if (this.#isNeedToCheckProperties && this.#actionKind === \"update\") {\n            // Path is already clean (e.g., \"a\", \"a.b.c\") - no prefix removal needed!\n            if (newPath.length > 0) {\n                this.#addPathToChangedProperty(newPath);\n            }\n        }\n    }\n\n    /**\n     * Determines whether a property should be updated based on the comparator.\n     *\n     * @param {any} target - The target object.\n     * @param {any} prop - The property to check.\n     * @param {any} val - The new value to set.\n     * @returns {boolean} True if the property should be updated, otherwise false.\n     */\n    #isUpdateNeeded(target: any, prop: any, val: any): boolean {\n        return this.#compareFn(target[prop], val);\n    }\n\n    #createHandler(path: string): ProxyHandler<StatemanjsStateWrapper<T>> {\n        return {\n            get: (target: any, prop: any): any => {\n                return this.#checkAccessKind(target, prop, path);\n            },\n            set: (target: any, prop: any, val: any): boolean => {\n                if (!this.#isAccessToStateAllowed) {\n                    throw new Error(\"Access is denied.\");\n                }\n\n                // Skip wrapper property in path (same logic as #checkAccessKind)\n                const propStr = this.#propToString(prop);\n                const newPath =\n                    propStr === \"__STATEMANJS_STATE__\"\n                        ? path // Don't change path for wrapper property\n                        : path\n                          ? `${path}.${propStr}`\n                          : propStr;\n\n                if (\n                    this.#skipComparison ||\n                    this.#isUpdateNeeded(target, prop, val)\n                ) {\n                    this.#updateProperty(target, prop, val, newPath);\n                }\n\n                return true;\n            },\n            defineProperty: (): boolean => {\n                throw new Error(\"Cannot define property.\");\n            },\n            deleteProperty: (target: any, prop: string | symbol): boolean => {\n                if (!this.#isAccessToStateAllowed) {\n                    throw new Error(\n                        'Cannot delete property directly. Use \"update\" instead.',\n                    );\n                }\n\n                if (!(prop in target)) {\n                    console.warn(`property not found: ${String(prop)}`);\n                    return false;\n                }\n\n                // Skip wrapper property in path (same logic as #checkAccessKind)\n                const propStr = this.#propToString(prop);\n                const newPath =\n                    propStr === \"__STATEMANJS_STATE__\"\n                        ? path // Don't change path for wrapper property\n                        : path\n                          ? `${path}.${propStr}`\n                          : propStr;\n                delete target[prop as string];\n                return true;\n            },\n        };\n    }\n\n    #addSubscriber(subscriber: Subscriber): void {\n        this.#activeSubscribers[subscriber.subId] = subscriber;\n    }\n\n    #generateSubscriberId(): symbol {\n        const id = Symbol();\n\n        return id;\n    }\n\n    #runActiveSubscribersCb(skipGenerationIncrement = false): void {\n        // Increment update generation before notifying subscribers\n        // This allows computed states to track if they've already processed this update\n        // Skip increment if requested (e.g., from computed states to avoid generation interference)\n        if (!skipGenerationIncrement) {\n            UpdateGeneration.increment();\n        }\n\n        if (!this.#batchingEnabled) {\n            // Synchronous notification (default behavior)\n            this.#notifySubscribersSync();\n            return;\n        }\n\n        // Batched notification via microtask queue\n        if (this.#pendingNotification) {\n            // Already scheduled, skip\n            return;\n        }\n\n        this.#pendingNotification = true;\n        queueMicrotask(() => {\n            this.#notifySubscribersSync();\n            this.#pendingNotification = false;\n        });\n    }\n\n    #notifySubscribersSync(): void {\n        const activeSubscribers = this.#activeSubscribers;\n        const inactiveSubscribersId: symbol[] = [];\n\n        const keys = Object.getOwnPropertySymbols(activeSubscribers);\n\n        for (const id of keys) {\n            const s = activeSubscribers[id];\n            try {\n                if (!s.notifyCondition || s.notifyCondition()) {\n                    s.subCb();\n                }\n            } catch (error) {\n                inactiveSubscribersId.push(id);\n                console.info(\n                    `One of your subscribers marked as inactive and was removed. Error message - ${getErrorMessage(\n                        error,\n                    )}`,\n                );\n            }\n        }\n\n        if (inactiveSubscribersId.length > 0) {\n            this.unsubscribeByIds(inactiveSubscribersId);\n        }\n\n        flushScheduledComputed();\n    }\n\n    #isObject(entity: unknown): boolean {\n        return entity !== null && typeof entity === \"object\";\n    }\n\n    /**\n     * Determines if any of the specified properties are part of any path in the state.\n     *\n     * @param {string[]} properties - The properties to check.\n     * @param {string[]} paths - The paths to compare against.\n     * @returns {boolean} True if any property is part of any path, otherwise false.\n     */\n    #isPropertyInPath(properties: string[], paths: string[]): boolean {\n        const propertiesMap = new Map(\n            properties.map((prop) => [prop, prop.length]),\n        );\n\n        // the root has been changed\n        if (paths.length === 0) {\n            return true;\n        }\n\n        return paths.some((path) => {\n            for (const [prop, length] of propertiesMap) {\n                if (path.slice(0, length) === prop) {\n                    return true;\n                }\n            }\n            return false;\n        });\n    }\n\n    /**\n     * Safely modifies the state within a controlled environment, ensuring access permissions.\n     *\n     * @param {() => void} modifier - The function that modifies the state.\n     * @param {ActionKind} actionKind - The kind of action being performed.\n     * @returns {boolean} True if the state was modified, otherwise false.\n     */\n    #performSafeModification(\n        modifier: () => void,\n        actionKind: ActionKind,\n    ): boolean {\n        this.#isAccessToStateAllowed = true;\n        this.#actionKind = actionKind;\n        modifier();\n        this.#actionKind = \"none\";\n        this.#isAccessToStateAllowed = false;\n\n        return this.#wasChanged;\n    }\n\n    public get(): T {\n        if (this.#isPrimitiveState) {\n            return this.#primitiveValue!;\n        }\n        return this.#proxiedState.__STATEMANJS_STATE__;\n    }\n\n    public set(newState: T, options: BaseSetOptions<T>): boolean {\n        // ULTRA-FAST path for primitives\n        if (this.#isPrimitiveState) {\n            // Inline comparison (avoid function call)\n            if (!options.skipComparison && this.#primitiveValue === newState) {\n                return false; // No change\n            }\n            this.#primitiveValue = newState;\n\n            // Inline afterUpdate check (avoid optional chaining overhead)\n            if (options.afterUpdate) {\n                options.afterUpdate();\n            }\n\n            // Inline subscriber notification (skip intermediate method calls)\n            // For primitives: no batching, no property tracking, no error handling\n            if (!options.skipGenerationIncrement) {\n                UpdateGeneration.increment();\n            }\n\n            const subscribers = this.#activeSubscribers;\n            const keys = Object.getOwnPropertySymbols(subscribers);\n\n            // HOT PATH: No try-catch, no condition checks for simple counters/flags\n            for (const id of keys) {\n                const s = subscribers[id];\n                // Most primitives don't have notifyCondition (simple counter/flag)\n                if (!s.notifyCondition || s.notifyCondition()) {\n                    s.subCb();\n                }\n            }\n\n            flushScheduledComputed();\n\n            return true;\n        }\n\n        // Standard path for objects (with error handling)\n        try {\n            // Standard path for objects\n            const wasChanged = this.#performSafeModification((): void => {\n                this.#skipComparison = options.skipComparison || false;\n\n                this.#proxiedState.__STATEMANJS_STATE__ = newState;\n            }, \"set\");\n\n            if (!wasChanged) {\n                return false;\n            }\n\n            options.afterUpdate();\n\n            this.#wasChanged = false;\n            this.#runActiveSubscribersCb(options.skipGenerationIncrement);\n            this.#resetPathToChangedProperty();\n            this.#actionKind = \"none\";\n\n            return true;\n        } catch (error) {\n            throw new Error(\n                formatError(\n                    \"An error occurred while setting the new state\",\n                    error,\n                ),\n            );\n        }\n    }\n\n    public update(updateCb: UpdateCb<T>, options: BaseSetOptions<T>): boolean {\n        try {\n            // Fast-path for primitives (bypass Proxy)\n            if (this.#isPrimitiveState) {\n                throw new Error(\n                    \"Cannot use 'update' method on primitive state. Use 'set' instead.\",\n                );\n            }\n\n            // Standard path for objects\n            const wasChanged = this.#performSafeModification((): void => {\n                this.#skipComparison = options.skipComparison || false;\n\n                updateCb(this.get());\n            }, \"update\");\n\n            if (!wasChanged) {\n                return false;\n            }\n\n            options.afterUpdate();\n\n            this.#wasChanged = false;\n            this.#runActiveSubscribersCb(options.skipGenerationIncrement);\n            this.#resetPathToChangedProperty();\n            this.#actionKind = \"none\";\n\n            return true;\n        } catch (error) {\n            throw new Error(\n                formatError(\n                    \"An error occurred while updating the state\",\n                    error,\n                ),\n            );\n        }\n    }\n\n    public subscribe(\n        subscriptionCb: SubscriptionCb<T>,\n        subscriptionOptions: SubscriptionOptions<T> = {},\n    ): UnsubscribeCb {\n        const subscriberId = this.#generateSubscriberId();\n\n        const notifyConditionCb = subscriptionOptions.notifyCondition;\n        const hasProperties =\n            subscriptionOptions.properties &&\n            subscriptionOptions.properties.length > 0;\n\n        if (hasProperties) {\n            this.#isNeedToCheckProperties = true;\n        }\n\n        this.#addSubscriber({\n            subId: subscriberId,\n            subCb: () => subscriptionCb(this.get()),\n            notifyCondition: (): boolean => {\n                if (hasProperties) {\n                    if (!this.#isObject(this.unwrap())) {\n                        throw new Error(\n                            \"You can't add properties to track if your state is not an object\",\n                        );\n                    }\n\n                    try {\n                        return this.#isPropertyInPath(\n                            subscriptionOptions.properties as string[],\n                            this.getPathToChangedProperty(),\n                        );\n                    } catch (error) {\n                        throw new Error(\n                            formatError(\n                                \"An error occurred when accessing a property from the subscriptionOptions list\",\n                                error,\n                            ),\n                        );\n                    }\n                }\n\n                return (\n                    notifyConditionCb === undefined ||\n                    notifyConditionCb(this.get())\n                );\n            },\n            isProtected: subscriptionOptions.protect ?? false,\n        });\n\n        // Register callback in FinalizationRegistry for automatic cleanup\n        if (this.#subscriberRegistry) {\n            this.#subscriberCallbacks.set(subscriberId, subscriptionCb);\n            this.#subscriberRegistry.register(\n                subscriptionCb,\n                subscriberId,\n                subscriptionCb,\n            );\n        }\n\n        return (): void => {\n            if (!hasProperties) {\n                this.#isNeedToCheckProperties = false;\n            }\n\n            this.unsubscribeById(subscriberId);\n        };\n    }\n\n    public unsubscribeById(subscriberId: symbol): void {\n        // Unregister from FinalizationRegistry if exists\n        if (\n            this.#subscriberRegistry &&\n            this.#subscriberCallbacks.has(subscriberId)\n        ) {\n            const callback = this.#subscriberCallbacks.get(subscriberId);\n            this.#subscriberRegistry.unregister(callback!);\n            this.#subscriberCallbacks.delete(subscriberId);\n        }\n\n        delete this.#activeSubscribers[subscriberId];\n    }\n\n    public unsubscribeByIds(subscriberIds: symbol[]): void {\n        subscriberIds.forEach((id) => {\n            this.unsubscribeById(id);\n        });\n    }\n\n    public getActiveSubscribersCount(): number {\n        return Object.getOwnPropertySymbols(this.#activeSubscribers).length;\n    }\n\n    public unsubscribeAll(): void {\n        this.#isNeedToCheckProperties = false;\n\n        const protectedSubscribers: Record<symbol, Subscriber> = {};\n\n        for (const id of Object.getOwnPropertySymbols(\n            this.#activeSubscribers,\n        )) {\n            const subscriber = this.#activeSubscribers[id];\n            if (subscriber.isProtected) {\n                protectedSubscribers[id] = subscriber;\n            }\n        }\n\n        this.#activeSubscribers = protectedSubscribers;\n    }\n\n    public unwrap(): T {\n        if (this.#isPrimitiveState) {\n            return this.#primitiveValue!;\n        }\n\n        this.#isUnwrapAllowed = true;\n        const unwrapped = this.get();\n        this.#isUnwrapAllowed = false;\n\n        return deepClone(unwrapped);\n    }\n\n    public getPathToChangedProperty(): string[] {\n        return Array.from(this.#pathToChangedProperty.values());\n    }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DebugAPI } from \"../api/debugAPI\";\nimport { StatemanjsAPI } from \"../api/statemanjsApi\";\nimport { StatemanjsBaseAPI } from \"../api/statemanjsBaseAPI\";\nimport { StatemanjsComputedAPI } from \"../api/statemanjsComputedAPI\";\nimport {\n    SetOptions,\n    StatemanjsComputedServiceOptions,\n    StatemanjsServiceOptions,\n    SubscriptionCb,\n    SubscriptionOptions,\n    UnsubscribeCb,\n    UpdateCb,\n    UpdateOptions,\n} from \"../shared/entities\";\nimport { StatemanjsBaseService } from \"./statemanjsBaseService\";\nimport { scheduleComputedRecompute } from \"../shared/computedScheduler\";\nimport { formatError } from \"../shared/utility\";\n\nexport class StatemanjsService<E> implements StatemanjsAPI<E> {\n    #statemanjsBaseService: StatemanjsBaseAPI<E>;\n\n    readonly DEBUG: DebugAPI<E> | undefined;\n\n    constructor(element: E, options: StatemanjsServiceOptions<E>) {\n        // Bindings\n        this.set = this.set.bind(this);\n        this.get = this.get.bind(this);\n        this.subscribe = this.subscribe.bind(this);\n        this.unsubscribeAll = this.unsubscribeAll.bind(this);\n        this.getActiveSubscribersCount =\n            this.getActiveSubscribersCount.bind(this);\n        this.update = this.update.bind(this);\n        this.unwrap = this.unwrap.bind(this);\n\n        this.#statemanjsBaseService = new StatemanjsBaseService(element, {\n            customComparator: options.customComparator,\n            defaultComparator: options.defaultComparator,\n            batch: options.batch,\n        });\n        this.DEBUG = options.debugService;\n    }\n\n    /**\n     * Accepts a new state and compares it with the current one.\n     * Nothing will happen if the passed value is equal to the current one.\n     * @param newState New state.\n     * @returns Status of operation.\n     */\n    set(newState: E, options: SetOptions<E> = {}): boolean {\n        try {\n            const wasChanged = this.#statemanjsBaseService.set(newState, {\n                afterUpdate: (): void => {\n                    if (this.DEBUG !== undefined) {\n                        this.DEBUG.transactionService.addTransaction(\n                            this.unwrap(),\n                        );\n                    }\n                },\n                ...options,\n            });\n\n            return wasChanged;\n        } catch (error) {\n            throw new Error(\n                formatError(\n                    \"An error occurred while setting the new state\",\n                    error,\n                ),\n            );\n        }\n    }\n\n    /** Get current state */\n    get(): E {\n        return this.#statemanjsBaseService.get();\n    }\n\n    /**\n     * The method of subscribing to the status change.\n     * Accepts a callback function (subscription callback),\n     * which will be called at each update, and a subscription options object.\n     * In the options, you can specify information about the subscription,\n     * as well as specify the condition under which the subscriber will be notified\n     * and mark the subscriber as protected. All subscribers are unprotected by default.\n     * Protected subscribers can only be unsubscribed using the unsubscribe method returned by this method.\n     * Returns the unsubscribe callback function.\n     *\n     * @param subscriptionCb A function that runs on every update.\n     * @param subscriptionOptions Additional information and notification condition.\n     * @returns Unsubscribe callback function.\n     */\n    subscribe(\n        subscriptionCb: SubscriptionCb<E>,\n        subscriptionOptions: SubscriptionOptions<E> = {},\n    ): UnsubscribeCb {\n        return this.#statemanjsBaseService.subscribe(\n            subscriptionCb,\n            subscriptionOptions,\n        );\n    }\n\n    /** Remove all unprotected subscribers */\n    unsubscribeAll(): void {\n        this.#statemanjsBaseService.unsubscribeAll();\n    }\n\n    /**\n     * Returns count of all active subscribers.\n     * @returns number.\n     */\n    getActiveSubscribersCount(): number {\n        return this.#statemanjsBaseService.getActiveSubscribersCount();\n    }\n\n    /**\n     * Flexible state update.\n     * @param updateCb Callback for state updates.\n     */\n    update(updateCb: UpdateCb<E>, options: UpdateOptions<E> = {}): boolean {\n        try {\n            const wasChanged = this.#statemanjsBaseService.update(updateCb, {\n                afterUpdate: (): void => {\n                    if (this.DEBUG !== undefined) {\n                        this.DEBUG.transactionService.addTransaction(\n                            this.unwrap(),\n                        );\n                    }\n                },\n                ...options,\n            });\n\n            return wasChanged;\n        } catch (error) {\n            throw new Error(\n                formatError(\n                    \"An error occurred while updating the state\",\n                    error,\n                ),\n            );\n        }\n    }\n\n    /**\n     * Unwrap a proxy object to a regular JavaScript object\n     * @returns unwrapped state\n     */\n    unwrap(): E {\n        return this.#statemanjsBaseService.unwrap();\n    }\n\n    /**\n     * Dispatch an async action\n     * @param action An async action. It accepts a stateManager object,\n     * which is used to access the current state.\n     * @returns Promise.\n     */\n    async asyncAction(\n        action: (stateManager: StatemanjsAPI<E>) => Promise<void>,\n    ): Promise<void> {\n        try {\n            await action(this);\n        } catch (error) {\n            throw new Error(\n                `An error occurred while dispatching the async action: ${\n                    (error as Error).message\n                }`,\n            );\n        }\n    }\n\n    /**\n     * Create a computed state for a state property.\n     * @param selectorFn A function that returns a value of a state property.\n     * @returns A computed state.\n     */\n    createSelector<T>(\n        selectorFn: (state: E) => T,\n        subscriptionOptions: SubscriptionOptions<any> = {},\n    ): StatemanjsComputedAPI<T> {\n        const selector = (): T => selectorFn(this.get());\n        return new StatemanjsComputedService<T>(selector, [this], {\n            debugService: this.DEBUG,\n            customComparator: this.#statemanjsBaseService.customComparator,\n            defaultComparator: this.#statemanjsBaseService.defaultComparator,\n            ...subscriptionOptions,\n        });\n    }\n}\n\nexport class StatemanjsComputedService<T> implements StatemanjsComputedAPI<T> {\n    #statemanjs: StatemanjsAPI<T>;\n    #callback: () => T;\n    #isDirty = true; // Initially dirty (needs first computation)\n    #isComputing = false; // Cycle detection flag\n    #cachedValue?: T;\n    #hasSubscribers = false; // Track if there are real subscribers\n    #isScheduled = false; // Track whether recomputation is queued\n    readonly #flushCallback: () => void;\n\n    constructor(\n        callback: () => T,\n        deps: (StatemanjsAPI<any> | StatemanjsComputedAPI<any>)[],\n        options: StatemanjsComputedServiceOptions<any>,\n    ) {\n        if (!deps.length) {\n            throw new Error(\"No dependencies provided\");\n        }\n\n        this.#callback = callback;\n        this.#flushCallback = () => {\n            this.#isScheduled = false;\n            this.#flushIfNeeded();\n        };\n\n        // Bindings\n        this.get = this.get.bind(this);\n        this.subscribe = this.subscribe.bind(this);\n        this.unsubscribeAll = this.unsubscribeAll.bind(this);\n        this.getActiveSubscribersCount =\n            this.getActiveSubscribersCount.bind(this);\n        this.unwrap = this.unwrap.bind(this);\n\n        // Initialize with dummy value (will be computed lazily on first get())\n        this.#statemanjs = new StatemanjsService<T>(undefined as any, {\n            debugService: options.debugService,\n            customComparator: options.customComparator,\n            defaultComparator: options.defaultComparator,\n            batch: options.batch,\n        });\n\n        // Subscribe to dependencies - mark as dirty instead of recomputing immediately\n        for (const d of deps) {\n            d.subscribe(\n                (): void => {\n                    this.#markDirty();\n                },\n                {\n                    notifyCondition: options.notifyCondition,\n                    protect:\n                        options.protect === undefined ? true : options.protect,\n                    properties: options.properties,\n                },\n            );\n        }\n    }\n\n    /** Mark computed state as dirty (needs recomputation) */\n    #markDirty(): void {\n        this.#isDirty = true;\n\n        if (!this.#hasSubscribers) {\n            return;\n        }\n\n        if (this.#isScheduled) {\n            return;\n        }\n\n        this.#isScheduled = true;\n        scheduleComputedRecompute(this.#flushCallback);\n    }\n\n    #flushIfNeeded(): void {\n        if (!this.#hasSubscribers) {\n            return;\n        }\n\n        if (!this.#isDirty) {\n            return;\n        }\n\n        // Avoid re-entrancy while computing\n        if (this.#isComputing) {\n            // Leave as dirty; another flush will run after current computation\n            this.#isScheduled = true;\n            scheduleComputedRecompute(this.#flushCallback);\n            return;\n        }\n\n        const oldValue = this.#cachedValue;\n        const newValue = this.#computeIfNeeded();\n\n        if (oldValue !== newValue) {\n            this.#statemanjs.set(newValue, {\n                skipGenerationIncrement: true,\n            });\n        }\n    }\n\n    /** Compute value if dirty, otherwise return cached value */\n    #computeIfNeeded(): T {\n        if (!this.#isDirty && this.#cachedValue !== undefined) {\n            return this.#cachedValue;\n        }\n\n        // Cycle detection\n        if (this.#isComputing) {\n            throw new Error(\n                \"Circular dependency detected in computed state. \" +\n                    \"A computed state cannot depend on itself directly or indirectly.\",\n            );\n        }\n\n        this.#isComputing = true;\n        try {\n            this.#cachedValue = this.#callback();\n            this.#isDirty = false;\n            return this.#cachedValue;\n        } finally {\n            this.#isComputing = false;\n        }\n    }\n\n    /** Get current state */\n    get(): T {\n        // Lazy evaluation: compute only when accessed and if dirty\n        if (this.#isDirty) {\n            const oldValue = this.#cachedValue;\n            const newValue = this.#computeIfNeeded();\n\n            this.#isScheduled = false;\n\n            // Notify subscribers if value changed\n            if (oldValue !== newValue) {\n                // Skip generation increment - not from a base state change\n                this.#statemanjs.set(newValue, {\n                    skipGenerationIncrement: true,\n                });\n            }\n\n            return newValue;\n        }\n\n        return this.#cachedValue!;\n    }\n\n    /**\n     * The method of subscribing to the status change.\n     * Accepts a callback function (subscription callback),\n     * which will be called at each update, and a subscription options object.\n     * In the options, you can specify information about the subscription,\n     * as well as specify the condition under which the subscriber will be notified\n     * and mark the subscriber as protected. All subscribers are unprotected by default.\n     * Protected subscribers can only be unsubscribed using the unsubscribe method returned by this method.\n     * Returns the unsubscribe callback function.\n     *\n     * @param subscriptionCb A function that runs on every update.\n     * @param subscriptionOptions Additional information and notification condition.\n     * @returns Unsubscribe callback function.\n     */\n    subscribe(\n        subscriptionCb: SubscriptionCb<T>,\n        subscriptionOptions?: SubscriptionOptions<T> | undefined,\n    ): UnsubscribeCb {\n        if (!this.#hasSubscribers) {\n            this.#hasSubscribers = true;\n\n            if (this.#isDirty && !this.#isScheduled) {\n                this.#isScheduled = true;\n                scheduleComputedRecompute(this.#flushCallback);\n            }\n        }\n\n        const unsubscribe = this.#statemanjs.subscribe(\n            subscriptionCb,\n            subscriptionOptions,\n        );\n\n        // Wrap unsubscribe to update flag\n        return () => {\n            unsubscribe();\n            // Update flag if no more subscribers\n            this.#hasSubscribers =\n                this.#statemanjs.getActiveSubscribersCount() > 0;\n        };\n    }\n\n    /** Remove all unprotected subscribers */\n    unsubscribeAll(): void {\n        this.#statemanjs.unsubscribeAll();\n        this.#hasSubscribers = this.#statemanjs.getActiveSubscribersCount() > 0;\n    }\n\n    /**\n     * Returns count of all active subscribers.\n     * @returns number.\n     */\n    getActiveSubscribersCount(): number {\n        return this.#statemanjs.getActiveSubscribersCount();\n    }\n\n    /**\n     * Unwrap a proxy object to a regular JavaScript object\n     * @returns unwrapped state\n     */\n    unwrap(): T {\n        return this.#statemanjs.unwrap();\n    }\n}\n","import { TransactionAPI } from \"../api/transactionAPI\";\nimport { Transaction, TransactionDiff } from \"../types/transactionTypes\";\n\nexport class TransactionService<T> implements TransactionAPI<T> {\n    constructor(maxLength: number) {\n        this.addTransaction = this.addTransaction.bind(this);\n        this.getLastTransaction = this.getLastTransaction.bind(this);\n        this.getAllTransactions = this.getAllTransactions.bind(this);\n        this.getTransactionByNumber = this.getTransactionByNumber.bind(this);\n        this.getLastDiff = this.getLastDiff.bind(this);\n        this.getDiffBetween = this.getDiffBetween.bind(this);\n\n        this.#maxLength = maxLength > 2 ? maxLength : 2;\n    }\n\n    #transactions: Map<number, Transaction<T>> = new Map();\n    #transactionCounter: number = 1;\n    #maxLength: number;\n\n    get totalTransactions(): number {\n        return this.#transactionCounter;\n    }\n\n    addTransaction(snapshot: T): void {\n        const number = this.#transactionCounter++;\n        const timestamp = Date.now();\n        const transaction: Transaction<T> = {\n            number,\n            snapshot: JSON.parse(JSON.stringify(snapshot)),\n            timestamp,\n        };\n\n        if (this.#transactions.size >= this.#maxLength) {\n            const oldestTransactionNumber = Array.from(\n                this.#transactions.keys(),\n            )[0];\n            this.#transactions.delete(oldestTransactionNumber);\n        }\n\n        this.#transactions.set(number, transaction);\n    }\n\n    getLastTransaction(): Transaction<T> | null {\n        return this.#transactions.size > 0\n            ? JSON.parse(\n                  JSON.stringify(Array.from(this.#transactions.values())),\n              ).pop()!\n            : null;\n    }\n\n    getAllTransactions(): Transaction<T>[] {\n        return JSON.parse(\n            JSON.stringify(Array.from(this.#transactions.values())),\n        );\n    }\n\n    getTransactionByNumber(number: number): Transaction<T> | null {\n        return (\n            JSON.parse(JSON.stringify(this.#transactions.get(number))) || null\n        );\n    }\n\n    getLastDiff(): TransactionDiff<T> | null {\n        const transactionsArray = JSON.parse(\n            JSON.stringify(Array.from(this.#transactions.values())),\n        );\n        const length = transactionsArray.length;\n        if (length < 2) {\n            return null;\n        }\n\n        const oldSnapshot = transactionsArray[length - 2].snapshot;\n        const newSnapshot = transactionsArray[length - 1].snapshot;\n\n        return { old: oldSnapshot, new: newSnapshot };\n    }\n\n    getDiffBetween(\n        transactionA: number,\n        transactionB: number,\n    ): TransactionDiff<T> | null {\n        if (transactionA >= transactionB) {\n            throw new Error(\"transactionA must be less than transactionB\");\n        }\n\n        const oldTransaction = this.#transactions.get(transactionA);\n        const newTransaction = this.#transactions.get(transactionB);\n\n        if (!oldTransaction || !newTransaction) {\n            return null;\n        }\n\n        return JSON.parse(\n            JSON.stringify({\n                old: oldTransaction.snapshot,\n                new: newTransaction.snapshot,\n            }),\n        );\n    }\n}\n","/* istanbul ignore file */\n\nimport { DebugAPI } from \"./api/debugAPI\";\nimport { StatemanjsAPI } from \"./api/statemanjsApi\";\nimport { StatemanjsComputedAPI } from \"./api/statemanjsComputedAPI\";\nimport {\n    CustomComparator,\n    DefaultComparator,\n    SubscriptionOptions,\n} from \"./shared/entities\";\nimport { DebugService } from \"./service/debugService\";\nimport {\n    StatemanjsService,\n    StatemanjsComputedService,\n} from \"./service/statemanjsService\";\nimport { TransactionService } from \"./service/transactionService\";\n\nexport type StatemanjsOptions<T> = {\n    transactionsLen?: number;\n    customComparator?: CustomComparator<T>;\n    defaultComparator?: DefaultComparator;\n    batch?: boolean;\n};\n\nexport function createState<T>(\n    element: T,\n    options?: StatemanjsOptions<T>,\n): StatemanjsAPI<T> {\n    let debugService: DebugAPI<T> | undefined;\n\n    if (options !== undefined && options.transactionsLen !== undefined) {\n        debugService = new DebugService(\n            new TransactionService(options.transactionsLen),\n        );\n    }\n\n    return new StatemanjsService(element, {\n        debugService,\n        customComparator: options?.customComparator,\n        defaultComparator: options?.defaultComparator,\n        batch: options?.batch,\n    });\n}\n\nexport function createComputedState<T>(\n    callback: () => T,\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    deps: (StatemanjsAPI<any> | StatemanjsComputedAPI<any>)[],\n    options?: StatemanjsOptions<T>,\n): StatemanjsComputedAPI<T> {\n    return new StatemanjsComputedService<T>(callback, deps, {\n        ...(options || {}),\n        debugService:\n            options !== undefined && options.transactionsLen !== undefined\n                ? new DebugService(\n                      new TransactionService(options.transactionsLen),\n                  )\n                : undefined,\n        customComparator: options?.customComparator,\n        defaultComparator: options?.defaultComparator,\n        batch: options?.batch,\n    });\n}\n\nexport type { StatemanjsAPI, StatemanjsComputedAPI, SubscriptionOptions };\n"],"names":["DebugService","constructor","transactionService","this","formatError","description","error","getErrorMessage","message","pending","Set","isFlushing","scheduleComputedRecompute","callback","add","flushScheduledComputed","size","callbacks","Array","from","clear","_generation","UpdateGeneration","current","__privateGet","increment","__privateWrapper","_","WeakMap","_proxiedState","_activeSubscribers","_subscriberRegistry","_subscriberCallbacks","_isNeedToCheckProperties","_actionKind","_isAccessToStateAllowed","_isUnwrapAllowed","_wasChanged","_pathToChangedProperty","_skipComparison","_proxyCache","_isPrimitiveState","_primitiveValue","_compareFn","_batchingEnabled","_pendingNotification","_dangerMethods","_arrayAccessorMethods","_StatemanjsBaseService_instances","isPrimitive_fn","addPathToChangedProperty_fn","resetPathToChangedProperty_fn","propToString_fn","checkAccessKind_fn","isEqualShallow_fn","updateProperty_fn","isUpdateNeeded_fn","createHandler_fn","addSubscriber_fn","generateSubscriberId_fn","runActiveSubscribersCb_fn","notifySubscribersSync_fn","isObject_fn","isPropertyInPath_fn","performSafeModification_fn","StatemanjsBaseService","element","options","__privateAdd","Map","get","bind","set","update","subscribe","unsubscribeById","unsubscribeByIds","getActiveSubscribersCount","unsubscribeAll","unwrap","getPathToChangedProperty","customComparator","defaultComparator","__privateSet","batch","FinalizationRegistry","subscriberId","a","b","__privateMethod","call","Error","Proxy","__STATEMANJS_STATE__","newState","skipComparison","afterUpdate","skipGenerationIncrement","subscribers","keys","Object","getOwnPropertySymbols","id","s","notifyCondition","subCb","updateCb","subscriptionCb","subscriptionOptions","notifyConditionCb","hasProperties","properties","length","subId","isProtected","protect","register","has","unregister","delete","subscriberIds","forEach","protectedSubscribers","subscriber","unwrapped","obj","structuredClone","JSON","parse","stringify","deepClone","values","WeakSet","value","path","prop","toString","String","target","targetProp","propType","isFunc","propStr","newPath","isArray","originalMethod","args","result","map","item","itemProxy","resultProxy","boundFunc","newProxy","key","val","defineProperty","deleteProperty","console","warn","Symbol","queueMicrotask","activeSubscribers","inactiveSubscribersId","push","info","entity","paths","propertiesMap","some","slice","modifier","actionKind","_statemanjsBaseService","_statemanjs","_callback","_isDirty","_isComputing","_cachedValue","_hasSubscribers","_isScheduled","_flushCallback","_StatemanjsComputedService_instances","markDirty_fn","flushIfNeeded_fn","computeIfNeeded_fn","StatemanjsService","DEBUG","debugService","addTransaction","asyncAction","action","createSelector","selectorFn","StatemanjsComputedService","deps","d","oldValue","newValue","unsubscribe","_transactions","_transactionCounter","_maxLength","TransactionService","maxLength","getLastTransaction","getAllTransactions","getTransactionByNumber","getLastDiff","getDiffBetween","totalTransactions","snapshot","number","timestamp","Date","now","transaction","oldestTransactionNumber","pop","transactionsArray","old","new","transactionA","transactionB","oldTransaction","newTransaction","createState","transactionsLen","createComputedState"],"mappings":"AAKO,MAAMA,EACT,WAAAC,CAAYC,GACRC,KAAKD,mBAAqBA,CAC9B,ECAJ,SAASE,EAAYC,EAAqBC,GACtC,MAAO,GAAGD,MAAgBE,EAAgBD,IAC9C,CAEA,SAASC,EAAgBD,GACrB,OAAQA,EAAgBE,OAC5B,CCZA,MAAMC,MAAcC,IACpB,IAAIC,GAAa,EAEV,SAASC,EAA0BC,GACtCJ,EAAQK,IAAID,EAChB,CAEO,SAASE,IACZ,IAAIJ,EAAJ,CAIAA,GAAa,EACb,IACI,KAAOF,EAAQO,KAAO,GAAG,CACrB,MAAMC,EAAYC,MAAMC,KAAKV,GAC7BA,EAAQW,QAER,IAAA,MAAWP,KAAYI,EACnBJ,GAER,CACJ,CAAA,QACIF,GAAa,CACjB,CAdA,CAeJ,KC3BAU,4PAKO,MAAMC,EAGT,kBAAWC,GACP,OAAOC,EAAArB,KAAKkB,EAChB,CAEA,gBAAOI,GACH,QAASC,OAAKL,GAALM,CACb,EARON,EAAA,IAAAO,UADEN,IACY,KAAdD,8GCNXQ,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,qWAkBO,MAAMC,GAgIT,WAAAhE,CACIiE,EACAC,GA0CA,OA5KDC,GAAAjE,KAAA6C,GAKHoB,GAAAjE,KAAA0B,GAKAuC,GAAAjE,KAAA2B,EAAiD,IAMjDsC,GAAAjE,KAAA4B,GAKAqC,GAAAjE,KA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