@storesjs/stores 0.9.0 → 0.11.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 +8 -8
- package/dist/createDerivedStore.d.ts +9 -17
- package/dist/createQueryStore.d.ts +11 -16
- package/dist/createVirtualStore.d.ts +1 -2
- 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/index.d.ts +1 -16
- 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/{config.d.ts → internal/config.d.ts} +5 -11
- package/dist/{utils → internal}/createStoreActions.d.ts +4 -5
- package/dist/{derivedStore → internal/derivedStore}/deriveProxy.d.ts +2 -2
- package/dist/{derivedStore → internal/derivedStore}/pathFinder.d.ts +1 -2
- package/dist/internal/derivedStore.d.ts +2 -0
- package/dist/{errors.d.ts → internal/errors.d.ts} +0 -4
- package/dist/{logger.d.ts → internal/logger.d.ts} +0 -2
- package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
- package/dist/internal/queryStore/queryParams.d.ts +18 -0
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/internal/queryStore.d.ts +2 -0
- package/dist/internal/runtime.d.ts +12 -0
- package/dist/internal/storage/storageCreators.d.ts +12 -0
- package/dist/{utils → internal}/storeUtils.d.ts +3 -21
- 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/types/internalSubscribeTypes.d.ts +16 -0
- 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/queryStore/classes/SubscriptionManager.d.ts +3 -31
- package/dist/queryStore/queryKey.d.ts +10 -0
- package/dist/queryStore/queryParam.d.ts +37 -0
- package/dist/queryStore/types.d.ts +12 -53
- 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/cascadeScheduler.d.ts +38 -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/types/setState.d.ts +22 -0
- package/dist/types/subscribe.d.ts +27 -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 +46 -94
- package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
- package/dist/utils/time.d.ts +0 -7
- package/dist/vanilla/createBaseStore.d.ts +35 -0
- package/dist/vanilla/createDerivedStore.d.ts +62 -0
- package/dist/vanilla/createQueryStore.d.ts +110 -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/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/queryParams.d.ts +17 -0
- package/dist/{queryStore → vanilla/internal/queryStore}/queryStoreDefaults.d.ts +1 -2
- package/dist/vanilla/internal/queryStore.d.ts +1 -0
- package/dist/vanilla/internal/runtime.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 +2 -3
- package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
- package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +1 -2
- package/dist/vanilla/internal/virtualStore.d.ts +1 -0
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +38 -0
- package/dist/vanilla/queryStore/queryKey.d.ts +9 -0
- package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
- package/dist/vanilla/queryStore/types.d.ts +360 -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/{derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
- 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 +26 -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 +287 -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 +28 -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-FENSEQ3V.mjs +1 -0
- package/dist/web/chunk-FPYZVFBM.mjs +1 -0
- package/dist/web/chunk-PLDNKWGX.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 +13 -11
- package/dist/createStoreWithEqualityFn.d.ts +0 -5
- package/dist/hooks/compareHooks.d.ts +0 -50
- package/dist/queryStore/signalTypes.d.ts +0 -13
- package/dist/signal.d.ts +0 -11
- 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/web/chunk-3U5A7HQV.mjs +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { defaultRetryDelay } from './internal/runtime';
|
|
2
|
+
import type { QueryStoreConfig, QueryStoreState } from './queryStore/types';
|
|
3
|
+
import type { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
|
|
4
|
+
export { defaultRetryDelay };
|
|
5
|
+
export { getQueryKey, parseQueryKey } from './queryStore/queryKey';
|
|
6
|
+
export { queryParam } from './queryStore/queryParam';
|
|
7
|
+
export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryStore/queryParam';
|
|
8
|
+
/**
|
|
9
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
10
|
+
*
|
|
11
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
12
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
13
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
14
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
15
|
+
*/
|
|
16
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (async storage).
|
|
19
|
+
*
|
|
20
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
21
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
22
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
23
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
24
|
+
*/
|
|
25
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
28
|
+
*
|
|
29
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
30
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
31
|
+
* @template CustomState - User-defined custom store state
|
|
32
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
33
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
34
|
+
*/
|
|
35
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (async storage).
|
|
38
|
+
*
|
|
39
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
40
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
41
|
+
* @template CustomState - User-defined custom store state
|
|
42
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
43
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
44
|
+
*/
|
|
45
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a query-enabled store with data fetching capabilities.
|
|
48
|
+
*
|
|
49
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
50
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
51
|
+
* @template CustomState - User-defined custom store state
|
|
52
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
53
|
+
*/
|
|
54
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options?: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>>): Store<QueryStoreState<TData, TParams, CustomState>>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a query-enabled store with data fetching capabilities.
|
|
57
|
+
*
|
|
58
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
59
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
60
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
61
|
+
*/
|
|
62
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options?: BaseStoreOptions<QueryStoreState<TData, TParams>>): Store<QueryStoreState<TData, TParams>>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a conditionally persisted, query-enabled store with data-fetching capabilities
|
|
65
|
+
* and custom state (sync storage).
|
|
66
|
+
*
|
|
67
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
68
|
+
*
|
|
69
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
70
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
71
|
+
* @template CustomState - User-defined custom store state
|
|
72
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
73
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
74
|
+
*/
|
|
75
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options?: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): OptionallyPersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a conditionally persisted, query-enabled store with data-fetching capabilities
|
|
78
|
+
* and custom state (async storage).
|
|
79
|
+
*
|
|
80
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
81
|
+
*
|
|
82
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
83
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
84
|
+
* @template CustomState - User-defined custom store state
|
|
85
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
86
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
87
|
+
*/
|
|
88
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options?: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): OptionallyPersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a conditionally persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
91
|
+
*
|
|
92
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
93
|
+
*
|
|
94
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
95
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
96
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
97
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
98
|
+
*/
|
|
99
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a conditionally persisted, query-enabled store with data fetching capabilities (async storage).
|
|
102
|
+
*
|
|
103
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
104
|
+
*
|
|
105
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
106
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
107
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
108
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
109
|
+
*/
|
|
110
|
+
export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BaseStore, DeriveGetter, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
|
|
2
|
+
type MethodOverrides<Store extends BaseStore<unknown>> = Partial<Pick<Store, 'getState' | 'setState'>>;
|
|
3
|
+
type VirtualStore<Store extends BaseStore<unknown>> = OptionallyPersistedStore<InferStoreState<Store>, InferPersistedState<Store>, InferSetStateReturn<Store>>;
|
|
4
|
+
type VirtualStoreOptions = {
|
|
5
|
+
debugMode?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether to lock dependencies (see: {@link DeriveOptions}) for the virtual store.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
lockDependencies?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* ### `createVirtualStore`
|
|
14
|
+
*
|
|
15
|
+
* Returns a stable store interface backed by different store instances over time.
|
|
16
|
+
* When dependencies change, the derive function runs and creates a new store, then
|
|
17
|
+
* all subscriptions rebind automatically. Only depend on state that should trigger
|
|
18
|
+
* new store creation.
|
|
19
|
+
*
|
|
20
|
+
* ---
|
|
21
|
+
* 💡 **Note:** `lockDependencies` (see: {@link DeriveOptions}) is enabled by default.
|
|
22
|
+
* Ensure that any `$` dependencies in your `createStore` function are called
|
|
23
|
+
* consistently. If they are not, set `lockDependencies` to `false`.
|
|
24
|
+
*
|
|
25
|
+
* ---
|
|
26
|
+
* @param createStore - Derive function that returns a store instance
|
|
27
|
+
* @param overrides - Optional method overrides (e.g., `getState(id?: string)`)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const useUserAssetsStore = createVirtualStore($ => {
|
|
32
|
+
* const address = $(useWalletsStore).accountAddress;
|
|
33
|
+
* return createUserAssetsStore(address);
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function createVirtualStore<Store extends BaseStore<InferStoreState<Store>>>(createStore: ($: DeriveGetter) => Store, options?: VirtualStoreOptions): VirtualStore<Store>;
|
|
38
|
+
export declare function createVirtualStore<Store extends BaseStore<InferStoreState<Store>>, Overrides extends MethodOverrides<Store>>(createStore: ($: DeriveGetter) => Store, overrides: (getStore: () => Store) => Overrides, options?: VirtualStoreOptions): VirtualStore<Store> & Overrides;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.shared';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=require("../web/internal/runtime.js");function t(e,t,r,n){return e}process.env.NODE_ENV,process.env.NODE_ENV;var r=Object.freeze(Object.create(null));function n(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,r)=>{const o=e[r];return t[r]=function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}(o)?n(o):o,t},Object.create(r))}var o=Symbol("stores.queryParamConfig");Object.defineProperty(exports,"QueryStatuses",{enumerable:!0,get:function(){return e.QueryStatuses}}),Object.defineProperty(exports,"StoresError",{enumerable:!0,get:function(){return e.StoresError}}),Object.defineProperty(exports,"applyStateUpdate",{enumerable:!0,get:function(){return e.applyStateUpdate}}),Object.defineProperty(exports,"configureStores",{enumerable:!0,get:function(){return e.configureStores}}),Object.defineProperty(exports,"createStoreActions",{enumerable:!0,get:function(){return e.createStoreActions}}),Object.defineProperty(exports,"deepEqual",{enumerable:!0,get:function(){return e.deepEqual}}),Object.defineProperty(exports,"defaultRetryDelay",{enumerable:!0,get:function(){return e.defaultRetryDelay}}),Object.defineProperty(exports,"destroyStore",{enumerable:!0,get:function(){return e.destroyStore}}),Object.defineProperty(exports,"destroyStores",{enumerable:!0,get:function(){return e.destroyStores}}),Object.defineProperty(exports,"getStoreName",{enumerable:!0,get:function(){return e.getStoreName}}),Object.defineProperty(exports,"hasGetSnapshot",{enumerable:!0,get:function(){return e.hasGetSnapshot}}),Object.defineProperty(exports,"identity",{enumerable:!0,get:function(){return e.identity}}),Object.defineProperty(exports,"isDerivedStore",{enumerable:!0,get:function(){return e.isDerivedStore}}),Object.defineProperty(exports,"isPersistedStore",{enumerable:!0,get:function(){return e.isPersistedStore}}),Object.defineProperty(exports,"isQueryStore",{enumerable:!0,get:function(){return e.isQueryStore}}),Object.defineProperty(exports,"isVirtualStore",{enumerable:!0,get:function(){return e.isVirtualStore}}),Object.defineProperty(exports,"nullObject",{enumerable:!0,get:function(){return e.nullObject}}),Object.defineProperty(exports,"replacer",{enumerable:!0,get:function(){return e.replacer}}),Object.defineProperty(exports,"reviver",{enumerable:!0,get:function(){return e.reviver}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return e.shallowEqual}}),Object.defineProperty(exports,"time",{enumerable:!0,get:function(){return e.time}}),exports.createBaseStore=function(r,n){const o=e.baseStore(r,n);return t(o,o.getState,o.getInitialState)},exports.createDerivedStore=function(r,n=Object.is){const o=e.derivedStore(r,n);return t(o,o.getSnapshot)},exports.createQueryStore=function(r,n,o){const u=e.queryStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.createVirtualStore=function(r,n,o){const u=e.virtualStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.getQueryKey=function(e){return JSON.stringify(n(e))},exports.parseQueryKey=function(e){return JSON.parse(e)},exports.queryParam=function(e,t){return{[o]:!0,key:t.key,value:e}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{baseStore as t,derivedStore as e,queryStore as r,virtualStore as n}from"../web/internal/runtime.mjs";export{QueryStatuses,StoresError,applyStateUpdate,configureStores,createStoreActions,deepEqual,defaultRetryDelay,destroyStore,destroyStores,getStoreName,hasGetSnapshot,identity,isDerivedStore,isPersistedStore,isQueryStore,isVirtualStore,nullObject,replacer,reviver,shallowEqual,time}from"../web/internal/runtime.mjs";function o(t,e,r,n){return t}function u(e,r){const n=t(e,r);return o(n,n.getState,n.getInitialState)}function i(t,r=Object.is){const n=e(t,r);return o(n,n.getSnapshot)}process.env.NODE_ENV,process.env.NODE_ENV;var s=Object.freeze(Object.create(null));function a(t){return JSON.stringify(l(t))}function c(t){return JSON.parse(t)}function l(t){return"object"!=typeof t||null===t?t:Object.keys(t).sort().reduce((e,r)=>{const n=t[r];return e[r]=function(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}(n)?l(n):n,e},Object.create(s))}var S=Symbol("stores.queryParamConfig");function f(t,e){return{[S]:!0,key:e.key,value:t}}function p(t,e,n){const u=r(t,e,n);return o(u,u.getState,u.getInitialState)}function y(t,e,r){const u=n(t,e,r);return o(u,u.getState,u.getInitialState)}export{u as createBaseStore,i as createDerivedStore,p as createQueryStore,y as createVirtualStore,a as getQueryKey,c as parseQueryKey,f as queryParam};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './createBaseStore';
|
|
2
|
+
export * from './createDerivedStore';
|
|
3
|
+
export * from './createQueryStore';
|
|
4
|
+
export * from './createVirtualStore';
|
|
5
|
+
export { configureStores, StoresError } from './internal/runtime';
|
|
6
|
+
export { applyStateUpdate, replacer, reviver } from './internal/runtime';
|
|
7
|
+
export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './internal/runtime';
|
|
8
|
+
export type * from './sync/types';
|
|
9
|
+
export { QueryStatuses } from './internal/runtime';
|
|
10
|
+
export type * from './queryStore/types';
|
|
11
|
+
export type * from './storage/storageTypes';
|
|
12
|
+
export type * from './types';
|
|
13
|
+
export { createStoreActions, deepEqual, identity, nullObject, shallowEqual, time } from './internal/runtime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.shared';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { QueryStoreConfig } from '../queryStore/types';
|
|
2
|
+
import { SyncEngine } from '../sync/types';
|
|
3
|
+
import { AsyncStorageInterface, SyncStorageInterface } from '../types';
|
|
4
|
+
import { NonFunction } from '../types/functions';
|
|
5
|
+
import { Prettify } from '../types/objects';
|
|
6
|
+
import { Logger } from './logger';
|
|
7
|
+
/**
|
|
8
|
+
* Global configuration for all stores.
|
|
9
|
+
*/
|
|
10
|
+
export type StoresConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* Custom logger for debug output. Defaults to a no-op logger in production.
|
|
13
|
+
*/
|
|
14
|
+
logger: Logger;
|
|
15
|
+
/**
|
|
16
|
+
* Default options used by all query stores.
|
|
17
|
+
*/
|
|
18
|
+
queryStoreDefaults: QueryStoreDefaults;
|
|
19
|
+
/**
|
|
20
|
+
* Storage backend for persisted stores. Defaults to `localStorage` in browsers,
|
|
21
|
+
* MMKV in React Native.
|
|
22
|
+
*/
|
|
23
|
+
storage: AsyncStorageInterface | SyncStorageInterface;
|
|
24
|
+
/**
|
|
25
|
+
* Prefix for storage keys built by the default storage adapter.
|
|
26
|
+
* Should include a delimiter, e.g., `'myapp:'`.
|
|
27
|
+
* @default 'stores:'
|
|
28
|
+
*/
|
|
29
|
+
storageKeyPrefix: string;
|
|
30
|
+
/**
|
|
31
|
+
* Sync engine for cross-client state synchronization. Defaults to cross-tab sync
|
|
32
|
+
* in browsers, no-op in other environments.
|
|
33
|
+
*/
|
|
34
|
+
syncEngine: SyncEngine;
|
|
35
|
+
};
|
|
36
|
+
export type QueryStoreDefaults = Prettify<ConfigDefaults<QueryStoreConfig<unknown, Record<string, unknown>>, 'disableCache' | 'enabled' | 'params', 'retryDelay'>> & {
|
|
37
|
+
/**
|
|
38
|
+
* Minimum stale time for auto-refetching query stores under which to log warnings in development.
|
|
39
|
+
* `false` disables warnings.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
minStaleTime?: number | false;
|
|
43
|
+
};
|
|
44
|
+
type ConfigDefaults<C, Excluded extends keyof C = never, AllowedFunctions extends keyof C = never> = Omit<{
|
|
45
|
+
[K in keyof C as K extends AllowedFunctions ? K : NonFunction<C[K]> extends undefined ? never : K]?: K extends AllowedFunctions ? C[K] : NonFunction<C[K]>;
|
|
46
|
+
}, Excluded>;
|
|
47
|
+
/**
|
|
48
|
+
* Configures global defaults for all stores.
|
|
49
|
+
*
|
|
50
|
+
* If used, must be called before creating any stores.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link StoresConfig}
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* configureStores({
|
|
57
|
+
* logger: { debug: console.debug, error: console.error },
|
|
58
|
+
* storageKeyPrefix: 'myapp:',
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function configureStores(config: Partial<StoresConfig>): void;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StoreApi } from '../store/types';
|
|
2
|
+
import type { InferStoreState, StoreActions } from '../types';
|
|
3
|
+
import type { FunctionRecord } from '../types/functions';
|
|
4
|
+
import type { NoOverlap } from '../types/objects';
|
|
5
|
+
/**
|
|
6
|
+
* Given a store instance, produces a new object containing only its actions.
|
|
7
|
+
*
|
|
8
|
+
* Intended for export alongside the associated store.
|
|
9
|
+
*
|
|
10
|
+
* @param store - The store to create actions for.
|
|
11
|
+
* @param bundledMethods - Optional extra methods to bundle into the actions object.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* export const useCounterStore = createRainbowStore(set => ({
|
|
15
|
+
* count: 0,
|
|
16
|
+
* increment: () => set(state => ({ count: state.count + 1 })),
|
|
17
|
+
* }));
|
|
18
|
+
*
|
|
19
|
+
* export const exampleActions = createStoreActions(useExampleStore);
|
|
20
|
+
* exampleActions.increment();
|
|
21
|
+
*/
|
|
22
|
+
export declare function createStoreActions<Store extends StoreApi<unknown>>(store: Store): StoreActions<Store>;
|
|
23
|
+
export declare function createStoreActions<Store extends StoreApi<unknown>, Bundled extends FunctionRecord>(store: Store, bundledMethods: NoOverlap<InferStoreState<Store>, Bundled>): StoreActions<Store> & Bundled;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StoreApi } from '../../store/types';
|
|
2
|
+
import { TrackPathFn } from './pathFinder';
|
|
3
|
+
/**
|
|
4
|
+
* Gets or creates a lightweight tracking proxy that records path access and store
|
|
5
|
+
* method invocations via proxy traps. Used to auto-generate selectors that point
|
|
6
|
+
* to either the accessed path or the value returned by an invoked store method.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getOrCreateProxy<S>(store: StoreApi<S>, rootProxyCache: WeakMap<object, unknown>, trackPath: TrackPathFn): S;
|
|
9
|
+
/**
|
|
10
|
+
* Strips tracking proxies from published values to ensure
|
|
11
|
+
* proxies remain confined to internal tracking contexts.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripProxies<T>(value: T): T;
|
|
14
|
+
export declare function stripProxies(value: unknown, seen?: WeakSet<object>): unknown;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Selector, SubscribableStore } from '../../types';
|
|
2
|
+
type TrackedInvocation = {
|
|
3
|
+
args: unknown[] | undefined;
|
|
4
|
+
};
|
|
5
|
+
type PathEntry = {
|
|
6
|
+
path: string[];
|
|
7
|
+
store: SubscribableStore;
|
|
8
|
+
invocation?: TrackedInvocation;
|
|
9
|
+
isLeaf: boolean;
|
|
10
|
+
};
|
|
11
|
+
type SubscriptionBuilder = (store: SubscribableStore, selector: Selector<unknown, unknown>, path: string[]) => void;
|
|
12
|
+
export type PathFinder = {
|
|
13
|
+
buildProxySubscriptions(createSubscription: SubscriptionBuilder, shouldLog: boolean, minConsolidationDepth?: number, shouldBuild?: (paths: Set<PathEntry>) => boolean): void;
|
|
14
|
+
reset(): void;
|
|
15
|
+
trackPath: TrackPathFn;
|
|
16
|
+
};
|
|
17
|
+
export type TrackPathFn = (store: SubscribableStore, path: string[], isLeaf: boolean, invocation?: TrackedInvocation) => void;
|
|
18
|
+
/**
|
|
19
|
+
* A factory that returns a proxy path-tracking object with three methods:
|
|
20
|
+
* - `buildProxySubscriptions()`: builds subscriptions to the final paths
|
|
21
|
+
* - `reset()`: clears all tracked paths
|
|
22
|
+
* - `trackPath()`: records usage of a store path
|
|
23
|
+
*/
|
|
24
|
+
export declare function createPathFinder(): PathFinder;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error reported or thrown by the stores package itself.
|
|
3
|
+
*
|
|
4
|
+
* If an underlying thrown value caused the failure, it is available as `cause`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StoresError extends Error {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
constructor(message: string, cause?: unknown);
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
debug: (message: string, context?: Record<string, unknown>) => void;
|
|
3
|
+
error: {
|
|
4
|
+
<T extends Error>(error: T, context?: Record<string, unknown>): void;
|
|
5
|
+
<T extends string>(error: T, context?: Record<string, unknown>): void;
|
|
6
|
+
};
|
|
7
|
+
info: (message: string, context?: Record<string, unknown>) => void;
|
|
8
|
+
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
9
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { StateCreator } from '../../types';
|
|
1
2
|
import { SyncContext } from '../sync/syncEnhancer';
|
|
2
|
-
import { StateCreator } from '../types';
|
|
3
3
|
type WrappedOnRehydrateStorage<S> = (userCallback: ((state: S) => ((finalState?: S, error?: unknown) => void) | void) | undefined, syncContext: SyncContext | undefined) => (state: S) => (finalState?: S, error?: unknown) => void;
|
|
4
4
|
/**
|
|
5
5
|
* Creates hydration-gating middleware that queues state updates until rehydration completes.
|
|
@@ -17,4 +17,3 @@ export declare function createHydrationGate<S>(stateCreator: StateCreator<S>): {
|
|
|
17
17
|
wrapOnRehydrateStorage: WrappedOnRehydrateStorage<S>;
|
|
18
18
|
};
|
|
19
19
|
export {};
|
|
20
|
-
//# sourceMappingURL=createHydrationGate.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QueryParam, ReactiveParam } from '../../queryStore/queryParam';
|
|
2
|
+
import type { StoreApi } from '../../store/types';
|
|
3
|
+
import type { InternalUnsubscribeFn } from '../types/internalSubscribeTypes';
|
|
4
|
+
export type TrackedValue<T> = {
|
|
5
|
+
readonly initialValue: T;
|
|
6
|
+
subscribe(listener: (value: T) => void): InternalUnsubscribeFn;
|
|
7
|
+
};
|
|
8
|
+
export type QueryParams<TParams extends Record<string, unknown>> = {
|
|
9
|
+
buildKey(params?: TParams): string;
|
|
10
|
+
complete(params: Partial<TParams> | undefined): TParams;
|
|
11
|
+
get(): TParams;
|
|
12
|
+
subscribe(onChange: (key: keyof TParams, oldValue: unknown, newValue: unknown) => void): InternalUnsubscribeFn;
|
|
13
|
+
};
|
|
14
|
+
export declare function createQueryParams<TParams extends Record<string, unknown>, State>(params: {
|
|
15
|
+
[K in keyof TParams]: QueryParam<TParams[K], State>;
|
|
16
|
+
} | undefined, store: StoreApi<State>, requiredKeys: (keyof TParams)[]): QueryParams<TParams>;
|
|
17
|
+
export declare function trackQueryValue<T, State>(getValue: ReactiveParam<T, State>, ownerStore: StoreApi<State>): TrackedValue<T>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { Prettify } from '../../types/objects';
|
|
1
2
|
import { QueryStoreDefaults } from '../config';
|
|
2
|
-
import { Prettify } from '../types/objects';
|
|
3
3
|
export declare function getQueryStoreDefaults(): Prettify<Required<QueryStoreDefaults>>;
|
|
4
4
|
/**
|
|
5
5
|
* Exponential backoff: starts at `baseDelay` (5s), doubles each retry, capped at `maxDelay` (5m).
|
|
6
6
|
*/
|
|
7
7
|
export declare function defaultRetryDelay(retryCount: number): number;
|
|
8
|
-
//# sourceMappingURL=queryStoreDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { configureStores } from './config';
|
|
2
|
+
export { StoresError } from './errors';
|
|
3
|
+
export { QueryStatuses } from '../queryStore/types';
|
|
4
|
+
export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
|
|
5
|
+
export { applyStateUpdate } from '../store/stateUpdate';
|
|
6
|
+
export { replacer, reviver } from '../utils/serialization';
|
|
7
|
+
export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './storeUtils';
|
|
8
|
+
export { identity, nullObject } from '../utils/core';
|
|
9
|
+
export { createStoreActions } from './createStoreActions';
|
|
10
|
+
export { deepEqual, shallowEqual } from '../utils/equality';
|
|
11
|
+
export { time } from '../utils/time';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AsyncPersistStorage, PersistStorageConfig } from '../../store/types';
|
|
2
|
+
import type { AsyncStorageInterface, BaseStoreOptions, EnforceStorageKey, SyncStorageInterface } from '../../types';
|
|
3
|
+
import type { SyncContext } from '../sync/syncEnhancer';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a persist storage object for the base store.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, storage: AsyncStorageInterface | SyncStorageInterface | undefined, syncContext: SyncContext | undefined): PersistStorageConfig<S, PersistedState>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an asynchronous persist storage adapter.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAsyncPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(storage: AsyncStorageInterface, options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, persistThrottleMs: number | undefined, syncContext?: SyncContext): AsyncPersistStorage<S, PersistedState>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { QueryStore, QueryStoreState } from '../queryStore/types';
|
|
2
|
+
import type { StoreApi } from '../store/types';
|
|
3
|
+
import type { BaseStore, InferStoreState, PersistedStore } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Calls the appropriate reset or destroy method on the store, if available.
|
|
6
|
+
* Handles both `DerivedStore` and `QueryStore`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function destroyStore(store: BaseStore<unknown> | StoreApi<unknown> | QueryStore<unknown, Record<string, unknown>, unknown>, options?: {
|
|
9
|
+
clearQueryCache?: boolean;
|
|
10
|
+
}): void;
|
|
11
|
+
export declare function destroyStores(stores: Partial<Record<string, BaseStore<unknown> | StoreApi<unknown>>> | (BaseStore<unknown> | StoreApi<unknown> | undefined)[], options?: {
|
|
12
|
+
clearQueryCache?: boolean;
|
|
13
|
+
skipDestroy?: (store: BaseStore<unknown> | StoreApi<unknown>) => boolean;
|
|
14
|
+
}): void;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the name of the store, either from the `persist` options or the store itself.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getStoreName(store: BaseStore<unknown>): string;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a store is a `DerivedStore` and reveals its internal `getSnapshot` method.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasGetSnapshot<T extends BaseStore<unknown> | StoreApi<unknown>>(store: T): store is T & {
|
|
23
|
+
getSnapshot: () => InferStoreState<T>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a store is a `QueryStore`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isQueryStore<T extends object>(store: T): store is Extract<T, BaseStore<QueryStoreState<unknown, Record<string, unknown>, unknown>>>;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a store is a `DerivedStore`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isDerivedStore<T extends BaseStore<unknown> | StoreApi<unknown>>(store: T): store is T & {
|
|
33
|
+
destroy: () => void;
|
|
34
|
+
flushUpdates: () => void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a store is persisted.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isPersistedStore<T extends BaseStore<unknown> | PersistedStore<unknown>>(store: T): store is T & {
|
|
40
|
+
persist: PersistedStore<InferStoreState<T>>['persist'];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a store is a virtual store.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isVirtualStore<T extends BaseStore<unknown> | StoreApi<unknown>>(store: T): store is T & BaseStore<InferStoreState<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { NormalizedSyncConfig } from '../../sync/types';
|
|
2
|
+
import { StateCreator } from '../../types';
|
|
3
3
|
export type SyncContext = {
|
|
4
4
|
isAsync: boolean;
|
|
5
5
|
clearFieldTimestamps: (snapshot: Record<string, number> | undefined) => void;
|
|
@@ -23,4 +23,3 @@ export declare function createSyncedStateCreator<T extends Record<string, unknow
|
|
|
23
23
|
* Readable indices for `FieldMetadata` tuples.
|
|
24
24
|
*/
|
|
25
25
|
export declare const TIMESTAMP: 0, SESSION_ID: 1;
|
|
26
|
-
//# sourceMappingURL=syncEnhancer.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Listener, ListenerArgs, Selector, SubscribeOptions } from '../../types/subscribe';
|
|
2
|
+
export type InternalSubscribeOptions<Selected> = SubscribeOptions<Selected> & {
|
|
3
|
+
isCascadeParticipant?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type InternalSelectorArgs<S, Selected> = [
|
|
6
|
+
selector: Selector<S, Selected>,
|
|
7
|
+
listener: Listener<Selected>,
|
|
8
|
+
options?: InternalSubscribeOptions<Selected>
|
|
9
|
+
];
|
|
10
|
+
export type InternalSubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | InternalSelectorArgs<S, Selected>;
|
|
11
|
+
export type InternalUnsubscribeFn = (skipAbortFetch?: boolean) => void;
|
|
12
|
+
export type InternalSubscribeOverloads<S> = {
|
|
13
|
+
(...args: ListenerArgs<S>): InternalUnsubscribeFn;
|
|
14
|
+
<Selected>(...args: InternalSelectorArgs<S, Selected>): InternalUnsubscribeFn;
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StorageValue } from '
|
|
1
|
+
import type { StorageValue } from '../../storage/storageTypes';
|
|
2
2
|
/**
|
|
3
3
|
* Default partialize function if none is provided. It omits top-level store
|
|
4
4
|
* methods and keeps all other state.
|
|
@@ -6,4 +6,3 @@ import type { StorageValue } from '../storage/storageTypes';
|
|
|
6
6
|
export declare function omitStoreMethods<S, PersistedState extends Partial<S> = Partial<S>>(state: S): PersistedState;
|
|
7
7
|
export declare function defaultSerializeState<PersistedState>(storageValue: StorageValue<PersistedState>, shouldUseReplacer: boolean): string;
|
|
8
8
|
export declare function defaultDeserializeState<PersistedState>(serializedState: string, shouldUseReviver: boolean): StorageValue<PersistedState>;
|
|
9
|
-
//# sourceMappingURL=persistUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy initialization config for subscription handlers.
|
|
3
|
+
*/
|
|
4
|
+
interface SubscriptionHandlerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Callback executed when a subscription is added.
|
|
7
|
+
* @param isFirstSubscription - Whether this is the first subscription
|
|
8
|
+
* @param shouldThrottle - Whether to throttle the fetch
|
|
9
|
+
*/
|
|
10
|
+
onSubscribe: (isFirstSubscription: boolean, shouldThrottle: boolean) => void;
|
|
11
|
+
/** Callback executed when the last remaining subscription is removed. */
|
|
12
|
+
onLastUnsubscribe: (willResubscribe?: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Manages subscription state and lifecycle events for a `createQueryStore` instance.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SubscriptionManager {
|
|
18
|
+
private count;
|
|
19
|
+
private lastSubscriptionTime;
|
|
20
|
+
private readonly fetchThrottleMs;
|
|
21
|
+
private onSubscribe;
|
|
22
|
+
private onLastUnsubscribe;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new SubscriptionManager instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(disableAutoRefetching: boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Initializes subscription event handlers.
|
|
29
|
+
*/
|
|
30
|
+
init({ onSubscribe, onLastUnsubscribe }: SubscriptionHandlerConfig): void;
|
|
31
|
+
hasSubscribers(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Adds a new subscription and triggers relevant lifecycle callbacks.
|
|
34
|
+
* @returns A cleanup function that removes the subscription when called
|
|
35
|
+
*/
|
|
36
|
+
subscribe(): (skipAbortFetch?: boolean) => void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a deterministic query store `queryKey` from the given
|
|
3
|
+
* key payload, consistent with internally generated keys.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getQueryKey<TKeyPayload extends Record<string, unknown>>(keyPayload: TKeyPayload): string;
|
|
6
|
+
/**
|
|
7
|
+
* Parses a query store `queryKey` into the key payload it encodes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseQueryKey<TKeyPayload extends Record<string, unknown> = Record<string, unknown>>(queryKey: string): TKeyPayload;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StoreApi } from '../store/types';
|
|
2
|
+
import type { DeriveGetter } from '../types';
|
|
3
|
+
import type { NonFunction } from '../types/functions';
|
|
4
|
+
declare const QUERY_PARAM_CONFIG: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Selects how a query parameter participates in the query key.
|
|
7
|
+
*/
|
|
8
|
+
export type QueryParamKey<T> = false | ((value: T) => unknown);
|
|
9
|
+
/**
|
|
10
|
+
* A query value derived from stores via `$`.
|
|
11
|
+
*/
|
|
12
|
+
export type ReactiveParam<T, State> = ($: DeriveGetter, store: StoreApi<State>) => T;
|
|
13
|
+
/**
|
|
14
|
+
* Query parameter wrapper for values whose fetcher value and key value differ.
|
|
15
|
+
*/
|
|
16
|
+
export type QueryParamConfig<T, State> = {
|
|
17
|
+
readonly [QUERY_PARAM_CONFIG]: true;
|
|
18
|
+
readonly key: QueryParamKey<T>;
|
|
19
|
+
readonly value: NonFunction<T> | ReactiveParam<T, State>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A direct, reactive, or key-configured query parameter.
|
|
23
|
+
*/
|
|
24
|
+
export type QueryParam<T, State> = NonFunction<T> | ReactiveParam<T, State> | QueryParamConfig<T, State>;
|
|
25
|
+
/**
|
|
26
|
+
* Wraps a query parameter when its full fetcher value should be excluded
|
|
27
|
+
* from the query key or represented by a smaller key value.
|
|
28
|
+
*/
|
|
29
|
+
export declare function queryParam<T, State>(value: NonFunction<T> | ReactiveParam<T, State>, options: {
|
|
30
|
+
key: QueryParamKey<T>;
|
|
31
|
+
}): QueryParamConfig<T, State>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a `QueryParam` value is a custom `queryParam(...)` config.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isQueryParamConfig<T, State>(value: QueryParam<T, State>): value is QueryParamConfig<T, State>;
|
|
36
|
+
export {};
|