import type { Accessor, Setter, Signal } from "solid-js"; import type { SetStoreFunction, Store } from "solid-js/store"; export type SyncStorage = { getItem: (key: string) => string | null; setItem: (key: string, value: string) => void; removeItem: (key: string) => void; [key: string]: any; }; export type AsyncStorage = { getItem: (key: string) => Promise; setItem: (key: string, value: string) => Promise; removeItem: (key: string) => Promise; [key: string]: any; }; export type SyncStorageWithOptions = undefined extends O ? { getItem: (key: string, options?: O) => string | null; setItem: (key: string, value: string, options?: O) => void; removeItem: (key: string, options?: O) => void; [key: string]: any; } : { getItem: (key: string, options: O) => string | null; setItem: (key: string, value: string, options: O) => void; removeItem: (key: string, options: O) => void; [key: string]: any; }; export type AsyncStorageWithOptions = undefined extends O ? { getItem: (key: string, options?: O) => Promise; setItem: (key: string, value: string, options?: O) => Promise; removeItem: (key: string, options?: O) => Promise; [key: string]: any; } : { getItem: (key: string, options: O) => Promise; setItem: (key: string, value: string, options: O) => Promise; removeItem: (key: string, options: O) => Promise; [key: string]: any; }; export type PersistenceSyncData = { key: string; newValue: string | null | undefined; timeStamp: number; url?: string; }; export type PersistenceSyncCallback = (data: PersistenceSyncData) => void; export type PersistenceSyncAPI = [ /** subscribes to sync */ subscribe: (subscriber: PersistenceSyncCallback) => void, update: (key: string, value: string | null | undefined) => void ]; export type PersistenceOptions | undefined> = { name?: string; serialize?: (data: T) => string; deserialize?: (data: string) => T; sync?: PersistenceSyncAPI; } & (undefined extends O ? { storage?: SyncStorage | AsyncStorage; } : { storage: SyncStorageWithOptions | AsyncStorageWithOptions; storageOptions?: O; }); export type SignalInput = Signal | [Store, SetStoreFunction]; export type SignalType = S extends Signal ? T : S extends [Store, SetStoreFunction] ? T : never; export type PersistedState = S extends Signal ? [get: Accessor, set: Setter, init: Promise | string | null] : S extends [Store, SetStoreFunction] ? [get: Store, set: SetStoreFunction, init: Promise | string | null] : never; /** * Persists a signal, store or similar API * ```ts * const [getter, setter] = makePersisted(createSignal("data"), options); * const options = { * storage: cookieStorage, // can be any synchronous or asynchronous storage * storageOptions: { ... }, // for storages with options, otherwise not needed * name: "solid-data", // optional * serialize: (value: string) => value, // optional * deserialize: (data: string) => data, // optional * }; * ``` * Can be used with `createSignal` or `createStore`. The initial value from the storage will overwrite the initial * value of the signal or store unless overwritten. Overwriting a signal with `null` or `undefined` will remove the * item from the storage. * * @param {Signal | [get: Store, set: SetStoreFunction]} signal - The signal or store to be persisted. * @param {PersistenceOptions} options - The options for persistence. * @returns {PersistedState} - The persisted signal or store. */ export declare function makePersisted(signal: S, options?: PersistenceOptions, undefined>): PersistedState; export declare function makePersisted>(signal: S, options: PersistenceOptions, O>): PersistedState; /** * storageSync - synchronize localStorage * This does only work for { storage: localStorage }. * If you wish to use e.g. cookieStorage, you may use a different sync method */ export declare const storageSync: PersistenceSyncAPI; /** * messageSync - synchronize over post message or broadcast channel API */ export declare const messageSync: (channel?: Window | BroadcastChannel) => PersistenceSyncAPI; /** * wsSync - syncronize persisted storage via web socket */ export declare const wsSync: (ws: WebSocket, warnOnError?: boolean) => PersistenceSyncAPI; /** * multiplex arbitrary sync APIs * * ```ts * makePersisted(createSignal(0), { sync: multiplexSync(messageSync(bc), wsSync(ws)) }) * ``` */ export declare const multiplexSync: (...syncAPIs: PersistenceSyncAPI[]) => PersistenceSyncAPI;