@wordpress/core-data 4.13.0 → 5.0.1-next.957ca95e4c.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 (201) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +148 -65
  3. package/build/entities.js +38 -51
  4. package/build/entities.js.map +1 -1
  5. package/build/hooks/index.js +14 -0
  6. package/build/hooks/index.js.map +1 -1
  7. package/build/hooks/use-entity-record.js +10 -6
  8. package/build/hooks/use-entity-record.js.map +1 -1
  9. package/build/hooks/use-entity-records.js +2 -0
  10. package/build/hooks/use-entity-records.js.map +1 -1
  11. package/build/hooks/use-query-select.js +5 -2
  12. package/build/hooks/use-query-select.js.map +1 -1
  13. package/build/hooks/use-resource-permissions.js +74 -11
  14. package/build/hooks/use-resource-permissions.js.map +1 -1
  15. package/build/index.js +1 -30
  16. package/build/index.js.map +1 -1
  17. package/build/resolvers.js +17 -21
  18. package/build/resolvers.js.map +1 -1
  19. package/build/selectors.js +9 -46
  20. package/build/selectors.js.map +1 -1
  21. package/build-module/entities.js +38 -52
  22. package/build-module/entities.js.map +1 -1
  23. package/build-module/hooks/index.js +1 -0
  24. package/build-module/hooks/index.js.map +1 -1
  25. package/build-module/hooks/use-entity-record.js +10 -6
  26. package/build-module/hooks/use-entity-record.js.map +1 -1
  27. package/build-module/hooks/use-entity-records.js +2 -0
  28. package/build-module/hooks/use-entity-records.js.map +1 -1
  29. package/build-module/hooks/use-query-select.js +4 -1
  30. package/build-module/hooks/use-query-select.js.map +1 -1
  31. package/build-module/hooks/use-resource-permissions.js +70 -10
  32. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  33. package/build-module/index.js +0 -5
  34. package/build-module/index.js.map +1 -1
  35. package/build-module/resolvers.js +17 -21
  36. package/build-module/resolvers.js.map +1 -1
  37. package/build-module/selectors.js +7 -44
  38. package/build-module/selectors.js.map +1 -1
  39. package/build-types/actions.d.ts +188 -0
  40. package/build-types/actions.d.ts.map +1 -0
  41. package/build-types/batch/create-batch.d.ts +71 -0
  42. package/build-types/batch/create-batch.d.ts.map +1 -0
  43. package/build-types/batch/default-processor.d.ts +11 -0
  44. package/build-types/batch/default-processor.d.ts.map +1 -0
  45. package/build-types/batch/index.d.ts +3 -0
  46. package/build-types/batch/index.d.ts.map +1 -0
  47. package/build-types/entities.d.ts +128 -0
  48. package/build-types/entities.d.ts.map +1 -0
  49. package/build-types/entity-provider.d.ts +68 -0
  50. package/build-types/entity-provider.d.ts.map +1 -0
  51. package/build-types/entity-types/attachment.d.ts +121 -0
  52. package/build-types/entity-types/attachment.d.ts.map +1 -0
  53. package/build-types/entity-types/base-entity-records.d.ts +37 -0
  54. package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
  55. package/build-types/entity-types/comment.d.ts +82 -0
  56. package/build-types/entity-types/comment.d.ts.map +1 -0
  57. package/build-types/entity-types/helpers.d.ts +123 -0
  58. package/build-types/entity-types/helpers.d.ts.map +1 -0
  59. package/build-types/entity-types/index.d.ts +64 -0
  60. package/build-types/entity-types/index.d.ts.map +1 -0
  61. package/build-types/entity-types/menu-location.d.ts +25 -0
  62. package/build-types/entity-types/menu-location.d.ts.map +1 -0
  63. package/build-types/entity-types/nav-menu-item.d.ts +88 -0
  64. package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
  65. package/build-types/entity-types/nav-menu.d.ts +45 -0
  66. package/build-types/entity-types/nav-menu.d.ts.map +1 -0
  67. package/build-types/entity-types/page.d.ts +120 -0
  68. package/build-types/entity-types/page.d.ts.map +1 -0
  69. package/build-types/entity-types/plugin.d.ts +62 -0
  70. package/build-types/entity-types/plugin.d.ts.map +1 -0
  71. package/build-types/entity-types/post.d.ts +128 -0
  72. package/build-types/entity-types/post.d.ts.map +1 -0
  73. package/build-types/entity-types/settings.d.ts +89 -0
  74. package/build-types/entity-types/settings.d.ts.map +1 -0
  75. package/build-types/entity-types/sidebar.d.ts +55 -0
  76. package/build-types/entity-types/sidebar.d.ts.map +1 -0
  77. package/build-types/entity-types/taxonomy.d.ts +83 -0
  78. package/build-types/entity-types/taxonomy.d.ts.map +1 -0
  79. package/build-types/entity-types/theme.d.ts +206 -0
  80. package/build-types/entity-types/theme.d.ts.map +1 -0
  81. package/build-types/entity-types/type.d.ts +71 -0
  82. package/build-types/entity-types/type.d.ts.map +1 -0
  83. package/build-types/entity-types/user.d.ts +93 -0
  84. package/build-types/entity-types/user.d.ts.map +1 -0
  85. package/build-types/entity-types/widget-type.d.ts +33 -0
  86. package/build-types/entity-types/widget-type.d.ts.map +1 -0
  87. package/build-types/entity-types/widget.d.ts +59 -0
  88. package/build-types/entity-types/widget.d.ts.map +1 -0
  89. package/build-types/entity-types/wp-template-part.d.ts +80 -0
  90. package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
  91. package/build-types/entity-types/wp-template.d.ts +80 -0
  92. package/build-types/entity-types/wp-template.d.ts.map +1 -0
  93. package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
  94. package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
  95. package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
  96. package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
  97. package/build-types/fetch/index.d.ts +3 -0
  98. package/build-types/fetch/index.d.ts.map +1 -0
  99. package/build-types/hooks/constants.d.ts +7 -0
  100. package/build-types/hooks/constants.d.ts.map +1 -0
  101. package/build-types/hooks/index.d.ts +4 -0
  102. package/build-types/hooks/index.d.ts.map +1 -0
  103. package/build-types/hooks/memoize.d.ts +3 -0
  104. package/build-types/hooks/memoize.d.ts.map +1 -0
  105. package/build-types/hooks/use-entity-record.d.ts +124 -0
  106. package/build-types/hooks/use-entity-record.d.ts.map +1 -0
  107. package/build-types/hooks/use-entity-records.d.ts +49 -0
  108. package/build-types/hooks/use-entity-records.d.ts.map +1 -0
  109. package/build-types/hooks/use-query-select.d.ts +46 -0
  110. package/build-types/hooks/use-query-select.d.ts.map +1 -0
  111. package/build-types/hooks/use-resource-permissions.d.ts +99 -0
  112. package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
  113. package/build-types/index.d.ts +131 -0
  114. package/build-types/index.d.ts.map +1 -0
  115. package/build-types/locks/actions.d.ts +7 -0
  116. package/build-types/locks/actions.d.ts.map +1 -0
  117. package/build-types/locks/engine.d.ts +5 -0
  118. package/build-types/locks/engine.d.ts.map +1 -0
  119. package/build-types/locks/reducer.d.ts +10 -0
  120. package/build-types/locks/reducer.d.ts.map +1 -0
  121. package/build-types/locks/selectors.d.ts +5 -0
  122. package/build-types/locks/selectors.d.ts.map +1 -0
  123. package/build-types/locks/utils.d.ts +8 -0
  124. package/build-types/locks/utils.d.ts.map +1 -0
  125. package/build-types/name.d.ts +8 -0
  126. package/build-types/name.d.ts.map +1 -0
  127. package/build-types/queried-data/actions.d.ts +32 -0
  128. package/build-types/queried-data/actions.d.ts.map +1 -0
  129. package/build-types/queried-data/get-query-parts.d.ts +60 -0
  130. package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
  131. package/build-types/queried-data/index.d.ts +4 -0
  132. package/build-types/queried-data/index.d.ts.map +1 -0
  133. package/build-types/queried-data/reducer.d.ts +54 -0
  134. package/build-types/queried-data/reducer.d.ts.map +1 -0
  135. package/build-types/queried-data/selectors.d.ts +16 -0
  136. package/build-types/queried-data/selectors.d.ts.map +1 -0
  137. package/build-types/reducer.d.ts +156 -0
  138. package/build-types/reducer.d.ts.map +1 -0
  139. package/build-types/resolvers.d.ts +74 -0
  140. package/build-types/resolvers.d.ts.map +1 -0
  141. package/build-types/selectors.d.ts +524 -0
  142. package/build-types/selectors.d.ts.map +1 -0
  143. package/build-types/types.d.ts +4 -0
  144. package/build-types/types.d.ts.map +1 -0
  145. package/build-types/utils/conservative-map-item.d.ts +12 -0
  146. package/build-types/utils/conservative-map-item.d.ts.map +1 -0
  147. package/build-types/utils/forward-resolver.d.ts +10 -0
  148. package/build-types/utils/forward-resolver.d.ts.map +1 -0
  149. package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
  150. package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
  151. package/build-types/utils/if-matching-action.d.ts +14 -0
  152. package/build-types/utils/if-matching-action.d.ts.map +1 -0
  153. package/build-types/utils/index.d.ts +9 -0
  154. package/build-types/utils/index.d.ts.map +1 -0
  155. package/build-types/utils/is-raw-attribute.d.ts +10 -0
  156. package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
  157. package/build-types/utils/on-sub-key.d.ts +4 -0
  158. package/build-types/utils/on-sub-key.d.ts.map +1 -0
  159. package/build-types/utils/replace-action.d.ts +13 -0
  160. package/build-types/utils/replace-action.d.ts.map +1 -0
  161. package/build-types/utils/with-weak-map-cache.d.ts +12 -0
  162. package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
  163. package/package.json +13 -11
  164. package/src/entities.js +325 -0
  165. package/src/entity-types/attachment.ts +3 -4
  166. package/src/entity-types/comment.ts +3 -4
  167. package/src/entity-types/index.ts +31 -88
  168. package/src/entity-types/menu-location.ts +3 -4
  169. package/src/entity-types/nav-menu-item.ts +3 -4
  170. package/src/entity-types/nav-menu.ts +3 -3
  171. package/src/entity-types/page.ts +3 -3
  172. package/src/entity-types/plugin.ts +3 -3
  173. package/src/entity-types/post.ts +3 -3
  174. package/src/entity-types/settings.ts +3 -3
  175. package/src/entity-types/sidebar.ts +3 -4
  176. package/src/entity-types/taxonomy.ts +3 -4
  177. package/src/entity-types/theme.ts +7 -3
  178. package/src/entity-types/type.ts +3 -3
  179. package/src/entity-types/user.ts +3 -3
  180. package/src/entity-types/widget-type.ts +3 -4
  181. package/src/entity-types/widget.ts +3 -3
  182. package/src/entity-types/wp-template-part.ts +3 -4
  183. package/src/entity-types/wp-template.ts +3 -4
  184. package/src/hooks/index.ts +4 -0
  185. package/src/hooks/test/use-entity-record.js +41 -1
  186. package/src/hooks/test/use-resource-permissions.js +32 -36
  187. package/src/hooks/use-entity-record.ts +18 -6
  188. package/src/hooks/use-entity-records.ts +2 -0
  189. package/src/hooks/use-query-select.ts +4 -1
  190. package/src/hooks/use-resource-permissions.ts +84 -20
  191. package/src/index.js +0 -5
  192. package/src/resolvers.js +36 -24
  193. package/src/selectors.ts +202 -341
  194. package/tsconfig.json +21 -0
  195. package/tsconfig.tsbuildinfo +1 -0
  196. package/build/entity-types/entities.js +0 -6
  197. package/build/entity-types/entities.js.map +0 -1
  198. package/build-module/entity-types/entities.js +0 -2
  199. package/build-module/entity-types/entities.js.map +0 -1
  200. package/src/entities.ts +0 -548
  201. package/src/entity-types/entities.ts +0 -130
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.0.0-next.0 (2022-08-29)
6
+
7
+ ### Breaking Changes
8
+
9
+ – Add TypeScript types to the built package (via "types": "build-types" in the package.json)
10
+
11
+ ## 4.14.0 (2022-08-24)
12
+
13
+ ### New Features
14
+
15
+ - Stabilized the `useResourcePermissions` hook ([#43268](https://github.com/WordPress/gutenberg/pull/43268))
16
+
5
17
  ## 4.13.0 (2022-08-10)
6
18
 
7
19
  ## 4.12.0 (2022-07-27)
package/README.md CHANGED
@@ -189,7 +189,7 @@ _Parameters_
189
189
  - _state_ `State`: Data state.
190
190
  - _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
191
191
  - _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'.
192
- - _id_ `GenericRecordKey`: Optional ID of the rest resource to check.
192
+ - _id_ `EntityRecordKey`: Optional ID of the rest resource to check.
193
193
 
194
194
  _Returns_
195
195
 
@@ -207,9 +207,9 @@ Calling this may trigger an OPTIONS request to the REST API via the
207
207
  _Parameters_
208
208
 
209
209
  - _state_ `State`: Data state.
210
- - _kind_ `Kind`: Entity kind.
211
- - _name_ `Name`: Entity name.
212
- - _recordId_ `GenericRecordKey`: Record's id.
210
+ - _kind_ `string`: Entity kind.
211
+ - _name_ `string`: Entity name.
212
+ - _recordId_ `EntityRecordKey`: Record's id.
213
213
 
214
214
  _Returns_
215
215
 
@@ -224,11 +224,11 @@ Returns all available authors.
224
224
  _Parameters_
225
225
 
226
226
  - _state_ `State`: Data state.
227
- - _query_ `EntityQuery< any >`: Optional object of query parameters to include with request.
227
+ - _query_ `GetRecordsHttpQuery`: Optional object of query parameters to include with request.
228
228
 
229
229
  _Returns_
230
230
 
231
- - `User< 'edit' >[]`: Authors list.
231
+ - `ET.User[]`: Authors list.
232
232
 
233
233
  ### getAutosave
234
234
 
@@ -238,8 +238,8 @@ _Parameters_
238
238
 
239
239
  - _state_ `State`: State tree.
240
240
  - _postType_ `string`: The type of the parent post.
241
- - _postId_ `GenericRecordKey`: The id of the parent post.
242
- - _authorId_ `GenericRecordKey`: The id of the author.
241
+ - _postId_ `EntityRecordKey`: The id of the parent post.
242
+ - _authorId_ `EntityRecordKey`: The id of the author.
243
243
 
244
244
  _Returns_
245
245
 
@@ -256,7 +256,7 @@ _Parameters_
256
256
 
257
257
  - _state_ `State`: State tree.
258
258
  - _postType_ `string`: The type of the parent post.
259
- - _postId_ `GenericRecordKey`: The id of the parent post.
259
+ - _postId_ `EntityRecordKey`: The id of the parent post.
260
260
 
261
261
  _Returns_
262
262
 
@@ -308,7 +308,7 @@ _Parameters_
308
308
 
309
309
  _Returns_
310
310
 
311
- - `User< 'edit' >`: Current user object.
311
+ - `undefined< 'edit' >`: Current user object.
312
312
 
313
313
  ### getEditedEntityRecord
314
314
 
@@ -317,13 +317,13 @@ Returns the specified entity record, merged with its edits.
317
317
  _Parameters_
318
318
 
319
319
  - _state_ `State`: State tree.
320
- - _kind_ `K`: Entity kind.
321
- - _name_ `N`: Entity name.
322
- - _recordId_ `KeyOf< K, N >`: Record ID.
320
+ - _kind_ `string`: Entity kind.
321
+ - _name_ `string`: Entity name.
322
+ - _recordId_ `EntityRecordKey`: Record ID.
323
323
 
324
324
  _Returns_
325
325
 
326
- - `EntityRecord | undefined`: The entity record, merged with its edits.
326
+ - `undefined< EntityRecord > | undefined`: The entity record, merged with its edits.
327
327
 
328
328
  ### getEmbedPreview
329
329
 
@@ -347,7 +347,7 @@ Returns the loaded entities for the given kind.
347
347
  _Parameters_
348
348
 
349
349
  - _state_ `State`: Data state.
350
- - _kind_ `Kind`: Entity kind.
350
+ - _kind_ `string`: Entity kind.
351
351
 
352
352
  _Returns_
353
353
 
@@ -360,7 +360,7 @@ Returns the loaded entities for the given kind.
360
360
  _Parameters_
361
361
 
362
362
  - _state_ `State`: Data state.
363
- - _kind_ `Kind`: Entity kind.
363
+ - _kind_ `string`: Entity kind.
364
364
 
365
365
  _Returns_
366
366
 
@@ -375,8 +375,8 @@ Returns the entity config given its kind and name.
375
375
  _Parameters_
376
376
 
377
377
  - _state_ `State`: Data state.
378
- - _kind_ `Kind`: Entity kind.
379
- - _name_ `Name`: Entity name.
378
+ - _kind_ `string`: Entity kind.
379
+ - _name_ `string`: Entity name.
380
380
 
381
381
  _Returns_
382
382
 
@@ -389,8 +389,8 @@ Returns the entity config given its kind and name.
389
389
  _Parameters_
390
390
 
391
391
  - _state_ `State`: Data state.
392
- - _kind_ `Kind`: Entity kind.
393
- - _name_ `Name`: Entity name.
392
+ - _kind_ `string`: Entity kind.
393
+ - _name_ `string`: Entity name.
394
394
 
395
395
  _Returns_
396
396
 
@@ -405,14 +405,14 @@ entity object if it exists and is received.
405
405
  _Parameters_
406
406
 
407
407
  - _state_ `State`: State tree
408
- - _kind_ `K`: Entity kind.
409
- - _name_ `N`: Entity name.
410
- - _key_ `KeyOf< R >`: Record's key
411
- - _query_ Optional query. If requesting specific fields, fields must always include the ID.
408
+ - _kind_ `string`: Entity kind.
409
+ - _name_ `string`: Entity name.
410
+ - _key_ `EntityRecordKey`: Record's key
411
+ - _query_ `GetRecordsHttpQuery`: Optional query. If requesting specific fields, fields must always include the ID.
412
412
 
413
413
  _Returns_
414
414
 
415
- - Record.
415
+ - `EntityRecord | undefined`: Record.
416
416
 
417
417
  ### getEntityRecordEdits
418
418
 
@@ -421,9 +421,9 @@ Returns the specified entity record's edits.
421
421
  _Parameters_
422
422
 
423
423
  - _state_ `State`: State tree.
424
- - _kind_ `K`: Entity kind.
425
- - _name_ `N`: Entity name.
426
- - _recordId_ `KeyOf< K, N >`: Record ID.
424
+ - _kind_ `string`: Entity kind.
425
+ - _name_ `string`: Entity name.
426
+ - _recordId_ `EntityRecordKey`: Record ID.
427
427
 
428
428
  _Returns_
429
429
 
@@ -440,9 +440,9 @@ They are defined in the entity's config.
440
440
  _Parameters_
441
441
 
442
442
  - _state_ `State`: State tree.
443
- - _kind_ `K`: Entity kind.
444
- - _name_ `N`: Entity name.
445
- - _recordId_ `KeyOf< K, N >`: Record ID.
443
+ - _kind_ `string`: Entity kind.
444
+ - _name_ `string`: Entity name.
445
+ - _recordId_ `EntityRecordKey`: Record ID.
446
446
 
447
447
  _Returns_
448
448
 
@@ -455,13 +455,13 @@ Returns the Entity's records.
455
455
  _Parameters_
456
456
 
457
457
  - _state_ `State`: State tree
458
- - _kind_ `K`: Entity kind.
459
- - _name_ `N`: Entity name.
460
- - _query_ Optional terms query. If requesting specific fields, fields must always include the ID.
458
+ - _kind_ `string`: Entity kind.
459
+ - _name_ `string`: Entity name.
460
+ - _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID.
461
461
 
462
462
  _Returns_
463
463
 
464
- - Records.
464
+ - `EntityRecord[] | null`: Records.
465
465
 
466
466
  ### getLastEntityDeleteError
467
467
 
@@ -470,9 +470,9 @@ Returns the specified entity record's last delete error.
470
470
  _Parameters_
471
471
 
472
472
  - _state_ `State`: State tree.
473
- - _kind_ `Kind`: Entity kind.
474
- - _name_ `Name`: Entity name.
475
- - _recordId_ `GenericRecordKey`: Record ID.
473
+ - _kind_ `string`: Entity kind.
474
+ - _name_ `string`: Entity name.
475
+ - _recordId_ `EntityRecordKey`: Record ID.
476
476
 
477
477
  _Returns_
478
478
 
@@ -485,9 +485,9 @@ Returns the specified entity record's last save error.
485
485
  _Parameters_
486
486
 
487
487
  - _state_ `State`: State tree.
488
- - _kind_ `Kind`: Entity kind.
489
- - _name_ `Name`: Entity name.
490
- - _recordId_ `GenericRecordKey`: Record ID.
488
+ - _kind_ `string`: Entity kind.
489
+ - _name_ `string`: Entity name.
490
+ - _recordId_ `EntityRecordKey`: Record ID.
491
491
 
492
492
  _Returns_
493
493
 
@@ -501,9 +501,9 @@ with its attributes mapped to their raw values.
501
501
  _Parameters_
502
502
 
503
503
  - _state_ `State`: State tree.
504
- - _kind_ `K`: Entity kind.
505
- - _name_ `N`: Entity name.
506
- - _key_ `KeyOf< K, N >`: Record's key.
504
+ - _kind_ `string`: Entity kind.
505
+ - _name_ `string`: Entity name.
506
+ - _key_ `EntityRecordKey`: Record's key.
507
507
 
508
508
  _Returns_
509
509
 
@@ -579,7 +579,7 @@ _Parameters_
579
579
 
580
580
  _Returns_
581
581
 
582
- - `User< 'edit' >[]`: Users list.
582
+ - `undefined< 'edit' >[]`: Users list.
583
583
 
584
584
  ### hasEditsForEntityRecord
585
585
 
@@ -589,9 +589,9 @@ and false otherwise.
589
589
  _Parameters_
590
590
 
591
591
  - _state_ `State`: State tree.
592
- - _kind_ `K`: Entity kind.
593
- - _name_ `N`: Entity name.
594
- - _recordId_ `KeyOf< K, N >`: Record ID.
592
+ - _kind_ `string`: Entity kind.
593
+ - _name_ `string`: Entity name.
594
+ - _recordId_ `EntityRecordKey`: Record ID.
595
595
 
596
596
  _Returns_
597
597
 
@@ -605,9 +605,9 @@ or false otherwise.
605
605
  _Parameters_
606
606
 
607
607
  - _state_ `State`: State tree
608
- - _kind_ `K`: Entity kind.
609
- - _name_ `N`: Entity name.
610
- - _query_ `EntityQuery< C >`: Optional terms query.
608
+ - _kind_ `string`: Entity kind.
609
+ - _name_ `string`: Entity name.
610
+ - _query_ `GetRecordsHttpQuery`: Optional terms query.
611
611
 
612
612
  _Returns_
613
613
 
@@ -621,7 +621,7 @@ _Parameters_
621
621
 
622
622
  - _state_ `State`: State tree.
623
623
  - _postType_ `string`: The type of the parent post.
624
- - _postId_ `GenericRecordKey`: The id of the parent post.
624
+ - _postId_ `EntityRecordKey`: The id of the parent post.
625
625
 
626
626
  _Returns_
627
627
 
@@ -660,9 +660,9 @@ Returns true if the specified entity record is autosaving, and false otherwise.
660
660
  _Parameters_
661
661
 
662
662
  - _state_ `State`: State tree.
663
- - _kind_ `Kind`: Entity kind.
664
- - _name_ `Name`: Entity name.
665
- - _recordId_ `GenericRecordKey`: Record ID.
663
+ - _kind_ `string`: Entity kind.
664
+ - _name_ `string`: Entity name.
665
+ - _recordId_ `EntityRecordKey`: Record ID.
666
666
 
667
667
  _Returns_
668
668
 
@@ -675,9 +675,9 @@ Returns true if the specified entity record is deleting, and false otherwise.
675
675
  _Parameters_
676
676
 
677
677
  - _state_ `State`: State tree.
678
- - _kind_ `Kind`: Entity kind.
679
- - _name_ `Name`: Entity name.
680
- - _recordId_ `GenericRecordKey`: Record ID.
678
+ - _kind_ `string`: Entity kind.
679
+ - _name_ `string`: Entity name.
680
+ - _recordId_ `EntityRecordKey`: Record ID.
681
681
 
682
682
  _Returns_
683
683
 
@@ -721,9 +721,9 @@ Returns true if the specified entity record is saving, and false otherwise.
721
721
  _Parameters_
722
722
 
723
723
  - _state_ `State`: State tree.
724
- - _kind_ `K`: Entity kind.
725
- - _name_ `N`: Entity name.
726
- - _recordId_ `KeyOf< K, N >`: Record ID.
724
+ - _kind_ `string`: Entity kind.
725
+ - _name_ `string`: Entity name.
726
+ - _recordId_ `EntityRecordKey`: Record ID.
727
727
 
728
728
  _Returns_
729
729
 
@@ -765,8 +765,8 @@ application, the page and the resolution details will be retrieved from
765
765
  the store state using `getEntityRecord()`, or resolved if missing.
766
766
 
767
767
  ```js
768
- import { useState } from '@wordpress/data';
769
768
  import { useDispatch } from '@wordpress/data';
769
+ import { useCallback } from '@wordpress/element';
770
770
  import { __ } from '@wordpress/i18n';
771
771
  import { TextControl } from '@wordpress/components';
772
772
  import { store as noticeStore } from '@wordpress/notices';
@@ -774,17 +774,22 @@ import { useEntityRecord } from '@wordpress/core-data';
774
774
 
775
775
  function PageRenameForm( { id } ) {
776
776
  const page = useEntityRecord( 'postType', 'page', id );
777
- const [ title, setTitle ] = useState( () => page.record.title.rendered );
778
777
  const { createSuccessNotice, createErrorNotice } =
779
778
  useDispatch( noticeStore );
780
779
 
780
+ const setTitle = useCallback(
781
+ ( title ) => {
782
+ page.edit( { title } );
783
+ },
784
+ [ page.edit ]
785
+ );
786
+
781
787
  if ( page.isResolving ) {
782
788
  return 'Loading...';
783
789
  }
784
790
 
785
791
  async function onRename( event ) {
786
792
  event.preventDefault();
787
- page.edit( { title } );
788
793
  try {
789
794
  await page.save();
790
795
  createSuccessNotice( __( 'Page renamed.' ), {
@@ -799,7 +804,7 @@ function PageRenameForm( { id } ) {
799
804
  <form onSubmit={ onRename }>
800
805
  <TextControl
801
806
  label={ __( 'Name' ) }
802
- value={ title }
807
+ value={ page.editedRecord.title }
803
808
  onChange={ setTitle }
804
809
  />
805
810
  <button type="submit">{ __( 'Save' ) }</button>
@@ -826,6 +831,10 @@ _Returns_
826
831
 
827
832
  - `EntityRecordResolution< RecordType >`: Entity record data.
828
833
 
834
+ _Changelog_
835
+
836
+ `6.1.0` Introduced in WordPress core.
837
+
829
838
  ### useEntityRecords
830
839
 
831
840
  Resolves the specified entity records.
@@ -870,6 +879,80 @@ _Returns_
870
879
 
871
880
  - `EntityRecordsResolution< RecordType >`: Entity records data.
872
881
 
882
+ _Changelog_
883
+
884
+ `6.1.0` Introduced in WordPress core.
885
+
886
+ ### useResourcePermissions
887
+
888
+ Resolves resource permissions.
889
+
890
+ _Usage_
891
+
892
+ ```js
893
+ import { useResourcePermissions } from '@wordpress/core-data';
894
+
895
+ function PagesList() {
896
+ const { canCreate, isResolving } = useResourcePermissions( 'pages' );
897
+
898
+ if ( isResolving ) {
899
+ return 'Loading ...';
900
+ }
901
+
902
+ return (
903
+ <div>
904
+ { canCreate ? <button>+ Create a new page</button> : false }
905
+ // ...
906
+ </div>
907
+ );
908
+ }
909
+
910
+ // Rendered in the application:
911
+ // <PagesList />
912
+ ```
913
+
914
+ ```js
915
+ import { useResourcePermissions } from '@wordpress/core-data';
916
+
917
+ function Page( { pageId } ) {
918
+ const { canCreate, canUpdate, canDelete, isResolving } =
919
+ useResourcePermissions( 'pages', pageId );
920
+
921
+ if ( isResolving ) {
922
+ return 'Loading ...';
923
+ }
924
+
925
+ return (
926
+ <div>
927
+ { canCreate ? <button>+ Create a new page</button> : false }
928
+ { canUpdate ? <button>Edit page</button> : false }
929
+ { canDelete ? <button>Delete page</button> : false }
930
+ // ...
931
+ </div>
932
+ );
933
+ }
934
+
935
+ // Rendered in the application:
936
+ // <Page pageId={ 15 } />
937
+ ```
938
+
939
+ In the above example, when `PagesList` is rendered into an
940
+ application, the appropriate permissions and the resolution details will be retrieved from
941
+ the store state using `canUser()`, or resolved if missing.
942
+
943
+ _Parameters_
944
+
945
+ - _resource_ `string`: The resource in question, e.g. media.
946
+ - _id_ `IdType`: ID of a specific resource entry, if needed, e.g. 10.
947
+
948
+ _Returns_
949
+
950
+ - `ResourcePermissionsResolution< IdType >`: Entity records data.
951
+
952
+ _Changelog_
953
+
954
+ `6.1.0` Introduced in WordPress core.
955
+
873
956
  <!-- END TOKEN(Autogenerated hooks|src/hooks/index.ts) -->
874
957
 
875
958
  ## Contributing to this package
package/build/entities.js CHANGED
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.rootEntitiesConfig = exports.prePersistPostType = exports.getOrLoadEntitiesConfig = exports.getMethodName = exports.additionalEntityConfigLoaders = exports.DEFAULT_ENTITY_KEY = void 0;
9
9
 
10
+ var _changeCase = require("change-case");
11
+
10
12
  var _lodash = require("lodash");
11
13
 
12
14
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
@@ -29,18 +31,15 @@ var _actions = require("./actions");
29
31
  const DEFAULT_ENTITY_KEY = 'id';
30
32
  exports.DEFAULT_ENTITY_KEY = DEFAULT_ENTITY_KEY;
31
33
  const POST_RAW_ATTRIBUTES = ['title', 'excerpt', 'content'];
32
- const attachmentConfig = {
33
- name: 'media',
34
+ const rootEntitiesConfig = [{
35
+ label: (0, _i18n.__)('Base'),
34
36
  kind: 'root',
35
- baseURL: '/wp/v2/media',
37
+ name: '__unstableBase',
38
+ baseURL: '/',
36
39
  baseURLParams: {
37
- context: 'edit'
38
- },
39
- plural: 'mediaItems',
40
- label: (0, _i18n.__)('Media'),
41
- rawAttributes: ['caption', 'title', 'description']
42
- };
43
- const siteConfig = {
40
+ _fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
41
+ }
42
+ }, {
44
43
  label: (0, _i18n.__)('Site'),
45
44
  name: 'site',
46
45
  kind: 'root',
@@ -48,8 +47,7 @@ const siteConfig = {
48
47
  getTitle: record => {
49
48
  return (0, _lodash.get)(record, ['title'], (0, _i18n.__)('Site Title'));
50
49
  }
51
- };
52
- const postTypeConfig = {
50
+ }, {
53
51
  label: (0, _i18n.__)('Post Type'),
54
52
  name: 'postType',
55
53
  kind: 'root',
@@ -58,8 +56,17 @@ const postTypeConfig = {
58
56
  baseURLParams: {
59
57
  context: 'edit'
60
58
  }
61
- };
62
- const taxonomyConfig = {
59
+ }, {
60
+ name: 'media',
61
+ kind: 'root',
62
+ baseURL: '/wp/v2/media',
63
+ baseURLParams: {
64
+ context: 'edit'
65
+ },
66
+ plural: 'mediaItems',
67
+ label: (0, _i18n.__)('Media'),
68
+ rawAttributes: ['caption', 'title', 'description']
69
+ }, {
63
70
  name: 'taxonomy',
64
71
  kind: 'root',
65
72
  key: 'slug',
@@ -69,8 +76,7 @@ const taxonomyConfig = {
69
76
  },
70
77
  plural: 'taxonomies',
71
78
  label: (0, _i18n.__)('Taxonomy')
72
- };
73
- const sidebarConfig = {
79
+ }, {
74
80
  name: 'sidebar',
75
81
  kind: 'root',
76
82
  baseURL: '/wp/v2/sidebars',
@@ -82,8 +88,7 @@ const sidebarConfig = {
82
88
  blocks: true
83
89
  },
84
90
  label: (0, _i18n.__)('Widget areas')
85
- };
86
- const widgetConfig = {
91
+ }, {
87
92
  name: 'widget',
88
93
  kind: 'root',
89
94
  baseURL: '/wp/v2/widgets',
@@ -95,8 +100,7 @@ const widgetConfig = {
95
100
  blocks: true
96
101
  },
97
102
  label: (0, _i18n.__)('Widgets')
98
- };
99
- const widgetTypeConfig = {
103
+ }, {
100
104
  name: 'widgetType',
101
105
  kind: 'root',
102
106
  baseURL: '/wp/v2/widget-types',
@@ -105,8 +109,7 @@ const widgetTypeConfig = {
105
109
  },
106
110
  plural: 'widgetTypes',
107
111
  label: (0, _i18n.__)('Widget types')
108
- };
109
- const userConfig = {
112
+ }, {
110
113
  label: (0, _i18n.__)('User'),
111
114
  name: 'user',
112
115
  kind: 'root',
@@ -115,8 +118,7 @@ const userConfig = {
115
118
  context: 'edit'
116
119
  },
117
120
  plural: 'users'
118
- };
119
- const commentConfig = {
121
+ }, {
120
122
  name: 'comment',
121
123
  kind: 'root',
122
124
  baseURL: '/wp/v2/comments',
@@ -125,8 +127,7 @@ const commentConfig = {
125
127
  },
126
128
  plural: 'comments',
127
129
  label: (0, _i18n.__)('Comment')
128
- };
129
- const menuConfig = {
130
+ }, {
130
131
  name: 'menu',
131
132
  kind: 'root',
132
133
  baseURL: '/wp/v2/menus',
@@ -135,8 +136,7 @@ const menuConfig = {
135
136
  },
136
137
  plural: 'menus',
137
138
  label: (0, _i18n.__)('Menu')
138
- };
139
- const menuItemConfig = {
139
+ }, {
140
140
  name: 'menuItem',
141
141
  kind: 'root',
142
142
  baseURL: '/wp/v2/menu-items',
@@ -146,8 +146,7 @@ const menuItemConfig = {
146
146
  plural: 'menuItems',
147
147
  label: (0, _i18n.__)('Menu Item'),
148
148
  rawAttributes: ['title']
149
- };
150
- const menuLocationConfig = {
149
+ }, {
151
150
  name: 'menuLocation',
152
151
  kind: 'root',
153
152
  baseURL: '/wp/v2/menu-locations',
@@ -157,8 +156,7 @@ const menuLocationConfig = {
157
156
  plural: 'menuLocations',
158
157
  label: (0, _i18n.__)('Menu Location'),
159
158
  key: 'name'
160
- };
161
- const globalStyleConfig = {
159
+ }, {
162
160
  label: (0, _i18n.__)('Global Styles'),
163
161
  name: 'globalStyles',
164
162
  kind: 'root',
@@ -173,8 +171,7 @@ const globalStyleConfig = {
173
171
 
174
172
  return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title);
175
173
  }
176
- };
177
- const themeConfig = {
174
+ }, {
178
175
  label: (0, _i18n.__)('Themes'),
179
176
  name: 'theme',
180
177
  kind: 'root',
@@ -183,8 +180,7 @@ const themeConfig = {
183
180
  context: 'edit'
184
181
  },
185
182
  key: 'stylesheet'
186
- };
187
- const pluginConfig = {
183
+ }, {
188
184
  label: (0, _i18n.__)('Plugins'),
189
185
  name: 'plugin',
190
186
  kind: 'root',
@@ -193,16 +189,7 @@ const pluginConfig = {
193
189
  context: 'edit'
194
190
  },
195
191
  key: 'plugin'
196
- };
197
- const rootEntitiesConfig = [{
198
- label: (0, _i18n.__)('Base'),
199
- kind: 'root',
200
- name: '__unstableBase',
201
- baseURL: '/',
202
- baseURLParams: {
203
- _fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
204
- }
205
- }, siteConfig, postTypeConfig, attachmentConfig, taxonomyConfig, sidebarConfig, widgetConfig, widgetTypeConfig, userConfig, commentConfig, menuConfig, menuItemConfig, menuLocationConfig, globalStyleConfig, themeConfig, pluginConfig];
192
+ }];
206
193
  exports.rootEntitiesConfig = rootEntitiesConfig;
207
194
  const additionalEntityConfigLoaders = [{
208
195
  kind: 'postType',
@@ -273,9 +260,9 @@ async function loadPostTypeEntities() {
273
260
  },
274
261
  rawAttributes: POST_RAW_ATTRIBUTES,
275
262
  getTitle: record => {
276
- var _record$title2;
263
+ var _record$title2, _record$slug;
277
264
 
278
- return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0, _lodash.startCase)(record.slug) : String(record.id));
265
+ return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0, _changeCase.capitalCase)((_record$slug = record.slug) !== null && _record$slug !== void 0 ? _record$slug : '') : String(record.id));
279
266
  },
280
267
  __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
281
268
  __unstable_rest_base: postType.rest_base
@@ -336,9 +323,9 @@ const getMethodName = function (kind, name) {
336
323
  kind,
337
324
  name
338
325
  });
339
- const kindPrefix = kind === 'root' ? '' : (0, _lodash.upperFirst)((0, _lodash.camelCase)(kind));
340
- const nameSuffix = (0, _lodash.upperFirst)((0, _lodash.camelCase)(name)) + (usePlural ? 's' : '');
341
- const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _lodash.upperFirst)((0, _lodash.camelCase)(entityConfig.plural)) : nameSuffix;
326
+ const kindPrefix = kind === 'root' ? '' : (0, _changeCase.pascalCase)(kind);
327
+ const nameSuffix = (0, _changeCase.pascalCase)(name) + (usePlural ? 's' : '');
328
+ const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _changeCase.pascalCase)(entityConfig.plural) : nameSuffix;
342
329
  return `${prefix}${kindPrefix}${suffix}`;
343
330
  };
344
331
  /**