{"version":3,"sources":["storage.ts"],"sourcesContent":["// deno-lint-ignore-file no-namespace\nimport { Runtime } from \"../runtime/runtime.ts\";\n\nimport type { ExecConditions, PointerSource } from \"../utils/global_types.ts\";\nimport { logger } from \"../utils/global_values.ts\";\nimport { client_type } from \"../utils/constants.ts\";\nimport { NOT_EXISTING } from \"../runtime/constants.ts\";\nimport { Pointer, type MinimalJSRef, ReactiveValue } from \"../runtime/pointers.ts\";\nimport { localStorage } from \"./storage-locations/local-storage-compat.ts\";\nimport { MessageLogger } from \"../utils/message_logger.ts\";\nimport { Type } from \"../types/type.ts\";\nimport { addPersistentListener } from \"../utils/persistent-listeners.ts\";\nimport { Endpoint, LOCAL_ENDPOINT } from \"../types/addressing.ts\";\nimport { ESCAPE_SEQUENCES, verboseArg } from \"../utils/logger.ts\";\nimport { StorageMap } from \"../types/storage-map.ts\";\nimport { StorageSet } from \"../types/storage-set.ts\";\nimport { IterableWeakSet } from \"../utils/iterable-weak-set.ts\";\nimport { LazyPointer } from \"../runtime/lazy-pointer.ts\";\nimport { AutoMap } from \"../utils/auto_map.ts\";\nimport { hasDebugCookie } from \"../utils/debug-cookie.ts\";\nimport { setStorage } from \"../runtime/reset.ts\";\nimport { KnownError, handleError } from \"../utils/error-handling.ts\";\n\n\n// displayInit();\n\n/***** imports and definitions with top-level await - node.js / browser interoperability *******************************/\nexport const site_suffix = (()=>{\n    // remove hash from url\n    if (globalThis.location?.origin) {\n        // const url = new URL(globalThis.location.href)\n        // url.hash = \"\";\n        // return url.toString();\n        return globalThis.location.origin\n    }\n    else return \"\"\n})();\n\n\ntype AtomicMatchInput<T> = T |\n    (\n        T extends string ? \n            RegExp :\n            never\n    )\n\ntype _MatchInput<T> = \n    MatchCondition<MatchConditionType, T> |\n    (\n        T extends object ? \n        {\n            [K in Exclude<keyof T,\"$\"|\"$$\">]?: MatchInputValue<T[K]>\n        } :\n        AtomicMatchInput<T>|AtomicMatchInput<T>[]\n    )\ntype MatchInputValue<T> = \n\t_MatchInput<T>| // exact match\n\t_MatchInput<T>[] // or match\n\nexport type MatchInput<T extends object> = MatchInputValue<T>\n\ntype ObjectKeyPaths<T> = \n    T extends object ?\n        (\n            ObjectKeyPaths<T[keyof T]> extends never ? \n            `${string & Exclude<keyof T, \"$\"|\"$$\">}` :\n            `${string & Exclude<keyof T, \"$\"|\"$$\">}`|`${string & Exclude<keyof T, \"$\"|\"$$\">}.${ObjectKeyPaths<T[Exclude<keyof T, \"$\"|\"$$\">]>}`\n        ):\n        never\n\nexport type MatchOptions<T = unknown> = {\n    /**\n     * Maximum number of matches to return\n     */\n    limit?: number,\n    /**\n     * Sort by key (e.g. address.street)\n     */\n    sortBy?: string // TODO: T extends object ? ObjectKeyPaths<T> : string,\n    /**\n     * Sort in descending order (only if sortBy is set)\n     */\n    sortDesc?: boolean,\n    /**\n     * Offset for match results\n     */\n    offset?: number,\n    /**\n     * Return advanced match results (e.g. total count of matches)\n     */\n    returnAdvanced?: boolean,\n    /**\n     * Provide a list of properties that should be returned as raw values. If provided, only the raw properties are returned\n     * and pointers are not loaded\n     */\n    returnRaw?: string[]\n    /**\n     * Return pointer ids of matched items\n     */\n    returnPointerIds?: boolean,\n    /**\n     * Return map keys (only works with StorageMaps)\n     */\n    returnKeys?: boolean,\n    /**\n     * Custom computed properties for match query\n     */\n    computedProperties?: Record<string, ComputedProperty<ComputedPropertyType>>\n}\n\nexport type MatchResult<T, Options extends MatchOptions> = Options[\"returnAdvanced\"] extends true ?\n    AdvancedMatchResult<T> & (\n        Options[\"returnPointerIds\"] extends true ?\n            {\n                pointerIds: Set<string>\n            } :\n            unknown\n    ) :\n    Set<T>\n\nexport type AdvancedMatchResult<T> = {\n    total: number,\n    pointerIds?: Set<string>,\n    matches: Set<T>\n}\n\nexport enum MatchConditionType {\n    BETWEEN = \"BETWEEN\",\n    LESS_THAN = \"LESS_THAN\",\n    GREATER_THAN = \"GREATER_THAN\",\n    LESS_OR_EQUAL = \"LESS_OR_EQUAL\",\n    GREATER_OR_EQUAL = \"GREATER_OR_EQUAL\",\n    NOT_EQUAL = \"NOT_EQUAL\",\n    CONTAINS = \"CONTAINS\",\n    POINTER_ID = \"POINTER_ID\",\n}\nexport type MatchConditionData<T extends MatchConditionType, V> = \n    T extends MatchConditionType.BETWEEN ? \n        [V, V] :\n    T extends MatchConditionType.LESS_THAN|MatchConditionType.GREATER_THAN|MatchConditionType.LESS_OR_EQUAL|MatchConditionType.GREATER_OR_EQUAL|MatchConditionType.NOT_EQUAL ?\n        V :\n    T extends MatchConditionType.CONTAINS ?\n        V :\n    T extends MatchConditionType.POINTER_ID ?\n        string[] :\n    never\n\nexport class MatchCondition<Type extends MatchConditionType, V> {\n    \n    private constructor(\n        public type: Type, \n        public data: MatchConditionData<Type, V>\n    ) {}\n\n    static between<V>(lower: V, upper: V) {\n        return new MatchCondition(MatchConditionType.BETWEEN, [lower, upper])\n    }\n\n    static lessThan<V>(value: V) {\n        return new MatchCondition(MatchConditionType.LESS_THAN, value)\n    }\n\n    static greaterThan<V>(value: V) {\n        return new MatchCondition(MatchConditionType.GREATER_THAN, value)\n    }\n\n    static lessOrEqual<V>(value: V) {\n        return new MatchCondition(MatchConditionType.LESS_OR_EQUAL, value)\n    }\n\n    static greaterOrEqual<V>(value: V) {\n        return new MatchCondition(MatchConditionType.GREATER_OR_EQUAL, value)\n    }\n\n    static notEqual<V>(value: V) {\n        return new MatchCondition(MatchConditionType.NOT_EQUAL, value)\n    }\n\n    static contains<V>(...values: V[]) {\n        return new MatchCondition(MatchConditionType.CONTAINS, new Set(values))\n    }\n\n    static pointerId(id: string): MatchCondition<MatchConditionType.POINTER_ID, string>\n    static pointerId(ids: string[]): MatchCondition<MatchConditionType.POINTER_ID, string>\n    static pointerId(id: string|string[]) {\n        return new MatchCondition(MatchConditionType.POINTER_ID, id instanceof Array ? id : [id])\n    }\n}\n\nexport enum ComputedPropertyType {\n    GEOGRAPHIC_DISTANCE = \"GEOGRAPHIC_DISTANCE\",\n    SUM = \"SUM\",\n}\n\nexport type ComputedPropertyData<Type extends ComputedPropertyType> =\n    Type extends ComputedPropertyType.GEOGRAPHIC_DISTANCE ?\n        {pointA: {lat: number|string, lon: number|string}, pointB: {lat: number|string, lon: number|string}} :\n    Type extends ComputedPropertyType.SUM ?\n        (number|string)[] :\n    never\n\nexport class ComputedProperty<Type extends ComputedPropertyType> {\n\n    private constructor(\n        public type: Type,\n        public data: ComputedPropertyData<Type>\n    ) {}\n\n    static geographicDistance(pointA: {lat: number|string, lon: number|string}, pointB: {lat: number|string, lon: number|string}) {\n        return new ComputedProperty(ComputedPropertyType.GEOGRAPHIC_DISTANCE, {pointA, pointB})\n    }\n\n    static sum(...values: (number|string)[]) {\n        return new ComputedProperty(ComputedPropertyType.SUM, values)\n    }\n}\n\n\nexport interface StorageLocation<SupportedModes extends Storage.Mode = Storage.Mode> {\n    name: string\n    isAsync: boolean\n    /**\n     * This storage location supports exec conditions for get operations\n     */\n    supportsExecConditions?: boolean\n    /**\n     * This storage location supports prefix selection for get operations\n     */\n    supportsPrefixSelection?: boolean\n    /**\n     * This storage location supports match selection for get operations\n     * Must implement supportsMatchForType if true\n     */\n    supportsMatchSelection?: boolean\n    /**\n     * This storage location supports partial updates for setPointer operations\n     */\n    supportsPartialUpdates?: boolean\n\n    isSupported(): boolean\n    onAfterExit?(): void // called when deno process exits\n    onAfterSnapshot?(isExit: boolean): void // called after a snapshot was saved to the storage (e.g. triggered by interval or exit event)\n\n    setItem(key:string, value:unknown): Promise<Set<Pointer>>|Set<Pointer>\n    getItem(key:string, conditions?:ExecConditions): Promise<unknown>|unknown\n    hasItem(key:string):Promise<boolean>|boolean\n    removeItem(key:string): Promise<void>|void\n    getItemValueDXB(key:string): Promise<ArrayBuffer|null>|ArrayBuffer|null\n    setItemValueDXB(key:string, value: ArrayBuffer):Promise<void>|void\n    getItemKeys(prefix?:string): Promise<Generator<string, void, unknown>> | Generator<string, void, unknown>\n    getItemKey?(value: unknown): Promise<string|undefined>|string|undefined\n\n    setPointer(pointer:Pointer, partialUpdateKey: unknown|typeof NOT_EXISTING): Promise<Set<Pointer>>|Set<Pointer>\n    getPointerValue(pointerId:string, outer_serialized:boolean, conditions?:ExecConditions):Promise<unknown>|unknown\n    removePointer(pointerId:string):Promise<void>|void\n    hasPointer(pointerId:string):Promise<boolean>|boolean\n    getPointerIds(): Promise<Generator<string, void, unknown>> | Generator<string, void, unknown>\n    getPointerValueDXB(pointerId:string): Promise<ArrayBuffer|null>|ArrayBuffer|null\n    setPointerValueDXB(pointerId:string, value: ArrayBuffer):Promise<void>|void\n\n    supportsMatchForType?(type: Type): Promise<boolean>|boolean\n    matchQuery?<T extends object, Options extends MatchOptions<T>>(itemPrefix: string, valueType: Type<T>, match: MatchInput<T>, options:Options): Promise<MatchResult<T, Options>>|MatchResult<T, Options>\n    clear(): Promise<void>|void\n    \n}\nexport abstract class SyncStorageLocation implements StorageLocation<Storage.Mode.SAVE_ON_CHANGE|Storage.Mode.SAVE_PERIODICALLY|Storage.Mode.SAVE_ON_EXIT> {\n\n    abstract name: string;\n    readonly isAsync = false;\n\n    abstract isSupported(): boolean\n    onAfterExit() {}\n\n    abstract setItem(key: string,value: unknown): Set<Pointer>\n    abstract getItem(key:string, conditions?:ExecConditions): Promise<unknown>|unknown\n    abstract hasItem(key:string): boolean\n    abstract getItemKeys(prefix?:string): Generator<string, void, unknown>\n    abstract getItemKey?(value: unknown): string|undefined\n\n    abstract removeItem(key: string): void\n    abstract getItemValueDXB(key: string): ArrayBuffer|null\n    abstract setItemValueDXB(key:string, value: ArrayBuffer):void\n\n    abstract setPointer(pointer: Pointer, partialUpdateKey: unknown|typeof NOT_EXISTING): Set<Pointer>\n    abstract getPointerValue(pointerId: string, outer_serialized:boolean, conditions?:ExecConditions): unknown\n    abstract getPointerIds(): Generator<string, void, unknown>\n\n    abstract removePointer(pointerId: string): void\n    abstract getPointerValueDXB(pointerId: string): ArrayBuffer|null\n    abstract setPointerValueDXB(pointerId:string, value: ArrayBuffer):void\n    abstract hasPointer(pointerId: string): boolean\n\n    supportsMatchForType?(type: Type): boolean\n    matchQuery?<T extends object, Options extends MatchOptions<T>>(itemPrefix: string, valueType: Type<T>, match: MatchInput<T>, options:Options): MatchResult<T, Options>\n\n    abstract clear(): void\n}\n\nexport abstract class AsyncStorageLocation implements StorageLocation<Storage.Mode.SAVE_ON_CHANGE|Storage.Mode.SAVE_PERIODICALLY> {\n    abstract name: string;\n    readonly isAsync = true;\n\n    abstract isSupported(): boolean\n    onAfterExit() {}\n\n    abstract setItem(key: string,value: unknown): Promise<Set<Pointer>>\n    abstract getItem(key:string, conditions?:ExecConditions): Promise<unknown>\n    abstract hasItem(key:string): Promise<boolean>\n    abstract getItemKeys(prefix?:string): Promise<Generator<string, void, unknown>>\n    abstract getItemKey?(value: unknown): Promise<string|undefined>\n\n    abstract removeItem(key: string): Promise<void>\n    abstract getItemValueDXB(key: string): Promise<ArrayBuffer|null> \n    abstract setItemValueDXB(key:string, value: ArrayBuffer):Promise<void>\n\n    abstract setPointer(pointer: Pointer, partialUpdateKey: unknown|typeof NOT_EXISTING): Promise<Set<Pointer>>\n    abstract getPointerValue(pointerId: string, outer_serialized:boolean, conditions?:ExecConditions): Promise<unknown>\n    abstract getPointerIds(): Promise<Generator<string, void, unknown>>\n\n    abstract removePointer(pointerId: string): Promise<void>\n    abstract getPointerValueDXB(pointerId: string): Promise<ArrayBuffer|null>\n    abstract setPointerValueDXB(pointerId:string, value: ArrayBuffer):Promise<void>\n    abstract hasPointer(pointerId: string): Promise<boolean>\n\n    supportsMatchForType?(type: Type): Promise<boolean>|boolean\n    matchQuery?<T extends object, Options extends MatchOptions<T>>(itemPrefix: string, valueType: Type<T>, match: MatchInput<T>, options:Options): Promise<MatchResult<T, Options>>\n\n    abstract clear(): Promise<void>\n}\n\ntype storage_options<M extends Storage.Mode> = {\n    modes: M[]\n    primary?: boolean // indicates if this storage should be used as the primary storage location\n    interval?: number\n}\n\ntype storage_location_options<L extends StorageLocation> = \n    L extends StorageLocation<infer T> ? storage_options<T> : never\n\ntype StorageSnapshotOptions = {\n    /**\n     * Display all internally used items (e.g. for garbage collection)\n     */\n    internalItems: boolean,\n    /**\n     * List all items and pointers of storage maps and sets\n     */\n    expandStorageMapsAndSets: boolean,\n    /**\n     * Only display items (and related pointers) that contain the given string in their key\n     */\n    itemFilter?: string,\n    /**\n     * Only display general information about storage data, no items or pointers\n     */\n    onlyHeaders?: boolean\n}\n\nexport class Storage {\n    \n    static cache:Map<string,any> = new Map(); // save stored values in a Map, return when calling getItem\n\n\n    static state_prefix = \"dxstate::\"\n\n    static pointer_prefix = \"dxptr::\"+site_suffix+\"::\"\n    static item_prefix = \"dxitem::\"+site_suffix+\"::\"\n\n    static meta_prefix = \"dxmeta::\"+site_suffix+\"::\"\n    static rc_prefix = \"rc::\"\n    static pointer_deps_prefix = \"deps::dxptr::\"\n    static item_deps_prefix = \"deps::dxitem::\"\n    static subscriber_cache_prefix = \"subscribers::\"\n\n    static #storage_active_pointers = new IterableWeakSet<Pointer>();\n    static #storage_active_pointer_ids = new Set<string>();\n    static #scheduledUpdates = new Set<()=>void|Promise<void>>();\n\n    /**\n     * Try to cache the actual pointer if it is stored in storage.\n     * Called from pointer once the value is initialized.\n     * @returns true if the pointer is stored in storage\n     */\n    static providePointer(ptr: Pointer) {\n        if (this.#storage_active_pointer_ids.has(ptr.id)) {\n            this.#storage_active_pointers.add(ptr);\n            this.#storage_active_pointer_ids.delete(ptr.id);\n            ptr.isStored = true;\n            return true;\n        }\n        return false;\n    }\n\n    static DEFAULT_INTERVAL = 60; // 60s\n\n    static #primary_location?: StorageLocation;\n    static #trusted_location?: StorageLocation;\n    static #trusted_pointers = new Set<string>()\n\n    // location which did that last complete backup in the last session, if none found, use the current primary location\n    static set trusted_location(location: StorageLocation | undefined) {\n        this.#trusted_location = location;\n        if (location != undefined) {\n            logger.debug `trusted storage location: #bold${location.name}`\n        }\n    }\n    static get trusted_location () {return this.#trusted_location}\n\n    // default location for saving pointers/items\n    static set primary_location(location: StorageLocation | undefined) {\n        this.#primary_location = location;\n    }\n    static get primary_location () {return this.#primary_location}\n\n    static #locations = new Map<StorageLocation, storage_location_options<StorageLocation>>()\n    static #auto_sync_enabled = false;\n\n    public static get locations() {\n        return this.#locations;\n    }\n\n    // set options for storage location and enable\n    public static addLocation<L extends StorageLocation>(location:L, options:storage_location_options<L>) {\n        this.#locations.set(location, options);\n\n        if (options.interval && !options.modes.includes(Storage.Mode.SAVE_PERIODICALLY)) {\n            throw new Error(\"The 'interval' option can only be used for the storage mode SAVE_PERIODICALLY\");\n        }\n\n        for (const mode of options.modes) {\n            // asynchronous saving on exit not possible\n            if (mode == Storage.Mode.SAVE_ON_EXIT && location.isAsync) throw new Error(\"Invalid DATEX Storage location: \"+location.name+\" is async and not compatible with SAVE_ON_EXIT mode\");\n            // supported? e.g. localStorage undefined in web worker\n            if (!location.isSupported()) {\n                throw new Error(\"Invalid DATEX Storage location: \"+location.name+\", not supported in this context\");\n            }\n        \n            if (mode == Storage.Mode.SAVE_PERIODICALLY) {\n                this.addSaveInterval(location, options.interval ?? this.DEFAULT_INTERVAL)\n            }\n        }\n\n        // update auto_sync_enabled\n        this.#auto_sync_enabled = false\n        for (const [_loc,options] of this.#locations) {\n            if (options.modes.includes(Storage.Mode.SAVE_ON_CHANGE)) this.#auto_sync_enabled = true;\n        }\n\n        logger.debug `using ${options.primary?'primary':'secondary'} storage location #bold${location.name}:#color(grey) ${options.modes.map(m=>Storage.Mode[m]).join(', ')}`\n\n        if (options.primary) {\n            this.primary_location = location;\n        }\n\n        this.determineTrustedLocation();\n\n        return this.restoreDirtyState()\n    }\n\n    // disable storage location\n    public static removeLocation(location:StorageLocation) {\n        const options = this.#locations.get(location);\n        this.#locations.delete(location);\n        if (options?.primary) this.primary_location = undefined;\n        if (options?.interval != undefined) clearInterval(this.#save_interval_refs.get(location))\n    }\n\n\n    static #save_interval_refs = new Map<StorageLocation, number>()\n\n    /**\n     * set the interval (in s) in which the current pointer should be saved in a storage storage\n     */\n    private static addSaveInterval(location:StorageLocation, interval:number) {\n        if (this.#save_interval_refs.has(location)) clearInterval(this.#save_interval_refs.get(location))\n        if (interval != 0) {\n            this.#save_interval_refs.set(location, setInterval(()=>this.saveCurrentState(location), interval * 1000))\n        }\n    }\n\n    static #exiting = false\n\n    static handleExit(){\n        if (this.#exiting) return;\n        this.#exiting = true\n        // TODO: add race promise with timeout to return if cache takes too long\n        // if (globalThis.Deno) setTimeout(()=>{Deno.exit(1)},20_000)\n\n        // first run remaining scheduled updates (only sync supported)\n        for (const update of this.#scheduledUpdates) {\n            const res = update()\n            if (res instanceof Promise) logger.error(\"Cannot store state in async storage location on exit\");\n        }\n\n        this.saveDirtyState();\n        \n        if (this.#dirty || this.dirtyValues.size) {\n            logger.debug(\"Storage has dirty flag set, following values could not be stored\", this.dirtyValues);\n        }\n        \n        for (const [loc,options] of this.#locations) {\n            if (options.modes.includes(<any>Storage.Mode.SAVE_ON_EXIT)) Storage.saveCurrentState(loc, true);\n            loc.onAfterExit?.();\n        }\n\n        // also save deno localstorage file, also if no local storage location set, metadata must stil be stored\n        if (localStorage.saveFile) localStorage.saveFile();\n\n        logger.debug(\"\\nexit - state saved in cache\");\n    }\n\n\n    // call to reload page without saving any data (for resetting)\n    static #exit_without_save = false;\n    public static allowExitWithoutSave(){\n        this.#exit_without_save = true;\n    }\n\n    private static saveCurrentState(location:StorageLocation, isExit = false){\n        if (this.#exit_without_save) {\n            // console.log(`exiting without save`);\n            return;\n        }\n\n        try {\n            // update items\n            let c = 0;\n            for (const [key, val] of Storage.cache) {\n                try {\n                    c++;\n                    const res = this.setItem(key, val, true, location);\n                    if (res instanceof Promise) res.catch(()=>{})\n                } catch (e) {}\n            }\n\n            // update pointers\n            for (const ptr of [...this.#storage_active_pointers]) {\n                try {\n                    c++;\n                    const res = this.setPointer(ptr, true, location);\n                    if (res instanceof Promise) res.catch(()=>{})\n                } catch (e) {}\n            }\n            for (const id of [...this.#storage_active_pointer_ids]) {\n                try {\n                    c++;\n                    const ptr = Pointer.get(id);\n                    if (ptr?.value_initialized) this.setPointer(ptr, true, location);\n                } catch (e) {}\n            }\n\n            this.updateSaveTime(location); // last full backup to this storage location\n            logger.debug(`current state saved to ${location.name} (${c} items)`);\n            location.onAfterSnapshot?.(isExit);\n        }\n        catch (e) {\n            console.error(e)\n        }\n     \n    }\n    \n    // called when a full backup to this storage location was made\n    private static updateSaveTime(location:StorageLocation) {\n        if (this.#exit_without_save) return; // currently exiting\n        localStorage.setItem(this.meta_prefix+'__saved__' + location.name, new Date().getTime().toString());\n    }\n\n    private static deleteSaveTime(location:StorageLocation) {\n        localStorage.removeItem(this.meta_prefix+'__saved__' + location.name);\n    }\n\n    private static getSaveTime(location:StorageLocation) {\n        return Number(localStorage.getItem(this.meta_prefix+'__saved__' + location.name) ?? 0);\n    }\n\n    // handle dirty states for async storage operations:\n    static #dirty_locations = new Map<StorageLocation, number>()\n\n    static dirtyValues = new Set<string>();\n    // called when a full backup to this storage location was made\n    public static setDirty(location:StorageLocation, dirty = true, metadata = '') {\n        // update counter\n        if (dirty) {\n            this.dirtyValues.add(metadata);\n            const currentCount = this.#dirty_locations.get(location)??0;\n            this.#dirty_locations.set(location, currentCount + 1);\n        }\n        else {\n            if (!this.#dirty_locations.has(location)) {\n                logger.warn(\"Invalid dirty state reset for location '\"+location.name + \"', dirty state was not set\", metadata);\n            }\n            else {\n                const newCount = this.#dirty_locations.get(location)! - 1;\n                if (newCount <= 0) {\n                    this.#dirty_locations.delete(location);\n                }\n                else this.#dirty_locations.set(location, newCount);\n                this.dirtyValues.delete(metadata);\n            }\n        }\n    }\n\n    static #dirty = false;\n    private static isInDirtyState(location:StorageLocation) {\n        this.#dirty = !!localStorage.getItem(this.meta_prefix+'__dirty__' + location.name)\n        return this.#dirty;\n    }\n\n    /**\n     * save current dirty states in localstorage\n     */\n    private static saveDirtyState(){\n        if (this.#exit_without_save) return; // currently exiting\n        for (const [location] of this.#dirty_locations) {\n            localStorage.setItem(this.meta_prefix+'__dirty__' + location.name, new Date().getTime().toString());\n        }\n    }\n\n    /**\n     * clear the dirty state in localstorage\n     */\n    private static clearDirtyState(location: StorageLocation){\n        localStorage.removeItem(this.meta_prefix+'__dirty__' + location.name);\n    }\n    \n\n    private static determineTrustedLocation(fromLocations: StorageLocation[] = [...this.#locations.keys()]) {\n        // primary is already trusted, use this\n        if (this.trusted_location === this.primary_location) return this.trusted_location;\n\n        let last:StorageLocation|undefined = this.trusted_location;\n        let last_time = last ? this.getSaveTime(last) : 0;\n\n        for (const location of fromLocations) {\n            if (this.isInDirtyState(location)) continue;\n            // found trusted primary location, use this\n            if (location === this.primary_location) {\n                last = location\n                break;\n            }\n\n            // find location with latest update\n\t\t\tconst time = this.getSaveTime(location)\n            if (time > last_time) {\n\t\t\t\tlast_time = time;\n\t\t\t\tlast = location\n\t\t\t}\n\t\t\tthis.deleteSaveTime(location); // no longer valid after this session\n        }\n        if (this.trusted_location !== last) this.trusted_location = last\n        return this.trusted_location;\n    }\n\n    static #unresolvedLocalItems = new Map<string, unknown>()\n    static #unresolvedLocalPointers = new IterableWeakSet<Pointer>()\n\n\n    static setItem(key:string, value:any, listen_for_pointer_changes = true, location:StorageLocation|null|undefined = this.#primary_location):Promise<boolean>|boolean {\n        Storage.cache.set(key, value); // save in cache\n\n        // cache deletion does not work, problems with storage item backup\n        // setTimeout(()=>Storage.cache.delete(key), 10000);\n\n\t\tif (location)  {\n\t\t\tif (location.isAsync) return this.setItemAsync(location as AsyncStorageLocation, key, value, listen_for_pointer_changes);\n\t\t\telse return this.setItemSync(location as SyncStorageLocation, key, value, listen_for_pointer_changes);\n\t\t}\n        else return false;\n    }\n\n\tstatic async setItemAsync(location:AsyncStorageLocation, key: string, value: unknown,listen_for_pointer_changes: boolean) {\n        const metadata = this.isDebugMode ? (key + \": \" +Runtime.valueToDatexString(value)) : undefined;\n        this.setDirty(location, true, metadata);\n        const itemExisted = await location.hasItem(key);\n        // store value (might be pointer reference)\n        const dependencies = await location.setItem(key, value);\n        if (Pointer.is_local) this.checkUnresolvedLocalDependenciesForItem(key, value, dependencies);\n        this.updateItemDependencies(key, [...dependencies].map(p=>p.id));\n        await this.saveDependencyPointersAsync(dependencies, listen_for_pointer_changes, location);\n        this.setDirty(location, false, metadata);\n        return itemExisted;\n\t}\n\n\tstatic setItemSync(location:SyncStorageLocation, key: string, value: unknown,listen_for_pointer_changes: boolean) {\n        const itemExisted = location.hasItem(key);\n        const dependencies = location.setItem(key, value);\n        if (Pointer.is_local) this.checkUnresolvedLocalDependenciesForItem(key, value, dependencies);\n        this.updateItemDependencies(key, [...dependencies].map(p=>p.id));\n        this.saveDependencyPointersSync(dependencies, listen_for_pointer_changes, location);\n        return itemExisted;\n\t}\n\n    /**\n     * Collects all pointer dependencies of an itemr entry with a @@local origin.\n     * Once the endpoint is initialized, the entry is updated with the correct pointer ids.\n     */\n    private static checkUnresolvedLocalDependenciesForItem(key: string, value:unknown, dependencies: Set<Pointer>) {\n        const hasUnresolvedLocalDependency = [...dependencies].some(p=>p.origin == LOCAL_ENDPOINT);\n        if (hasUnresolvedLocalDependency) this.#unresolvedLocalItems.set(key, value);\n    }\n\n    /**\n     * Collects all pointer dependencies of a pointer entry with a @@local origin.\n     * Once the endpoint is initialized, the entry is updated with the correct pointer ids.\n     */\n    private static checkUnresolvedLocalDependenciesForPointer(pointer: Pointer, dependencies: Set<Pointer>) {\n        const hasUnresolvedLocalDependency = [...dependencies].some(p=>p.origin == LOCAL_ENDPOINT);\n        if (hasUnresolvedLocalDependency) this.#unresolvedLocalPointers.add(pointer);\n    }\n\n    /**\n     * Updates all item/pointer entries in storage that still are stored with unresolved @@local pointers\n     */\n    static updateEntriesWithUnresolvedLocalDependencies() {\n        for (const [key, value] of this.#unresolvedLocalItems) {\n            logger.debug(\"update item containing pointers with @@local origin: \" +  key)\n            this.setItem(key, value)\n        }\n        this.#unresolvedLocalItems.clear()\n\n        for (const ptr of this.#unresolvedLocalPointers) {\n            logger.debug(\"update pointer containing pointers with @@local origin: \" + ptr.idString())\n            this.setPointer(ptr as Pointer)\n        }\n        this.#unresolvedLocalPointers.clear()\n    }\n\n\n    public static setPointer(pointer:Pointer, listen_for_changes = true, location:StorageLocation|undefined = this.#primary_location, partialUpdateKey: unknown = NOT_EXISTING): Promise<boolean>|boolean {\n        if (!pointer.value_initialized) {\n            // logger.warn(\"pointer value \" + pointer.idString() + \" not available, cannot save in storage\");\n            this.#storage_active_pointers.delete(pointer);\n            this.#storage_active_pointer_ids.delete(pointer.id);\n            return false\n        }\n        \n\t\tif (location)  {\n\t\t\tif (location.isAsync) return this.initPointerAsync(location as AsyncStorageLocation, pointer, listen_for_changes, partialUpdateKey);\n\t\t\telse return this.initPointerSync(location as SyncStorageLocation, pointer, listen_for_changes, partialUpdateKey);\n\t\t}\n\t\telse return false;\n    }\n\n    private static initPointerSync(location: SyncStorageLocation, pointer:Pointer, listen_for_changes = true, partialUpdateKey: unknown = NOT_EXISTING):boolean {\n        // if (pointer.transform_scope && this.hasPointer(pointer)) return true; // ignore transform pointer, initial transform scope already stored, does not change\n        // was garbage collected in the meantime\n        if (pointer.garbage_collected) {\n            return false\n        }\n\n        const dependencies = this.updatePointerSync(location, pointer, partialUpdateKey);\n        dependencies.delete(pointer);\n        if (Pointer.is_local) this.checkUnresolvedLocalDependenciesForPointer(pointer, dependencies);\n        this.updatePointerDependencies(pointer.id, [...dependencies].map(p=>p.id));\n        this.saveDependencyPointersSync(dependencies, listen_for_changes, location);\n\n        // listen for changes\n        if (listen_for_changes) this.syncPointer(pointer, location);\n\n        this.#storage_active_pointers.add(pointer);\n        // remember that this pointer is stored in storage\n        pointer.isStored = true;\n\n        return true;\n    }\n\n    private static updatePointerSync(location: SyncStorageLocation, pointer:Pointer, partialUpdateKey: unknown = NOT_EXISTING): Set<Pointer>{\n        // was garbage collected in the meantime\n        if (pointer.garbage_collected) {\n            return new Set();\n        }\n\t\treturn location.setPointer(pointer, partialUpdateKey);\n    }\n\n    private static async initPointerAsync(location: AsyncStorageLocation, pointer:Pointer, listen_for_changes = true, partialUpdateKey: unknown = NOT_EXISTING):Promise<boolean>{\n        // if (pointer.transform_scope && await this.hasPointer(pointer)) return true; // ignore transform pointer, initial transform scope already stored, does not change\n        // was garbage collected in the meantime\n        if (pointer.garbage_collected) {\n            return false\n        }\n\n        const dependencies = await this.updatePointerAsync(location, pointer, partialUpdateKey);\n        dependencies.delete(pointer);\n        if (Pointer.is_local) this.checkUnresolvedLocalDependenciesForPointer(pointer, dependencies);\n        this.updatePointerDependencies(pointer.id, [...dependencies].map(p=>p.id));\n        await this.saveDependencyPointersAsync(dependencies, listen_for_changes, location);\n\n        // listen for changes\n        if (listen_for_changes) this.syncPointer(pointer, location);\n\n        this.#storage_active_pointers.add(pointer);\n        // remember that this pointer is stored in storage\n        pointer.isStored = true;\n\n        return true;\n    }\n\n    private static get isDebugMode(): boolean {\n        return (verboseArg || hasDebugCookie());\n    }\n\n    private static async updatePointerAsync(location: AsyncStorageLocation, pointer:Pointer, partialUpdateKey: unknown = NOT_EXISTING): Promise<Set<Pointer>> {\n        // was garbage collected in the meantime\n        if (pointer.garbage_collected) {\n            return new Set();\n        }\n        const metadata = this.isDebugMode ? `${pointer.id}: ${Runtime.valueToDatexString(pointer.val)}` : undefined;\n        this.setDirty(location, true, metadata);\n        const res = await location.setPointer(pointer, partialUpdateKey);\n        this.setDirty(location, false, metadata);\n        return res;\n    }\n\n    /**\n     * Save dependency pointers to storage (SyncStorageLocation)\n     * Not all pointers in the set are saved, only those which are not yet in storage or not accessible in other ways\n     * @param dependencies List of dependency pointers\n     * @param listen_for_changes should update pointers in storage when value changes\n     * @param location storage location\n     */\n    private static saveDependencyPointersSync(dependencies: Set<Pointer>, listen_for_changes = true, location: SyncStorageLocation) {\n        for (const ptr of dependencies) {\n            // add if not yet in storage\n            if (!location.hasPointer(ptr.id)) this.setPointer(ptr, listen_for_changes, location)\n        }\n    }\n\n    /**\n     * Save dependency pointers to storage (AsyncStorageLocation)\n     * Not all pointers in the set are saved, only those which are not yet in storage or not accessible in other ways\n     * @param dependencies List of dependency pointers\n     * @param listen_for_changes should update pointers in storage when value changes\n     * @param location storage location\n     */\n    private static async saveDependencyPointersAsync(dependencies: Set<Pointer>, listen_for_changes = true, location: AsyncStorageLocation) {\n        await Promise.all([...dependencies].map(async ptr=>{\n            // add if not yet in storage\n            if (!await location.hasPointer(ptr.id)) await this.setPointer(ptr, listen_for_changes, location)\n        }));\n    }\n\n\n    private static synced_pointers = new WeakSet<Pointer>();\n\n    static syncPointer(pointer: Pointer, location: StorageLocation|undefined = this.#primary_location) {\n        if (!this.#auto_sync_enabled) return;\n\n        if (!pointer) {\n            logger.error(\"tried to sync non-existing pointer with storage\")\n            return;\n        }\n        if (!location) {\n            logger.error(\"location required for syncPointer\")\n            return;\n        }\n\n        // already syncing?\n        if (this.synced_pointers.has(pointer)) return;\n        this.synced_pointers.add(pointer)\n\n        // any value change\n        let saving = false;\n\n\n        const handler = (v:unknown,key:unknown,t?:ReactiveValue.UPDATE_TYPE)=>{\n            if (saving) return;\n\n            // don't block saving if only partial update\n            if (!(location.supportsPartialUpdates && key !== NOT_EXISTING)) saving = true;\n            const metadata = this.isDebugMode ? `${pointer.id}: ${Runtime.valueToDatexString(pointer.val)}` : undefined;\n\n            this.scheduleStorageUpdate(()=>{\n                // set pointer (async)\n                saving = false;\n                const res = this.setPointer(pointer, false, location, key); // update value and add new dependencies recursively\n                if (res instanceof Promise) {\n                    return res.then((couldSave)=>{\n                        if (couldSave) {\n                            logger.debug(\"updated \" + pointer.idString() + \" in storage\");\n                        }\n                        else {\n                            pointer.unobserve(handler);\n                        }\n                    });\n                }\n                else {\n                    const couldSave = res; \n                    if (couldSave) {\n                        logger.debug(\"updated \" + pointer.idString() + \" in storage\");\n                    }\n                    else {\n                        pointer.unobserve(handler);\n                    }\n                }\n            }, location, metadata);\n        };\n\n        pointer.observe(handler, undefined, undefined, {ignore_transforms:true, recursive:false});   \n    }\n\n\n    /**\n     * Run a pointer update after 1s or on process exit and keep the dirty state until the update is finished\n     */\n    private static scheduleStorageUpdate(update:()=>void|Promise<void>, location: StorageLocation, metadata?: string) {\n        \n        this.setDirty(location, true, metadata);\n        const updateFn = () => {\n            clearTimeout(timeout);\n            const res = update();\n            if (res instanceof Promise) {\n                return res.then(()=>{\n                    this.setDirty(location, false, metadata);\n                    this.#scheduledUpdates.delete(updateFn);\n                }).catch(e => console.error(e));\n            }\n            else {\n                this.#scheduledUpdates.delete(updateFn);\n                this.setDirty(location, false, metadata);\n            }\n        }\n\n        this.#scheduledUpdates.add(updateFn);\n        const timeout = setTimeout(updateFn, 1000);\n    }\n \n    public static hasPointer(pointer:Pointer, location:StorageLocation|undefined = this.#trusted_location) {\n\t\tif (location)  {\n\t\t\treturn location.hasPointer(pointer.id);\n\t\t}\n\t\telse return false;\n    }\n\n    private static getLocationPriorityOrder(pointer_id:string) {\n        if (this.#trusted_pointers.has(pointer_id)) return [this.#primary_location, this.#trusted_location]; // value already loaded from trusted location, use primary location now\n        else return [this.#trusted_location, this.#primary_location] // first try to get from trusted location\n    }\n\n    private static initPointerFromTrustedLocation(id:string, maybe_trusted_location:StorageLocation) {\n        if (this.#primary_location == undefined) return;\n        if (this.#primary_location == this.#trusted_location) return;\n\n        // wait until pointer loaded, TODO: timeout or return promise?\n        setTimeout(async ()=>{\n            if (this.#primary_location == maybe_trusted_location) {\n                const pointer = Pointer.get(id);\n                if (pointer?.value_initialized) {\n                    await this.setPointer(pointer, true, this.#primary_location)\n                    this.#trusted_pointers.add(id)\n                }\n                else {\n                    console.log(\"cannot init pointer \" +id)\n                }\n            }\n        }, 3000);\n\n    }\n\n    private static async initItemFromTrustedLocation(key: string, value:any, maybe_trusted_location:StorageLocation) {\n        if (this.#primary_location == undefined) return;\n        if (this.#primary_location == this.#trusted_location) return;\n\n        if (this.#primary_location == maybe_trusted_location) {\n            await this.setItem(key, value, true, this.#primary_location)\n        }\n\n    }\n\n\n    private static async restoreDirtyState() {\n        if (this.#primary_location != undefined && this.isInDirtyState(this.#primary_location) && this.#trusted_location != undefined && this.#trusted_location!=this.#primary_location) {\n            await this.copyStorage(this.#trusted_location, this.#primary_location)\n            logger.warn `restored dirty state of ${this.#primary_location.name} from trusted location ${this.#trusted_location.name}`\n            if (this.#dirty_locations.has(this.#primary_location)) this.setDirty(this.#primary_location, false) // remove from dirty set\n            this.clearDirtyState(this.#primary_location) // remove from localstorage\n            this.#dirty = false;\n            // primary location is now trusted, update\n            this.determineTrustedLocation()\n            // this.trusted_location = this.#primary_location\n        }\n    }\n\n    private static handleDirtyStateError() {\n        handleError(new KnownError(\n            `Cannot restore dirty eternal state (location: ${this.#primary_location!.name})`,\n            [],\n            [\n                {\n                    description: \"Do you want to reset the current application state? (THIS IS IRREVERSIBLE)\",\n                    fix: () => {\n                        this.clearAndReload();\n                    }\n                }\n            ]\n        ))\n    }\n\n\n    /**\n     * Maps pointer ids to existing subscriber caches that were preloaded from storage\n     */\n    public static subscriberCaches = new Map<string, Set<Endpoint>>()\n\n    /**\n     * gets the value of a pointer from storage\n     * @param pointer_id id string\n     * @param pointerify creates DATEX Pointer if true, otherwise just returns the value\n     * @param outer_serialized if true, the outer value type is not evaluated and only the serialized value is returned\n     * @returns value from pointer storage\n     */\n    public static async getPointer(pointer_id:string, pointerify?:boolean, bind?:any, location?:StorageLocation, conditions?: ExecConditions):Promise<any> {\n\n        if (this.#dirty) {\n            this.handleDirtyStateError();\n        }\n\n        // try to find pointer at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(pointer_id))) {\n            if (loc==undefined) continue;\n            const val = await this.getPointerFromLocation(pointer_id, pointerify, bind, loc, conditions);\n            if (val !== NOT_EXISTING) return val;\n        }\n        \n        return NOT_EXISTING\n    }\n\n    private static async getPointerFromLocation(pointer_id:string, pointerify: boolean|undefined, bind:any|undefined, location:StorageLocation, conditions?: ExecConditions) {\n        const val = await this.getPointerAsync(location, pointer_id, pointerify, bind, conditions);\n\t\tif (val == NOT_EXISTING) return NOT_EXISTING;\n        \n\t\tawait this.initPointerFromTrustedLocation(pointer_id, location)\n        return val;\n    }\n\n    private static async getPointerAsync(location:StorageLocation, pointer_id:string, pointerify?:boolean, bind?:any, conditions?: ExecConditions) {\n\n        let pointer:Pointer|undefined;\n\t\tif (pointerify && (pointer = Pointer.get(pointer_id))?.value_initialized) {\n            return pointer.val; // pointer exists in runtime\n        }\n\n\n        // load from storage\n\t\tlet val = await location.getPointerValue(pointer_id, !!bind, conditions);\n\n        if (val == NOT_EXISTING) return NOT_EXISTING;\n\n        // bind serialized val to existing value\n        if (bind) {\n            Type.ofValue(bind).updateValue(bind, val);\n            val = bind;\n        }\n\n        // create pointer with saved id and value + start syncing, if pointer not already created in DATEX\n        if (pointerify) {\n            let pointer = Pointer.get(pointer_id)\n\n            // if the value is a pointer with a tranform scope, copy the transform, not the value (TODO still just a workaround to preserve transforms in storage, maybe better solution?)\n            if (val instanceof Pointer && val.transform_scope) {\n                console.log(\"init value\",val);\n                pointer = await Pointer.createTransformAsync(val.transform_scope.internal_vars, val.transform_scope);\n            }\n            // set value of existing pointer\n            else if (pointer) {\n                if (pointer.value_initialized) logger.warn(\"pointer value \" + pointer.idString() + \" already initialized, setting new value from storage\");\n                pointer = pointer.setValue(val);\n            }\n            // create new pointer from value\n            else {\n                pointer = Pointer.create(pointer_id, val, false, Runtime.endpoint);\n            }\n\n            this.syncPointer(pointer);\n            this.#storage_active_pointers.add(pointer);\n            pointer.isStored = true;\n            if (pointer.is_js_primitive) return pointer;\n            else return pointer.val;\n        }\n\n        else {\n            this.#storage_active_pointer_ids.add(pointer_id);\n            return val;\n        }\n    }\n\n    private static async removePointer(pointer_id:string, location?:StorageLocation, force_remove = false) {\n        if (!force_remove && this.getReferenceCount(pointer_id) > 0) {\n            logger.warn(\"Cannot remove pointer $\" + pointer_id + \", still referenced\");\n            return;\n        }\n        logger.debug(\"Removing pointer $\" + pointer_id + \" from storage\" + (location ? \" (\" + location.name  + \")\" : \"\"));\n\n        // remove from specific location\n\t\tif (location) return location.removePointer(pointer_id);\n\t\t// remove from all\n\t\telse {\n\n            const ptr = Pointer.get(pointer_id)\n            if (ptr) {\n                this.#storage_active_pointers.delete(ptr);\n                // remember that this pointer is not stored in storage             \n                ptr.isStored = false;\n            }\n            this.#storage_active_pointer_ids.delete(pointer_id);\n\n            const promises = []\n\n            // remove pointer from all locations\n\t\t\tfor (const location of this.#locations.keys()) {\n\t\t\t\tpromises.push(location.removePointer(pointer_id));\n\t\t\t}\n\n            // remove subscriber cache\n            promises.push(this.removePointerSubscriberCache(pointer_id));\n\n            await Promise.all(promises);\n\n            // clear dependencies\n            this.updatePointerDependencies(pointer_id, [])\n\t\t}\n    }\n\n    public static async getPointerDecompiled(pointer_id:string, colorized = false, location?:StorageLocation):Promise<string|undefined|typeof NOT_EXISTING> {\n        // try to find pointer at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(pointer_id))) {\n            if (loc==undefined) continue;\n            const val = await this.getPointerDecompiledFromLocation(pointer_id, colorized, loc);\n            if (val !== NOT_EXISTING) return val;\n        }\n        return NOT_EXISTING;\n    }\n\n\n    private static async getPointerDecompiledFromLocation(pointer_id:string, colorized = false, location:StorageLocation) {\n\t\tconst buffer = await location.getPointerValueDXB(pointer_id);\n\t\tif (buffer != null) return MessageLogger.decompile(buffer, false, colorized);\n        return NOT_EXISTING;\n    }\n\n    /**\n     * Gets a subscriber cache for a pointer if it exists\n     */\n    public static async getPointerSubscriberCache(pointer_id:string) {\n        // return existing cache from memory\n        if (this.subscriberCaches.has(pointer_id)) return this.subscriberCaches.get(pointer_id);\n        // load from storage\n        const id = this.subscriber_cache_prefix + pointer_id;\n        const subscribers = await this.getItem(id) as Set<Endpoint>|undefined;\n        if (subscribers) this.subscriberCaches.set(pointer_id, subscribers);\n        return subscribers;\n    }\n\n    /**\n     * Removes the subscriber cache from memory and storage\n     * @returns \n     */\n    private static removePointerSubscriberCache(pointer_id:string) {\n        const id = this.subscriber_cache_prefix + pointer_id;\n        this.subscriberCaches.delete(pointer_id);\n        return this.removeItem(id);\n    }\n\n    /**\n     * Gets or creates a new subscriber cache for a pointer and\n     * puts it into the subscriberCaches map\n     * @returns \n     */\n    public static async requestSubscriberCache(pointer_id:string) {\n        // return existing cache\n        const existingCache = await this.getPointerSubscriberCache(pointer_id);\n        if (existingCache) return existingCache;\n        // create new cache\n        const id = this.subscriber_cache_prefix + pointer_id;\n        const subscribers = Pointer.createOrGet(new Set<Endpoint>()).val;\n        this.subscriberCaches.set(pointer_id, subscribers);\n        await this.setItem(id, subscribers);\n        return subscribers;\n    }\n\n    public static async getItemDecompiled(key:string, colorized = false, location?:StorageLocation) {\n        // try to find pointer at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(key))) {\n            if (loc==undefined) continue;\n            const val = await this.getItemDecompiledFromLocation(key, colorized, loc);\n            if (val !== NOT_EXISTING) return val;\n        }\n        return NOT_EXISTING;\n    }\n\n    public static async getItemDecompiledFromLocation(key:string, colorized = false, location:StorageLocation) {\n\t\tconst buffer = await location.getItemValueDXB(key);\n\t\tif (buffer != null) return MessageLogger.decompile(buffer, false, colorized);\n        return NOT_EXISTING;\n    }\n\n    public static async getItemKeys(location?:StorageLocation, prefix?: string){\n\n\t\t// for specific location\n\t\tif (location) return location.getItemKeys(prefix);\n\n\t\t// ... iterate over keys from all locations\n\n\t\tconst generators = [];\n\t\tfor (const location of this.#locations.keys()) {\n\t\t\tgenerators.push(await location.getItemKeys(prefix))\n\t\t}\n\n        return (function*(){\n            const used = new Set<string>();\n\n\t\t\tfor (const generator of generators) {\n\t\t\t\tfor (const key of generator) {\n                    if (used.has(key)) continue;\n                    used.add(key);\n                    yield key;\n                } \n\t\t\t}\n        })()\n    }\n\n\n    public static async getItemKeysStartingWith(prefix:string, location?:StorageLocation) {\n        const keyIterator = await Storage.getItemKeys(location, prefix);\n        return (function*(){\n            for (const key of keyIterator) {\n                if (key.startsWith(prefix)) yield key;\n            }\n        })()\n    }\n\n    public static async getItemCountStartingWith(prefix:string, location?:StorageLocation) {\n        const keyIterator = await Storage.getItemKeys(location, prefix);\n        let count = 0;\n        for (const key of keyIterator) {\n            if (key.startsWith(prefix)) count++;\n        }\n        return count\n    }\n\n    public static async supportsMatchQueries(type: Type) {\n        return (this.#primary_location?.supportsMatchSelection && await this.#primary_location?.supportsMatchForType!(type)) ?? false;\n    }\n\n    public static itemMatchQuery<T extends object, Options extends MatchOptions<T>>(itemPrefix: string, valueType:Type<T>, match: MatchInput<T>, options?:Options) {\n        options ??= {} as Options;\n        if (!this.#primary_location?.supportsMatchSelection) throw new Error(\"Primary storage location does not support match queries\");\n        return this.#primary_location!.matchQuery!(itemPrefix, valueType, match, options);\n    }\n\n\n    public static async getPointerIds(location?:StorageLocation){\n\n\t\t// for specific location\n\t\tif (location) return location.getPointerIds();\n\n\t\t// ... iterate over keys from all locations\n\n\t\tconst generators = [];\n\t\tfor (const location of this.#locations.keys()) {\n\t\t\tgenerators.push(await location.getPointerIds())\n\t\t}\n\n        return (function*(){\n            const used = new Set<string>();\n\n\t\t\tfor (const generator of generators) {\n\t\t\t\tfor (const id of generator) {\n                    if (used.has(id)) continue;\n                    used.add(id);\n                    yield id;\n                } \n\t\t\t}\n        })()         \n    }\n\n    private static async copyStorage(from:StorageLocation, to:StorageLocation) {\n\n        await this.clear(to);\n\n        const promises = [];\n        \n        for (const pointer_id of await this.getPointerIds(from)) {\n\t\t\tconst buffer = await from.getPointerValueDXB(pointer_id);\n\t\t\tif (!buffer) logger.error(\"could not copy empty pointer value: \" + pointer_id)\n\t\t\telse promises.push(to.setPointerValueDXB(pointer_id, buffer))\n        }\n\n        for (const key of await this.getItemKeys(from)) {\n            const buffer = await from.getItemValueDXB(key);\n\t\t\tif (!buffer) logger.error(\"could not copy empty item value: \" + key)\n\t\t\telse promises.push(to.setItemValueDXB(key, buffer))\n        }\n\n        await Promise.all(promises);\n    }\n\n    public static async getItem(key:string, location?:StorageLocation|undefined/* = this.#primary_location*/, conditions?: ExecConditions):Promise<any> {\n\n        if (this.#dirty) {\n            this.handleDirtyStateError();\n        }\n\n        // get from cache\n        if (Storage.cache.has(key)) return Storage.cache.get(key);\n\n        // try to find item at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(key))) {\n            if (loc==undefined) continue;\n            const val = await this.getItemFromLocation(key, loc, conditions);\n            if (val!==NOT_EXISTING) return val;\n        }\n\n        return undefined;\n    }\n\n\n    public static async getItemFromLocation(key:string, location:StorageLocation/* = this.#primary_location*/, conditions?: ExecConditions):Promise<any> {\n\n        if (!location.supportsExecConditions && conditions) throw new Error(`Storage Location ${location.name} does not support exec conditions`);\n\n\t\tconst val = await location.getItem(key, conditions);\n\t\tif (val == NOT_EXISTING) return NOT_EXISTING;\n\n\t\tStorage.cache.set(key, val);\n\t\tawait this.initItemFromTrustedLocation(key, val, location)\n\n\t\treturn val;\n    }\n\n    public static async getItemKey(value: any, location?:StorageLocation|undefined):Promise<string|undefined> {\n        // try to find item at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(\"\"))) {\n            if (loc==undefined) continue;\n            const val = await this.getItemKeyFromLocation(value, loc);\n            if (val !== undefined) return val;\n        }\n        return undefined;\n    }\n\n    public static getItemKeyFromLocation(value: any, location:StorageLocation):Promise<string|undefined>|string|undefined {\n        if (!location.supportsMatchSelection) throw new Error(`Storage Location ${location.name} does not support match queries (getItemKey)`);\n        return location.getItemKey?.(value);\n    }\n\n    \n    public static async hasItem(key:string, location?:StorageLocation):Promise<boolean> {\n        \n        if (Storage.cache.has(key)) return true; // get from cache\n \n        // try to find item at a storage location\n        for (const loc of (location!=undefined ? [location] : this.getLocationPriorityOrder(key))) {\n            if (loc==undefined) continue;\n            const val = await this.hasItemFromLocation(key, loc);\n            if (val) return true;\n        }\n\n        return false;\n    }\n\n    public static hasItemFromLocation(key:string, location:StorageLocation):Promise<boolean>|boolean {\n\t\tif (location)  {\n\t\t\treturn location.hasItem(key);\n\t\t}\n\t\telse return false;\n    }\n\n    /**\n     * Remove an item from storage, returns true if the item existed\n     */\n    public static async removeItem(key:string, location?:StorageLocation):Promise<boolean> {\n\n        logger.debug(\"Removing item '\" + key + \"' from storage\" + (location ? \" (\" + location.name + \")\" : \"\"))\n\n\t\t// remove from specific location\n\t\tif (location) {\n            // TODO: handle hasItem() internally in storage locations\n            const itemExists = await location.hasItem(key);\n            await location.removeItem(key);\n            return itemExists;\n        }\n\t\t// remove from all\n\t\telse {\n            Storage.cache.delete(key); // delete from cache\n            \n            let itemExists = false;\n\t\t\tfor (const location of this.#locations.keys()) {\n                // TODO: handle hasItem() internally in storage locations\n                if (!itemExists) itemExists = await location.hasItem(key);\n\t\t\t\tawait location.removeItem(key);\n\t\t\t}\n\n            // clear dependencies\n            this.updateItemDependencies(key, [])\n\n            return itemExists;\n\t\t}\n    }\n\n    /**\n     * Increase the reference count of a pointer in storage\n     */\n    private static increaseReferenceCount(ptrId:string) {\n        localStorage.setItem(this.rc_prefix+ptrId, (this.getReferenceCount(ptrId) + 1).toString());\n    }\n    /**\n     * Decrease the reference count of a pointer in storage\n     */\n    private static decreaseReferenceCount(ptrId:string) {\n        const newCount = this.getReferenceCount(ptrId) - 1;\n        // RC is 0, delete pointer from storage\n        if (newCount <= 0) {\n            localStorage.removeItem(this.rc_prefix+ptrId);\n            this.removePointer(ptrId, undefined, true)\n                .catch(e=>console.error(e))\n        }\n        // decrease RC\n        else localStorage.setItem(this.rc_prefix+ptrId, newCount.toString());\n    }\n    /**\n     * Get the current reference count of a pointer (number of entries that have a reference to this pointer)\n     * @returns \n     */\n    private static getReferenceCount(ptrId:string) {\n        const entry = localStorage.getItem(this.rc_prefix+ptrId);\n        return entry ? Number(entry) : 0;\n    }\n\n    private static addDependency(key:string, depPtrId:string, prefix:string) {\n        const uniqueKey = prefix+key;\n        if (localStorage.getItem(uniqueKey)?.includes(depPtrId)) return;\n        else localStorage.setItem(uniqueKey, (localStorage.getItem(uniqueKey) ?? \"\") + depPtrId);\n    }\n    private static removeDependency(key:string, depPtrId:string, prefix:string) {\n        const uniqueKey = prefix+key;\n        if (!localStorage.getItem(uniqueKey)?.includes(depPtrId)) return;\n        else {\n            const newDeps = localStorage.getItem(uniqueKey)!.replace(depPtrId, \"\");\n            // remove key if no more dependencies\n            if (newDeps.length == 0) localStorage.removeItem(uniqueKey);\n            // remove dependency\n            else localStorage.setItem(uniqueKey, newDeps);\n        }\n    }\n    private static setDependencies(key:string, depPtrIds:string[], prefix:string) {\n        const uniqueKey = prefix+key;\n        if (!depPtrIds.length) localStorage.removeItem(uniqueKey);\n        else localStorage.setItem(uniqueKey, depPtrIds.join(\",\"));\n    }\n\n    private static setItemDependencies(key:string, depPtrIds:string[]) {\n        this.setDependencies(key, depPtrIds, this.item_deps_prefix);\n    }\n    private static setPointerDependencies(key:string, depPtrIds:string[]) {\n        this.setDependencies(key, depPtrIds, this.pointer_deps_prefix);\n    }\n    private static getItemDependencies(key:string) {\n        const uniqueKey = this.item_deps_prefix+key;\n        return localStorage.getItem(uniqueKey)?.split(\",\") ?? [];\n    }\n    private static getPointerDependencies(key:string) {\n        const uniqueKey = this.pointer_deps_prefix+key;\n        return localStorage.getItem(uniqueKey)?.split(\",\") ?? [];\n    }\n\n    private static updateItemDependencies(key:string, newDeps:string[]) {\n        const oldDeps = this.getItemDependencies(key);\n        const added = newDeps.filter(p=>!oldDeps.includes(p));\n        const removed = oldDeps.filter(p=>!newDeps.includes(p));\n        for (const ptrId of added) this.increaseReferenceCount(ptrId);\n        for (const ptrId of removed) this.decreaseReferenceCount(ptrId);\n        this.setItemDependencies(key, newDeps);\n    }\n    private static updatePointerDependencies(key:string, newDeps:string[]) {\n        const oldDeps = this.getPointerDependencies(key);\n        const added = newDeps.filter(p=>!oldDeps.includes(p));\n        const removed = oldDeps.filter(p=>!newDeps.includes(p));\n        for (const ptrId of added) this.increaseReferenceCount(ptrId);\n        for (const ptrId of removed) this.decreaseReferenceCount(ptrId);\n        this.setPointerDependencies(key, newDeps);\n    }\n    \n\n    public static clearAll(){\n        return this.clear()\n    }\n\n    // clear all storages\n    public static async clear(onlyLocation?:StorageLocation):Promise<void> {\n\n\t\tfor (const location of this.#locations.keys()) {\n\t\t\tif (onlyLocation == undefined || location === onlyLocation) {\n\t\t\t\tthis.deleteSaveTime(location);\n\t\t\t\tthis.clearDirtyState(location)\n\t\t\t\tawait location.clear()\n\t\t\t}\n\t\t}\n\n        // remove internal localstorage entries\n        for (const key of Object.keys(localStorage)) {\n            if (key.startsWith(this.rc_prefix) || key.startsWith(this.item_deps_prefix) || key.startsWith(this.pointer_deps_prefix) || key.startsWith(this.meta_prefix)) {\n                localStorage.removeItem(key);\n            }\n        }\n\n    }\n\n    /**\n     * reset state, \n     */\n    public static async clearAndReload() {\n        await Storage.clearAll();\n        Storage.allowExitWithoutSave();\n        if (client_type === \"deno\") Deno.exit(1);\n        else if (globalThis.window?.location) {\n            globalThis.location.reload();\n        }\n        else logger.error(\"Could not reload in non-browser or Deno context\")\n    }\n\n    // load saved state\n    public static async loadOrCreate<T>(id:string|number, create?:()=>Promise<T>|T, conditions?: ExecConditions, override = false):Promise<MinimalJSRef<T>> {\n        const state_name = this.state_prefix+id.toString();\n\n        // already has a saved state\n        if (!override && await this.hasItem(state_name)) {\n            return await this.getItem(state_name, undefined, conditions)\n        }\n        // create state\n        else if (create){\n            const state = Pointer.createOrGet(await create());\n\n            // workaround: update item as soon as pointer id is changed with actual endpoint id (e.g. for Datex.Runtime.ENV)\n            if (Runtime.endpoint === LOCAL_ENDPOINT) {\n                Runtime.onEndpointChanged(() => {\n                    this.setItem(state_name, state.js_value, true);\n                })\n            }\n\n            await this.setItem(state_name, state.js_value, true);\n            return <any>state.js_value;\n        }\n        else throw new Error(\"Cannot find or create the state '\" + id + \"'\")\n    }\n\n\n    public static async printSnapshot(options: StorageSnapshotOptions = {internalItems: false, expandStorageMapsAndSets: true, onlyHeaders: false}) {\n        const {items, pointers} = await this.getSnapshot(options);\n\n        const COLOR_PTR = `\\x1b[38;2;${[65,102,238].join(';')}m`\n        const COLOR_NUMBER = `\\x1b[38;2;${[253,139,25].join(';')}m`\n\n        let string = ESCAPE_SEQUENCES.BOLD+\"Storage Locations\\n\\n\"+ESCAPE_SEQUENCES.RESET\n        string += `${ESCAPE_SEQUENCES.ITALIC}A list of all currently used storage locations and their corresponding store strategies.\\n${ESCAPE_SEQUENCES.RESET}`\n\n        for (const [location, options] of this.#locations) {\n            string += `\\n  • ${location.name} ${ESCAPE_SEQUENCES.GREY}(${options.modes.map(m=>Storage.Mode[m]).join(', ')})${ESCAPE_SEQUENCES.RESET}`\n        }\n\n        string += `\\n\\n${ESCAPE_SEQUENCES.BOLD}Trusted Location:${ESCAPE_SEQUENCES.RESET} ${this.#trusted_location?.name ?? \"none\"}`\n        string += `\\n${ESCAPE_SEQUENCES.BOLD}Primary Location:${ESCAPE_SEQUENCES.RESET} ${this.#primary_location?.name ?? \"none\"}`\n\n        console.log(string+\"\\n\\n\");\n\n        // pointers\n        string = ESCAPE_SEQUENCES.BOLD+\"Pointers\\n\\n\"+ESCAPE_SEQUENCES.RESET\n        string += `${ESCAPE_SEQUENCES.ITALIC}A list of all pointers stored in any storage location. Pointers are only stored as long as they are referenced somewhere else in the storage.\\n\\n${ESCAPE_SEQUENCES.RESET}`\n\n        const pointersInMemory = [...pointers.snapshot.keys()].filter(id => Pointer.get(id)).length;\n        string += `\\nTotal:     ${ESCAPE_SEQUENCES.BOLD}${pointers.snapshot.size}${ESCAPE_SEQUENCES.RESET} pointers`\n        string += `\\nIn memory: ${ESCAPE_SEQUENCES.BOLD}${pointersInMemory}${ESCAPE_SEQUENCES.RESET} pointers\\n\\n`\n\n        if (!options.onlyHeaders) {\n            for (const [key, storageMap] of pointers.snapshot) {\n                // check if stored in all locations, otherwise print in which location it is stored (functional programming)\n                const locations = [...storageMap.keys()]\n                const storedInAll = [...this.#locations.keys()].every(l => locations.includes(l));\n                \n                const value = [...storageMap.values()][0];\n                string += `  • ${COLOR_PTR}$${key}${ESCAPE_SEQUENCES.GREY}${storedInAll ? \"\" : (` (only in ${locations.map(l=>l.name).join(\",\")})`)} = ${value.replaceAll(\"\\n\", \"\\n    \")}\\n`\n            }\n        }\n        console.log(string+\"\\n\");\n\n        // items\n        string = ESCAPE_SEQUENCES.BOLD+\"Items\\n\\n\"+ESCAPE_SEQUENCES.RESET\n        string += `${ESCAPE_SEQUENCES.ITALIC}A list of all named items stored in any storage location.\\n\\n${ESCAPE_SEQUENCES.RESET}`\n\n        if (!options.onlyHeaders) {\n            for (const [key, storageMap] of items.snapshot) {\n                // check if stored in all locations, otherwise print in which location it is stored (functional programming)\n                const locations = [...storageMap.keys()]\n                const storedInAll = [...this.#locations.keys()].every(l => locations.includes(l));\n                \n                const value = [...storageMap.values()][0];\n                string += `  • ${key}${ESCAPE_SEQUENCES.GREY}${storedInAll ? \"\" : (` (only in ${locations.map(l=>l.name).join(\",\")})`)} = ${value}\\n`\n            }\n        }\n        console.log(string+\"\\n\");\n\n        // memory management\n        if (options?.internalItems) {\n            string = ESCAPE_SEQUENCES.BOLD+\"Memory Management\\n\\n\"+ESCAPE_SEQUENCES.RESET\n            string += `${ESCAPE_SEQUENCES.ITALIC}This section shows the reference count (rc::) of pointers and the dependencies (deps::) of items and pointers. The reference count of a pointer tracks the number of items and pointers that reference this pointer.\\n\\n${ESCAPE_SEQUENCES.RESET}`\n            let rc_string = \"\"\n            let item_deps_string = \"\"\n            let pointer_deps_string = \"\"\n            if (!options.onlyHeaders) {\n                for (let i = 0, len = localStorage.length; i < len; ++i ) {\n                    const key = localStorage.key(i)!;\n                    if (key.startsWith(this.rc_prefix)) {\n                        const ptrId = key.substring(this.rc_prefix.length);\n                        const count = this.getReferenceCount(ptrId);\n                        rc_string += `\\x1b[0m  • ${key} = ${COLOR_NUMBER}${count}\\n`\n                    }\n                    else if (key.startsWith(this.item_deps_prefix)) {\n                        const depsRaw = localStorage.getItem(key);\n                        // single entry\n                        if (!depsRaw?.includes(\",\")) {\n                            item_deps_string += `\\x1b[0m  • ${key} = (${COLOR_PTR}${depsRaw}\\x1b[0m)\\n`\n                        }\n                        // multiple entries\n                        else {\n                            let deps = localStorage.getItem(key)!.split(\",\").join(`\\x1b[0m,\\n      ${COLOR_PTR}$`)\n                            if (deps) deps = `      ${COLOR_PTR}$`+deps\n                            item_deps_string += `\\x1b[0m  • ${key} = (\\n${COLOR_PTR}${deps}\\x1b[0m\\n    )\\n`\n                        }\n                    }\n                    else if (key.startsWith(this.pointer_deps_prefix)) {\n                        const depsRaw = localStorage.getItem(key);\n                        // single entry\n                        if (!depsRaw?.includes(\",\")) {\n                            pointer_deps_string += `\\x1b[0m  • ${key} = (${COLOR_PTR}${depsRaw}\\x1b[0m)\\n`\n                        }\n                        // multiple entries\n                        else {\n                            let deps = localStorage.getItem(key)!.split(\",\").join(`\\x1b[0m,\\n      ${COLOR_PTR}$`)\n                            if (deps) deps = `      ${COLOR_PTR}$`+deps\n                            pointer_deps_string += `\\x1b[0m  • ${key} = (\\n${COLOR_PTR}${deps}\\x1b[0m\\n    )\\n`\n                        }\n                    }\n                }\n            }\n\n            string += rc_string + \"\\n\" + item_deps_string + \"\\n\" + pointer_deps_string;\n            console.log(string+\"\\n\");\n        }\n\n        // inconsistencies\n        if (pointers.inconsistencies.size > 0 || items.inconsistencies.size > 0) {\n            string = ESCAPE_SEQUENCES.BOLD+\"Inconsistencies\\n\\n\"+ESCAPE_SEQUENCES.RESET\n            string += `${ESCAPE_SEQUENCES.ITALIC}Inconsistencies between storage locations don't necessarily indicate that something is wrong. They can occur when a storage location is not updated immediately (e.g. when only using SAVE_ON_EXIT).\\n\\n${ESCAPE_SEQUENCES.RESET}`\n            \n            \n            if (!options.onlyHeaders) {\n                for (const [key, storageMap] of pointers.inconsistencies) {\n                    for (const [location, value] of storageMap) {\n                        string += `  • ${COLOR_PTR}$${key}${ESCAPE_SEQUENCES.GREY} (${(location.name+\")\").padEnd(15, \" \")} = ${value.replaceAll(\"\\n\", \"\\n    \")}\\n`\n                    }\n                    string += `\\n`\n                }\n                for (const [key, storageMap] of items.inconsistencies) {\n                    for (const [location, value] of storageMap) {\n                        string += `  • ${key}${ESCAPE_SEQUENCES.GREY} (${(location.name+\")\").padEnd(15, \" \")} = ${value}`\n                    }\n                    string += `\\n`\n                }\n            }\n\n            console.info(string+\"\\n\");\n        }\n        \n\n    }\n\n    public static removeTrailingSemicolon(str:string) {\n        // replace ; and reset sequences with nothing\n        return str.replace(/;(\\x1b\\[0m)?$/g, \"\")\n    }\n\n    public static async getSnapshot(options: StorageSnapshotOptions = {internalItems: false, expandStorageMapsAndSets: true}) {\n        const allowedPointerIds = options.itemFilter ? new Set<string>() : undefined;\n        const items = await this.createSnapshot(this.getItemKeys.bind(this), this.getItemDecompiled.bind(this), options.itemFilter, allowedPointerIds);\n        const pointers = await this.createSnapshot(this.getPointerIds.bind(this), this.getPointerDecompiledFromLocation.bind(this), options.itemFilter, allowedPointerIds);\n\n        // remove keys items that are unrelated to normal storage\n        for (const [key] of items.snapshot) {\n            if (key.startsWith(\"keys_\") || key.startsWith(\"hash_keys_\")) {\n                if (options.internalItems) {\n                    for (const [location, _value] of items.snapshot.get(key)!) {\n                        items.snapshot.get(key)!.set(location, \"...\" + ESCAPE_SEQUENCES.RESET);\n                    }\n                }\n                else items.snapshot.delete(key);\n            }\n        }\n\n        // additional pointer entries from storage maps/sets\n        const additionalEntries = new Set<string>();\n\n        // iterate over storage maps and sets and render all entries\n        if (options.expandStorageMapsAndSets) {\n            for (const [ptrId, storageMap] of pointers.snapshot) {\n                // display entry from first storage\n                const [location, value] = [...storageMap.entries()][0];\n\n                if (value.startsWith(\"\\x1b[38;2;50;153;220m<StorageMap>\") || value.startsWith(\"\\x1b[38;2;50;153;220m<StorageSet>\")) {\n                    const ptr = await Pointer.load(ptrId, undefined, true);\n                    if (ptr instanceof LazyPointer) {\n                        console.error(\"LazyPointer in StorageMap/StorageSet\");\n                        continue;\n                    }\n                    if (ptr.val instanceof StorageMap) {\n                        const map = ptr.val;\n                        const keyIterator = await this.getItemKeysStartingWith((map as any)._prefix)\n                        const pointerIds = new Set<string>();\n                        let inner = \"\";\n                        for await (const key of keyIterator) {\n                            const valString = await this.getItemDecompiled(key, true, location);\n                            if (valString === NOT_EXISTING) {\n                                logger.error(\"Invalid entry in storage (\" + location.name + \"): \" + key);\n                                continue;\n                            }\n                            const keyString = await this.getItemDecompiled('key.' + key, true, location);\n                            if (keyString === NOT_EXISTING) {\n                                logger.error(\"Invalid key in storage (\" + location.name + \"): \" + key);\n                                continue;\n                            }\n                            inner += `   ${this.removeTrailingSemicolon(keyString)}\\x1b[0m => ${this.removeTrailingSemicolon(valString)}\\n`\n\n                            // additional pointer ids included in value or key\n                            if (allowedPointerIds) {\n                                const valMatches = valString.match(/\\$[a-zA-Z0-9]+/g)??[]\n                                const keyMatches = keyString.match(/\\$[a-zA-Z0-9]+/g)??[];\n\n                                for (const match of valMatches) {\n                                    const id = match.substring(1);\n                                    pointerIds.add(id)\n                                    if (!allowedPointerIds.has(id)) additionalEntries.add(id);\n                                }\n                                for (const match of keyMatches) {\n                                    const id = match.substring(1);\n                                    if (!allowedPointerIds.has(id)) additionalEntries.add(id);\n                                \n                                }\n                            }\n                        }\n\n                        // size in memory / total size\n                        const totalSize = await (ptr.val as StorageMap<unknown,unknown>).getSize();\n                        const totalDirectPointerSize = pointerIds.size;\n                        const inMemoryPointersSize= [...pointerIds].filter(id => Pointer.get(id)).length;\n                        const sizeInfo = `   ${ESCAPE_SEQUENCES.GREY}total size: ${totalSize}, in memory: ${inMemoryPointersSize}/${totalDirectPointerSize} pointers${ESCAPE_SEQUENCES.RESET}\\n`\n\n                        // substring: remove last \\n\n                        if (inner) storageMap.set(location, \"\\x1b[38;2;50;153;220m<StorageMap> \\x1b[0m{\\n\"+sizeInfo+inner.substring(0, inner.length-1)+\"\\x1b[0m\\n}\")\n                    }\n                    else if (ptr.val instanceof StorageSet) {\n                        const set = ptr.val;\n                        const keyIterator = await this.getItemKeysStartingWith((set as any)._prefix)\n                        const pointerIds = new Set<string>();\n\n                        let inner = \"\";\n                        for await (const key of keyIterator) {\n                            const valString = await this.getItemDecompiled(key, true, location);\n                            if (valString === NOT_EXISTING) {\n                                logger.error(\"Invalid entry in storage (\" + location.name + \"): \" + key);\n                                continue;\n                            }\n                            inner += `   ${this.removeTrailingSemicolon(valString)},\\n`\n\n                            // additional pointer ids included in value\n                            if (allowedPointerIds) {\n                                const matches = valString.match(/\\$[a-zA-Z0-9]+/g)??[];\n                                for (const match of matches) {\n                                    const id = match.substring(1);\n                                    pointerIds.add(id)\n                                    if (!allowedPointerIds.has(id)) additionalEntries.add(id);\n                                }\n                            }\n                        }\n\n                        // size in memory / total size\n                        const totalSize = await (ptr.val as StorageSet<unknown>).getSize();\n                        const totalDirectPointerSize = pointerIds.size;\n                        const inMemoryPointersSize= [...pointerIds].filter(id => Pointer.get(id)).length;\n                        const sizeInfo = `   ${ESCAPE_SEQUENCES.GREY}total size: ${totalSize}, in memory: ${inMemoryPointersSize}/${totalDirectPointerSize} pointers${ESCAPE_SEQUENCES.RESET}\\n`\n\n                        // substring: remove last \\n\n                        if (inner) storageMap.set(location, \"\\x1b[38;2;50;153;220m<StorageSet> \\x1b[0m{\\n\"+sizeInfo+inner.substring(0, inner.length-1)+\"\\x1b[0m\\n}\")\n                    }\n                }\n            }\n        }\n\n        if (additionalEntries.size > 0) {\n            await this.createSnapshot(this.getPointerIds.bind(this), this.getPointerDecompiledFromLocation.bind(this), options.itemFilter, additionalEntries, {\n                snapshot: pointers.snapshot,\n                inconsistencies: pointers.inconsistencies\n            });\n        }\n\n        return {items, pointers}\n    }\n\n    private static async createSnapshot(\n        keyGenerator: (location?: StorageLocation<Storage.Mode> | undefined) => Promise<Generator<string, void, unknown>>,\n        itemGetter: (key: string, colorized: boolean, location: StorageLocation<Storage.Mode>) => Promise<string|symbol>,\n        filter?: string,\n        allowedPointerIds?: Set<string>,\n        baseSnapshot?: {\n            snapshot: AutoMap<string, Map<StorageLocation<Storage.Mode>, string>>;\n            inconsistencies: AutoMap<string, Map<StorageLocation<Storage.Mode>, string>>;\n        }\n    ) {\n        const snapshot = baseSnapshot?.snapshot ?? new Map<string, Map<StorageLocation, string>>().setAutoDefault(Map);\n        const inconsistencies = baseSnapshot?.inconsistencies ?? new Map<string, Map<StorageLocation, string>>().setAutoDefault(Map);\n\n        const skippedEntries = new Set<string>();\n        const additionalEntries = new Set<string>();\n\n        for (const location of new Set([this.#primary_location!, ...this.#locations.keys()].filter(l=>!!l))) {\n            for (const key of await keyGenerator(location)) {\n                if (filter && !key.includes(filter) && !allowedPointerIds?.has(key)) {\n                    if (allowedPointerIds) skippedEntries.add(key); // remember skipped entries that might be added later\n                    continue;\n                }\n                const decompiled = await itemGetter(key, true, location);\n\n                if (typeof decompiled !== \"string\") {\n                    console.error(\"Invalid entry in storage (\" + location.name + \"): \" + key);\n                    continue;\n                }\n\n                // collect referenced pointer ids\n                if (allowedPointerIds) {\n                    const matches = decompiled.match(/\\$[a-zA-Z0-9]+/g);\n                    if (matches) {\n                        for (const match of matches) {\n                            const id = match.substring(1);\n                            if (skippedEntries.has(id)) additionalEntries.add(id);\n                            allowedPointerIds.add(id);\n                        }\n                    }\n                }\n                snapshot.getAuto(key).set(location, this.removeTrailingSemicolon(decompiled));\n            }\n        }\n        \n        // run again with additional entries\n        if (additionalEntries.size > 0) {\n            await this.createSnapshot(keyGenerator, itemGetter, filter, additionalEntries, {\n                snapshot,\n                inconsistencies\n            });\n        }\n\n        // find inconsistencies\n        for (const [key, storageMap] of snapshot) {\n            const [location, value] = [...storageMap.entries()][0];\n            // compare with first entry\n            for (const [location2, value2] of storageMap) {\n                if (value !== value2) {\n                    inconsistencies.getAuto(key).set(location, value);\n                    inconsistencies.getAuto(key).set(location2, value2);\n                }\n            }\n        }\n\n        return {snapshot, inconsistencies};\n    }\n\n}\n\nsetStorage(Storage);\n\nexport namespace Storage {\n\n\texport enum Mode {\n        SAVE_ON_EXIT, // save pointers on program exit / tab close\n        SAVE_ON_CHANGE, // save a pointer immediately when the value changes\n        SAVE_PERIODICALLY // save in fix interval\n    }\n}\n\n\n// TODO: convert to static block (saFrari) --------------------------------------\n// // @ts-ignore NO_INIT\n// if (!globalThis.NO_INIT) {\n//     Storage.determineTrustedLocation([]);\n// }\n\n// @ts-ignore NO_INIT\nif (!globalThis.NO_INIT) {\n    if (client_type == \"deno\") addEventListener(\"unload\", ()=>Storage.handleExit(), {capture: true});\n    addPersistentListener(globalThis, \"beforeunload\", ()=>Storage.handleExit(), {capture: true})\n    // @ts-ignore document\n    if (globalThis.document) addEventListener(\"visibilitychange\", ()=>{\n        // @ts-ignore document\n        if (document.visibilityState === 'hidden') Storage.handleExit()\n    });\n    if (client_type == \"deno\") {\n        Deno.addSignalListener(\"SIGINT\", ()=>Deno.exit())\n        try {\n            // not supported by WiNdoWs\n            await Deno.addSignalListener(\"SIGTERM\", ()=>Deno.exit(1))\n            await Deno.addSignalListener(\"SIGQUIT\", ()=>Deno.exit())\n        }\n        catch {}\n    }\n}\n// ------------------------------------------------------------------------------\n\n// proxy for Storage\nclass DatexStoragePointerSource implements PointerSource {\n    getPointer(pointer_id:string, pointerify?:boolean, localOnly?: boolean) {\n        return Storage.getPointer(pointer_id, pointerify, undefined, undefined, localOnly ? {onlyLocalPointers: true} : undefined)\n    }\n    syncPointer(pointer:Pointer) {\n        return Storage.syncPointer(pointer)\n    }\n}\n\nexport function registerStorageAsPointerSource() {\n\tPointer.registerPointerSource(new DatexStoragePointerSource());\n}\n\n"],"names":["MatchConditionType","ComputedPropertyType","Storage","Mode","Runtime","logger","client_type","NOT_EXISTING","Pointer","localStorage","MessageLogger","Type","addPersistentListener","LOCAL_ENDPOINT","ESCAPE_SEQUENCES","verboseArg","StorageMap","StorageSet","IterableWeakSet","LazyPointer","hasDebugCookie","setStorage","KnownError","handleError","site_suffix","globalThis","location","origin","MatchCondition","type","data","between","lower","upper","lessThan","value","greaterThan","lessOrEqual","greaterOrEqual","notEqual","contains","values","Set","pointerId","id","Array","ComputedProperty","geographicDistance","pointA","pointB","sum","SyncStorageLocation","isAsync","onAfterExit","AsyncStorageLocation","cache","Map","state_prefix","pointer_prefix","item_prefix","meta_prefix","rc_prefix","pointer_deps_prefix","item_deps_prefix","subscriber_cache_prefix","providePointer","ptr","has","add","delete","isStored","DEFAULT_INTERVAL","trusted_location","undefined","debug","name","primary_location","locations","addLocation","options","set","interval","modes","includes","SAVE_PERIODICALLY","Error","mode","SAVE_ON_EXIT","isSupported","addSaveInterval","_loc","SAVE_ON_CHANGE","primary","map","m","join","determineTrustedLocation","restoreDirtyState","removeLocation","get","clearInterval","setInterval","saveCurrentState","handleExit","update","Promise","error","loc","saveDirtyState","dirtyValues","size","saveFile","allowExitWithoutSave","isExit","c","key","val","res","setItem","catch","e","setPointer","value_initialized","updateSaveTime","onAfterSnapshot","console","Date","getTime","toString","deleteSaveTime","removeItem","getSaveTime","Number","getItem","setDirty","dirty","metadata","currentCount","newCount","warn","isInDirtyState","clearDirtyState","fromLocations","keys","last","last_time","time","listen_for_pointer_changes","setItemAsync","setItemSync","isDebugMode","valueToDatexString","itemExisted","hasItem","dependencies","is_local","checkUnresolvedLocalDependenciesForItem","updateItemDependencies","p","saveDependencyPointersAsync","saveDependencyPointersSync","some","checkUnresolvedLocalDependenciesForPointer","pointer","updateEntriesWithUnresolvedLocalDependencies","clear","idString","listen_for_changes","partialUpdateKey","initPointerAsync","initPointerSync","garbage_collected","updatePointerSync","updatePointerDependencies","syncPointer","updatePointerAsync","hasPointer","all","synced_pointers","WeakSet","saving","handler","v","t","supportsPartialUpdates","scheduleStorageUpdate","then","couldSave","unobserve","observe","ignore_transforms","recursive","updateFn","clearTimeout","timeout","setTimeout","getLocationPriorityOrder","pointer_id","initPointerFromTrustedLocation","maybe_trusted_location","log","initItemFromTrustedLocation","copyStorage","handleDirtyStateError","description","fix","clearAndReload","subscriberCaches","getPointer","pointerify","bind","conditions","getPointerFromLocation","getPointerAsync","getPointerValue","ofValue","updateValue","transform_scope","createTransformAsync","internal_vars","setValue","create","endpoint","is_js_primitive","removePointer","force_remove","getReferenceCount","promises","push","removePointerSubscriberCache","getPointerDecompiled","colorized","getPointerDecompiledFromLocation","buffer","getPointerValueDXB","decompile","getPointerSubscriberCache","subscribers","requestSubscriberCache","existingCache","createOrGet","getItemDecompiled","getItemDecompiledFromLocation","getItemValueDXB","getItemKeys","prefix","generators","used","generator","getItemKeysStartingWith","keyIterator","startsWith","getItemCountStartingWith","count","supportsMatchQueries","supportsMatchSelection","supportsMatchForType","itemMatchQuery","itemPrefix","valueType","match","matchQuery","getPointerIds","from","to","setPointerValueDXB","setItemValueDXB","getItemFromLocation","supportsExecConditions","getItemKey","getItemKeyFromLocation","hasItemFromLocation","itemExists","increaseReferenceCount","ptrId","decreaseReferenceCount","entry","addDependency","depPtrId","uniqueKey","removeDependency","newDeps","replace","length","setDependencies","depPtrIds","setItemDependencies","setPointerDependencies","getItemDependencies","split","getPointerDependencies","oldDeps","added","filter","removed","clearAll","onlyLocation","Object","Deno","exit","window","reload","loadOrCreate","override","state_name","state","onEndpointChanged","js_value","printSnapshot","internalItems","expandStorageMapsAndSets","onlyHeaders","items","pointers","getSnapshot","COLOR_PTR","COLOR_NUMBER","string","BOLD","RESET","ITALIC","GREY","pointersInMemory","snapshot","storageMap","storedInAll","every","l","replaceAll","rc_string","item_deps_string","pointer_deps_string","i","len","substring","depsRaw","deps","inconsistencies","padEnd","info","removeTrailingSemicolon","str","allowedPointerIds","itemFilter","createSnapshot","_value","additionalEntries","entries","load","_prefix","pointerIds","inner","valString","keyString","valMatches","keyMatches","totalSize","getSize","totalDirectPointerSize","inMemoryPointersSize","sizeInfo","keyGenerator","itemGetter","baseSnapshot","setAutoDefault","skippedEntries","decompiled","matches","getAuto","location2","value2","NO_INIT","addEventListener","capture","document","visibilityState","addSignalListener","DatexStoragePointerSource","localOnly","onlyLocalPointers","registerStorageAsPointerSource","registerPointerSource"],"mappings":"IA8HYA,oBA+DAC,sBAspDKC,SAEJC;AAp1Db,SAASC,OAAO,QA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