@solid-primitives/storage
Advanced tools
Comparing version 3.4.0 to 3.5.0
@@ -266,3 +266,3 @@ import { Accessor, Setter, Signal } from 'solid-js'; | ||
]; | ||
type PersistenceBaseOptions<T> = { | ||
type PersistenceOptions<T, O extends Record<string, any> | undefined> = { | ||
name?: string; | ||
@@ -272,9 +272,9 @@ serialize?: (data: T) => string; | ||
sync?: PersistenceSyncAPI; | ||
}; | ||
type PersistenceOptions<T, O extends Record<string, any>> = PersistenceBaseOptions<T> & ({ | ||
} & (undefined extends O ? { | ||
storage?: Storage | AsyncStorage; | ||
} : { | ||
storage: StorageWithOptions<O> | AsyncStorageWithOptions<O>; | ||
storageOptions: O; | ||
} | { | ||
storage?: Storage | AsyncStorage; | ||
storageOptions?: O; | ||
}); | ||
type SignalType<S extends Signal<any> | [Store<any>, SetStoreFunction<any>]> = S extends Signal<infer T> ? T : S extends [Store<infer T>, SetStoreFunction<infer T>] ? T : never; | ||
/** | ||
@@ -300,67 +300,5 @@ * Persists a signal, store or similar API | ||
*/ | ||
declare function makePersisted<T>(signal: [Accessor<T>, Setter<T>], options?: PersistenceOptions<T, {}>): [Accessor<T>, Setter<T>]; | ||
declare function makePersisted<S extends Signal<any> | [Store<any>, SetStoreFunction<any>]>(signal: S, options?: PersistenceOptions<SignalType<S>, undefined>): S; | ||
declare function makePersisted<S extends Signal<any> | [Store<any>, SetStoreFunction<any>], O extends Record<string, any>>(signal: S, options: PersistenceOptions<SignalType<S>, O>): S; | ||
/** | ||
* 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<T> | [get: Store<T>, set: SetStoreFunction<T>]} signal - The signal or store to be persisted. | ||
* @param {PersistenceOptions<T, O>} options - The options for persistence. | ||
* @returns {Signal<T> | [get: Store<T>, set: SetStoreFunction<T>]} - The persisted signal or store. | ||
*/ | ||
declare function makePersisted<T, O extends Record<string, any>>(signal: Signal<T>, options: PersistenceOptions<T, O>): Signal<T>; | ||
/** | ||
* 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<T> | [get: Store<T>, set: SetStoreFunction<T>]} signal - The signal or store to be persisted. | ||
* @param {PersistenceOptions<T, O>} options - The options for persistence. | ||
* @returns {Signal<T> | [get: Store<T>, set: SetStoreFunction<T>]} - The persisted signal or store. | ||
*/ | ||
declare function makePersisted<T>(signal: [get: Store<T>, set: SetStoreFunction<T>], options?: PersistenceOptions<T, {}>): [get: Store<T>, set: SetStoreFunction<T>]; | ||
/** | ||
* 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<T> | [get: Store<T>, set: SetStoreFunction<T>]} signal - The signal or store to be persisted. | ||
* @param {PersistenceOptions<T, O>} options - The options for persistence. | ||
* @returns {Signal<T> | [get: Store<T>, set: SetStoreFunction<T>]} - The persisted signal or store. | ||
*/ | ||
declare function makePersisted<T, O extends Record<string, any>>(signal: [get: Store<T>, set: SetStoreFunction<T>], options: PersistenceOptions<T, O>): [get: Store<T>, set: SetStoreFunction<T>]; | ||
/** | ||
* storageSync - synchronize localStorage | ||
@@ -388,2 +326,2 @@ * This does only work for { storage: localStorage }. | ||
export { type AnyStorageProps, type AsyncStorage, type AsyncStorageObject, type AsyncStorageSetter, type AsyncStorageWithOptions, type CookieOptions, type PersistenceBaseOptions, type PersistenceOptions, type PersistenceSyncAPI, type PersistenceSyncCallback, type PersistenceSyncData, type StorageDeserializer, type StorageObject, type StorageProps, type StorageSerializer, type StorageSetter, type StorageSignalProps, type StorageWithOptions, type StringStorageProps, addClearMethod, addWithOptionsMethod, cookieStorage, createAsyncStorage, createCookieStorage, createLocalStorage, createSessionStorage, createStorage, createStorageSignal, makePersisted, messageSync, multiplexStorage, multiplexSync, storageSync, tauriStorage, wsSync }; | ||
export { type AnyStorageProps, type AsyncStorage, type AsyncStorageObject, type AsyncStorageSetter, type AsyncStorageWithOptions, type CookieOptions, type PersistenceOptions, type PersistenceSyncAPI, type PersistenceSyncCallback, type PersistenceSyncData, type StorageDeserializer, type StorageObject, type StorageProps, type StorageSerializer, type StorageSetter, type StorageSignalProps, type StorageWithOptions, type StringStorageProps, addClearMethod, addWithOptionsMethod, cookieStorage, createAsyncStorage, createCookieStorage, createLocalStorage, createSessionStorage, createStorage, createStorageSignal, makePersisted, messageSync, multiplexStorage, multiplexSync, storageSync, tauriStorage, wsSync }; |
{ | ||
"name": "@solid-primitives/storage", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "Primitive that provides reactive wrappers for storage access", | ||
@@ -5,0 +5,0 @@ "author": "Alex Lohr <alex.lohr@logmein.com>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90101
1616