@storesjs/stores 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1583 -4
- package/dist/native/index.js +7 -1
- package/dist/native/index.mjs +7 -1
- package/dist/plugins/chrome/index.d.ts +186 -4
- package/dist/vanilla/index.js +1 -1
- package/dist/vanilla/index.mjs +1 -1
- package/dist/vanilla/index.vanilla.d.ts +1469 -1
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +2 -1
- package/dist/web/internal/runtime.mjs +2 -1
- package/dist/web/queryParam-Ckp7Zi5t.mjs +1 -0
- package/dist/web/queryParam-Ctnhipnd.js +1 -0
- package/dist/web/serialization-BgaGfw_1.mjs +1 -0
- package/dist/web/serialization-Dau9pNHc.js +1 -0
- package/dist/web/utils-Ba1RIeAA.mjs +1 -0
- package/dist/web/utils-CwejruRb.js +1 -0
- package/package.json +7 -7
- package/dist/createBaseStore.d.ts +0 -36
- package/dist/createDerivedStore.d.ts +0 -63
- package/dist/createQueryStore.d.ts +0 -117
- package/dist/createVirtualStore.d.ts +0 -40
- package/dist/env.native.d.ts +0 -7
- package/dist/env.web.d.ts +0 -7
- package/dist/hooks/useLazyRef.d.ts +0 -13
- package/dist/hooks/useListen.d.ts +0 -98
- package/dist/hooks/useStableValue.d.ts +0 -16
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +0 -5
- package/dist/index.shared.d.ts +0 -14
- package/dist/index.vanilla.d.ts +0 -2
- package/dist/internal/baseStore.d.ts +0 -2
- package/dist/internal/config.d.ts +0 -64
- package/dist/internal/createStoreActions.d.ts +0 -24
- package/dist/internal/derivedStore/cascadeScheduler.d.ts +0 -31
- package/dist/internal/derivedStore/deriveProxy.d.ts +0 -15
- package/dist/internal/derivedStore/pathFinder.d.ts +0 -26
- package/dist/internal/derivedStore.d.ts +0 -2
- package/dist/internal/errors.d.ts +0 -10
- package/dist/internal/logger.d.ts +0 -10
- package/dist/internal/middleware/createHydrationGate.d.ts +0 -20
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +0 -8
- package/dist/internal/queryStore.d.ts +0 -2
- package/dist/internal/runtime.d.ts +0 -13
- package/dist/internal/signal.d.ts +0 -12
- package/dist/internal/storage/storageCreators.d.ts +0 -12
- package/dist/internal/storeUtils.d.ts +0 -46
- package/dist/internal/sync/browserSyncEngine.d.ts +0 -3
- package/dist/internal/sync/noopSyncEngine.d.ts +0 -3
- package/dist/internal/sync/syncEnhancer.d.ts +0 -26
- package/dist/internal/sync/syncUtils.d.ts +0 -6
- package/dist/internal/utils/persistUtils.d.ts +0 -9
- package/dist/internal/virtualStore.d.ts +0 -2
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +0 -30
- package/dist/plugins/chrome/chromeStorageAdapter.d.ts +0 -31
- package/dist/plugins/chrome/createSyncedChromeStorage.d.ts +0 -14
- package/dist/queryStore/classes/SubscriptionManager.d.ts +0 -67
- package/dist/queryStore/queryKey.d.ts +0 -3
- package/dist/queryStore/signalTypes.d.ts +0 -14
- package/dist/queryStore/types.d.ts +0 -403
- package/dist/storage/storageTypes.d.ts +0 -13
- package/dist/store/attachStoreHook.react.d.ts +0 -5
- package/dist/store/attachStoreHook.vanilla.d.ts +0 -6
- package/dist/store/batchStoreNotifications.native.d.ts +0 -3
- package/dist/store/batchStoreNotifications.web.d.ts +0 -2
- package/dist/store/createStore.d.ts +0 -6
- package/dist/store/persist.d.ts +0 -14
- package/dist/store/stateUpdate.d.ts +0 -10
- package/dist/store/types.d.ts +0 -108
- package/dist/storesStorage.native.d.ts +0 -3
- package/dist/storesStorage.web.d.ts +0 -3
- package/dist/sync/types.d.ts +0 -115
- package/dist/types/functions.d.ts +0 -24
- package/dist/types/objects.d.ts +0 -11
- package/dist/types/setState.d.ts +0 -22
- package/dist/types/subscribe.d.ts +0 -28
- package/dist/types/useStoreCallSignatures.d.ts +0 -2
- package/dist/types/useStoreCallSignatures.react.d.ts +0 -6
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +0 -2
- package/dist/types/utils.d.ts +0 -13
- package/dist/types.d.ts +0 -286
- package/dist/utils/core.d.ts +0 -26
- package/dist/utils/createAsyncMicrotaskScheduler.d.ts +0 -35
- package/dist/utils/createMicrotaskScheduler.d.ts +0 -28
- package/dist/utils/debounce.d.ts +0 -22
- package/dist/utils/equality.d.ts +0 -38
- package/dist/utils/hydrationCoordinator.d.ts +0 -13
- package/dist/utils/promiseUtils.d.ts +0 -2
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/stringUtils.d.ts +0 -7
- package/dist/utils/time.d.ts +0 -37
- package/dist/vanilla/createBaseStore.d.ts +0 -35
- package/dist/vanilla/createDerivedStore.d.ts +0 -62
- package/dist/vanilla/createQueryStore.d.ts +0 -116
- package/dist/vanilla/createVirtualStore.d.ts +0 -39
- package/dist/vanilla/env.web.d.ts +0 -6
- package/dist/vanilla/index.d.ts +0 -1
- package/dist/vanilla/index.shared.d.ts +0 -13
- package/dist/vanilla/internal/baseStore.d.ts +0 -1
- package/dist/vanilla/internal/config.d.ts +0 -63
- package/dist/vanilla/internal/createStoreActions.d.ts +0 -23
- package/dist/vanilla/internal/derivedStore/cascadeScheduler.d.ts +0 -30
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +0 -14
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +0 -25
- package/dist/vanilla/internal/derivedStore.d.ts +0 -1
- package/dist/vanilla/internal/errors.d.ts +0 -9
- package/dist/vanilla/internal/logger.d.ts +0 -9
- package/dist/vanilla/internal/middleware/createHydrationGate.d.ts +0 -19
- package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +0 -7
- package/dist/vanilla/internal/queryStore.d.ts +0 -1
- package/dist/vanilla/internal/runtime.d.ts +0 -12
- package/dist/vanilla/internal/signal.d.ts +0 -11
- package/dist/vanilla/internal/storage/storageCreators.d.ts +0 -11
- package/dist/vanilla/internal/storeUtils.d.ts +0 -45
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/syncEnhancer.d.ts +0 -25
- package/dist/vanilla/internal/utils/persistUtils.d.ts +0 -8
- package/dist/vanilla/internal/virtualStore.d.ts +0 -1
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +0 -66
- package/dist/vanilla/queryStore/queryKey.d.ts +0 -2
- package/dist/vanilla/queryStore/signalTypes.d.ts +0 -13
- package/dist/vanilla/queryStore/types.d.ts +0 -402
- package/dist/vanilla/storage/storageTypes.d.ts +0 -12
- package/dist/vanilla/store/attachStoreHook.d.ts +0 -5
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +0 -5
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +0 -1
- package/dist/vanilla/store/createStore.d.ts +0 -5
- package/dist/vanilla/store/persist.d.ts +0 -13
- package/dist/vanilla/store/stateUpdate.d.ts +0 -9
- package/dist/vanilla/store/types.d.ts +0 -107
- package/dist/vanilla/storesStorage.web.d.ts +0 -2
- package/dist/vanilla/sync/types.d.ts +0 -114
- package/dist/vanilla/types/functions.d.ts +0 -23
- package/dist/vanilla/types/objects.d.ts +0 -10
- package/dist/vanilla/types/setState.d.ts +0 -21
- package/dist/vanilla/types/subscribe.d.ts +0 -27
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +0 -1
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +0 -1
- package/dist/vanilla/types/utils.d.ts +0 -12
- package/dist/vanilla/types.d.ts +0 -285
- package/dist/vanilla/utils/core.d.ts +0 -25
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +0 -34
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +0 -27
- package/dist/vanilla/utils/debounce.d.ts +0 -21
- package/dist/vanilla/utils/equality.d.ts +0 -37
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +0 -12
- package/dist/vanilla/utils/promiseUtils.d.ts +0 -1
- package/dist/vanilla/utils/serialization.d.ts +0 -13
- package/dist/vanilla/utils/stringUtils.d.ts +0 -6
- package/dist/vanilla/utils/time.d.ts +0 -36
- package/dist/web/chunk-QJLWBD7M.mjs +0 -1
- package/dist/web/chunk-V4LHP7LR.mjs +0 -1
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { SetStateArgs, SetStateOverloads } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Calls a `setState` function with captured `setState` arguments.
|
|
4
|
-
*/
|
|
5
|
-
export declare function applySetState<S, SetReturn extends Promise<void> | void>(set: SetStateOverloads<S, SetReturn>, args: SetStateArgs<S>): SetReturn;
|
|
6
|
-
/**
|
|
7
|
-
* Applies a `setState` payload to the current state.
|
|
8
|
-
*/
|
|
9
|
-
export declare function applyStateUpdate<S>(state: S, ...setArgs: SetStateArgs<S>): S;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import type { StorageValue } from '../storage/storageTypes';
|
|
2
|
-
import type { SetStateOverloads } from '../types/setState';
|
|
3
|
-
import type { SubscribeOverloads } from '../types/subscribe';
|
|
4
|
-
/**
|
|
5
|
-
* Store object contract shared by creators, middleware, and internal store utilities.
|
|
6
|
-
*/
|
|
7
|
-
export type StoreApi<S> = {
|
|
8
|
-
getInitialState: () => S;
|
|
9
|
-
getState: () => S;
|
|
10
|
-
setState: SetStateOverloads<S>;
|
|
11
|
-
subscribe: SubscribeOverloads<S>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Callback that builds store state from the set/get/store API supplied during construction.
|
|
15
|
-
*/
|
|
16
|
-
export type StateCreator<S, Mutators extends StoreMutators = [], StoreMutatorOutput extends StoreMutators = [], U = S> = ((setState: Get<Mutate<StoreApi<S>, Mutators>, 'setState', never>, getState: Get<Mutate<StoreApi<S>, Mutators>, 'getState', never>, store: Mutate<StoreApi<S>, Mutators>) => U) & {
|
|
17
|
-
$$storeMutators?: StoreMutatorOutput;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Synchronous storage adapter consumed by the persistence wrapper.
|
|
21
|
-
*/
|
|
22
|
-
export type SyncPersistStorage<State, PersistedState = Partial<State>> = {
|
|
23
|
-
getItem: (name: string) => StorageValue<PersistedState> | null;
|
|
24
|
-
removeItem: (name: string) => void;
|
|
25
|
-
setItem: (name: string, state: State, version: number | undefined) => void;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Asynchronous storage adapter consumed by the persistence wrapper.
|
|
29
|
-
*/
|
|
30
|
-
export type AsyncPersistStorage<State, PersistedState = Partial<State>> = {
|
|
31
|
-
getItem: (name: string) => Promise<StorageValue<PersistedState> | null>;
|
|
32
|
-
removeItem: (name: string) => Promise<void>;
|
|
33
|
-
setItem: (name: string, state: State, version: number | undefined) => Promise<void>;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Accepted storage adapter types for sync or async persistence.
|
|
37
|
-
*/
|
|
38
|
-
export type PersistStorage<State, PersistedState = Partial<State>> = AsyncPersistStorage<State, PersistedState> | SyncPersistStorage<State, PersistedState>;
|
|
39
|
-
/**
|
|
40
|
-
* Resolved storage config for persisted stores.
|
|
41
|
-
*/
|
|
42
|
-
export type PersistStorageConfig<State, PersistedState extends Partial<State>> = {
|
|
43
|
-
async: false;
|
|
44
|
-
persistStorage: SyncPersistStorage<State, PersistedState>;
|
|
45
|
-
version: number;
|
|
46
|
-
} | {
|
|
47
|
-
async: true;
|
|
48
|
-
persistStorage: AsyncPersistStorage<State, PersistedState>;
|
|
49
|
-
version: number;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Persistence options consumed by the persistence wrapper.
|
|
53
|
-
*/
|
|
54
|
-
export type PersistOptions<S, PersistedState = Partial<S>> = {
|
|
55
|
-
merge?: (persistedState: PersistedState | undefined, currentState: S) => S;
|
|
56
|
-
migrate?: (persistedState: PersistedState, version: number) => PersistedState | Promise<PersistedState>;
|
|
57
|
-
name: string;
|
|
58
|
-
onRehydrateStorage?: (state: S) => ((state?: S, error?: unknown) => void) | void;
|
|
59
|
-
skipHydration?: boolean;
|
|
60
|
-
storage: PersistStorage<S, PersistedState>;
|
|
61
|
-
version: number;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Methods attached by the persistence wrapper before async hydration state is added.
|
|
65
|
-
*/
|
|
66
|
-
export type PersistMethods<S, PersistedState> = {
|
|
67
|
-
clearStorage: () => void;
|
|
68
|
-
getOptions: () => Partial<PersistOptions<S, PersistedState>>;
|
|
69
|
-
hasHydrated: () => boolean;
|
|
70
|
-
onHydrate: (listener: (state: S) => void) => () => void;
|
|
71
|
-
onFinishHydration: (listener: (state: S) => void) => () => void;
|
|
72
|
-
rehydrate: () => Promise<void> | void;
|
|
73
|
-
setOptions: (options: Partial<PersistOptions<S, PersistedState>>) => void;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Store shape after the persistence wrapper adds persistence methods, write-through `setState`,
|
|
77
|
-
* and async hydration state when applicable.
|
|
78
|
-
*/
|
|
79
|
-
export type WithPersist<Store, PersistedState, PersistReturn extends void | Promise<void>> = Store extends StoreApi<infer S> ? Write<Store, {
|
|
80
|
-
persist: PersistMethods<S, PersistedState> & HydrationPromise<PersistReturn>;
|
|
81
|
-
setState: SetStateOverloads<S, PersistReturn>;
|
|
82
|
-
}> : Store;
|
|
83
|
-
type HydrationPromise<PersistReturn> = PersistReturn extends Promise<void> ? {
|
|
84
|
-
/** Invoke to get a promise that resolves once hydration completes. */
|
|
85
|
-
hydrationPromise: () => Promise<void>;
|
|
86
|
-
} : {
|
|
87
|
-
hydrationPromise?: undefined;
|
|
88
|
-
};
|
|
89
|
-
type Get<T, K, Fallback> = K extends keyof T ? T[K] : Fallback;
|
|
90
|
-
type Write<T, U> = Omit<T, keyof U> & U;
|
|
91
|
-
type PersistMutator<Store, Args> = Args extends [infer PersistedState, infer PersistReturn extends void | Promise<void>] ? WithPersist<Store, PersistedState, PersistReturn> : Store;
|
|
92
|
-
type StoreMutatorIdentifier = keyof StoreMutatorMap<unknown, unknown>;
|
|
93
|
-
/**
|
|
94
|
-
* Mapping from store mutator identifiers to the store API shape they add.
|
|
95
|
-
*/
|
|
96
|
-
export interface StoreMutatorMap<Store, Args> {
|
|
97
|
-
'stores/persist': PersistMutator<Store, Args>;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Ordered list of store mutators applied to a state creator.
|
|
101
|
-
*/
|
|
102
|
-
export type StoreMutators = [StoreMutatorIdentifier, unknown][];
|
|
103
|
-
/**
|
|
104
|
-
* Applies a list of store mutators to a store API type.
|
|
105
|
-
*/
|
|
106
|
-
export type Mutate<Store, Mutators> = number extends Mutators['length' & keyof Mutators] ? Store : Mutators extends [] ? Store : Mutators extends [[infer Identifier, infer Args], ...infer Rest] ? Identifier extends StoreMutatorIdentifier ? Rest extends StoreMutators ? Mutate<StoreMutatorMap<Store, Args>[Identifier], Rest> : StoreMutatorMap<Store, Args>[Identifier] : Store : Store;
|
|
107
|
-
export {};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { UnknownFunction } from '../types/functions';
|
|
2
|
-
/**
|
|
3
|
-
* Metadata for a field's last write.
|
|
4
|
-
*/
|
|
5
|
-
export type FieldMetadata = readonly [timestamp: number, sessionId: string];
|
|
6
|
-
export type SyncStateKey<T extends Record<string, unknown>> = Extract<{
|
|
7
|
-
[K in keyof T]-?: T[K] extends UnknownFunction ? never : K;
|
|
8
|
-
}[keyof T], string>;
|
|
9
|
-
export type SyncValues<T extends Record<string, unknown>> = Partial<T> & {
|
|
10
|
-
[K in SyncStateKey<T>]?: T[K];
|
|
11
|
-
};
|
|
12
|
-
export type SyncUpdate<T extends Record<string, unknown>> = {
|
|
13
|
-
replace: boolean;
|
|
14
|
-
sessionId: string;
|
|
15
|
-
timestamp: number;
|
|
16
|
-
values: SyncValues<T>;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Passed to `SyncEngine.register()` to connect a store to the sync system.
|
|
20
|
-
*/
|
|
21
|
-
export type SyncRegistration<T extends Record<string, unknown>> = {
|
|
22
|
-
/** Callback invoked by the engine to apply incoming remote updates to the store. */
|
|
23
|
-
apply: (update: SyncUpdate<T>) => void;
|
|
24
|
-
/** The state keys to sync. Non-function properties only. */
|
|
25
|
-
fields: ReadonlyArray<SyncStateKey<T>>;
|
|
26
|
-
/** Returns the store's current state. Used by engines that need to read state (e.g., for diffing). */
|
|
27
|
-
getState: () => T;
|
|
28
|
-
/** Unique identifier for this store. Must match across clients to sync the same data. */
|
|
29
|
-
key: string;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Returned by `SyncEngine.register()`. Controls the lifecycle of a synced store.
|
|
33
|
-
*/
|
|
34
|
-
export interface SyncHandle<T extends Record<string, unknown>> {
|
|
35
|
-
/**
|
|
36
|
-
* Permanently removes this store from the sync engine. After calling, the handle
|
|
37
|
-
* is invalid and the store will no longer send or receive updates. To temporarily
|
|
38
|
-
* pause sync, use `onFirstSubscribe`/`onLastUnsubscribe` lifecycle hooks instead.
|
|
39
|
-
*/
|
|
40
|
-
destroy: () => void;
|
|
41
|
-
/** Returns `true` once the store has received its initial state from the engine. */
|
|
42
|
-
hydrated?: () => boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Called when the store's subscriber count goes from 0 to 1. The registration
|
|
45
|
-
* remains active. Use for lazy resource acquisition (e.g., opening a WebSocket).
|
|
46
|
-
*/
|
|
47
|
-
onFirstSubscribe?: () => void;
|
|
48
|
-
/** Registers a one-time callback to run when hydration completes. */
|
|
49
|
-
onHydrated?: (callback: () => void) => void;
|
|
50
|
-
/**
|
|
51
|
-
* Called when the store's subscriber count drops to 0. The registration remains
|
|
52
|
-
* active and `onFirstSubscribe` will fire again on the next subscription.
|
|
53
|
-
* Use for resource cleanup (e.g., closing idle connections).
|
|
54
|
-
*/
|
|
55
|
-
onLastUnsubscribe?: () => void;
|
|
56
|
-
/**
|
|
57
|
-
* Broadcasts a state update to other clients. Set to `null` for engines where
|
|
58
|
-
* publishing is implicit (e.g., `chrome.storage` where the write itself triggers sync).
|
|
59
|
-
*/
|
|
60
|
-
publish: ((update: SyncUpdate<T>) => void) | null;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Interface for multi-client state synchronization. Stores register to send and receive updates.
|
|
64
|
-
*/
|
|
65
|
-
export interface SyncEngine {
|
|
66
|
-
/**
|
|
67
|
-
* When `true`, embeds sync metadata (`{ origin, timestamp, fields }`) into persisted
|
|
68
|
-
* storage values. Required for engines that use storage writes as their transport.
|
|
69
|
-
* Only effective when the store is also persisted.
|
|
70
|
-
* @default false
|
|
71
|
-
*/
|
|
72
|
-
readonly injectStorageMetadata?: boolean;
|
|
73
|
-
/** Registers a store for synchronization. Returns a handle to control the sync lifecycle. */
|
|
74
|
-
register: {
|
|
75
|
-
<T extends Record<string, unknown>>(registration: SyncRegistration<T>): SyncHandle<T>;
|
|
76
|
-
(registration: SyncRegistration<Record<string, unknown>>): SyncHandle<Record<string, unknown>>;
|
|
77
|
-
};
|
|
78
|
-
/** Unique identifier for this client session. Used for conflict resolution and filtering self-updates. */
|
|
79
|
-
readonly sessionId: string;
|
|
80
|
-
}
|
|
81
|
-
export type SyncMergeFn<T, TState = unknown> = (incoming: T, current: T, currentState: TState, incomingValues: Partial<TState>) => T;
|
|
82
|
-
export type SyncConfig<T extends Record<string, unknown>> = {
|
|
83
|
-
/**
|
|
84
|
-
* The sync engine implementation to use.
|
|
85
|
-
*
|
|
86
|
-
* Defaults to cross-tab sync in browser environments. No-op in other environments unless a
|
|
87
|
-
* custom engine is provided.
|
|
88
|
-
*/
|
|
89
|
-
engine?: SyncEngine;
|
|
90
|
-
/** The state keys to sync. If unspecified, all non-function store properties are synced. */
|
|
91
|
-
fields?: ReadonlyArray<SyncStateKey<T>>;
|
|
92
|
-
/**
|
|
93
|
-
* When true, injects sync metadata (`{ origin, timestamp, fields }`) into the persisted
|
|
94
|
-
* storage payload. Only takes effect when used with a persisted store.
|
|
95
|
-
*
|
|
96
|
-
* Useful for sync engines that use storage events as their transport (e.g., `chrome.storage`).
|
|
97
|
-
*
|
|
98
|
-
* Can also be set on the `engine` object. This option takes precedence if both are provided.
|
|
99
|
-
* @default false
|
|
100
|
-
*/
|
|
101
|
-
injectStorageMetadata?: boolean;
|
|
102
|
-
/** The key used to identify the store to the sync engine. Required if `storageKey` is absent. */
|
|
103
|
-
key?: string;
|
|
104
|
-
/** Optional merge function to use for each synced state key. Use with caution. */
|
|
105
|
-
merge?: {
|
|
106
|
-
[K in SyncStateKey<T>]?: SyncMergeFn<T[K], T>;
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Internal type for `SyncConfig` with `key` always present.
|
|
111
|
-
*/
|
|
112
|
-
export type NormalizedSyncConfig<T extends Record<string, unknown>> = SyncConfig<T> & {
|
|
113
|
-
key: string;
|
|
114
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Relaxes function parameter variance to allow subtype
|
|
3
|
-
* assignment otherwise blocked by strict contravariance.
|
|
4
|
-
*/
|
|
5
|
-
export type BivariantMethod<T extends Record<string, UnknownFunction>> = T[keyof T];
|
|
6
|
-
/**
|
|
7
|
-
* Extract the keys of `T` whose values are functions.
|
|
8
|
-
*/
|
|
9
|
-
export type FunctionKeys<T> = {
|
|
10
|
-
[K in keyof T]-?: T[K] extends UnknownFunction ? K : never;
|
|
11
|
-
}[keyof T];
|
|
12
|
-
/**
|
|
13
|
-
* A record of string keys to unknown functions.
|
|
14
|
-
*/
|
|
15
|
-
export type FunctionRecord = Record<string, UnknownFunction>;
|
|
16
|
-
/**
|
|
17
|
-
* Return `T` if it is **not** a function, otherwise `never`.
|
|
18
|
-
*/
|
|
19
|
-
export type NonFunction<T> = T extends (...args: infer _) => unknown ? never : T;
|
|
20
|
-
/**
|
|
21
|
-
* Unknown generic function type.
|
|
22
|
-
*/
|
|
23
|
-
export type UnknownFunction = (...args: never[]) => unknown;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Forces TypeScript to expand a type for clearer IDE display.
|
|
3
|
-
*/
|
|
4
|
-
export type Prettify<T> = T extends infer U ? {
|
|
5
|
-
[K in keyof U]: U[K];
|
|
6
|
-
} : never;
|
|
7
|
-
/**
|
|
8
|
-
* Enforce no overlapping keys between two objects.
|
|
9
|
-
*/
|
|
10
|
-
export type NoOverlap<A, B> = B & Record<Extract<keyof A, keyof B>, never>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { BivariantMethod } from './functions';
|
|
2
|
-
export type SetPartial<S> = S | Partial<S> | BivariantMethod<{
|
|
3
|
-
updater(state: S): S | Partial<S>;
|
|
4
|
-
}>;
|
|
5
|
-
export type SetFull<S> = S | BivariantMethod<{
|
|
6
|
-
updater(state: S): S;
|
|
7
|
-
}>;
|
|
8
|
-
export type SetStateReplaceArgs<S, ExtraArgs extends unknown[] = []> = [update: SetFull<S>, replace: true, ...extraArgs: ExtraArgs];
|
|
9
|
-
export type SetStatePartialArgs<S, ExtraArgs extends unknown[] = []> = [update: SetPartial<S>, replace?: false, ...extraArgs: ExtraArgs];
|
|
10
|
-
export type SetStateArgs<S, ExtraArgs extends unknown[] = []> = SetStatePartialArgs<S, ExtraArgs> | SetStateReplaceArgs<S, ExtraArgs>;
|
|
11
|
-
/**
|
|
12
|
-
* Rest-argument form of `setState`, used when forwarding calls.
|
|
13
|
-
*/
|
|
14
|
-
export type SetState<S, ExtraArgs extends unknown[] = [], PersistReturn extends Promise<void> | void = void> = (...args: SetStateArgs<S, ExtraArgs>) => PersistReturn;
|
|
15
|
-
/**
|
|
16
|
-
* Store `setState` method overloads for partial updates and full replacement.
|
|
17
|
-
*/
|
|
18
|
-
export type SetStateOverloads<S, PersistReturn extends Promise<void> | void = void> = BivariantMethod<{
|
|
19
|
-
setState(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
20
|
-
setState(update: SetFull<S>, replace: true): PersistReturn;
|
|
21
|
-
}>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type Listener<S> = (state: S, prevState: S) => void;
|
|
2
|
-
export type Selector<S, Selected> = (state: S) => Selected;
|
|
3
|
-
export type EqualityFn<T = unknown> = (a: T, b: T) => boolean;
|
|
4
|
-
/**
|
|
5
|
-
* Minimum store API required for subscription.
|
|
6
|
-
*/
|
|
7
|
-
export type SubscribableStore = {
|
|
8
|
-
subscribe(selector: Selector<unknown, unknown>, listener: () => void, options?: SubscribeOptions<unknown>): UnsubscribeFn;
|
|
9
|
-
};
|
|
10
|
-
export type SubscribeOptions<Selected> = {
|
|
11
|
-
equalityFn?: EqualityFn<Selected>;
|
|
12
|
-
fireImmediately?: boolean;
|
|
13
|
-
isDerivedStore?: boolean;
|
|
14
|
-
};
|
|
15
|
-
export type ListenerArgs<S> = [listener: Listener<S>];
|
|
16
|
-
export type SelectorArgs<S, Selected> = [
|
|
17
|
-
selector: Selector<S, Selected>,
|
|
18
|
-
listener: Listener<Selected>,
|
|
19
|
-
options?: SubscribeOptions<Selected>
|
|
20
|
-
];
|
|
21
|
-
export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
|
|
22
|
-
export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
|
|
23
|
-
export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
|
|
24
|
-
export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
|
|
25
|
-
(listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
|
|
26
|
-
<Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
|
|
27
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type UseStoreCallSignatures<_> = Record<never, never>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type UseStoreCallSignatures<_> = Record<never, never>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed `hasOwnProperty` alias.
|
|
3
|
-
*/
|
|
4
|
-
export declare function hasOwn<T extends Record<string, unknown>, K extends string>(value: T, key: K): value is T & Record<K, unknown>;
|
|
5
|
-
/**
|
|
6
|
-
* Checks prototype is `Object.prototype` or `null`. Excludes arrays, class instances, etc.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
/**
|
|
10
|
-
* Checks for non-null, non-array objects.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isRecordLike(value: unknown): value is Record<string, unknown>;
|
package/dist/vanilla/types.d.ts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import type { StorageValue } from './storage/storageTypes';
|
|
2
|
-
import type { PersistOptions, StateCreator as StoreStateCreator, StoreApi, StoreMutators, WithPersist } from './store/types';
|
|
3
|
-
import type { SyncConfig } from './sync/types';
|
|
4
|
-
import type { FunctionKeys } from './types/functions';
|
|
5
|
-
import type { SetFull, SetPartial, SetStateArgs } from './types/setState';
|
|
6
|
-
import type { EqualityFn, Selector, SubscribeOverloads } from './types/subscribe';
|
|
7
|
-
import type { UseStoreCallSignatures } from './types/useStoreCallSignatures';
|
|
8
|
-
export type { StoreMutators } from './store/types';
|
|
9
|
-
export type * from './types/setState';
|
|
10
|
-
export type * from './types/subscribe';
|
|
11
|
-
export type * from './types/useStoreCallSignatures';
|
|
12
|
-
export type StoreMutatorsWithSelector<Mutators extends StoreMutators = StoreMutators> = Mutators;
|
|
13
|
-
export type StateCreator<S, U = S> = StoreStateCreator<S, [], [], U>;
|
|
14
|
-
export type UseBoundStoreWithEqualityFn<Store extends {
|
|
15
|
-
getState: () => unknown;
|
|
16
|
-
}, State = InferStoreState<Store>> = UseStoreCallSignatures<State> & Store;
|
|
17
|
-
export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
|
|
18
|
-
subscribe: SubscribeOverloads<S, ExtraSubscribeOptions>;
|
|
19
|
-
};
|
|
20
|
-
export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S, ExtraSubscribeOptions>, PersistedState, PersistReturn>;
|
|
21
|
-
export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = [PersistedState] extends [never] ? BaseStore<S, ExtraSubscribeOptions> : PersistedStore<S, PersistedState, PersistReturn, ExtraSubscribeOptions>;
|
|
22
|
-
/**
|
|
23
|
-
* Store returned by creators that accept optional persistence options.
|
|
24
|
-
* `persist` exists only when persistence is configured.
|
|
25
|
-
*/
|
|
26
|
-
export type OptionallyPersistedStore<S, PersistedState, PersistReturn extends void | Promise<void> = void> = UseStoreCallSignatures<S> & Omit<BaseStore<S>, 'setState'> & {
|
|
27
|
-
persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
|
|
28
|
-
setState(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
29
|
-
setState(update: SetFull<S>, replace: true): PersistReturn;
|
|
30
|
-
};
|
|
31
|
-
export type NoInfer<T> = [T][T extends unknown ? 0 : never];
|
|
32
|
-
export type Timeout = ReturnType<typeof setTimeout>;
|
|
33
|
-
export type InferStoreState<Store> = Store extends {
|
|
34
|
-
getState: () => infer T;
|
|
35
|
-
} ? T : never;
|
|
36
|
-
/**
|
|
37
|
-
* Action methods returned by `createStoreActions(store)`.
|
|
38
|
-
*/
|
|
39
|
-
export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState<Store>, FunctionKeys<InferStoreState<Store>>>;
|
|
40
|
-
/**
|
|
41
|
-
* Extracts a store's `setState` return type.
|
|
42
|
-
* - `void` for non-persisted or synchronous persisted stores.
|
|
43
|
-
* - `Promise<void>` for async persisted stores.
|
|
44
|
-
*/
|
|
45
|
-
export type InferSetStateReturn<Store> = Store extends {
|
|
46
|
-
setState(...args: SetStateArgs<infer S>): infer R;
|
|
47
|
-
} ? R : void;
|
|
48
|
-
/**
|
|
49
|
-
* Extracts a store's `PersistedState` type.
|
|
50
|
-
* Returns `never` if the store doesn't use persistence.
|
|
51
|
-
*/
|
|
52
|
-
export type InferPersistedState<PersistedStore> = PersistedStore extends Store<infer _, infer PersistedState> ? PersistedState : never;
|
|
53
|
-
/**
|
|
54
|
-
* Reads store state and records the dependencies of a derived computation.
|
|
55
|
-
* - `$(store, selector, equalityFn?)` depends on the selected state
|
|
56
|
-
* - `$(store)` depends on accessed state paths
|
|
57
|
-
*/
|
|
58
|
-
export type DeriveGetter = {
|
|
59
|
-
<S extends Store<InferStoreState<S>>>(store: S): InferStoreState<S>;
|
|
60
|
-
<S extends Store<InferStoreState<S>>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
61
|
-
};
|
|
62
|
-
export type DerivedStore<S> = WithFlushUpdates<ReadOnlyDerivedStore<BaseStore<S>>>;
|
|
63
|
-
export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
|
|
64
|
-
/**
|
|
65
|
-
* Destroy the derived store and its subscriptions.
|
|
66
|
-
*
|
|
67
|
-
* Derived stores automatically clean up internal resources and subscriptions
|
|
68
|
-
* when no subscribers exist. So calling `destroy()` is usually unnecessary,
|
|
69
|
-
* unless `keepAlive: true` is specified and explict teardown is desired.
|
|
70
|
-
*/
|
|
71
|
-
destroy: () => void;
|
|
72
|
-
/**
|
|
73
|
-
* Flush all pending updates — only applicable to **debounced** derived stores.
|
|
74
|
-
*/
|
|
75
|
-
flushUpdates: () => void;
|
|
76
|
-
};
|
|
77
|
-
export type WithGetSnapshot<Store extends StoreApi<unknown>> = Store & {
|
|
78
|
-
/**
|
|
79
|
-
* Reads the current snapshot while activating lazy derived stores before subscription.
|
|
80
|
-
*/
|
|
81
|
-
getSnapshot: () => InferStoreState<Store>;
|
|
82
|
-
};
|
|
83
|
-
type ReadOnlyDerivedStore<Store extends BaseStore<unknown>> = Omit<Store, 'getInitialState' | 'setState'> & UseStoreCallSignatures<InferStoreState<Store>> & {
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated **Not applicable to derived stores.** Will throw an error.
|
|
86
|
-
*/
|
|
87
|
-
getInitialState: Store['getInitialState'];
|
|
88
|
-
/**
|
|
89
|
-
* @deprecated **Not applicable to derived stores.** Will throw an error.
|
|
90
|
-
*/
|
|
91
|
-
setState: Store['setState'];
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Configuration for creating derived stores. You can pass either:
|
|
95
|
-
* - A **function** (used as `equalityFn`), or
|
|
96
|
-
* - An **object** with the fields below
|
|
97
|
-
*/
|
|
98
|
-
export type DeriveOptions<DerivedState = unknown> = EqualityFn<DerivedState> | {
|
|
99
|
-
/**
|
|
100
|
-
* Delay before triggering a re-derive when dependencies change.
|
|
101
|
-
* Accepts a number (ms) or debounce options:
|
|
102
|
-
*
|
|
103
|
-
* `{ delay: number, leading?: boolean, trailing?: boolean, maxWait?: number }`
|
|
104
|
-
* @default 0
|
|
105
|
-
*/
|
|
106
|
-
debounce?: number | DebounceOptions;
|
|
107
|
-
/**
|
|
108
|
-
* If `true`, the store will log debug messages to the console.
|
|
109
|
-
*
|
|
110
|
-
* If `'verbose'`, the store will log the subscriptions it creates each time the derive
|
|
111
|
-
* function is run, rather than only the first time.
|
|
112
|
-
* @default false
|
|
113
|
-
*/
|
|
114
|
-
debugMode?: boolean | 'verbose';
|
|
115
|
-
/**
|
|
116
|
-
* A custom comparison function for detecting state changes.
|
|
117
|
-
* @default `Object.is`
|
|
118
|
-
*/
|
|
119
|
-
equalityFn?: EqualityFn<DerivedState>;
|
|
120
|
-
/**
|
|
121
|
-
* If `true`, the derived store will never destroy itself. Useful in cases where your
|
|
122
|
-
* derived store serves as a permanent cache subscribed to intermittently or not at all.
|
|
123
|
-
* Manual calls to `destroy` *will* destroy the store even when `keepAlive` is `true`.
|
|
124
|
-
*
|
|
125
|
-
* *Use this option carefully.*
|
|
126
|
-
* @default false
|
|
127
|
-
*/
|
|
128
|
-
keepAlive?: boolean;
|
|
129
|
-
/**
|
|
130
|
-
* Locks the dependency graph after the first derivation. Subscriptions to
|
|
131
|
-
* underlying stores are established once and reused on subsequent runs, rather
|
|
132
|
-
* than being torn down and rebuilt (the default behavior).
|
|
133
|
-
*
|
|
134
|
-
* This avoids the overhead of regenerating selectors and prevents unnecessary
|
|
135
|
-
* subscription churn. However, it means only the *initially tracked* dependencies
|
|
136
|
-
* will trigger updates — even if your derive function conditionally reads different
|
|
137
|
-
* stores in later runs.
|
|
138
|
-
*
|
|
139
|
-
* **Requirement**: All `$` calls in your derive function must be consistent and
|
|
140
|
-
* top level. Conditional dependency tracking will not work correctly.
|
|
141
|
-
*
|
|
142
|
-
* Safe to enable for most derived stores where dependencies are static.
|
|
143
|
-
*
|
|
144
|
-
* @default false
|
|
145
|
-
*/
|
|
146
|
-
lockDependencies?: boolean;
|
|
147
|
-
};
|
|
148
|
-
export type Deserializer<SerializedState, PersistedState> = (serializedState: SerializedState) => StorageValue<PersistedState>;
|
|
149
|
-
export type Serializer<SerializedState> = <PersistedState>(storageValue: StorageValue<PersistedState>) => SerializedState;
|
|
150
|
-
/**
|
|
151
|
-
* Synchronous storage interface.
|
|
152
|
-
* Used for localStorage and MMKV implementations.
|
|
153
|
-
*/
|
|
154
|
-
export type SyncStorageInterface<SerializedState = unknown> = {
|
|
155
|
-
readonly async?: false;
|
|
156
|
-
/**
|
|
157
|
-
* Adapter-level deserializer used when a store does not supply its own.
|
|
158
|
-
* Acts as the default before falling back to the framework implementation.
|
|
159
|
-
*/
|
|
160
|
-
deserializer?<PersistedState>(serializedState: SerializedState): StorageValue<PersistedState>;
|
|
161
|
-
/**
|
|
162
|
-
* Adapter-level serializer used when a store does not supply its own.
|
|
163
|
-
* Acts as the default before falling back to the framework implementation.
|
|
164
|
-
*/
|
|
165
|
-
serializer?<PersistedState>(storageValue: StorageValue<PersistedState>): SerializedState;
|
|
166
|
-
clearAll(): void;
|
|
167
|
-
contains(key: string): boolean;
|
|
168
|
-
delete(key: string): void;
|
|
169
|
-
get(key: string): SerializedState | undefined;
|
|
170
|
-
getAllKeys(): string[];
|
|
171
|
-
set(key: string, value: SerializedState): void;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Asynchronous storage interface.
|
|
175
|
-
* Used for Chrome storage and other async storage implementations.
|
|
176
|
-
*/
|
|
177
|
-
export type AsyncStorageInterface<SerializedState = unknown> = {
|
|
178
|
-
readonly async: true;
|
|
179
|
-
/**
|
|
180
|
-
* Adapter-level deserializer used when a store does not supply its own.
|
|
181
|
-
* Acts as the default before falling back to the framework implementation.
|
|
182
|
-
*/
|
|
183
|
-
deserializer?<PersistedState>(serializedState: SerializedState): StorageValue<PersistedState>;
|
|
184
|
-
/**
|
|
185
|
-
* Adapter-level serializer used when a store does not supply its own.
|
|
186
|
-
* Acts as the default before falling back to the framework implementation.
|
|
187
|
-
*/
|
|
188
|
-
serializer?<PersistedState>(storageValue: StorageValue<PersistedState>): SerializedState;
|
|
189
|
-
clearAll(): Promise<void>;
|
|
190
|
-
contains(key: string): Promise<boolean>;
|
|
191
|
-
delete(key: string): Promise<void>;
|
|
192
|
-
get(key: string): Promise<SerializedState | undefined>;
|
|
193
|
-
getAllKeys(): Promise<string[]>;
|
|
194
|
-
set(key: string, value: SerializedState): Promise<void>;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Configuration options for creating a persistable store.
|
|
198
|
-
*/
|
|
199
|
-
export type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = {
|
|
200
|
-
/**
|
|
201
|
-
* A function to convert the serialized value back into the state object.
|
|
202
|
-
* If not provided, the storage adapter's `deserializer` is used before falling back to the default implementation.
|
|
203
|
-
*/
|
|
204
|
-
deserializer?: (serializedState: unknown) => StorageValue<PersistedState>;
|
|
205
|
-
/**
|
|
206
|
-
* A function to merge persisted state with current state during hydration.
|
|
207
|
-
* By default, persisted state is shallow-merged into the current state.
|
|
208
|
-
*/
|
|
209
|
-
merge?: PersistOptions<S, PersistedState>['merge'];
|
|
210
|
-
/**
|
|
211
|
-
* A function to perform persisted state migration.
|
|
212
|
-
* This function will be called when persisted state versions mismatch with the one specified here.
|
|
213
|
-
*/
|
|
214
|
-
migrate?: PersistOptions<S, PersistedState>['migrate'];
|
|
215
|
-
/**
|
|
216
|
-
* A function returning another (optional) function.
|
|
217
|
-
* The main function will be called before the state rehydration.
|
|
218
|
-
* The returned function will be called after the state rehydration or when an error occurred.
|
|
219
|
-
*/
|
|
220
|
-
onRehydrateStorage?: PersistOptions<S, PersistedState>['onRehydrateStorage'];
|
|
221
|
-
/**
|
|
222
|
-
* A function that determines which parts of the state should be persisted.
|
|
223
|
-
* By default, the entire state is persisted.
|
|
224
|
-
*/
|
|
225
|
-
partialize?: (state: Readonly<S>) => PersistedState;
|
|
226
|
-
/**
|
|
227
|
-
* The throttle rate for the persist operation in milliseconds.
|
|
228
|
-
* @default iOS: time.seconds(3) | Android: time.seconds(5)
|
|
229
|
-
*/
|
|
230
|
-
persistThrottleMs?: PersistReturn extends Promise<unknown> ? undefined : number;
|
|
231
|
-
/**
|
|
232
|
-
* A function to serialize the state and version for storage.
|
|
233
|
-
* If not provided, the storage adapter's `serializer` is used before falling back to the default implementation.
|
|
234
|
-
*/
|
|
235
|
-
serializer?: (storageValue: StorageValue<PersistedState>) => string;
|
|
236
|
-
/**
|
|
237
|
-
* Custom storage implementation. If async, `setState` will return a Promise that resolves
|
|
238
|
-
* when the state is persisted. If sync, `setState` will return void.
|
|
239
|
-
*/
|
|
240
|
-
storage?: PersistReturn extends Promise<unknown> ? AsyncStorageInterface : SyncStorageInterface;
|
|
241
|
-
/**
|
|
242
|
-
* The unique key for the persisted store.
|
|
243
|
-
*/
|
|
244
|
-
storageKey: string;
|
|
245
|
-
/**
|
|
246
|
-
* The version of the store's schema.
|
|
247
|
-
* Useful for handling schema changes across app versions.
|
|
248
|
-
* @default 0
|
|
249
|
-
*/
|
|
250
|
-
version?: number;
|
|
251
|
-
};
|
|
252
|
-
export type EnforceStorageKey<Options> = {
|
|
253
|
-
storageKey: string;
|
|
254
|
-
} extends Options ? Options : never;
|
|
255
|
-
export type BaseStoreOptions<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = (PersistConfig<S, PersistedState, PersistReturn> & {
|
|
256
|
-
sync?: S extends Record<string, unknown> ? SyncOption<S> : undefined;
|
|
257
|
-
}) | ({
|
|
258
|
-
sync: S extends Record<string, unknown> ? SyncWithoutStorageOption<NoInfer<S>> : undefined;
|
|
259
|
-
} & UndefinedPersistKeys<S, PersistedState, PersistReturn>);
|
|
260
|
-
/**
|
|
261
|
-
* The `sync` option can be:
|
|
262
|
-
* - `SyncConfig` object
|
|
263
|
-
* - `string` (shorthand for `{ key: string }`)
|
|
264
|
-
* - `true` (inherits key from `storageKey` — only valid with persistence)
|
|
265
|
-
*/
|
|
266
|
-
export type SyncOption<S extends Record<string, unknown>> = SyncConfig<S> | string | true;
|
|
267
|
-
type SyncWithoutStorageOption<S extends Record<string, unknown>> = string | (Omit<SyncConfig<S>, 'injectStorageMetadata' | 'key'> & {
|
|
268
|
-
injectStorageMetadata?: never;
|
|
269
|
-
key: SyncWithoutStorageKey<SyncConfig<S>>;
|
|
270
|
-
});
|
|
271
|
-
type SyncWithoutStorageKey<Config> = Config extends {
|
|
272
|
-
key?: infer Key;
|
|
273
|
-
} ? Extract<Key, string> extends never ? string : Extract<Key, string> : string;
|
|
274
|
-
type UndefinedPersistKeys<S, PersistedState extends Partial<S>, PersistReturn> = {
|
|
275
|
-
[K in keyof PersistConfig<S, PersistedState, PersistReturn>]?: undefined;
|
|
276
|
-
};
|
|
277
|
-
/**
|
|
278
|
-
* Expanded options for custom debounce behavior.
|
|
279
|
-
*/
|
|
280
|
-
export type DebounceOptions = {
|
|
281
|
-
delay: number;
|
|
282
|
-
leading?: boolean;
|
|
283
|
-
maxWait?: number;
|
|
284
|
-
trailing?: boolean;
|
|
285
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the argument provided.
|
|
3
|
-
*/
|
|
4
|
-
export declare function identity<T>(value: T): T;
|
|
5
|
-
export declare function identity<T, _>(value: T): T;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a null-prototype object using the runtime-optimal path:
|
|
8
|
-
* - React Native: direct literal `{ __proto__: null }`
|
|
9
|
-
* - Web/Node: `Object.create` with a shared, frozen null prototype
|
|
10
|
-
*/
|
|
11
|
-
export declare function nullObject<T extends Record<string, unknown> | object = Record<string, unknown>>(): T;
|
|
12
|
-
/**
|
|
13
|
-
* Builds null-prototype objects. Provided arguments are
|
|
14
|
-
* shallow-merged into a newly created null-prototype object:
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* Object.assign(nullObject(), a, b?)
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function buildNullObject<A extends Record<string, unknown>>(a: A): A;
|
|
21
|
-
export declare function buildNullObject<A extends object, B>(a: object, b?: object): [undefined] extends B ? A : A & B;
|
|
22
|
-
/**
|
|
23
|
-
* Does nothing.
|
|
24
|
-
*/
|
|
25
|
-
export declare function noop(): void;
|