@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
|
@@ -7,22 +7,14 @@ import { find, includes, get, hasIn, compact, uniq } from 'lodash';
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { addQueryArgs } from '@wordpress/url';
|
|
10
|
-
import
|
|
11
|
-
import { apiFetch } from '@wordpress/data-controls';
|
|
10
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
12
11
|
/**
|
|
13
12
|
* Internal dependencies
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
|
-
import { regularFetch } from './controls';
|
|
17
15
|
import { STORE_NAME } from './name';
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { receiveUserQuery, receiveCurrentTheme, receiveCurrentUser, receiveEntityRecords, receiveThemeSupports, receiveEmbedPreview, receiveUserPermission, receiveAutosaves } from './actions';
|
|
23
16
|
import { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';
|
|
24
17
|
import { ifNotResolved, getNormalizedCommaSeparable } from './utils';
|
|
25
|
-
import { __unstableAcquireStoreLock, __unstableReleaseStoreLock } from './locks';
|
|
26
18
|
/**
|
|
27
19
|
* Requests authors from the REST API.
|
|
28
20
|
*
|
|
@@ -30,23 +22,27 @@ import { __unstableAcquireStoreLock, __unstableReleaseStoreLock } from './locks'
|
|
|
30
22
|
* include with request.
|
|
31
23
|
*/
|
|
32
24
|
|
|
33
|
-
export
|
|
25
|
+
export const getAuthors = query => async ({
|
|
26
|
+
dispatch
|
|
27
|
+
}) => {
|
|
34
28
|
const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
|
|
35
|
-
const users =
|
|
29
|
+
const users = await apiFetch({
|
|
36
30
|
path
|
|
37
31
|
});
|
|
38
|
-
|
|
39
|
-
}
|
|
32
|
+
dispatch.receiveUserQuery(path, users);
|
|
33
|
+
};
|
|
40
34
|
/**
|
|
41
35
|
* Requests the current user from the REST API.
|
|
42
36
|
*/
|
|
43
37
|
|
|
44
|
-
export
|
|
45
|
-
|
|
38
|
+
export const getCurrentUser = () => async ({
|
|
39
|
+
dispatch
|
|
40
|
+
}) => {
|
|
41
|
+
const currentUser = await apiFetch({
|
|
46
42
|
path: '/wp/v2/users/me'
|
|
47
43
|
});
|
|
48
|
-
|
|
49
|
-
}
|
|
44
|
+
dispatch.receiveCurrentUser(currentUser);
|
|
45
|
+
};
|
|
50
46
|
/**
|
|
51
47
|
* Requests an entity's record from the REST API.
|
|
52
48
|
*
|
|
@@ -57,18 +53,21 @@ export function* getCurrentUser() {
|
|
|
57
53
|
* include with request.
|
|
58
54
|
*/
|
|
59
55
|
|
|
60
|
-
export
|
|
61
|
-
|
|
56
|
+
export const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
57
|
+
select,
|
|
58
|
+
dispatch
|
|
59
|
+
}) => {
|
|
60
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
62
61
|
const entity = find(entities, {
|
|
63
62
|
kind,
|
|
64
63
|
name
|
|
65
64
|
});
|
|
66
65
|
|
|
67
|
-
if (!entity) {
|
|
66
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
const lock =
|
|
70
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
|
|
72
71
|
exclusive: false
|
|
73
72
|
});
|
|
74
73
|
|
|
@@ -99,23 +98,23 @@ export function* getEntityRecord(kind, name, key = '', query) {
|
|
|
99
98
|
// fields, so it's tested here, prior to initiating the REST request,
|
|
100
99
|
// and without causing `getEntityRecords` resolution to occur.
|
|
101
100
|
|
|
102
|
-
const hasRecords =
|
|
101
|
+
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
103
102
|
|
|
104
103
|
if (hasRecords) {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
const record =
|
|
108
|
+
const record = await apiFetch({
|
|
110
109
|
path
|
|
111
110
|
});
|
|
112
|
-
|
|
111
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
113
112
|
} catch (error) {// We need a way to handle and access REST API errors in state
|
|
114
113
|
// Until then, catching the error ensures the resolver is marked as resolved.
|
|
115
114
|
} finally {
|
|
116
|
-
|
|
115
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
117
116
|
}
|
|
118
|
-
}
|
|
117
|
+
};
|
|
119
118
|
/**
|
|
120
119
|
* Requests an entity's record from the REST API.
|
|
121
120
|
*/
|
|
@@ -134,18 +133,20 @@ export const getEditedEntityRecord = ifNotResolved(getRawEntityRecord, 'getRawEn
|
|
|
134
133
|
* @param {Object?} query Query Object.
|
|
135
134
|
*/
|
|
136
135
|
|
|
137
|
-
export
|
|
138
|
-
|
|
136
|
+
export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
137
|
+
dispatch
|
|
138
|
+
}) => {
|
|
139
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
139
140
|
const entity = find(entities, {
|
|
140
141
|
kind,
|
|
141
142
|
name
|
|
142
143
|
});
|
|
143
144
|
|
|
144
|
-
if (!entity) {
|
|
145
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
const lock =
|
|
149
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
|
|
149
150
|
exclusive: false
|
|
150
151
|
});
|
|
151
152
|
|
|
@@ -164,7 +165,7 @@ export function* getEntityRecords(kind, name, query = {}) {
|
|
|
164
165
|
const path = addQueryArgs(entity.baseURL, { ...entity.baseURLParams,
|
|
165
166
|
...query
|
|
166
167
|
});
|
|
167
|
-
let records = Object.values(
|
|
168
|
+
let records = Object.values(await apiFetch({
|
|
168
169
|
path
|
|
169
170
|
})); // If we request fields but the result doesn't contain the fields,
|
|
170
171
|
// explicitely set these fields as "undefined"
|
|
@@ -182,28 +183,28 @@ export function* getEntityRecords(kind, name, query = {}) {
|
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
|
|
186
|
+
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
186
187
|
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
187
188
|
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
188
189
|
|
|
189
190
|
if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
|
|
190
191
|
const key = entity.key || DEFAULT_ENTITY_KEY;
|
|
191
192
|
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
192
|
-
|
|
193
|
+
dispatch({
|
|
193
194
|
type: 'START_RESOLUTIONS',
|
|
194
195
|
selectorName: 'getEntityRecord',
|
|
195
196
|
args: resolutionsArgs
|
|
196
|
-
};
|
|
197
|
-
|
|
197
|
+
});
|
|
198
|
+
dispatch({
|
|
198
199
|
type: 'FINISH_RESOLUTIONS',
|
|
199
200
|
selectorName: 'getEntityRecord',
|
|
200
201
|
args: resolutionsArgs
|
|
201
|
-
};
|
|
202
|
+
});
|
|
202
203
|
}
|
|
203
204
|
} finally {
|
|
204
|
-
|
|
205
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
205
206
|
}
|
|
206
|
-
}
|
|
207
|
+
};
|
|
207
208
|
|
|
208
209
|
getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
209
210
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name;
|
|
@@ -213,41 +214,47 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
|
213
214
|
*/
|
|
214
215
|
|
|
215
216
|
|
|
216
|
-
export
|
|
217
|
-
|
|
217
|
+
export const getCurrentTheme = () => async ({
|
|
218
|
+
dispatch
|
|
219
|
+
}) => {
|
|
220
|
+
const activeThemes = await apiFetch({
|
|
218
221
|
path: '/wp/v2/themes?status=active'
|
|
219
222
|
});
|
|
220
|
-
|
|
221
|
-
}
|
|
223
|
+
dispatch.receiveCurrentTheme(activeThemes[0]);
|
|
224
|
+
};
|
|
222
225
|
/**
|
|
223
226
|
* Requests theme supports data from the index.
|
|
224
227
|
*/
|
|
225
228
|
|
|
226
|
-
export
|
|
227
|
-
|
|
229
|
+
export const getThemeSupports = () => async ({
|
|
230
|
+
dispatch
|
|
231
|
+
}) => {
|
|
232
|
+
const activeThemes = await apiFetch({
|
|
228
233
|
path: '/wp/v2/themes?status=active'
|
|
229
234
|
});
|
|
230
|
-
|
|
231
|
-
}
|
|
235
|
+
dispatch.receiveThemeSupports(activeThemes[0].theme_supports);
|
|
236
|
+
};
|
|
232
237
|
/**
|
|
233
238
|
* Requests a preview from the from the Embed API.
|
|
234
239
|
*
|
|
235
240
|
* @param {string} url URL to get the preview for.
|
|
236
241
|
*/
|
|
237
242
|
|
|
238
|
-
export
|
|
243
|
+
export const getEmbedPreview = url => async ({
|
|
244
|
+
dispatch
|
|
245
|
+
}) => {
|
|
239
246
|
try {
|
|
240
|
-
const embedProxyResponse =
|
|
247
|
+
const embedProxyResponse = await apiFetch({
|
|
241
248
|
path: addQueryArgs('/oembed/1.0/proxy', {
|
|
242
249
|
url
|
|
243
250
|
})
|
|
244
251
|
});
|
|
245
|
-
|
|
252
|
+
dispatch.receiveEmbedPreview(url, embedProxyResponse);
|
|
246
253
|
} catch (error) {
|
|
247
254
|
// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
|
|
248
|
-
|
|
255
|
+
dispatch.receiveEmbedPreview(url, false);
|
|
249
256
|
}
|
|
250
|
-
}
|
|
257
|
+
};
|
|
251
258
|
/**
|
|
252
259
|
* Checks whether the current user can perform the given action on the given
|
|
253
260
|
* REST resource.
|
|
@@ -258,7 +265,9 @@ export function* getEmbedPreview(url) {
|
|
|
258
265
|
* @param {?string} id ID of the rest resource to check.
|
|
259
266
|
*/
|
|
260
267
|
|
|
261
|
-
export
|
|
268
|
+
export const canUser = (action, resource, id) => async ({
|
|
269
|
+
dispatch
|
|
270
|
+
}) => {
|
|
262
271
|
const methods = {
|
|
263
272
|
create: 'POST',
|
|
264
273
|
read: 'GET',
|
|
@@ -275,7 +284,7 @@ export function* canUser(action, resource, id) {
|
|
|
275
284
|
let response;
|
|
276
285
|
|
|
277
286
|
try {
|
|
278
|
-
response =
|
|
287
|
+
response = await apiFetch({
|
|
279
288
|
path,
|
|
280
289
|
// Ideally this would always be an OPTIONS request, but unfortunately there's
|
|
281
290
|
// a bug in the REST API which causes the Allow header to not be sent on
|
|
@@ -304,8 +313,8 @@ export function* canUser(action, resource, id) {
|
|
|
304
313
|
|
|
305
314
|
const key = compact([action, resource, id]).join('/');
|
|
306
315
|
const isAllowed = includes(allowHeader, method);
|
|
307
|
-
|
|
308
|
-
}
|
|
316
|
+
dispatch.receiveUserPermission(key, isAllowed);
|
|
317
|
+
};
|
|
309
318
|
/**
|
|
310
319
|
* Checks whether the current user can perform the given action on the given
|
|
311
320
|
* REST resource.
|
|
@@ -315,8 +324,10 @@ export function* canUser(action, resource, id) {
|
|
|
315
324
|
* @param {string} recordId Record's id.
|
|
316
325
|
*/
|
|
317
326
|
|
|
318
|
-
export
|
|
319
|
-
|
|
327
|
+
export const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
328
|
+
dispatch
|
|
329
|
+
}) => {
|
|
330
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
320
331
|
const entity = find(entities, {
|
|
321
332
|
kind,
|
|
322
333
|
name
|
|
@@ -327,8 +338,8 @@ export function* canUserEditEntityRecord(kind, name, recordId) {
|
|
|
327
338
|
}
|
|
328
339
|
|
|
329
340
|
const resource = entity.__unstable_rest_base;
|
|
330
|
-
|
|
331
|
-
}
|
|
341
|
+
await dispatch(canUser('update', resource, recordId));
|
|
342
|
+
};
|
|
332
343
|
/**
|
|
333
344
|
* Request autosave data from the REST API.
|
|
334
345
|
*
|
|
@@ -336,18 +347,21 @@ export function* canUserEditEntityRecord(kind, name, recordId) {
|
|
|
336
347
|
* @param {number} postId The id of the parent post.
|
|
337
348
|
*/
|
|
338
349
|
|
|
339
|
-
export
|
|
350
|
+
export const getAutosaves = (postType, postId) => async ({
|
|
351
|
+
dispatch,
|
|
352
|
+
resolveSelect
|
|
353
|
+
}) => {
|
|
340
354
|
const {
|
|
341
355
|
rest_base: restBase
|
|
342
|
-
} =
|
|
343
|
-
const autosaves =
|
|
356
|
+
} = await resolveSelect.getPostType(postType);
|
|
357
|
+
const autosaves = await apiFetch({
|
|
344
358
|
path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit`
|
|
345
359
|
});
|
|
346
360
|
|
|
347
361
|
if (autosaves && autosaves.length) {
|
|
348
|
-
|
|
362
|
+
dispatch.receiveAutosaves(postId, autosaves);
|
|
349
363
|
}
|
|
350
|
-
}
|
|
364
|
+
};
|
|
351
365
|
/**
|
|
352
366
|
* Request autosave data from the REST API.
|
|
353
367
|
*
|
|
@@ -358,25 +372,32 @@ export function* getAutosaves(postType, postId) {
|
|
|
358
372
|
* @param {number} postId The id of the parent post.
|
|
359
373
|
*/
|
|
360
374
|
|
|
361
|
-
export
|
|
362
|
-
|
|
363
|
-
}
|
|
375
|
+
export const getAutosave = (postType, postId) => async ({
|
|
376
|
+
resolveSelect
|
|
377
|
+
}) => {
|
|
378
|
+
await resolveSelect.getAutosaves(postType, postId);
|
|
379
|
+
};
|
|
364
380
|
/**
|
|
365
381
|
* Retrieve the frontend template used for a given link.
|
|
366
382
|
*
|
|
367
383
|
* @param {string} link Link.
|
|
368
384
|
*/
|
|
369
385
|
|
|
370
|
-
export
|
|
386
|
+
export const __experimentalGetTemplateForLink = link => async ({
|
|
387
|
+
dispatch,
|
|
388
|
+
resolveSelect
|
|
389
|
+
}) => {
|
|
371
390
|
// Ideally this should be using an apiFetch call
|
|
372
391
|
// We could potentially do so by adding a "filter" to the `wp_template` end point.
|
|
373
392
|
// Also it seems the returned object is not a regular REST API post type.
|
|
374
393
|
let template;
|
|
375
394
|
|
|
376
395
|
try {
|
|
377
|
-
template =
|
|
396
|
+
template = await window.fetch(addQueryArgs(link, {
|
|
378
397
|
'_wp-find-template': true
|
|
379
|
-
}))
|
|
398
|
+
})).then(res => res.json()).then(({
|
|
399
|
+
data
|
|
400
|
+
}) => data);
|
|
380
401
|
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
381
402
|
}
|
|
382
403
|
|
|
@@ -384,15 +405,14 @@ export function* __experimentalGetTemplateForLink(link) {
|
|
|
384
405
|
return;
|
|
385
406
|
}
|
|
386
407
|
|
|
387
|
-
|
|
388
|
-
const record = yield controls.select(STORE_NAME, 'getEntityRecord', 'postType', 'wp_template', template.id);
|
|
408
|
+
const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id);
|
|
389
409
|
|
|
390
410
|
if (record) {
|
|
391
|
-
|
|
411
|
+
dispatch.receiveEntityRecords('postType', 'wp_template', [record], {
|
|
392
412
|
'find-template': link
|
|
393
413
|
});
|
|
394
414
|
}
|
|
395
|
-
}
|
|
415
|
+
};
|
|
396
416
|
|
|
397
417
|
__experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
398
418
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","hasIn","compact","uniq","addQueryArgs","controls","apiFetch","regularFetch","STORE_NAME","receiveUserQuery","receiveCurrentTheme","receiveCurrentUser","receiveEntityRecords","receiveThemeSupports","receiveEmbedPreview","receiveUserPermission","receiveAutosaves","getKindEntities","DEFAULT_ENTITY_KEY","ifNotResolved","getNormalizedCommaSeparable","__unstableAcquireStoreLock","__unstableReleaseStoreLock","getAuthors","query","path","users","getCurrentUser","currentUser","getEntityRecord","kind","name","key","entities","entity","lock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","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","isAllowed","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","resolveSelect","autosaves","length","getAutosave","__experimentalGetTemplateForLink","link","template","e"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,QAAT,QAAyB,iBAAzB;AACA,SAASC,QAAT,QAAyB,0BAAzB;AACA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,YAA7B;AACA,SAASC,UAAT,QAA2B,QAA3B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,mBAFD,EAGCC,kBAHD,EAICC,oBAJD,EAKCC,oBALD,EAMCC,mBAND,EAOCC,qBAPD,EAQCC,gBARD,QASO,WATP;AAUA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,aAAT,EAAwBC,2BAAxB,QAA2D,SAA3D;AACA,SACCC,0BADD,EAECC,0BAFD,QAGO,SAHP;AAKA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,UAAUC,UAAV,CAAsBC,KAAtB,EAA8B;AACpC,QA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AACjB;AACA;;AAED,QAAM1E,eAAe,CAAE,UAAF,EAAc,aAAd,EAA6B0E,QAAQ,CAAC3B,EAAtC,CAArB;AACA,QAAM/B,MAAM,GAAG,MAAMxC,QAAQ,CAACuC,MAAT,CACpBpC,UADoB,EAEpB,iBAFoB,EAGpB,UAHoB,EAIpB,aAJoB,EAKpB+F,QAAQ,CAAC3B,EALW,CAArB;;AAQA,MAAK/B,MAAL,EAAc;AACb,UAAMjC,oBAAoB,CAAE,UAAF,EAAc,aAAd,EAA6B,CAAEiC,MAAF,CAA7B,EAAyC;AAClE,uBAAiByD;AADiD,KAAzC,CAA1B;AAGA;AACD;;AAEDD,gCAAgC,CAACrC,gBAAjC,GAAsDC,MAAF,IAAc;AACjE,SACC,CAAEA,MAAM,CAACJ,IAAP,KAAgB,eAAhB,IAAmCI,MAAM,CAACJ,IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAACnC,IAAP,KAAgB,UAFhB,IAGAmC,MAAM,CAAClC,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 { 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":["find","includes","get","hasIn","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","ifNotResolved","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","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","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":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,aAAT,EAAwBC,2BAAxB,QAA2D,SAA3D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAKC,KAAF,IAAa,OAAQ;AAAEC,EAAAA;AAAF,CAAR,KAA0B;AAChE,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,GAAF,CAA5B;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CAPM;AASP;AAC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J,IAAP,KAAgB,eAAhB,IAAmCI,MAAM,CAACJ,IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAACxC,IAAP,KAAgB,UAFhB,IAGAwC,MAAM,CAACvC,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"]}
|
|
@@ -17,7 +17,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
17
17
|
import { STORE_NAME } from './name';
|
|
18
18
|
import { getQueriedItems } from './queried-data';
|
|
19
19
|
import { DEFAULT_ENTITY_KEY } from './entities';
|
|
20
|
-
import { getNormalizedCommaSeparable } from './utils';
|
|
20
|
+
import { getNormalizedCommaSeparable, isRawAttribute } from './utils';
|
|
21
21
|
/**
|
|
22
22
|
* Shared reference to an empty array for cases where it is important to avoid
|
|
23
23
|
* returning a new array reference on every invocation, as in a connected or
|
|
@@ -129,7 +129,7 @@ export function getEntity(state, kind, name) {
|
|
|
129
129
|
* @return {Object?} Record.
|
|
130
130
|
*/
|
|
131
131
|
|
|
132
|
-
export
|
|
132
|
+
export const getEntityRecord = createSelector((state, kind, name, key, query) => {
|
|
133
133
|
var _query$context, _queriedState$items$c;
|
|
134
134
|
|
|
135
135
|
const queriedState = get(state.entities.data, [kind, name, 'queriedData']);
|
|
@@ -167,7 +167,12 @@ export function getEntityRecord(state, kind, name, key, query) {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
return item;
|
|
170
|
-
}
|
|
170
|
+
}, (state, kind, name, recordId, query) => {
|
|
171
|
+
var _query$context2;
|
|
172
|
+
|
|
173
|
+
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
174
|
+
return [get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
175
|
+
});
|
|
171
176
|
/**
|
|
172
177
|
* 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.
|
|
173
178
|
*
|
|
@@ -197,13 +202,23 @@ export function __experimentalGetEntityRecordNoResolver(state, kind, name, key)
|
|
|
197
202
|
export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
198
203
|
const record = getEntityRecord(state, kind, name, key);
|
|
199
204
|
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
if (isRawAttribute(getEntity(state, kind, name), _key)) {
|
|
206
|
+
// Because edits are the "raw" attribute values,
|
|
207
|
+
// we return those from record selectors to make rendering,
|
|
208
|
+
// comparisons, and joins with edits easier.
|
|
209
|
+
accumulator[_key] = get(record[_key], 'raw', record[_key]);
|
|
210
|
+
} else {
|
|
211
|
+
accumulator[_key] = record[_key];
|
|
212
|
+
}
|
|
213
|
+
|
|
204
214
|
return accumulator;
|
|
205
215
|
}, {});
|
|
206
|
-
}, state =>
|
|
216
|
+
}, (state, kind, name, recordId, query) => {
|
|
217
|
+
var _query$context3;
|
|
218
|
+
|
|
219
|
+
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
220
|
+
return [state.entities.config, get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
221
|
+
});
|
|
207
222
|
/**
|
|
208
223
|
* Returns true if records have been received for the given set of parameters,
|
|
209
224
|
* or false otherwise.
|
|
@@ -367,7 +382,7 @@ export const getEntityRecordNonTransientEdits = createSelector((state, kind, nam
|
|
|
367
382
|
|
|
368
383
|
return acc;
|
|
369
384
|
}, {});
|
|
370
|
-
}, state => [state.entities.config, state.entities.data]);
|
|
385
|
+
}, (state, kind, name, recordId) => [state.entities.config, get(state.entities.data, [kind, name, 'edits', recordId])]);
|
|
371
386
|
/**
|
|
372
387
|
* Returns true if the specified entity record has edits,
|
|
373
388
|
* and false otherwise.
|
|
@@ -396,7 +411,12 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
396
411
|
|
|
397
412
|
export const getEditedEntityRecord = createSelector((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
398
413
|
...getEntityRecordEdits(state, kind, name, recordId)
|
|
399
|
-
}), state =>
|
|
414
|
+
}), (state, kind, name, recordId, query) => {
|
|
415
|
+
var _query$context4;
|
|
416
|
+
|
|
417
|
+
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
418
|
+
return [state.entities.config, get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), get(state.entities.data, [kind, name, 'edits', recordId])];
|
|
419
|
+
});
|
|
400
420
|
/**
|
|
401
421
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
402
422
|
*
|