@wordpress/core-data 4.1.2 → 4.2.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 +1 -9
- package/build/actions.js +8 -12
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +17 -12
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +1 -1
- package/build/entities.js.map +1 -1
- package/build/{types → entity-types}/attachment.js +0 -0
- package/build/{types → entity-types}/attachment.js.map +0 -0
- package/build/{types → entity-types}/base-entity-types.js +0 -0
- package/build/entity-types/base-entity-types.js.map +1 -0
- package/build/{types → entity-types}/comment.js +0 -0
- package/build/{types → entity-types}/comment.js.map +0 -0
- package/build/{types → entity-types}/helpers.js +0 -0
- package/build/{types → entity-types}/helpers.js.map +0 -0
- package/build/{types → entity-types}/index.js +0 -0
- package/build/{types → entity-types}/index.js.map +0 -0
- package/build/{types → entity-types}/menu-location.js +0 -0
- package/build/{types → entity-types}/menu-location.js.map +0 -0
- package/build/{types → entity-types}/nav-menu-item.js +0 -0
- package/build/{types → entity-types}/nav-menu-item.js.map +0 -0
- package/build/{types → entity-types}/nav-menu.js +0 -0
- package/build/{types → entity-types}/nav-menu.js.map +0 -0
- package/build/{types → entity-types}/navigation-area.js +0 -0
- package/build/{types → entity-types}/navigation-area.js.map +0 -0
- package/build/{types → entity-types}/page.js +0 -0
- package/build/{types → entity-types}/page.js.map +0 -0
- package/build/{types → entity-types}/plugin.js +0 -0
- package/build/{types → entity-types}/plugin.js.map +0 -0
- package/build/{types → entity-types}/post.js +0 -0
- package/build/{types → entity-types}/post.js.map +0 -0
- package/build/{types → entity-types}/settings.js +0 -0
- package/build/{types → entity-types}/settings.js.map +0 -0
- package/build/{types → entity-types}/sidebar.js +0 -0
- package/build/{types → entity-types}/sidebar.js.map +0 -0
- package/build/{types → entity-types}/taxonomy.js +0 -0
- package/build/{types → entity-types}/taxonomy.js.map +0 -0
- package/build/{types → entity-types}/theme.js +0 -0
- package/build/{types → entity-types}/theme.js.map +0 -0
- package/build/{types → entity-types}/type.js +0 -0
- package/build/{types → entity-types}/type.js.map +0 -0
- package/build/{types → entity-types}/user.js +0 -0
- package/build/{types → entity-types}/user.js.map +0 -0
- package/build/{types → entity-types}/widget-type.js +0 -0
- package/build/{types → entity-types}/widget-type.js.map +0 -0
- package/build/{types → entity-types}/widget.js +0 -0
- package/build/{types → entity-types}/widget.js.map +0 -0
- package/build/{types → entity-types}/wp-template-part.js +0 -0
- package/build/{types → entity-types}/wp-template-part.js.map +0 -0
- package/build/{types → entity-types}/wp-template.js +0 -0
- package/build/{types → entity-types}/wp-template.js.map +0 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/hooks/use-entity-records.js +12 -2
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/index.js +4 -4
- package/build/index.js.map +1 -1
- package/build/reducer.js +1 -1
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +7 -2
- package/build/resolvers.js.map +1 -1
- package/build-module/actions.js +8 -12
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +17 -12
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +1 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/{types → entity-types}/attachment.js +0 -0
- package/build-module/{types → entity-types}/attachment.js.map +0 -0
- package/build-module/{types → entity-types}/base-entity-types.js +0 -0
- package/build-module/entity-types/base-entity-types.js.map +1 -0
- package/build-module/{types → entity-types}/comment.js +0 -0
- package/build-module/{types → entity-types}/comment.js.map +0 -0
- package/build-module/{types → entity-types}/helpers.js +0 -0
- package/build-module/{types → entity-types}/helpers.js.map +0 -0
- package/build-module/{types → entity-types}/index.js +0 -0
- package/build-module/{types → entity-types}/index.js.map +0 -0
- package/build-module/{types → entity-types}/menu-location.js +0 -0
- package/build-module/{types → entity-types}/menu-location.js.map +0 -0
- package/build-module/{types → entity-types}/nav-menu-item.js +0 -0
- package/build-module/{types → entity-types}/nav-menu-item.js.map +0 -0
- package/build-module/{types → entity-types}/nav-menu.js +0 -0
- package/build-module/{types → entity-types}/nav-menu.js.map +0 -0
- package/build-module/{types → entity-types}/navigation-area.js +0 -0
- package/build-module/{types → entity-types}/navigation-area.js.map +0 -0
- package/build-module/{types → entity-types}/page.js +0 -0
- package/build-module/{types → entity-types}/page.js.map +0 -0
- package/build-module/{types → entity-types}/plugin.js +0 -0
- package/build-module/{types → entity-types}/plugin.js.map +0 -0
- package/build-module/{types → entity-types}/post.js +0 -0
- package/build-module/{types → entity-types}/post.js.map +0 -0
- package/build-module/{types → entity-types}/settings.js +0 -0
- package/build-module/{types → entity-types}/settings.js.map +0 -0
- package/build-module/{types → entity-types}/sidebar.js +0 -0
- package/build-module/{types → entity-types}/sidebar.js.map +0 -0
- package/build-module/{types → entity-types}/taxonomy.js +0 -0
- package/build-module/{types → entity-types}/taxonomy.js.map +0 -0
- package/build-module/{types → entity-types}/theme.js +0 -0
- package/build-module/{types → entity-types}/theme.js.map +0 -0
- package/build-module/{types → entity-types}/type.js +0 -0
- package/build-module/{types → entity-types}/type.js.map +0 -0
- package/build-module/{types → entity-types}/user.js +0 -0
- package/build-module/{types → entity-types}/user.js.map +0 -0
- package/build-module/{types → entity-types}/widget-type.js +0 -0
- package/build-module/{types → entity-types}/widget-type.js.map +0 -0
- package/build-module/{types → entity-types}/widget.js +0 -0
- package/build-module/{types → entity-types}/widget.js.map +0 -0
- package/build-module/{types → entity-types}/wp-template-part.js +0 -0
- package/build-module/{types → entity-types}/wp-template-part.js.map +0 -0
- package/build-module/{types → entity-types}/wp-template.js +0 -0
- package/build-module/{types → entity-types}/wp-template.js.map +0 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +11 -2
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/reducer.js +1 -1
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +7 -2
- package/build-module/resolvers.js.map +1 -1
- package/package.json +14 -11
- package/src/actions.js +8 -12
- package/src/batch/create-batch.js +16 -12
- package/src/entities.js +1 -1
- package/src/{types → entity-types}/README.md +0 -0
- package/src/{types → entity-types}/attachment.ts +0 -0
- package/src/{types → entity-types}/base-entity-types.ts +0 -0
- package/src/{types → entity-types}/comment.ts +0 -0
- package/src/{types → entity-types}/helpers.ts +0 -0
- package/src/{types → entity-types}/index.ts +0 -0
- package/src/{types → entity-types}/menu-location.ts +0 -0
- package/src/{types → entity-types}/nav-menu-item.ts +0 -0
- package/src/{types → entity-types}/nav-menu.ts +0 -0
- package/src/{types → entity-types}/navigation-area.ts +0 -0
- package/src/{types → entity-types}/page.ts +0 -0
- package/src/{types → entity-types}/plugin.ts +0 -0
- package/src/{types → entity-types}/post.ts +0 -0
- package/src/{types → entity-types}/settings.ts +0 -0
- package/src/{types → entity-types}/sidebar.ts +0 -0
- package/src/{types → entity-types}/taxonomy.ts +0 -0
- package/src/{types → entity-types}/theme.ts +0 -0
- package/src/{types → entity-types}/type.ts +0 -0
- package/src/{types → entity-types}/user.ts +0 -0
- package/src/{types → entity-types}/widget-type.ts +0 -0
- package/src/{types → entity-types}/widget.ts +0 -0
- package/src/{types → entity-types}/wp-template-part.ts +0 -0
- package/src/{types → entity-types}/wp-template.ts +0 -0
- package/src/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/src/hooks/use-entity-records.ts +12 -2
- package/src/index.js +1 -1
- package/src/locks/test/engine.js +13 -13
- package/src/locks/test/reducer.js +3 -3
- package/src/locks/test/utils.js +2 -2
- package/src/reducer.js +1 -1
- package/src/resolvers.js +4 -1
- package/src/test/resolvers.js +13 -13
- package/src/test/selectors.js +2 -3
- package/build/types/base-entity-types.js.map +0 -1
- package/build-module/types/base-entity-types.js.map +0 -1
|
@@ -43,6 +43,7 @@ import defaultProcessor from './default-processor';
|
|
|
43
43
|
*/
|
|
44
44
|
export default function createBatch( processor = defaultProcessor ) {
|
|
45
45
|
let lastId = 0;
|
|
46
|
+
/** @type {Array<{ input: any; resolve: ( value: any ) => void; reject: ( error: any ) => void }>} */
|
|
46
47
|
let queue = [];
|
|
47
48
|
const pending = new ObservableSet();
|
|
48
49
|
|
|
@@ -100,7 +101,7 @@ export default function createBatch( processor = defaultProcessor ) {
|
|
|
100
101
|
* Runs the batch. This calls `batchProcessor` and resolves or rejects
|
|
101
102
|
* all promises returned by `add()`.
|
|
102
103
|
*
|
|
103
|
-
* @return {Promise} A promise that resolves to a boolean that is true
|
|
104
|
+
* @return {Promise<boolean>} A promise that resolves to a boolean that is true
|
|
104
105
|
* if the processor returned no errors.
|
|
105
106
|
*/
|
|
106
107
|
async run() {
|
|
@@ -109,7 +110,7 @@ export default function createBatch( processor = defaultProcessor ) {
|
|
|
109
110
|
const unsubscribe = pending.subscribe( () => {
|
|
110
111
|
if ( ! pending.size ) {
|
|
111
112
|
unsubscribe();
|
|
112
|
-
resolve();
|
|
113
|
+
resolve( undefined );
|
|
113
114
|
}
|
|
114
115
|
} );
|
|
115
116
|
} );
|
|
@@ -137,15 +138,18 @@ export default function createBatch( processor = defaultProcessor ) {
|
|
|
137
138
|
|
|
138
139
|
let isSuccess = true;
|
|
139
140
|
|
|
140
|
-
for ( const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
for ( const pair of zip( results, queue ) ) {
|
|
142
|
+
/** @type {{error?: unknown, output?: unknown}} */
|
|
143
|
+
const result = pair[ 0 ];
|
|
144
|
+
|
|
145
|
+
/** @type {{resolve: (value: any) => void; reject: (error: any) => void} | undefined} */
|
|
146
|
+
const queueItem = pair[ 1 ];
|
|
147
|
+
|
|
144
148
|
if ( result?.error ) {
|
|
145
|
-
reject( result.error );
|
|
149
|
+
queueItem?.reject( result.error );
|
|
146
150
|
isSuccess = false;
|
|
147
151
|
} else {
|
|
148
|
-
resolve( result?.output ?? result );
|
|
152
|
+
queueItem?.resolve( result?.output ?? result );
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
|
|
@@ -166,14 +170,14 @@ class ObservableSet {
|
|
|
166
170
|
return this.set.size;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
add(
|
|
170
|
-
this.set.add(
|
|
173
|
+
add( value ) {
|
|
174
|
+
this.set.add( value );
|
|
171
175
|
this.subscribers.forEach( ( subscriber ) => subscriber() );
|
|
172
176
|
return this;
|
|
173
177
|
}
|
|
174
178
|
|
|
175
|
-
delete(
|
|
176
|
-
const isSuccess = this.set.delete(
|
|
179
|
+
delete( value ) {
|
|
180
|
+
const isSuccess = this.set.delete( value );
|
|
177
181
|
this.subscribers.forEach( ( subscriber ) => subscriber() );
|
|
178
182
|
return isSuccess;
|
|
179
183
|
}
|
package/src/entities.js
CHANGED
|
@@ -143,7 +143,7 @@ export const defaultEntities = [
|
|
|
143
143
|
kind: 'root',
|
|
144
144
|
baseURL: '/wp/v2/global-styles',
|
|
145
145
|
baseURLParams: { context: 'edit' },
|
|
146
|
-
plural: 'globalStylesVariations', //
|
|
146
|
+
plural: 'globalStylesVariations', // Should be different than name.
|
|
147
147
|
getTitle: ( record ) => record?.title?.rendered || record?.title,
|
|
148
148
|
},
|
|
149
149
|
{
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -103,7 +103,7 @@ const fetchLinkSuggestions = async (
|
|
|
103
103
|
};
|
|
104
104
|
} );
|
|
105
105
|
} )
|
|
106
|
-
.catch( () => [] ) //
|
|
106
|
+
.catch( () => [] ) // Fail by returning no results.
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -156,7 +156,7 @@ const fetchLinkSuggestions = async (
|
|
|
156
156
|
return Promise.all( queries ).then( ( results ) => {
|
|
157
157
|
return results
|
|
158
158
|
.reduce(
|
|
159
|
-
( accumulator, current ) => accumulator.concat( current ), //
|
|
159
|
+
( accumulator, current ) => accumulator.concat( current ), // Flatten list.
|
|
160
160
|
[]
|
|
161
161
|
)
|
|
162
162
|
.filter(
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
@@ -29,7 +34,6 @@ interface EntityRecordsResolution< RecordType > {
|
|
|
29
34
|
* @param kind Kind of the requested entities.
|
|
30
35
|
* @param name Name of the requested entities.
|
|
31
36
|
* @param queryArgs HTTP query for the requested entities.
|
|
32
|
-
*
|
|
33
37
|
* @example
|
|
34
38
|
* ```js
|
|
35
39
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -66,10 +70,16 @@ export default function __experimentalUseEntityRecords< RecordType >(
|
|
|
66
70
|
name: string,
|
|
67
71
|
queryArgs: unknown = {}
|
|
68
72
|
): EntityRecordsResolution< RecordType > {
|
|
73
|
+
// Serialize queryArgs to a string that can be safely used as a React dep.
|
|
74
|
+
// We can't just pass queryArgs as one of the deps, because if it is passed
|
|
75
|
+
// as an object literal, then it will be a different object on each call even
|
|
76
|
+
// if the values remain the same.
|
|
77
|
+
const queryAsString = addQueryArgs( '', queryArgs );
|
|
78
|
+
|
|
69
79
|
const { data: records, ...rest } = useQuerySelect(
|
|
70
80
|
( query ) =>
|
|
71
81
|
query( coreStore ).getEntityRecords( kind, name, queryArgs ),
|
|
72
|
-
[ kind, name,
|
|
82
|
+
[ kind, name, queryAsString ]
|
|
73
83
|
);
|
|
74
84
|
|
|
75
85
|
return {
|
package/src/index.js
CHANGED
|
@@ -77,4 +77,4 @@ export { default as __experimentalUseEntityRecord } from './hooks/use-entity-rec
|
|
|
77
77
|
export { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';
|
|
78
78
|
export * from './entity-provider';
|
|
79
79
|
export * from './fetch';
|
|
80
|
-
export * from './types';
|
|
80
|
+
export * from './entity-types';
|
package/src/locks/test/engine.js
CHANGED
|
@@ -5,7 +5,7 @@ import createLocks from '../engine';
|
|
|
5
5
|
|
|
6
6
|
jest.useRealTimers();
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// We correctly await all promises with expect calls, but the rule doesn't detect that.
|
|
9
9
|
/* eslint-disable jest/valid-expect-in-promise */
|
|
10
10
|
|
|
11
11
|
describe( 'Locks engine', () => {
|
|
@@ -15,11 +15,11 @@ describe( 'Locks engine', () => {
|
|
|
15
15
|
let l1Granted = false;
|
|
16
16
|
let l2Granted = false;
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// Request two locks.
|
|
19
19
|
const l1 = locks.acquire( 'store', [ 'root' ], true );
|
|
20
20
|
const l2 = locks.acquire( 'store', [ 'root' ], true );
|
|
21
21
|
|
|
22
|
-
//
|
|
22
|
+
// On each grant, verify that the other lock is not granted at the same time.
|
|
23
23
|
const check1 = l1.then( () => {
|
|
24
24
|
l1Granted = true;
|
|
25
25
|
expect( l2Granted ).toBe( false );
|
|
@@ -30,7 +30,7 @@ describe( 'Locks engine', () => {
|
|
|
30
30
|
expect( l1Granted ).toBe( false );
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// Unlock both.
|
|
34
34
|
const lock1 = await l1;
|
|
35
35
|
locks.release( lock1 );
|
|
36
36
|
l1Granted = false;
|
|
@@ -39,7 +39,7 @@ describe( 'Locks engine', () => {
|
|
|
39
39
|
locks.release( lock2 );
|
|
40
40
|
l2Granted = false;
|
|
41
41
|
|
|
42
|
-
//
|
|
42
|
+
// Ensure that both locks were granted and checked.
|
|
43
43
|
return await Promise.all( [ check1, check2 ] );
|
|
44
44
|
} );
|
|
45
45
|
|
|
@@ -49,11 +49,11 @@ describe( 'Locks engine', () => {
|
|
|
49
49
|
let l1Granted = false;
|
|
50
50
|
let l2Granted = false;
|
|
51
51
|
|
|
52
|
-
//
|
|
52
|
+
// Request two locks.
|
|
53
53
|
const l1 = locks.acquire( 'store', [ 'root' ], false );
|
|
54
54
|
const l2 = locks.acquire( 'store', [ 'root' ], true );
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// On each grant, verify that the other lock is not granted at the same time.
|
|
57
57
|
const check1 = l1.then( () => {
|
|
58
58
|
l1Granted = true;
|
|
59
59
|
expect( l2Granted ).toBe( false );
|
|
@@ -64,7 +64,7 @@ describe( 'Locks engine', () => {
|
|
|
64
64
|
expect( l1Granted ).toBe( false );
|
|
65
65
|
} );
|
|
66
66
|
|
|
67
|
-
//
|
|
67
|
+
// Unlock both.
|
|
68
68
|
const lock1 = await l1;
|
|
69
69
|
locks.release( lock1 );
|
|
70
70
|
l1Granted = false;
|
|
@@ -73,7 +73,7 @@ describe( 'Locks engine', () => {
|
|
|
73
73
|
locks.release( lock2 );
|
|
74
74
|
l2Granted = false;
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Ensure that both locks were granted and checked.
|
|
77
77
|
return await Promise.all( [ check1, check2 ] );
|
|
78
78
|
} );
|
|
79
79
|
|
|
@@ -83,11 +83,11 @@ describe( 'Locks engine', () => {
|
|
|
83
83
|
let l1Granted = false;
|
|
84
84
|
let l2Granted = false;
|
|
85
85
|
|
|
86
|
-
//
|
|
86
|
+
// Request two locks.
|
|
87
87
|
const l1 = locks.acquire( 'store', [ 'root' ], true );
|
|
88
88
|
const l2 = locks.acquire( 'store', [ 'root', 'child' ], true );
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// On each grant, verify that the other lock is not granted at the same time.
|
|
91
91
|
const check1 = l1.then( () => {
|
|
92
92
|
l1Granted = true;
|
|
93
93
|
expect( l2Granted ).toBe( false );
|
|
@@ -98,7 +98,7 @@ describe( 'Locks engine', () => {
|
|
|
98
98
|
expect( l1Granted ).toBe( false );
|
|
99
99
|
} );
|
|
100
100
|
|
|
101
|
-
//
|
|
101
|
+
// Unlock both.
|
|
102
102
|
const lock1 = await l1;
|
|
103
103
|
locks.release( lock1 );
|
|
104
104
|
l1Granted = false;
|
|
@@ -107,7 +107,7 @@ describe( 'Locks engine', () => {
|
|
|
107
107
|
locks.release( lock2 );
|
|
108
108
|
l2Granted = false;
|
|
109
109
|
|
|
110
|
-
//
|
|
110
|
+
// Ensure that both locks were granted and checked.
|
|
111
111
|
return await Promise.all( [ check1, check2 ] );
|
|
112
112
|
} );
|
|
113
113
|
|
|
@@ -62,7 +62,7 @@ describe( 'locks', () => {
|
|
|
62
62
|
red,
|
|
63
63
|
blue,
|
|
64
64
|
green: {
|
|
65
|
-
// ...and add the lock
|
|
65
|
+
// ...and add the lock.
|
|
66
66
|
locks: [ lock ],
|
|
67
67
|
children: {},
|
|
68
68
|
},
|
|
@@ -92,7 +92,7 @@ describe( 'locks', () => {
|
|
|
92
92
|
red,
|
|
93
93
|
blue,
|
|
94
94
|
green: {
|
|
95
|
-
// ...and add the lock
|
|
95
|
+
// ...and add the lock.
|
|
96
96
|
locks: [ lock ],
|
|
97
97
|
children: {},
|
|
98
98
|
},
|
|
@@ -118,7 +118,7 @@ describe( 'locks', () => {
|
|
|
118
118
|
red,
|
|
119
119
|
blue,
|
|
120
120
|
green: {
|
|
121
|
-
// Should remove the lock
|
|
121
|
+
// Should remove the lock.
|
|
122
122
|
locks: [],
|
|
123
123
|
children: {},
|
|
124
124
|
},
|
package/src/locks/test/utils.js
CHANGED
|
@@ -193,13 +193,13 @@ describe( 'deepCopyLocksTreePath', () => {
|
|
|
193
193
|
expect( deepCopy.children ).not.toBe( tree.children );
|
|
194
194
|
expect( deepCopy.children.target ).not.toBe( tree.children.target );
|
|
195
195
|
|
|
196
|
-
// Locks lists should be preserved
|
|
196
|
+
// Locks lists should be preserved.
|
|
197
197
|
expect( deepCopy.locks ).toBe( tree.locks );
|
|
198
198
|
expect( deepCopy.children.target.locks ).toBe(
|
|
199
199
|
tree.children.target.locks
|
|
200
200
|
);
|
|
201
201
|
|
|
202
|
-
// Specific locks should be preserved
|
|
202
|
+
// Specific locks should be preserved.
|
|
203
203
|
expect( deepCopy.locks[ 0 ] ).toBe( tree.locks[ 0 ] );
|
|
204
204
|
|
|
205
205
|
// No need to clone lower levels of the tree, let's check if they're still the same:
|
package/src/reducer.js
CHANGED
|
@@ -355,7 +355,7 @@ export function entitiesConfig( state = defaultEntities, action ) {
|
|
|
355
355
|
export const entities = ( state = {}, action ) => {
|
|
356
356
|
const newConfig = entitiesConfig( state.config, action );
|
|
357
357
|
|
|
358
|
-
// Generates a dynamic reducer for the entities
|
|
358
|
+
// Generates a dynamic reducer for the entities.
|
|
359
359
|
let entitiesDataReducer = state.reducer;
|
|
360
360
|
if ( ! entitiesDataReducer || newConfig !== state.config ) {
|
|
361
361
|
const entitiesByKind = groupBy( newConfig, 'kind' );
|
package/src/resolvers.js
CHANGED
|
@@ -292,7 +292,10 @@ export const canUser = ( action, resource, id ) => async ( { dispatch } ) => {
|
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
|
|
295
|
+
// Optional chaining operator is used here because the API requests don't
|
|
296
|
+
// return the expected result in the native version. Instead, API requests
|
|
297
|
+
// only return the result, without including response properties like the headers.
|
|
298
|
+
const allowHeader = response.headers?.get( 'allow' );
|
|
296
299
|
const key = compact( [ action, resource, id ] ).join( '/' );
|
|
297
300
|
const isAllowed = includes( allowHeader, method );
|
|
298
301
|
dispatch.receiveUserPermission( key, isAllowed );
|
package/src/test/resolvers.js
CHANGED
|
@@ -46,12 +46,12 @@ describe( 'getEntityRecord', () => {
|
|
|
46
46
|
|
|
47
47
|
await getEntityRecord( 'root', 'postType', 'post' )( { dispatch } );
|
|
48
48
|
|
|
49
|
-
// Fetch request should have been issued
|
|
49
|
+
// Fetch request should have been issued.
|
|
50
50
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
51
51
|
path: '/wp/v2/types/post?context=edit',
|
|
52
52
|
} );
|
|
53
53
|
|
|
54
|
-
// The record should have been received
|
|
54
|
+
// The record should have been received.
|
|
55
55
|
expect( dispatch.receiveEntityRecords ).toHaveBeenCalledWith(
|
|
56
56
|
'root',
|
|
57
57
|
'postType',
|
|
@@ -59,7 +59,7 @@ describe( 'getEntityRecord', () => {
|
|
|
59
59
|
undefined
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
-
// Locks should have been acquired and released
|
|
62
|
+
// Locks should have been acquired and released.
|
|
63
63
|
expect( dispatch.__unstableAcquireStoreLock ).toHaveBeenCalledTimes(
|
|
64
64
|
1
|
|
65
65
|
);
|
|
@@ -94,19 +94,19 @@ describe( 'getEntityRecord', () => {
|
|
|
94
94
|
query
|
|
95
95
|
)( { dispatch, select } );
|
|
96
96
|
|
|
97
|
-
// Check resolution cache for an existing entity that fulfills the request with query
|
|
97
|
+
// Check resolution cache for an existing entity that fulfills the request with query.
|
|
98
98
|
expect( select.hasEntityRecords ).toHaveBeenCalledWith(
|
|
99
99
|
'root',
|
|
100
100
|
'postType',
|
|
101
101
|
queryObj
|
|
102
102
|
);
|
|
103
103
|
|
|
104
|
-
// Trigger apiFetch, test that the query is present in the url
|
|
104
|
+
// Trigger apiFetch, test that the query is present in the url.
|
|
105
105
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
106
106
|
path: '/wp/v2/types/post?context=view&_envelope=1',
|
|
107
107
|
} );
|
|
108
108
|
|
|
109
|
-
// The record should have been received
|
|
109
|
+
// The record should have been received.
|
|
110
110
|
expect( dispatch.receiveEntityRecords ).toHaveBeenCalledWith(
|
|
111
111
|
'root',
|
|
112
112
|
'postType',
|
|
@@ -114,7 +114,7 @@ describe( 'getEntityRecord', () => {
|
|
|
114
114
|
queryObj
|
|
115
115
|
);
|
|
116
116
|
|
|
117
|
-
// Locks should have been acquired and released
|
|
117
|
+
// Locks should have been acquired and released.
|
|
118
118
|
expect( dispatch.__unstableAcquireStoreLock ).toHaveBeenCalledTimes(
|
|
119
119
|
1
|
|
120
120
|
);
|
|
@@ -163,12 +163,12 @@ describe( 'getEntityRecords', () => {
|
|
|
163
163
|
|
|
164
164
|
await getEntityRecords( 'root', 'postType' )( { dispatch } );
|
|
165
165
|
|
|
166
|
-
// Fetch request should have been issued
|
|
166
|
+
// Fetch request should have been issued.
|
|
167
167
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
168
168
|
path: '/wp/v2/types?context=edit',
|
|
169
169
|
} );
|
|
170
170
|
|
|
171
|
-
// The record should have been received
|
|
171
|
+
// The record should have been received.
|
|
172
172
|
expect( dispatch.receiveEntityRecords ).toHaveBeenCalledWith(
|
|
173
173
|
'root',
|
|
174
174
|
'postType',
|
|
@@ -191,12 +191,12 @@ describe( 'getEntityRecords', () => {
|
|
|
191
191
|
|
|
192
192
|
await getEntityRecords( 'root', 'postType' )( { dispatch } );
|
|
193
193
|
|
|
194
|
-
// Fetch request should have been issued
|
|
194
|
+
// Fetch request should have been issued.
|
|
195
195
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
196
196
|
path: '/wp/v2/types?context=edit',
|
|
197
197
|
} );
|
|
198
198
|
|
|
199
|
-
// The record should have been received
|
|
199
|
+
// The record should have been received.
|
|
200
200
|
expect(
|
|
201
201
|
dispatch.__unstableAcquireStoreLock
|
|
202
202
|
).toHaveBeenCalledWith(
|
|
@@ -223,12 +223,12 @@ describe( 'getEntityRecords', () => {
|
|
|
223
223
|
|
|
224
224
|
await getEntityRecords( 'root', 'postType' )( { dispatch } );
|
|
225
225
|
|
|
226
|
-
// Fetch request should have been issued
|
|
226
|
+
// Fetch request should have been issued.
|
|
227
227
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
228
228
|
path: '/wp/v2/types?context=edit',
|
|
229
229
|
} );
|
|
230
230
|
|
|
231
|
-
// The record should have been received
|
|
231
|
+
// The record should have been received.
|
|
232
232
|
expect( dispatch ).toHaveBeenCalledWith( {
|
|
233
233
|
type: 'START_RESOLUTIONS',
|
|
234
234
|
selectorName: 'getEntityRecord',
|
package/src/test/selectors.js
CHANGED
|
@@ -24,8 +24,7 @@ import {
|
|
|
24
24
|
getCurrentUser,
|
|
25
25
|
getReferenceByDistinctEdits,
|
|
26
26
|
} from '../selectors';
|
|
27
|
-
|
|
28
|
-
// getEntityRecord and __experimentalGetEntityRecordNoResolver selectors share the same tests
|
|
27
|
+
// getEntityRecord and __experimentalGetEntityRecordNoResolver selectors share the same tests.
|
|
29
28
|
describe.each( [
|
|
30
29
|
[ getEntityRecord ],
|
|
31
30
|
[ __experimentalGetEntityRecordNoResolver ],
|
|
@@ -398,7 +397,7 @@ describe( 'getEntityRecords', () => {
|
|
|
398
397
|
'wp_block'
|
|
399
398
|
);
|
|
400
399
|
|
|
401
|
-
// Simulate update states
|
|
400
|
+
// Simulate update states.
|
|
402
401
|
state = { ...state };
|
|
403
402
|
|
|
404
403
|
const postTypeSecondRecords = getEntityRecords(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/types/base-entity-types.ts"],"names":["BaseEntityTypes"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;iCACiBA,e,+BAAAA,e","sourcesContent":["/**\n * This module exists solely to make the BaseEntityTypes namespace extensible\n * with declaration merging:\n *\n * ```ts\n * declare module './base-entity-types' {\n * export namespace BaseEntityTypes {\n * \t\t export interface Comment< C extends Context > {\n * \t\t id: number;\n * \t\t // ...\n * \t }\n * \t }\n * }\n * ```\n *\n * The huge upside is that consumers of @wordpress/core-data may extend the\n * exported data types using interface merging as follows:\n *\n * ```ts\n * import type { Context } from '@wordpress/core-data';\n * declare module '@wordpress/core-data' {\n * export namespace BaseEntityTypes {\n * export interface Comment< C extends Context > {\n * numberOfViews: number;\n * }\n * }\n * }\n *\n * import type { Comment } from '@wordpress/core-data';\n * const c : Comment< 'view' > = ...;\n *\n * // c.numberOfViews is a number\n * // c.id is still present\n * ```\n */\nexport namespace BaseEntityTypes {}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/types/base-entity-types.ts"],"names":["BaseEntityTypes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;iCAAiBA,e,KAAAA,e","sourcesContent":["/**\n * This module exists solely to make the BaseEntityTypes namespace extensible\n * with declaration merging:\n *\n * ```ts\n * declare module './base-entity-types' {\n * export namespace BaseEntityTypes {\n * \t\t export interface Comment< C extends Context > {\n * \t\t id: number;\n * \t\t // ...\n * \t }\n * \t }\n * }\n * ```\n *\n * The huge upside is that consumers of @wordpress/core-data may extend the\n * exported data types using interface merging as follows:\n *\n * ```ts\n * import type { Context } from '@wordpress/core-data';\n * declare module '@wordpress/core-data' {\n * export namespace BaseEntityTypes {\n * export interface Comment< C extends Context > {\n * numberOfViews: number;\n * }\n * }\n * }\n *\n * import type { Comment } from '@wordpress/core-data';\n * const c : Comment< 'view' > = ...;\n *\n * // c.numberOfViews is a number\n * // c.id is still present\n * ```\n */\nexport namespace BaseEntityTypes {}\n"]}
|