@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.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 (383) hide show
  1. package/build/actions.js +375 -632
  2. package/build/actions.js.map +7 -1
  3. package/build/batch/create-batch.js +49 -62
  4. package/build/batch/create-batch.js.map +7 -1
  5. package/build/batch/default-processor.js +43 -39
  6. package/build/batch/default-processor.js.map +7 -1
  7. package/build/batch/index.js +38 -17
  8. package/build/batch/index.js.map +7 -1
  9. package/build/dynamic-entities.js +30 -32
  10. package/build/dynamic-entities.js.map +7 -1
  11. package/build/entities.js +298 -410
  12. package/build/entities.js.map +7 -1
  13. package/build/entity-context.js +29 -12
  14. package/build/entity-context.js.map +7 -1
  15. package/build/entity-provider.js +38 -46
  16. package/build/entity-provider.js.map +7 -1
  17. package/build/entity-types/attachment.js +16 -5
  18. package/build/entity-types/attachment.js.map +7 -1
  19. package/build/entity-types/base-entity-records.js +16 -42
  20. package/build/entity-types/base-entity-records.js.map +7 -1
  21. package/build/entity-types/base.js +16 -5
  22. package/build/entity-types/base.js.map +7 -1
  23. package/build/entity-types/comment.js +16 -5
  24. package/build/entity-types/comment.js.map +7 -1
  25. package/build/entity-types/global-styles-revision.js +16 -5
  26. package/build/entity-types/global-styles-revision.js.map +7 -1
  27. package/build/entity-types/helpers.js +16 -5
  28. package/build/entity-types/helpers.js.map +7 -1
  29. package/build/entity-types/index.js +16 -5
  30. package/build/entity-types/index.js.map +7 -1
  31. package/build/entity-types/menu-location.js +16 -5
  32. package/build/entity-types/menu-location.js.map +7 -1
  33. package/build/entity-types/nav-menu-item.js +16 -5
  34. package/build/entity-types/nav-menu-item.js.map +7 -1
  35. package/build/entity-types/nav-menu.js +16 -5
  36. package/build/entity-types/nav-menu.js.map +7 -1
  37. package/build/entity-types/page.js +16 -5
  38. package/build/entity-types/page.js.map +7 -1
  39. package/build/entity-types/plugin.js +16 -5
  40. package/build/entity-types/plugin.js.map +7 -1
  41. package/build/entity-types/post-revision.js +16 -5
  42. package/build/entity-types/post-revision.js.map +7 -1
  43. package/build/entity-types/post-status.js +16 -5
  44. package/build/entity-types/post-status.js.map +7 -1
  45. package/build/entity-types/post.js +16 -5
  46. package/build/entity-types/post.js.map +7 -1
  47. package/build/entity-types/settings.js +16 -5
  48. package/build/entity-types/settings.js.map +7 -1
  49. package/build/entity-types/sidebar.js +16 -5
  50. package/build/entity-types/sidebar.js.map +7 -1
  51. package/build/entity-types/taxonomy.js +16 -5
  52. package/build/entity-types/taxonomy.js.map +7 -1
  53. package/build/entity-types/term.js +16 -5
  54. package/build/entity-types/term.js.map +7 -1
  55. package/build/entity-types/theme.js +16 -5
  56. package/build/entity-types/theme.js.map +7 -1
  57. package/build/entity-types/type.js +16 -5
  58. package/build/entity-types/type.js.map +7 -1
  59. package/build/entity-types/user.js +16 -5
  60. package/build/entity-types/user.js.map +7 -1
  61. package/build/entity-types/widget-type.js +16 -5
  62. package/build/entity-types/widget-type.js.map +7 -1
  63. package/build/entity-types/widget.js +16 -5
  64. package/build/entity-types/widget.js.map +7 -1
  65. package/build/entity-types/wp-template-part.js +16 -5
  66. package/build/entity-types/wp-template-part.js.map +7 -1
  67. package/build/entity-types/wp-template.js +16 -5
  68. package/build/entity-types/wp-template.js.map +7 -1
  69. package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
  70. package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
  71. package/build/fetch/__experimental-fetch-url-data.js +47 -59
  72. package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
  73. package/build/fetch/index.js +53 -32
  74. package/build/fetch/index.js.map +7 -1
  75. package/build/footnotes/get-footnotes-order.js +38 -25
  76. package/build/footnotes/get-footnotes-order.js.map +7 -1
  77. package/build/footnotes/get-rich-text-values-cached.js +26 -27
  78. package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
  79. package/build/footnotes/index.js +68 -55
  80. package/build/footnotes/index.js.map +7 -1
  81. package/build/hooks/constants.js +33 -12
  82. package/build/hooks/constants.js.map +7 -1
  83. package/build/hooks/index.js +59 -68
  84. package/build/hooks/index.js.map +7 -1
  85. package/build/hooks/memoize.js +34 -12
  86. package/build/hooks/memoize.js.map +7 -1
  87. package/build/hooks/use-entity-block-editor.js +111 -119
  88. package/build/hooks/use-entity-block-editor.js.map +7 -1
  89. package/build/hooks/use-entity-id.js +25 -23
  90. package/build/hooks/use-entity-id.js.map +7 -1
  91. package/build/hooks/use-entity-prop.js +59 -60
  92. package/build/hooks/use-entity-prop.js.map +7 -1
  93. package/build/hooks/use-entity-record.js +95 -155
  94. package/build/hooks/use-entity-record.js.map +7 -1
  95. package/build/hooks/use-entity-records.js +131 -139
  96. package/build/hooks/use-entity-records.js.map +7 -1
  97. package/build/hooks/use-query-select.js +65 -84
  98. package/build/hooks/use-query-select.js.map +7 -1
  99. package/build/hooks/use-resource-permissions.js +92 -145
  100. package/build/hooks/use-resource-permissions.js.map +7 -1
  101. package/build/index.js +96 -153
  102. package/build/index.js.map +7 -1
  103. package/build/lock-unlock.js +31 -14
  104. package/build/lock-unlock.js.map +7 -1
  105. package/build/locks/actions.js +36 -19
  106. package/build/locks/actions.js.map +7 -1
  107. package/build/locks/engine.js +48 -47
  108. package/build/locks/engine.js.map +7 -1
  109. package/build/locks/reducer.js +54 -63
  110. package/build/locks/reducer.js.map +7 -1
  111. package/build/locks/selectors.js +35 -30
  112. package/build/locks/selectors.js.map +7 -1
  113. package/build/locks/utils.js +37 -16
  114. package/build/locks/utils.js.map +7 -1
  115. package/build/name.js +27 -12
  116. package/build/name.js.map +7 -1
  117. package/build/private-actions.js +67 -75
  118. package/build/private-actions.js.map +7 -1
  119. package/build/private-apis.js +33 -16
  120. package/build/private-apis.js.map +7 -1
  121. package/build/private-selectors.js +204 -184
  122. package/build/private-selectors.js.map +7 -1
  123. package/build/queried-data/actions.js +32 -41
  124. package/build/queried-data/actions.js.map +7 -1
  125. package/build/queried-data/get-query-parts.js +41 -79
  126. package/build/queried-data/get-query-parts.js.map +7 -1
  127. package/build/queried-data/index.js +39 -36
  128. package/build/queried-data/index.js.map +7 -1
  129. package/build/queried-data/reducer.js +162 -193
  130. package/build/queried-data/reducer.js.map +7 -1
  131. package/build/queried-data/selectors.js +57 -85
  132. package/build/queried-data/selectors.js.map +7 -1
  133. package/build/reducer.js +279 -404
  134. package/build/reducer.js.map +7 -1
  135. package/build/resolvers.js +553 -600
  136. package/build/resolvers.js.map +7 -1
  137. package/build/selectors.js +456 -981
  138. package/build/selectors.js.map +7 -1
  139. package/build/sync.js +34 -22
  140. package/build/sync.js.map +7 -1
  141. package/build/types.js +16 -5
  142. package/build/types.js.map +7 -1
  143. package/build/utils/conservative-map-item.js +34 -27
  144. package/build/utils/conservative-map-item.js.map +7 -1
  145. package/build/utils/crdt-blocks.js +289 -0
  146. package/build/utils/crdt-blocks.js.map +7 -0
  147. package/build/utils/crdt.js +202 -0
  148. package/build/utils/crdt.js.map +7 -0
  149. package/build/utils/forward-resolver.js +24 -16
  150. package/build/utils/forward-resolver.js.map +7 -1
  151. package/build/utils/get-nested-value.js +26 -21
  152. package/build/utils/get-nested-value.js.map +7 -1
  153. package/build/utils/get-normalized-comma-separable.js +25 -17
  154. package/build/utils/get-normalized-comma-separable.js.map +7 -1
  155. package/build/utils/if-matching-action.js +25 -19
  156. package/build/utils/if-matching-action.js.map +7 -1
  157. package/build/utils/index.js +77 -108
  158. package/build/utils/index.js.map +7 -1
  159. package/build/utils/is-numeric-id.js +22 -12
  160. package/build/utils/is-numeric-id.js.map +7 -1
  161. package/build/utils/is-raw-attribute.js +22 -13
  162. package/build/utils/is-raw-attribute.js.map +7 -1
  163. package/build/utils/log-entity-deprecation.js +37 -38
  164. package/build/utils/log-entity-deprecation.js.map +7 -1
  165. package/build/utils/on-sub-key.js +30 -24
  166. package/build/utils/on-sub-key.js.map +7 -1
  167. package/build/utils/receive-intermediate-results.js +29 -6
  168. package/build/utils/receive-intermediate-results.js.map +7 -1
  169. package/build/utils/replace-action.js +24 -17
  170. package/build/utils/replace-action.js.map +7 -1
  171. package/build/utils/set-nested-value.js +25 -30
  172. package/build/utils/set-nested-value.js.map +7 -1
  173. package/build/utils/user-permissions.js +41 -13
  174. package/build/utils/user-permissions.js.map +7 -1
  175. package/build/utils/with-weak-map-cache.js +26 -22
  176. package/build/utils/with-weak-map-cache.js.map +7 -1
  177. package/build-module/actions.js +322 -601
  178. package/build-module/actions.js.map +7 -1
  179. package/build-module/batch/create-batch.js +21 -57
  180. package/build-module/batch/create-batch.js.map +7 -1
  181. package/build-module/batch/default-processor.js +14 -33
  182. package/build-module/batch/default-processor.js.map +7 -1
  183. package/build-module/batch/index.js +7 -3
  184. package/build-module/batch/index.js.map +7 -1
  185. package/build-module/dynamic-entities.js +7 -28
  186. package/build-module/dynamic-entities.js.map +7 -1
  187. package/build-module/entities.js +263 -399
  188. package/build-module/entities.js.map +7 -1
  189. package/build-module/entity-context.js +7 -7
  190. package/build-module/entity-context.js.map +7 -1
  191. package/build-module/entity-provider.js +19 -42
  192. package/build-module/entity-provider.js.map +7 -1
  193. package/build-module/entity-types/attachment.js +1 -2
  194. package/build-module/entity-types/attachment.js.map +7 -1
  195. package/build-module/entity-types/base-entity-records.js +1 -37
  196. package/build-module/entity-types/base-entity-records.js.map +7 -1
  197. package/build-module/entity-types/base.js +1 -2
  198. package/build-module/entity-types/base.js.map +7 -1
  199. package/build-module/entity-types/comment.js +1 -2
  200. package/build-module/entity-types/comment.js.map +7 -1
  201. package/build-module/entity-types/global-styles-revision.js +1 -2
  202. package/build-module/entity-types/global-styles-revision.js.map +7 -1
  203. package/build-module/entity-types/helpers.js +1 -2
  204. package/build-module/entity-types/helpers.js.map +7 -1
  205. package/build-module/entity-types/index.js +1 -2
  206. package/build-module/entity-types/index.js.map +7 -1
  207. package/build-module/entity-types/menu-location.js +1 -2
  208. package/build-module/entity-types/menu-location.js.map +7 -1
  209. package/build-module/entity-types/nav-menu-item.js +1 -2
  210. package/build-module/entity-types/nav-menu-item.js.map +7 -1
  211. package/build-module/entity-types/nav-menu.js +1 -2
  212. package/build-module/entity-types/nav-menu.js.map +7 -1
  213. package/build-module/entity-types/page.js +1 -2
  214. package/build-module/entity-types/page.js.map +7 -1
  215. package/build-module/entity-types/plugin.js +1 -2
  216. package/build-module/entity-types/plugin.js.map +7 -1
  217. package/build-module/entity-types/post-revision.js +1 -2
  218. package/build-module/entity-types/post-revision.js.map +7 -1
  219. package/build-module/entity-types/post-status.js +1 -2
  220. package/build-module/entity-types/post-status.js.map +7 -1
  221. package/build-module/entity-types/post.js +1 -2
  222. package/build-module/entity-types/post.js.map +7 -1
  223. package/build-module/entity-types/settings.js +1 -2
  224. package/build-module/entity-types/settings.js.map +7 -1
  225. package/build-module/entity-types/sidebar.js +1 -2
  226. package/build-module/entity-types/sidebar.js.map +7 -1
  227. package/build-module/entity-types/taxonomy.js +1 -2
  228. package/build-module/entity-types/taxonomy.js.map +7 -1
  229. package/build-module/entity-types/term.js +1 -2
  230. package/build-module/entity-types/term.js.map +7 -1
  231. package/build-module/entity-types/theme.js +1 -2
  232. package/build-module/entity-types/theme.js.map +7 -1
  233. package/build-module/entity-types/type.js +1 -2
  234. package/build-module/entity-types/type.js.map +7 -1
  235. package/build-module/entity-types/user.js +1 -2
  236. package/build-module/entity-types/user.js.map +7 -1
  237. package/build-module/entity-types/widget-type.js +1 -2
  238. package/build-module/entity-types/widget-type.js.map +7 -1
  239. package/build-module/entity-types/widget.js +1 -2
  240. package/build-module/entity-types/widget.js.map +7 -1
  241. package/build-module/entity-types/wp-template-part.js +1 -2
  242. package/build-module/entity-types/wp-template-part.js.map +7 -1
  243. package/build-module/entity-types/wp-template.js +1 -2
  244. package/build-module/entity-types/wp-template.js.map +7 -1
  245. package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
  246. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
  247. package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
  248. package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
  249. package/build-module/fetch/index.js +20 -15
  250. package/build-module/fetch/index.js.map +7 -1
  251. package/build-module/footnotes/get-footnotes-order.js +10 -19
  252. package/build-module/footnotes/get-footnotes-order.js.map +7 -1
  253. package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
  254. package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
  255. package/build-module/footnotes/index.js +34 -47
  256. package/build-module/footnotes/index.js.map +7 -1
  257. package/build-module/hooks/constants.js +11 -8
  258. package/build-module/hooks/constants.js.map +7 -1
  259. package/build-module/hooks/index.js +27 -15
  260. package/build-module/hooks/index.js.map +7 -1
  261. package/build-module/hooks/memoize.js +6 -8
  262. package/build-module/hooks/memoize.js.map +7 -1
  263. package/build-module/hooks/use-entity-block-editor.js +80 -110
  264. package/build-module/hooks/use-entity-block-editor.js.map +7 -1
  265. package/build-module/hooks/use-entity-id.js +7 -19
  266. package/build-module/hooks/use-entity-id.js.map +7 -1
  267. package/build-module/hooks/use-entity-prop.js +31 -55
  268. package/build-module/hooks/use-entity-prop.js.map +7 -1
  269. package/build-module/hooks/use-entity-record.js +63 -148
  270. package/build-module/hooks/use-entity-record.js.map +7 -1
  271. package/build-module/hooks/use-entity-records.js +98 -131
  272. package/build-module/hooks/use-entity-records.js.map +7 -1
  273. package/build-module/hooks/use-query-select.js +27 -71
  274. package/build-module/hooks/use-query-select.js.map +7 -1
  275. package/build-module/hooks/use-resource-permissions.js +57 -136
  276. package/build-module/hooks/use-resource-permissions.js.map +7 -1
  277. package/build-module/index.js +49 -71
  278. package/build-module/index.js.map +7 -1
  279. package/build-module/lock-unlock.js +8 -7
  280. package/build-module/lock-unlock.js.map +7 -1
  281. package/build-module/locks/actions.js +8 -13
  282. package/build-module/locks/actions.js.map +7 -1
  283. package/build-module/locks/engine.js +17 -38
  284. package/build-module/locks/engine.js.map +7 -1
  285. package/build-module/locks/reducer.js +37 -59
  286. package/build-module/locks/reducer.js.map +7 -1
  287. package/build-module/locks/selectors.js +16 -23
  288. package/build-module/locks/selectors.js.map +7 -1
  289. package/build-module/locks/utils.js +15 -12
  290. package/build-module/locks/utils.js.map +7 -1
  291. package/build-module/name.js +5 -8
  292. package/build-module/name.js.map +7 -1
  293. package/build-module/private-actions.js +35 -69
  294. package/build-module/private-actions.js.map +7 -1
  295. package/build-module/private-apis.js +8 -8
  296. package/build-module/private-apis.js.map +7 -1
  297. package/build-module/private-selectors.js +167 -174
  298. package/build-module/private-selectors.js.map +7 -1
  299. package/build-module/queried-data/actions.js +11 -38
  300. package/build-module/queried-data/actions.js.map +7 -1
  301. package/build-module/queried-data/get-query-parts.js +20 -75
  302. package/build-module/queried-data/get-query-parts.js.map +7 -1
  303. package/build-module/queried-data/index.js +7 -4
  304. package/build-module/queried-data/index.js.map +7 -1
  305. package/build-module/queried-data/reducer.js +134 -185
  306. package/build-module/queried-data/reducer.js.map +7 -1
  307. package/build-module/queried-data/selectors.js +23 -78
  308. package/build-module/queried-data/selectors.js.map +7 -1
  309. package/build-module/reducer.js +243 -393
  310. package/build-module/reducer.js.map +7 -1
  311. package/build-module/resolvers.js +478 -549
  312. package/build-module/resolvers.js.map +7 -1
  313. package/build-module/selectors.js +410 -953
  314. package/build-module/selectors.js.map +7 -1
  315. package/build-module/sync.js +14 -17
  316. package/build-module/sync.js.map +7 -1
  317. package/build-module/types.js +1 -2
  318. package/build-module/types.js.map +7 -1
  319. package/build-module/utils/conservative-map-item.js +6 -22
  320. package/build-module/utils/conservative-map-item.js.map +7 -1
  321. package/build-module/utils/crdt-blocks.js +255 -0
  322. package/build-module/utils/crdt-blocks.js.map +7 -0
  323. package/build-module/utils/crdt.js +167 -0
  324. package/build-module/utils/crdt.js.map +7 -0
  325. package/build-module/utils/forward-resolver.js +6 -12
  326. package/build-module/utils/forward-resolver.js.map +7 -1
  327. package/build-module/utils/get-nested-value.js +9 -18
  328. package/build-module/utils/get-nested-value.js.map +7 -1
  329. package/build-module/utils/get-normalized-comma-separable.js +7 -13
  330. package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
  331. package/build-module/utils/if-matching-action.js +7 -15
  332. package/build-module/utils/if-matching-action.js.map +7 -1
  333. package/build-module/utils/index.js +35 -14
  334. package/build-module/utils/index.js.map +7 -1
  335. package/build-module/utils/is-numeric-id.js +5 -9
  336. package/build-module/utils/is-numeric-id.js.map +7 -1
  337. package/build-module/utils/is-raw-attribute.js +5 -10
  338. package/build-module/utils/is-raw-attribute.js.map +7 -1
  339. package/build-module/utils/log-entity-deprecation.js +8 -31
  340. package/build-module/utils/log-entity-deprecation.js.map +7 -1
  341. package/build-module/utils/on-sub-key.js +8 -19
  342. package/build-module/utils/on-sub-key.js.map +7 -1
  343. package/build-module/utils/receive-intermediate-results.js +7 -2
  344. package/build-module/utils/receive-intermediate-results.js.map +7 -1
  345. package/build-module/utils/replace-action.js +6 -13
  346. package/build-module/utils/replace-action.js.map +7 -1
  347. package/build-module/utils/set-nested-value.js +8 -27
  348. package/build-module/utils/set-nested-value.js.map +7 -1
  349. package/build-module/utils/user-permissions.js +19 -9
  350. package/build-module/utils/user-permissions.js.map +7 -1
  351. package/build-module/utils/with-weak-map-cache.js +8 -18
  352. package/build-module/utils/with-weak-map-cache.js.map +7 -1
  353. package/build-types/actions.d.ts.map +1 -1
  354. package/build-types/entities.d.ts +0 -56
  355. package/build-types/entities.d.ts.map +1 -1
  356. package/build-types/index.d.ts.map +1 -1
  357. package/build-types/private-selectors.d.ts.map +1 -1
  358. package/build-types/resolvers.d.ts +3 -0
  359. package/build-types/resolvers.d.ts.map +1 -1
  360. package/build-types/selectors.d.ts.map +1 -1
  361. package/build-types/sync.d.ts +6 -1
  362. package/build-types/sync.d.ts.map +1 -1
  363. package/build-types/types.d.ts +9 -0
  364. package/build-types/types.d.ts.map +1 -1
  365. package/build-types/utils/crdt-blocks.d.ts +30 -0
  366. package/build-types/utils/crdt-blocks.d.ts.map +1 -0
  367. package/build-types/utils/crdt.d.ts +49 -0
  368. package/build-types/utils/crdt.d.ts.map +1 -0
  369. package/package.json +26 -19
  370. package/src/actions.js +56 -74
  371. package/src/entities.js +59 -113
  372. package/src/private-selectors.ts +32 -7
  373. package/src/resolvers.js +173 -120
  374. package/src/selectors.ts +0 -13
  375. package/src/sync.ts +12 -0
  376. package/src/test/resolvers.js +183 -0
  377. package/src/types.ts +12 -0
  378. package/src/utils/crdt-blocks.ts +503 -0
  379. package/src/utils/crdt.ts +310 -0
  380. package/src/utils/test/crdt-blocks.ts +375 -0
  381. package/src/utils/test/crdt.ts +254 -0
  382. package/tsconfig.tsbuildinfo +1 -1
  383. package/src/sync.js +0 -27
@@ -1 +1,7 @@
1
- {"version":3,"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","_getNormalizedCommaSe","join","_getNormalizedCommaSe2","toString","map","slice"],"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,gBAAgB;;AAE7C;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,2BAA2B,QAAQ,UAAU;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAEC,KAAK,EAAG;EACtC;AACD;AACA;EACC,MAAMC,KAAK,GAAG;IACbC,SAAS,EAAE,EAAE;IACbC,IAAI,EAAE,CAAC;IACPC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAE,IAAI;IACZC,OAAO,EAAE,IAAI;IACbC,OAAO,EAAE;EACV,CAAC;;EAED;EACA,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAAER,KAAM,CAAC,CAACU,IAAI,CAAC,CAAC;EAExC,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,EAAG;IACvC,MAAME,GAAG,GAAGL,IAAI,CAAEG,CAAC,CAAE;IACrB,IAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAG,CAAE;IAExB,QAASA,GAAG;MACX,KAAK,MAAM;QACVZ,KAAK,CAAEY,GAAG,CAAE,GAAGE,MAAM,CAAED,KAAM,CAAC;QAC9B;MAED,KAAK,UAAU;QACdb,KAAK,CAACG,OAAO,GAAGW,MAAM,CAAED,KAAM,CAAC;QAC/B;MAED,KAAK,SAAS;QACbb,KAAK,CAACM,OAAO,GAAGO,KAAK;QACrB;MAED;QACC;QACA;QACA;QACA;QACA;QACA,IAAKD,GAAG,KAAK,SAAS,EAAG;UAAA,IAAAG,qBAAA;UACxBf,KAAK,CAACI,MAAM,IAAAW,qBAAA,GAAGlB,2BAA2B,CAAEgB,KAAM,CAAC,cAAAE,qBAAA,cAAAA,qBAAA,GAAI,EAAE;UACzD;UACAF,KAAK,GAAGb,KAAK,CAACI,MAAM,CAACY,IAAI,CAAC,CAAC;QAC5B;;QAEA;QACA,IAAKJ,GAAG,KAAK,SAAS,EAAG;UAAA,IAAAK,sBAAA;UACxB,IAAK,OAAOJ,KAAK,KAAK,QAAQ,EAAG;YAChCA,KAAK,GAAGA,KAAK,CAACK,QAAQ,CAAC,CAAC;UACzB;UACAlB,KAAK,CAACK,OAAO,GAAG,EAAAY,sBAAA,GACfpB,2BAA2B,CAAEgB,KAAM,CAAC,cAAAI,sBAAA,cAAAA,sBAAA,GAAI,EAAE,EACzCE,GAAG,CAAEL,MAAO,CAAC;UACf;UACAD,KAAK,GAAGb,KAAK,CAACK,OAAO,CAACW,IAAI,CAAC,CAAC;QAC7B;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACAhB,KAAK,CAACC,SAAS,IACd,CAAED,KAAK,CAACC,SAAS,GAAG,GAAG,GAAG,EAAE,IAC5BN,YAAY,CAAE,EAAE,EAAE;UAAE,CAAEiB,GAAG,GAAIC;QAAM,CAAE,CAAC,CAACO,KAAK,CAAE,CAAE,CAAC;IACpD;EACD;EAEA,OAAOpB,KAAK;AACb;AAEA,eAAeJ,gBAAgB,CAAEE,aAAc,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/queried-data/get-query-parts.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],
5
+ "mappings": "AAGA,SAAS,oBAAoB;AAK7B,SAAS,kBAAkB,mCAAmC;AA2BvD,SAAS,cAAe,OAAQ;AAItC,QAAM,QAAQ;AAAA,IACb,WAAW;AAAA,IACX,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAGA,QAAM,OAAO,OAAO,KAAM,KAAM,EAAE,KAAK;AAEvC,WAAU,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAM;AACvC,UAAM,MAAM,KAAM,CAAE;AACpB,QAAI,QAAQ,MAAO,GAAI;AAEvB,YAAS,KAAM;AAAA,MACd,KAAK;AACJ,cAAO,GAAI,IAAI,OAAQ,KAAM;AAC7B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU,OAAQ,KAAM;AAC9B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU;AAChB;AAAA,MAED;AAMC,YAAK,QAAQ,WAAY;AACxB,gBAAM,SAAS,4BAA6B,KAAM,KAAK,CAAC;AAExD,kBAAQ,MAAM,OAAO,KAAK;AAAA,QAC3B;AAGA,YAAK,QAAQ,WAAY;AACxB,cAAK,OAAO,UAAU,UAAW;AAChC,oBAAQ,MAAM,SAAS;AAAA,UACxB;AACA,gBAAM,WACL,4BAA6B,KAAM,KAAK,CAAC,GACxC,IAAK,MAAO;AAEd,kBAAQ,MAAM,QAAQ,KAAK;AAAA,QAC5B;AASA,cAAM,cACH,MAAM,YAAY,MAAM,MAC1B,aAAc,IAAI,EAAE,CAAE,GAAI,GAAG,MAAM,CAAE,EAAE,MAAO,CAAE;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,0BAAQ,iBAAkB,aAAc;",
6
+ "names": []
7
+ }
@@ -1,4 +1,7 @@
1
- export * from './actions';
2
- export * from './selectors';
3
- export { default as reducer } from './reducer';
4
- //# sourceMappingURL=index.js.map
1
+ export * from "./actions";
2
+ export * from "./selectors";
3
+ import { default as default2 } from "./reducer";
4
+ export {
5
+ default2 as reducer
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["default","reducer"],"sources":["@wordpress/core-data/src/queried-data/index.js"],"sourcesContent":["export * from './actions';\nexport * from './selectors';\nexport { default as reducer } from './reducer';\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,aAAa;AAC3B,SAASA,OAAO,IAAIC,OAAO,QAAQ,WAAW","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/queried-data/index.js"],
4
+ "sourcesContent": ["export * from './actions';\nexport * from './selectors';\nexport { default as reducer } from './reducer';\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA0B;",
6
+ "names": ["default"]
7
+ }
@@ -1,235 +1,184 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { combineReducers } from '@wordpress/data';
5
- import { compose } from '@wordpress/compose';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { conservativeMapItem, ifMatchingAction, replaceAction, onSubKey } from '../utils';
11
- import { DEFAULT_ENTITY_KEY } from '../entities';
12
- import getQueryParts from './get-query-parts';
1
+ import { combineReducers } from "@wordpress/data";
2
+ import { compose } from "@wordpress/compose";
3
+ import {
4
+ conservativeMapItem,
5
+ ifMatchingAction,
6
+ replaceAction,
7
+ onSubKey
8
+ } from "../utils";
9
+ import { DEFAULT_ENTITY_KEY } from "../entities";
10
+ import getQueryParts from "./get-query-parts";
13
11
  function getContextFromAction(action) {
14
- const {
15
- query
16
- } = action;
12
+ const { query } = action;
17
13
  if (!query) {
18
- return 'default';
14
+ return "default";
19
15
  }
20
16
  const queryParts = getQueryParts(query);
21
17
  return queryParts.context;
22
18
  }
23
-
24
- /**
25
- * Returns a merged array of item IDs, given details of the received paginated
26
- * items. The array is sparse-like with `undefined` entries where holes exist.
27
- *
28
- * @param {?Array<number>} itemIds Original item IDs (default empty array).
29
- * @param {number[]} nextItemIds Item IDs to merge.
30
- * @param {number} page Page of items merged.
31
- * @param {number} perPage Number of items per page.
32
- *
33
- * @return {number[]} Merged array of item IDs.
34
- */
35
- export function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
36
- var _itemIds$length;
19
+ function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
37
20
  const receivedAllIds = page === 1 && perPage === -1;
38
21
  if (receivedAllIds) {
39
22
  return nextItemIds;
40
23
  }
41
24
  const nextItemIdsStartIndex = (page - 1) * perPage;
42
-
43
- // If later page has already been received, default to the larger known
44
- // size of the existing array, else calculate as extending the existing.
45
- const size = Math.max((_itemIds$length = itemIds?.length) !== null && _itemIds$length !== void 0 ? _itemIds$length : 0, nextItemIdsStartIndex + nextItemIds.length);
46
-
47
- // Preallocate array since size is known.
25
+ const size = Math.max(
26
+ itemIds?.length ?? 0,
27
+ nextItemIdsStartIndex + nextItemIds.length
28
+ );
48
29
  const mergedItemIds = new Array(size);
49
30
  for (let i = 0; i < size; i++) {
50
- // Preserve existing item ID except for subset of range of next items.
51
- // We need to check against the possible maximum upper boundary because
52
- // a page could receive fewer than what was previously stored.
53
31
  const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;
54
32
  mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds?.[i];
55
33
  }
56
34
  return mergedItemIds;
57
35
  }
58
-
59
- /**
60
- * Helper function to filter out entities with certain IDs.
61
- * Entities are keyed by their ID.
62
- *
63
- * @param {Object} entities Entity objects, keyed by entity ID.
64
- * @param {Array} ids Entity IDs to filter out.
65
- *
66
- * @return {Object} Filtered entities.
67
- */
68
36
  function removeEntitiesById(entities, ids) {
69
- return Object.fromEntries(Object.entries(entities).filter(([id]) => !ids.some(itemId => {
70
- if (Number.isInteger(itemId)) {
71
- return itemId === +id;
72
- }
73
- return itemId === id;
74
- })));
37
+ return Object.fromEntries(
38
+ Object.entries(entities).filter(
39
+ ([id]) => !ids.some((itemId) => {
40
+ if (Number.isInteger(itemId)) {
41
+ return itemId === +id;
42
+ }
43
+ return itemId === id;
44
+ })
45
+ )
46
+ );
75
47
  }
76
-
77
- /**
78
- * Reducer tracking items state, keyed by ID. Items are assumed to be normal,
79
- * where identifiers are common across all queries.
80
- *
81
- * @param {Object} state Current state.
82
- * @param {Object} action Dispatched action.
83
- *
84
- * @return {Object} Next state.
85
- */
86
- export function items(state = {}, action) {
48
+ function items(state = {}, action) {
87
49
  switch (action.type) {
88
- case 'RECEIVE_ITEMS':
89
- {
90
- const context = getContextFromAction(action);
91
- const key = action.key || DEFAULT_ENTITY_KEY;
92
- return {
93
- ...state,
94
- [context]: {
95
- ...state[context],
96
- ...action.items.reduce((accumulator, value) => {
97
- const itemId = value?.[key];
98
- accumulator[itemId] = conservativeMapItem(state?.[context]?.[itemId], value);
99
- return accumulator;
100
- }, {})
101
- }
102
- };
103
- }
104
- case 'REMOVE_ITEMS':
105
- return Object.fromEntries(Object.entries(state).map(([itemId, contextState]) => [itemId, removeEntitiesById(contextState, action.itemIds)]));
50
+ case "RECEIVE_ITEMS": {
51
+ const context = getContextFromAction(action);
52
+ const key = action.key || DEFAULT_ENTITY_KEY;
53
+ return {
54
+ ...state,
55
+ [context]: {
56
+ ...state[context],
57
+ ...action.items.reduce((accumulator, value) => {
58
+ const itemId = value?.[key];
59
+ accumulator[itemId] = conservativeMapItem(
60
+ state?.[context]?.[itemId],
61
+ value
62
+ );
63
+ return accumulator;
64
+ }, {})
65
+ }
66
+ };
67
+ }
68
+ case "REMOVE_ITEMS":
69
+ return Object.fromEntries(
70
+ Object.entries(state).map(([itemId, contextState]) => [
71
+ itemId,
72
+ removeEntitiesById(contextState, action.itemIds)
73
+ ])
74
+ );
106
75
  }
107
76
  return state;
108
77
  }
109
-
110
- /**
111
- * Reducer tracking item completeness, keyed by ID. A complete item is one for
112
- * which all fields are known. This is used in supporting `_fields` queries,
113
- * where not all properties associated with an entity are necessarily returned.
114
- * In such cases, completeness is used as an indication of whether it would be
115
- * safe to use queried data for a non-`_fields`-limited request.
116
- *
117
- * @param {Object<string,Object<string,boolean>>} state Current state.
118
- * @param {Object} action Dispatched action.
119
- *
120
- * @return {Object<string,Object<string,boolean>>} Next state.
121
- */
122
- export function itemIsComplete(state = {}, action) {
78
+ function itemIsComplete(state = {}, action) {
123
79
  switch (action.type) {
124
- case 'RECEIVE_ITEMS':
125
- {
126
- const context = getContextFromAction(action);
127
- const {
128
- query,
129
- key = DEFAULT_ENTITY_KEY
130
- } = action;
131
-
132
- // An item is considered complete if it is received without an associated
133
- // fields query. Ideally, this would be implemented in such a way where the
134
- // complete aggregate of all fields would satisfy completeness. Since the
135
- // fields are not consistent across all entities, this would require
136
- // introspection on the REST schema for each entity to know which fields
137
- // compose a complete item for that entity.
138
- const queryParts = query ? getQueryParts(query) : {};
139
- const isCompleteQuery = !query || !Array.isArray(queryParts.fields);
140
- return {
141
- ...state,
142
- [context]: {
143
- ...state[context],
144
- ...action.items.reduce((result, item) => {
145
- const itemId = item?.[key];
146
-
147
- // Defer to completeness if already assigned. Technically the
148
- // data may be outdated if receiving items for a field subset.
149
- result[itemId] = state?.[context]?.[itemId] || isCompleteQuery;
150
- return result;
151
- }, {})
152
- }
153
- };
154
- }
155
- case 'REMOVE_ITEMS':
156
- return Object.fromEntries(Object.entries(state).map(([itemId, contextState]) => [itemId, removeEntitiesById(contextState, action.itemIds)]));
80
+ case "RECEIVE_ITEMS": {
81
+ const context = getContextFromAction(action);
82
+ const { query, key = DEFAULT_ENTITY_KEY } = action;
83
+ const queryParts = query ? getQueryParts(query) : {};
84
+ const isCompleteQuery = !query || !Array.isArray(queryParts.fields);
85
+ return {
86
+ ...state,
87
+ [context]: {
88
+ ...state[context],
89
+ ...action.items.reduce((result, item) => {
90
+ const itemId = item?.[key];
91
+ result[itemId] = state?.[context]?.[itemId] || isCompleteQuery;
92
+ return result;
93
+ }, {})
94
+ }
95
+ };
96
+ }
97
+ case "REMOVE_ITEMS":
98
+ return Object.fromEntries(
99
+ Object.entries(state).map(([itemId, contextState]) => [
100
+ itemId,
101
+ removeEntitiesById(contextState, action.itemIds)
102
+ ])
103
+ );
157
104
  }
158
105
  return state;
159
106
  }
160
-
161
- /**
162
- * Reducer tracking queries state, keyed by stable query key. Each reducer
163
- * query object includes `itemIds` and `requestingPageByPerPage`.
164
- *
165
- * @param {Object} state Current state.
166
- * @param {Object} action Dispatched action.
167
- *
168
- * @return {Object} Next state.
169
- */
170
107
  const receiveQueries = compose([
171
- // Limit to matching action type so we don't attempt to replace action on
172
- // an unhandled action.
173
- ifMatchingAction(action => 'query' in action),
174
- // Inject query parts into action for use both in `onSubKey` and reducer.
175
- replaceAction(action => {
176
- // `ifMatchingAction` still passes on initialization, where state is
177
- // undefined and a query is not assigned. Avoid attempting to parse
178
- // parts. `onSubKey` will omit by lack of `stableKey`.
179
- if (action.query) {
180
- return {
181
- ...action,
182
- ...getQueryParts(action.query)
183
- };
184
- }
185
- return action;
186
- }), onSubKey('context'),
187
- // Queries shape is shared, but keyed by query `stableKey` part. Original
188
- // reducer tracks only a single query object.
189
- onSubKey('stableKey')])((state = {}, action) => {
190
- const {
191
- type,
192
- page,
193
- perPage,
194
- key = DEFAULT_ENTITY_KEY
195
- } = action;
196
- if (type !== 'RECEIVE_ITEMS') {
108
+ // Limit to matching action type so we don't attempt to replace action on
109
+ // an unhandled action.
110
+ ifMatchingAction((action) => "query" in action),
111
+ // Inject query parts into action for use both in `onSubKey` and reducer.
112
+ replaceAction((action) => {
113
+ if (action.query) {
114
+ return {
115
+ ...action,
116
+ ...getQueryParts(action.query)
117
+ };
118
+ }
119
+ return action;
120
+ }),
121
+ onSubKey("context"),
122
+ // Queries shape is shared, but keyed by query `stableKey` part. Original
123
+ // reducer tracks only a single query object.
124
+ onSubKey("stableKey")
125
+ ])((state = {}, action) => {
126
+ const { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;
127
+ if (type !== "RECEIVE_ITEMS") {
197
128
  return state;
198
129
  }
199
130
  return {
200
- itemIds: getMergedItemIds(state?.itemIds || [], action.items.map(item => item?.[key]).filter(Boolean), page, perPage),
131
+ itemIds: getMergedItemIds(
132
+ state?.itemIds || [],
133
+ action.items.map((item) => item?.[key]).filter(Boolean),
134
+ page,
135
+ perPage
136
+ ),
201
137
  meta: action.meta
202
138
  };
203
139
  });
204
-
205
- /**
206
- * Reducer tracking queries state.
207
- *
208
- * @param {Object} state Current state.
209
- * @param {Object} action Dispatched action.
210
- *
211
- * @return {Object} Next state.
212
- */
213
140
  const queries = (state = {}, action) => {
214
141
  switch (action.type) {
215
- case 'RECEIVE_ITEMS':
142
+ case "RECEIVE_ITEMS":
216
143
  return receiveQueries(state, action);
217
- case 'REMOVE_ITEMS':
144
+ case "REMOVE_ITEMS":
218
145
  const removedItems = action.itemIds.reduce((result, itemId) => {
219
146
  result[itemId] = true;
220
147
  return result;
221
148
  }, {});
222
- return Object.fromEntries(Object.entries(state).map(([queryGroup, contextQueries]) => [queryGroup, Object.fromEntries(Object.entries(contextQueries).map(([query, queryItems]) => [query, {
223
- ...queryItems,
224
- itemIds: queryItems.itemIds.filter(queryId => !removedItems[queryId])
225
- }]))]));
149
+ return Object.fromEntries(
150
+ Object.entries(state).map(
151
+ ([queryGroup, contextQueries]) => [
152
+ queryGroup,
153
+ Object.fromEntries(
154
+ Object.entries(contextQueries).map(
155
+ ([query, queryItems]) => [
156
+ query,
157
+ {
158
+ ...queryItems,
159
+ itemIds: queryItems.itemIds.filter(
160
+ (queryId) => !removedItems[queryId]
161
+ )
162
+ }
163
+ ]
164
+ )
165
+ )
166
+ ]
167
+ )
168
+ );
226
169
  default:
227
170
  return state;
228
171
  }
229
172
  };
230
- export default combineReducers({
173
+ var reducer_default = combineReducers({
231
174
  items,
232
175
  itemIsComplete,
233
176
  queries
234
177
  });
235
- //# sourceMappingURL=reducer.js.map
178
+ export {
179
+ reducer_default as default,
180
+ getMergedItemIds,
181
+ itemIsComplete,
182
+ items
183
+ };
184
+ //# sourceMappingURL=reducer.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["combineReducers","compose","conservativeMapItem","ifMatchingAction","replaceAction","onSubKey","DEFAULT_ENTITY_KEY","getQueryParts","getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","_itemIds$length","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","removeEntitiesById","entities","ids","Object","fromEntries","entries","filter","id","some","itemId","Number","isInteger","items","state","type","key","reduce","accumulator","value","map","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","Boolean","meta","queries","removedItems","queryGroup","contextQueries","queryItems","queryId"],"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value?.[ key ];\n\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,iBAAiB;AACjD,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,SACCC,mBAAmB,EACnBC,gBAAgB,EAChBC,aAAa,EACbC,QAAQ,QACF,UAAU;AACjB,SAASC,kBAAkB,QAAQ,aAAa;AAChD,OAAOC,aAAa,MAAM,mBAAmB;AAE7C,SAASC,oBAAoBA,CAAEC,MAAM,EAAG;EACvC,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAK,CAAEC,KAAK,EAAG;IACd,OAAO,SAAS;EACjB;EAEA,MAAMC,UAAU,GAAGJ,aAAa,CAAEG,KAAM,CAAC;EACzC,OAAOC,UAAU,CAACC,OAAO;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAEC,OAAO,EAAEC,WAAW,EAAEC,IAAI,EAAEC,OAAO,EAAG;EAAA,IAAAC,eAAA;EACvE,MAAMC,cAAc,GAAGH,IAAI,KAAK,CAAC,IAAIC,OAAO,KAAK,CAAC,CAAC;EACnD,IAAKE,cAAc,EAAG;IACrB,OAAOJ,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E,KAAM,CACrCD,UAAU,EACV7B,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAAE4B,cAAe,CAAC,CAACd,GAAG,CACnC,CAAE,CAAEtC,KAAK,EAAEqD,UAAU,CAAE,KAAM,CAC5BrD,KAAK,EACL;QACC,GAAGqD,UAAU;QACbjD,OAAO,EAAEiD,UAAU,CAACjD,OAAO,CAACqB,MAAM,CAC/B6B,OAAO,IACR,CAAEJ,YAAY,CAAEI,OAAO,CACzB;MACD,CAAC,CAEH,CACD,CAAC,CAEH,CACD,CAAC;IACF;MACC,OAAOtB,KAAK;EACd;AACD,CAAC;AAED,eAAe1C,eAAe,CAAE;EAC/ByC,KAAK;EACLS,cAAc;EACdS;AACD,CAAE,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/queried-data/reducer.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value?.[ key ];\n\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],
5
+ "mappings": "AAGA,SAAS,uBAAuB;AAChC,SAAS,eAAe;AA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CAAE,OAAO,UAAW,MAAO;AAAA,kBAC5B;AAAA,kBACA;AAAA,oBACC,GAAG;AAAA,oBACH,SAAS,WAAW,QAAQ;AAAA,sBAC3B,CAAE,YACD,CAAE,aAAc,OAAQ;AAAA,oBAC1B;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACC,aAAO;AAAA,EACT;AACD;AAEA,IAAO,kBAAQ,gBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
6
+ "names": []
7
+ }
@@ -1,45 +1,10 @@
1
- /**
2
- * External dependencies
3
- */
4
- import EquivalentKeyMap from 'equivalent-key-map';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { createSelector } from '@wordpress/data';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import getQueryParts from './get-query-parts';
15
- import { setNestedValue } from '../utils';
16
-
17
- /**
18
- * Cache of state keys to EquivalentKeyMap where the inner map tracks queries
19
- * to their resulting items set. WeakMap allows garbage collection on expired
20
- * state references.
21
- *
22
- * @type {WeakMap<Object,EquivalentKeyMap>}
23
- */
24
- const queriedItemsCacheByState = new WeakMap();
25
-
26
- /**
27
- * Returns items for a given query, or null if the items are not known.
28
- *
29
- * @param {Object} state State object.
30
- * @param {?Object} query Optional query.
31
- *
32
- * @return {?Array} Query items.
33
- */
1
+ import EquivalentKeyMap from "equivalent-key-map";
2
+ import { createSelector } from "@wordpress/data";
3
+ import getQueryParts from "./get-query-parts";
4
+ import { setNestedValue } from "../utils";
5
+ const queriedItemsCacheByState = /* @__PURE__ */ new WeakMap();
34
6
  function getQueriedItemsUncached(state, query) {
35
- const {
36
- stableKey,
37
- page,
38
- perPage,
39
- include,
40
- fields,
41
- context
42
- } = getQueryParts(query);
7
+ const { stableKey, page, perPage, include, fields, context } = getQueryParts(query);
43
8
  let itemIds;
44
9
  if (state.queries?.[context]?.[stableKey]) {
45
10
  itemIds = state.queries[context][stableKey].itemIds;
@@ -55,10 +20,9 @@ function getQueriedItemsUncached(state, query) {
55
20
  if (Array.isArray(include) && !include.includes(itemId)) {
56
21
  continue;
57
22
  }
58
- if (itemId === undefined) {
23
+ if (itemId === void 0) {
59
24
  continue;
60
25
  }
61
- // Having a target item ID doesn't guarantee that this object has been queried.
62
26
  if (!state.items[context]?.hasOwnProperty(itemId)) {
63
27
  return null;
64
28
  }
@@ -67,16 +31,14 @@ function getQueriedItemsUncached(state, query) {
67
31
  if (Array.isArray(fields)) {
68
32
  filteredItem = {};
69
33
  for (let f = 0; f < fields.length; f++) {
70
- const field = fields[f].split('.');
34
+ const field = fields[f].split(".");
71
35
  let value = item;
72
- field.forEach(fieldName => {
36
+ field.forEach((fieldName) => {
73
37
  value = value?.[fieldName];
74
38
  });
75
39
  setNestedValue(filteredItem, field, value);
76
40
  }
77
41
  } else {
78
- // If expecting a complete item, validate that completeness, or
79
- // otherwise abort.
80
42
  if (!state.itemIsComplete[context]?.[itemId]) {
81
43
  return null;
82
44
  }
@@ -86,25 +48,11 @@ function getQueriedItemsUncached(state, query) {
86
48
  }
87
49
  return items;
88
50
  }
89
-
90
- /**
91
- * Returns items for a given query, or null if the items are not known. Caches
92
- * result both per state (by reference) and per query (by deep equality).
93
- * The caching approach is intended to be durable to query objects which are
94
- * deeply but not referentially equal, since otherwise:
95
- *
96
- * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`
97
- *
98
- * @param {Object} state State object.
99
- * @param {?Object} query Optional query.
100
- *
101
- * @return {?Array} Query items.
102
- */
103
- export const getQueriedItems = createSelector((state, query = {}) => {
51
+ const getQueriedItems = createSelector((state, query = {}) => {
104
52
  let queriedItemsCache = queriedItemsCacheByState.get(state);
105
53
  if (queriedItemsCache) {
106
54
  const queriedItems = queriedItemsCache.get(query);
107
- if (queriedItems !== undefined) {
55
+ if (queriedItems !== void 0) {
108
56
  return queriedItems;
109
57
  }
110
58
  } else {
@@ -115,20 +63,17 @@ export const getQueriedItems = createSelector((state, query = {}) => {
115
63
  queriedItemsCache.set(query, items);
116
64
  return items;
117
65
  });
118
- export function getQueriedTotalItems(state, query = {}) {
119
- var _state$queries$contex;
120
- const {
121
- stableKey,
122
- context
123
- } = getQueryParts(query);
124
- return (_state$queries$contex = state.queries?.[context]?.[stableKey]?.meta?.totalItems) !== null && _state$queries$contex !== void 0 ? _state$queries$contex : null;
66
+ function getQueriedTotalItems(state, query = {}) {
67
+ const { stableKey, context } = getQueryParts(query);
68
+ return state.queries?.[context]?.[stableKey]?.meta?.totalItems ?? null;
125
69
  }
126
- export function getQueriedTotalPages(state, query = {}) {
127
- var _state$queries$contex2;
128
- const {
129
- stableKey,
130
- context
131
- } = getQueryParts(query);
132
- return (_state$queries$contex2 = state.queries?.[context]?.[stableKey]?.meta?.totalPages) !== null && _state$queries$contex2 !== void 0 ? _state$queries$contex2 : null;
70
+ function getQueriedTotalPages(state, query = {}) {
71
+ const { stableKey, context } = getQueryParts(query);
72
+ return state.queries?.[context]?.[stableKey]?.meta?.totalPages ?? null;
133
73
  }
134
- //# sourceMappingURL=selectors.js.map
74
+ export {
75
+ getQueriedItems,
76
+ getQueriedTotalItems,
77
+ getQueriedTotalPages
78
+ };
79
+ //# sourceMappingURL=selectors.js.map