@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,113 +1,47 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import deprecated from '@wordpress/deprecated';
5
- import warning from '@wordpress/warning';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { store as coreStore } from '../';
11
- import { Status } from './constants';
12
- import useQuerySelect from './use-query-select';
13
-
14
- /**
15
- * Is the data resolved by now?
16
- */
17
-
18
- /**
19
- * Resolves resource permissions.
20
- *
21
- * @since 6.1.0 Introduced in WordPress core.
22
- *
23
- * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
24
- * or REST base as a string - `media`.
25
- * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged
26
- * when using an entity object as a resource to check permissions and will be ignored.
27
- *
28
- * @example
29
- * ```js
30
- * import { useResourcePermissions } from '@wordpress/core-data';
31
- *
32
- * function PagesList() {
33
- * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );
34
- *
35
- * if ( isResolving ) {
36
- * return 'Loading ...';
37
- * }
38
- *
39
- * return (
40
- * <div>
41
- * {canCreate ? (<button>+ Create a new page</button>) : false}
42
- * // ...
43
- * </div>
44
- * );
45
- * }
46
- *
47
- * // Rendered in the application:
48
- * // <PagesList />
49
- * ```
50
- *
51
- * @example
52
- * ```js
53
- * import { useResourcePermissions } from '@wordpress/core-data';
54
- *
55
- * function Page({ pageId }) {
56
- * const {
57
- * canCreate,
58
- * canUpdate,
59
- * canDelete,
60
- * isResolving
61
- * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );
62
- *
63
- * if ( isResolving ) {
64
- * return 'Loading ...';
65
- * }
66
- *
67
- * return (
68
- * <div>
69
- * {canCreate ? (<button>+ Create a new page</button>) : false}
70
- * {canUpdate ? (<button>Edit page</button>) : false}
71
- * {canDelete ? (<button>Delete page</button>) : false}
72
- * // ...
73
- * </div>
74
- * );
75
- * }
76
- *
77
- * // Rendered in the application:
78
- * // <Page pageId={ 15 } />
79
- * ```
80
- *
81
- * In the above example, when `PagesList` is rendered into an
82
- * application, the appropriate permissions and the resolution details will be retrieved from
83
- * the store state using `canUser()`, or resolved if missing.
84
- *
85
- * @return Entity records data.
86
- * @template IdType
87
- */
1
+ import deprecated from "@wordpress/deprecated";
2
+ import warning from "@wordpress/warning";
3
+ import { store as coreStore } from "../";
4
+ import { Status } from "./constants";
5
+ import useQuerySelect from "./use-query-select";
88
6
  function useResourcePermissions(resource, id) {
89
- // Serialize `resource` to a string that can be safely used as a React dep.
90
- // We can't just pass `resource` as one of the deps, because if it is passed
91
- // as an object literal, then it will be a different object on each call even
92
- // if the values remain the same.
93
- const isEntity = typeof resource === 'object';
7
+ const isEntity = typeof resource === "object";
94
8
  const resourceAsString = isEntity ? JSON.stringify(resource) : resource;
95
- if (isEntity && typeof id !== 'undefined') {
96
- globalThis.SCRIPT_DEBUG === true ? warning(`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`) : void 0;
9
+ if (isEntity && typeof id !== "undefined") {
10
+ warning(
11
+ `When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`
12
+ );
97
13
  }
98
- return useQuerySelect(resolve => {
99
- const hasId = isEntity ? !!resource.id : !!id;
100
- const {
101
- canUser
102
- } = resolve(coreStore);
103
- const create = canUser('create', isEntity ? {
104
- kind: resource.kind,
105
- name: resource.name
106
- } : resource);
107
- if (!hasId) {
108
- const read = canUser('read', resource);
109
- const isResolving = create.isResolving || read.isResolving;
110
- const hasResolved = create.hasResolved && read.hasResolved;
14
+ return useQuerySelect(
15
+ (resolve) => {
16
+ const hasId = isEntity ? !!resource.id : !!id;
17
+ const { canUser } = resolve(coreStore);
18
+ const create = canUser(
19
+ "create",
20
+ isEntity ? { kind: resource.kind, name: resource.name } : resource
21
+ );
22
+ if (!hasId) {
23
+ const read2 = canUser("read", resource);
24
+ const isResolving2 = create.isResolving || read2.isResolving;
25
+ const hasResolved2 = create.hasResolved && read2.hasResolved;
26
+ let status2 = Status.Idle;
27
+ if (isResolving2) {
28
+ status2 = Status.Resolving;
29
+ } else if (hasResolved2) {
30
+ status2 = Status.Success;
31
+ }
32
+ return {
33
+ status: status2,
34
+ isResolving: isResolving2,
35
+ hasResolved: hasResolved2,
36
+ canCreate: create.hasResolved && create.data,
37
+ canRead: read2.hasResolved && read2.data
38
+ };
39
+ }
40
+ const read = canUser("read", resource, id);
41
+ const update = canUser("update", resource, id);
42
+ const _delete = canUser("delete", resource, id);
43
+ const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
44
+ const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
111
45
  let status = Status.Idle;
112
46
  if (isResolving) {
113
47
  status = Status.Resolving;
@@ -118,38 +52,25 @@ function useResourcePermissions(resource, id) {
118
52
  status,
119
53
  isResolving,
120
54
  hasResolved,
121
- canCreate: create.hasResolved && create.data,
122
- canRead: read.hasResolved && read.data
55
+ canRead: hasResolved && read.data,
56
+ canCreate: hasResolved && create.data,
57
+ canUpdate: hasResolved && update.data,
58
+ canDelete: hasResolved && _delete.data
123
59
  };
124
- }
125
- const read = canUser('read', resource, id);
126
- const update = canUser('update', resource, id);
127
- const _delete = canUser('delete', resource, id);
128
- const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
129
- const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
130
- let status = Status.Idle;
131
- if (isResolving) {
132
- status = Status.Resolving;
133
- } else if (hasResolved) {
134
- status = Status.Success;
135
- }
136
- return {
137
- status,
138
- isResolving,
139
- hasResolved,
140
- canRead: hasResolved && read.data,
141
- canCreate: hasResolved && create.data,
142
- canUpdate: hasResolved && update.data,
143
- canDelete: hasResolved && _delete.data
144
- };
145
- }, [resourceAsString, id]);
60
+ },
61
+ [resourceAsString, id]
62
+ );
146
63
  }
147
- export default useResourcePermissions;
148
- export function __experimentalUseResourcePermissions(resource, id) {
64
+ var use_resource_permissions_default = useResourcePermissions;
65
+ function __experimentalUseResourcePermissions(resource, id) {
149
66
  deprecated(`wp.data.__experimentalUseResourcePermissions`, {
150
- alternative: 'wp.data.useResourcePermissions',
151
- since: '6.1'
67
+ alternative: "wp.data.useResourcePermissions",
68
+ since: "6.1"
152
69
  });
153
70
  return useResourcePermissions(resource, id);
154
71
  }
155
- //# sourceMappingURL=use-resource-permissions.js.map
72
+ export {
73
+ __experimentalUseResourcePermissions,
74
+ use_resource_permissions_default as default
75
+ };
76
+ //# sourceMappingURL=use-resource-permissions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["deprecated","warning","store","coreStore","Status","useQuerySelect","useResourcePermissions","resource","id","isEntity","resourceAsString","JSON","stringify","globalThis","SCRIPT_DEBUG","resolve","hasId","canUser","create","kind","name","read","isResolving","hasResolved","status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,uBAAuB;AAC9C,OAAOC,OAAO,MAAM,oBAAoB;;AAExC;AACA;AACA;AACA,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AACxC,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,cAAc,MAAM,oBAAoB;;AAqB/C;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AACW,IAAI;MACrCI,SAAS,EAAEV,WAAW,IAAIQ,MAAM,CAACF,IAAI;MACrCK,SAAS,EAAEX,WAAW,IAAIS,OAAO,CAACH;IACnC,CAAC;EACF,CAAC,EACD,CAAEnB,gBAAgB,EAAEF,EAAE,CACvB,CAAC;AACF;AAEA,eAAeF,sBAAsB;AAErC,OAAO,SAAS6B,oCAAoCA,CACnD5B,QAAgB,EAChBC,EAAY,EACX;EACDR,UAAU,CAAE,8CAA8C,EAAE;IAC3DoC,WAAW,EAAE,gCAAgC;IAC7CC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAO/B,sBAAsB,CAAEC,QAAQ,EAAEC,EAAG,CAAC;AAC9C","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-resource-permissions.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],
5
+ "mappings": "AAGA,OAAO,gBAAgB;AACvB,OAAO,aAAa;AAKpB,SAAS,SAAS,iBAAiB;AACnC,SAAS,cAAc;AACvB,OAAO,oBAAoB;AAmH3B,SAAS,uBACR,UACA,IAC0C;AAK1C,QAAM,WAAW,OAAO,aAAa;AACrC,QAAM,mBAAmB,WAAW,KAAK,UAAW,QAAS,IAAI;AAEjE,MAAK,YAAY,OAAO,OAAO,aAAc;AAC5C;AAAA,MACC;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN,CAAE,YAAa;AACd,YAAM,QAAQ,WAAW,CAAC,CAAE,SAAS,KAAK,CAAC,CAAE;AAC7C,YAAM,EAAE,QAAQ,IAAI,QAAS,SAAU;AACvC,YAAM,SAAS;AAAA,QACd;AAAA,QACA,WACG,EAAE,MAAM,SAAS,MAAM,MAAM,SAAS,KAAK,IAC3C;AAAA,MACJ;AAEA,UAAK,CAAE,OAAQ;AACd,cAAMA,QAAO,QAAS,QAAQ,QAAS;AAEvC,cAAMC,eAAc,OAAO,eAAeD,MAAK;AAC/C,cAAME,eAAc,OAAO,eAAeF,MAAK;AAC/C,YAAIG,UAAS,OAAO;AACpB,YAAKF,cAAc;AAClB,UAAAE,UAAS,OAAO;AAAA,QACjB,WAAYD,cAAc;AACzB,UAAAC,UAAS,OAAO;AAAA,QACjB;AAEA,eAAO;AAAA,UACN,QAAAA;AAAA,UACA,aAAAF;AAAA,UACA,aAAAC;AAAA,UACA,WAAW,OAAO,eAAe,OAAO;AAAA,UACxC,SAASF,MAAK,eAAeA,MAAK;AAAA,QACnC;AAAA,MACD;AAEA,YAAM,OAAO,QAAS,QAAQ,UAAU,EAAG;AAC3C,YAAM,SAAS,QAAS,UAAU,UAAU,EAAG;AAC/C,YAAM,UAAU,QAAS,UAAU,UAAU,EAAG;AAChD,YAAM,cACL,KAAK,eACL,OAAO,eACP,OAAO,eACP,QAAQ;AACT,YAAM,cACL,KAAK,eACL,OAAO,eACP,OAAO,eACP,QAAQ;AAET,UAAI,SAAS,OAAO;AACpB,UAAK,aAAc;AAClB,iBAAS,OAAO;AAAA,MACjB,WAAY,aAAc;AACzB,iBAAS,OAAO;AAAA,MACjB;AACA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,eAAe,KAAK;AAAA,QAC7B,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,QAAQ;AAAA,MACnC;AAAA,IACD;AAAA,IACA,CAAE,kBAAkB,EAAG;AAAA,EACxB;AACD;AAEA,IAAO,mCAAQ;AAER,SAAS,qCACf,UACA,IACC;AACD,aAAY,gDAAgD;AAAA,IAC3D,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,uBAAwB,UAAU,EAAG;AAC7C;",
6
+ "names": ["read", "isResolving", "hasResolved", "status"]
7
+ }
@@ -1,49 +1,40 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createReduxStore, register } from '@wordpress/data';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import reducer from './reducer';
10
- import * as selectors from './selectors';
11
- import * as privateSelectors from './private-selectors';
12
- import * as actions from './actions';
13
- import * as privateActions from './private-actions';
14
- import * as resolvers from './resolvers';
15
- import createLocksActions from './locks/actions';
16
- import { rootEntitiesConfig, additionalEntityConfigLoaders, getMethodName } from './entities';
17
- import { STORE_NAME } from './name';
18
- import { unlock } from './lock-unlock';
19
- import { dynamicActions, dynamicSelectors } from './dynamic-entities';
20
- import logEntityDeprecation from './utils/log-entity-deprecation';
21
-
22
- // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
23
- // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
24
- // Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
25
- // The "kind" and the "name" of the entity are combined to generate these shortcuts.
26
- const entitiesConfig = [...rootEntitiesConfig, ...additionalEntityConfigLoaders.filter(config => !!config.name)];
1
+ import { createReduxStore, register } from "@wordpress/data";
2
+ import reducer from "./reducer";
3
+ import * as selectors from "./selectors";
4
+ import * as privateSelectors from "./private-selectors";
5
+ import * as actions from "./actions";
6
+ import * as privateActions from "./private-actions";
7
+ import * as resolvers from "./resolvers";
8
+ import createLocksActions from "./locks/actions";
9
+ import {
10
+ rootEntitiesConfig,
11
+ additionalEntityConfigLoaders,
12
+ getMethodName
13
+ } from "./entities";
14
+ import { STORE_NAME } from "./name";
15
+ import { unlock } from "./lock-unlock";
16
+ import { dynamicActions, dynamicSelectors } from "./dynamic-entities";
17
+ import logEntityDeprecation from "./utils/log-entity-deprecation";
18
+ const entitiesConfig = [
19
+ ...rootEntitiesConfig,
20
+ ...additionalEntityConfigLoaders.filter((config) => !!config.name)
21
+ ];
27
22
  const entitySelectors = entitiesConfig.reduce((result, entity) => {
28
- const {
29
- kind,
30
- name,
31
- plural
32
- } = entity;
23
+ const { kind, name, plural } = entity;
33
24
  const getEntityRecordMethodName = getMethodName(kind, name);
34
25
  result[getEntityRecordMethodName] = (state, key, query) => {
35
26
  logEntityDeprecation(kind, name, getEntityRecordMethodName, {
36
27
  isShorthandSelector: true,
37
- alternativeFunctionName: 'getEntityRecord'
28
+ alternativeFunctionName: "getEntityRecord"
38
29
  });
39
30
  return selectors.getEntityRecord(state, kind, name, key, query);
40
31
  };
41
32
  if (plural) {
42
- const getEntityRecordsMethodName = getMethodName(kind, plural, 'get');
33
+ const getEntityRecordsMethodName = getMethodName(kind, plural, "get");
43
34
  result[getEntityRecordsMethodName] = (state, query) => {
44
35
  logEntityDeprecation(kind, name, getEntityRecordsMethodName, {
45
36
  isShorthandSelector: true,
46
- alternativeFunctionName: 'getEntityRecords'
37
+ alternativeFunctionName: "getEntityRecords"
47
38
  });
48
39
  return selectors.getEntityRecords(state, kind, name, query);
49
40
  };
@@ -51,50 +42,43 @@ const entitySelectors = entitiesConfig.reduce((result, entity) => {
51
42
  return result;
52
43
  }, {});
53
44
  const entityResolvers = entitiesConfig.reduce((result, entity) => {
54
- const {
55
- kind,
56
- name,
57
- plural
58
- } = entity;
45
+ const { kind, name, plural } = entity;
59
46
  const getEntityRecordMethodName = getMethodName(kind, name);
60
47
  result[getEntityRecordMethodName] = (key, query) => {
61
48
  logEntityDeprecation(kind, name, getEntityRecordMethodName, {
62
49
  isShorthandSelector: true,
63
- alternativeFunctionName: 'getEntityRecord'
50
+ alternativeFunctionName: "getEntityRecord"
64
51
  });
65
52
  return resolvers.getEntityRecord(kind, name, key, query);
66
53
  };
67
54
  if (plural) {
68
- const getEntityRecordsMethodName = getMethodName(kind, plural, 'get');
55
+ const getEntityRecordsMethodName = getMethodName(kind, plural, "get");
69
56
  result[getEntityRecordsMethodName] = (...args) => {
70
57
  logEntityDeprecation(kind, plural, getEntityRecordsMethodName, {
71
58
  isShorthandSelector: true,
72
- alternativeFunctionName: 'getEntityRecords'
59
+ alternativeFunctionName: "getEntityRecords"
73
60
  });
74
61
  return resolvers.getEntityRecords(kind, name, ...args);
75
62
  };
76
- result[getEntityRecordsMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
63
+ result[getEntityRecordsMethodName].shouldInvalidate = (action) => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
77
64
  }
78
65
  return result;
79
66
  }, {});
80
67
  const entityActions = entitiesConfig.reduce((result, entity) => {
81
- const {
82
- kind,
83
- name
84
- } = entity;
85
- const saveEntityRecordMethodName = getMethodName(kind, name, 'save');
68
+ const { kind, name } = entity;
69
+ const saveEntityRecordMethodName = getMethodName(kind, name, "save");
86
70
  result[saveEntityRecordMethodName] = (record, options) => {
87
71
  logEntityDeprecation(kind, name, saveEntityRecordMethodName, {
88
72
  isShorthandSelector: true,
89
- alternativeFunctionName: 'saveEntityRecord'
73
+ alternativeFunctionName: "saveEntityRecord"
90
74
  });
91
75
  return actions.saveEntityRecord(kind, name, record, options);
92
76
  };
93
- const deleteEntityRecordMethodName = getMethodName(kind, name, 'delete');
77
+ const deleteEntityRecordMethodName = getMethodName(kind, name, "delete");
94
78
  result[deleteEntityRecordMethodName] = (key, query, options) => {
95
79
  logEntityDeprecation(kind, name, deleteEntityRecordMethodName, {
96
80
  isShorthandSelector: true,
97
- alternativeFunctionName: 'deleteEntityRecord'
81
+ alternativeFunctionName: "deleteEntityRecord"
98
82
  });
99
83
  return actions.deleteEntityRecord(kind, name, key, query, options);
100
84
  };
@@ -113,26 +97,20 @@ const storeConfig = () => ({
113
97
  ...selectors,
114
98
  ...entitySelectors
115
99
  },
116
- resolvers: {
117
- ...resolvers,
118
- ...entityResolvers
119
- }
100
+ resolvers: { ...resolvers, ...entityResolvers }
120
101
  });
121
-
122
- /**
123
- * Store definition for the code data namespace.
124
- *
125
- * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
126
- */
127
- export const store = createReduxStore(STORE_NAME, storeConfig());
102
+ const store = createReduxStore(STORE_NAME, storeConfig());
128
103
  unlock(store).registerPrivateSelectors(privateSelectors);
129
104
  unlock(store).registerPrivateActions(privateActions);
130
- register(store); // Register store after unlocking private selectors to allow resolvers to use them.
131
-
132
- export { default as EntityProvider } from './entity-provider';
133
- export * from './entity-provider';
134
- export * from './entity-types';
135
- export * from './fetch';
136
- export * from './hooks';
137
- export * from './private-apis';
138
- //# sourceMappingURL=index.js.map
105
+ register(store);
106
+ import { default as default2 } from "./entity-provider";
107
+ export * from "./entity-provider";
108
+ export * from "./entity-types";
109
+ export * from "./fetch";
110
+ export * from "./hooks";
111
+ export * from "./private-apis";
112
+ export {
113
+ default2 as EntityProvider,
114
+ store
115
+ };
116
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createReduxStore","register","reducer","selectors","privateSelectors","actions","privateActions","resolvers","createLocksActions","rootEntitiesConfig","additionalEntityConfigLoaders","getMethodName","STORE_NAME","unlock","dynamicActions","dynamicSelectors","logEntityDeprecation","entitiesConfig","filter","config","name","entitySelectors","reduce","result","entity","kind","plural","getEntityRecordMethodName","state","key","query","isShorthandSelector","alternativeFunctionName","getEntityRecord","getEntityRecordsMethodName","getEntityRecords","entityResolvers","args","shouldInvalidate","action","entityActions","saveEntityRecordMethodName","record","options","saveEntityRecord","deleteEntityRecordMethodName","deleteEntityRecord","storeConfig","store","registerPrivateSelectors","registerPrivateActions","default","EntityProvider"],"sources":["@wordpress/core-data/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,gBAAgB,MAAM,qBAAqB;AACvD,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAOC,kBAAkB,MAAM,iBAAiB;AAChD,SACCC,kBAAkB,EAClBC,6BAA6B,EAC7BC,aAAa,QACP,YAAY;AACnB,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB;AACrE,OAAOC,oBAAoB,MAAM,gCAAgC;;AAEjE;AACA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,CACtB,GAAGR,kBAAkB,EACrB,GAAGC,6BAA6B,CAACQ,MAAM,CAAIC,MAAM,IAAM,CAAC,CAAEA,MAAM,CAACC,IAAK,CAAC,CACvE;AAED,MAAMC,eAAe,GAAGJ,cAAc,CAACK,MAAM,CAAE,CAAEC,MAAM,EAAEC,MAAM,KAAM;EACpE,MAAM;IAAEC,IAAI;IAAEL,IAAI;IAAEM;EAAO,CAAC,GAAGF,MAAM;EAErC,MAAMG,yBAAyB,GAAGhB,aAAa,CAAEc,IAAI,EAAEL,IAAK,CAAC;EAC7DG,MAAM,CAAEI,yBAAyB,CAAE,GAAG,CAAEC,KAAK,EAAEC,GAAG,EAAEC,KAAK,KAAM;IAC9Dd,oBAAoB,CAAES,IAAI,EAAEL,IAAI,EAAEO,yBAAyB,EAAE;MAC5DI,mBAAmB,EAAE,IAAI;MACzBC,uBAAuB,EAAE;IAC1B,CAAE,CAAC;IAC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IACnE3B,oBAAoB,CAAES,IAAI,EAAEL,IAAI,EAAEyB,4BAA4B,EAAE;MAC/Dd,mBAAmB,EAAE,IAAI;MACzBC,uBAAuB,EAAE;IAC1B,CAAE,CAAC;IACH,OAAO3B,OAAO,CAACyC,kBAAkB,CAAErB,IAAI,EAAEL,IAAI,EAAES,GAAG,EAAEC,KAAK,EAAEa,OAAQ,CAAC;EACrE,CAAC;EAED,OAAOpB,MAAM;AACd,CAAC,EAAE,CAAC,CAAE,CAAC;AAEP,MAAMwB,WAAW,GAAGA,CAAA,MAAQ;EAC3B7C,OAAO;EACPG,OAAO,EAAE;IACR,GAAGS,cAAc;IACjB,GAAGT,OAAO;IACV,GAAGmC,aAAa;IAChB,GAAGhC,kBAAkB,CAAC;EACvB,CAAC;EACDL,SAAS,EAAE;IACV,GAAGY,gBAAgB;IACnB,GAAGZ,SAAS;IACZ,GAAGkB;EACJ,CAAC;EACDd,SAAS,EAAE;IAAE,GAAGA,SAAS;IAAE,GAAG6B;EAAgB;AAC/C,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMY,KAAK,GAAGhD,gBAAgB,CAAEY,UAAU,EAAEmC,WAAW,CAAC,CAAE,CAAC;AAClElC,MAAM,CAAEmC,KAAM,CAAC,CAACC,wBAAwB,CAAE7C,gBAAiB,CAAC;AAC5DS,MAAM,CAAEmC,KAAM,CAAC,CAACE,sBAAsB,CAAE5C,cAAe,CAAC;AACxDL,QAAQ,CAAE+C,KAAM,CAAC,CAAC,CAAC;;AAEnB,SAASG,OAAO,IAAIC,cAAc,QAAQ,mBAAmB;AAC7D,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,gBAAgB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\n"],
5
+ "mappings": "AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,aAAa;AACzB,YAAY,oBAAoB;AAChC,YAAY,eAAe;AAC3B,OAAO,wBAAwB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,gBAAgB,wBAAwB;AACjD,OAAO,0BAA0B;AAMjC,MAAM,iBAAiB;AAAA,EACtB,GAAG;AAAA,EACH,GAAG,8BAA8B,OAAQ,CAAE,WAAY,CAAC,CAAE,OAAO,IAAK;AACvE;AAEA,MAAM,kBAAkB,eAAe,OAAQ,CAAE,QAAQ,WAAY;AACpE,QAAM,EAAE,MAAM,MAAM,OAAO,IAAI;AAE/B,QAAM,4BAA4B,cAAe,MAAM,IAAK;AAC5D,SAAQ,yBAA0B,IAAI,CAAE,OAAO,KAAK,UAAW;AAC9D,yBAAsB,MAAM,MAAM,2BAA2B;AAAA,MAC5D,qBAAqB;AAAA,MACrB,yBAAyB;AAAA,IAC1B,CAAE;AACF,WAAO,UAAU,gBAAiB,OAAO,MAAM,MAAM,KAAK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AAE,QAAQ,YAAa;AAC7D,yBAAsB,MAAM,MAAM,4BAA4B;AAAA,MAC7D,qBAAqB;AAAA,MACrB,yBAAyB;AAAA,IAC1B,CAAE;AACF,WAAO,QAAQ,iBAAkB,MAAM,MAAM,QAAQ,OAAQ;AAAA,EAC9D;AAEA,QAAM,+BAA+B,cAAe,MAAM,MAAM,QAAS;AACzE,SAAQ,4BAA6B,IAAI,CAAE,KAAK,OAAO,YAAa;AACnE,yBAAsB,MAAM,MAAM,8BAA8B;AAAA,MAC/D,qBAAqB;AAAA,MACrB,yBAAyB;AAAA,IAC1B,CAAE;AACF,WAAO,QAAQ,mBAAoB,MAAM,MAAM,KAAK,OAAO,OAAQ;AAAA,EACpE;AAEA,SAAO;AACR,GAAG,CAAC,CAAE;AAEN,MAAM,cAAc,OAAQ;AAAA,EAC3B;AAAA,EACA,SAAS;AAAA,IACR,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG,mBAAmB;AAAA,EACvB;AAAA,EACA,WAAW;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AAAA,EACA,WAAW,EAAE,GAAG,WAAW,GAAG,gBAAgB;AAC/C;AAOO,MAAM,QAAQ,iBAAkB,YAAY,YAAY,CAAE;AACjE,OAAQ,KAAM,EAAE,yBAA0B,gBAAiB;AAC3D,OAAQ,KAAM,EAAE,uBAAwB,cAAe;AACvD,SAAU,KAAM;AAEhB,SAAoB,WAAXA,gBAAiC;AAC1C,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": ["default"]
7
+ }
@@ -1,9 +1,10 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
5
- export const {
1
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
2
+ const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
3
+ "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
4
+ "@wordpress/core-data"
5
+ );
6
+ export {
6
7
  lock,
7
8
  unlock
8
- } = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/core-data');
9
- //# sourceMappingURL=lock-unlock.js.map
9
+ };
10
+ //# sourceMappingURL=lock-unlock.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/core-data/src/lock-unlock.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/core-data'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAE1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,+HAA+H,EAC/H,sBACD,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lock-unlock.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/core-data'\n\t);\n"],
5
+ "mappings": "AAGA,SAAS,wDAAwD;AAE1D,MAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
6
+ "names": []
7
+ }
@@ -1,20 +1,15 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import createLocks from './engine';
5
- export default function createLocksActions() {
1
+ import createLocks from "./engine";
2
+ function createLocksActions() {
6
3
  const locks = createLocks();
7
- function __unstableAcquireStoreLock(store, path, {
8
- exclusive
9
- }) {
4
+ function __unstableAcquireStoreLock(store, path, { exclusive }) {
10
5
  return () => locks.acquire(store, path, exclusive);
11
6
  }
12
7
  function __unstableReleaseStoreLock(lock) {
13
8
  return () => locks.release(lock);
14
9
  }
15
- return {
16
- __unstableAcquireStoreLock,
17
- __unstableReleaseStoreLock
18
- };
10
+ return { __unstableAcquireStoreLock, __unstableReleaseStoreLock };
19
11
  }
20
- //# sourceMappingURL=actions.js.map
12
+ export {
13
+ createLocksActions as default
14
+ };
15
+ //# sourceMappingURL=actions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"sources":["@wordpress/core-data/src/locks/actions.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,UAAU;AAElC,eAAe,SAASC,kBAAkBA,CAAA,EAAG;EAC5C,MAAMC,KAAK,GAAGF,WAAW,CAAC,CAAC;EAE3B,SAASG,0BAA0BA,CAAEC,KAAK,EAAEC,IAAI,EAAE;IAAEC;EAAU,CAAC,EAAG;IACjE,OAAO,MAAMJ,KAAK,CAACK,OAAO,CAAEH,KAAK,EAAEC,IAAI,EAAEC,SAAU,CAAC;EACrD;EAEA,SAASE,0BAA0BA,CAAEC,IAAI,EAAG;IAC3C,OAAO,MAAMP,KAAK,CAACQ,OAAO,CAAED,IAAK,CAAC;EACnC;EAEA,OAAO;IAAEN,0BAA0B;IAAEK;EAA2B,CAAC;AAClE","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/locks/actions.js"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"],
5
+ "mappings": "AAGA,OAAO,iBAAiB;AAET,SAAR,qBAAsC;AAC5C,QAAM,QAAQ,YAAY;AAE1B,WAAS,2BAA4B,OAAO,MAAM,EAAE,UAAU,GAAI;AACjE,WAAO,MAAM,MAAM,QAAS,OAAO,MAAM,SAAU;AAAA,EACpD;AAEA,WAAS,2BAA4B,MAAO;AAC3C,WAAO,MAAM,MAAM,QAAS,IAAK;AAAA,EAClC;AAEA,SAAO,EAAE,4BAA4B,2BAA2B;AACjE;",
6
+ "names": []
7
+ }
@@ -1,30 +1,14 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import reducer from './reducer';
5
- import { isLockAvailable, getPendingLockRequests } from './selectors';
6
- export default function createLocks() {
7
- let state = reducer(undefined, {
8
- type: '@@INIT'
9
- });
1
+ import reducer from "./reducer";
2
+ import { isLockAvailable, getPendingLockRequests } from "./selectors";
3
+ function createLocks() {
4
+ let state = reducer(void 0, { type: "@@INIT" });
10
5
  function processPendingLockRequests() {
11
6
  for (const request of getPendingLockRequests(state)) {
12
- const {
13
- store,
14
- path,
15
- exclusive,
16
- notifyAcquired
17
- } = request;
18
- if (isLockAvailable(state, store, path, {
19
- exclusive
20
- })) {
21
- const lock = {
22
- store,
23
- path,
24
- exclusive
25
- };
7
+ const { store, path, exclusive, notifyAcquired } = request;
8
+ if (isLockAvailable(state, store, path, { exclusive })) {
9
+ const lock = { store, path, exclusive };
26
10
  state = reducer(state, {
27
- type: 'GRANT_LOCK_REQUEST',
11
+ type: "GRANT_LOCK_REQUEST",
28
12
  lock,
29
13
  request
30
14
  });
@@ -33,29 +17,24 @@ export default function createLocks() {
33
17
  }
34
18
  }
35
19
  function acquire(store, path, exclusive) {
36
- return new Promise(resolve => {
20
+ return new Promise((resolve) => {
37
21
  state = reducer(state, {
38
- type: 'ENQUEUE_LOCK_REQUEST',
39
- request: {
40
- store,
41
- path,
42
- exclusive,
43
- notifyAcquired: resolve
44
- }
22
+ type: "ENQUEUE_LOCK_REQUEST",
23
+ request: { store, path, exclusive, notifyAcquired: resolve }
45
24
  });
46
25
  processPendingLockRequests();
47
26
  });
48
27
  }
49
28
  function release(lock) {
50
29
  state = reducer(state, {
51
- type: 'RELEASE_LOCK',
30
+ type: "RELEASE_LOCK",
52
31
  lock
53
32
  });
54
33
  processPendingLockRequests();
55
34
  }
56
- return {
57
- acquire,
58
- release
59
- };
35
+ return { acquire, release };
60
36
  }
61
- //# sourceMappingURL=engine.js.map
37
+ export {
38
+ createLocks as default
39
+ };
40
+ //# sourceMappingURL=engine.js.map