UNPKG

@stainless-code/persist

Version:

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

44 lines (43 loc) • 1.75 kB
import { f as StateStorage, u as PersistStorage } from "../persist-core-B649IGlX.mjs"; import { MMKV } from "react-native-mmkv"; //#region src/adapters/backends/mmkv.d.ts /** * `StateStorage` over a `react-native-mmkv` `MMKV` instance — synchronous, * string-wire. Pass an instance from `createMMKV({ id, encryptionKey?, path? })`. * * @example * ```ts * import { createMMKV } from "react-native-mmkv"; * import { mmkvStateStorage } from "@stainless-code/persist/backends/mmkv"; * * const instance = createMMKV({ id: "app-prefs" }); * const storage = mmkvStateStorage(instance); * ``` */ declare function mmkvStateStorage(instance: MMKV): StateStorage; interface MmkvStorageOptions { /** MMKV instance id — namespaces persisted state into its own file. */ id: string; /** Custom MMKV root path. */ path?: string; /** Encryption key (max 16 bytes) — MMKV encrypts the file at rest. */ encryptionKey?: string; } /** * Build a JSON-encoded `PersistStorage` over a fresh `react-native-mmkv` * instance. Synchronous backend → hydration settles before first render → * no `useHydrated` gate required (unlike IndexedDB / AsyncStorage). MMKV is * the fastest RN KV store; pair `encryptionKey` for secrets-at-rest. * * @example * ```ts * import { createMmkvStorage } from "@stainless-code/persist/backends/mmkv"; * import { persistStore } from "@stainless-code/persist/sources/tanstack-store"; * * const storage = createMmkvStorage<Prefs>({ id: "app-prefs" })!; * persistStore(store, { name: "app:prefs:v1", storage }); * ``` */ declare function createMmkvStorage<S>(options: MmkvStorageOptions): PersistStorage<S> | undefined; //#endregion export { MmkvStorageOptions, createMmkvStorage, mmkvStateStorage };