@wordpress/core-data 4.13.0 → 5.0.1-next.957ca95e4c.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 +12 -0
- package/README.md +148 -65
- package/build/entities.js +38 -51
- 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 +10 -6
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -0
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +5 -2
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +74 -11
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -30
- package/build/index.js.map +1 -1
- package/build/resolvers.js +17 -21
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +9 -46
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +38 -52
- 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 +10 -6
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -0
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +4 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +70 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -5
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +17 -21
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +7 -44
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +188 -0
- package/build-types/actions.d.ts.map +1 -0
- package/build-types/batch/create-batch.d.ts +71 -0
- package/build-types/batch/create-batch.d.ts.map +1 -0
- package/build-types/batch/default-processor.d.ts +11 -0
- package/build-types/batch/default-processor.d.ts.map +1 -0
- package/build-types/batch/index.d.ts +3 -0
- package/build-types/batch/index.d.ts.map +1 -0
- package/build-types/entities.d.ts +128 -0
- package/build-types/entities.d.ts.map +1 -0
- package/build-types/entity-provider.d.ts +68 -0
- package/build-types/entity-provider.d.ts.map +1 -0
- package/build-types/entity-types/attachment.d.ts +121 -0
- package/build-types/entity-types/attachment.d.ts.map +1 -0
- package/build-types/entity-types/base-entity-records.d.ts +37 -0
- package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
- package/build-types/entity-types/comment.d.ts +82 -0
- package/build-types/entity-types/comment.d.ts.map +1 -0
- package/build-types/entity-types/helpers.d.ts +123 -0
- package/build-types/entity-types/helpers.d.ts.map +1 -0
- package/build-types/entity-types/index.d.ts +64 -0
- package/build-types/entity-types/index.d.ts.map +1 -0
- package/build-types/entity-types/menu-location.d.ts +25 -0
- package/build-types/entity-types/menu-location.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu-item.d.ts +88 -0
- package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu.d.ts +45 -0
- package/build-types/entity-types/nav-menu.d.ts.map +1 -0
- package/build-types/entity-types/page.d.ts +120 -0
- package/build-types/entity-types/page.d.ts.map +1 -0
- package/build-types/entity-types/plugin.d.ts +62 -0
- package/build-types/entity-types/plugin.d.ts.map +1 -0
- package/build-types/entity-types/post.d.ts +128 -0
- package/build-types/entity-types/post.d.ts.map +1 -0
- package/build-types/entity-types/settings.d.ts +89 -0
- package/build-types/entity-types/settings.d.ts.map +1 -0
- package/build-types/entity-types/sidebar.d.ts +55 -0
- package/build-types/entity-types/sidebar.d.ts.map +1 -0
- package/build-types/entity-types/taxonomy.d.ts +83 -0
- package/build-types/entity-types/taxonomy.d.ts.map +1 -0
- package/build-types/entity-types/theme.d.ts +206 -0
- package/build-types/entity-types/theme.d.ts.map +1 -0
- package/build-types/entity-types/type.d.ts +71 -0
- package/build-types/entity-types/type.d.ts.map +1 -0
- package/build-types/entity-types/user.d.ts +93 -0
- package/build-types/entity-types/user.d.ts.map +1 -0
- package/build-types/entity-types/widget-type.d.ts +33 -0
- package/build-types/entity-types/widget-type.d.ts.map +1 -0
- package/build-types/entity-types/widget.d.ts +59 -0
- package/build-types/entity-types/widget.d.ts.map +1 -0
- package/build-types/entity-types/wp-template-part.d.ts +80 -0
- package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
- package/build-types/entity-types/wp-template.d.ts +80 -0
- package/build-types/entity-types/wp-template.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
- package/build-types/fetch/index.d.ts +3 -0
- package/build-types/fetch/index.d.ts.map +1 -0
- package/build-types/hooks/constants.d.ts +7 -0
- package/build-types/hooks/constants.d.ts.map +1 -0
- package/build-types/hooks/index.d.ts +4 -0
- package/build-types/hooks/index.d.ts.map +1 -0
- package/build-types/hooks/memoize.d.ts +3 -0
- package/build-types/hooks/memoize.d.ts.map +1 -0
- package/build-types/hooks/use-entity-record.d.ts +124 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -0
- package/build-types/hooks/use-entity-records.d.ts +49 -0
- package/build-types/hooks/use-entity-records.d.ts.map +1 -0
- package/build-types/hooks/use-query-select.d.ts +46 -0
- package/build-types/hooks/use-query-select.d.ts.map +1 -0
- package/build-types/hooks/use-resource-permissions.d.ts +99 -0
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
- package/build-types/index.d.ts +131 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/locks/actions.d.ts +7 -0
- package/build-types/locks/actions.d.ts.map +1 -0
- package/build-types/locks/engine.d.ts +5 -0
- package/build-types/locks/engine.d.ts.map +1 -0
- package/build-types/locks/reducer.d.ts +10 -0
- package/build-types/locks/reducer.d.ts.map +1 -0
- package/build-types/locks/selectors.d.ts +5 -0
- package/build-types/locks/selectors.d.ts.map +1 -0
- package/build-types/locks/utils.d.ts +8 -0
- package/build-types/locks/utils.d.ts.map +1 -0
- package/build-types/name.d.ts +8 -0
- package/build-types/name.d.ts.map +1 -0
- package/build-types/queried-data/actions.d.ts +32 -0
- package/build-types/queried-data/actions.d.ts.map +1 -0
- package/build-types/queried-data/get-query-parts.d.ts +60 -0
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
- package/build-types/queried-data/index.d.ts +4 -0
- package/build-types/queried-data/index.d.ts.map +1 -0
- package/build-types/queried-data/reducer.d.ts +54 -0
- package/build-types/queried-data/reducer.d.ts.map +1 -0
- package/build-types/queried-data/selectors.d.ts +16 -0
- package/build-types/queried-data/selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +156 -0
- package/build-types/reducer.d.ts.map +1 -0
- package/build-types/resolvers.d.ts +74 -0
- package/build-types/resolvers.d.ts.map +1 -0
- package/build-types/selectors.d.ts +524 -0
- package/build-types/selectors.d.ts.map +1 -0
- package/build-types/types.d.ts +4 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/conservative-map-item.d.ts +12 -0
- package/build-types/utils/conservative-map-item.d.ts.map +1 -0
- package/build-types/utils/forward-resolver.d.ts +10 -0
- package/build-types/utils/forward-resolver.d.ts.map +1 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
- package/build-types/utils/if-matching-action.d.ts +14 -0
- package/build-types/utils/if-matching-action.d.ts.map +1 -0
- package/build-types/utils/index.d.ts +9 -0
- package/build-types/utils/index.d.ts.map +1 -0
- package/build-types/utils/is-raw-attribute.d.ts +10 -0
- package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
- package/build-types/utils/on-sub-key.d.ts +4 -0
- package/build-types/utils/on-sub-key.d.ts.map +1 -0
- package/build-types/utils/replace-action.d.ts +13 -0
- package/build-types/utils/replace-action.d.ts.map +1 -0
- package/build-types/utils/with-weak-map-cache.d.ts +12 -0
- package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
- package/package.json +13 -11
- package/src/entities.js +325 -0
- package/src/entity-types/attachment.ts +3 -4
- package/src/entity-types/comment.ts +3 -4
- package/src/entity-types/index.ts +31 -88
- package/src/entity-types/menu-location.ts +3 -4
- package/src/entity-types/nav-menu-item.ts +3 -4
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +3 -4
- package/src/entity-types/taxonomy.ts +3 -4
- package/src/entity-types/theme.ts +7 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +3 -4
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +3 -4
- package/src/entity-types/wp-template.ts +3 -4
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +41 -1
- package/src/hooks/test/use-resource-permissions.js +32 -36
- package/src/hooks/use-entity-record.ts +18 -6
- package/src/hooks/use-entity-records.ts +2 -0
- package/src/hooks/use-query-select.ts +4 -1
- package/src/hooks/use-resource-permissions.ts +84 -20
- package/src/index.js +0 -5
- package/src/resolvers.js +36 -24
- package/src/selectors.ts +202 -341
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/entity-types/entities.js +0 -6
- package/build/entity-types/entities.js.map +0 -1
- package/build-module/entity-types/entities.js +0 -2
- package/build-module/entity-types/entities.js.map +0 -1
- package/src/entities.ts +0 -548
- package/src/entity-types/entities.ts +0 -130
package/src/resolvers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { camelCase
|
|
4
|
+
import { camelCase } from 'change-case';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -57,7 +57,9 @@ export const getEntityRecord =
|
|
|
57
57
|
( kind, name, key = '', query ) =>
|
|
58
58
|
async ( { select, dispatch } ) => {
|
|
59
59
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
60
|
-
const entityConfig = find(
|
|
60
|
+
const entityConfig = configs.find(
|
|
61
|
+
( config ) => config.name === name && config.kind === kind
|
|
62
|
+
);
|
|
61
63
|
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
@@ -75,11 +77,13 @@ export const getEntityRecord =
|
|
|
75
77
|
// the ID.
|
|
76
78
|
query = {
|
|
77
79
|
...query,
|
|
78
|
-
_fields:
|
|
79
|
-
...
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
_fields: [
|
|
81
|
+
...new Set( [
|
|
82
|
+
...( getNormalizedCommaSeparable( query._fields ) ||
|
|
83
|
+
[] ),
|
|
84
|
+
entityConfig.key || DEFAULT_ENTITY_KEY,
|
|
85
|
+
] ),
|
|
86
|
+
].join(),
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
|
|
@@ -139,7 +143,9 @@ export const getEntityRecords =
|
|
|
139
143
|
( kind, name, query = {} ) =>
|
|
140
144
|
async ( { dispatch } ) => {
|
|
141
145
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
142
|
-
const entityConfig = find(
|
|
146
|
+
const entityConfig = configs.find(
|
|
147
|
+
( config ) => config.name === name && config.kind === kind
|
|
148
|
+
);
|
|
143
149
|
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {
|
|
144
150
|
return;
|
|
145
151
|
}
|
|
@@ -157,11 +163,13 @@ export const getEntityRecords =
|
|
|
157
163
|
// the ID.
|
|
158
164
|
query = {
|
|
159
165
|
...query,
|
|
160
|
-
_fields:
|
|
161
|
-
...
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
_fields: [
|
|
167
|
+
...new Set( [
|
|
168
|
+
...( getNormalizedCommaSeparable( query._fields ) ||
|
|
169
|
+
[] ),
|
|
170
|
+
entityConfig.key || DEFAULT_ENTITY_KEY,
|
|
171
|
+
] ),
|
|
172
|
+
].join(),
|
|
165
173
|
};
|
|
166
174
|
}
|
|
167
175
|
|
|
@@ -307,7 +315,8 @@ export const canUser =
|
|
|
307
315
|
// only return the result, without including response properties like the headers.
|
|
308
316
|
const allowHeader = response.headers?.get( 'allow' );
|
|
309
317
|
const key = [ action, resource, id ].filter( Boolean ).join( '/' );
|
|
310
|
-
const isAllowed =
|
|
318
|
+
const isAllowed =
|
|
319
|
+
allowHeader?.includes?.( method ) || allowHeader?.allow === method;
|
|
311
320
|
dispatch.receiveUserPermission( key, isAllowed );
|
|
312
321
|
};
|
|
313
322
|
|
|
@@ -323,7 +332,9 @@ export const canUserEditEntityRecord =
|
|
|
323
332
|
( kind, name, recordId ) =>
|
|
324
333
|
async ( { dispatch } ) => {
|
|
325
334
|
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
|
|
326
|
-
const entityConfig = find(
|
|
335
|
+
const entityConfig = configs.find(
|
|
336
|
+
( config ) => config.name === name && config.kind === kind
|
|
337
|
+
);
|
|
327
338
|
if ( ! entityConfig ) {
|
|
328
339
|
return;
|
|
329
340
|
}
|
|
@@ -427,13 +438,9 @@ export const __experimentalGetCurrentGlobalStylesId =
|
|
|
427
438
|
'theme',
|
|
428
439
|
{ status: 'active' }
|
|
429
440
|
);
|
|
430
|
-
const globalStylesURL =
|
|
431
|
-
0
|
|
432
|
-
|
|
433
|
-
'wp:user-global-styles',
|
|
434
|
-
0,
|
|
435
|
-
'href',
|
|
436
|
-
] );
|
|
441
|
+
const globalStylesURL =
|
|
442
|
+
activeThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]
|
|
443
|
+
?.href;
|
|
437
444
|
if ( globalStylesURL ) {
|
|
438
445
|
const globalStylesObject = await apiFetch( {
|
|
439
446
|
url: globalStylesURL,
|
|
@@ -476,8 +483,13 @@ export const getBlockPatterns =
|
|
|
476
483
|
const restPatterns = await apiFetch( {
|
|
477
484
|
path: '/wp/v2/block-patterns/patterns',
|
|
478
485
|
} );
|
|
479
|
-
const patterns = map(
|
|
480
|
-
|
|
486
|
+
const patterns = restPatterns?.map( ( pattern ) =>
|
|
487
|
+
Object.fromEntries(
|
|
488
|
+
Object.entries( pattern ).map( ( [ key, value ] ) => [
|
|
489
|
+
camelCase( key ),
|
|
490
|
+
value,
|
|
491
|
+
] )
|
|
492
|
+
)
|
|
481
493
|
);
|
|
482
494
|
dispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );
|
|
483
495
|
};
|