@solidnative-dev/storage
Validated asynchronous key-value storage for Solid Native applications. Portable application and navigation code depend on KeyValueStorage, while versioned native ABI adapters remain explicit subpath imports.
Installation#
sh
pnpm add @solidnative-dev/storage @react-native-async-storage/async-storageGenerate the typed native binding for your app so AsyncStorage's React-facing JS wrapper never enters the bundle:
sh
sn generate --platform all --solid-library @react-native-async-storage/async-storageUsage#
ts
import { createAsyncStorage3KeyValueStorage } from "@solidnative-dev/storage/async-storage-3";
import { requireRNAsyncStorageNativeModule } from "./generated/SolidNativeBindings";
import * as TurboModuleRegistry from "react-native/Libraries/TurboModule/TurboModuleRegistry";
const native = requireRNAsyncStorageNativeModule(TurboModuleRegistry);
const storage = createAsyncStorage3KeyValueStorage(native, {
databaseName: "application",
prefix: "solid-native",
});
await storage.setItem("theme", "dark");
const theme = await storage.getItem("theme");
await storage.removeItem("theme");The returned KeyValueStorage also plugs directly into @solidnative-dev/navigation persistence:
ts
const launch = await createNativeHistoryFromStorage({
storage,
storageKey: "navigation",
});
const persistence = createNativeHistoryPersistence(launch.history, storage, {
storageKey: "navigation",
});Entrypoints#
| Import | Key exports |
|---|---|
@solidnative-dev/storage | createKeyValueStorage, KeyValueStorage, KeyValueStorageAdapter, KEY_VALUE_STORAGE_MAX_KEY_LENGTH (1024) |
@solidnative-dev/storage/async-storage-3 | createAsyncStorage3KeyValueStorage, AsyncStorage3NativeModule, AsyncStorage3KeyValueStorageOptions |
Behavior & platform notes#
- Narrow native seam: Only
getValues,setValues, andremoveValuescross into the adapter. Database names, keys (up to 1,024 chars), and returned values are validated before reaching application state. - Not for secrets: Values are stored unencrypted. Use
@solidnative-dev/secure-storagefor tokens and credentials. - Construct on demand: AsyncStorage 3's iOS implementation embeds a Kotlin/Native
SharedAsyncStorageframework whose runtime stays active once initialized. If you do not need storage before first paint, construct the adapter lazily.