@wordpress/data 10.41.0 → 10.41.1-next.v.202603102151.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 (213) hide show
  1. package/README.md +20 -28
  2. package/build/components/async-mode-provider/context.cjs +1 -1
  3. package/build/components/async-mode-provider/context.cjs.map +3 -3
  4. package/build/components/async-mode-provider/index.cjs +1 -1
  5. package/build/components/async-mode-provider/index.cjs.map +1 -1
  6. package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
  7. package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
  8. package/build/components/registry-provider/context.cjs +1 -1
  9. package/build/components/registry-provider/context.cjs.map +1 -1
  10. package/build/components/registry-provider/index.cjs +1 -1
  11. package/build/components/registry-provider/index.cjs.map +1 -1
  12. package/build/components/registry-provider/use-registry.cjs +1 -1
  13. package/build/components/registry-provider/use-registry.cjs.map +3 -3
  14. package/build/components/use-dispatch/index.cjs +1 -1
  15. package/build/components/use-dispatch/index.cjs.map +1 -1
  16. package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
  17. package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
  18. package/build/components/use-dispatch/use-dispatch.cjs +1 -1
  19. package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
  20. package/build/components/use-select/index.cjs +2 -2
  21. package/build/components/use-select/index.cjs.map +3 -3
  22. package/build/components/with-dispatch/index.cjs +1 -1
  23. package/build/components/with-dispatch/index.cjs.map +3 -3
  24. package/build/components/with-registry/index.cjs +1 -1
  25. package/build/components/with-registry/index.cjs.map +3 -3
  26. package/build/components/with-select/index.cjs +1 -1
  27. package/build/components/with-select/index.cjs.map +3 -3
  28. package/build/controls.cjs +7 -6
  29. package/build/controls.cjs.map +3 -3
  30. package/build/default-registry.cjs +3 -2
  31. package/build/default-registry.cjs.map +3 -3
  32. package/build/dispatch.cjs +3 -1
  33. package/build/dispatch.cjs.map +2 -2
  34. package/build/factory.cjs.map +2 -2
  35. package/build/index.cjs +9 -8
  36. package/build/index.cjs.map +3 -3
  37. package/build/plugins/index.cjs +1 -1
  38. package/build/plugins/index.cjs.map +1 -1
  39. package/build/plugins/persistence/index.cjs +13 -8
  40. package/build/plugins/persistence/index.cjs.map +3 -3
  41. package/build/plugins/persistence/storage/default.cjs +1 -1
  42. package/build/plugins/persistence/storage/default.cjs.map +3 -3
  43. package/build/plugins/persistence/storage/object.cjs +1 -1
  44. package/build/plugins/persistence/storage/object.cjs.map +3 -3
  45. package/build/promise-middleware.cjs +2 -1
  46. package/build/promise-middleware.cjs.map +3 -3
  47. package/build/redux-store/index.cjs +32 -16
  48. package/build/redux-store/index.cjs.map +3 -3
  49. package/build/redux-store/metadata/selectors.cjs +1 -1
  50. package/build/redux-store/metadata/selectors.cjs.map +3 -3
  51. package/build/redux-store/metadata/types.cjs +19 -0
  52. package/build/redux-store/metadata/types.cjs.map +7 -0
  53. package/build/registry.cjs +11 -7
  54. package/build/registry.cjs.map +3 -3
  55. package/build/resolvers-cache-middleware.cjs +6 -3
  56. package/build/resolvers-cache-middleware.cjs.map +3 -3
  57. package/build/select.cjs +3 -1
  58. package/build/select.cjs.map +2 -2
  59. package/build/store/index.cjs +1 -1
  60. package/build/store/index.cjs.map +3 -3
  61. package/build/types.cjs.map +1 -1
  62. package/build-module/components/async-mode-provider/context.mjs +1 -1
  63. package/build-module/components/async-mode-provider/context.mjs.map +3 -3
  64. package/build-module/components/async-mode-provider/index.mjs +1 -1
  65. package/build-module/components/async-mode-provider/index.mjs.map +1 -1
  66. package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
  67. package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
  68. package/build-module/components/registry-provider/context.mjs +1 -1
  69. package/build-module/components/registry-provider/context.mjs.map +1 -1
  70. package/build-module/components/registry-provider/index.mjs +1 -1
  71. package/build-module/components/registry-provider/index.mjs.map +1 -1
  72. package/build-module/components/registry-provider/use-registry.mjs +1 -1
  73. package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
  74. package/build-module/components/use-dispatch/index.mjs +1 -1
  75. package/build-module/components/use-dispatch/index.mjs.map +1 -1
  76. package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
  77. package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
  78. package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
  79. package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
  80. package/build-module/components/use-select/index.mjs +2 -2
  81. package/build-module/components/use-select/index.mjs.map +3 -3
  82. package/build-module/components/with-dispatch/index.mjs +1 -1
  83. package/build-module/components/with-dispatch/index.mjs.map +3 -3
  84. package/build-module/components/with-registry/index.mjs +1 -1
  85. package/build-module/components/with-registry/index.mjs.map +3 -3
  86. package/build-module/components/with-select/index.mjs +1 -1
  87. package/build-module/components/with-select/index.mjs.map +3 -3
  88. package/build-module/controls.mjs +7 -6
  89. package/build-module/controls.mjs.map +3 -3
  90. package/build-module/default-registry.mjs +3 -2
  91. package/build-module/default-registry.mjs.map +3 -3
  92. package/build-module/dispatch.mjs +3 -1
  93. package/build-module/dispatch.mjs.map +2 -2
  94. package/build-module/factory.mjs.map +2 -2
  95. package/build-module/index.mjs +4 -3
  96. package/build-module/index.mjs.map +2 -2
  97. package/build-module/plugins/index.mjs +1 -1
  98. package/build-module/plugins/index.mjs.map +1 -1
  99. package/build-module/plugins/persistence/index.mjs +13 -8
  100. package/build-module/plugins/persistence/index.mjs.map +3 -3
  101. package/build-module/plugins/persistence/storage/default.mjs +1 -1
  102. package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
  103. package/build-module/plugins/persistence/storage/object.mjs +1 -1
  104. package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
  105. package/build-module/promise-middleware.mjs +2 -1
  106. package/build-module/promise-middleware.mjs.map +3 -3
  107. package/build-module/redux-store/index.mjs +32 -16
  108. package/build-module/redux-store/index.mjs.map +3 -3
  109. package/build-module/redux-store/metadata/selectors.mjs +1 -1
  110. package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
  111. package/build-module/redux-store/metadata/types.mjs +1 -0
  112. package/build-module/redux-store/metadata/types.mjs.map +7 -0
  113. package/build-module/registry.mjs +11 -7
  114. package/build-module/registry.mjs.map +3 -3
  115. package/build-module/resolvers-cache-middleware.mjs +6 -3
  116. package/build-module/resolvers-cache-middleware.mjs.map +3 -3
  117. package/build-module/select.mjs +3 -1
  118. package/build-module/select.mjs.map +2 -2
  119. package/build-module/store/index.mjs +1 -1
  120. package/build-module/store/index.mjs.map +3 -3
  121. package/build-types/components/async-mode-provider/context.d.ts +37 -3
  122. package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
  123. package/build-types/components/async-mode-provider/index.d.ts +2 -2
  124. package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
  125. package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
  126. package/build-types/components/registry-provider/context.d.ts +10 -3
  127. package/build-types/components/registry-provider/context.d.ts.map +1 -1
  128. package/build-types/components/registry-provider/index.d.ts +2 -2
  129. package/build-types/components/registry-provider/index.d.ts.map +1 -1
  130. package/build-types/components/registry-provider/use-registry.d.ts +3 -2
  131. package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
  132. package/build-types/components/use-dispatch/index.d.ts +2 -2
  133. package/build-types/components/use-dispatch/index.d.ts.map +1 -1
  134. package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
  135. package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
  136. package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
  137. package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
  138. package/build-types/components/use-select/index.d.ts +24 -28
  139. package/build-types/components/use-select/index.d.ts.map +1 -1
  140. package/build-types/components/with-dispatch/index.d.ts +10 -11
  141. package/build-types/components/with-dispatch/index.d.ts.map +1 -1
  142. package/build-types/components/with-registry/index.d.ts +2 -6
  143. package/build-types/components/with-registry/index.d.ts.map +1 -1
  144. package/build-types/components/with-select/index.d.ts +7 -8
  145. package/build-types/components/with-select/index.d.ts.map +1 -1
  146. package/build-types/controls.d.ts +57 -44
  147. package/build-types/controls.d.ts.map +1 -1
  148. package/build-types/default-registry.d.ts +2 -2
  149. package/build-types/default-registry.d.ts.map +1 -1
  150. package/build-types/dispatch.d.ts +4 -0
  151. package/build-types/dispatch.d.ts.map +1 -1
  152. package/build-types/factory.d.ts +2 -1
  153. package/build-types/factory.d.ts.map +1 -1
  154. package/build-types/index.d.ts.map +1 -1
  155. package/build-types/plugins/index.d.ts +1 -1
  156. package/build-types/plugins/index.d.ts.map +1 -1
  157. package/build-types/plugins/persistence/index.d.ts +38 -27
  158. package/build-types/plugins/persistence/index.d.ts.map +1 -1
  159. package/build-types/plugins/persistence/storage/default.d.ts +7 -1
  160. package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
  161. package/build-types/plugins/persistence/storage/object.d.ts +4 -5
  162. package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
  163. package/build-types/promise-middleware.d.ts +6 -4
  164. package/build-types/promise-middleware.d.ts.map +1 -1
  165. package/build-types/redux-store/index.d.ts +12 -15
  166. package/build-types/redux-store/index.d.ts.map +1 -1
  167. package/build-types/redux-store/metadata/selectors.d.ts +45 -50
  168. package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
  169. package/build-types/redux-store/metadata/types.d.ts +48 -0
  170. package/build-types/redux-store/metadata/types.d.ts.map +1 -0
  171. package/build-types/registry.d.ts +5 -49
  172. package/build-types/registry.d.ts.map +1 -1
  173. package/build-types/resolvers-cache-middleware.d.ts +13 -7
  174. package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
  175. package/build-types/select.d.ts +3 -0
  176. package/build-types/select.d.ts.map +1 -1
  177. package/build-types/store/index.d.ts +5 -12
  178. package/build-types/store/index.d.ts.map +1 -1
  179. package/build-types/types.d.ts +201 -10
  180. package/build-types/types.d.ts.map +1 -1
  181. package/package.json +9 -9
  182. package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
  183. package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
  184. package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
  185. package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
  186. package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
  187. package/src/components/use-select/{index.js → index.ts} +84 -70
  188. package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
  189. package/src/components/with-registry/{index.js → index.tsx} +1 -5
  190. package/src/components/with-select/{index.js → index.tsx} +17 -10
  191. package/src/{controls.js → controls.ts} +53 -26
  192. package/src/{default-registry.js → default-registry.ts} +3 -1
  193. package/src/dispatch.ts +7 -1
  194. package/src/factory.ts +4 -3
  195. package/src/index.ts +4 -8
  196. package/src/plugins/persistence/{index.js → index.ts} +93 -54
  197. package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
  198. package/src/plugins/persistence/storage/object.ts +25 -0
  199. package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
  200. package/src/redux-store/{index.js → index.ts} +218 -131
  201. package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
  202. package/src/redux-store/metadata/types.ts +100 -0
  203. package/src/{registry.js → registry.ts} +98 -88
  204. package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
  205. package/src/select.ts +6 -1
  206. package/src/store/{index.js → index.ts} +13 -8
  207. package/src/types.ts +263 -24
  208. package/src/plugins/persistence/storage/object.js +0 -23
  209. /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
  210. /package/src/components/registry-provider/{context.js → context.ts} +0 -0
  211. /package/src/components/registry-provider/{index.js → index.ts} +0 -0
  212. /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
  213. /package/src/plugins/{index.js → index.ts} +0 -0
package/src/types.ts CHANGED
@@ -1,8 +1,21 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- // eslint-disable-next-line no-restricted-imports
5
- import type { combineReducers as reduxCombineReducers } from 'redux';
4
+
5
+ import type {
6
+ // eslint-disable-next-line no-restricted-imports
7
+ combineReducers as reduxCombineReducers,
8
+ Store as ReduxStore,
9
+ } from 'redux';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import type { DataEmitter } from './utils/emitter';
15
+ import type {
16
+ MetadataSelectors,
17
+ MetadataActions,
18
+ } from './redux-store/metadata/types';
6
19
 
7
20
  type MapOf< T > = { [ name: string ]: T };
8
21
 
@@ -30,11 +43,7 @@ export interface StoreDescriptor< Config extends AnyConfig = AnyConfig > {
30
43
  instantiate: ( registry: DataRegistry ) => StoreInstance< Config >;
31
44
  }
32
45
 
33
- export interface ReduxStoreConfig<
34
- State,
35
- ActionCreators extends MapOf< ActionCreator >,
36
- Selectors,
37
- > {
46
+ export interface ReduxStoreConfig< State, ActionCreators, Selectors > {
38
47
  initialState?: State;
39
48
  reducer: ( state: any, action: any ) => any;
40
49
  actions?: ActionCreators;
@@ -54,7 +63,7 @@ export type UseSelectReturn< F extends MapSelect | StoreDescriptor< any > > =
54
63
  // Return type for the useDispatch() hook.
55
64
  export type UseDispatchReturn< StoreNameOrDescriptor > =
56
65
  StoreNameOrDescriptor extends StoreDescriptor< any >
57
- ? ActionCreatorsOf< ConfigOf< StoreNameOrDescriptor > >
66
+ ? ActionCreatorsOf< StoreNameOrDescriptor >
58
67
  : StoreNameOrDescriptor extends undefined
59
68
  ? DispatchFunction
60
69
  : any;
@@ -65,7 +74,7 @@ export type DispatchFunction = < StoreNameOrDescriptor >(
65
74
 
66
75
  export type DispatchReturn< StoreNameOrDescriptor > =
67
76
  StoreNameOrDescriptor extends StoreDescriptor< any >
68
- ? ActionCreatorsOf< ConfigOf< StoreNameOrDescriptor > >
77
+ ? ActionCreatorsOf< StoreNameOrDescriptor >
69
78
  : unknown;
70
79
 
71
80
  export type MapSelect = (
@@ -84,7 +93,9 @@ export type ListenerFunction = () => void;
84
93
  export type CurriedSelectorsOf< S > = S extends StoreDescriptor<
85
94
  ReduxStoreConfig< any, any, infer Selectors >
86
95
  >
87
- ? { [ key in keyof Selectors ]: CurriedState< Selectors[ key ] > }
96
+ ? {
97
+ [ key in keyof Selectors ]: CurriedState< Selectors[ key ] >;
98
+ } & MetadataSelectors< S >
88
99
  : never;
89
100
 
90
101
  /**
@@ -193,39 +204,244 @@ export interface SelectorWithCustomCurrySignature {
193
204
  PromiseCurriedSignature?: Function;
194
205
  }
195
206
 
207
+ /**
208
+ * A store name or store descriptor, used throughout the API.
209
+ */
210
+ export type StoreNameOrDescriptor = string | StoreDescriptor;
211
+
212
+ /**
213
+ * An isolated orchestrator of store registrations.
214
+ *
215
+ * Returned by `createRegistry`. Provides methods to register stores,
216
+ * select data, dispatch actions, and subscribe to changes.
217
+ */
196
218
  export interface DataRegistry {
219
+ batch: ( callback: () => void ) => void;
220
+ stores: Record< string, InternalStoreInstance >;
221
+ namespaces: Record< string, InternalStoreInstance >;
222
+ subscribe: (
223
+ listener: ListenerFunction,
224
+ storeNameOrDescriptor?: StoreNameOrDescriptor
225
+ ) => () => void;
226
+ select: {
227
+ < S extends StoreDescriptor< any > >(
228
+ store: S
229
+ ): CurriedSelectorsOf< S >;
230
+ (
231
+ store: StoreNameOrDescriptor
232
+ ): Record< string, ( ...args: any[] ) => any >;
233
+ };
234
+ resolveSelect: {
235
+ < S extends StoreDescriptor< any > >(
236
+ store: S
237
+ ): CurriedSelectorsResolveOf< S >;
238
+ (
239
+ store: StoreNameOrDescriptor
240
+ ): Record< string, ( ...args: any[] ) => Promise< any > >;
241
+ };
242
+ suspendSelect: {
243
+ < S extends StoreDescriptor< any > >(
244
+ store: S
245
+ ): CurriedSelectorsOf< S >;
246
+ (
247
+ store: StoreNameOrDescriptor
248
+ ): Record< string, ( ...args: any[] ) => any >;
249
+ };
250
+ dispatch: {
251
+ < S extends StoreDescriptor< any > >( store: S ): ActionCreatorsOf< S >;
252
+ (
253
+ store: StoreNameOrDescriptor
254
+ ): Record< string, ( ...args: any[] ) => any >;
255
+ };
256
+ use: (
257
+ plugin: DataPlugin,
258
+ options?: Record< string, unknown >
259
+ ) => DataRegistry;
197
260
  register: ( store: StoreDescriptor< any > ) => void;
198
- dispatch: < S extends StoreDescriptor< any > >(
199
- store: S
200
- ) => ActionCreatorsOf< ConfigOf< S > >;
261
+ registerGenericStore: (
262
+ name: string,
263
+ store: StoreInstance< AnyConfig >
264
+ ) => void;
265
+ registerStore: (
266
+ storeName: string,
267
+ options: ReduxStoreConfig< any, any, any >
268
+ ) => ReduxStore;
269
+ __unstableMarkListeningStores: < T >(
270
+ callback: () => T,
271
+ ref: { current: string[] | null }
272
+ ) => T;
273
+ }
274
+
275
+ /**
276
+ * The plugin function signature.
277
+ */
278
+ export type DataPlugin = (
279
+ registry: DataRegistry,
280
+ options?: Record< string, unknown >
281
+ ) => Partial< DataRegistry >;
282
+
283
+ /**
284
+ * Status of a selector resolution.
285
+ */
286
+ export type ResolutionStatus = 'resolving' | 'finished' | 'error';
287
+
288
+ /**
289
+ * State value for a single resolution.
290
+ */
291
+ export type ResolutionState =
292
+ | { status: 'resolving' }
293
+ | { status: 'finished' }
294
+ | { status: 'error'; error: Error | unknown };
295
+
296
+ /**
297
+ * A normalized resolver with a `fulfill` method and optional `isFulfilled`.
298
+ */
299
+ export interface NormalizedResolver {
300
+ /**
301
+ * The function to call to fulfill the resolver.
302
+ */
303
+ fulfill: ( ...args: any[] ) => any;
304
+ /**
305
+ * Optional function to check if the resolver is already fulfilled.
306
+ */
307
+ isFulfilled?: ( state: any, ...args: any[] ) => boolean;
308
+ /**
309
+ * Optional function to check if the resolver should be invalidated.
310
+ */
311
+ shouldInvalidate?: ( action: any, ...args: any[] ) => boolean;
312
+ }
313
+
314
+ /**
315
+ * A bound selector with optional resolver metadata.
316
+ */
317
+ export interface BoundSelector {
318
+ ( ...args: any[] ): any;
319
+ /**
320
+ * Whether this selector has a resolver attached.
321
+ */
322
+ hasResolver: boolean;
323
+ /**
324
+ * Optional function to normalize the arguments.
325
+ */
326
+ __unstableNormalizeArgs?: ( args: any[] ) => any[];
327
+ /**
328
+ * Whether this selector is a registry selector.
329
+ */
330
+ isRegistrySelector?: boolean;
331
+ /**
332
+ * The registry instance this selector is bound to.
333
+ */
334
+ registry?: DataRegistry;
335
+ }
336
+
337
+ /**
338
+ * The shape of a store instance as seen internally by the registry.
339
+ * Extends the public StoreInstance with additional internal properties.
340
+ */
341
+ export interface InternalStoreInstance< Config extends AnyConfig = AnyConfig >
342
+ extends StoreInstance< Config > {
343
+ /**
344
+ * The Redux store instance (only for Redux-based stores).
345
+ */
346
+ store?: ReduxStore;
347
+ /**
348
+ * The internal emitter for pause/resume batching.
349
+ */
350
+ emitter: DataEmitter;
351
+ /**
352
+ * The combined reducer.
353
+ */
354
+ reducer?: ( state: any, action: any ) => any;
355
+ /**
356
+ * Bound actions object.
357
+ */
358
+ actions?: Record< string, ActionCreator >;
359
+ /**
360
+ * Bound selectors object.
361
+ */
362
+ selectors?: Record< string, Selector >;
363
+ /**
364
+ * Resolver definitions.
365
+ */
366
+ resolvers?: Record< string, NormalizedResolver >;
367
+ /**
368
+ * Returns resolve-wrapped selectors.
369
+ */
370
+ getResolveSelectors?: () => Record<
371
+ string,
372
+ ( ...args: any[] ) => Promise< any >
373
+ >;
374
+ /**
375
+ * Returns suspense-wrapped selectors.
376
+ */
377
+ getSuspendSelectors?: () => Record< string, ( ...args: any[] ) => any >;
378
+ }
379
+
380
+ /**
381
+ * Control descriptor for the controls system.
382
+ */
383
+ export interface ControlDescriptor {
384
+ /**
385
+ * The type of the control action.
386
+ */
387
+ type: string;
388
+ /**
389
+ * The store key to target.
390
+ */
391
+ storeKey: string;
392
+ /**
393
+ * The name of the selector (for select/resolveSelect controls).
394
+ */
395
+ selectorName?: string;
396
+ /**
397
+ * The name of the action (for dispatch controls).
398
+ */
399
+ actionName?: string;
400
+ /**
401
+ * Arguments for the selector or action.
402
+ */
403
+ args: any[];
404
+ }
405
+
406
+ /**
407
+ * Storage interface (Web Storage API subset).
408
+ */
409
+ export interface StorageInterface {
410
+ getItem: ( key: string ) => string | null;
411
+ setItem: ( key: string, value: string ) => void;
412
+ removeItem?: ( key: string ) => void;
413
+ clear?: VoidFunction;
201
414
  }
202
415
 
203
416
  // Type Helpers.
204
417
 
205
418
  export type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;
206
419
 
207
- export type ActionCreatorsOf< Config extends AnyConfig > =
208
- Config extends ReduxStoreConfig< any, infer ActionCreators, any >
209
- ? PromisifiedActionCreators< ActionCreators >
210
- : never;
420
+ export type ActionCreatorsOf< T > = T extends StoreDescriptor<
421
+ ReduxStoreConfig< any, infer ActionCreators, any >
422
+ >
423
+ ? PromisifiedActionCreators< ActionCreators > & MetadataActions< T >
424
+ : T extends ReduxStoreConfig< any, infer ActionCreators, any >
425
+ ? PromisifiedActionCreators< ActionCreators >
426
+ : never;
211
427
 
212
428
  // Takes an object containing all action creators for a store and updates the
213
429
  // return type of each action creator to account for internal registry details --
214
430
  // for example, dispatched actions are wrapped with a Promise.
215
- export type PromisifiedActionCreators<
216
- ActionCreators extends MapOf< ActionCreator >,
217
- > = {
218
- [ Action in keyof ActionCreators ]: PromisifyActionCreator<
219
- ActionCreators[ Action ]
220
- >;
431
+ export type PromisifiedActionCreators< ActionCreators > = {
432
+ [ Action in keyof ActionCreators ]: ActionCreators[ Action ] extends ActionCreator
433
+ ? PromisifyActionCreator< ActionCreators[ Action ] >
434
+ : ActionCreators[ Action ];
221
435
  };
222
436
 
223
- // Wraps action creator return types with a Promise and handles thunks.
437
+ // Wraps action creator return types with a Promise and handles thunks and generators.
224
438
  export type PromisifyActionCreator< Action extends ActionCreator > = (
225
439
  ...args: Parameters< Action >
226
440
  ) => Promise<
227
441
  ReturnType< Action > extends ( ..._args: any[] ) => any
228
442
  ? ThunkReturnType< Action >
443
+ : ReturnType< Action > extends Generator< any, infer TReturn, any >
444
+ ? TReturn
229
445
  : ReturnType< Action >
230
446
  >;
231
447
 
@@ -245,4 +461,27 @@ type SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<
245
461
  ? { [ name in keyof Selectors ]: Function }
246
462
  : never;
247
463
 
464
+ /**
465
+ * The argument object passed to every thunk function. When parameterized with
466
+ * a store descriptor, `dispatch`, `select`, and `resolveSelect` are fully
467
+ * typed against that store's actions and selectors.
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * const myAction =
472
+ * ( id: number ) =>
473
+ * async ( { dispatch, select }: ThunkArgs< typeof myStore > ) => {
474
+ * const record = select.getRecord( id );
475
+ * dispatch.setLoading( true );
476
+ * };
477
+ * ```
478
+ */
479
+ export interface ThunkArgs< S extends StoreDescriptor = StoreDescriptor > {
480
+ dispatch: ActionCreatorsOf< S > &
481
+ ( ( action: Record< string, unknown > | Function ) => unknown );
482
+ select: CurriedSelectorsOf< S >;
483
+ resolveSelect: CurriedSelectorsResolveOf< S >;
484
+ registry: DataRegistry;
485
+ }
486
+
248
487
  export type combineReducers = typeof reduxCombineReducers;
@@ -1,23 +0,0 @@
1
- let objectStorage;
2
-
3
- const storage = {
4
- getItem( key ) {
5
- if ( ! objectStorage || ! objectStorage[ key ] ) {
6
- return null;
7
- }
8
-
9
- return objectStorage[ key ];
10
- },
11
- setItem( key, value ) {
12
- if ( ! objectStorage ) {
13
- storage.clear();
14
- }
15
-
16
- objectStorage[ key ] = String( value );
17
- },
18
- clear() {
19
- objectStorage = Object.create( null );
20
- },
21
- };
22
-
23
- export default storage;
File without changes