@storesjs/stores 0.8.7 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/README.md +55 -29
  2. package/dist/createBaseStore.d.ts +6 -6
  3. package/dist/createDerivedStore.d.ts +9 -17
  4. package/dist/createQueryStore.d.ts +6 -21
  5. package/dist/createVirtualStore.d.ts +5 -5
  6. package/dist/env.native.d.ts +0 -2
  7. package/dist/env.web.d.ts +0 -1
  8. package/dist/hooks/useListen.d.ts +2 -2
  9. package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +5 -0
  10. package/dist/index.d.ts +1 -14
  11. package/dist/index.shared.d.ts +14 -0
  12. package/dist/index.vanilla.d.ts +2 -0
  13. package/dist/internal/baseStore.d.ts +2 -0
  14. package/dist/internal/config.d.ts +64 -0
  15. package/dist/{utils → internal}/createStoreActions.d.ts +5 -6
  16. package/dist/internal/derivedStore/cascadeScheduler.d.ts +31 -0
  17. package/dist/internal/derivedStore/deriveProxy.d.ts +15 -0
  18. package/dist/internal/derivedStore/pathFinder.d.ts +26 -0
  19. package/dist/internal/derivedStore.d.ts +2 -0
  20. package/dist/internal/errors.d.ts +10 -0
  21. package/dist/{logger.d.ts → internal/logger.d.ts} +0 -7
  22. package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
  23. package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
  24. package/dist/internal/queryStore.d.ts +2 -0
  25. package/dist/internal/runtime.d.ts +13 -0
  26. package/dist/internal/signal.d.ts +12 -0
  27. package/dist/internal/storage/storageCreators.d.ts +12 -0
  28. package/dist/{utils → internal}/storeUtils.d.ts +4 -22
  29. package/dist/internal/sync/browserSyncEngine.d.ts +3 -0
  30. package/dist/internal/sync/noopSyncEngine.d.ts +3 -0
  31. package/dist/internal/sync/syncEnhancer.d.ts +26 -0
  32. package/dist/{sync → internal/sync}/syncUtils.d.ts +1 -1
  33. package/dist/internal/utils/persistUtils.d.ts +9 -0
  34. package/dist/internal/virtualStore.d.ts +2 -0
  35. package/dist/native/index.js +1 -1
  36. package/dist/native/index.mjs +1 -1
  37. package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +3 -1
  38. package/dist/queryStore/queryKey.d.ts +3 -0
  39. package/dist/queryStore/signalTypes.d.ts +14 -0
  40. package/dist/queryStore/types.d.ts +39 -33
  41. package/dist/store/attachStoreHook.react.d.ts +5 -0
  42. package/dist/store/attachStoreHook.vanilla.d.ts +6 -0
  43. package/dist/store/batchStoreNotifications.native.d.ts +3 -0
  44. package/dist/store/batchStoreNotifications.web.d.ts +2 -0
  45. package/dist/store/createStore.d.ts +6 -0
  46. package/dist/store/persist.d.ts +14 -0
  47. package/dist/store/stateUpdate.d.ts +10 -0
  48. package/dist/store/types.d.ts +108 -0
  49. package/dist/sync/types.d.ts +53 -128
  50. package/dist/types/functions.d.ts +19 -2
  51. package/dist/types/objects.d.ts +10 -3
  52. package/dist/types/setState.d.ts +22 -0
  53. package/dist/types/subscribe.d.ts +28 -0
  54. package/dist/types/useStoreCallSignatures.d.ts +2 -0
  55. package/dist/types/useStoreCallSignatures.react.d.ts +6 -0
  56. package/dist/types/useStoreCallSignatures.vanilla.d.ts +2 -0
  57. package/dist/types/utils.d.ts +4 -0
  58. package/dist/types.d.ts +59 -110
  59. package/dist/utils/core.d.ts +23 -4
  60. package/dist/utils/time.d.ts +0 -10
  61. package/dist/vanilla/createBaseStore.d.ts +35 -0
  62. package/dist/vanilla/createDerivedStore.d.ts +62 -0
  63. package/dist/vanilla/createQueryStore.d.ts +116 -0
  64. package/dist/vanilla/createVirtualStore.d.ts +39 -0
  65. package/dist/vanilla/env.web.d.ts +6 -0
  66. package/dist/vanilla/index.d.ts +1 -0
  67. package/dist/vanilla/index.js +1 -0
  68. package/dist/vanilla/index.mjs +1 -0
  69. package/dist/vanilla/index.shared.d.ts +13 -0
  70. package/dist/vanilla/index.vanilla.d.ts +1 -0
  71. package/dist/vanilla/internal/baseStore.d.ts +1 -0
  72. package/dist/vanilla/internal/config.d.ts +63 -0
  73. package/dist/vanilla/internal/createStoreActions.d.ts +23 -0
  74. package/dist/{derivedStore → vanilla/internal/derivedStore}/cascadeScheduler.d.ts +8 -1
  75. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +14 -0
  76. package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +25 -0
  77. package/dist/vanilla/internal/derivedStore.d.ts +1 -0
  78. package/dist/vanilla/internal/errors.d.ts +9 -0
  79. package/dist/vanilla/internal/logger.d.ts +9 -0
  80. package/dist/{middleware → vanilla/internal/middleware}/createHydrationGate.d.ts +1 -2
  81. package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +7 -0
  82. package/dist/vanilla/internal/queryStore.d.ts +1 -0
  83. package/dist/vanilla/internal/runtime.d.ts +12 -0
  84. package/dist/vanilla/internal/signal.d.ts +11 -0
  85. package/dist/vanilla/internal/storage/storageCreators.d.ts +11 -0
  86. package/dist/vanilla/internal/storeUtils.d.ts +45 -0
  87. package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +2 -0
  88. package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +2 -0
  89. package/dist/{sync → vanilla/internal/sync}/syncEnhancer.d.ts +6 -3
  90. package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +2 -3
  91. package/dist/vanilla/internal/virtualStore.d.ts +1 -0
  92. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +66 -0
  93. package/dist/vanilla/queryStore/queryKey.d.ts +2 -0
  94. package/dist/vanilla/queryStore/signalTypes.d.ts +13 -0
  95. package/dist/vanilla/queryStore/types.d.ts +402 -0
  96. package/dist/vanilla/storage/storageTypes.d.ts +12 -0
  97. package/dist/vanilla/store/attachStoreHook.d.ts +5 -0
  98. package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +5 -0
  99. package/dist/vanilla/store/batchStoreNotifications.web.d.ts +1 -0
  100. package/dist/vanilla/store/createStore.d.ts +5 -0
  101. package/dist/vanilla/store/persist.d.ts +13 -0
  102. package/dist/vanilla/store/stateUpdate.d.ts +9 -0
  103. package/dist/vanilla/store/types.d.ts +107 -0
  104. package/dist/vanilla/storesStorage.web.d.ts +2 -0
  105. package/dist/vanilla/sync/types.d.ts +114 -0
  106. package/dist/vanilla/types/functions.d.ts +23 -0
  107. package/dist/vanilla/types/objects.d.ts +10 -0
  108. package/dist/vanilla/types/setState.d.ts +21 -0
  109. package/dist/vanilla/types/subscribe.d.ts +27 -0
  110. package/dist/vanilla/types/useStoreCallSignatures.d.ts +1 -0
  111. package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +1 -0
  112. package/dist/vanilla/types/utils.d.ts +12 -0
  113. package/dist/vanilla/types.d.ts +285 -0
  114. package/dist/vanilla/utils/core.d.ts +25 -0
  115. package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +34 -0
  116. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +27 -0
  117. package/dist/vanilla/utils/debounce.d.ts +21 -0
  118. package/dist/vanilla/utils/equality.d.ts +37 -0
  119. package/dist/vanilla/utils/hydrationCoordinator.d.ts +12 -0
  120. package/dist/vanilla/utils/promiseUtils.d.ts +1 -0
  121. package/dist/vanilla/utils/serialization.d.ts +13 -0
  122. package/dist/vanilla/utils/stringUtils.d.ts +6 -0
  123. package/dist/vanilla/utils/time.d.ts +36 -0
  124. package/dist/web/chrome.js +1 -1
  125. package/dist/web/chrome.mjs +1 -1
  126. package/dist/web/chunk-QJLWBD7M.mjs +1 -0
  127. package/dist/web/chunk-V4LHP7LR.mjs +1 -0
  128. package/dist/web/index.js +1 -1
  129. package/dist/web/index.mjs +1 -1
  130. package/dist/web/internal/runtime.js +1 -0
  131. package/dist/web/internal/runtime.mjs +1 -0
  132. package/package.json +21 -15
  133. package/dist/config.d.ts +0 -40
  134. package/dist/derivedStore/deriveProxy.d.ts +0 -25
  135. package/dist/hooks/compareHooks.d.ts +0 -50
  136. package/dist/signal.d.ts +0 -20
  137. package/dist/storage/storageCreators.d.ts +0 -22
  138. package/dist/sync/browserSyncEngine.d.ts +0 -3
  139. package/dist/sync/noopSyncEngine.d.ts +0 -3
  140. package/dist/sync/transport.d.ts +0 -113
  141. package/dist/web/chunk-MMPMCVRC.mjs +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stores
2
2
 
3
- Stores provides a minimal, reactive state layer built on top of Zustand.
3
+ Stores provides a minimal, reactive state layer that runs with or without React.
4
4
 
5
5
  It defines three types of runtime-evaluated stores—**base**, **derived**, and **query**—each representing a distinct state type: local, computed, or asynchronously fetched. Stores track dependencies at runtime, evaluate lazily, and clean up automatically when unused.
6
6
 
@@ -10,10 +10,32 @@ All stores expose a consistent interface and can be used both inside and outside
10
10
  - **Derived stores** compute values from other stores and re-run only when inputs change.
11
11
  - **Query stores** fetch and cache async data, refetching when reactive parameters change.
12
12
 
13
- All store types share a common interface: a React-compatible hook, a
14
- stable store object with `.getState()` and `.subscribe()`, and optional
15
- support for persistence. They compose naturally, interoperate cleanly,
16
- and scale as application complexity grows.
13
+ All store types expose a stable store object with `.getState()` and
14
+ `.subscribe()`, plus optional support for persistence. In the React build,
15
+ stores are also callable hooks. In the vanilla build, stores remain plain store
16
+ objects. They compose naturally, interoperate cleanly, and scale as application
17
+ complexity grows.
18
+
19
+ ## Runtime Modes
20
+
21
+ The root import is mode-aware:
22
+
23
+ - React web apps use `@storesjs/stores` by default.
24
+ - React Native apps use `@storesjs/stores`; the `react-native` package condition selects the native build.
25
+ - Vanilla apps use `@storesjs/stores` with the `vanilla` package condition enabled.
26
+
27
+ For TypeScript vanilla projects, use a condition-aware resolver and add the
28
+ same condition to `tsconfig.json`:
29
+
30
+ ```json
31
+ {
32
+ "compilerOptions": {
33
+ "module": "ESNext",
34
+ "moduleResolution": "bundler",
35
+ "customConditions": ["vanilla"]
36
+ }
37
+ }
38
+ ```
17
39
 
18
40
  ## Base Store
19
41
 
@@ -21,7 +43,7 @@ A base store defines local state along with an interface for reading and
21
43
  updating that state.
22
44
 
23
45
  ```ts
24
- export const useSettingsStore = createBaseStore<Settings>(set => ({
46
+ export const settingsStore = createBaseStore<Settings>(set => ({
25
47
  currency: 'USD',
26
48
  setCurrency: currency => set({ currency }),
27
49
  }));
@@ -30,14 +52,14 @@ export const useSettingsStore = createBaseStore<Settings>(set => ({
30
52
  In React, subscribe to values with selectors:
31
53
 
32
54
  ```ts
33
- const currency = useSettingsStore(s => s.currency);
55
+ const currency = settingsStore(s => s.currency);
34
56
  ```
35
57
 
36
58
  Outside React:
37
59
 
38
60
  ```ts
39
- useSettingsStore.getState().currency;
40
- useSettingsStore.subscribe(selector, listener, options);
61
+ settingsStore.getState().currency;
62
+ settingsStore.subscribe(selector, listener, options);
41
63
  ```
42
64
 
43
65
  Enable persistence per store:
@@ -52,7 +74,7 @@ createBaseStore<Settings>(set => ({ ... }), {
52
74
  You can also export actions as a stable object:
53
75
 
54
76
  ```ts
55
- export const settingsActions = createStoreActions(useSettingsStore);
77
+ export const settingsActions = createStoreActions(settingsStore);
56
78
  ```
57
79
 
58
80
  ## Derived Store
@@ -61,9 +83,9 @@ Derived stores compute values from other stores. The `$` accessor tracks
61
83
  dependencies at runtime:
62
84
 
63
85
  ```ts
64
- export const useTotal = createDerivedStore($ => {
65
- const { currency } = $(useSettingsStore);
66
- const { subtotal, tax } = $(useCartStore);
86
+ export const totalStore = createDerivedStore($ => {
87
+ const { currency } = $(settingsStore);
88
+ const { subtotal, tax } = $(cartStore);
67
89
  return formatTotal(currency, subtotal, tax);
68
90
  });
69
91
  ```
@@ -78,10 +100,10 @@ Query stores manage remote data. They fetch, cache, and revalidate based
78
100
  on reactive parameters:
79
101
 
80
102
  ```ts
81
- export const useAccountStore = createQueryStore<Account, Params>({
103
+ export const accountStore = createQueryStore<Account, Params>({
82
104
  fetcher: fetchAccount,
83
105
  params: {
84
- userId: $ => $(useAuthStore).userId,
106
+ userId: $ => $(authStore).userId,
85
107
  },
86
108
  staleTime: time.minutes(10),
87
109
  });
@@ -93,13 +115,13 @@ idle.
93
115
  Use it in React:
94
116
 
95
117
  ```ts
96
- const account = useAccountStore(s => s.getData());
118
+ const account = accountStore(s => s.getData());
97
119
  ```
98
120
 
99
121
  Or imperatively:
100
122
 
101
123
  ```ts
102
- useAccountStore.getState().fetch();
124
+ accountStore.getState().fetch();
103
125
  ```
104
126
 
105
127
  Query stores support full customization: extended local state, manual cache control, configurable staleness and retry behavior, and optional persistence.
@@ -108,22 +130,26 @@ They deduplicate fetches across consumers and compute stable query keys automati
108
130
 
109
131
  ## Store Interface
110
132
 
111
- All stores implement the same API:
133
+ All stores implement the same store-object API:
112
134
 
113
135
  ```ts
114
- useStore()
115
- useStore(selector, equalityFn?)
136
+ store.getState()
137
+ store.setState() // Except for derived stores
138
+ store.subscribe(selector, listener, options?)
139
+ ```
116
140
 
117
- useStore.getState()
118
- useStore.setState() // Except for derived stores
119
- useStore.subscribe(selector, listener, options?)
141
+ In the React build, stores are also callable hooks:
142
+
143
+ ```ts
144
+ store()
145
+ store(selector, equalityFn?)
120
146
  ```
121
147
 
122
148
  ## Composed Example
123
149
 
124
150
  ```ts
125
- export const useCurrencyFormatter = createDerivedStore($ => {
126
- const { currency, locale } = $(useSettingsStore);
151
+ export const currencyFormatterStore = createDerivedStore($ => {
152
+ const { currency, locale } = $(settingsStore);
127
153
  return new Intl.NumberFormat(locale, {
128
154
  currency,
129
155
  style: 'currency',
@@ -132,16 +158,16 @@ export const useCurrencyFormatter = createDerivedStore($ => {
132
158
  ```
133
159
 
134
160
  ```ts
135
- export const useAccountBalance = createDerivedStore($ => {
136
- const balance = $(useAccountStore).getData()?.balance ?? 0;
137
- const formatter = $(useCurrencyFormatter);
161
+ export const accountBalanceStore = createDerivedStore($ => {
162
+ const balance = $(accountStore).getData()?.balance ?? 0;
163
+ const formatter = $(currencyFormatterStore);
138
164
  return formatter.format(balance);
139
165
  });
140
166
  ```
141
167
 
142
168
  ```ts
143
169
  function AccountSummary() {
144
- const balance = useAccountBalance();
170
+ const balance = accountBalanceStore();
145
171
  return <Text>Balance: {balance}</Text>;
146
172
  }
147
173
  ```
@@ -1,36 +1,36 @@
1
- import { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
1
+ import type { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
2
2
  /**
3
3
  * Creates a base store without persistence.
4
4
  * @param createState - The state creator function for the base store.
5
- * @returns A Zustand store with the specified state.
5
+ * @returns A store with the specified state.
6
6
  */
7
7
  export declare function createBaseStore<S>(createState: StateCreator<S>): Store<S>;
8
8
  /**
9
9
  * Creates a base store with persistence.
10
10
  * @param createState - The state creator function for the base store.
11
11
  * @param options - The configuration options for persistence and sync.
12
- * @returns A Zustand store with the specified state and persistence.
12
+ * @returns A store with the specified state and persistence.
13
13
  */
14
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, false>;
15
15
  /**
16
16
  * Creates a base store with async persistence.
17
17
  * @param createState - The state creator function for the base store.
18
18
  * @param options - The configuration options for persistence and sync.
19
- * @returns A Zustand store with the specified state and persistence.
19
+ * @returns A store with the specified state and persistence.
20
20
  */
21
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, false>;
22
22
  /**
23
23
  * Creates a base store with optional persistence.
24
24
  * @param createState - The state creator function for the base store.
25
25
  * @param options - The configuration options for persistence and sync.
26
- * @returns A Zustand store with the specified state and optional persistence.
26
+ * @returns A store with the specified state and optional persistence.
27
27
  */
28
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
29
  /**
30
30
  * Creates a base store with optional async persistence.
31
31
  * @param createState - The state creator function for the base store.
32
32
  * @param options - The configuration options for persistence and sync.
33
- * @returns A Zustand store with the specified state and optional persistence.
33
+ * @returns A store with the specified state and optional persistence.
34
34
  */
35
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>;
36
36
  //# sourceMappingURL=createBaseStore.d.ts.map
@@ -1,8 +1,8 @@
1
- import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreState } from './types';
1
+ import type { DeriveGetter, DeriveOptions, DerivedStore } from './types';
2
2
  /**
3
3
  * ### `createDerivedStore`
4
4
  *
5
- * Creates a **read-only** store derived from one or more underlying Zustand stores.
5
+ * Creates a **read-only** store derived from one or more source stores.
6
6
  *
7
7
  * ---
8
8
  * The `deriveFunction` is called whenever its dependencies change, producing a new derived state.
@@ -28,10 +28,10 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
28
28
  *
29
29
  * ---
30
30
  * Derived stores automatically unsubscribe from all dependencies when no consumers remain, and
31
- * resubscribe when new consumers appear. The returned function doubles as:
31
+ * resubscribe when new consumers appear. The returned store exposes:
32
32
  *
33
- * - A **React hook** (`const state = useDerivedStore(selector, equalityFn?)`)
34
33
  * - A **store object** with `getState()`, `subscribe()`, and `destroy()`
34
+ * - In the React build, a **React hook** (`const state = derivedStore(selector, equalityFn?)`)
35
35
  *
36
36
  * ---
37
37
  * You can optionally pass a second parameter (either an equality function or a config object)
@@ -44,28 +44,20 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
44
44
  * @example
45
45
  * ```ts
46
46
  * // Create a derived store
47
- * const useSearchResults = createDerivedStore($ => {
48
- * const query = $(useSearchStore).query.trim().toLowerCase();
49
- * const items = $(useItemsStore).items;
47
+ * const searchResultsStore = createDerivedStore($ => {
48
+ * const query = $(searchStore).query.trim().toLowerCase();
49
+ * const items = $(itemsStore).items;
50
50
  * return findResults(query, items);
51
51
  * }, shallowEqual);
52
52
  *
53
- * function SearchResults() {
54
- * // Consume the derived state
55
- * const results = useSearchResults(); // Or (selector, equalityFn?)
56
- * return <ResultsList items={results} />;
57
- * }
53
+ * const results = searchResultsStore.getState();
58
54
  * ```
59
55
  *
60
56
  * ---
61
57
  * @param deriveFunction - Function that reads from other stores via `$` to produce derived state.
62
58
  * @param optionsOrEqualityFn - Either an equality function or a config object (see `DeriveOptions`).
63
59
  *
64
- * @returns A read-only derived store (usable as a hook or standard store object).
60
+ * @returns A read-only derived store. In the React build, it is also callable as a hook.
65
61
  */
66
62
  export declare function createDerivedStore<Derived>(deriveFunction: ($: DeriveGetter) => Derived, optionsOrEqualityFn?: DeriveOptions<Derived>): DerivedStore<Derived>;
67
- export type DeriveGetter = {
68
- <S extends Store<unknown>>(store: S): InferStoreState<S>;
69
- <S extends Store<unknown>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
70
- };
71
63
  //# sourceMappingURL=createDerivedStore.d.ts.map
@@ -1,5 +1,7 @@
1
- import { QueryStoreConfig, QueryStoreState } from './queryStore/types';
2
- import { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
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 };
3
5
  /**
4
6
  * Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
5
7
  *
@@ -91,7 +93,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
91
93
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
92
94
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
93
95
  */
94
- 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, QueryStoreState<TData, TParams>>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
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>;
95
97
  /**
96
98
  * Creates a conditionally persisted, query-enabled store with data fetching capabilities (async storage).
97
99
  *
@@ -102,24 +104,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
102
104
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
103
105
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
104
106
  */
105
- 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, QueryStoreState<TData, TParams>>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
106
- /**
107
- * The default query store `retryDelay` function.
108
- *
109
- * Exponential backoff starting at `baseDelay` (5s default), doubling each retry, capped at `maxDelay` (5m default).
110
- *
111
- * ```ts
112
- * retryCount => Math.min(baseDelay * Math.pow(2, retryCount), maxDelay)
113
- * ```
114
- */
115
- export declare function defaultRetryDelay(retryCount: number, options?: {
116
- baseDelay?: number;
117
- maxDelay?: number;
118
- }): number;
119
- /**
120
- * @deprecated Use `getQueryKey` instead, unless using for non-parsable query keys.
121
- */
122
- export declare function getLegacyQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
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>;
123
108
  /**
124
109
  * Generates a deterministic query store `queryKey` from the given parameters,
125
110
  * consistent with internally generated keys.
@@ -1,6 +1,6 @@
1
- import { DeriveGetter } from './createDerivedStore';
2
- import { BaseStore, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
3
- type MethodOverrides<Store extends BaseStore<State>, State = InferStoreState<Store>> = Partial<Pick<Store, 'getState' | 'setState'>>;
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
4
  type VirtualStoreOptions = {
5
5
  debugMode?: boolean;
6
6
  /**
@@ -34,7 +34,7 @@ type VirtualStoreOptions = {
34
34
  * });
35
35
  * ```
36
36
  */
37
- export declare function createVirtualStore<Store extends BaseStore<InferStoreState<Store>>>(createStore: ($: DeriveGetter) => Store, options?: VirtualStoreOptions): OptionallyPersistedStore<InferStoreState<Store>, InferPersistedState<Store, InferStoreState<Store>>, InferSetStateReturn<Store>>;
38
- export declare function createVirtualStore<Store extends BaseStore<InferStoreState<Store>>, Overrides extends MethodOverrides<Store>>(createStore: ($: DeriveGetter) => Store, overrides: (getStore: () => Store) => Overrides, options?: VirtualStoreOptions): OptionallyPersistedStore<InferStoreState<Store>, InferPersistedState<Store, InferStoreState<Store>>, InferSetStateReturn<Store>> & Overrides;
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
39
  export {};
40
40
  //# sourceMappingURL=createVirtualStore.d.ts.map
@@ -1,9 +1,7 @@
1
- import { unstable_batchedUpdates } from 'react-native';
2
1
  export declare const IS_REACT_NATIVE = true;
3
2
  export declare const IS_BROWSER = false;
4
3
  export declare const IS_IOS: boolean;
5
4
  export declare const IS_ANDROID: boolean;
6
5
  export declare const IS_DEV: boolean;
7
6
  export declare const IS_TEST: boolean;
8
- export { unstable_batchedUpdates };
9
7
  //# sourceMappingURL=env.native.d.ts.map
package/dist/env.web.d.ts CHANGED
@@ -4,5 +4,4 @@ export declare const IS_IOS = false;
4
4
  export declare const IS_ANDROID = false;
5
5
  export declare const IS_DEV: boolean;
6
6
  export declare const IS_TEST: boolean;
7
- export declare const unstable_batchedUpdates: <T>(callback: () => T) => T;
8
7
  //# sourceMappingURL=env.web.d.ts.map
@@ -61,7 +61,7 @@ export type UseListenOptions<Selected> = {
61
61
  /**
62
62
  * ### `useListen`
63
63
  *
64
- * Subscribes to a slice of a Zustand store and runs a callback whenever that slice changes,
64
+ * Subscribes to a slice of a store and runs a callback whenever that slice changes,
65
65
  * **without triggering re-renders**.
66
66
  *
67
67
  * Useful for forwarding updates to non-React state (e.g. Reanimated shared values), scoped side
@@ -75,7 +75,7 @@ export type UseListenOptions<Selected> = {
75
75
  * They take effect only if a resubscription occurs.
76
76
  *
77
77
  * ---
78
- * @param store - Zustand store to listen to. Should be a stable reference.
78
+ * @param store - Store to listen to. Should be a stable reference.
79
79
  * @param selector - Selects the slice of the store state to listen to.
80
80
  * @param react - Triggered when the selected slice changes. Receives `(current, previous, unsubscribe)`.
81
81
  * @param optionsOrEqualityFn - Optional `equalityFn`, `fireImmediately` settings, forwarded to `store.subscribe`.
@@ -0,0 +1,5 @@
1
+ import type { EqualityFn, Selector, SubscribeOverloads } from '../types';
2
+ export declare function useSyncExternalStoreWithSelector<State>(subscribe: SubscribeOverloads<State>, getSnapshot: () => State, getServerSnapshot?: (() => State) | undefined, selector?: undefined, equalityFn?: undefined): State;
3
+ export declare function useSyncExternalStoreWithSelector<State, Selected>(subscribe: SubscribeOverloads<State>, getSnapshot: () => State, getServerSnapshot: (() => State) | undefined, selector: Selector<State, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
4
+ export declare function useSyncExternalStoreWithSelector<State, Selected>(subscribe: SubscribeOverloads<State>, getSnapshot: () => State, getServerSnapshot: (() => State) | undefined, selector: Selector<State, Selected> | undefined, equalityFn?: EqualityFn<Selected>): State | Selected;
5
+ //# sourceMappingURL=useSyncExternalStoreWithSelector.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,17 +1,4 @@
1
- export { configureStores } from './config';
2
- export { createBaseStore } from './createBaseStore';
3
- export * from './createDerivedStore';
4
- export * from './createQueryStore';
5
- export * from './createVirtualStore';
6
- export { replacer, reviver } from './utils/serialization';
7
- export { applyStateUpdate, destroyStore, destroyStores, getStoreName, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './utils/storeUtils';
1
+ export * from './index.shared';
8
2
  export * from './hooks/useListen';
9
3
  export * from './hooks/useStableValue';
10
- export * from './sync/types';
11
- export * from './queryStore/types';
12
- export * from './storage/storageTypes';
13
- export * from './types';
14
- export * from './utils/createStoreActions';
15
- export { deepEqual, shallowEqual } from './utils/equality';
16
- export { time } from './utils/time';
17
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,14 @@
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';
14
+ //# sourceMappingURL=index.shared.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './index.shared';
2
+ //# sourceMappingURL=index.vanilla.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=baseStore.d.ts.map
@@ -0,0 +1,64 @@
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 {};
64
+ //# sourceMappingURL=config.d.ts.map
@@ -1,8 +1,7 @@
1
- import { StoreApi } from 'zustand';
2
- import { InferStoreState } from '../types';
3
- import { NoOverlap, ObjectMethods } from '../types/objects';
4
- import { FunctionKeys } from '../types/functions';
5
- export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState<Store>, FunctionKeys<InferStoreState<Store>>>;
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';
6
5
  /**
7
6
  * Given a store instance, produces a new object containing only its actions.
8
7
  *
@@ -21,5 +20,5 @@ export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState
21
20
  * exampleActions.increment();
22
21
  */
23
22
  export declare function createStoreActions<Store extends StoreApi<unknown>>(store: Store): StoreActions<Store>;
24
- export declare function createStoreActions<Store extends StoreApi<unknown>, Bundled extends ObjectMethods>(store: Store, bundledMethods: NoOverlap<InferStoreState<Store>, Bundled>): StoreActions<Store> & Bundled;
23
+ export declare function createStoreActions<Store extends StoreApi<unknown>, Bundled extends FunctionRecord>(store: Store, bundledMethods: NoOverlap<InferStoreState<Store>, Bundled>): StoreActions<Store> & Bundled;
25
24
  //# sourceMappingURL=createStoreActions.d.ts.map
@@ -0,0 +1,31 @@
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 {};
31
+ //# sourceMappingURL=cascadeScheduler.d.ts.map
@@ -0,0 +1,15 @@
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;
15
+ //# sourceMappingURL=deriveProxy.d.ts.map
@@ -0,0 +1,26 @@
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 {};
26
+ //# sourceMappingURL=pathFinder.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=derivedStore.d.ts.map
@@ -0,0 +1,10 @@
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
+ }
10
+ //# sourceMappingURL=errors.d.ts.map
@@ -1,7 +1,3 @@
1
- export declare class StoresError extends Error {
2
- cause: Error;
3
- constructor(message: string, error?: unknown);
4
- }
5
1
  export interface Logger {
6
2
  debug: (message: string, context?: Record<string, unknown>) => void;
7
3
  error: {
@@ -11,7 +7,4 @@ export interface Logger {
11
7
  info: (message: string, context?: Record<string, unknown>) => void;
12
8
  warn: (message: string, context?: Record<string, unknown>) => void;
13
9
  }
14
- export declare let logger: Logger;
15
- export declare function ensureError(error: unknown): Error;
16
- export declare function setLogger(customLogger: Logger): void;
17
10
  //# sourceMappingURL=logger.d.ts.map