@wordpress/core-data 4.0.1-next.253d9b6e21.0 → 4.0.3
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.
- package/README.md +11 -3
- package/build/actions.js +124 -117
- package/build/actions.js.map +1 -1
- package/build/batch/default-processor.js +58 -27
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +24 -18
- package/build/entities.js.map +1 -1
- package/build/index.js +9 -17
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +17 -77
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +77 -0
- package/build/locks/engine.js.map +1 -0
- package/build/locks/reducer.js +1 -5
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +6 -6
- package/build/locks/selectors.js.map +1 -1
- package/build/queried-data/get-query-parts.js +9 -4
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/selectors.js +3 -9
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +1 -4
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +120 -91
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +31 -11
- package/build/selectors.js.map +1 -1
- package/build/utils/if-not-resolved.js +6 -21
- package/build/utils/if-not-resolved.js.map +1 -1
- package/build/utils/index.js +8 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +19 -0
- package/build/utils/is-raw-attribute.js.map +1 -0
- package/build-module/actions.js +106 -107
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/default-processor.js +57 -27
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +19 -14
- package/build-module/entities.js.map +1 -1
- package/build-module/index.js +10 -14
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +14 -68
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +66 -0
- package/build-module/locks/engine.js.map +1 -0
- package/build-module/locks/reducer.js +1 -2
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +4 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +9 -4
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/selectors.js +3 -9
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +1 -3
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +94 -74
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +30 -10
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/if-not-resolved.js +6 -19
- package/build-module/utils/if-not-resolved.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +12 -0
- package/build-module/utils/is-raw-attribute.js.map +1 -0
- package/package.json +11 -12
- package/src/actions.js +112 -189
- package/src/batch/default-processor.js +57 -26
- package/src/batch/test/default-processor.js +53 -26
- package/src/entities.js +15 -16
- package/src/index.js +7 -10
- package/src/locks/actions.js +10 -61
- package/src/locks/engine.js +43 -0
- package/src/locks/reducer.js +1 -3
- package/src/locks/selectors.js +4 -4
- package/src/locks/test/engine.js +135 -0
- package/src/locks/test/reducer.js +1 -1
- package/src/locks/test/selectors.js +105 -124
- package/src/queried-data/get-query-parts.js +11 -6
- package/src/queried-data/selectors.js +2 -9
- package/src/queried-data/test/get-query-parts.js +1 -1
- package/src/queried-data/test/selectors.js +1 -0
- package/src/reducer.js +0 -2
- package/src/resolvers.js +86 -106
- package/src/selectors.js +113 -40
- package/src/test/actions.js +243 -172
- package/src/test/entities.js +40 -26
- package/src/test/resolvers.js +270 -223
- package/src/test/selectors.js +71 -0
- package/src/utils/if-not-resolved.js +8 -26
- package/src/utils/index.js +1 -0
- package/src/utils/is-raw-attribute.js +11 -0
- package/src/utils/test/if-not-resolved.js +28 -27
- package/src/utils/test/is-raw-attribute.js +22 -0
- package/build/controls.js +0 -44
- package/build/controls.js.map +0 -1
- package/build/locks/index.js +0 -47
- package/build/locks/index.js.map +0 -1
- package/build-module/controls.js +0 -31
- package/build-module/controls.js.map +0 -1
- package/build-module/locks/index.js +0 -4
- package/build-module/locks/index.js.map +0 -1
- package/src/controls.js +0 -31
- package/src/locks/index.js +0 -3
- package/src/locks/test/actions.js +0 -307
- package/src/test/integration.js +0 -264
package/build/resolvers.js
CHANGED
|
@@ -1,42 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.getAuthors =
|
|
7
|
-
exports.getCurrentUser = getCurrentUser;
|
|
8
|
-
exports.getEntityRecord = getEntityRecord;
|
|
9
|
-
exports.getEntityRecords = getEntityRecords;
|
|
10
|
-
exports.getCurrentTheme = getCurrentTheme;
|
|
11
|
-
exports.getThemeSupports = getThemeSupports;
|
|
12
|
-
exports.getEmbedPreview = getEmbedPreview;
|
|
13
|
-
exports.canUser = canUser;
|
|
14
|
-
exports.canUserEditEntityRecord = canUserEditEntityRecord;
|
|
15
|
-
exports.getAutosaves = getAutosaves;
|
|
16
|
-
exports.getAutosave = getAutosave;
|
|
17
|
-
exports.__experimentalGetTemplateForLink = __experimentalGetTemplateForLink;
|
|
18
|
-
exports.getEditedEntityRecord = exports.getRawEntityRecord = void 0;
|
|
8
|
+
exports.__experimentalGetTemplateForLink = exports.getAutosave = exports.getAutosaves = exports.canUserEditEntityRecord = exports.canUser = exports.getEmbedPreview = exports.getThemeSupports = exports.getCurrentTheme = exports.getEntityRecords = exports.getEditedEntityRecord = exports.getRawEntityRecord = exports.getEntityRecord = exports.getCurrentUser = exports.getAuthors = void 0;
|
|
19
9
|
|
|
20
10
|
var _lodash = require("lodash");
|
|
21
11
|
|
|
22
12
|
var _url = require("@wordpress/url");
|
|
23
13
|
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
var _dataControls = require("@wordpress/data-controls");
|
|
27
|
-
|
|
28
|
-
var _controls = require("./controls");
|
|
14
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
29
15
|
|
|
30
16
|
var _name = require("./name");
|
|
31
17
|
|
|
32
|
-
var _actions = require("./actions");
|
|
33
|
-
|
|
34
18
|
var _entities = require("./entities");
|
|
35
19
|
|
|
36
20
|
var _utils = require("./utils");
|
|
37
21
|
|
|
38
|
-
var _locks = require("./locks");
|
|
39
|
-
|
|
40
22
|
/**
|
|
41
23
|
* External dependencies
|
|
42
24
|
*/
|
|
@@ -49,34 +31,36 @@ var _locks = require("./locks");
|
|
|
49
31
|
* Internal dependencies
|
|
50
32
|
*/
|
|
51
33
|
|
|
52
|
-
/**
|
|
53
|
-
* Internal dependencies
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
34
|
/**
|
|
57
35
|
* Requests authors from the REST API.
|
|
58
36
|
*
|
|
59
37
|
* @param {Object|undefined} query Optional object of query parameters to
|
|
60
38
|
* include with request.
|
|
61
39
|
*/
|
|
62
|
-
|
|
40
|
+
const getAuthors = query => async ({
|
|
41
|
+
dispatch
|
|
42
|
+
}) => {
|
|
63
43
|
const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
|
|
64
|
-
const users =
|
|
44
|
+
const users = await (0, _apiFetch.default)({
|
|
65
45
|
path
|
|
66
46
|
});
|
|
67
|
-
|
|
68
|
-
}
|
|
47
|
+
dispatch.receiveUserQuery(path, users);
|
|
48
|
+
};
|
|
69
49
|
/**
|
|
70
50
|
* Requests the current user from the REST API.
|
|
71
51
|
*/
|
|
72
52
|
|
|
73
53
|
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
exports.getAuthors = getAuthors;
|
|
55
|
+
|
|
56
|
+
const getCurrentUser = () => async ({
|
|
57
|
+
dispatch
|
|
58
|
+
}) => {
|
|
59
|
+
const currentUser = await (0, _apiFetch.default)({
|
|
76
60
|
path: '/wp/v2/users/me'
|
|
77
61
|
});
|
|
78
|
-
|
|
79
|
-
}
|
|
62
|
+
dispatch.receiveCurrentUser(currentUser);
|
|
63
|
+
};
|
|
80
64
|
/**
|
|
81
65
|
* Requests an entity's record from the REST API.
|
|
82
66
|
*
|
|
@@ -88,18 +72,23 @@ function* getCurrentUser() {
|
|
|
88
72
|
*/
|
|
89
73
|
|
|
90
74
|
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
exports.getCurrentUser = getCurrentUser;
|
|
76
|
+
|
|
77
|
+
const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
78
|
+
select,
|
|
79
|
+
dispatch
|
|
80
|
+
}) => {
|
|
81
|
+
const entities = await dispatch((0, _entities.getKindEntities)(kind));
|
|
93
82
|
const entity = (0, _lodash.find)(entities, {
|
|
94
83
|
kind,
|
|
95
84
|
name
|
|
96
85
|
});
|
|
97
86
|
|
|
98
|
-
if (!entity) {
|
|
87
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
99
88
|
return;
|
|
100
89
|
}
|
|
101
90
|
|
|
102
|
-
const lock =
|
|
91
|
+
const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name, key], {
|
|
103
92
|
exclusive: false
|
|
104
93
|
});
|
|
105
94
|
|
|
@@ -130,28 +119,29 @@ function* getEntityRecord(kind, name, key = '', query) {
|
|
|
130
119
|
// fields, so it's tested here, prior to initiating the REST request,
|
|
131
120
|
// and without causing `getEntityRecords` resolution to occur.
|
|
132
121
|
|
|
133
|
-
const hasRecords =
|
|
122
|
+
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
134
123
|
|
|
135
124
|
if (hasRecords) {
|
|
136
125
|
return;
|
|
137
126
|
}
|
|
138
127
|
}
|
|
139
128
|
|
|
140
|
-
const record =
|
|
129
|
+
const record = await (0, _apiFetch.default)({
|
|
141
130
|
path
|
|
142
131
|
});
|
|
143
|
-
|
|
132
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
144
133
|
} catch (error) {// We need a way to handle and access REST API errors in state
|
|
145
134
|
// Until then, catching the error ensures the resolver is marked as resolved.
|
|
146
135
|
} finally {
|
|
147
|
-
|
|
136
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
148
137
|
}
|
|
149
|
-
}
|
|
138
|
+
};
|
|
150
139
|
/**
|
|
151
140
|
* Requests an entity's record from the REST API.
|
|
152
141
|
*/
|
|
153
142
|
|
|
154
143
|
|
|
144
|
+
exports.getEntityRecord = getEntityRecord;
|
|
155
145
|
const getRawEntityRecord = (0, _utils.ifNotResolved)(getEntityRecord, 'getEntityRecord');
|
|
156
146
|
/**
|
|
157
147
|
* Requests an entity's record from the REST API.
|
|
@@ -169,18 +159,20 @@ const getEditedEntityRecord = (0, _utils.ifNotResolved)(getRawEntityRecord, 'get
|
|
|
169
159
|
|
|
170
160
|
exports.getEditedEntityRecord = getEditedEntityRecord;
|
|
171
161
|
|
|
172
|
-
|
|
173
|
-
|
|
162
|
+
const getEntityRecords = (kind, name, query = {}) => async ({
|
|
163
|
+
dispatch
|
|
164
|
+
}) => {
|
|
165
|
+
const entities = await dispatch((0, _entities.getKindEntities)(kind));
|
|
174
166
|
const entity = (0, _lodash.find)(entities, {
|
|
175
167
|
kind,
|
|
176
168
|
name
|
|
177
169
|
});
|
|
178
170
|
|
|
179
|
-
if (!entity) {
|
|
171
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
180
172
|
return;
|
|
181
173
|
}
|
|
182
174
|
|
|
183
|
-
const lock =
|
|
175
|
+
const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name], {
|
|
184
176
|
exclusive: false
|
|
185
177
|
});
|
|
186
178
|
|
|
@@ -199,7 +191,7 @@ function* getEntityRecords(kind, name, query = {}) {
|
|
|
199
191
|
const path = (0, _url.addQueryArgs)(entity.baseURL, { ...entity.baseURLParams,
|
|
200
192
|
...query
|
|
201
193
|
});
|
|
202
|
-
let records = Object.values(
|
|
194
|
+
let records = Object.values(await (0, _apiFetch.default)({
|
|
203
195
|
path
|
|
204
196
|
})); // If we request fields but the result doesn't contain the fields,
|
|
205
197
|
// explicitely set these fields as "undefined"
|
|
@@ -217,28 +209,30 @@ function* getEntityRecords(kind, name, query = {}) {
|
|
|
217
209
|
});
|
|
218
210
|
}
|
|
219
211
|
|
|
220
|
-
|
|
212
|
+
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
221
213
|
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
222
214
|
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
223
215
|
|
|
224
216
|
if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
|
|
225
217
|
const key = entity.key || _entities.DEFAULT_ENTITY_KEY;
|
|
226
218
|
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
227
|
-
|
|
219
|
+
dispatch({
|
|
228
220
|
type: 'START_RESOLUTIONS',
|
|
229
221
|
selectorName: 'getEntityRecord',
|
|
230
222
|
args: resolutionsArgs
|
|
231
|
-
};
|
|
232
|
-
|
|
223
|
+
});
|
|
224
|
+
dispatch({
|
|
233
225
|
type: 'FINISH_RESOLUTIONS',
|
|
234
226
|
selectorName: 'getEntityRecord',
|
|
235
227
|
args: resolutionsArgs
|
|
236
|
-
};
|
|
228
|
+
});
|
|
237
229
|
}
|
|
238
230
|
} finally {
|
|
239
|
-
|
|
231
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
240
232
|
}
|
|
241
|
-
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
exports.getEntityRecords = getEntityRecords;
|
|
242
236
|
|
|
243
237
|
getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
244
238
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name;
|
|
@@ -248,23 +242,29 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
|
248
242
|
*/
|
|
249
243
|
|
|
250
244
|
|
|
251
|
-
|
|
252
|
-
|
|
245
|
+
const getCurrentTheme = () => async ({
|
|
246
|
+
dispatch
|
|
247
|
+
}) => {
|
|
248
|
+
const activeThemes = await (0, _apiFetch.default)({
|
|
253
249
|
path: '/wp/v2/themes?status=active'
|
|
254
250
|
});
|
|
255
|
-
|
|
256
|
-
}
|
|
251
|
+
dispatch.receiveCurrentTheme(activeThemes[0]);
|
|
252
|
+
};
|
|
257
253
|
/**
|
|
258
254
|
* Requests theme supports data from the index.
|
|
259
255
|
*/
|
|
260
256
|
|
|
261
257
|
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
exports.getCurrentTheme = getCurrentTheme;
|
|
259
|
+
|
|
260
|
+
const getThemeSupports = () => async ({
|
|
261
|
+
dispatch
|
|
262
|
+
}) => {
|
|
263
|
+
const activeThemes = await (0, _apiFetch.default)({
|
|
264
264
|
path: '/wp/v2/themes?status=active'
|
|
265
265
|
});
|
|
266
|
-
|
|
267
|
-
}
|
|
266
|
+
dispatch.receiveThemeSupports(activeThemes[0].theme_supports);
|
|
267
|
+
};
|
|
268
268
|
/**
|
|
269
269
|
* Requests a preview from the from the Embed API.
|
|
270
270
|
*
|
|
@@ -272,19 +272,23 @@ function* getThemeSupports() {
|
|
|
272
272
|
*/
|
|
273
273
|
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
exports.getThemeSupports = getThemeSupports;
|
|
276
|
+
|
|
277
|
+
const getEmbedPreview = url => async ({
|
|
278
|
+
dispatch
|
|
279
|
+
}) => {
|
|
276
280
|
try {
|
|
277
|
-
const embedProxyResponse =
|
|
281
|
+
const embedProxyResponse = await (0, _apiFetch.default)({
|
|
278
282
|
path: (0, _url.addQueryArgs)('/oembed/1.0/proxy', {
|
|
279
283
|
url
|
|
280
284
|
})
|
|
281
285
|
});
|
|
282
|
-
|
|
286
|
+
dispatch.receiveEmbedPreview(url, embedProxyResponse);
|
|
283
287
|
} catch (error) {
|
|
284
288
|
// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
|
|
285
|
-
|
|
289
|
+
dispatch.receiveEmbedPreview(url, false);
|
|
286
290
|
}
|
|
287
|
-
}
|
|
291
|
+
};
|
|
288
292
|
/**
|
|
289
293
|
* Checks whether the current user can perform the given action on the given
|
|
290
294
|
* REST resource.
|
|
@@ -296,7 +300,11 @@ function* getEmbedPreview(url) {
|
|
|
296
300
|
*/
|
|
297
301
|
|
|
298
302
|
|
|
299
|
-
|
|
303
|
+
exports.getEmbedPreview = getEmbedPreview;
|
|
304
|
+
|
|
305
|
+
const canUser = (action, resource, id) => async ({
|
|
306
|
+
dispatch
|
|
307
|
+
}) => {
|
|
300
308
|
const methods = {
|
|
301
309
|
create: 'POST',
|
|
302
310
|
read: 'GET',
|
|
@@ -313,7 +321,7 @@ function* canUser(action, resource, id) {
|
|
|
313
321
|
let response;
|
|
314
322
|
|
|
315
323
|
try {
|
|
316
|
-
response =
|
|
324
|
+
response = await (0, _apiFetch.default)({
|
|
317
325
|
path,
|
|
318
326
|
// Ideally this would always be an OPTIONS request, but unfortunately there's
|
|
319
327
|
// a bug in the REST API which causes the Allow header to not be sent on
|
|
@@ -342,8 +350,8 @@ function* canUser(action, resource, id) {
|
|
|
342
350
|
|
|
343
351
|
const key = (0, _lodash.compact)([action, resource, id]).join('/');
|
|
344
352
|
const isAllowed = (0, _lodash.includes)(allowHeader, method);
|
|
345
|
-
|
|
346
|
-
}
|
|
353
|
+
dispatch.receiveUserPermission(key, isAllowed);
|
|
354
|
+
};
|
|
347
355
|
/**
|
|
348
356
|
* Checks whether the current user can perform the given action on the given
|
|
349
357
|
* REST resource.
|
|
@@ -354,8 +362,12 @@ function* canUser(action, resource, id) {
|
|
|
354
362
|
*/
|
|
355
363
|
|
|
356
364
|
|
|
357
|
-
|
|
358
|
-
|
|
365
|
+
exports.canUser = canUser;
|
|
366
|
+
|
|
367
|
+
const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
368
|
+
dispatch
|
|
369
|
+
}) => {
|
|
370
|
+
const entities = await dispatch((0, _entities.getKindEntities)(kind));
|
|
359
371
|
const entity = (0, _lodash.find)(entities, {
|
|
360
372
|
kind,
|
|
361
373
|
name
|
|
@@ -366,8 +378,8 @@ function* canUserEditEntityRecord(kind, name, recordId) {
|
|
|
366
378
|
}
|
|
367
379
|
|
|
368
380
|
const resource = entity.__unstable_rest_base;
|
|
369
|
-
|
|
370
|
-
}
|
|
381
|
+
await dispatch(canUser('update', resource, recordId));
|
|
382
|
+
};
|
|
371
383
|
/**
|
|
372
384
|
* Request autosave data from the REST API.
|
|
373
385
|
*
|
|
@@ -376,18 +388,23 @@ function* canUserEditEntityRecord(kind, name, recordId) {
|
|
|
376
388
|
*/
|
|
377
389
|
|
|
378
390
|
|
|
379
|
-
|
|
391
|
+
exports.canUserEditEntityRecord = canUserEditEntityRecord;
|
|
392
|
+
|
|
393
|
+
const getAutosaves = (postType, postId) => async ({
|
|
394
|
+
dispatch,
|
|
395
|
+
resolveSelect
|
|
396
|
+
}) => {
|
|
380
397
|
const {
|
|
381
398
|
rest_base: restBase
|
|
382
|
-
} =
|
|
383
|
-
const autosaves =
|
|
399
|
+
} = await resolveSelect.getPostType(postType);
|
|
400
|
+
const autosaves = await (0, _apiFetch.default)({
|
|
384
401
|
path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit`
|
|
385
402
|
});
|
|
386
403
|
|
|
387
404
|
if (autosaves && autosaves.length) {
|
|
388
|
-
|
|
405
|
+
dispatch.receiveAutosaves(postId, autosaves);
|
|
389
406
|
}
|
|
390
|
-
}
|
|
407
|
+
};
|
|
391
408
|
/**
|
|
392
409
|
* Request autosave data from the REST API.
|
|
393
410
|
*
|
|
@@ -399,9 +416,13 @@ function* getAutosaves(postType, postId) {
|
|
|
399
416
|
*/
|
|
400
417
|
|
|
401
418
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
419
|
+
exports.getAutosaves = getAutosaves;
|
|
420
|
+
|
|
421
|
+
const getAutosave = (postType, postId) => async ({
|
|
422
|
+
resolveSelect
|
|
423
|
+
}) => {
|
|
424
|
+
await resolveSelect.getAutosaves(postType, postId);
|
|
425
|
+
};
|
|
405
426
|
/**
|
|
406
427
|
* Retrieve the frontend template used for a given link.
|
|
407
428
|
*
|
|
@@ -409,16 +430,23 @@ function* getAutosave(postType, postId) {
|
|
|
409
430
|
*/
|
|
410
431
|
|
|
411
432
|
|
|
412
|
-
|
|
433
|
+
exports.getAutosave = getAutosave;
|
|
434
|
+
|
|
435
|
+
const __experimentalGetTemplateForLink = link => async ({
|
|
436
|
+
dispatch,
|
|
437
|
+
resolveSelect
|
|
438
|
+
}) => {
|
|
413
439
|
// Ideally this should be using an apiFetch call
|
|
414
440
|
// We could potentially do so by adding a "filter" to the `wp_template` end point.
|
|
415
441
|
// Also it seems the returned object is not a regular REST API post type.
|
|
416
442
|
let template;
|
|
417
443
|
|
|
418
444
|
try {
|
|
419
|
-
template =
|
|
445
|
+
template = await window.fetch((0, _url.addQueryArgs)(link, {
|
|
420
446
|
'_wp-find-template': true
|
|
421
|
-
}))
|
|
447
|
+
})).then(res => res.json()).then(({
|
|
448
|
+
data
|
|
449
|
+
}) => data);
|
|
422
450
|
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
423
451
|
}
|
|
424
452
|
|
|
@@ -426,15 +454,16 @@ function* __experimentalGetTemplateForLink(link) {
|
|
|
426
454
|
return;
|
|
427
455
|
}
|
|
428
456
|
|
|
429
|
-
|
|
430
|
-
const record = yield _data.controls.select(_name.STORE_NAME, 'getEntityRecord', 'postType', 'wp_template', template.id);
|
|
457
|
+
const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id);
|
|
431
458
|
|
|
432
459
|
if (record) {
|
|
433
|
-
|
|
460
|
+
dispatch.receiveEntityRecords('postType', 'wp_template', [record], {
|
|
434
461
|
'find-template': link
|
|
435
462
|
});
|
|
436
463
|
}
|
|
437
|
-
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
exports.__experimentalGetTemplateForLink = __experimentalGetTemplateForLink;
|
|
438
467
|
|
|
439
468
|
__experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
440
469
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
package/build/resolvers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","path","users","getCurrentUser","currentUser","getEntityRecord","kind","name","key","entities","entity","lock","STORE_NAME","exclusive","undefined","_fields","DEFAULT_ENTITY_KEY","join","baseURL","baseURLParams","include","hasRecords","controls","select","record","error","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","activeThemes","getThemeSupports","theme_supports","getEmbedPreview","url","embedProxyResponse","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","get","isAllowed","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","resolveSelect","autosaves","length","getAutosave","__experimentalGetTemplateForLink","link","template","e"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAIA;;AACA;;AAKA;;AAUA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACO,UAAUA,UAAV,CAAsBC,KAAtB,EAA8B;AACpC,QAAMC,IAAI,GAAG,uBACZ,wCADY,EAEZD,KAFY,CAAb;AAIA,QAAME,KAAK,GAAG,MAAM,4BAAU;AAAED,IAAAA;AAAF,GAAV,CAApB;AACA,QAAM,+BAAkBA,IAAlB,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AAgB,aAJjB;AAMA,CAPD","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport { controls } from '@wordpress/data';\nimport { apiFetch } from '@wordpress/data-controls';\n/**\n * Internal dependencies\n */\nimport { regularFetch } from './controls';\nimport { STORE_NAME } from './name';\n\n/**\n * Internal dependencies\n */\nimport {\n\treceiveUserQuery,\n\treceiveCurrentTheme,\n\treceiveCurrentUser,\n\treceiveEntityRecords,\n\treceiveThemeSupports,\n\treceiveEmbedPreview,\n\treceiveUserPermission,\n\treceiveAutosaves,\n} from './actions';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { ifNotResolved, getNormalizedCommaSeparable } from './utils';\nimport {\n\t__unstableAcquireStoreLock,\n\t__unstableReleaseStoreLock,\n} from './locks';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport function* getAuthors( query ) {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = yield apiFetch( { path } );\n\tyield receiveUserQuery( path, users );\n}\n\n/**\n * Requests the current user from the REST API.\n */\nexport function* getCurrentUser() {\n\tconst currentUser = yield apiFetch( { path: '/wp/v2/users/me' } );\n\tyield receiveCurrentUser( currentUser );\n}\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport function* getEntityRecord( kind, name, key = '', query ) {\n\tconst entities = yield getKindEntities( kind );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst lock = yield* __unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + '/' + key, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = yield controls.select(\n\t\t\t\tSTORE_NAME,\n\t\t\t\t'hasEntityRecords',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tquery\n\t\t\t);\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = yield apiFetch( { path } );\n\t\tyield receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t} finally {\n\t\tyield* __unstableReleaseStoreLock( lock );\n\t}\n}\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = ifNotResolved(\n\tgetEntityRecord,\n\t'getEntityRecord'\n);\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = ifNotResolved(\n\tgetRawEntityRecord,\n\t'getRawEntityRecord'\n);\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport function* getEntityRecords( kind, name, query = {} ) {\n\tconst entities = yield getKindEntities( kind );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst lock = yield* __unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( yield apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tyield receiveEntityRecords( kind, name, records, query );\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tyield {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t};\n\t\t\tyield {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t};\n\t\t}\n\t} finally {\n\t\tyield* __unstableReleaseStoreLock( lock );\n\t}\n}\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport function* getCurrentTheme() {\n\tconst activeThemes = yield apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tyield receiveCurrentTheme( activeThemes[ 0 ] );\n}\n\n/**\n * Requests theme supports data from the index.\n */\nexport function* getThemeSupports() {\n\tconst activeThemes = yield apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tyield receiveThemeSupports( activeThemes[ 0 ].theme_supports );\n}\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport function* getEmbedPreview( url ) {\n\ttry {\n\t\tconst embedProxyResponse = yield apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tyield receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tyield receiveEmbedPreview( url, false );\n\t}\n}\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport function* canUser( action, resource, id ) {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = yield apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tyield receiveUserPermission( key, isAllowed );\n}\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport function* canUserEditEntityRecord( kind, name, recordId ) {\n\tconst entities = yield getKindEntities( kind );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tyield canUser( 'update', resource, recordId );\n}\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport function* getAutosaves( postType, postId ) {\n\tconst { rest_base: restBase } = yield controls.resolveSelect(\n\t\tSTORE_NAME,\n\t\t'getPostType',\n\t\tpostType\n\t);\n\tconst autosaves = yield apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tyield receiveAutosaves( postId, autosaves );\n\t}\n}\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport function* getAutosave( postType, postId ) {\n\tyield controls.resolveSelect(\n\t\tSTORE_NAME,\n\t\t'getAutosaves',\n\t\tpostType,\n\t\tpostId\n\t);\n}\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport function* __experimentalGetTemplateForLink( link ) {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = yield regularFetch(\n\t\t\taddQueryArgs( link, {\n\t\t\t\t'_wp-find-template': true,\n\t\t\t} )\n\t\t);\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tyield getEntityRecord( 'postType', 'wp_template', template.id );\n\tconst record = yield controls.select(\n\t\tSTORE_NAME,\n\t\t'getEntityRecord',\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tyield receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n}\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","DEFAULT_ENTITY_KEY","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","activeThemes","receiveCurrentTheme","getThemeSupports","receiveThemeSupports","theme_supports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","get","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","resolveSelect","rest_base","restBase","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAKC,KAAF,IAAa,O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B,eAAhB,IAAmCI,MAAM,CAACJ,IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAAC1C,IAAP,KAAgB,UAFhB,IAGA0C,MAAM,CAACzC,IAAP,KAAgB,aAJjB;AAMA,CAPD","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { ifNotResolved, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + '/' + key, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = ifNotResolved(\n\tgetEntityRecord,\n\t'getEntityRecord'\n);\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = ifNotResolved(\n\tgetRawEntityRecord,\n\t'getRawEntityRecord'\n);\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme = () => async ( { dispatch } ) => {\n\tconst activeThemes = await apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = () => async ( { dispatch } ) => {\n\tconst activeThemes = await apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tdispatch.receiveThemeSupports( activeThemes[ 0 ].theme_supports );\n};\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n"]}
|
package/build/selectors.js
CHANGED
|
@@ -9,7 +9,6 @@ exports.getAuthors = getAuthors;
|
|
|
9
9
|
exports.getCurrentUser = getCurrentUser;
|
|
10
10
|
exports.getEntitiesByKind = getEntitiesByKind;
|
|
11
11
|
exports.getEntity = getEntity;
|
|
12
|
-
exports.getEntityRecord = getEntityRecord;
|
|
13
12
|
exports.__experimentalGetEntityRecordNoResolver = __experimentalGetEntityRecordNoResolver;
|
|
14
13
|
exports.hasEntityRecords = hasEntityRecords;
|
|
15
14
|
exports.getEntityRecords = getEntityRecords;
|
|
@@ -33,7 +32,7 @@ exports.canUserEditEntityRecord = canUserEditEntityRecord;
|
|
|
33
32
|
exports.getAutosaves = getAutosaves;
|
|
34
33
|
exports.getAutosave = getAutosave;
|
|
35
34
|
exports.__experimentalGetTemplateForLink = __experimentalGetTemplateForLink;
|
|
36
|
-
exports.getReferenceByDistinctEdits = exports.hasFetchedAutosaves = exports.getEditedEntityRecord = exports.getEntityRecordNonTransientEdits = exports.__experimentalGetEntitiesBeingSaved = exports.__experimentalGetDirtyEntityRecords = exports.getRawEntityRecord = exports.getUserQueryResults = exports.isRequestingEmbedPreview = void 0;
|
|
35
|
+
exports.getReferenceByDistinctEdits = exports.hasFetchedAutosaves = exports.getEditedEntityRecord = exports.getEntityRecordNonTransientEdits = exports.__experimentalGetEntitiesBeingSaved = exports.__experimentalGetDirtyEntityRecords = exports.getRawEntityRecord = exports.getEntityRecord = exports.getUserQueryResults = exports.isRequestingEmbedPreview = void 0;
|
|
37
36
|
|
|
38
37
|
var _rememo = _interopRequireDefault(require("rememo"));
|
|
39
38
|
|
|
@@ -183,7 +182,7 @@ function getEntity(state, kind, name) {
|
|
|
183
182
|
*/
|
|
184
183
|
|
|
185
184
|
|
|
186
|
-
|
|
185
|
+
const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) => {
|
|
187
186
|
var _query$context, _queriedState$items$c;
|
|
188
187
|
|
|
189
188
|
const queriedState = (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData']);
|
|
@@ -221,7 +220,12 @@ function getEntityRecord(state, kind, name, key, query) {
|
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
return item;
|
|
224
|
-
}
|
|
223
|
+
}, (state, kind, name, recordId, query) => {
|
|
224
|
+
var _query$context2;
|
|
225
|
+
|
|
226
|
+
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
227
|
+
return [(0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
228
|
+
});
|
|
225
229
|
/**
|
|
226
230
|
* Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.
|
|
227
231
|
*
|
|
@@ -233,6 +237,7 @@ function getEntityRecord(state, kind, name, key, query) {
|
|
|
233
237
|
* @return {Object|null} Record.
|
|
234
238
|
*/
|
|
235
239
|
|
|
240
|
+
exports.getEntityRecord = getEntityRecord;
|
|
236
241
|
|
|
237
242
|
function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
238
243
|
return getEntityRecord(state, kind, name, key);
|
|
@@ -253,13 +258,23 @@ function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
|
253
258
|
const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
|
|
254
259
|
const record = getEntityRecord(state, kind, name, key);
|
|
255
260
|
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
261
|
+
if ((0, _utils.isRawAttribute)(getEntity(state, kind, name), _key)) {
|
|
262
|
+
// Because edits are the "raw" attribute values,
|
|
263
|
+
// we return those from record selectors to make rendering,
|
|
264
|
+
// comparisons, and joins with edits easier.
|
|
265
|
+
accumulator[_key] = (0, _lodash.get)(record[_key], 'raw', record[_key]);
|
|
266
|
+
} else {
|
|
267
|
+
accumulator[_key] = record[_key];
|
|
268
|
+
}
|
|
269
|
+
|
|
260
270
|
return accumulator;
|
|
261
271
|
}, {});
|
|
262
|
-
}, state =>
|
|
272
|
+
}, (state, kind, name, recordId, query) => {
|
|
273
|
+
var _query$context3;
|
|
274
|
+
|
|
275
|
+
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
276
|
+
return [state.entities.config, (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
277
|
+
});
|
|
263
278
|
/**
|
|
264
279
|
* Returns true if records have been received for the given set of parameters,
|
|
265
280
|
* or false otherwise.
|
|
@@ -434,7 +449,7 @@ const getEntityRecordNonTransientEdits = (0, _rememo.default)((state, kind, name
|
|
|
434
449
|
|
|
435
450
|
return acc;
|
|
436
451
|
}, {});
|
|
437
|
-
}, state => [state.entities.config, state.entities.data]);
|
|
452
|
+
}, (state, kind, name, recordId) => [state.entities.config, (0, _lodash.get)(state.entities.data, [kind, name, 'edits', recordId])]);
|
|
438
453
|
/**
|
|
439
454
|
* Returns true if the specified entity record has edits,
|
|
440
455
|
* and false otherwise.
|
|
@@ -466,7 +481,12 @@ function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
466
481
|
|
|
467
482
|
const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
468
483
|
...getEntityRecordEdits(state, kind, name, recordId)
|
|
469
|
-
}), state =>
|
|
484
|
+
}), (state, kind, name, recordId, query) => {
|
|
485
|
+
var _query$context4;
|
|
486
|
+
|
|
487
|
+
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
488
|
+
return [state.entities.config, (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0, _lodash.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), (0, _lodash.get)(state.entities.data, [kind, name, 'edits', recordId])];
|
|
489
|
+
});
|
|
470
490
|
/**
|
|
471
491
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
472
492
|
*
|