@storesjs/stores 0.9.0 → 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 +4 -3
- 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/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 +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/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/queryKey.d.ts +3 -0
- package/dist/queryStore/signalTypes.d.ts +4 -3
- package/dist/queryStore/types.d.ts +5 -4
- 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/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 +43 -93
- 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 +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/vanilla/internal/derivedStore/cascadeScheduler.d.ts +30 -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/{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 +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 +2 -3
- 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 +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 +13 -11
- package/dist/createStoreWithEqualityFn.d.ts +0 -5
- package/dist/hooks/compareHooks.d.ts +0 -50
- 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
- /package/dist/{derivedStore → internal/derivedStore}/cascadeScheduler.d.ts +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
7
|
+
*
|
|
8
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
9
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
10
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
11
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
12
|
+
*/
|
|
13
|
+
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, false>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (async storage).
|
|
16
|
+
*
|
|
17
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
18
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
19
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
20
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
21
|
+
*/
|
|
22
|
+
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, false>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
25
|
+
*
|
|
26
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
27
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
28
|
+
* @template CustomState - User-defined custom store state
|
|
29
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
30
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
31
|
+
*/
|
|
32
|
+
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, false>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a persisted, query-enabled store with data fetching capabilities (async storage).
|
|
35
|
+
*
|
|
36
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
37
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
38
|
+
* @template CustomState - User-defined custom store state
|
|
39
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
40
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
41
|
+
*/
|
|
42
|
+
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, false>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a query-enabled store with data fetching capabilities.
|
|
45
|
+
*
|
|
46
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
47
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
48
|
+
* @template CustomState - User-defined custom store state
|
|
49
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
50
|
+
*/
|
|
51
|
+
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>>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a query-enabled store with data fetching capabilities.
|
|
54
|
+
*
|
|
55
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
56
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
57
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
58
|
+
*/
|
|
59
|
+
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>>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a conditionally persisted, query-enabled store with data-fetching capabilities
|
|
62
|
+
* and custom state (sync storage).
|
|
63
|
+
*
|
|
64
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
65
|
+
*
|
|
66
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
67
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
68
|
+
* @template CustomState - User-defined custom store state
|
|
69
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
70
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
71
|
+
*/
|
|
72
|
+
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>;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a conditionally persisted, query-enabled store with data-fetching capabilities
|
|
75
|
+
* and custom state (async storage).
|
|
76
|
+
*
|
|
77
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
78
|
+
*
|
|
79
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
80
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
81
|
+
* @template CustomState - User-defined custom store state
|
|
82
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
83
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
84
|
+
*/
|
|
85
|
+
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>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a conditionally persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
88
|
+
*
|
|
89
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
90
|
+
*
|
|
91
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
92
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
93
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
94
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
95
|
+
*/
|
|
96
|
+
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>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a conditionally persisted, query-enabled store with data fetching capabilities (async storage).
|
|
99
|
+
*
|
|
100
|
+
* `options.persist` may be `undefined` – the returned store exposes `persist?`.
|
|
101
|
+
*
|
|
102
|
+
* @template TQueryFnData - The raw data type returned by the fetcher
|
|
103
|
+
* @template TParams - Parameters passed to the fetcher function
|
|
104
|
+
* @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
|
|
105
|
+
* @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
|
|
106
|
+
*/
|
|
107
|
+
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>;
|
|
108
|
+
/**
|
|
109
|
+
* Generates a deterministic query store `queryKey` from the given parameters,
|
|
110
|
+
* consistent with internally generated keys.
|
|
111
|
+
*/
|
|
112
|
+
export declare function getQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
|
|
113
|
+
/**
|
|
114
|
+
* Parses a query store `queryKey` into the corresponding parameters.
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseQueryKey<TParams extends Record<string, unknown>>(queryKey: string): TParams;
|
|
@@ -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}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(t){return e.getQueryKey(t)},exports.parseQueryKey=function(t){return e.parseQueryKey(t)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{baseStore as t,derivedStore as e,queryStore as r,getQueryKey as n,parseQueryKey as o,virtualStore as i}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 a(t,e,r,n){return t}function s(e,r){const n=t(e,r);return a(n,n.getState,n.getInitialState)}function u(t,r=Object.is){const n=e(t,r);return a(n,n.getSnapshot)}function S(t,e,n){const o=r(t,e,n);return a(o,o.getState,o.getInitialState)}function c(t){return n(t)}function l(t){return o(t)}function y(t,e,r){const n=i(t,e,r);return a(n,n.getState,n.getInitialState)}export{s as createBaseStore,u as createDerivedStore,S as createQueryStore,y as createVirtualStore,c as getQueryKey,l as parseQueryKey};
|
|
@@ -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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cascade Scheduler
|
|
3
|
+
*
|
|
4
|
+
* - Coalesces derivations into a single microtask.
|
|
5
|
+
* - Tasks run once at their maximum rank via a ranked dirty queue.
|
|
6
|
+
* - Doesn't retain snapshots or dependency graphs.
|
|
7
|
+
* - Component listeners get notified after all derivations have settled.
|
|
8
|
+
*/
|
|
9
|
+
type Rank = number;
|
|
10
|
+
type StoreId = string;
|
|
11
|
+
type Task = () => void;
|
|
12
|
+
export declare function isCascadeActive(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Rank of the currently running derive batch, or null if not in a batch.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCurrentDeriveRank(): Rank | null;
|
|
17
|
+
/**
|
|
18
|
+
* Arms the cascade and schedules a single microtask flush.
|
|
19
|
+
*/
|
|
20
|
+
export declare function activateCascade(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Enlist one per-store component flush (idempotent per store).
|
|
23
|
+
*/
|
|
24
|
+
export declare function joinCascade(storeId: StoreId, task: Task): void;
|
|
25
|
+
/**
|
|
26
|
+
* Enqueue (or upgrade) a derive task with the given rank.
|
|
27
|
+
* If the task is already present, we keep the maximum rank (run later).
|
|
28
|
+
*/
|
|
29
|
+
export declare function enqueueDerive(task: Task, rank: Rank): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseStore } from '../../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: BaseStore<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
|
|
@@ -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,12 @@
|
|
|
1
|
+
export { configureStores } from './config';
|
|
2
|
+
export { StoresError } from './errors';
|
|
3
|
+
export { QueryStatuses } from '../queryStore/types';
|
|
4
|
+
export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
|
|
5
|
+
export { getQueryKey, parseQueryKey } from '../queryStore/queryKey';
|
|
6
|
+
export { applyStateUpdate } from '../store/stateUpdate';
|
|
7
|
+
export { replacer, reviver } from '../utils/serialization';
|
|
8
|
+
export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './storeUtils';
|
|
9
|
+
export { identity, nullObject } from '../utils/core';
|
|
10
|
+
export { createStoreActions } from './createStoreActions';
|
|
11
|
+
export { deepEqual, shallowEqual } from '../utils/equality';
|
|
12
|
+
export { time } from '../utils/time';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AttachValue } from '../queryStore/signalTypes';
|
|
2
|
+
import type { StoreApi } from '../store/types';
|
|
3
|
+
import type { EqualityFn, Selector, UnsubscribeFn } from '../types/subscribe';
|
|
4
|
+
export declare const attachValueSubscriptionMap: WeakMap<AttachValue<unknown>, Subscribe>;
|
|
5
|
+
export type Subscribe = (callback: () => void) => UnsubscribeFn;
|
|
6
|
+
export type GetValue = () => unknown;
|
|
7
|
+
export type SetValue = (path: unknown[], value: unknown) => void;
|
|
8
|
+
export declare function $<T>(store: StoreApi<T>): AttachValue<T>;
|
|
9
|
+
export declare function $<T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
|
|
10
|
+
export declare const createSignal: <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn: EqualityFn<S>) => [Subscribe, GetValue, SetValue];
|
|
11
|
+
export declare function getAttachValueSubscribeFn<AttachVal extends AttachValue<unknown>>(attachVal: AttachVal): Subscribe | undefined;
|
|
@@ -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
|
|
@@ -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,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialization config for the SubscriptionManager.
|
|
3
|
+
*/
|
|
4
|
+
interface SubscriptionManagerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The store's `disableAutoRefetching` option, passed through from the query config.
|
|
7
|
+
*/
|
|
8
|
+
disableAutoRefetching: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The initial enabled state for the SubscriptionManager.
|
|
11
|
+
*/
|
|
12
|
+
initialEnabled: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Lazy initialization config for subscription handlers.
|
|
16
|
+
*/
|
|
17
|
+
interface SubscriptionHandlerConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Callback executed when a subscription is added.
|
|
20
|
+
* @param enabled - The current enabled state
|
|
21
|
+
* @param isFirstSubscription - Whether this is the first subscription
|
|
22
|
+
* @param shouldThrottle - Whether to throttle the fetch
|
|
23
|
+
*/
|
|
24
|
+
onSubscribe: (enabled: boolean, isFirstSubscription: boolean, shouldThrottle: boolean) => void;
|
|
25
|
+
/** Callback executed when the last remaining subscription is removed. */
|
|
26
|
+
onLastUnsubscribe: (willResubscribe?: boolean) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Manages subscription state and lifecycle events for a `createQueryStore` instance.
|
|
30
|
+
*/
|
|
31
|
+
export declare class SubscriptionManager {
|
|
32
|
+
private count;
|
|
33
|
+
private enabled;
|
|
34
|
+
private lastSubscriptionTime;
|
|
35
|
+
private readonly fetchThrottleMs;
|
|
36
|
+
private onSubscribe;
|
|
37
|
+
private onLastUnsubscribe;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new SubscriptionManager instance.
|
|
40
|
+
*/
|
|
41
|
+
constructor({ disableAutoRefetching, initialEnabled }: SubscriptionManagerConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Initializes subscription event handlers.
|
|
44
|
+
*/
|
|
45
|
+
init({ onSubscribe, onLastUnsubscribe }: SubscriptionHandlerConfig): void;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the current subscription state.
|
|
48
|
+
* @returns An object containing `enabled`, `lastSubscriptionTime`, and `subscriptionCount`
|
|
49
|
+
*/
|
|
50
|
+
get(): {
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
lastSubscriptionTime: number | null;
|
|
53
|
+
subscriptionCount: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Updates the enabled state for queries.
|
|
57
|
+
* @param enabled - The new enabled state
|
|
58
|
+
*/
|
|
59
|
+
setEnabled(enabled: boolean): void;
|
|
60
|
+
/**
|
|
61
|
+
* Adds a new subscription and triggers relevant lifecycle callbacks.
|
|
62
|
+
* @returns A cleanup function that removes the subscription when called
|
|
63
|
+
*/
|
|
64
|
+
subscribe(): (skipAbortFetch?: boolean) => void;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoreApi } from '../store/types';
|
|
2
|
+
import type { EqualityFn, Selector } from '../types/subscribe';
|
|
3
|
+
type NestedAttachValue<T> = T extends object ? {
|
|
4
|
+
readonly [K in keyof T]: AttachValue<T[K]>;
|
|
5
|
+
} : Record<string, never>;
|
|
6
|
+
export type AttachValue<T> = {
|
|
7
|
+
readonly value: T;
|
|
8
|
+
} & NestedAttachValue<T>;
|
|
9
|
+
export type SignalFunction = {
|
|
10
|
+
<T>(store: StoreApi<T>): AttachValue<T>;
|
|
11
|
+
<T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|