@wordpress/core-data 4.2.1 → 4.3.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +41 -8
  3. package/build/actions.js +61 -41
  4. package/build/actions.js.map +1 -1
  5. package/build/entities.js +36 -23
  6. package/build/entities.js.map +1 -1
  7. package/build/entity-provider.js +46 -44
  8. package/build/entity-provider.js.map +1 -1
  9. package/build/entity-types/{base-entity-types.js → base-entity-records.js} +9 -9
  10. package/build/entity-types/base-entity-records.js.map +1 -0
  11. package/build/fetch/__experimental-fetch-link-suggestions.js +1 -1
  12. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  13. package/build/fetch/__experimental-fetch-url-data.js +1 -1
  14. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  15. package/build/hooks/use-entity-record.js +15 -5
  16. package/build/hooks/use-entity-record.js.map +1 -1
  17. package/build/hooks/use-entity-records.js +17 -5
  18. package/build/hooks/use-entity-records.js.map +1 -1
  19. package/build/index.js +9 -21
  20. package/build/index.js.map +1 -1
  21. package/build/queried-data/actions.js +4 -4
  22. package/build/queried-data/actions.js.map +1 -1
  23. package/build/queried-data/get-query-parts.js +7 -3
  24. package/build/queried-data/get-query-parts.js.map +1 -1
  25. package/build/queried-data/reducer.js +8 -6
  26. package/build/queried-data/reducer.js.map +1 -1
  27. package/build/reducer.js +16 -16
  28. package/build/reducer.js.map +1 -1
  29. package/build/resolvers.js +17 -23
  30. package/build/resolvers.js.map +1 -1
  31. package/build/selectors.js +92 -51
  32. package/build/selectors.js.map +1 -1
  33. package/build/utils/conservative-map-item.js +1 -1
  34. package/build/utils/conservative-map-item.js.map +1 -1
  35. package/build/utils/is-raw-attribute.js +1 -1
  36. package/build/utils/is-raw-attribute.js.map +1 -1
  37. package/build-module/actions.js +62 -42
  38. package/build-module/actions.js.map +1 -1
  39. package/build-module/entities.js +32 -19
  40. package/build-module/entities.js.map +1 -1
  41. package/build-module/entity-provider.js +47 -45
  42. package/build-module/entity-provider.js.map +1 -1
  43. package/build-module/entity-types/{base-entity-types.js → base-entity-records.js} +7 -7
  44. package/build-module/entity-types/base-entity-records.js.map +1 -0
  45. package/build-module/fetch/__experimental-fetch-link-suggestions.js +1 -1
  46. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  47. package/build-module/fetch/__experimental-fetch-url-data.js +1 -1
  48. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  49. package/build-module/hooks/use-entity-record.js +15 -5
  50. package/build-module/hooks/use-entity-record.js.map +1 -1
  51. package/build-module/hooks/use-entity-records.js +17 -5
  52. package/build-module/hooks/use-entity-records.js.map +1 -1
  53. package/build-module/index.js +10 -22
  54. package/build-module/index.js.map +1 -1
  55. package/build-module/queried-data/actions.js +4 -4
  56. package/build-module/queried-data/actions.js.map +1 -1
  57. package/build-module/queried-data/get-query-parts.js +7 -3
  58. package/build-module/queried-data/get-query-parts.js.map +1 -1
  59. package/build-module/queried-data/reducer.js +8 -6
  60. package/build-module/queried-data/reducer.js.map +1 -1
  61. package/build-module/reducer.js +17 -17
  62. package/build-module/reducer.js.map +1 -1
  63. package/build-module/resolvers.js +18 -24
  64. package/build-module/resolvers.js.map +1 -1
  65. package/build-module/selectors.js +88 -51
  66. package/build-module/selectors.js.map +1 -1
  67. package/build-module/utils/conservative-map-item.js +1 -1
  68. package/build-module/utils/conservative-map-item.js.map +1 -1
  69. package/build-module/utils/is-raw-attribute.js +1 -1
  70. package/build-module/utils/is-raw-attribute.js.map +1 -1
  71. package/package.json +11 -11
  72. package/src/actions.js +62 -42
  73. package/src/entities.js +43 -17
  74. package/src/entity-provider.js +50 -44
  75. package/src/entity-types/attachment.ts +5 -5
  76. package/src/entity-types/{base-entity-types.ts → base-entity-records.ts} +5 -5
  77. package/src/entity-types/comment.ts +5 -5
  78. package/src/entity-types/helpers.ts +1 -1
  79. package/src/entity-types/index.ts +4 -4
  80. package/src/entity-types/menu-location.ts +5 -5
  81. package/src/entity-types/nav-menu-item.ts +10 -5
  82. package/src/entity-types/nav-menu.ts +5 -5
  83. package/src/entity-types/navigation-area.ts +5 -5
  84. package/src/entity-types/page.ts +5 -5
  85. package/src/entity-types/plugin.ts +10 -5
  86. package/src/entity-types/post.ts +5 -5
  87. package/src/entity-types/settings.ts +10 -5
  88. package/src/entity-types/sidebar.ts +6 -7
  89. package/src/entity-types/taxonomy.ts +5 -5
  90. package/src/entity-types/theme.ts +5 -5
  91. package/src/entity-types/type.ts +5 -5
  92. package/src/entity-types/user.ts +10 -5
  93. package/src/entity-types/widget-type.ts +5 -5
  94. package/src/entity-types/widget.ts +5 -5
  95. package/src/entity-types/wp-template-part.ts +5 -5
  96. package/src/entity-types/wp-template.ts +5 -5
  97. package/src/fetch/__experimental-fetch-link-suggestions.js +1 -1
  98. package/src/fetch/__experimental-fetch-url-data.js +1 -0
  99. package/src/hooks/use-entity-record.ts +19 -8
  100. package/src/hooks/use-entity-records.ts +26 -9
  101. package/src/index.js +10 -15
  102. package/src/locks/test/selectors.js +4 -4
  103. package/src/queried-data/actions.js +4 -4
  104. package/src/queried-data/get-query-parts.js +5 -5
  105. package/src/queried-data/reducer.js +6 -6
  106. package/src/reducer.js +17 -17
  107. package/src/resolvers.js +25 -30
  108. package/src/selectors.js +92 -53
  109. package/src/test/actions.js +138 -33
  110. package/src/test/entities.js +11 -11
  111. package/src/test/reducer.js +4 -4
  112. package/src/test/resolvers.js +5 -5
  113. package/src/test/selectors.js +22 -22
  114. package/src/utils/conservative-map-item.js +1 -1
  115. package/src/utils/is-raw-attribute.js +1 -1
  116. package/src/utils/test/is-raw-attribute.js +4 -4
  117. package/build/entity-types/base-entity-types.js.map +0 -1
  118. package/build-module/entity-types/base-entity-types.js.map +0 -1
@@ -30,21 +30,25 @@ jest.mock( '../batch', () => {
30
30
 
31
31
  describe( 'editEntityRecord', () => {
32
32
  it( 'throws when the edited entity does not have a loaded config.', async () => {
33
- const entity = { kind: 'someKind', name: 'someName', id: 'someId' };
33
+ const entityConfig = {
34
+ kind: 'someKind',
35
+ name: 'someName',
36
+ id: 'someId',
37
+ };
34
38
  const select = {
35
- getEntity: jest.fn(),
39
+ getEntityConfig: jest.fn(),
36
40
  };
37
41
  const fulfillment = () =>
38
42
  editEntityRecord(
39
- entity.kind,
40
- entity.name,
41
- entity.id,
43
+ entityConfig.kind,
44
+ entityConfig.name,
45
+ entityConfig.id,
42
46
  {}
43
47
  )( { select } );
44
48
  expect( fulfillment ).toThrow(
45
- `The entity being edited (${ entity.kind }, ${ entity.name }) does not have a loaded config.`
49
+ `The entity being edited (${ entityConfig.kind }, ${ entityConfig.name }) does not have a loaded config.`
46
50
  );
47
- expect( select.getEntity ).toHaveBeenCalledTimes( 1 );
51
+ expect( select.getEntityConfig ).toHaveBeenCalledTimes( 1 );
48
52
  } );
49
53
  } );
50
54
 
@@ -56,7 +60,7 @@ describe( 'deleteEntityRecord', () => {
56
60
 
57
61
  it( 'triggers a DELETE request for an existing record', async () => {
58
62
  const deletedRecord = { title: 'new post', id: 10 };
59
- const entities = [
63
+ const configs = [
60
64
  { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
61
65
  ];
62
66
 
@@ -66,7 +70,7 @@ describe( 'deleteEntityRecord', () => {
66
70
  __unstableReleaseStoreLock: jest.fn(),
67
71
  } );
68
72
  // Provide entities
69
- dispatch.mockReturnValueOnce( entities );
73
+ dispatch.mockReturnValueOnce( configs );
70
74
 
71
75
  // Provide response
72
76
  apiFetch.mockImplementation( () => deletedRecord );
@@ -106,6 +110,68 @@ describe( 'deleteEntityRecord', () => {
106
110
 
107
111
  expect( result ).toBe( deletedRecord );
108
112
  } );
113
+
114
+ it( 'throws on error when throwOnError is true', async () => {
115
+ const entities = [
116
+ { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
117
+ ];
118
+
119
+ const dispatch = Object.assign( jest.fn(), {
120
+ receiveEntityRecords: jest.fn(),
121
+ __unstableAcquireStoreLock: jest.fn(),
122
+ __unstableReleaseStoreLock: jest.fn(),
123
+ } );
124
+ // Provide entities
125
+ dispatch.mockReturnValueOnce( entities );
126
+
127
+ // Provide response
128
+ apiFetch.mockImplementation( () => {
129
+ throw new Error( 'API error' );
130
+ } );
131
+
132
+ await expect(
133
+ deleteEntityRecord(
134
+ 'postType',
135
+ 'post',
136
+ 10,
137
+ {},
138
+ {
139
+ throwOnError: true,
140
+ }
141
+ )( { dispatch } )
142
+ ).rejects.toEqual( new Error( 'API error' ) );
143
+ } );
144
+
145
+ it( 'resolves on error when throwOnError is false', async () => {
146
+ const entities = [
147
+ { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
148
+ ];
149
+
150
+ const dispatch = Object.assign( jest.fn(), {
151
+ receiveEntityRecords: jest.fn(),
152
+ __unstableAcquireStoreLock: jest.fn(),
153
+ __unstableReleaseStoreLock: jest.fn(),
154
+ } );
155
+ // Provide entities
156
+ dispatch.mockReturnValueOnce( entities );
157
+
158
+ // Provide response
159
+ apiFetch.mockImplementation( () => {
160
+ throw new Error( 'API error' );
161
+ } );
162
+
163
+ await expect(
164
+ deleteEntityRecord(
165
+ 'postType',
166
+ 'post',
167
+ 10,
168
+ {},
169
+ {
170
+ throwOnError: false,
171
+ }
172
+ )( { dispatch } )
173
+ ).resolves.toBe( false );
174
+ } );
109
175
  } );
110
176
 
111
177
  describe( 'saveEditedEntityRecord', () => {
@@ -116,7 +182,7 @@ describe( 'saveEditedEntityRecord', () => {
116
182
 
117
183
  it( 'Uses "id" as a key when no entity key is provided', async () => {
118
184
  const area = { id: 1, menu: 0 };
119
- const entities = [
185
+ const configs = [
120
186
  {
121
187
  kind: 'root',
122
188
  name: 'navigationArea',
@@ -132,7 +198,7 @@ describe( 'saveEditedEntityRecord', () => {
132
198
  saveEntityRecord: jest.fn(),
133
199
  } );
134
200
  // Provide entities
135
- dispatch.mockReturnValueOnce( entities );
201
+ dispatch.mockReturnValueOnce( configs );
136
202
 
137
203
  // Provide response
138
204
  const updatedRecord = { ...area, menu: 10 };
@@ -156,7 +222,7 @@ describe( 'saveEditedEntityRecord', () => {
156
222
 
157
223
  it( 'Uses the entity key when provided', async () => {
158
224
  const area = { area: 'primary', menu: 0 };
159
- const entities = [
225
+ const configs = [
160
226
  {
161
227
  kind: 'root',
162
228
  name: 'navigationArea',
@@ -173,7 +239,7 @@ describe( 'saveEditedEntityRecord', () => {
173
239
  saveEntityRecord: jest.fn(),
174
240
  } );
175
241
  // Provide entities
176
- dispatch.mockReturnValueOnce( entities );
242
+ dispatch.mockReturnValueOnce( configs );
177
243
 
178
244
  // Provide response
179
245
  const updatedRecord = { ...area, menu: 10 };
@@ -197,27 +263,28 @@ describe( 'saveEditedEntityRecord', () => {
197
263
  } );
198
264
 
199
265
  describe( 'saveEntityRecord', () => {
266
+ let dispatch;
200
267
  beforeEach( async () => {
201
268
  apiFetch.mockReset();
202
269
  jest.useFakeTimers();
270
+ dispatch = Object.assign( jest.fn(), {
271
+ receiveEntityRecords: jest.fn(),
272
+ __unstableAcquireStoreLock: jest.fn(),
273
+ __unstableReleaseStoreLock: jest.fn(),
274
+ } );
203
275
  } );
204
276
 
205
277
  it( 'triggers a POST request for a new record', async () => {
206
278
  const post = { title: 'new post' };
207
- const entities = [
279
+ const configs = [
208
280
  { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
209
281
  ];
210
282
  const select = {
211
283
  getRawEntityRecord: () => post,
212
284
  };
213
285
 
214
- const dispatch = Object.assign( jest.fn(), {
215
- receiveEntityRecords: jest.fn(),
216
- __unstableAcquireStoreLock: jest.fn(),
217
- __unstableReleaseStoreLock: jest.fn(),
218
- } );
219
286
  // Provide entities
220
- dispatch.mockReturnValueOnce( entities );
287
+ dispatch.mockReturnValueOnce( configs );
221
288
 
222
289
  // Provide response
223
290
  const updatedRecord = { ...post, id: 10 };
@@ -274,8 +341,8 @@ describe( 'saveEntityRecord', () => {
274
341
  expect( result ).toBe( updatedRecord );
275
342
  } );
276
343
 
277
- it( 'triggers a PUT request for an existing record', async () => {
278
- const post = { id: 10, title: 'new post' };
344
+ it( 'throws on error when throwOnError is true', async () => {
345
+ const post = { title: 'new post' };
279
346
  const entities = [
280
347
  { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
281
348
  ];
@@ -283,14 +350,57 @@ describe( 'saveEntityRecord', () => {
283
350
  getRawEntityRecord: () => post,
284
351
  };
285
352
 
286
- const dispatch = Object.assign( jest.fn(), {
287
- receiveEntityRecords: jest.fn(),
288
- __unstableAcquireStoreLock: jest.fn(),
289
- __unstableReleaseStoreLock: jest.fn(),
353
+ // Provide entities
354
+ dispatch.mockReturnValueOnce( entities );
355
+
356
+ // Provide response
357
+ apiFetch.mockImplementation( () => {
358
+ throw new Error( 'API error' );
290
359
  } );
360
+
361
+ await expect(
362
+ saveEntityRecord( 'postType', 'post', post, {
363
+ throwOnError: true,
364
+ } )( { select, dispatch } )
365
+ ).rejects.toEqual( new Error( 'API error' ) );
366
+ } );
367
+
368
+ it( 'resolves on error when throwOnError is false', async () => {
369
+ const post = { title: 'new post' };
370
+ const entities = [
371
+ { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
372
+ ];
373
+ const select = {
374
+ getRawEntityRecord: () => post,
375
+ };
376
+
291
377
  // Provide entities
292
378
  dispatch.mockReturnValueOnce( entities );
293
379
 
380
+ // Provide response
381
+ apiFetch.mockImplementation( () => {
382
+ throw new Error( 'API error' );
383
+ } );
384
+
385
+ await expect(
386
+ saveEntityRecord( 'postType', 'post', post, {
387
+ throwOnError: false,
388
+ } )( { select, dispatch } )
389
+ ).resolves.toEqual( undefined );
390
+ } );
391
+
392
+ it( 'triggers a PUT request for an existing record', async () => {
393
+ const post = { id: 10, title: 'new post' };
394
+ const configs = [
395
+ { name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
396
+ ];
397
+ const select = {
398
+ getRawEntityRecord: () => post,
399
+ };
400
+
401
+ // Provide entities
402
+ dispatch.mockReturnValueOnce( configs );
403
+
294
404
  // Provide response
295
405
  const updatedRecord = { ...post, id: 10 };
296
406
  apiFetch.mockImplementation( () => {
@@ -348,7 +458,7 @@ describe( 'saveEntityRecord', () => {
348
458
 
349
459
  it( 'triggers a PUT request for an existing record with a custom key', async () => {
350
460
  const postType = { slug: 'page', title: 'Pages' };
351
- const entities = [
461
+ const configs = [
352
462
  {
353
463
  name: 'postType',
354
464
  kind: 'root',
@@ -360,13 +470,8 @@ describe( 'saveEntityRecord', () => {
360
470
  getRawEntityRecord: () => ( {} ),
361
471
  };
362
472
 
363
- const dispatch = Object.assign( jest.fn(), {
364
- receiveEntityRecords: jest.fn(),
365
- __unstableAcquireStoreLock: jest.fn(),
366
- __unstableReleaseStoreLock: jest.fn(),
367
- } );
368
473
  // Provide entities
369
- dispatch.mockReturnValueOnce( entities );
474
+ dispatch.mockReturnValueOnce( configs );
370
475
 
371
476
  // Provide response
372
477
  apiFetch.mockImplementation( () => postType );
@@ -9,8 +9,8 @@ jest.mock( '@wordpress/api-fetch' );
9
9
  */
10
10
  import {
11
11
  getMethodName,
12
- defaultEntities,
13
- getKindEntities,
12
+ rootEntitiesConfig,
13
+ getOrLoadEntitiesConfig,
14
14
  prePersistPostType,
15
15
  } from '../entities';
16
16
 
@@ -40,10 +40,10 @@ describe( 'getMethodName', () => {
40
40
  } );
41
41
 
42
42
  it( 'should include the kind in the method name', () => {
43
- const id = defaultEntities.length;
44
- defaultEntities[ id ] = { name: 'book', kind: 'postType' };
43
+ const id = rootEntitiesConfig.length;
44
+ rootEntitiesConfig[ id ] = { name: 'book', kind: 'postType' };
45
45
  const methodName = getMethodName( 'postType', 'book' );
46
- delete defaultEntities[ id ];
46
+ delete rootEntitiesConfig[ id ];
47
47
 
48
48
  expect( methodName ).toEqual( 'getPostTypeBook' );
49
49
  } );
@@ -58,19 +58,19 @@ describe( 'getKindEntities', () => {
58
58
  it( 'shouldn’t do anything if the entities have already been resolved', async () => {
59
59
  const dispatch = jest.fn();
60
60
  const select = {
61
- getEntitiesByKind: jest.fn( () => entities ),
61
+ getEntitiesConfig: jest.fn( () => entities ),
62
62
  };
63
63
  const entities = [ { kind: 'postType' } ];
64
- await getKindEntities( 'postType' )( { dispatch, select } );
64
+ await getOrLoadEntitiesConfig( 'postType' )( { dispatch, select } );
65
65
  expect( dispatch ).not.toHaveBeenCalled();
66
66
  } );
67
67
 
68
68
  it( 'shouldn’t do anything if there no defined kind config', async () => {
69
69
  const dispatch = jest.fn();
70
70
  const select = {
71
- getEntitiesByKind: jest.fn( () => [] ),
71
+ getEntitiesConfig: jest.fn( () => [] ),
72
72
  };
73
- await getKindEntities( 'unknownKind' )( { dispatch, select } );
73
+ await getOrLoadEntitiesConfig( 'unknownKind' )( { dispatch, select } );
74
74
  expect( dispatch ).not.toHaveBeenCalled();
75
75
  } );
76
76
 
@@ -85,11 +85,11 @@ describe( 'getKindEntities', () => {
85
85
  ];
86
86
  const dispatch = jest.fn();
87
87
  const select = {
88
- getEntitiesByKind: jest.fn( () => [] ),
88
+ getEntitiesConfig: jest.fn( () => [] ),
89
89
  };
90
90
  triggerFetch.mockImplementation( () => fetchedEntities );
91
91
 
92
- await getKindEntities( 'postType' )( { dispatch, select } );
92
+ await getOrLoadEntitiesConfig( 'postType' )( { dispatch, select } );
93
93
  expect( dispatch ).toHaveBeenCalledTimes( 1 );
94
94
  expect( dispatch.mock.calls[ 0 ][ 0 ].type ).toBe( 'ADD_ENTITIES' );
95
95
  expect( dispatch.mock.calls[ 0 ][ 0 ].entities.length ).toBe( 1 );
@@ -46,7 +46,7 @@ describe( 'entities', () => {
46
46
  it( 'returns the default state for all defined entities', () => {
47
47
  const state = entities( undefined, {} );
48
48
 
49
- expect( state.data.root.postType.queriedData ).toEqual( {
49
+ expect( state.records.root.postType.queriedData ).toEqual( {
50
50
  items: {},
51
51
  queries: {},
52
52
  itemIsComplete: {},
@@ -65,7 +65,7 @@ describe( 'entities', () => {
65
65
  name: 'postType',
66
66
  } );
67
67
 
68
- expect( state.data.root.postType.queriedData ).toEqual( {
68
+ expect( state.records.root.postType.queriedData ).toEqual( {
69
69
  items: {
70
70
  default: {
71
71
  b: { slug: 'b', title: 'beach' },
@@ -84,7 +84,7 @@ describe( 'entities', () => {
84
84
 
85
85
  it( 'appends the received post types by slug', () => {
86
86
  const originalState = deepFreeze( {
87
- data: {
87
+ records: {
88
88
  root: {
89
89
  postType: {
90
90
  queriedData: {
@@ -111,7 +111,7 @@ describe( 'entities', () => {
111
111
  name: 'postType',
112
112
  } );
113
113
 
114
- expect( state.data.root.postType.queriedData ).toEqual( {
114
+ expect( state.records.root.postType.queriedData ).toEqual( {
115
115
  items: {
116
116
  default: {
117
117
  w: { slug: 'w', title: 'water' },
@@ -201,7 +201,7 @@ describe( 'getEntityRecords', () => {
201
201
  dispatch.__unstableAcquireStoreLock
202
202
  ).toHaveBeenCalledWith(
203
203
  'core',
204
- [ 'entities', 'data', 'root', 'postType' ],
204
+ [ 'entities', 'records', 'root', 'postType' ],
205
205
  { exclusive: false }
206
206
  );
207
207
  expect( dispatch.__unstableReleaseStoreLock ).toHaveBeenCalledTimes(
@@ -393,14 +393,14 @@ describe( 'getAutosaves', () => {
393
393
  const postType = 'post';
394
394
  const postId = 1;
395
395
  const restBase = 'posts';
396
- const postEntity = { rest_base: restBase };
396
+ const postEntityConfig = { rest_base: restBase };
397
397
 
398
398
  triggerFetch.mockImplementation( () => SUCCESSFUL_RESPONSE );
399
399
  const dispatch = Object.assign( jest.fn(), {
400
400
  receiveAutosaves: jest.fn(),
401
401
  } );
402
402
  const resolveSelect = Object.assign( jest.fn(), {
403
- getPostType: jest.fn( () => postEntity ),
403
+ getPostType: jest.fn( () => postEntityConfig ),
404
404
  } );
405
405
  await getAutosaves( postType, postId )( { dispatch, resolveSelect } );
406
406
 
@@ -417,14 +417,14 @@ describe( 'getAutosaves', () => {
417
417
  const postType = 'post';
418
418
  const postId = 1;
419
419
  const restBase = 'posts';
420
- const postEntity = { rest_base: restBase };
420
+ const postEntityConfig = { rest_base: restBase };
421
421
 
422
422
  triggerFetch.mockImplementation( () => [] );
423
423
  const dispatch = Object.assign( jest.fn(), {
424
424
  receiveAutosaves: jest.fn(),
425
425
  } );
426
426
  const resolveSelect = Object.assign( jest.fn(), {
427
- getPostType: jest.fn( () => postEntity ),
427
+ getPostType: jest.fn( () => postEntityConfig ),
428
428
  } );
429
429
  await getAutosaves( postType, postId )( { dispatch, resolveSelect } );
430
430
 
@@ -32,7 +32,7 @@ describe.each( [
32
32
  it( 'should return undefined for unknown entity kind, name', () => {
33
33
  const state = deepFreeze( {
34
34
  entities: {
35
- data: {
35
+ records: {
36
36
  root: {
37
37
  postType: {
38
38
  queriedData: {
@@ -51,7 +51,7 @@ describe.each( [
51
51
  it( 'should return undefined for unknown record’s key', () => {
52
52
  const state = deepFreeze( {
53
53
  entities: {
54
- data: {
54
+ records: {
55
55
  root: {
56
56
  postType: {
57
57
  queriedData: {
@@ -70,7 +70,7 @@ describe.each( [
70
70
  it( 'should return a record by key', () => {
71
71
  const state = deepFreeze( {
72
72
  entities: {
73
- data: {
73
+ records: {
74
74
  root: {
75
75
  postType: {
76
76
  queriedData: {
@@ -105,7 +105,7 @@ describe.each( [
105
105
  it( 'should return filtered item if complete item received, filtered item requested', () => {
106
106
  const state = deepFreeze( {
107
107
  entities: {
108
- data: {
108
+ records: {
109
109
  postType: {
110
110
  post: {
111
111
  queriedData: {
@@ -142,7 +142,7 @@ describe( 'hasEntityRecords', () => {
142
142
  it( 'returns false if entity records have not been received', () => {
143
143
  const state = deepFreeze( {
144
144
  entities: {
145
- data: {
145
+ records: {
146
146
  root: {
147
147
  postType: {
148
148
  queriedData: {
@@ -162,7 +162,7 @@ describe( 'hasEntityRecords', () => {
162
162
  it( 'returns false if the entity configuration is not known', () => {
163
163
  const state = deepFreeze( {
164
164
  entities: {
165
- data: {},
165
+ records: {},
166
166
  },
167
167
  } );
168
168
 
@@ -172,7 +172,7 @@ describe( 'hasEntityRecords', () => {
172
172
  it( 'returns true if entity records have been received', () => {
173
173
  const state = deepFreeze( {
174
174
  entities: {
175
- data: {
175
+ records: {
176
176
  root: {
177
177
  postType: {
178
178
  queriedData: {
@@ -239,7 +239,7 @@ describe( 'getRawEntityRecord', () => {
239
239
  name: 'someName',
240
240
  },
241
241
  ],
242
- data: { ...data },
242
+ records: { ...data },
243
243
  },
244
244
  } );
245
245
  expect(
@@ -261,7 +261,7 @@ describe( 'getRawEntityRecord', () => {
261
261
  rawAttributes: [ 'title' ],
262
262
  },
263
263
  ],
264
- data: { ...data },
264
+ records: { ...data },
265
265
  },
266
266
  } );
267
267
  expect(
@@ -278,7 +278,7 @@ describe( 'getEntityRecords', () => {
278
278
  it( 'should return null by default', () => {
279
279
  const state = deepFreeze( {
280
280
  entities: {
281
- data: {
281
+ records: {
282
282
  root: {
283
283
  postType: {
284
284
  queriedData: {
@@ -297,7 +297,7 @@ describe( 'getEntityRecords', () => {
297
297
  it( 'should return null for an unknown entity configuration', () => {
298
298
  const state = deepFreeze( {
299
299
  entities: {
300
- data: {},
300
+ records: {},
301
301
  },
302
302
  } );
303
303
 
@@ -307,7 +307,7 @@ describe( 'getEntityRecords', () => {
307
307
  it( 'should return all the records', () => {
308
308
  const state = deepFreeze( {
309
309
  entities: {
310
- data: {
310
+ records: {
311
311
  root: {
312
312
  postType: {
313
313
  queriedData: {
@@ -343,7 +343,7 @@ describe( 'getEntityRecords', () => {
343
343
  it( 'should return filtered items', () => {
344
344
  const state = deepFreeze( {
345
345
  entities: {
346
- data: {
346
+ records: {
347
347
  postType: {
348
348
  post: {
349
349
  queriedData: {
@@ -382,7 +382,7 @@ describe( 'getEntityRecords', () => {
382
382
  it( 'should return the same instance with the same arguments', () => {
383
383
  let state = deepFreeze( {
384
384
  entities: {
385
- data: {},
385
+ records: {},
386
386
  },
387
387
  } );
388
388
 
@@ -427,7 +427,7 @@ describe( '__experimentalGetDirtyEntityRecords', () => {
427
427
  transientEdits: { someTransientEditProperty: true },
428
428
  },
429
429
  ],
430
- data: {
430
+ records: {
431
431
  someKind: {
432
432
  someName: {
433
433
  queriedData: {
@@ -476,7 +476,7 @@ describe( '__experimentalGetDirtyEntityRecords', () => {
476
476
  transientEdits: { someTransientEditProperty: true },
477
477
  },
478
478
  ],
479
- data: {
479
+ records: {
480
480
  someKind: {
481
481
  someName: {
482
482
  queriedData: {
@@ -533,7 +533,7 @@ describe( '__experimentalGetEntitiesBeingSaved', () => {
533
533
  transientEdits: { someTransientEditProperty: true },
534
534
  },
535
535
  ],
536
- data: {
536
+ records: {
537
537
  someKind: {
538
538
  someName: {
539
539
  queriedData: {
@@ -573,7 +573,7 @@ describe( '__experimentalGetEntitiesBeingSaved', () => {
573
573
  describe( 'getEntityRecordNonTransientEdits', () => {
574
574
  it( 'should return an empty object when the entity does not have a loaded config.', () => {
575
575
  const state = deepFreeze( {
576
- entities: { config: [], data: {} },
576
+ entities: { config: [], records: {} },
577
577
  } );
578
578
  expect(
579
579
  getEntityRecordNonTransientEdits(
@@ -597,11 +597,11 @@ describe( 'getEmbedPreview()', () => {
597
597
 
598
598
  state = deepFreeze( {
599
599
  embedPreviews: {
600
- 'http://example.com/': { data: 42 },
600
+ 'http://example.com/': { records: 42 },
601
601
  },
602
602
  } );
603
603
  expect( getEmbedPreview( state, 'http://example.com/' ) ).toEqual( {
604
- data: 42,
604
+ records: 42,
605
605
  } );
606
606
  } );
607
607
  } );
@@ -653,7 +653,7 @@ describe( 'canUserEditEntityRecord', () => {
653
653
  it( 'returns false by default', () => {
654
654
  const state = deepFreeze( {
655
655
  userPermissions: {},
656
- entities: { data: {} },
656
+ entities: { records: {} },
657
657
  } );
658
658
  expect( canUserEditEntityRecord( state, 'postType', 'post' ) ).toBe(
659
659
  false
@@ -674,7 +674,7 @@ describe( 'canUserEditEntityRecord', () => {
674
674
  __unstable_rest_base: 'posts',
675
675
  },
676
676
  ],
677
- data: {
677
+ records: {
678
678
  root: {
679
679
  postType: {
680
680
  queriedData: {
@@ -4,7 +4,7 @@
4
4
  import { isEqual } from 'lodash';
5
5
 
6
6
  /**
7
- * Given the current and next item entity, returns the minimally "modified"
7
+ * Given the current and next item entity record, returns the minimally "modified"
8
8
  * result of the next item, preferring value references from the original item
9
9
  * if equal. If all values match, the original item is returned.
10
10
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Checks whether the attribute is a "raw" attribute or not.
3
3
  *
4
- * @param {Object} entity Entity data.
4
+ * @param {Object} entity Entity record.
5
5
  * @param {string} attribute Attribute name.
6
6
  *
7
7
  * @return {boolean} Is the attribute raw
@@ -5,18 +5,18 @@ import { isRawAttribute } from '../';
5
5
 
6
6
  describe( 'isRawAttribute', () => {
7
7
  it( 'should correctly assess that the attribute is not raw', () => {
8
- const entity = {
8
+ const entityConfig = {
9
9
  kind: 'someKind',
10
10
  name: 'someName',
11
11
  };
12
- expect( isRawAttribute( entity, 'title' ) ).toBe( false );
12
+ expect( isRawAttribute( entityConfig, 'title' ) ).toBe( false );
13
13
  } );
14
14
  it( 'should correctly assess that the attribute is raw', () => {
15
- const entity = {
15
+ const entityConfig = {
16
16
  kind: 'someKind',
17
17
  name: 'someName',
18
18
  rawAttributes: [ 'title' ],
19
19
  };
20
- expect( isRawAttribute( entity, 'title' ) ).toBe( true );
20
+ expect( isRawAttribute( entityConfig, 'title' ) ).toBe( true );
21
21
  } );
22
22
  } );
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/entity-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/entity-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"]}