@wordpress/core-data 4.5.0 → 4.8.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 (58) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +175 -85
  3. package/build/entities.js +49 -46
  4. package/build/entities.js.map +1 -1
  5. package/build/entity-types/{navigation-area.js → entities.js} +1 -1
  6. package/build/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
  7. package/build/hooks/constants.js +0 -2
  8. package/build/hooks/constants.js.map +1 -1
  9. package/build/hooks/index.js +38 -0
  10. package/build/hooks/index.js.map +1 -0
  11. package/build/hooks/use-entity-record.js +22 -8
  12. package/build/hooks/use-entity-record.js.map +1 -1
  13. package/build/hooks/use-entity-records.js +21 -8
  14. package/build/hooks/use-entity-records.js.map +1 -1
  15. package/build/index.js +17 -21
  16. package/build/index.js.map +1 -1
  17. package/build/queried-data/get-query-parts.js +4 -0
  18. package/build/queried-data/get-query-parts.js.map +1 -1
  19. package/build/selectors.js +163 -163
  20. package/build/selectors.js.map +1 -1
  21. package/build-module/entities.js +49 -46
  22. package/build-module/entities.js.map +1 -1
  23. package/build-module/entity-types/entities.js +2 -0
  24. package/build-module/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
  25. package/build-module/hooks/constants.js +0 -1
  26. package/build-module/hooks/constants.js.map +1 -1
  27. package/build-module/hooks/index.js +3 -0
  28. package/build-module/hooks/index.js.map +1 -0
  29. package/build-module/hooks/use-entity-record.js +18 -7
  30. package/build-module/hooks/use-entity-record.js.map +1 -1
  31. package/build-module/hooks/use-entity-records.js +17 -7
  32. package/build-module/hooks/use-entity-records.js.map +1 -1
  33. package/build-module/index.js +2 -3
  34. package/build-module/index.js.map +1 -1
  35. package/build-module/queried-data/get-query-parts.js +4 -0
  36. package/build-module/queried-data/get-query-parts.js.map +1 -1
  37. package/build-module/selectors.js +164 -163
  38. package/build-module/selectors.js.map +1 -1
  39. package/package.json +12 -12
  40. package/src/entities.ts +342 -129
  41. package/src/entity-types/entities.ts +127 -0
  42. package/src/entity-types/index.ts +1 -3
  43. package/src/hooks/constants.ts +1 -2
  44. package/src/hooks/index.ts +8 -0
  45. package/src/hooks/test/use-entity-record.js +1 -0
  46. package/src/hooks/test/use-entity-records.js +1 -0
  47. package/src/hooks/test/use-query-select.js +1 -0
  48. package/src/hooks/use-entity-record.ts +32 -9
  49. package/src/hooks/use-entity-records.ts +28 -30
  50. package/src/index.js +2 -3
  51. package/src/queried-data/get-query-parts.js +3 -0
  52. package/src/queried-data/test/get-query-parts.js +4 -0
  53. package/src/selectors.ts +406 -216
  54. package/src/test/actions.js +30 -14
  55. package/src/test/entities.js +5 -0
  56. package/src/test/resolvers.js +11 -0
  57. package/build-module/entity-types/navigation-area.js +0 -2
  58. package/src/entity-types/navigation-area.ts +0 -29
@@ -58,6 +58,11 @@ describe( 'deleteEntityRecord', () => {
58
58
  jest.useFakeTimers();
59
59
  } );
60
60
 
61
+ afterEach( () => {
62
+ jest.runOnlyPendingTimers();
63
+ jest.useRealTimers();
64
+ } );
65
+
61
66
  it( 'triggers a DELETE request for an existing record', async () => {
62
67
  const deletedRecord = { title: 'new post', id: 10 };
63
68
  const configs = [
@@ -180,13 +185,18 @@ describe( 'saveEditedEntityRecord', () => {
180
185
  jest.useFakeTimers();
181
186
  } );
182
187
 
188
+ afterEach( () => {
189
+ jest.runOnlyPendingTimers();
190
+ jest.useRealTimers();
191
+ } );
192
+
183
193
  it( 'Uses "id" as a key when no entity key is provided', async () => {
184
- const area = { id: 1, menu: 0 };
194
+ const item = { id: 1, menu: 0 };
185
195
  const configs = [
186
196
  {
187
197
  kind: 'root',
188
- name: 'navigationArea',
189
- baseURL: '/wp/v2/block-navigation-areas',
198
+ name: 'menuItem',
199
+ baseURL: '/wp/v2/menu-items',
190
200
  },
191
201
  ];
192
202
  const select = {
@@ -201,33 +211,33 @@ describe( 'saveEditedEntityRecord', () => {
201
211
  dispatch.mockReturnValueOnce( configs );
202
212
 
203
213
  // Provide response
204
- const updatedRecord = { ...area, menu: 10 };
214
+ const updatedRecord = { ...item, menu: 10 };
205
215
  apiFetch.mockImplementation( () => {
206
216
  return updatedRecord;
207
217
  } );
208
218
 
209
219
  await saveEditedEntityRecord(
210
220
  'root',
211
- 'navigationArea',
221
+ 'menuItem',
212
222
  1
213
223
  )( { dispatch, select } );
214
224
 
215
225
  expect( dispatch.saveEntityRecord ).toHaveBeenCalledWith(
216
226
  'root',
217
- 'navigationArea',
227
+ 'menuItem',
218
228
  { id: 1 },
219
229
  undefined
220
230
  );
221
231
  } );
222
232
 
223
233
  it( 'Uses the entity key when provided', async () => {
224
- const area = { area: 'primary', menu: 0 };
234
+ const item = { name: 'primary', menu: 0 };
225
235
  const configs = [
226
236
  {
227
237
  kind: 'root',
228
- name: 'navigationArea',
229
- baseURL: '/wp/v2/block-navigation-areas',
230
- key: 'area',
238
+ name: 'menuLocation',
239
+ baseURL: '/wp/v2/menu-items',
240
+ key: 'name',
231
241
  },
232
242
  ];
233
243
  const select = {
@@ -242,21 +252,21 @@ describe( 'saveEditedEntityRecord', () => {
242
252
  dispatch.mockReturnValueOnce( configs );
243
253
 
244
254
  // Provide response
245
- const updatedRecord = { ...area, menu: 10 };
255
+ const updatedRecord = { ...item, menu: 10 };
246
256
  apiFetch.mockImplementation( () => {
247
257
  return updatedRecord;
248
258
  } );
249
259
 
250
260
  await saveEditedEntityRecord(
251
261
  'root',
252
- 'navigationArea',
262
+ 'menuLocation',
253
263
  'primary'
254
264
  )( { dispatch, select } );
255
265
 
256
266
  expect( dispatch.saveEntityRecord ).toHaveBeenCalledWith(
257
267
  'root',
258
- 'navigationArea',
259
- { area: 'primary' },
268
+ 'menuLocation',
269
+ { name: 'primary' },
260
270
  undefined
261
271
  );
262
272
  } );
@@ -264,6 +274,7 @@ describe( 'saveEditedEntityRecord', () => {
264
274
 
265
275
  describe( 'saveEntityRecord', () => {
266
276
  let dispatch;
277
+
267
278
  beforeEach( async () => {
268
279
  apiFetch.mockReset();
269
280
  jest.useFakeTimers();
@@ -274,6 +285,11 @@ describe( 'saveEntityRecord', () => {
274
285
  } );
275
286
  } );
276
287
 
288
+ afterEach( () => {
289
+ jest.runOnlyPendingTimers();
290
+ jest.useRealTimers();
291
+ } );
292
+
277
293
  it( 'triggers a POST request for a new record', async () => {
278
294
  const post = { title: 'new post' };
279
295
  const configs = [
@@ -55,6 +55,11 @@ describe( 'getKindEntities', () => {
55
55
  jest.useFakeTimers();
56
56
  } );
57
57
 
58
+ afterEach( () => {
59
+ jest.runOnlyPendingTimers();
60
+ jest.useRealTimers();
61
+ } );
62
+
58
63
  it( 'shouldn’t do anything if the entities have already been resolved', async () => {
59
64
  const dispatch = jest.fn();
60
65
  const select = {
@@ -27,11 +27,17 @@ describe( 'getEntityRecord', () => {
27
27
  baseURLParams: { context: 'edit' },
28
28
  },
29
29
  ];
30
+
30
31
  beforeEach( async () => {
31
32
  triggerFetch.mockReset();
32
33
  jest.useFakeTimers();
33
34
  } );
34
35
 
36
+ afterEach( () => {
37
+ jest.runOnlyPendingTimers();
38
+ jest.useRealTimers();
39
+ } );
40
+
35
41
  it( 'yields with requested post type', async () => {
36
42
  const dispatch = Object.assign( jest.fn(), {
37
43
  receiveEntityRecords: jest.fn(),
@@ -149,6 +155,11 @@ describe( 'getEntityRecords', () => {
149
155
  jest.useFakeTimers();
150
156
  } );
151
157
 
158
+ afterEach( () => {
159
+ jest.runOnlyPendingTimers();
160
+ jest.useRealTimers();
161
+ } );
162
+
152
163
  it( 'dispatches the requested post type', async () => {
153
164
  const dispatch = Object.assign( jest.fn(), {
154
165
  receiveEntityRecords: jest.fn(),
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=navigation-area.js.map
@@ -1,29 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Context, OmitNevers } from './helpers';
5
-
6
- import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
-
8
- declare module './base-entity-records' {
9
- export namespace BaseEntityRecords {
10
- export interface NavigationArea< C extends Context > {
11
- /**
12
- * The name of the navigation area.
13
- */
14
- name: string;
15
- /**
16
- * The description of the navigation area.
17
- */
18
- description: string;
19
- /**
20
- * The ID of the assigned navigation.
21
- */
22
- navigation: number;
23
- }
24
- }
25
- }
26
-
27
- export type NavigationArea< C extends Context > = OmitNevers<
28
- _BaseEntityRecords.NavigationArea< C >
29
- >;