@storesjs/stores 0.11.0 → 0.12.1

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.
Files changed (157) hide show
  1. package/dist/index.d.ts +1586 -4
  2. package/dist/native/index.js +7 -1
  3. package/dist/native/index.mjs +7 -1
  4. package/dist/plugins/chrome/index.d.ts +186 -4
  5. package/dist/vanilla/index.js +1 -1
  6. package/dist/vanilla/index.mjs +1 -1
  7. package/dist/vanilla/index.vanilla.d.ts +1472 -1
  8. package/dist/web/chrome.js +1 -1
  9. package/dist/web/chrome.mjs +1 -1
  10. package/dist/web/index.js +1 -1
  11. package/dist/web/index.mjs +1 -1
  12. package/dist/web/internal/runtime.js +2 -1
  13. package/dist/web/internal/runtime.mjs +2 -1
  14. package/dist/web/queryParam-Ckp7Zi5t.mjs +1 -0
  15. package/dist/web/queryParam-Ctnhipnd.js +1 -0
  16. package/dist/web/serialization-BgaGfw_1.mjs +1 -0
  17. package/dist/web/serialization-Dau9pNHc.js +1 -0
  18. package/dist/web/utils-Ba1RIeAA.mjs +1 -0
  19. package/dist/web/utils-CwejruRb.js +1 -0
  20. package/package.json +9 -8
  21. package/dist/createBaseStore.d.ts +0 -36
  22. package/dist/createDerivedStore.d.ts +0 -63
  23. package/dist/createQueryStore.d.ts +0 -111
  24. package/dist/createVirtualStore.d.ts +0 -40
  25. package/dist/env.native.d.ts +0 -7
  26. package/dist/env.web.d.ts +0 -7
  27. package/dist/hooks/useLazyRef.d.ts +0 -13
  28. package/dist/hooks/useListen.d.ts +0 -98
  29. package/dist/hooks/useStableValue.d.ts +0 -16
  30. package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +0 -5
  31. package/dist/index.shared.d.ts +0 -14
  32. package/dist/index.vanilla.d.ts +0 -2
  33. package/dist/internal/baseStore.d.ts +0 -2
  34. package/dist/internal/config.d.ts +0 -64
  35. package/dist/internal/createStoreActions.d.ts +0 -24
  36. package/dist/internal/derivedStore/deriveProxy.d.ts +0 -15
  37. package/dist/internal/derivedStore/pathFinder.d.ts +0 -26
  38. package/dist/internal/derivedStore.d.ts +0 -2
  39. package/dist/internal/errors.d.ts +0 -10
  40. package/dist/internal/logger.d.ts +0 -10
  41. package/dist/internal/middleware/createHydrationGate.d.ts +0 -20
  42. package/dist/internal/queryStore/queryParams.d.ts +0 -18
  43. package/dist/internal/queryStore/queryStoreDefaults.d.ts +0 -8
  44. package/dist/internal/queryStore.d.ts +0 -2
  45. package/dist/internal/runtime.d.ts +0 -12
  46. package/dist/internal/storage/storageCreators.d.ts +0 -12
  47. package/dist/internal/storeUtils.d.ts +0 -46
  48. package/dist/internal/sync/browserSyncEngine.d.ts +0 -3
  49. package/dist/internal/sync/noopSyncEngine.d.ts +0 -3
  50. package/dist/internal/sync/syncEnhancer.d.ts +0 -26
  51. package/dist/internal/sync/syncUtils.d.ts +0 -6
  52. package/dist/internal/types/internalSubscribeTypes.d.ts +0 -16
  53. package/dist/internal/utils/persistUtils.d.ts +0 -9
  54. package/dist/internal/virtualStore.d.ts +0 -2
  55. package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +0 -30
  56. package/dist/plugins/chrome/chromeStorageAdapter.d.ts +0 -31
  57. package/dist/plugins/chrome/createSyncedChromeStorage.d.ts +0 -14
  58. package/dist/queryStore/classes/SubscriptionManager.d.ts +0 -39
  59. package/dist/queryStore/queryKey.d.ts +0 -10
  60. package/dist/queryStore/queryParam.d.ts +0 -37
  61. package/dist/queryStore/types.d.ts +0 -361
  62. package/dist/storage/storageTypes.d.ts +0 -13
  63. package/dist/store/attachStoreHook.react.d.ts +0 -5
  64. package/dist/store/attachStoreHook.vanilla.d.ts +0 -6
  65. package/dist/store/batchStoreNotifications.native.d.ts +0 -3
  66. package/dist/store/batchStoreNotifications.web.d.ts +0 -2
  67. package/dist/store/cascadeScheduler.d.ts +0 -38
  68. package/dist/store/createStore.d.ts +0 -6
  69. package/dist/store/persist.d.ts +0 -14
  70. package/dist/store/stateUpdate.d.ts +0 -10
  71. package/dist/store/types.d.ts +0 -108
  72. package/dist/storesStorage.native.d.ts +0 -3
  73. package/dist/storesStorage.web.d.ts +0 -3
  74. package/dist/sync/types.d.ts +0 -115
  75. package/dist/types/functions.d.ts +0 -24
  76. package/dist/types/objects.d.ts +0 -11
  77. package/dist/types/setState.d.ts +0 -22
  78. package/dist/types/subscribe.d.ts +0 -27
  79. package/dist/types/useStoreCallSignatures.d.ts +0 -2
  80. package/dist/types/useStoreCallSignatures.react.d.ts +0 -6
  81. package/dist/types/useStoreCallSignatures.vanilla.d.ts +0 -2
  82. package/dist/types/utils.d.ts +0 -13
  83. package/dist/types.d.ts +0 -288
  84. package/dist/utils/core.d.ts +0 -26
  85. package/dist/utils/createAsyncMicrotaskScheduler.d.ts +0 -35
  86. package/dist/utils/createMicrotaskScheduler.d.ts +0 -29
  87. package/dist/utils/debounce.d.ts +0 -22
  88. package/dist/utils/equality.d.ts +0 -38
  89. package/dist/utils/hydrationCoordinator.d.ts +0 -13
  90. package/dist/utils/promiseUtils.d.ts +0 -2
  91. package/dist/utils/serialization.d.ts +0 -14
  92. package/dist/utils/stringUtils.d.ts +0 -7
  93. package/dist/utils/time.d.ts +0 -37
  94. package/dist/vanilla/createBaseStore.d.ts +0 -35
  95. package/dist/vanilla/createDerivedStore.d.ts +0 -62
  96. package/dist/vanilla/createQueryStore.d.ts +0 -110
  97. package/dist/vanilla/createVirtualStore.d.ts +0 -39
  98. package/dist/vanilla/env.web.d.ts +0 -6
  99. package/dist/vanilla/index.d.ts +0 -1
  100. package/dist/vanilla/index.shared.d.ts +0 -13
  101. package/dist/vanilla/internal/baseStore.d.ts +0 -1
  102. package/dist/vanilla/internal/config.d.ts +0 -63
  103. package/dist/vanilla/internal/createStoreActions.d.ts +0 -23
  104. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +0 -14
  105. package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +0 -25
  106. package/dist/vanilla/internal/derivedStore.d.ts +0 -1
  107. package/dist/vanilla/internal/errors.d.ts +0 -9
  108. package/dist/vanilla/internal/logger.d.ts +0 -9
  109. package/dist/vanilla/internal/middleware/createHydrationGate.d.ts +0 -19
  110. package/dist/vanilla/internal/queryStore/queryParams.d.ts +0 -17
  111. package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +0 -7
  112. package/dist/vanilla/internal/queryStore.d.ts +0 -1
  113. package/dist/vanilla/internal/runtime.d.ts +0 -11
  114. package/dist/vanilla/internal/storage/storageCreators.d.ts +0 -11
  115. package/dist/vanilla/internal/storeUtils.d.ts +0 -45
  116. package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +0 -2
  117. package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +0 -2
  118. package/dist/vanilla/internal/sync/syncEnhancer.d.ts +0 -25
  119. package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +0 -15
  120. package/dist/vanilla/internal/utils/persistUtils.d.ts +0 -8
  121. package/dist/vanilla/internal/virtualStore.d.ts +0 -1
  122. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +0 -38
  123. package/dist/vanilla/queryStore/queryKey.d.ts +0 -9
  124. package/dist/vanilla/queryStore/queryParam.d.ts +0 -36
  125. package/dist/vanilla/queryStore/types.d.ts +0 -360
  126. package/dist/vanilla/storage/storageTypes.d.ts +0 -12
  127. package/dist/vanilla/store/attachStoreHook.d.ts +0 -5
  128. package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +0 -5
  129. package/dist/vanilla/store/batchStoreNotifications.web.d.ts +0 -1
  130. package/dist/vanilla/store/cascadeScheduler.d.ts +0 -37
  131. package/dist/vanilla/store/createStore.d.ts +0 -5
  132. package/dist/vanilla/store/persist.d.ts +0 -13
  133. package/dist/vanilla/store/stateUpdate.d.ts +0 -9
  134. package/dist/vanilla/store/types.d.ts +0 -107
  135. package/dist/vanilla/storesStorage.web.d.ts +0 -2
  136. package/dist/vanilla/sync/types.d.ts +0 -114
  137. package/dist/vanilla/types/functions.d.ts +0 -23
  138. package/dist/vanilla/types/objects.d.ts +0 -10
  139. package/dist/vanilla/types/setState.d.ts +0 -21
  140. package/dist/vanilla/types/subscribe.d.ts +0 -26
  141. package/dist/vanilla/types/useStoreCallSignatures.d.ts +0 -1
  142. package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +0 -1
  143. package/dist/vanilla/types/utils.d.ts +0 -12
  144. package/dist/vanilla/types.d.ts +0 -287
  145. package/dist/vanilla/utils/core.d.ts +0 -25
  146. package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +0 -34
  147. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +0 -28
  148. package/dist/vanilla/utils/debounce.d.ts +0 -21
  149. package/dist/vanilla/utils/equality.d.ts +0 -37
  150. package/dist/vanilla/utils/hydrationCoordinator.d.ts +0 -12
  151. package/dist/vanilla/utils/promiseUtils.d.ts +0 -1
  152. package/dist/vanilla/utils/serialization.d.ts +0 -13
  153. package/dist/vanilla/utils/stringUtils.d.ts +0 -6
  154. package/dist/vanilla/utils/time.d.ts +0 -36
  155. package/dist/web/chunk-FENSEQ3V.mjs +0 -1
  156. package/dist/web/chunk-FPYZVFBM.mjs +0 -1
  157. package/dist/web/chunk-PLDNKWGX.mjs +0 -1
@@ -1,38 +0,0 @@
1
- /**
2
- * **Worklet compatible**
3
- *
4
- * Performs a deep equality check between two values.
5
- *
6
- * This function recursively compares two values, checking if they are equal. For objects,
7
- * it validates that both have the same keys and that each corresponding value is deeply equal.
8
- * For non-objects, it uses strict equality.
9
- *
10
- * @param obj1 - The first value to compare.
11
- * @param obj2 - The second value to compare.
12
- * @returns `true` if the values are deeply equal; otherwise, `false`.
13
- */
14
- export declare function deepEqual<U>(obj1: U, obj2: U): boolean;
15
- /**
16
- * **Worklet compatible**
17
- *
18
- * Performs a shallow equality check between two values.
19
- *
20
- * For non-objects, uses strict equality (===). For objects, checks that both have identical
21
- * keys and compares their values using `Object.is` without recursing into nested objects.
22
- *
23
- * Ideal for preventing re-renders due to top-level object recreation.
24
- *
25
- * @param obj1 - The first value to compare.
26
- * @param obj2 - The second value to compare.
27
- * @returns `true` if the values are shallowly equal; otherwise, `false`.
28
- */
29
- export declare function shallowEqual<U>(obj1: U, obj2: U): boolean;
30
- /**
31
- * Performs a deep equality check between two values, supporting objects, arrays, maps, sets, dates, regexps, array buffers, and more.
32
- * Copied from dequal@2.0.3 and fully typed for TypeScript.
33
- * @param foo - The first value to compare.
34
- * @param bar - The second value to compare.
35
- * @returns `true` if the values are deeply equal; otherwise, `false`.
36
- */
37
- export declare function dequal(foo: unknown, bar: unknown): boolean;
38
- //# sourceMappingURL=equality.d.ts.map
@@ -1,13 +0,0 @@
1
- export type HydrationCoordinator = {
2
- readonly complete: () => void;
3
- readonly fail: (error: Error) => void;
4
- readonly isHydrated: () => boolean;
5
- readonly promise: Promise<void>;
6
- };
7
- /**
8
- * Creates a coordinator for tracking async storage hydration lifecycle.
9
- * Provides a promise that resolves once hydration completes and methods
10
- * to signal completion or failure.
11
- */
12
- export declare function createHydrationCoordinator(): HydrationCoordinator;
13
- //# sourceMappingURL=hydrationCoordinator.d.ts.map
@@ -1,2 +0,0 @@
1
- export declare function isPromiseLike<T>(value: T | Promise<T> | void): value is Promise<T>;
2
- //# sourceMappingURL=promiseUtils.d.ts.map
@@ -1,14 +0,0 @@
1
- type SerializedMap = {
2
- __type: 'Map';
3
- entries: [unknown, unknown][];
4
- };
5
- export declare function isSerializedMap(value: unknown): value is SerializedMap;
6
- type SerializedSet = {
7
- __type: 'Set';
8
- values: unknown[];
9
- };
10
- export declare function isSerializedSet(value: unknown): value is SerializedSet;
11
- export declare function replacer(_: string, value: unknown): unknown;
12
- export declare function reviver(_: string, value: unknown): unknown;
13
- export {};
14
- //# sourceMappingURL=serialization.d.ts.map
@@ -1,7 +0,0 @@
1
- /**
2
- * Returns a pluralized (by default: `word` + `'s'`) string based on the count.
3
- *
4
- * `word` should be provided in singular form.
5
- */
6
- export declare function pluralize(word: string, count: number, pluralSuffix?: string): string;
7
- //# sourceMappingURL=stringUtils.d.ts.map
@@ -1,37 +0,0 @@
1
- type TimeInMs = number;
2
- type TimeUtils = {
3
- /** Returns the input value unchanged, in milliseconds */
4
- ms: (ms: number) => TimeInMs;
5
- /** Converts seconds to milliseconds */
6
- seconds: (seconds: number) => TimeInMs;
7
- /** Converts minutes to milliseconds */
8
- minutes: (minutes: number) => TimeInMs;
9
- /** Converts hours to milliseconds */
10
- hours: (hours: number) => TimeInMs;
11
- /** Converts days to milliseconds */
12
- days: (days: number) => TimeInMs;
13
- /** Converts weeks to milliseconds */
14
- weeks: (weeks: number) => TimeInMs;
15
- /** Represents infinite time */
16
- infinity: typeof Infinity;
17
- /** Represents zero time */
18
- zero: 0;
19
- };
20
- /**
21
- * Worklet-compatible utility object for defining time values.
22
- *
23
- * All methods convert the input unit to milliseconds.
24
- *
25
- * @example
26
- * time.seconds(5) // 5 seconds
27
- * time.minutes(2) // 2 minutes
28
- * time.hours(1) // 1 hour
29
- * time.days(5) // 5 days
30
- * time.weeks(2) // 2 weeks
31
- * ––
32
- * time.infinity // Infinity
33
- * time.zero // 0
34
- */
35
- export declare const time: TimeUtils;
36
- export {};
37
- //# sourceMappingURL=time.d.ts.map
@@ -1,35 +0,0 @@
1
- import type { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
2
- /**
3
- * Creates a base store without persistence.
4
- * @param createState - The state creator function for the base store.
5
- * @returns A store with the specified state.
6
- */
7
- export declare function createBaseStore<S>(createState: StateCreator<S>): Store<S>;
8
- /**
9
- * Creates a base store with persistence.
10
- * @param createState - The state creator function for the base store.
11
- * @param options - The configuration options for persistence and sync.
12
- * @returns A store with the specified state and persistence.
13
- */
14
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
15
- /**
16
- * Creates a base store with async persistence.
17
- * @param createState - The state creator function for the base store.
18
- * @param options - The configuration options for persistence and sync.
19
- * @returns A store with the specified state and persistence.
20
- */
21
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
22
- /**
23
- * Creates a base store with optional persistence.
24
- * @param createState - The state creator function for the base store.
25
- * @param options - The configuration options for persistence and sync.
26
- * @returns A store with the specified state and optional persistence.
27
- */
28
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
29
- /**
30
- * Creates a base store with optional async persistence.
31
- * @param createState - The state creator function for the base store.
32
- * @param options - The configuration options for persistence and sync.
33
- * @returns A store with the specified state and optional persistence.
34
- */
35
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
@@ -1,62 +0,0 @@
1
- import type { DeriveGetter, DeriveOptions, DerivedStore } from './types';
2
- /**
3
- * ### `createDerivedStore`
4
- *
5
- * Creates a **read-only** store derived from one or more source stores.
6
- *
7
- * ---
8
- * The `deriveFunction` is called whenever its dependencies change, producing a new derived state.
9
- * Dependencies are automatically tracked through a special `$` helper, which supports:
10
- *
11
- * 1) **Selector-based** usage:
12
- * ```ts
13
- * $ => {
14
- * const user = $(useUserStore, s => s.user, shallowEqual);
15
- * const theme = $(useSettingsStore, s => s.appearance.theme);
16
- * return { user, theme, isAdmin: user?.roles.includes('admin') };
17
- * }
18
- * ```
19
- *
20
- * 2) **Proxy-based** usage (auto-built selectors for nested properties):
21
- * ```ts
22
- * $ => {
23
- * const { user } = $(useUserStore); // Subscribe to `user`
24
- * const theme = $(useSettingsStore).appearance.theme; // Subscribe to `theme`
25
- * return { isAdmin: user?.roles.includes('admin'), theme, user };
26
- * }
27
- * ```
28
- *
29
- * ---
30
- * Derived stores automatically unsubscribe from all dependencies when no consumers remain, and
31
- * resubscribe when new consumers appear. The returned store exposes:
32
- *
33
- * - A **store object** with `getState()`, `subscribe()`, and `destroy()`
34
- * - In the React build, a **React hook** (`const state = derivedStore(selector, equalityFn?)`)
35
- *
36
- * ---
37
- * You can optionally pass a second parameter (either an equality function or a config object)
38
- * to enable debouncing, customize the equality function, or set `lockDependencies: true`.
39
- *
40
- * (When dependencies are locked, subscriptions created via `$` are established once and are
41
- * not rebuilt on subsequent re-derives, which can be a performance win for certain workloads.)
42
- *
43
- * ---
44
- * @example
45
- * ```ts
46
- * // Create a derived store
47
- * const searchResultsStore = createDerivedStore($ => {
48
- * const query = $(searchStore).query.trim().toLowerCase();
49
- * const items = $(itemsStore).items;
50
- * return findResults(query, items);
51
- * }, shallowEqual);
52
- *
53
- * const results = searchResultsStore.getState();
54
- * ```
55
- *
56
- * ---
57
- * @param deriveFunction - Function that reads from other stores via `$` to produce derived state.
58
- * @param optionsOrEqualityFn - Either an equality function or a config object (see `DeriveOptions`).
59
- *
60
- * @returns A read-only derived store. In the React build, it is also callable as a hook.
61
- */
62
- export declare function createDerivedStore<Derived>(deriveFunction: ($: DeriveGetter) => Derived, optionsOrEqualityFn?: DeriveOptions<Derived>): DerivedStore<Derived>;
@@ -1,110 +0,0 @@
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>;
@@ -1,39 +0,0 @@
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 {};
@@ -1,6 +0,0 @@
1
- export declare const IS_REACT_NATIVE = false;
2
- export declare const IS_BROWSER: boolean;
3
- export declare const IS_IOS = false;
4
- export declare const IS_ANDROID = false;
5
- export declare const IS_DEV: boolean;
6
- export declare const IS_TEST: boolean;
@@ -1 +0,0 @@
1
- export * from './index.shared';
@@ -1,13 +0,0 @@
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';
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
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 {};
@@ -1,23 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,25 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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,19 +0,0 @@
1
- import { StateCreator } from '../../types';
2
- import { SyncContext } from '../sync/syncEnhancer';
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
- /**
5
- * Creates hydration-gating middleware that queues state updates until rehydration completes.
6
- *
7
- * **Before hydration**: Queues all `set()` calls and flushes them sequentially after rehydration.
8
- *
9
- * **After hydration**: Passes `set()` calls through synchronously without batching.
10
- *
11
- * This ensures persistence sees a fully rehydrated base state before applying queued updates,
12
- * while keeping in-memory state changes synchronous post-hydration.
13
- */
14
- export declare function createHydrationGate<S>(stateCreator: StateCreator<S>): {
15
- hydrationPromise: () => Promise<void>;
16
- stateCreator: StateCreator<S>;
17
- wrapOnRehydrateStorage: WrappedOnRehydrateStorage<S>;
18
- };
19
- export {};
@@ -1,17 +0,0 @@
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,7 +0,0 @@
1
- import { Prettify } from '../../types/objects';
2
- import { QueryStoreDefaults } from '../config';
3
- export declare function getQueryStoreDefaults(): Prettify<Required<QueryStoreDefaults>>;
4
- /**
5
- * Exponential backoff: starts at `baseDelay` (5s), doubles each retry, capped at `maxDelay` (5m).
6
- */
7
- export declare function defaultRetryDelay(retryCount: number): number;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
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';
@@ -1,11 +0,0 @@
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>;