@wordpress/core-data 4.2.0-next.e230fbab09.0 → 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 +7 -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
@@ -1,12 +1,17 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers';
4
+ import type {
5
+ CommentingStatus,
6
+ Context,
7
+ OmitNevers,
8
+ PingStatus,
9
+ } from './helpers';
5
10
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
11
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
12
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
13
+ declare module './base-entity-records' {
14
+ export namespace BaseEntityRecords {
10
15
  export interface Settings< C extends Context > {
11
16
  /**
12
17
  * What to show on the front page
@@ -89,5 +94,5 @@ declare module './base-entity-types' {
89
94
  }
90
95
 
91
96
  export type Settings< C extends Context > = OmitNevers<
92
- _BaseEntityTypes.Settings< C >
97
+ _BaseEntityRecords.Settings< C >
93
98
  >;
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Widget } from './widget';
5
- import { Context, OmitNevers } from './helpers';
4
+ import type { Context, OmitNevers } from './helpers';
6
5
 
7
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
8
7
 
9
- declare module './base-entity-types' {
10
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
11
10
  export interface Sidebar< C extends Context > {
12
11
  /**
13
12
  * ID of sidebar.
@@ -48,7 +47,7 @@ declare module './base-entity-types' {
48
47
  /**
49
48
  * Nested widgets.
50
49
  */
51
- widgets: ( Widget< C > | string )[];
50
+ widgets: ( BaseEntityRecords.Widget< C > | string )[];
52
51
  }
53
52
  }
54
53
  }
@@ -56,5 +55,5 @@ declare module './base-entity-types' {
56
55
  type SidebarStatus = 'active' | 'inactive';
57
56
 
58
57
  export type Sidebar< C extends Context > = OmitNevers<
59
- _BaseEntityTypes.Sidebar< C >
58
+ _BaseEntityRecords.Sidebar< C >
60
59
  >;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Context, ContextualField, OmitNevers } from './helpers';
4
+ import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
7
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
10
10
  export interface Taxonomy< C extends Context > {
11
11
  /**
12
12
  * All capabilities used by the taxonomy.
@@ -88,5 +88,5 @@ declare module './base-entity-types' {
88
88
  }
89
89
 
90
90
  export type Taxonomy< C extends Context > = OmitNevers<
91
- _BaseEntityTypes.Taxonomy< C >
91
+ _BaseEntityRecords.Taxonomy< C >
92
92
  >;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Context, PostFormat, RenderedText, OmitNevers } from './helpers';
4
+ import type { Context, PostFormat, RenderedText, OmitNevers } from './helpers';
5
5
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
7
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
10
10
  export interface Theme< C extends Context > {
11
11
  /**
12
12
  * The theme's stylesheet. This uniquely identifies the theme.
@@ -218,5 +218,5 @@ declare module './base-entity-types' {
218
218
  }
219
219
 
220
220
  export type Theme< C extends Context > = OmitNevers<
221
- _BaseEntityTypes.Theme< C >
221
+ _BaseEntityRecords.Theme< C >
222
222
  >;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Context, ContextualField, OmitNevers } from './helpers';
4
+ import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
7
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
10
10
  export interface Type< C extends Context > {
11
11
  /**
12
12
  * All capabilities used by the post type.
@@ -76,5 +76,5 @@ declare module './base-entity-types' {
76
76
  }
77
77
 
78
78
  export type Type< C extends Context > = OmitNevers<
79
- _BaseEntityTypes.Type< C >
79
+ _BaseEntityRecords.Type< C >
80
80
  >;
@@ -1,12 +1,17 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers';
4
+ import type {
5
+ AvatarUrls,
6
+ Context,
7
+ ContextualField,
8
+ OmitNevers,
9
+ } from './helpers';
5
10
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
11
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
12
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
13
+ declare module './base-entity-records' {
14
+ export namespace BaseEntityRecords {
10
15
  export interface User< C extends Context > {
11
16
  /**
12
17
  * Unique identifier for the user.
@@ -105,5 +110,5 @@ declare module './base-entity-types' {
105
110
  }
106
111
 
107
112
  export type User< C extends Context > = OmitNevers<
108
- _BaseEntityTypes.User< C >
113
+ _BaseEntityRecords.User< C >
109
114
  >;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Context, OmitNevers } from './helpers';
4
+ import type { Context, OmitNevers } from './helpers';
5
5
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
7
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
10
10
  export interface WidgetType< C extends Context > {
11
11
  /**
12
12
  * Unique slug identifying the widget type.
@@ -33,5 +33,5 @@ declare module './base-entity-types' {
33
33
  }
34
34
 
35
35
  export type WidgetType< C extends Context > = OmitNevers<
36
- _BaseEntityTypes.WidgetType< C >
36
+ _BaseEntityRecords.WidgetType< C >
37
37
  >;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { Context, ContextualField, OmitNevers } from './helpers';
4
+ import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
6
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
7
 
8
- declare module './base-entity-types' {
9
- export namespace BaseEntityTypes {
8
+ declare module './base-entity-records' {
9
+ export namespace BaseEntityRecords {
10
10
  export interface Widget< C extends Context > {
11
11
  /**
12
12
  * Unique identifier for the widget.
@@ -60,5 +60,5 @@ declare module './base-entity-types' {
60
60
  }
61
61
 
62
62
  export type Widget< C extends Context > = OmitNevers<
63
- _BaseEntityTypes.Widget< C >
63
+ _BaseEntityRecords.Widget< C >
64
64
  >;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import {
4
+ import type {
5
5
  Context,
6
6
  PostStatus,
7
7
  RenderedText,
@@ -9,10 +9,10 @@ import {
9
9
  ContextualField,
10
10
  } from './helpers';
11
11
 
12
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
12
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
13
13
 
14
- declare module './base-entity-types' {
15
- export namespace BaseEntityTypes {
14
+ declare module './base-entity-records' {
15
+ export namespace BaseEntityRecords {
16
16
  export interface WpTemplatePart< C extends Context > {
17
17
  /**
18
18
  * ID of template.
@@ -90,5 +90,5 @@ declare module './base-entity-types' {
90
90
  }
91
91
 
92
92
  export type WpTemplatePart< C extends Context > = OmitNevers<
93
- _BaseEntityTypes.WpTemplatePart< C >
93
+ _BaseEntityRecords.WpTemplatePart< C >
94
94
  >;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import {
4
+ import type {
5
5
  Context,
6
6
  PostStatus,
7
7
  RenderedText,
@@ -9,10 +9,10 @@ import {
9
9
  ContextualField,
10
10
  } from './helpers';
11
11
 
12
- import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
12
+ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
13
13
 
14
- declare module './base-entity-types' {
15
- export namespace BaseEntityTypes {
14
+ declare module './base-entity-records' {
15
+ export namespace BaseEntityRecords {
16
16
  export interface WpTemplate< C extends Context > {
17
17
  /**
18
18
  * ID of template.
@@ -90,5 +90,5 @@ declare module './base-entity-types' {
90
90
  }
91
91
 
92
92
  export type WpTemplate< C extends Context > = OmitNevers<
93
- _BaseEntityTypes.WpTemplate< C >
93
+ _BaseEntityRecords.WpTemplate< C >
94
94
  >;
@@ -170,7 +170,7 @@ const fetchLinkSuggestions = async (
170
170
  .slice( 0, perPage )
171
171
  .map(
172
172
  /**
173
- * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result
173
+ * @param {{ id: number, meta?: object, url:string, title?:string, subtype?: string, type?: string }} result
174
174
  */
175
175
  ( result ) => {
176
176
  return {
@@ -60,6 +60,7 @@ const fetchUrlData = async ( url, options = {} ) => {
60
60
  const protocol = getProtocol( url );
61
61
 
62
62
  if (
63
+ ! protocol ||
63
64
  ! isValidProtocol( protocol ) ||
64
65
  ! protocol.startsWith( 'http' ) ||
65
66
  ! /^https?:\/\/[^\/\s]/i.test( url )
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import useQuerySelect from './use-query-select';
5
5
  import { store as coreStore } from '../';
6
- import { Status } from './constants';
6
+ import type { Status } from './constants';
7
7
 
8
8
  interface EntityRecordResolution< RecordType > {
9
9
  /** The requested entity record */
@@ -23,13 +23,18 @@ interface EntityRecordResolution< RecordType > {
23
23
  status: Status;
24
24
  }
25
25
 
26
+ interface Options {
27
+ enabled: boolean;
28
+ }
29
+
26
30
  /**
27
31
  * Resolves the specified entity record.
28
32
  *
29
- * @param kind Kind of the requested entity.
30
- * @param name Name of the requested entity.
31
- * @param recordId Record ID of the requested entity.
32
- *
33
+ * @param kind Kind of the requested entity.
34
+ * @param name Name of the requested entity.
35
+ * @param recordId Record ID of the requested entity.
36
+ * @param options Hook options.
37
+ * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
33
38
  * @example
34
39
  * ```js
35
40
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -58,11 +63,17 @@ interface EntityRecordResolution< RecordType > {
58
63
  export default function __experimentalUseEntityRecord< RecordType >(
59
64
  kind: string,
60
65
  name: string,
61
- recordId: string | number
66
+ recordId: string | number,
67
+ options: Options = { enabled: true }
62
68
  ): EntityRecordResolution< RecordType > {
63
69
  const { data: record, ...rest } = useQuerySelect(
64
- ( query ) => query( coreStore ).getEntityRecord( kind, name, recordId ),
65
- [ kind, name, recordId ]
70
+ ( query ) => {
71
+ if ( ! options.enabled ) {
72
+ return null;
73
+ }
74
+ return query( coreStore ).getEntityRecord( kind, name, recordId );
75
+ },
76
+ [ kind, name, recordId, options.enabled ]
66
77
  );
67
78
 
68
79
  return {
@@ -8,7 +8,7 @@ import { addQueryArgs } from '@wordpress/url';
8
8
  */
9
9
  import useQuerySelect from './use-query-select';
10
10
  import { store as coreStore } from '../';
11
- import { Status } from './constants';
11
+ import type { Status } from './constants';
12
12
 
13
13
  interface EntityRecordsResolution< RecordType > {
14
14
  /** The requested entity record */
@@ -28,12 +28,22 @@ interface EntityRecordsResolution< RecordType > {
28
28
  status: Status;
29
29
  }
30
30
 
31
+ interface Options {
32
+ /**
33
+ * Whether to run the query or short-circuit and return null.
34
+ *
35
+ * @default true
36
+ */
37
+ enabled: boolean;
38
+ }
39
+
31
40
  /**
32
41
  * Resolves the specified entity records.
33
42
  *
34
- * @param kind Kind of the requested entities.
35
- * @param name Name of the requested entities.
36
- * @param queryArgs HTTP query for the requested entities.
43
+ * @param kind Kind of the requested entities.
44
+ * @param name Name of the requested entities.
45
+ * @param queryArgs HTTP query for the requested entities.
46
+ * @param options Hook options.
37
47
  * @example
38
48
  * ```js
39
49
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -62,13 +72,14 @@ interface EntityRecordsResolution< RecordType > {
62
72
  * application, the list of records and the resolution details will be retrieved from
63
73
  * the store state using `getEntityRecords()`, or resolved if missing.
64
74
  *
65
- * @return {EntityRecordsResolution<RecordType>} Entity records data.
75
+ * @return Entity records data.
66
76
  * @template RecordType
67
77
  */
68
78
  export default function __experimentalUseEntityRecords< RecordType >(
69
79
  kind: string,
70
80
  name: string,
71
- queryArgs: unknown = {}
81
+ queryArgs: Record< string, unknown > = {},
82
+ options: Options = { enabled: true }
72
83
  ): EntityRecordsResolution< RecordType > {
73
84
  // Serialize queryArgs to a string that can be safely used as a React dep.
74
85
  // We can't just pass queryArgs as one of the deps, because if it is passed
@@ -77,9 +88,15 @@ export default function __experimentalUseEntityRecords< RecordType >(
77
88
  const queryAsString = addQueryArgs( '', queryArgs );
78
89
 
79
90
  const { data: records, ...rest } = useQuerySelect(
80
- ( query ) =>
81
- query( coreStore ).getEntityRecords( kind, name, queryArgs ),
82
- [ kind, name, queryAsString ]
91
+ ( query ) => {
92
+ if ( ! options.enabled ) {
93
+ return {
94
+ data: [],
95
+ };
96
+ }
97
+ return query( coreStore ).getEntityRecords( kind, name, queryArgs );
98
+ },
99
+ [ kind, name, queryAsString, options.enabled ]
83
100
  );
84
101
 
85
102
  return {
package/src/index.js CHANGED
@@ -11,41 +11,36 @@ import * as selectors from './selectors';
11
11
  import * as actions from './actions';
12
12
  import * as resolvers from './resolvers';
13
13
  import createLocksActions from './locks/actions';
14
- import { defaultEntities, getMethodName } from './entities';
14
+ import { rootEntitiesConfig, getMethodName } from './entities';
15
15
  import { STORE_NAME } from './name';
16
16
 
17
17
  // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
18
- // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
19
- // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...
18
+ // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
19
+ // Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
20
20
  // The "kind" and the "name" of the entity are combined to generate these shortcuts.
21
21
 
22
- const entitySelectors = defaultEntities.reduce( ( result, entity ) => {
22
+ const entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {
23
23
  const { kind, name } = entity;
24
24
  result[ getMethodName( kind, name ) ] = ( state, key, query ) =>
25
25
  selectors.getEntityRecord( state, kind, name, key, query );
26
- result[ getMethodName( kind, name, 'get', true ) ] = ( state, ...args ) =>
27
- selectors.getEntityRecords( state, kind, name, ...args );
26
+ result[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>
27
+ selectors.getEntityRecords( state, kind, name, query );
28
28
  return result;
29
29
  }, {} );
30
30
 
31
- const entityResolvers = defaultEntities.reduce( ( result, entity ) => {
31
+ const entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {
32
32
  const { kind, name } = entity;
33
33
  result[ getMethodName( kind, name ) ] = ( key, query ) =>
34
34
  resolvers.getEntityRecord( kind, name, key, query );
35
35
  const pluralMethodName = getMethodName( kind, name, 'get', true );
36
36
  result[ pluralMethodName ] = ( ...args ) =>
37
37
  resolvers.getEntityRecords( kind, name, ...args );
38
- result[ pluralMethodName ].shouldInvalidate = ( action, ...args ) =>
39
- resolvers.getEntityRecords.shouldInvalidate(
40
- action,
41
- kind,
42
- name,
43
- ...args
44
- );
38
+ result[ pluralMethodName ].shouldInvalidate = ( action ) =>
39
+ resolvers.getEntityRecords.shouldInvalidate( action, kind, name );
45
40
  return result;
46
41
  }, {} );
47
42
 
48
- const entityActions = defaultEntities.reduce( ( result, entity ) => {
43
+ const entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {
49
44
  const { kind, name } = entity;
50
45
  result[ getMethodName( kind, name, 'save' ) ] = ( key ) =>
51
46
  actions.saveEntityRecord( kind, name, key );
@@ -116,7 +116,7 @@ describe( 'isLockAvailable', () => {
116
116
  store: 'core',
117
117
  path: [
118
118
  'entities',
119
- 'data',
119
+ 'records',
120
120
  'postType',
121
121
  'post',
122
122
  16,
@@ -163,7 +163,7 @@ describe( 'isLockAvailable', () => {
163
163
  entities: {
164
164
  locks: [],
165
165
  children: {
166
- data: {
166
+ records: {
167
167
  locks: [],
168
168
  children: {
169
169
  postType: {
@@ -178,7 +178,7 @@ describe( 'isLockAvailable', () => {
178
178
  path: [
179
179
  'core',
180
180
  'entities',
181
- 'data',
181
+ 'records',
182
182
  'postType',
183
183
  'book',
184
184
  67,
@@ -205,7 +205,7 @@ describe( 'isLockAvailable', () => {
205
205
  isLockAvailable(
206
206
  deepFreeze( subState ),
207
207
  'core',
208
- [ 'entities', 'data', 'postType', 'book', 67 ],
208
+ [ 'entities', 'records', 'postType', 'book', 67 ],
209
209
  { exclusive: false }
210
210
  )
211
211
  ).toBe( false );
@@ -23,10 +23,10 @@ export function receiveItems( items, edits ) {
23
23
  * Returns an action object used in signalling that entity records have been
24
24
  * deleted and they need to be removed from entities state.
25
25
  *
26
- * @param {string} kind Kind of the removed entities.
27
- * @param {string} name Name of the removed entities.
28
- * @param {Array|number} records Record IDs of the removed entities.
29
- * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
26
+ * @param {string} kind Kind of the removed entities.
27
+ * @param {string} name Name of the removed entities.
28
+ * @param {Array|number|string} records Record IDs of the removed entities.
29
+ * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
30
30
  * @return {Object} Action object.
31
31
  */
32
32
  export function removeItems( kind, name, records, invalidateCache = false ) {
@@ -70,19 +70,19 @@ export function getQueryParts( query ) {
70
70
  // While in theory, we could exclude "_fields" from the stableKey
71
71
  // because two request with different fields have the same results
72
72
  // We're not able to ensure that because the server can decide to omit
73
- // fields from the response even if we explicitely asked for it.
73
+ // fields from the response even if we explicitly asked for it.
74
74
  // Example: Asking for titles in posts without title support.
75
75
  if ( key === '_fields' ) {
76
- parts.fields = getNormalizedCommaSeparable( value );
76
+ parts.fields = getNormalizedCommaSeparable( value ) ?? [];
77
77
  // Make sure to normalize value for `stableKey`
78
78
  value = parts.fields.join();
79
79
  }
80
80
 
81
81
  // Two requests with different include values cannot have same results.
82
82
  if ( key === 'include' ) {
83
- parts.include = getNormalizedCommaSeparable( value ).map(
84
- Number
85
- );
83
+ parts.include = (
84
+ getNormalizedCommaSeparable( value ) ?? []
85
+ ).map( Number );
86
86
  // Normalize value for `stableKey`.
87
87
  value = parts.include.join();
88
88
  }
@@ -51,7 +51,7 @@ export function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {
51
51
  // If later page has already been received, default to the larger known
52
52
  // size of the existing array, else calculate as extending the existing.
53
53
  const size = Math.max(
54
- itemIds.length,
54
+ itemIds?.length ?? 0,
55
55
  nextItemIdsStartIndex + nextItemIds.length
56
56
  );
57
57
 
@@ -66,7 +66,7 @@ export function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {
66
66
 
67
67
  mergedItemIds[ i ] = isInNextItemsRange
68
68
  ? nextItemIds[ i - nextItemIdsStartIndex ]
69
- : itemIds[ i ];
69
+ : itemIds?.[ i ];
70
70
  }
71
71
 
72
72
  return mergedItemIds;
@@ -116,10 +116,10 @@ export function items( state = {}, action ) {
116
116
  * In such cases, completeness is used as an indication of whether it would be
117
117
  * safe to use queried data for a non-`_fields`-limited request.
118
118
  *
119
- * @param {Object<string,boolean>} state Current state.
120
- * @param {Object} action Dispatched action.
119
+ * @param {Object<string,Object<string,boolean>>} state Current state.
120
+ * @param {Object} action Dispatched action.
121
121
  *
122
- * @return {Object<string,boolean>} Next state.
122
+ * @return {Object<string,Object<string,boolean>>} Next state.
123
123
  */
124
124
  export function itemIsComplete( state = {}, action ) {
125
125
  switch ( action.type ) {
@@ -130,7 +130,7 @@ export function itemIsComplete( state = {}, action ) {
130
130
  // An item is considered complete if it is received without an associated
131
131
  // fields query. Ideally, this would be implemented in such a way where the
132
132
  // complete aggregate of all fields would satisfy completeness. Since the
133
- // fields are not consistent across all entity types, this would require
133
+ // fields are not consistent across all entities, this would require
134
134
  // introspection on the REST schema for each entity to know which fields
135
135
  // compose a complete item for that entity.
136
136
  const queryParts = query ? getQueryParts( query ) : {};