@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-storage

Generate 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-storage

Usage#

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#

ImportKey exports
@solidnative-dev/storagecreateKeyValueStorage, KeyValueStorage, KeyValueStorageAdapter, KEY_VALUE_STORAGE_MAX_KEY_LENGTH (1024)
@solidnative-dev/storage/async-storage-3createAsyncStorage3KeyValueStorage, AsyncStorage3NativeModule, AsyncStorage3KeyValueStorageOptions

Behavior & platform notes#

  • Narrow native seam: Only getValues, setValues, and removeValues cross 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-storage for tokens and credentials.
  • Construct on demand: AsyncStorage 3's iOS implementation embeds a Kotlin/Native SharedAsyncStorage framework whose runtime stays active once initialized. If you do not need storage before first paint, construct the adapter lazily.