@wordpress/core-data 4.11.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +2 -81
- package/build/actions.js +27 -0
- package/build/actions.js.map +1 -1
- package/build/resolvers.js +5 -3
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +5 -3
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +27 -0
- package/build-module/actions.js.map +1 -1
- package/build-module/resolvers.js +6 -4
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +6 -4
- package/build-module/selectors.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.js +27 -0
- package/src/resolvers.js +6 -13
- package/src/selectors.ts +6 -4
package/src/resolvers.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
camelCase,
|
|
6
|
-
compact,
|
|
7
|
-
find,
|
|
8
|
-
get,
|
|
9
|
-
includes,
|
|
10
|
-
map,
|
|
11
|
-
mapKeys,
|
|
12
|
-
uniq,
|
|
13
|
-
} from 'lodash';
|
|
4
|
+
import { camelCase, find, get, includes, map, mapKeys, uniq } from 'lodash';
|
|
14
5
|
|
|
15
6
|
/**
|
|
16
7
|
* WordPress dependencies
|
|
@@ -59,7 +50,8 @@ export const getCurrentUser =
|
|
|
59
50
|
* @param {string} name Entity name.
|
|
60
51
|
* @param {number|string} key Record's key
|
|
61
52
|
* @param {Object|undefined} query Optional object of query parameters to
|
|
62
|
-
* include with request.
|
|
53
|
+
* include with request. If requesting specific
|
|
54
|
+
* fields, fields must always include the ID.
|
|
63
55
|
*/
|
|
64
56
|
export const getEntityRecord =
|
|
65
57
|
( kind, name, key = '', query ) =>
|
|
@@ -140,7 +132,8 @@ export const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );
|
|
|
140
132
|
*
|
|
141
133
|
* @param {string} kind Entity kind.
|
|
142
134
|
* @param {string} name Entity name.
|
|
143
|
-
* @param {Object?} query Query Object.
|
|
135
|
+
* @param {Object?} query Query Object. If requesting specific fields, fields
|
|
136
|
+
* must always include the ID.
|
|
144
137
|
*/
|
|
145
138
|
export const getEntityRecords =
|
|
146
139
|
( kind, name, query = {} ) =>
|
|
@@ -313,7 +306,7 @@ export const canUser =
|
|
|
313
306
|
// return the expected result in the native version. Instead, API requests
|
|
314
307
|
// only return the result, without including response properties like the headers.
|
|
315
308
|
const allowHeader = response.headers?.get( 'allow' );
|
|
316
|
-
const key =
|
|
309
|
+
const key = [ action, resource, id ].filter( Boolean ).join( '/' );
|
|
317
310
|
const isAllowed = includes( allowHeader, method );
|
|
318
311
|
dispatch.receiveUserPermission( key, isAllowed );
|
|
319
312
|
};
|
package/src/selectors.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import { set, map, find, get, filter
|
|
5
|
+
import { set, map, find, get, filter } from 'lodash';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -296,7 +296,8 @@ interface GetEntityRecord {
|
|
|
296
296
|
* @param kind Entity kind.
|
|
297
297
|
* @param name Entity name.
|
|
298
298
|
* @param key Record's key
|
|
299
|
-
* @param query Optional query.
|
|
299
|
+
* @param query Optional query. If requesting specific
|
|
300
|
+
* fields, fields must always include the ID.
|
|
300
301
|
*
|
|
301
302
|
* @return Record.
|
|
302
303
|
*/
|
|
@@ -526,7 +527,8 @@ interface GetEntityRecords {
|
|
|
526
527
|
* @param state State tree
|
|
527
528
|
* @param kind Entity kind.
|
|
528
529
|
* @param name Entity name.
|
|
529
|
-
* @param query Optional terms query.
|
|
530
|
+
* @param query Optional terms query. If requesting specific
|
|
531
|
+
* fields, fields must always include the ID.
|
|
530
532
|
*
|
|
531
533
|
* @return Records.
|
|
532
534
|
*/
|
|
@@ -1115,7 +1117,7 @@ export function canUser(
|
|
|
1115
1117
|
resource: string,
|
|
1116
1118
|
id?: GenericRecordKey
|
|
1117
1119
|
): boolean | undefined {
|
|
1118
|
-
const key =
|
|
1120
|
+
const key = [ action, resource, id ].filter( Boolean ).join( '/' );
|
|
1119
1121
|
return get( state, [ 'userPermissions', key ] );
|
|
1120
1122
|
}
|
|
1121
1123
|
|