@storesjs/stores 0.8.7 → 0.10.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/README.md +55 -29
- package/dist/createBaseStore.d.ts +6 -6
- package/dist/createDerivedStore.d.ts +9 -17
- package/dist/createQueryStore.d.ts +6 -21
- package/dist/createVirtualStore.d.ts +5 -5
- package/dist/env.native.d.ts +0 -2
- package/dist/env.web.d.ts +0 -1
- package/dist/hooks/useListen.d.ts +2 -2
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +5 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.shared.d.ts +14 -0
- package/dist/index.vanilla.d.ts +2 -0
- package/dist/internal/baseStore.d.ts +2 -0
- package/dist/internal/config.d.ts +64 -0
- package/dist/{utils → internal}/createStoreActions.d.ts +5 -6
- package/dist/internal/derivedStore/cascadeScheduler.d.ts +31 -0
- package/dist/internal/derivedStore/deriveProxy.d.ts +15 -0
- package/dist/internal/derivedStore/pathFinder.d.ts +26 -0
- package/dist/internal/derivedStore.d.ts +2 -0
- package/dist/internal/errors.d.ts +10 -0
- package/dist/{logger.d.ts → internal/logger.d.ts} +0 -7
- package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/internal/queryStore.d.ts +2 -0
- package/dist/internal/runtime.d.ts +13 -0
- package/dist/internal/signal.d.ts +12 -0
- package/dist/internal/storage/storageCreators.d.ts +12 -0
- package/dist/{utils → internal}/storeUtils.d.ts +4 -22
- package/dist/internal/sync/browserSyncEngine.d.ts +3 -0
- package/dist/internal/sync/noopSyncEngine.d.ts +3 -0
- package/dist/internal/sync/syncEnhancer.d.ts +26 -0
- package/dist/{sync → internal/sync}/syncUtils.d.ts +1 -1
- package/dist/internal/utils/persistUtils.d.ts +9 -0
- package/dist/internal/virtualStore.d.ts +2 -0
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +3 -1
- package/dist/queryStore/queryKey.d.ts +3 -0
- package/dist/queryStore/signalTypes.d.ts +14 -0
- package/dist/queryStore/types.d.ts +39 -33
- package/dist/store/attachStoreHook.react.d.ts +5 -0
- package/dist/store/attachStoreHook.vanilla.d.ts +6 -0
- package/dist/store/batchStoreNotifications.native.d.ts +3 -0
- package/dist/store/batchStoreNotifications.web.d.ts +2 -0
- package/dist/store/createStore.d.ts +6 -0
- package/dist/store/persist.d.ts +14 -0
- package/dist/store/stateUpdate.d.ts +10 -0
- package/dist/store/types.d.ts +108 -0
- package/dist/sync/types.d.ts +53 -128
- package/dist/types/functions.d.ts +19 -2
- package/dist/types/objects.d.ts +10 -3
- package/dist/types/setState.d.ts +22 -0
- package/dist/types/subscribe.d.ts +28 -0
- package/dist/types/useStoreCallSignatures.d.ts +2 -0
- package/dist/types/useStoreCallSignatures.react.d.ts +6 -0
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +2 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types.d.ts +59 -110
- package/dist/utils/core.d.ts +23 -4
- package/dist/utils/time.d.ts +0 -10
- package/dist/vanilla/createBaseStore.d.ts +35 -0
- package/dist/vanilla/createDerivedStore.d.ts +62 -0
- package/dist/vanilla/createQueryStore.d.ts +116 -0
- package/dist/vanilla/createVirtualStore.d.ts +39 -0
- package/dist/vanilla/env.web.d.ts +6 -0
- package/dist/vanilla/index.d.ts +1 -0
- package/dist/vanilla/index.js +1 -0
- package/dist/vanilla/index.mjs +1 -0
- package/dist/vanilla/index.shared.d.ts +13 -0
- package/dist/vanilla/index.vanilla.d.ts +1 -0
- package/dist/vanilla/internal/baseStore.d.ts +1 -0
- package/dist/vanilla/internal/config.d.ts +63 -0
- package/dist/vanilla/internal/createStoreActions.d.ts +23 -0
- package/dist/{derivedStore → vanilla/internal/derivedStore}/cascadeScheduler.d.ts +8 -1
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +14 -0
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +25 -0
- package/dist/vanilla/internal/derivedStore.d.ts +1 -0
- package/dist/vanilla/internal/errors.d.ts +9 -0
- package/dist/vanilla/internal/logger.d.ts +9 -0
- package/dist/{middleware → vanilla/internal/middleware}/createHydrationGate.d.ts +1 -2
- package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +7 -0
- package/dist/vanilla/internal/queryStore.d.ts +1 -0
- package/dist/vanilla/internal/runtime.d.ts +12 -0
- package/dist/vanilla/internal/signal.d.ts +11 -0
- package/dist/vanilla/internal/storage/storageCreators.d.ts +11 -0
- package/dist/vanilla/internal/storeUtils.d.ts +45 -0
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +2 -0
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +2 -0
- package/dist/{sync → vanilla/internal/sync}/syncEnhancer.d.ts +6 -3
- package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +2 -3
- package/dist/vanilla/internal/virtualStore.d.ts +1 -0
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +66 -0
- package/dist/vanilla/queryStore/queryKey.d.ts +2 -0
- package/dist/vanilla/queryStore/signalTypes.d.ts +13 -0
- package/dist/vanilla/queryStore/types.d.ts +402 -0
- package/dist/vanilla/storage/storageTypes.d.ts +12 -0
- package/dist/vanilla/store/attachStoreHook.d.ts +5 -0
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +5 -0
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +1 -0
- package/dist/vanilla/store/createStore.d.ts +5 -0
- package/dist/vanilla/store/persist.d.ts +13 -0
- package/dist/vanilla/store/stateUpdate.d.ts +9 -0
- package/dist/vanilla/store/types.d.ts +107 -0
- package/dist/vanilla/storesStorage.web.d.ts +2 -0
- package/dist/vanilla/sync/types.d.ts +114 -0
- package/dist/vanilla/types/functions.d.ts +23 -0
- package/dist/vanilla/types/objects.d.ts +10 -0
- package/dist/vanilla/types/setState.d.ts +21 -0
- package/dist/vanilla/types/subscribe.d.ts +27 -0
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +1 -0
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +1 -0
- package/dist/vanilla/types/utils.d.ts +12 -0
- package/dist/vanilla/types.d.ts +285 -0
- package/dist/vanilla/utils/core.d.ts +25 -0
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +34 -0
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +27 -0
- package/dist/vanilla/utils/debounce.d.ts +21 -0
- package/dist/vanilla/utils/equality.d.ts +37 -0
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +12 -0
- package/dist/vanilla/utils/promiseUtils.d.ts +1 -0
- package/dist/vanilla/utils/serialization.d.ts +13 -0
- package/dist/vanilla/utils/stringUtils.d.ts +6 -0
- package/dist/vanilla/utils/time.d.ts +36 -0
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-QJLWBD7M.mjs +1 -0
- package/dist/web/chunk-V4LHP7LR.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +1 -0
- package/dist/web/internal/runtime.mjs +1 -0
- package/package.json +21 -15
- package/dist/config.d.ts +0 -40
- package/dist/derivedStore/deriveProxy.d.ts +0 -25
- package/dist/hooks/compareHooks.d.ts +0 -50
- package/dist/signal.d.ts +0 -20
- package/dist/storage/storageCreators.d.ts +0 -22
- package/dist/sync/browserSyncEngine.d.ts +0 -3
- package/dist/sync/noopSyncEngine.d.ts +0 -3
- package/dist/sync/transport.d.ts +0 -113
- package/dist/web/chunk-MMPMCVRC.mjs +0 -1
package/dist/sync/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { UnknownFunction } from '../types/functions';
|
|
2
2
|
/**
|
|
3
3
|
* Metadata for a field's last write.
|
|
4
4
|
*/
|
|
@@ -9,147 +9,86 @@ export type SyncStateKey<T extends Record<string, unknown>> = Extract<{
|
|
|
9
9
|
export type SyncValues<T extends Record<string, unknown>> = Partial<T> & {
|
|
10
10
|
[K in SyncStateKey<T>]?: T[K];
|
|
11
11
|
};
|
|
12
|
-
export type RecordDeltaPayload<TValue = unknown> = {
|
|
13
|
-
readonly clear?: true;
|
|
14
|
-
readonly del?: readonly string[];
|
|
15
|
-
readonly set?: Record<string, TValue>;
|
|
16
|
-
readonly patch?: Record<string, RecordDeltaPayload>;
|
|
17
|
-
};
|
|
18
|
-
export type SyncDeltaPayload<TValue = unknown> = {
|
|
19
|
-
readonly kind: 'record';
|
|
20
|
-
} & RecordDeltaPayload<TValue>;
|
|
21
|
-
export type SyncDeltaDescriptor = {
|
|
22
|
-
/**
|
|
23
|
-
* Minimum fraction of the full payload the delta must save (0–1).
|
|
24
|
-
*/
|
|
25
|
-
readonly minSavingsRatio?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Minimum number of bytes the delta must save compared to sending the full payload.
|
|
28
|
-
*/
|
|
29
|
-
readonly minSavingsBytes?: number;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Per-field delta configuration. Use `true` to enable with defaults, or provide thresholds.
|
|
33
|
-
*/
|
|
34
|
-
export type SyncDeltaConfig<T extends Record<string, unknown>> = Partial<Record<SyncStateKey<T>, SyncDeltaDescriptor | true>>;
|
|
35
|
-
export type SyncDeltaMap<T extends Record<string, unknown>> = Partial<Record<SyncStateKey<T>, SyncDeltaPayload<T[SyncStateKey<T>]>>>;
|
|
36
12
|
export type SyncUpdate<T extends Record<string, unknown>> = {
|
|
37
|
-
deltas?: SyncDeltaMap<T>;
|
|
38
13
|
replace: boolean;
|
|
39
14
|
sessionId: string;
|
|
40
15
|
timestamp: number;
|
|
41
16
|
values: SyncValues<T>;
|
|
42
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Passed to `SyncEngine.register()` to connect a store to the sync system.
|
|
20
|
+
*/
|
|
43
21
|
export type SyncRegistration<T extends Record<string, unknown>> = {
|
|
22
|
+
/** Callback invoked by the engine to apply incoming remote updates to the store. */
|
|
44
23
|
apply: (update: SyncUpdate<T>) => void;
|
|
24
|
+
/** The state keys to sync. Non-function properties only. */
|
|
45
25
|
fields: ReadonlyArray<SyncStateKey<T>>;
|
|
26
|
+
/** Returns the store's current state. Used by engines that need to read state (e.g., for diffing). */
|
|
46
27
|
getState: () => T;
|
|
28
|
+
/** Unique identifier for this store. Must match across clients to sync the same data. */
|
|
47
29
|
key: string;
|
|
48
|
-
delta?: SyncDeltaConfig<T>;
|
|
49
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Returned by `SyncEngine.register()`. Controls the lifecycle of a synced store.
|
|
33
|
+
*/
|
|
50
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
|
+
*/
|
|
51
40
|
destroy: () => void;
|
|
41
|
+
/** Returns `true` once the store has received its initial state from the engine. */
|
|
52
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. */
|
|
53
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
|
+
*/
|
|
54
60
|
publish: ((update: SyncUpdate<T>) => void) | null;
|
|
55
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Interface for multi-client state synchronization. Stores register to send and receive updates.
|
|
64
|
+
*/
|
|
56
65
|
export interface SyncEngine {
|
|
57
|
-
register<T extends Record<string, unknown>>(registration: SyncRegistration<T>): SyncHandle<T>;
|
|
58
|
-
registerPresence?<Presence>(registration: SyncPresenceRegistration<Presence>): SyncPresenceChannel<Presence> | null;
|
|
59
66
|
/**
|
|
60
|
-
* When true
|
|
61
|
-
* storage
|
|
62
|
-
*
|
|
63
|
-
* Useful for sync engines that use storage events as their transport (e.g., `chrome.storage`).
|
|
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.
|
|
64
70
|
* @default false
|
|
65
71
|
*/
|
|
66
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. */
|
|
67
79
|
readonly sessionId: string;
|
|
68
80
|
}
|
|
69
81
|
export type SyncMergeFn<T, TState = unknown> = (incoming: T, current: T, currentState: TState, incomingValues: Partial<TState>) => T;
|
|
70
|
-
export type SyncPresenceJoinHandler<Presence> = (userId: string, data: Presence) => void;
|
|
71
|
-
export type SyncPresenceUpdateHandler<Presence> = (userId: string, data: Presence) => void;
|
|
72
|
-
export type SyncPresenceLeaveHandler = (userId: string) => void;
|
|
73
|
-
export type PresencePruneStrategy = 'updates' | 'activity';
|
|
74
|
-
type PresenceActivityField<Presence> = Presence extends Record<string, unknown> ? Extract<keyof Presence, string> : string;
|
|
75
|
-
export type SyncPresenceHeartbeatConfig<Presence> = {
|
|
76
|
-
/** Interval in milliseconds between heartbeat broadcasts */
|
|
77
|
-
interval: number;
|
|
78
|
-
/** Reuse the last presence payload for each heartbeat (default). */
|
|
79
|
-
behavior?: 'reuse' | undefined;
|
|
80
|
-
} | {
|
|
81
|
-
/** Interval in milliseconds between heartbeat broadcasts */
|
|
82
|
-
interval: number;
|
|
83
|
-
/** Clone the payload and refresh an activity field on every heartbeat. */
|
|
84
|
-
behavior: 'refresh-activity';
|
|
85
|
-
/**
|
|
86
|
-
* Field from the presence payload to refresh. Defaults to the prune strategy's activity field or `timestamp`.
|
|
87
|
-
*/
|
|
88
|
-
activityField?: PresenceActivityField<Presence>;
|
|
89
|
-
} | {
|
|
90
|
-
/** Interval in milliseconds between heartbeat broadcasts */
|
|
91
|
-
interval: number;
|
|
92
|
-
/** Derive a custom payload for each heartbeat. */
|
|
93
|
-
behavior: 'transform';
|
|
94
|
-
/**
|
|
95
|
-
* Transform invoked before each heartbeat. Return a payload to broadcast, or void to reuse the current data.
|
|
96
|
-
*/
|
|
97
|
-
onHeartbeat: (currentData: Presence) => Presence | void;
|
|
98
|
-
};
|
|
99
|
-
export type SyncPresenceRegistration<Presence> = {
|
|
100
|
-
key: string;
|
|
101
|
-
/**
|
|
102
|
-
* Optional heartbeat configuration. When enabled, presence data is re-broadcast at the
|
|
103
|
-
* specified interval. Use `'reuse'` (default) to emit the last payload unchanged, `'refresh-activity'`
|
|
104
|
-
* to automatically update a timestamp-like field on object payloads, or `'transform'` to derive a custom payload.
|
|
105
|
-
*/
|
|
106
|
-
heartbeat?: SyncPresenceHeartbeatConfig<Presence>;
|
|
107
|
-
/**
|
|
108
|
-
* Optional stale presence pruning. When enabled, remote presence entries that
|
|
109
|
-
* haven't been updated within the specified threshold are automatically removed.
|
|
110
|
-
*/
|
|
111
|
-
pruneStale?: {
|
|
112
|
-
/**
|
|
113
|
-
* Determines how staleness is evaluated.
|
|
114
|
-
* - `updates` (default) considers the time since the last presence message arrived.
|
|
115
|
-
* - `activity` considers a timestamp field within the presence payload (defaults to `timestamp`).
|
|
116
|
-
*/
|
|
117
|
-
basedOn?: PresencePruneStrategy;
|
|
118
|
-
/**
|
|
119
|
-
* Field from the presence payload to inspect when `basedOn` is set to `activity`.
|
|
120
|
-
* Defaults to `timestamp`.
|
|
121
|
-
*/
|
|
122
|
-
activityField?: PresenceActivityField<Presence>;
|
|
123
|
-
/** Time in milliseconds after which presence is considered stale */
|
|
124
|
-
after: number;
|
|
125
|
-
/** Optional callback invoked before removing stale presence */
|
|
126
|
-
onPrune?: (userId: string, data: Presence) => void;
|
|
127
|
-
};
|
|
128
|
-
onJoin?: SyncPresenceJoinHandler<Presence>;
|
|
129
|
-
onLeave?: SyncPresenceLeaveHandler;
|
|
130
|
-
onUpdate?: SyncPresenceUpdateHandler<Presence>;
|
|
131
|
-
};
|
|
132
|
-
export interface SyncPresenceChannel<Presence> {
|
|
133
|
-
join(userId: string, data: Presence): void;
|
|
134
|
-
leave(): void;
|
|
135
|
-
update(data: Presence): void;
|
|
136
|
-
/**
|
|
137
|
-
* Destroys the presence channel and cleans up all resources.
|
|
138
|
-
* Automatically calls leave() and clears all timers.
|
|
139
|
-
* Safe to call multiple times.
|
|
140
|
-
*/
|
|
141
|
-
destroy(): void;
|
|
142
|
-
}
|
|
143
82
|
export type SyncConfig<T extends Record<string, unknown>> = {
|
|
144
|
-
engine?: SyncEngine;
|
|
145
|
-
fields?: ReadonlyArray<SyncStateKey<T>>;
|
|
146
83
|
/**
|
|
147
|
-
* The
|
|
84
|
+
* The sync engine implementation to use.
|
|
148
85
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
86
|
+
* Defaults to cross-tab sync in browser environments. No-op in other environments unless a
|
|
87
|
+
* custom engine is provided.
|
|
151
88
|
*/
|
|
152
|
-
|
|
89
|
+
engine?: SyncEngine;
|
|
90
|
+
/** The state keys to sync. If unspecified, all non-function store properties are synced. */
|
|
91
|
+
fields?: ReadonlyArray<SyncStateKey<T>>;
|
|
153
92
|
/**
|
|
154
93
|
* When true, injects sync metadata (`{ origin, timestamp, fields }`) into the persisted
|
|
155
94
|
* storage payload. Only takes effect when used with a persisted store.
|
|
@@ -160,7 +99,9 @@ export type SyncConfig<T extends Record<string, unknown>> = {
|
|
|
160
99
|
* @default false
|
|
161
100
|
*/
|
|
162
101
|
injectStorageMetadata?: boolean;
|
|
102
|
+
/** The key used to identify the store to the sync engine. Required if `storageKey` is absent. */
|
|
163
103
|
key?: string;
|
|
104
|
+
/** Optional merge function to use for each synced state key. Use with caution. */
|
|
164
105
|
merge?: {
|
|
165
106
|
[K in SyncStateKey<T>]?: SyncMergeFn<T[K], T>;
|
|
166
107
|
};
|
|
@@ -171,20 +112,4 @@ export type SyncConfig<T extends Record<string, unknown>> = {
|
|
|
171
112
|
export type NormalizedSyncConfig<T extends Record<string, unknown>> = SyncConfig<T> & {
|
|
172
113
|
key: string;
|
|
173
114
|
};
|
|
174
|
-
export type SyncAuthPhase = 'connect' | 'refresh' | 'challenge';
|
|
175
|
-
export type SyncAuthPayload = {
|
|
176
|
-
readonly headers?: Record<string, string>;
|
|
177
|
-
readonly query?: Record<string, string>;
|
|
178
|
-
readonly token?: string;
|
|
179
|
-
};
|
|
180
|
-
export type SyncAuthFailure = {
|
|
181
|
-
readonly code: string;
|
|
182
|
-
readonly message?: string;
|
|
183
|
-
readonly retryable: boolean;
|
|
184
|
-
};
|
|
185
|
-
export type SyncAuthenticator = {
|
|
186
|
-
readonly getPayload: (phase: SyncAuthPhase) => Promise<SyncAuthPayload | null> | SyncAuthPayload | null;
|
|
187
|
-
readonly onFailure?: (failure: SyncAuthFailure) => void;
|
|
188
|
-
};
|
|
189
|
-
export {};
|
|
190
115
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
/**
|
|
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
|
+
*/
|
|
2
9
|
export type FunctionKeys<T> = {
|
|
3
10
|
[K in keyof T]-?: T[K] extends UnknownFunction ? K : never;
|
|
4
11
|
}[keyof T];
|
|
5
|
-
|
|
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
|
+
*/
|
|
6
23
|
export type UnknownFunction = (...args: never[]) => unknown;
|
|
7
24
|
//# sourceMappingURL=functions.d.ts.map
|
package/dist/types/objects.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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>;
|
|
4
11
|
//# sourceMappingURL=objects.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=setState.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
};
|
|
28
|
+
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EqualityFn, Selector } from './subscribe';
|
|
2
|
+
export type UseStoreCallSignatures<State> = {
|
|
3
|
+
(): State;
|
|
4
|
+
<Selected>(selector: Selector<State, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=useStoreCallSignatures.react.d.ts.map
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export declare function hasOwn<T extends Record<string, unknown>, K extends stri
|
|
|
6
6
|
* Checks prototype is `Object.prototype` or `null`. Excludes arrays, class instances, etc.
|
|
7
7
|
*/
|
|
8
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>;
|
|
9
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,112 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PersistOptions } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
} ? {
|
|
20
|
-
setState(...args: SetPartialArgs): PersistReturn;
|
|
21
|
-
setState(...args: SetFullArgs): PersistReturn;
|
|
22
|
-
persist: {
|
|
23
|
-
clearStorage: () => void;
|
|
24
|
-
getOptions: () => Partial<PersistOptions<S, PersistedState>>;
|
|
25
|
-
hasHydrated: () => boolean;
|
|
26
|
-
onHydrate: (listener: (state: S) => void) => () => void;
|
|
27
|
-
onFinishHydration: (listener: (state: S) => void) => () => void;
|
|
28
|
-
rehydrate: () => Promise<void> | void;
|
|
29
|
-
setOptions: (options: Partial<PersistOptions<S, PersistedState, PersistReturn>>) => void;
|
|
30
|
-
} & HydrationPromise<PersistReturn>;
|
|
31
|
-
} : never;
|
|
32
|
-
export type StateCreator<S, U = S> = ZustandStateCreator<S, [SubscribeWithSelector], [SubscribeWithSelector], U>;
|
|
33
|
-
export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<Mutate<StoreApi<S>, [SubscribeWithSelector]>> & {
|
|
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>> & {
|
|
34
18
|
subscribe: SubscribeOverloads<S, ExtraSubscribeOptions>;
|
|
35
19
|
};
|
|
36
|
-
export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export type OptionallyPersistedStore<S, PersistedState, PersistReturn = void> = WithAsyncSet<Store<S>, S, PersistedState, PersistReturn> & UseStoreCallSignatures<S> & {
|
|
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'> & {
|
|
44
27
|
persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
|
|
28
|
+
setState(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
29
|
+
setState(update: SetFull<S>, replace: true): PersistReturn;
|
|
45
30
|
};
|
|
46
31
|
export type NoInfer<T> = [T][T extends unknown ? 0 : never];
|
|
47
32
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
48
|
-
export type
|
|
49
|
-
export type Selector<S, Selected> = (state: S) => Selected;
|
|
50
|
-
export type EqualityFn<T = unknown> = (a: T, b: T) => boolean;
|
|
51
|
-
export type UseStoreCallSignatures<S> = {
|
|
52
|
-
(): S;
|
|
53
|
-
<Selected>(selector: Selector<S, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
54
|
-
};
|
|
55
|
-
export type InferStoreState<Store extends StoreApi<unknown>> = Store extends {
|
|
33
|
+
export type InferStoreState<Store> = Store extends {
|
|
56
34
|
getState: () => infer T;
|
|
57
35
|
} ? T : never;
|
|
58
36
|
/**
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
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.
|
|
62
44
|
*/
|
|
63
45
|
export type InferSetStateReturn<Store> = Store extends {
|
|
64
46
|
setState(...args: SetStateArgs<infer S>): infer R;
|
|
65
47
|
} ? R : void;
|
|
66
48
|
/**
|
|
67
|
-
* Extracts
|
|
68
|
-
* Returns `
|
|
49
|
+
* Extracts a store's `PersistedState` type.
|
|
50
|
+
* Returns `never` if the store doesn't use persistence.
|
|
69
51
|
*/
|
|
70
|
-
export type InferPersistedState<Store,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export type SetStateReplaceArgs<S, ExtraArgs extends unknown[] = []> = [update: SetFull<S>, replace: true, ...extraArgs: ExtraArgs];
|
|
80
|
-
export type SetStatePartialArgs<S, ExtraArgs extends unknown[] = []> = [update: SetPartial<S>, replace?: false, ...extraArgs: ExtraArgs];
|
|
81
|
-
export type SetStateArgs<S, ExtraArgs extends unknown[] = []> = SetStatePartialArgs<S, ExtraArgs> | SetStateReplaceArgs<S, ExtraArgs>;
|
|
82
|
-
export type SetState<S, ExtraArgs extends unknown[] = [], PersistReturn extends Promise<void> | void = void> = (...args: SetStateArgs<S, ExtraArgs>) => PersistReturn;
|
|
83
|
-
export type SetStateOverloads<S, PersistReturn extends Promise<void> | void = void> = {
|
|
84
|
-
(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
85
|
-
(update: SetFull<S>, replace: true): PersistReturn;
|
|
86
|
-
};
|
|
87
|
-
export type WithAsyncSet<Store extends StoreApi<unknown>, S, PersistedState, PersistReturn> = Omit<Store, 'persist' | 'setState'> & {
|
|
88
|
-
persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
|
|
89
|
-
setState(update: SetPartial<InferStoreState<Store>>, replace?: false): PersistReturn;
|
|
90
|
-
setState(update: SetFull<InferStoreState<Store>>, replace: true): PersistReturn;
|
|
91
|
-
};
|
|
92
|
-
export type SubscribeOptions<Selected> = {
|
|
93
|
-
equalityFn?: EqualityFn<Selected>;
|
|
94
|
-
fireImmediately?: boolean;
|
|
95
|
-
isDerivedStore?: boolean;
|
|
96
|
-
};
|
|
97
|
-
export type ListenerArgs<S> = [listener: Listener<S>];
|
|
98
|
-
export type SelectorArgs<S, Selected> = [
|
|
99
|
-
selector: Selector<S, Selected>,
|
|
100
|
-
listener: Listener<Selected>,
|
|
101
|
-
options?: SubscribeOptions<Selected>
|
|
102
|
-
];
|
|
103
|
-
export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
|
|
104
|
-
(listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
|
|
105
|
-
<Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
|
|
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;
|
|
106
61
|
};
|
|
107
|
-
export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
|
|
108
|
-
export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
|
|
109
|
-
export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
|
|
110
62
|
export type DerivedStore<S> = WithFlushUpdates<ReadOnlyDerivedStore<BaseStore<S>>>;
|
|
111
63
|
export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
|
|
112
64
|
/**
|
|
@@ -124,8 +76,7 @@ export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
|
|
|
124
76
|
};
|
|
125
77
|
export type WithGetSnapshot<Store extends StoreApi<unknown>> = Store & {
|
|
126
78
|
/**
|
|
127
|
-
*
|
|
128
|
-
* store when it gets the initial state before subscribing to the store.
|
|
79
|
+
* Reads the current snapshot while activating lazy derived stores before subscription.
|
|
129
80
|
*/
|
|
130
81
|
getSnapshot: () => InferStoreState<Store>;
|
|
131
82
|
};
|
|
@@ -200,25 +151,25 @@ export type Serializer<SerializedState> = <PersistedState>(storageValue: Storage
|
|
|
200
151
|
* Synchronous storage interface.
|
|
201
152
|
* Used for localStorage and MMKV implementations.
|
|
202
153
|
*/
|
|
203
|
-
export
|
|
154
|
+
export type SyncStorageInterface<SerializedState = unknown> = {
|
|
204
155
|
readonly async?: false;
|
|
205
156
|
/**
|
|
206
157
|
* Adapter-level deserializer used when a store does not supply its own.
|
|
207
158
|
* Acts as the default before falling back to the framework implementation.
|
|
208
159
|
*/
|
|
209
|
-
|
|
160
|
+
deserializer?<PersistedState>(serializedState: SerializedState): StorageValue<PersistedState>;
|
|
210
161
|
/**
|
|
211
162
|
* Adapter-level serializer used when a store does not supply its own.
|
|
212
163
|
* Acts as the default before falling back to the framework implementation.
|
|
213
164
|
*/
|
|
214
|
-
|
|
165
|
+
serializer?<PersistedState>(storageValue: StorageValue<PersistedState>): SerializedState;
|
|
215
166
|
clearAll(): void;
|
|
216
167
|
contains(key: string): boolean;
|
|
217
168
|
delete(key: string): void;
|
|
218
169
|
get(key: string): SerializedState | undefined;
|
|
219
170
|
getAllKeys(): string[];
|
|
220
171
|
set(key: string, value: SerializedState): void;
|
|
221
|
-
}
|
|
172
|
+
};
|
|
222
173
|
/**
|
|
223
174
|
* Asynchronous storage interface.
|
|
224
175
|
* Used for Chrome storage and other async storage implementations.
|
|
@@ -229,12 +180,12 @@ export type AsyncStorageInterface<SerializedState = unknown> = {
|
|
|
229
180
|
* Adapter-level deserializer used when a store does not supply its own.
|
|
230
181
|
* Acts as the default before falling back to the framework implementation.
|
|
231
182
|
*/
|
|
232
|
-
|
|
183
|
+
deserializer?<PersistedState>(serializedState: SerializedState): StorageValue<PersistedState>;
|
|
233
184
|
/**
|
|
234
185
|
* Adapter-level serializer used when a store does not supply its own.
|
|
235
186
|
* Acts as the default before falling back to the framework implementation.
|
|
236
187
|
*/
|
|
237
|
-
|
|
188
|
+
serializer?<PersistedState>(storageValue: StorageValue<PersistedState>): SerializedState;
|
|
238
189
|
clearAll(): Promise<void>;
|
|
239
190
|
contains(key: string): Promise<boolean>;
|
|
240
191
|
delete(key: string): Promise<void>;
|
|
@@ -245,15 +196,15 @@ export type AsyncStorageInterface<SerializedState = unknown> = {
|
|
|
245
196
|
/**
|
|
246
197
|
* Configuration options for creating a persistable store.
|
|
247
198
|
*/
|
|
248
|
-
export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void> = {
|
|
199
|
+
export type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = {
|
|
249
200
|
/**
|
|
250
201
|
* A function to convert the serialized value back into the state object.
|
|
251
202
|
* If not provided, the storage adapter's `deserializer` is used before falling back to the default implementation.
|
|
252
203
|
*/
|
|
253
|
-
deserializer?:
|
|
204
|
+
deserializer?: (serializedState: unknown) => StorageValue<PersistedState>;
|
|
254
205
|
/**
|
|
255
206
|
* A function to merge persisted state with current state during hydration.
|
|
256
|
-
* By default,
|
|
207
|
+
* By default, persisted state is shallow-merged into the current state.
|
|
257
208
|
*/
|
|
258
209
|
merge?: PersistOptions<S, PersistedState>['merge'];
|
|
259
210
|
/**
|
|
@@ -271,7 +222,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
271
222
|
* A function that determines which parts of the state should be persisted.
|
|
272
223
|
* By default, the entire state is persisted.
|
|
273
224
|
*/
|
|
274
|
-
partialize?: (state: S) => PersistedState;
|
|
225
|
+
partialize?: (state: Readonly<S>) => PersistedState;
|
|
275
226
|
/**
|
|
276
227
|
* The throttle rate for the persist operation in milliseconds.
|
|
277
228
|
* @default iOS: time.seconds(3) | Android: time.seconds(5)
|
|
@@ -281,7 +232,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
281
232
|
* A function to serialize the state and version for storage.
|
|
282
233
|
* If not provided, the storage adapter's `serializer` is used before falling back to the default implementation.
|
|
283
234
|
*/
|
|
284
|
-
serializer?:
|
|
235
|
+
serializer?: (storageValue: StorageValue<PersistedState>) => string;
|
|
285
236
|
/**
|
|
286
237
|
* Custom storage implementation. If async, `setState` will return a Promise that resolves
|
|
287
238
|
* when the state is persisted. If sync, `setState` will return void.
|
|
@@ -301,7 +252,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
301
252
|
export type EnforceStorageKey<Options> = {
|
|
302
253
|
storageKey: string;
|
|
303
254
|
} extends Options ? Options : never;
|
|
304
|
-
export type BaseStoreOptions<S, PersistedState = Partial<S>, PersistReturn = void> = (PersistConfig<S, PersistedState, PersistReturn> & {
|
|
255
|
+
export type BaseStoreOptions<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = (PersistConfig<S, PersistedState, PersistReturn> & {
|
|
305
256
|
sync?: S extends Record<string, unknown> ? SyncOption<S> : undefined;
|
|
306
257
|
}) | ({
|
|
307
258
|
sync: S extends Record<string, unknown> ? SyncWithoutStorageOption<NoInfer<S>> : undefined;
|
|
@@ -316,12 +267,11 @@ export type SyncOption<S extends Record<string, unknown>> = SyncConfig<S> | stri
|
|
|
316
267
|
type SyncWithoutStorageOption<S extends Record<string, unknown>> = string | (Omit<SyncConfig<S>, 'injectStorageMetadata' | 'key'> & {
|
|
317
268
|
injectStorageMetadata?: never;
|
|
318
269
|
key: SyncWithoutStorageKey<SyncConfig<S>>;
|
|
319
|
-
readonly __syncStateBrand?: (state: S) => S;
|
|
320
270
|
});
|
|
321
271
|
type SyncWithoutStorageKey<Config> = Config extends {
|
|
322
272
|
key?: infer Key;
|
|
323
273
|
} ? Extract<Key, string> extends never ? string : Extract<Key, string> : string;
|
|
324
|
-
type UndefinedPersistKeys<S, PersistedState
|
|
274
|
+
type UndefinedPersistKeys<S, PersistedState extends Partial<S>, PersistReturn> = {
|
|
325
275
|
[K in keyof PersistConfig<S, PersistedState, PersistReturn>]?: undefined;
|
|
326
276
|
};
|
|
327
277
|
/**
|
|
@@ -333,5 +283,4 @@ export type DebounceOptions = {
|
|
|
333
283
|
maxWait?: number;
|
|
334
284
|
trailing?: boolean;
|
|
335
285
|
};
|
|
336
|
-
export {};
|
|
337
286
|
//# sourceMappingURL=types.d.ts.map
|