@wordpress/core-data 6.16.0 → 6.17.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 (236) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/actions.js +69 -134
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +0 -22
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/batch/default-processor.js +3 -15
  7. package/build/batch/default-processor.js.map +1 -1
  8. package/build/batch/index.js +0 -3
  9. package/build/batch/index.js.map +1 -1
  10. package/build/entities.js +109 -36
  11. package/build/entities.js.map +1 -1
  12. package/build/entity-provider.js +34 -53
  13. package/build/entity-provider.js.map +1 -1
  14. package/build/entity-types/attachment.js.map +1 -1
  15. package/build/entity-types/base-entity-records.js +0 -3
  16. package/build/entity-types/base-entity-records.js.map +1 -1
  17. package/build/entity-types/comment.js.map +1 -1
  18. package/build/entity-types/helpers.js.map +1 -1
  19. package/build/entity-types/index.js.map +1 -1
  20. package/build/entity-types/menu-location.js.map +1 -1
  21. package/build/entity-types/nav-menu-item.js.map +1 -1
  22. package/build/entity-types/nav-menu.js.map +1 -1
  23. package/build/entity-types/page.js.map +1 -1
  24. package/build/entity-types/plugin.js.map +1 -1
  25. package/build/entity-types/post.js.map +1 -1
  26. package/build/entity-types/settings.js.map +1 -1
  27. package/build/entity-types/sidebar.js.map +1 -1
  28. package/build/entity-types/taxonomy.js.map +1 -1
  29. package/build/entity-types/theme.js.map +1 -1
  30. package/build/entity-types/type.js.map +1 -1
  31. package/build/entity-types/user.js.map +1 -1
  32. package/build/entity-types/widget-type.js.map +1 -1
  33. package/build/entity-types/widget.js.map +1 -1
  34. package/build/entity-types/wp-template-part.js.map +1 -1
  35. package/build/entity-types/wp-template.js.map +1 -1
  36. package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
  37. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  38. package/build/fetch/__experimental-fetch-url-data.js +4 -13
  39. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  40. package/build/fetch/index.js +0 -3
  41. package/build/fetch/index.js.map +1 -1
  42. package/build/hooks/constants.js +4 -5
  43. package/build/hooks/constants.js.map +1 -1
  44. package/build/hooks/index.js +0 -5
  45. package/build/hooks/index.js.map +1 -1
  46. package/build/hooks/memoize.js +0 -3
  47. package/build/hooks/memoize.js.map +1 -1
  48. package/build/hooks/use-entity-record.js +0 -9
  49. package/build/hooks/use-entity-record.js.map +1 -1
  50. package/build/hooks/use-entity-records.js +2 -9
  51. package/build/hooks/use-entity-records.js.map +1 -1
  52. package/build/hooks/use-query-select.js +1 -13
  53. package/build/hooks/use-query-select.js.map +1 -1
  54. package/build/hooks/use-resource-permissions.js +0 -15
  55. package/build/hooks/use-resource-permissions.js.map +1 -1
  56. package/build/index.js +9 -41
  57. package/build/index.js.map +1 -1
  58. package/build/locks/actions.js +1 -6
  59. package/build/locks/actions.js.map +1 -1
  60. package/build/locks/engine.js +1 -9
  61. package/build/locks/engine.js.map +1 -1
  62. package/build/locks/reducer.js +8 -9
  63. package/build/locks/reducer.js.map +1 -1
  64. package/build/locks/selectors.js +8 -11
  65. package/build/locks/selectors.js.map +1 -1
  66. package/build/locks/utils.js +4 -19
  67. package/build/locks/utils.js.map +1 -1
  68. package/build/name.js +0 -1
  69. package/build/name.js.map +1 -1
  70. package/build/private-apis.js +1 -2
  71. package/build/private-apis.js.map +1 -1
  72. package/build/private-selectors.js +2 -5
  73. package/build/private-selectors.js.map +1 -1
  74. package/build/queried-data/actions.js +4 -6
  75. package/build/queried-data/actions.js.map +1 -1
  76. package/build/queried-data/get-query-parts.js +11 -24
  77. package/build/queried-data/get-query-parts.js.map +1 -1
  78. package/build/queried-data/index.js +0 -6
  79. package/build/queried-data/index.js.map +1 -1
  80. package/build/queried-data/reducer.js +33 -51
  81. package/build/queried-data/reducer.js.map +1 -1
  82. package/build/queried-data/selectors.js +4 -25
  83. package/build/queried-data/selectors.js.map +1 -1
  84. package/build/reducer.js +76 -128
  85. package/build/reducer.js.map +1 -1
  86. package/build/resolvers.js +91 -133
  87. package/build/resolvers.js.map +1 -1
  88. package/build/selectors.js +51 -145
  89. package/build/selectors.js.map +1 -1
  90. package/build/sync.js +19 -0
  91. package/build/sync.js.map +1 -0
  92. package/build/types.js.map +1 -1
  93. package/build/utils/conservative-map-item.js +3 -10
  94. package/build/utils/conservative-map-item.js.map +1 -1
  95. package/build/utils/forward-resolver.js +0 -2
  96. package/build/utils/forward-resolver.js.map +1 -1
  97. package/build/utils/get-normalized-comma-separable.js +0 -3
  98. package/build/utils/get-normalized-comma-separable.js.map +1 -1
  99. package/build/utils/if-matching-action.js +0 -3
  100. package/build/utils/if-matching-action.js.map +1 -1
  101. package/build/utils/index.js +0 -10
  102. package/build/utils/index.js.map +1 -1
  103. package/build/utils/is-raw-attribute.js +0 -1
  104. package/build/utils/is-raw-attribute.js.map +1 -1
  105. package/build/utils/on-sub-key.js +5 -9
  106. package/build/utils/on-sub-key.js.map +1 -1
  107. package/build/utils/replace-action.js +0 -2
  108. package/build/utils/replace-action.js.map +1 -1
  109. package/build/utils/set-nested-value.js +0 -4
  110. package/build/utils/set-nested-value.js.map +1 -1
  111. package/build/utils/with-weak-map-cache.js +3 -6
  112. package/build/utils/with-weak-map-cache.js.map +1 -1
  113. package/build-module/actions.js +72 -95
  114. package/build-module/actions.js.map +1 -1
  115. package/build-module/batch/create-batch.js +1 -20
  116. package/build-module/batch/create-batch.js.map +1 -1
  117. package/build-module/batch/default-processor.js +4 -13
  118. package/build-module/batch/default-processor.js.map +1 -1
  119. package/build-module/batch/index.js.map +1 -1
  120. package/build-module/entities.js +109 -25
  121. package/build-module/entities.js.map +1 -1
  122. package/build-module/entity-provider.js +35 -45
  123. package/build-module/entity-provider.js.map +1 -1
  124. package/build-module/entity-types/attachment.js.map +1 -1
  125. package/build-module/entity-types/base-entity-records.js +0 -2
  126. package/build-module/entity-types/base-entity-records.js.map +1 -1
  127. package/build-module/entity-types/comment.js.map +1 -1
  128. package/build-module/entity-types/helpers.js.map +1 -1
  129. package/build-module/entity-types/index.js.map +1 -1
  130. package/build-module/entity-types/menu-location.js.map +1 -1
  131. package/build-module/entity-types/nav-menu-item.js.map +1 -1
  132. package/build-module/entity-types/nav-menu.js.map +1 -1
  133. package/build-module/entity-types/page.js.map +1 -1
  134. package/build-module/entity-types/plugin.js.map +1 -1
  135. package/build-module/entity-types/post.js.map +1 -1
  136. package/build-module/entity-types/settings.js.map +1 -1
  137. package/build-module/entity-types/sidebar.js.map +1 -1
  138. package/build-module/entity-types/taxonomy.js.map +1 -1
  139. package/build-module/entity-types/theme.js.map +1 -1
  140. package/build-module/entity-types/type.js.map +1 -1
  141. package/build-module/entity-types/user.js.map +1 -1
  142. package/build-module/entity-types/widget-type.js.map +1 -1
  143. package/build-module/entity-types/widget.js.map +1 -1
  144. package/build-module/entity-types/wp-template-part.js.map +1 -1
  145. package/build-module/entity-types/wp-template.js.map +1 -1
  146. package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
  147. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  148. package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
  149. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  150. package/build-module/fetch/index.js.map +1 -1
  151. package/build-module/hooks/constants.js +3 -4
  152. package/build-module/hooks/constants.js.map +1 -1
  153. package/build-module/hooks/index.js.map +1 -1
  154. package/build-module/hooks/memoize.js +2 -1
  155. package/build-module/hooks/memoize.js.map +1 -1
  156. package/build-module/hooks/use-entity-record.js +1 -3
  157. package/build-module/hooks/use-entity-record.js.map +1 -1
  158. package/build-module/hooks/use-entity-records.js +2 -3
  159. package/build-module/hooks/use-entity-records.js.map +1 -1
  160. package/build-module/hooks/use-query-select.js +1 -9
  161. package/build-module/hooks/use-query-select.js.map +1 -1
  162. package/build-module/hooks/use-resource-permissions.js +1 -10
  163. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  164. package/build-module/index.js +11 -19
  165. package/build-module/index.js.map +1 -1
  166. package/build-module/locks/actions.js +0 -3
  167. package/build-module/locks/actions.js.map +1 -1
  168. package/build-module/locks/engine.js +0 -5
  169. package/build-module/locks/engine.js.map +1 -1
  170. package/build-module/locks/reducer.js +7 -7
  171. package/build-module/locks/reducer.js.map +1 -1
  172. package/build-module/locks/selectors.js +7 -8
  173. package/build-module/locks/selectors.js.map +1 -1
  174. package/build-module/locks/utils.js +4 -14
  175. package/build-module/locks/utils.js.map +1 -1
  176. package/build-module/name.js.map +1 -1
  177. package/build-module/private-apis.js.map +1 -1
  178. package/build-module/private-selectors.js +2 -2
  179. package/build-module/private-selectors.js.map +1 -1
  180. package/build-module/queried-data/actions.js +4 -3
  181. package/build-module/queried-data/actions.js.map +1 -1
  182. package/build-module/queried-data/get-query-parts.js +13 -21
  183. package/build-module/queried-data/get-query-parts.js.map +1 -1
  184. package/build-module/queried-data/index.js.map +1 -1
  185. package/build-module/queried-data/reducer.js +33 -42
  186. package/build-module/queried-data/reducer.js.map +1 -1
  187. package/build-module/queried-data/selectors.js +6 -21
  188. package/build-module/queried-data/selectors.js.map +1 -1
  189. package/build-module/reducer.js +79 -104
  190. package/build-module/reducer.js.map +1 -1
  191. package/build-module/resolvers.js +94 -96
  192. package/build-module/resolvers.js.map +1 -1
  193. package/build-module/selectors.js +56 -92
  194. package/build-module/selectors.js.map +1 -1
  195. package/build-module/sync.js +12 -0
  196. package/build-module/sync.js.map +1 -0
  197. package/build-module/types.js.map +1 -1
  198. package/build-module/utils/conservative-map-item.js +4 -8
  199. package/build-module/utils/conservative-map-item.js.map +1 -1
  200. package/build-module/utils/forward-resolver.js +0 -1
  201. package/build-module/utils/forward-resolver.js.map +1 -1
  202. package/build-module/utils/get-normalized-comma-separable.js +0 -2
  203. package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
  204. package/build-module/utils/if-matching-action.js +0 -2
  205. package/build-module/utils/if-matching-action.js.map +1 -1
  206. package/build-module/utils/index.js.map +1 -1
  207. package/build-module/utils/is-raw-attribute.js.map +1 -1
  208. package/build-module/utils/on-sub-key.js +5 -7
  209. package/build-module/utils/on-sub-key.js.map +1 -1
  210. package/build-module/utils/replace-action.js +0 -1
  211. package/build-module/utils/replace-action.js.map +1 -1
  212. package/build-module/utils/set-nested-value.js +0 -3
  213. package/build-module/utils/set-nested-value.js.map +1 -1
  214. package/build-module/utils/with-weak-map-cache.js +3 -5
  215. package/build-module/utils/with-weak-map-cache.js.map +1 -1
  216. package/build-types/actions.d.ts.map +1 -1
  217. package/build-types/entities.d.ts +53 -0
  218. package/build-types/entities.d.ts.map +1 -1
  219. package/build-types/entity-provider.d.ts +1 -1
  220. package/build-types/entity-provider.d.ts.map +1 -1
  221. package/build-types/hooks/memoize.d.ts +1 -1
  222. package/build-types/hooks/memoize.d.ts.map +1 -1
  223. package/build-types/index.d.ts +3 -3
  224. package/build-types/index.d.ts.map +1 -1
  225. package/build-types/resolvers.d.ts.map +1 -1
  226. package/build-types/sync.d.ts +2 -0
  227. package/build-types/sync.d.ts.map +1 -0
  228. package/package.json +17 -15
  229. package/src/actions.js +24 -14
  230. package/src/entities.js +91 -0
  231. package/src/entity-provider.js +11 -2
  232. package/src/resolvers.js +89 -41
  233. package/src/sync.js +18 -0
  234. package/src/test/entity-provider.js +272 -0
  235. package/tsconfig.json +1 -0
  236. package/tsconfig.tsbuildinfo +1 -1
@@ -3,21 +3,23 @@
3
3
  */
4
4
  import fastDeepEqual from 'fast-deep-equal/es6';
5
5
  import { v4 as uuid } from 'uuid';
6
+
6
7
  /**
7
8
  * WordPress dependencies
8
9
  */
9
-
10
10
  import apiFetch from '@wordpress/api-fetch';
11
11
  import { addQueryArgs } from '@wordpress/url';
12
12
  import deprecated from '@wordpress/deprecated';
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
16
-
17
17
  import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
18
18
  import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
19
19
  import { createBatch } from './batch';
20
20
  import { STORE_NAME } from './name';
21
+ import { getSyncProvider } from './sync';
22
+
21
23
  /**
22
24
  * Returns an action object used in signalling that authors have been received.
23
25
  * Ignored from documentation as it's internal to the data store.
@@ -29,7 +31,6 @@ import { STORE_NAME } from './name';
29
31
  *
30
32
  * @return {Object} Action object.
31
33
  */
32
-
33
34
  export function receiveUserQuery(queryID, users) {
34
35
  return {
35
36
  type: 'RECEIVE_USER_QUERY',
@@ -37,6 +38,7 @@ export function receiveUserQuery(queryID, users) {
37
38
  queryID
38
39
  };
39
40
  }
41
+
40
42
  /**
41
43
  * Returns an action used in signalling that the current user has been received.
42
44
  * Ignored from documentation as it's internal to the data store.
@@ -47,13 +49,13 @@ export function receiveUserQuery(queryID, users) {
47
49
  *
48
50
  * @return {Object} Action object.
49
51
  */
50
-
51
52
  export function receiveCurrentUser(currentUser) {
52
53
  return {
53
54
  type: 'RECEIVE_CURRENT_USER',
54
55
  currentUser
55
56
  };
56
57
  }
58
+
57
59
  /**
58
60
  * Returns an action object used in adding new entities.
59
61
  *
@@ -61,13 +63,13 @@ export function receiveCurrentUser(currentUser) {
61
63
  *
62
64
  * @return {Object} Action object.
63
65
  */
64
-
65
66
  export function addEntities(entities) {
66
67
  return {
67
68
  type: 'ADD_ENTITIES',
68
69
  entities
69
70
  };
70
71
  }
72
+
71
73
  /**
72
74
  * Returns an action object used in signalling that entity records have been received.
73
75
  *
@@ -79,30 +81,29 @@ export function addEntities(entities) {
79
81
  * @param {?Object} edits Edits to reset.
80
82
  * @return {Object} Action object.
81
83
  */
82
-
83
84
  export function receiveEntityRecords(kind, name, records, query, invalidateCache = false, edits) {
84
85
  // Auto drafts should not have titles, but some plugins rely on them so we can't filter this
85
86
  // on the server.
86
87
  if (kind === 'postType') {
87
- records = (Array.isArray(records) ? records : [records]).map(record => record.status === 'auto-draft' ? { ...record,
88
+ records = (Array.isArray(records) ? records : [records]).map(record => record.status === 'auto-draft' ? {
89
+ ...record,
88
90
  title: ''
89
91
  } : record);
90
92
  }
91
-
92
93
  let action;
93
-
94
94
  if (query) {
95
95
  action = receiveQueriedItems(records, query, edits);
96
96
  } else {
97
97
  action = receiveItems(records, edits);
98
98
  }
99
-
100
- return { ...action,
99
+ return {
100
+ ...action,
101
101
  kind,
102
102
  name,
103
103
  invalidateCache
104
104
  };
105
105
  }
106
+
106
107
  /**
107
108
  * Returns an action object used in signalling that the current theme has been received.
108
109
  * Ignored from documentation as it's internal to the data store.
@@ -113,13 +114,13 @@ export function receiveEntityRecords(kind, name, records, query, invalidateCache
113
114
  *
114
115
  * @return {Object} Action object.
115
116
  */
116
-
117
117
  export function receiveCurrentTheme(currentTheme) {
118
118
  return {
119
119
  type: 'RECEIVE_CURRENT_THEME',
120
120
  currentTheme
121
121
  };
122
122
  }
123
+
123
124
  /**
124
125
  * Returns an action object used in signalling that the current global styles id has been received.
125
126
  * Ignored from documentation as it's internal to the data store.
@@ -130,13 +131,13 @@ export function receiveCurrentTheme(currentTheme) {
130
131
  *
131
132
  * @return {Object} Action object.
132
133
  */
133
-
134
134
  export function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId) {
135
135
  return {
136
136
  type: 'RECEIVE_CURRENT_GLOBAL_STYLES_ID',
137
137
  id: currentGlobalStylesId
138
138
  };
139
139
  }
140
+
140
141
  /**
141
142
  * Returns an action object used in signalling that the theme base global styles have been received
142
143
  * Ignored from documentation as it's internal to the data store.
@@ -148,7 +149,6 @@ export function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId
148
149
  *
149
150
  * @return {Object} Action object.
150
151
  */
151
-
152
152
  export function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalStyles) {
153
153
  return {
154
154
  type: 'RECEIVE_THEME_GLOBAL_STYLES',
@@ -156,6 +156,7 @@ export function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalSty
156
156
  globalStyles
157
157
  };
158
158
  }
159
+
159
160
  /**
160
161
  * Returns an action object used in signalling that the theme global styles variations have been received.
161
162
  * Ignored from documentation as it's internal to the data store.
@@ -167,7 +168,6 @@ export function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalSty
167
168
  *
168
169
  * @return {Object} Action object.
169
170
  */
170
-
171
171
  export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, variations) {
172
172
  return {
173
173
  type: 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS',
@@ -175,6 +175,7 @@ export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, vari
175
175
  variations
176
176
  };
177
177
  }
178
+
178
179
  /**
179
180
  * Returns an action object used in signalling that the index has been received.
180
181
  *
@@ -182,7 +183,6 @@ export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, vari
182
183
  *
183
184
  * @return {Object} Action object.
184
185
  */
185
-
186
186
  export function receiveThemeSupports() {
187
187
  deprecated("wp.data.dispatch( 'core' ).receiveThemeSupports", {
188
188
  since: '5.9'
@@ -191,6 +191,7 @@ export function receiveThemeSupports() {
191
191
  type: 'DO_NOTHING'
192
192
  };
193
193
  }
194
+
194
195
  /**
195
196
  * Returns an action object used in signalling that the theme global styles CPT post revisions have been received.
196
197
  * Ignored from documentation as it's internal to the data store.
@@ -202,7 +203,6 @@ export function receiveThemeSupports() {
202
203
  *
203
204
  * @return {Object} Action object.
204
205
  */
205
-
206
206
  export function receiveThemeGlobalStyleRevisions(currentId, revisions) {
207
207
  return {
208
208
  type: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS',
@@ -210,6 +210,7 @@ export function receiveThemeGlobalStyleRevisions(currentId, revisions) {
210
210
  revisions
211
211
  };
212
212
  }
213
+
213
214
  /**
214
215
  * Returns an action object used in signalling that the preview data for
215
216
  * a given URl has been received.
@@ -222,7 +223,6 @@ export function receiveThemeGlobalStyleRevisions(currentId, revisions) {
222
223
  *
223
224
  * @return {Object} Action object.
224
225
  */
225
-
226
226
  export function receiveEmbedPreview(url, preview) {
227
227
  return {
228
228
  type: 'RECEIVE_EMBED_PREVIEW',
@@ -230,6 +230,7 @@ export function receiveEmbedPreview(url, preview) {
230
230
  preview
231
231
  };
232
232
  }
233
+
233
234
  /**
234
235
  * Action triggered to delete an entity record.
235
236
  *
@@ -245,7 +246,6 @@ export function receiveEmbedPreview(url, preview) {
245
246
  * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
246
247
  * the exceptions. Defaults to false.
247
248
  */
248
-
249
249
  export const deleteEntityRecord = (kind, name, recordId, query, {
250
250
  __unstableFetch = apiFetch,
251
251
  throwOnError = false
@@ -256,15 +256,12 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
256
256
  const entityConfig = configs.find(config => config.kind === kind && config.name === name);
257
257
  let error;
258
258
  let deletedRecord = false;
259
-
260
259
  if (!entityConfig || entityConfig?.__experimentalNoFetch) {
261
260
  return;
262
261
  }
263
-
264
262
  const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId], {
265
263
  exclusive: true
266
264
  });
267
-
268
265
  try {
269
266
  dispatch({
270
267
  type: 'DELETE_ENTITY_RECORD_START',
@@ -273,14 +270,11 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
273
270
  recordId
274
271
  });
275
272
  let hasError = false;
276
-
277
273
  try {
278
274
  let path = `${entityConfig.baseURL}/${recordId}`;
279
-
280
275
  if (query) {
281
276
  path = addQueryArgs(path, query);
282
277
  }
283
-
284
278
  deletedRecord = await __unstableFetch({
285
279
  path,
286
280
  method: 'DELETE'
@@ -290,7 +284,6 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
290
284
  hasError = true;
291
285
  error = _error;
292
286
  }
293
-
294
287
  dispatch({
295
288
  type: 'DELETE_ENTITY_RECORD_FINISH',
296
289
  kind,
@@ -298,16 +291,15 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
298
291
  recordId,
299
292
  error
300
293
  });
301
-
302
294
  if (hasError && throwOnError) {
303
295
  throw error;
304
296
  }
305
-
306
297
  return deletedRecord;
307
298
  } finally {
308
299
  dispatch.__unstableReleaseStoreLock(lock);
309
300
  }
310
301
  };
302
+
311
303
  /**
312
304
  * Returns an action object that triggers an
313
305
  * edit to an entity record.
@@ -321,17 +313,14 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
321
313
  *
322
314
  * @return {Object} Action object.
323
315
  */
324
-
325
316
  export const editEntityRecord = (kind, name, recordId, edits, options = {}) => ({
326
317
  select,
327
318
  dispatch
328
319
  }) => {
329
320
  const entityConfig = select.getEntityConfig(kind, name);
330
-
331
321
  if (!entityConfig) {
332
322
  throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
333
323
  }
334
-
335
324
  const {
336
325
  mergedEdits = {}
337
326
  } = entityConfig;
@@ -346,79 +335,83 @@ export const editEntityRecord = (kind, name, recordId, edits, options = {}) => (
346
335
  edits: Object.keys(edits).reduce((acc, key) => {
347
336
  const recordValue = record[key];
348
337
  const editedRecordValue = editedRecord[key];
349
- const value = mergedEdits[key] ? { ...editedRecordValue,
338
+ const value = mergedEdits[key] ? {
339
+ ...editedRecordValue,
350
340
  ...edits[key]
351
341
  } : edits[key];
352
342
  acc[key] = fastDeepEqual(recordValue, value) ? undefined : value;
353
343
  return acc;
354
344
  }, {})
355
345
  };
356
- dispatch({
357
- type: 'EDIT_ENTITY_RECORD',
358
- ...edit,
359
- meta: {
360
- undo: !options.undoIgnore && { ...edit,
361
- // Send the current values for things like the first undo stack entry.
362
- edits: Object.keys(edits).reduce((acc, key) => {
363
- acc[key] = editedRecord[key];
364
- return acc;
365
- }, {}),
366
- isCached: options.isCached
346
+ if (window.__experimentalEnableSync && entityConfig.syncConfig) {
347
+ const objectId = entityConfig.getSyncObjectId(recordId);
348
+ getSyncProvider().update(entityConfig.syncObjectType + '--edit', objectId, edit.edits);
349
+ } else {
350
+ dispatch({
351
+ type: 'EDIT_ENTITY_RECORD',
352
+ ...edit,
353
+ meta: {
354
+ undo: !options.undoIgnore && {
355
+ ...edit,
356
+ // Send the current values for things like the first undo stack entry.
357
+ edits: Object.keys(edits).reduce((acc, key) => {
358
+ acc[key] = editedRecord[key];
359
+ return acc;
360
+ }, {}),
361
+ isCached: options.isCached
362
+ }
367
363
  }
368
- }
369
- });
364
+ });
365
+ }
370
366
  };
367
+
371
368
  /**
372
369
  * Action triggered to undo the last edit to
373
370
  * an entity record, if any.
374
371
  */
375
-
376
372
  export const undo = () => ({
377
373
  select,
378
374
  dispatch
379
375
  }) => {
380
376
  const undoEdit = select.getUndoEdits();
381
-
382
377
  if (!undoEdit) {
383
378
  return;
384
379
  }
385
-
386
380
  dispatch({
387
381
  type: 'UNDO',
388
382
  stackedEdits: undoEdit
389
383
  });
390
384
  };
385
+
391
386
  /**
392
387
  * Action triggered to redo the last undoed
393
388
  * edit to an entity record, if any.
394
389
  */
395
-
396
390
  export const redo = () => ({
397
391
  select,
398
392
  dispatch
399
393
  }) => {
400
394
  const redoEdit = select.getRedoEdits();
401
-
402
395
  if (!redoEdit) {
403
396
  return;
404
397
  }
405
-
406
398
  dispatch({
407
399
  type: 'REDO',
408
400
  stackedEdits: redoEdit
409
401
  });
410
402
  };
403
+
411
404
  /**
412
405
  * Forces the creation of a new undo level.
413
406
  *
414
407
  * @return {Object} Action object.
415
408
  */
416
-
417
409
  export function __unstableCreateUndoLevel() {
418
410
  return {
419
411
  type: 'CREATE_UNDO_LEVEL'
420
412
  };
421
413
  }
414
+
422
415
  /**
423
416
  * Action triggered to save an entity record.
424
417
  *
@@ -433,7 +426,6 @@ export function __unstableCreateUndoLevel() {
433
426
  * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
434
427
  * the exceptions. Defaults to false.
435
428
  */
436
-
437
429
  export const saveEntityRecord = (kind, name, record, {
438
430
  isAutosave = false,
439
431
  __unstableFetch = apiFetch,
@@ -445,17 +437,14 @@ export const saveEntityRecord = (kind, name, record, {
445
437
  }) => {
446
438
  const configs = await dispatch(getOrLoadEntitiesConfig(kind));
447
439
  const entityConfig = configs.find(config => config.kind === kind && config.name === name);
448
-
449
440
  if (!entityConfig || entityConfig?.__experimentalNoFetch) {
450
441
  return;
451
442
  }
452
-
453
443
  const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
454
444
  const recordId = record[entityIdKey];
455
445
  const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId || uuid()], {
456
446
  exclusive: true
457
447
  });
458
-
459
448
  try {
460
449
  // Evaluate optimized edits.
461
450
  // (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
@@ -470,7 +459,6 @@ export const saveEntityRecord = (kind, name, record, {
470
459
  record[key] = evaluatedValue;
471
460
  }
472
461
  }
473
-
474
462
  dispatch({
475
463
  type: 'SAVE_ENTITY_RECORD_START',
476
464
  kind,
@@ -481,11 +469,9 @@ export const saveEntityRecord = (kind, name, record, {
481
469
  let updatedRecord;
482
470
  let error;
483
471
  let hasError = false;
484
-
485
472
  try {
486
473
  const path = `${entityConfig.baseURL}${recordId ? '/' + recordId : ''}`;
487
474
  const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
488
-
489
475
  if (isAutosave) {
490
476
  // Most of this autosave logic is very specific to posts.
491
477
  // This is fine for now as it is the only supported autosave,
@@ -493,12 +479,13 @@ export const saveEntityRecord = (kind, name, record, {
493
479
  // so the client just sends and receives objects.
494
480
  const currentUser = select.getCurrentUser();
495
481
  const currentUserId = currentUser ? currentUser.id : undefined;
496
- const autosavePost = await resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
482
+ const autosavePost = await resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId);
483
+ // Autosaves need all expected fields to be present.
497
484
  // So we fallback to the previous autosave and then
498
485
  // to the actual persisted entity if the edits don't
499
486
  // have a value.
500
-
501
- let data = { ...persistedRecord,
487
+ let data = {
488
+ ...persistedRecord,
502
489
  ...autosavePost,
503
490
  ...record
504
491
  };
@@ -506,7 +493,6 @@ export const saveEntityRecord = (kind, name, record, {
506
493
  if (['title', 'excerpt', 'content', 'meta'].includes(key)) {
507
494
  acc[key] = data[key];
508
495
  }
509
-
510
496
  return acc;
511
497
  }, {
512
498
  status: data.status === 'auto-draft' ? 'draft' : data.status
@@ -515,12 +501,14 @@ export const saveEntityRecord = (kind, name, record, {
515
501
  path: `${path}/autosaves`,
516
502
  method: 'POST',
517
503
  data
518
- }); // An autosave may be processed by the server as a regular save
504
+ });
505
+
506
+ // An autosave may be processed by the server as a regular save
519
507
  // when its update is requested by the author and the post had
520
508
  // draft or auto-draft status.
521
-
522
509
  if (persistedRecord.id === updatedRecord.id) {
523
- let newRecord = { ...persistedRecord,
510
+ let newRecord = {
511
+ ...persistedRecord,
524
512
  ...data,
525
513
  ...updatedRecord
526
514
  };
@@ -536,7 +524,6 @@ export const saveEntityRecord = (kind, name, record, {
536
524
  // These properties are not persisted in autosaves.
537
525
  acc[key] = persistedRecord[key];
538
526
  }
539
-
540
527
  return acc;
541
528
  }, {});
542
529
  dispatch.receiveEntityRecords(kind, name, newRecord, undefined, true);
@@ -545,13 +532,12 @@ export const saveEntityRecord = (kind, name, record, {
545
532
  }
546
533
  } else {
547
534
  let edits = record;
548
-
549
535
  if (entityConfig.__unstablePrePersist) {
550
- edits = { ...edits,
536
+ edits = {
537
+ ...edits,
551
538
  ...entityConfig.__unstablePrePersist(persistedRecord, edits)
552
539
  };
553
540
  }
554
-
555
541
  updatedRecord = await __unstableFetch({
556
542
  path,
557
543
  method: recordId ? 'PUT' : 'POST',
@@ -563,7 +549,6 @@ export const saveEntityRecord = (kind, name, record, {
563
549
  hasError = true;
564
550
  error = _error;
565
551
  }
566
-
567
552
  dispatch({
568
553
  type: 'SAVE_ENTITY_RECORD_FINISH',
569
554
  kind,
@@ -572,16 +557,15 @@ export const saveEntityRecord = (kind, name, record, {
572
557
  error,
573
558
  isAutosave
574
559
  });
575
-
576
560
  if (hasError && throwOnError) {
577
561
  throw error;
578
562
  }
579
-
580
563
  return updatedRecord;
581
564
  } finally {
582
565
  dispatch.__unstableReleaseStoreLock(lock);
583
566
  }
584
567
  };
568
+
585
569
  /**
586
570
  * Runs multiple core-data actions at the same time using one API request.
587
571
  *
@@ -604,35 +588,35 @@ export const saveEntityRecord = (kind, name, record, {
604
588
  * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return
605
589
  * values of each function given in `requests`.
606
590
  */
607
-
608
591
  export const __experimentalBatch = requests => async ({
609
592
  dispatch
610
593
  }) => {
611
594
  const batch = createBatch();
612
595
  const api = {
613
596
  saveEntityRecord(kind, name, record, options) {
614
- return batch.add(add => dispatch.saveEntityRecord(kind, name, record, { ...options,
597
+ return batch.add(add => dispatch.saveEntityRecord(kind, name, record, {
598
+ ...options,
615
599
  __unstableFetch: add
616
600
  }));
617
601
  },
618
-
619
602
  saveEditedEntityRecord(kind, name, recordId, options) {
620
- return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, { ...options,
603
+ return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, {
604
+ ...options,
621
605
  __unstableFetch: add
622
606
  }));
623
607
  },
624
-
625
608
  deleteEntityRecord(kind, name, recordId, query, options) {
626
- return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, { ...options,
609
+ return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, {
610
+ ...options,
627
611
  __unstableFetch: add
628
612
  }));
629
613
  }
630
-
631
614
  };
632
615
  const resultPromises = requests.map(request => request(api));
633
616
  const [, ...results] = await Promise.all([batch.run(), ...resultPromises]);
634
617
  return results;
635
618
  };
619
+
636
620
  /**
637
621
  * Action triggered to save an entity record's edits.
638
622
  *
@@ -641,7 +625,6 @@ export const __experimentalBatch = requests => async ({
641
625
  * @param {Object} recordId ID of the record.
642
626
  * @param {Object} options Saving options.
643
627
  */
644
-
645
628
  export const saveEditedEntityRecord = (kind, name, recordId, options) => async ({
646
629
  select,
647
630
  dispatch
@@ -649,14 +632,11 @@ export const saveEditedEntityRecord = (kind, name, recordId, options) => async (
649
632
  if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
650
633
  return;
651
634
  }
652
-
653
635
  const configs = await dispatch(getOrLoadEntitiesConfig(kind));
654
636
  const entityConfig = configs.find(config => config.kind === kind && config.name === name);
655
-
656
637
  if (!entityConfig) {
657
638
  return;
658
639
  }
659
-
660
640
  const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
661
641
  const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
662
642
  const record = {
@@ -665,6 +645,7 @@ export const saveEditedEntityRecord = (kind, name, recordId, options) => async (
665
645
  };
666
646
  return await dispatch.saveEntityRecord(kind, name, record, options);
667
647
  };
648
+
668
649
  /**
669
650
  * Action triggered to save only specified properties for the entity.
670
651
  *
@@ -674,7 +655,6 @@ export const saveEditedEntityRecord = (kind, name, recordId, options) => async (
674
655
  * @param {Array} itemsToSave List of entity properties to save.
675
656
  * @param {Object} options Saving options.
676
657
  */
677
-
678
658
  export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({
679
659
  select,
680
660
  dispatch
@@ -682,29 +662,27 @@ export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, ite
682
662
  if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
683
663
  return;
684
664
  }
685
-
686
665
  const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
687
666
  const editsToSave = {};
688
-
689
667
  for (const edit in edits) {
690
668
  if (itemsToSave.some(item => item === edit)) {
691
669
  editsToSave[edit] = edits[edit];
692
670
  }
693
671
  }
694
-
695
672
  const configs = await dispatch(getOrLoadEntitiesConfig(kind));
696
673
  const entityConfig = configs.find(config => config.kind === kind && config.name === name);
697
- const entityIdKey = entityConfig?.key || DEFAULT_ENTITY_KEY; // If a record key is provided then update the existing record.
674
+ const entityIdKey = entityConfig?.key || DEFAULT_ENTITY_KEY;
675
+
676
+ // If a record key is provided then update the existing record.
698
677
  // This necessitates providing `recordKey` to saveEntityRecord as part of the
699
678
  // `record` argument (here called `editsToSave`) to stop that action creating
700
679
  // a new record and instead cause it to update the existing record.
701
-
702
680
  if (recordId) {
703
681
  editsToSave[entityIdKey] = recordId;
704
682
  }
705
-
706
683
  return await dispatch.saveEntityRecord(kind, name, editsToSave, options);
707
684
  };
685
+
708
686
  /**
709
687
  * Returns an action object used in signalling that Upload permissions have been received.
710
688
  *
@@ -714,7 +692,6 @@ export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, ite
714
692
  *
715
693
  * @return {Object} Action object.
716
694
  */
717
-
718
695
  export function receiveUploadPermissions(hasUploadPermissions) {
719
696
  deprecated("wp.data.dispatch( 'core' ).receiveUploadPermissions", {
720
697
  since: '5.9',
@@ -722,6 +699,7 @@ export function receiveUploadPermissions(hasUploadPermissions) {
722
699
  });
723
700
  return receiveUserPermission('create/media', hasUploadPermissions);
724
701
  }
702
+
725
703
  /**
726
704
  * Returns an action object used in signalling that the current user has
727
705
  * permission to perform an action on a REST resource.
@@ -734,7 +712,6 @@ export function receiveUploadPermissions(hasUploadPermissions) {
734
712
  *
735
713
  * @return {Object} Action object.
736
714
  */
737
-
738
715
  export function receiveUserPermission(key, isAllowed) {
739
716
  return {
740
717
  type: 'RECEIVE_USER_PERMISSION',
@@ -742,6 +719,7 @@ export function receiveUserPermission(key, isAllowed) {
742
719
  isAllowed
743
720
  };
744
721
  }
722
+
745
723
  /**
746
724
  * Returns an action object used in signalling that the autosaves for a
747
725
  * post have been received.
@@ -754,7 +732,6 @@ export function receiveUserPermission(key, isAllowed) {
754
732
  *
755
733
  * @return {Object} Action object.
756
734
  */
757
-
758
735
  export function receiveAutosaves(postId, autosaves) {
759
736
  return {
760
737
  type: 'RECEIVE_AUTOSAVES',
@@ -762,6 +739,7 @@ export function receiveAutosaves(postId, autosaves) {
762
739
  autosaves: Array.isArray(autosaves) ? autosaves : [autosaves]
763
740
  };
764
741
  }
742
+
765
743
  /**
766
744
  * Returns an action object signalling that the fallback Navigation
767
745
  * Menu id has been received.
@@ -769,7 +747,6 @@ export function receiveAutosaves(postId, autosaves) {
769
747
  * @param {integer} fallbackId the id of the fallback Navigation Menu
770
748
  * @return {Object} Action object.
771
749
  */
772
-
773
750
  export function receiveNavigationFallbackId(fallbackId) {
774
751
  return {
775
752
  type: 'RECEIVE_NAVIGATION_FALLBACK_ID',