@wordpress/core-data 4.11.0 → 4.14.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 +10 -0
- package/README.md +124 -81
- package/build/actions.js +27 -0
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +3 -15
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +7 -5
- package/build/entities.js.map +1 -1
- package/build/hooks/index.js +14 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-record.js +84 -2
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +72 -11
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -28
- package/build/index.js.map +1 -1
- package/build/resolvers.js +22 -24
- 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/batch/create-batch.js +3 -14
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +7 -6
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +82 -2
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +68 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -3
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +22 -24
- 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 +12 -11
- package/src/actions.js +27 -0
- package/src/batch/create-batch.js +3 -12
- package/src/entities.ts +8 -6
- package/src/entity-types/theme.ts +4 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +49 -1
- package/src/hooks/test/use-resource-permissions.js +32 -36
- package/src/hooks/use-entity-record.ts +107 -2
- package/src/hooks/use-resource-permissions.ts +82 -20
- package/src/index.js +0 -3
- package/src/resolvers.js +41 -36
- 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 } from 'change-case';
|
|
14
5
|
|
|
15
6
|
/**
|
|
16
7
|
* WordPress dependencies
|
|
@@ -59,13 +50,16 @@ 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 ) =>
|
|
66
58
|
async ( { select, dispatch } ) => {
|
|
67
59
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
68
|
-
const entityConfig = find(
|
|
60
|
+
const entityConfig = configs.find(
|
|
61
|
+
( config ) => config.name === name && config.kind === kind
|
|
62
|
+
);
|
|
69
63
|
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {
|
|
70
64
|
return;
|
|
71
65
|
}
|
|
@@ -83,11 +77,13 @@ export const getEntityRecord =
|
|
|
83
77
|
// the ID.
|
|
84
78
|
query = {
|
|
85
79
|
...query,
|
|
86
|
-
_fields:
|
|
87
|
-
...
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
_fields: [
|
|
81
|
+
...new Set( [
|
|
82
|
+
...( getNormalizedCommaSeparable( query._fields ) ||
|
|
83
|
+
[] ),
|
|
84
|
+
entityConfig.key || DEFAULT_ENTITY_KEY,
|
|
85
|
+
] ),
|
|
86
|
+
].join(),
|
|
91
87
|
};
|
|
92
88
|
}
|
|
93
89
|
|
|
@@ -140,13 +136,16 @@ export const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );
|
|
|
140
136
|
*
|
|
141
137
|
* @param {string} kind Entity kind.
|
|
142
138
|
* @param {string} name Entity name.
|
|
143
|
-
* @param {Object?} query Query Object.
|
|
139
|
+
* @param {Object?} query Query Object. If requesting specific fields, fields
|
|
140
|
+
* must always include the ID.
|
|
144
141
|
*/
|
|
145
142
|
export const getEntityRecords =
|
|
146
143
|
( kind, name, query = {} ) =>
|
|
147
144
|
async ( { dispatch } ) => {
|
|
148
145
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
149
|
-
const entityConfig = find(
|
|
146
|
+
const entityConfig = configs.find(
|
|
147
|
+
( config ) => config.name === name && config.kind === kind
|
|
148
|
+
);
|
|
150
149
|
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {
|
|
151
150
|
return;
|
|
152
151
|
}
|
|
@@ -164,11 +163,13 @@ export const getEntityRecords =
|
|
|
164
163
|
// the ID.
|
|
165
164
|
query = {
|
|
166
165
|
...query,
|
|
167
|
-
_fields:
|
|
168
|
-
...
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
_fields: [
|
|
167
|
+
...new Set( [
|
|
168
|
+
...( getNormalizedCommaSeparable( query._fields ) ||
|
|
169
|
+
[] ),
|
|
170
|
+
entityConfig.key || DEFAULT_ENTITY_KEY,
|
|
171
|
+
] ),
|
|
172
|
+
].join(),
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
|
|
@@ -313,8 +314,9 @@ export const canUser =
|
|
|
313
314
|
// return the expected result in the native version. Instead, API requests
|
|
314
315
|
// only return the result, without including response properties like the headers.
|
|
315
316
|
const allowHeader = response.headers?.get( 'allow' );
|
|
316
|
-
const key =
|
|
317
|
-
const isAllowed =
|
|
317
|
+
const key = [ action, resource, id ].filter( Boolean ).join( '/' );
|
|
318
|
+
const isAllowed =
|
|
319
|
+
allowHeader?.includes?.( method ) || allowHeader?.allow === method;
|
|
318
320
|
dispatch.receiveUserPermission( key, isAllowed );
|
|
319
321
|
};
|
|
320
322
|
|
|
@@ -330,7 +332,9 @@ export const canUserEditEntityRecord =
|
|
|
330
332
|
( kind, name, recordId ) =>
|
|
331
333
|
async ( { dispatch } ) => {
|
|
332
334
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
333
|
-
const entityConfig = find(
|
|
335
|
+
const entityConfig = configs.find(
|
|
336
|
+
( config ) => config.name === name && config.kind === kind
|
|
337
|
+
);
|
|
334
338
|
if ( ! entityConfig ) {
|
|
335
339
|
return;
|
|
336
340
|
}
|
|
@@ -434,13 +438,9 @@ export const __experimentalGetCurrentGlobalStylesId =
|
|
|
434
438
|
'theme',
|
|
435
439
|
{ status: 'active' }
|
|
436
440
|
);
|
|
437
|
-
const globalStylesURL =
|
|
438
|
-
0
|
|
439
|
-
|
|
440
|
-
'wp:user-global-styles',
|
|
441
|
-
0,
|
|
442
|
-
'href',
|
|
443
|
-
] );
|
|
441
|
+
const globalStylesURL =
|
|
442
|
+
activeThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]
|
|
443
|
+
?.href;
|
|
444
444
|
if ( globalStylesURL ) {
|
|
445
445
|
const globalStylesObject = await apiFetch( {
|
|
446
446
|
url: globalStylesURL,
|
|
@@ -483,8 +483,13 @@ export const getBlockPatterns =
|
|
|
483
483
|
const restPatterns = await apiFetch( {
|
|
484
484
|
path: '/wp/v2/block-patterns/patterns',
|
|
485
485
|
} );
|
|
486
|
-
const patterns = map(
|
|
487
|
-
|
|
486
|
+
const patterns = restPatterns?.map( ( pattern ) =>
|
|
487
|
+
Object.fromEntries(
|
|
488
|
+
Object.entries( pattern ).map( ( [ key, value ] ) => [
|
|
489
|
+
camelCase( key ),
|
|
490
|
+
value,
|
|
491
|
+
] )
|
|
492
|
+
)
|
|
488
493
|
);
|
|
489
494
|
dispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );
|
|
490
495
|
};
|
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
|
|