|
| 1 | +namespace Partas.Solid.Primitives |
| 2 | + |
| 3 | +open System |
| 4 | +open Fable.Core |
| 5 | +open Fable.Core.JS |
| 6 | +open Fable.Core.JsInterop |
| 7 | +open Partas.Solid |
| 8 | +[<Erase; AutoOpen>] |
| 9 | +module StorageSpec = |
| 10 | + [<Erase>] |
| 11 | + module Spec = |
| 12 | + [<Literal>] |
| 13 | + let path = "@solid-primitives/storage" |
| 14 | + [<Literal>] |
| 15 | + let version = "4.3.2" |
| 16 | + |
| 17 | +type SyncStorage = |
| 18 | + abstract getItem: key: string -> string option |
| 19 | + abstract setItem: key: string * value: string -> unit |
| 20 | + abstract removeItem: key: string -> unit |
| 21 | + [<EmitIndexer>] |
| 22 | + abstract Item: string -> obj |
| 23 | +type AsyncStorage = |
| 24 | + abstract getItem: key: string -> Promise<string option> |
| 25 | + abstract setItem: key: string * value: string -> Promise<obj> |
| 26 | + abstract removeItem: key: string -> Promise<unit> |
| 27 | + [<EmitIndexer>] |
| 28 | + abstract Item: string -> obj |
| 29 | +type SyncStorageWithOptions<'Options> = |
| 30 | + abstract getItem: key: string * ?options: 'Options -> string option |
| 31 | + abstract setItem: key: string * value: string * ?options: 'Options -> unit |
| 32 | + abstract removeItem: key: string * ?options: 'Options -> unit |
| 33 | + [<EmitIndexer>] |
| 34 | + abstract Item: string -> obj |
| 35 | +type AsyncStorageWithOptions<'Options> = |
| 36 | + abstract getItem: key: string * ?options: 'Options -> Promise<string option> |
| 37 | + abstract setItem: key: string * value: string * ?options: 'Options -> Promise<obj> |
| 38 | + abstract removeItem: key: string * ?options: 'Options -> Promise<unit> |
| 39 | + [<EmitIndexer>] |
| 40 | + abstract Item: string -> obj |
| 41 | + |
| 42 | +type PersistenceSyncData = |
| 43 | + abstract key: string with get,set |
| 44 | + abstract newValue: string option with get,set |
| 45 | + abstract timeStamp: float with get,set |
| 46 | + abstract url: string option with get,set |
| 47 | +type PersistenceSyncCallback = PersistenceSyncData -> unit |
| 48 | +type PersistenceSyncSubscribe = PersistenceSyncCallback -> unit |
| 49 | +type PersistenceSyncUpdate = string * string option -> unit |
| 50 | +type PersistenceSyncAPI = PersistenceSyncSubscribe * PersistenceSyncUpdate |
| 51 | +[<Pojo>] |
| 52 | +type PersistenceOptions<'T, 'Options>( |
| 53 | + ?name: string |
| 54 | + ,?serialize: 'T -> string |
| 55 | + ,?deserialize: string -> 'T |
| 56 | + ,?sync: PersistenceSyncAPI |
| 57 | + ,?storage: U4<SyncStorage, AsyncStorage, SyncStorageWithOptions<'Options>, AsyncStorageWithOptions<'Options>> |
| 58 | + ,?storageOptions: 'Options |
| 59 | + ) = |
| 60 | + [<DefaultValue>] |
| 61 | + val mutable name: string |
| 62 | + [<DefaultValue>] |
| 63 | + val mutable serialize: 'T -> string |
| 64 | + [<DefaultValue>] |
| 65 | + val mutable deserialize: string -> 'T |
| 66 | + [<DefaultValue>] |
| 67 | + val mutable sync: PersistenceSyncAPI |
| 68 | + [<DefaultValue>] |
| 69 | + val mutable storage: U4<SyncStorage, AsyncStorage, SyncStorageWithOptions<'Options>, AsyncStorageWithOptions<'Options>> |
| 70 | + [<DefaultValue>] |
| 71 | + val mutable storageOptions: 'Options |
| 72 | + |
| 73 | +type PersistedState<'T> = Accessor<'T> * Setter<'T> * obj |
| 74 | + |
| 75 | + |
| 76 | +[<Erase; AutoOpen>] |
| 77 | +type Storage = |
| 78 | + [<ImportMember(Spec.path)>] |
| 79 | + static member makePersisted<'T>(signal: Signal<'T>, ?options: PersistenceOptions<'T, _>): PersistedState<'T> = jsNative |
| 80 | + [<ImportMember(Spec.path)>] |
| 81 | + static member storageSync: PersistenceSyncAPI = jsNative |
| 82 | + // TODO broadcast channel overload |
| 83 | + [<ImportMember(Spec.path)>] |
| 84 | + static member messageSync(?channel: Browser.Types.Window): PersistenceSyncAPI = jsNative |
| 85 | + // TODO |
| 86 | + // [<ImportMember(Spec.path)>] |
| 87 | + // static member wsSync(ws: WebSocket, ?warnOnError: bool): PersistenceSyncAPI = jsNative |
| 88 | + [<ImportMember(Spec.path)>] |
| 89 | + static member multiplexSync([<ParamArray>] syncAPIs: PersistenceSyncAPI[]): PersistenceSyncAPI = jsNative |
0 commit comments