@wordpress/core-data 4.6.0 → 4.9.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 (98) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +209 -119
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +1 -1
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/entities.js +49 -35
  7. package/build/entities.js.map +1 -1
  8. package/build/entity-provider.js.map +1 -1
  9. package/build/entity-types/entities.js +6 -0
  10. package/build/entity-types/entities.js.map +1 -0
  11. package/build/hooks/constants.js +0 -2
  12. package/build/hooks/constants.js.map +1 -1
  13. package/build/hooks/index.js +38 -0
  14. package/build/hooks/index.js.map +1 -0
  15. package/build/hooks/use-entity-record.js +22 -8
  16. package/build/hooks/use-entity-record.js.map +1 -1
  17. package/build/hooks/use-entity-records.js +21 -8
  18. package/build/hooks/use-entity-records.js.map +1 -1
  19. package/build/hooks/use-query-select.js.map +1 -1
  20. package/build/index.js +17 -21
  21. package/build/index.js.map +1 -1
  22. package/build/queried-data/selectors.js.map +1 -1
  23. package/build/resolvers.js.map +1 -1
  24. package/build/selectors.js +206 -169
  25. package/build/selectors.js.map +1 -1
  26. package/build/utils/forward-resolver.js.map +1 -1
  27. package/build/utils/on-sub-key.js.map +1 -1
  28. package/build/utils/with-weak-map-cache.js +1 -7
  29. package/build/utils/with-weak-map-cache.js.map +1 -1
  30. package/build-module/actions.js.map +1 -1
  31. package/build-module/batch/create-batch.js +2 -2
  32. package/build-module/batch/create-batch.js.map +1 -1
  33. package/build-module/entities.js +49 -35
  34. package/build-module/entities.js.map +1 -1
  35. package/build-module/entity-provider.js.map +1 -1
  36. package/build-module/entity-types/entities.js +2 -0
  37. package/build-module/entity-types/entities.js.map +1 -0
  38. package/build-module/hooks/constants.js +0 -1
  39. package/build-module/hooks/constants.js.map +1 -1
  40. package/build-module/hooks/index.js +3 -0
  41. package/build-module/hooks/index.js.map +1 -0
  42. package/build-module/hooks/use-entity-record.js +18 -7
  43. package/build-module/hooks/use-entity-record.js.map +1 -1
  44. package/build-module/hooks/use-entity-records.js +17 -7
  45. package/build-module/hooks/use-entity-records.js.map +1 -1
  46. package/build-module/hooks/use-query-select.js.map +1 -1
  47. package/build-module/index.js +2 -3
  48. package/build-module/index.js.map +1 -1
  49. package/build-module/queried-data/selectors.js.map +1 -1
  50. package/build-module/resolvers.js.map +1 -1
  51. package/build-module/selectors.js +203 -166
  52. package/build-module/selectors.js.map +1 -1
  53. package/build-module/utils/forward-resolver.js.map +1 -1
  54. package/build-module/utils/on-sub-key.js.map +1 -1
  55. package/build-module/utils/with-weak-map-cache.js +1 -6
  56. package/build-module/utils/with-weak-map-cache.js.map +1 -1
  57. package/package.json +12 -12
  58. package/src/actions.js +389 -372
  59. package/src/batch/create-batch.js +2 -2
  60. package/src/entities.ts +357 -135
  61. package/src/entity-provider.js +4 -6
  62. package/src/entity-types/attachment.ts +4 -3
  63. package/src/entity-types/comment.ts +4 -3
  64. package/src/entity-types/entities.ts +130 -0
  65. package/src/entity-types/index.ts +115 -20
  66. package/src/entity-types/menu-location.ts +4 -3
  67. package/src/entity-types/nav-menu-item.ts +4 -3
  68. package/src/entity-types/nav-menu.ts +3 -3
  69. package/src/entity-types/page.ts +3 -3
  70. package/src/entity-types/plugin.ts +3 -3
  71. package/src/entity-types/post.ts +3 -3
  72. package/src/entity-types/settings.ts +3 -3
  73. package/src/entity-types/sidebar.ts +4 -3
  74. package/src/entity-types/taxonomy.ts +4 -3
  75. package/src/entity-types/theme.ts +3 -3
  76. package/src/entity-types/type.ts +3 -3
  77. package/src/entity-types/user.ts +3 -3
  78. package/src/entity-types/widget-type.ts +4 -3
  79. package/src/entity-types/widget.ts +3 -3
  80. package/src/entity-types/wp-template-part.ts +4 -3
  81. package/src/entity-types/wp-template.ts +4 -3
  82. package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
  83. package/src/hooks/constants.ts +1 -2
  84. package/src/hooks/index.ts +8 -0
  85. package/src/hooks/test/use-query-select.js +4 -2
  86. package/src/hooks/use-entity-record.ts +31 -9
  87. package/src/hooks/use-entity-records.ts +28 -30
  88. package/src/hooks/use-query-select.ts +26 -24
  89. package/src/index.js +2 -3
  90. package/src/locks/test/selectors.js +2 -1
  91. package/src/queried-data/selectors.js +2 -8
  92. package/src/resolvers.js +344 -325
  93. package/src/selectors.ts +639 -296
  94. package/src/test/resolvers.js +1 -3
  95. package/src/test/selectors.js +1 -2
  96. package/src/utils/forward-resolver.js +6 -5
  97. package/src/utils/on-sub-key.js +20 -20
  98. package/src/utils/with-weak-map-cache.js +1 -6
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Context } from './helpers';
5
+ import type { EntityRecord } from './index';
6
+
7
+ /**
8
+ * HTTP Query parameters sent with the API request to fetch the entity records.
9
+ */
10
+ export type EntityQuery<
11
+ C extends Context,
12
+ Fields extends string[] | undefined = undefined
13
+ > = Record< string, any > & {
14
+ context?: C;
15
+ /**
16
+ * The requested fields. If specified, the REST API will remove from the response
17
+ * any fields not on that list.
18
+ */
19
+ _fields?: Fields;
20
+ };
21
+
22
+ interface Edit {}
23
+
24
+ /**
25
+ * Helper type that transforms "raw" entity configuration from entities.ts
26
+ * into a format that makes searching by root and kind easy and extensible.
27
+ *
28
+ * This is the foundation of return type inference in calls such as:
29
+ * `getEntityRecord( "root", "comment", 15 )`.
30
+ *
31
+ * @see EntityRecordOf
32
+ * @see getEntityRecord
33
+ */
34
+ export type EntityType<
35
+ Config extends Pick< EntityConfig< Record, Ctx >, RequiredConfigKeys >,
36
+ Record extends EntityRecord< Ctx >,
37
+ Ctx extends Context
38
+ > = {
39
+ record: Record;
40
+ config: Omit< EntityConfig< Record, Ctx >, RequiredConfigKeys > & Config;
41
+ key: Config[ 'key' ] extends string ? Config[ 'key' ] : 'id';
42
+ defaultContext: Config[ 'baseURLParams' ] extends {
43
+ context: infer InferredContext;
44
+ }
45
+ ? InferredContext
46
+ : 'view';
47
+ };
48
+
49
+ type RequiredConfigKeys = 'name' | 'kind' | 'key' | 'baseURLParams';
50
+
51
+ export interface EntityConfig<
52
+ R extends EntityRecord< C >,
53
+ C extends Context
54
+ > {
55
+ /** Path in WP REST API from which to request records of this entity. */
56
+ baseURL: string;
57
+
58
+ /** Arguments to supply by default to API requests for records of this entity. */
59
+ baseURLParams?: EntityQuery< Context >;
60
+
61
+ /**
62
+ * Returns the title for a given record of this entity.
63
+ *
64
+ * Some entities have an associated title, such as the name of a
65
+ * particular template part ("full width") or of a menu ("main nav").
66
+ */
67
+ getTitle?: ( record: R ) => string;
68
+
69
+ /**
70
+ * Indicates an alternate field in record that can be used for identification.
71
+ *
72
+ * e.g. a post has an id but may also be uniquely identified by its `slug`
73
+ */
74
+ key?: string;
75
+
76
+ /**
77
+ * Collection in which to classify records of this entity.
78
+ *
79
+ * 'root' is a special name given to the core entities provided by the editor.
80
+ *
81
+ * It may be the case that we request an entity record for which we have no
82
+ * valid config in memory. In these cases the editor will look for a loader
83
+ * function to requests more entity configs from the server for the given
84
+ * "kind." This is how WordPress defers loading of template entity configs.
85
+ */
86
+ kind: string;
87
+
88
+ /** Translated form of human-recognizable name or reference to records of this entity. */
89
+ label: string;
90
+
91
+ mergedEdits?: {
92
+ meta?: boolean;
93
+ };
94
+
95
+ /** Name given to records of this entity, e.g. 'media', 'postType', 'widget' */
96
+ name: string;
97
+
98
+ /**
99
+ * Manually provided plural form of the entity name.
100
+ *
101
+ * When not supplied the editor will attempt to auto-generate a plural form.
102
+ */
103
+ plural?: string;
104
+
105
+ /**
106
+ * Fields in record of this entity which may appear as a compound object with
107
+ * a source value (`raw`) as well as a processed value (`rendered`).
108
+ *
109
+ * e.g. a post's `content` in the edit context contains the raw value stored
110
+ * in the database as well as the rendered version with shortcodes replaced,
111
+ * content texturized, blocks transformed, etc…
112
+ */
113
+ rawAttributes?: ( keyof R )[];
114
+
115
+ /**
116
+ * Which transient edit operations records of this entity support.
117
+ */
118
+ transientEdits?: {
119
+ blocks?: boolean;
120
+ selection?: boolean;
121
+ };
122
+
123
+ // Unstable properties
124
+
125
+ /** Returns additional changes before applying edits to a record of this entity. */
126
+ __unstablePrePersist?: ( record: R, edits: Edit[] ) => Edit[];
127
+
128
+ /** Used in `canEdit()` */
129
+ __unstable_rest_base?: string;
130
+ }
@@ -20,7 +20,9 @@ import type { Widget } from './widget';
20
20
  import type { WidgetType } from './widget-type';
21
21
  import type { WpTemplate } from './wp-template';
22
22
  import type { WpTemplatePart } from './wp-template-part';
23
+ import type { CoreEntities } from '../entities';
23
24
 
25
+ export type { EntityType } from './entities';
24
26
  export type { BaseEntityRecords } from './base-entity-records';
25
27
 
26
28
  export type {
@@ -46,24 +48,117 @@ export type {
46
48
  WpTemplatePart,
47
49
  };
48
50
 
49
- export type EntityRecord< C extends Context > =
50
- | Attachment< C >
51
- | Comment< C >
52
- | MenuLocation< C >
53
- | NavMenu< C >
54
- | NavMenuItem< C >
55
- | Page< C >
56
- | Plugin< C >
57
- | Post< C >
58
- | Settings< C >
59
- | Sidebar< C >
60
- | Taxonomy< C >
61
- | Theme< C >
62
- | Type< C >
63
- | User< C >
64
- | Widget< C >
65
- | WidgetType< C >
66
- | WpTemplate< C >
67
- | WpTemplatePart< C >;
68
-
69
51
  export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >;
52
+
53
+ /**
54
+ * An interface that may be extended to add types for new entities. Each entry
55
+ * must be a union of entity definitions adhering to the EntityInterface type.
56
+ *
57
+ * Example:
58
+ *
59
+ * ```ts
60
+ * import type { Context } from '@wordpress/core-data';
61
+ * // ...
62
+ *
63
+ * interface Order {
64
+ * id: number;
65
+ * clientId: number;
66
+ * // ...
67
+ * }
68
+ *
69
+ * type OrderEntity = {
70
+ * kind: 'myPlugin';
71
+ * name: 'order';
72
+ * recordType: Order;
73
+ * }
74
+ *
75
+ * declare module '@wordpress/core-data' {
76
+ * export interface PerPackageEntities< C extends Context > {
77
+ * myPlugin: OrderEntity | ClientEntity
78
+ * }
79
+ * }
80
+ *
81
+ * const c = getEntityRecord( 'myPlugin', 'order', 15 );
82
+ * // c is of the type Order
83
+ * ```
84
+ */
85
+ export interface PerPackageEntityConfig< C extends Context > {
86
+ core: CoreEntities< C >;
87
+ }
88
+
89
+ /**
90
+ * A union of all the registered entities.
91
+ */
92
+ type EntityConfig< C extends Context = any > =
93
+ PerPackageEntityConfig< C >[ keyof PerPackageEntityConfig< C > ];
94
+
95
+ /**
96
+ * A union of all known record types.
97
+ */
98
+ export type EntityRecord< C extends Context = any > =
99
+ EntityConfig< C >[ 'record' ];
100
+
101
+ /**
102
+ * An entity corresponding to a specified record type.
103
+ */
104
+ export type EntityConfigOf<
105
+ RecordOrKind extends EntityRecord | Kind,
106
+ N extends Name | undefined = undefined
107
+ > = RecordOrKind extends EntityRecord
108
+ ? Extract< EntityConfig, { record: RecordOrKind } >
109
+ : Extract< EntityConfig, { config: { kind: RecordOrKind; name: N } } >;
110
+
111
+ /**
112
+ * Name of the requested entity.
113
+ */
114
+ export type NameOf< R extends EntityRecord > =
115
+ EntityConfigOf< R >[ 'config' ][ 'name' ];
116
+
117
+ /**
118
+ * Kind of the requested entity.
119
+ */
120
+ export type KindOf< R extends EntityRecord > =
121
+ EntityConfigOf< R >[ 'config' ][ 'kind' ];
122
+
123
+ /**
124
+ * Primary key type of the requested entity, sourced from PerPackageEntities.
125
+ *
126
+ * For core entities, the key type is computed using the entity configuration in entities.js.
127
+ */
128
+ export type KeyOf<
129
+ RecordOrKind extends EntityRecord | Kind,
130
+ N extends Name | undefined = undefined,
131
+ E extends EntityConfig = EntityConfigOf< RecordOrKind, N >
132
+ > = ( E[ 'key' ] extends keyof E[ 'record' ]
133
+ ? E[ 'record' ][ E[ 'key' ] ]
134
+ : never ) &
135
+ ( number | string );
136
+
137
+ /**
138
+ * Default context of the requested entity, sourced from PerPackageEntities.
139
+ *
140
+ * For core entities, the default context is extracted from the entity configuration
141
+ * in entities.js.
142
+ */
143
+ export type DefaultContextOf<
144
+ RecordOrKind extends EntityRecord | Kind,
145
+ N extends Name | undefined = undefined
146
+ > = EntityConfigOf< RecordOrKind, N >[ 'defaultContext' ];
147
+
148
+ /**
149
+ * An entity record type associated with specified kind and name, sourced from PerPackageEntities.
150
+ */
151
+ export type EntityRecordOf<
152
+ K extends Kind,
153
+ N extends Name,
154
+ C extends Context = DefaultContextOf< K, N >
155
+ > = Extract< EntityConfig< C >, { config: { kind: K; name: N } } >[ 'record' ];
156
+
157
+ /**
158
+ * A union of all known entity kinds.
159
+ */
160
+ export type Kind = EntityConfig[ 'config' ][ 'kind' ];
161
+ /**
162
+ * A union of all known entity names.
163
+ */
164
+ export type Name = EntityConfig[ 'config' ][ 'name' ];
@@ -4,6 +4,7 @@
4
4
  import type { Context, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -24,6 +25,6 @@ declare module './base-entity-records' {
24
25
  }
25
26
  }
26
27
 
27
- export type MenuLocation< C extends Context > = OmitNevers<
28
- _BaseEntityRecords.MenuLocation< C >
29
- >;
28
+ export type MenuLocation<
29
+ C extends Context = DefaultContextOf< 'root', 'menuLocation' >
30
+ > = OmitNevers< _BaseEntityRecords.MenuLocation< C > >;
@@ -9,6 +9,7 @@ import type {
9
9
  } from './helpers';
10
10
 
11
11
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
12
+ import type { DefaultContextOf } from './index';
12
13
 
13
14
  export type NavMenuItemType =
14
15
  | 'taxonomy'
@@ -106,6 +107,6 @@ declare module './base-entity-records' {
106
107
  }
107
108
  }
108
109
 
109
- export type NavMenuItem< C extends Context > = OmitNevers<
110
- _BaseEntityRecords.NavMenuItem< C >
111
- >;
110
+ export type NavMenuItem<
111
+ C extends Context = DefaultContextOf< 'root', 'menuItem' >
112
+ > = OmitNevers< _BaseEntityRecords.NavMenuItem< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -48,6 +49,5 @@ declare module './base-entity-records' {
48
49
  }
49
50
  }
50
51
 
51
- export type NavMenu< C extends Context > = OmitNevers<
52
- _BaseEntityRecords.NavMenu< C >
53
- >;
52
+ export type NavMenu< C extends Context = DefaultContextOf< 'root', 'menu' > > =
53
+ OmitNevers< _BaseEntityRecords.NavMenu< C > >;
@@ -12,6 +12,7 @@ import type {
12
12
  } from './helpers';
13
13
 
14
14
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
15
+ import type { DefaultContextOf } from './index';
15
16
 
16
17
  declare module './base-entity-records' {
17
18
  export namespace BaseEntityRecords {
@@ -139,6 +140,5 @@ declare module './base-entity-records' {
139
140
  }
140
141
  }
141
142
 
142
- export type Page< C extends Context > = OmitNevers<
143
- _BaseEntityRecords.Page< C >
144
- >;
143
+ export type Page< C extends Context = DefaultContextOf< 'postType', 'page' > > =
144
+ OmitNevers< _BaseEntityRecords.Page< C > >;
@@ -9,6 +9,7 @@ import type {
9
9
  } from './helpers';
10
10
 
11
11
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
12
+ import type { DefaultContextOf } from './index';
12
13
 
13
14
  declare module './base-entity-records' {
14
15
  export namespace BaseEntityRecords {
@@ -74,6 +75,5 @@ declare module './base-entity-records' {
74
75
  }
75
76
 
76
77
  export type PluginStatus = 'active' | 'inactive';
77
- export type Plugin< C extends Context > = OmitNevers<
78
- _BaseEntityRecords.Plugin< C >
79
- >;
78
+ export type Plugin< C extends Context = DefaultContextOf< 'root', 'plugin' > > =
79
+ OmitNevers< _BaseEntityRecords.Plugin< C > >;
@@ -13,6 +13,7 @@ import type {
13
13
  } from './helpers';
14
14
 
15
15
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
16
+ import type { DefaultContextOf } from './index';
16
17
 
17
18
  declare module './base-entity-records' {
18
19
  export namespace BaseEntityRecords {
@@ -148,6 +149,5 @@ declare module './base-entity-records' {
148
149
  }
149
150
  }
150
151
 
151
- export type Post< C extends Context > = OmitNevers<
152
- _BaseEntityRecords.Post< C >
153
- >;
152
+ export type Post< C extends Context = DefaultContextOf< 'postType', 'post' > > =
153
+ OmitNevers< _BaseEntityRecords.Post< C > >;
@@ -9,6 +9,7 @@ import type {
9
9
  } from './helpers';
10
10
 
11
11
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
12
+ import type { DefaultContextOf } from './index';
12
13
 
13
14
  declare module './base-entity-records' {
14
15
  export namespace BaseEntityRecords {
@@ -93,6 +94,5 @@ declare module './base-entity-records' {
93
94
  }
94
95
  }
95
96
 
96
- export type Settings< C extends Context > = OmitNevers<
97
- _BaseEntityRecords.Settings< C >
98
- >;
97
+ export type Settings< C extends Context = DefaultContextOf< 'root', 'site' > > =
98
+ OmitNevers< _BaseEntityRecords.Settings< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -54,6 +55,6 @@ declare module './base-entity-records' {
54
55
 
55
56
  type SidebarStatus = 'active' | 'inactive';
56
57
 
57
- export type Sidebar< C extends Context > = OmitNevers<
58
- _BaseEntityRecords.Sidebar< C >
59
- >;
58
+ export type Sidebar<
59
+ C extends Context = DefaultContextOf< 'root', 'sidebar' >
60
+ > = OmitNevers< _BaseEntityRecords.Sidebar< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -87,6 +88,6 @@ declare module './base-entity-records' {
87
88
  }
88
89
  }
89
90
 
90
- export type Taxonomy< C extends Context > = OmitNevers<
91
- _BaseEntityRecords.Taxonomy< C >
92
- >;
91
+ export type Taxonomy<
92
+ C extends Context = DefaultContextOf< 'postType', 'taxonomy' >
93
+ > = OmitNevers< _BaseEntityRecords.Taxonomy< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, PostFormat, RenderedText, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -217,6 +218,5 @@ declare module './base-entity-records' {
217
218
  }
218
219
  }
219
220
 
220
- export type Theme< C extends Context > = OmitNevers<
221
- _BaseEntityRecords.Theme< C >
222
- >;
221
+ export type Theme< C extends Context = DefaultContextOf< 'root', 'theme' > > =
222
+ OmitNevers< _BaseEntityRecords.Theme< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -75,6 +76,5 @@ declare module './base-entity-records' {
75
76
  }
76
77
  }
77
78
 
78
- export type Type< C extends Context > = OmitNevers<
79
- _BaseEntityRecords.Type< C >
80
- >;
79
+ export type Type< C extends Context = DefaultContextOf< 'root', 'postType' > > =
80
+ OmitNevers< _BaseEntityRecords.Type< C > >;
@@ -9,6 +9,7 @@ import type {
9
9
  } from './helpers';
10
10
 
11
11
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
12
+ import type { DefaultContextOf } from './index';
12
13
 
13
14
  declare module './base-entity-records' {
14
15
  export namespace BaseEntityRecords {
@@ -109,6 +110,5 @@ declare module './base-entity-records' {
109
110
  }
110
111
  }
111
112
 
112
- export type User< C extends Context > = OmitNevers<
113
- _BaseEntityRecords.User< C >
114
- >;
113
+ export type User< C extends Context = DefaultContextOf< 'root', 'user' > > =
114
+ OmitNevers< _BaseEntityRecords.User< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -32,6 +33,6 @@ declare module './base-entity-records' {
32
33
  }
33
34
  }
34
35
 
35
- export type WidgetType< C extends Context > = OmitNevers<
36
- _BaseEntityRecords.WidgetType< C >
37
- >;
36
+ export type WidgetType<
37
+ C extends Context = DefaultContextOf< 'root', 'widgetType' >
38
+ > = OmitNevers< _BaseEntityRecords.WidgetType< C > >;
@@ -4,6 +4,7 @@
4
4
  import type { Context, ContextualField, OmitNevers } from './helpers';
5
5
 
6
6
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
7
+ import type { DefaultContextOf } from './index';
7
8
 
8
9
  declare module './base-entity-records' {
9
10
  export namespace BaseEntityRecords {
@@ -59,6 +60,5 @@ declare module './base-entity-records' {
59
60
  }
60
61
  }
61
62
 
62
- export type Widget< C extends Context > = OmitNevers<
63
- _BaseEntityRecords.Widget< C >
64
- >;
63
+ export type Widget< C extends Context = DefaultContextOf< 'root', 'widget' > > =
64
+ OmitNevers< _BaseEntityRecords.Widget< C > >;
@@ -10,6 +10,7 @@ import type {
10
10
  } from './helpers';
11
11
 
12
12
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
13
+ import type { DefaultContextOf } from './index';
13
14
 
14
15
  declare module './base-entity-records' {
15
16
  export namespace BaseEntityRecords {
@@ -89,6 +90,6 @@ declare module './base-entity-records' {
89
90
  }
90
91
  }
91
92
 
92
- export type WpTemplatePart< C extends Context > = OmitNevers<
93
- _BaseEntityRecords.WpTemplatePart< C >
94
- >;
93
+ export type WpTemplatePart<
94
+ C extends Context = DefaultContextOf< 'postType', 'wp_template_part' >
95
+ > = OmitNevers< _BaseEntityRecords.WpTemplatePart< C > >;
@@ -10,6 +10,7 @@ import type {
10
10
  } from './helpers';
11
11
 
12
12
  import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
13
+ import type { DefaultContextOf } from './index';
13
14
 
14
15
  declare module './base-entity-records' {
15
16
  export namespace BaseEntityRecords {
@@ -89,6 +90,6 @@ declare module './base-entity-records' {
89
90
  }
90
91
  }
91
92
 
92
- export type WpTemplate< C extends Context > = OmitNevers<
93
- _BaseEntityRecords.WpTemplate< C >
94
- >;
93
+ export type WpTemplate<
94
+ C extends Context = DefaultContextOf< 'postType', 'wp_template' >
95
+ > = OmitNevers< _BaseEntityRecords.WpTemplate< C > >;
@@ -175,8 +175,7 @@ describe( 'fetchLinkSuggestions', () => {
175
175
  {
176
176
  id: 54,
177
177
  title: 'Some Test Media Title',
178
- url:
179
- 'http://localhost:8888/wp-content/uploads/2022/03/test-pdf.pdf',
178
+ url: 'http://localhost:8888/wp-content/uploads/2022/03/test-pdf.pdf',
180
179
  type: 'attachment',
181
180
  kind: 'media',
182
181
  },
@@ -225,8 +224,7 @@ describe( 'fetchLinkSuggestions', () => {
225
224
  {
226
225
  id: 54,
227
226
  title: 'Some Test Media Title',
228
- url:
229
- 'http://localhost:8888/wp-content/uploads/2022/03/test-pdf.pdf',
227
+ url: 'http://localhost:8888/wp-content/uploads/2022/03/test-pdf.pdf',
230
228
  type: 'attachment',
231
229
  kind: 'media',
232
230
  },
@@ -1,5 +1,4 @@
1
- /* eslint-disable-next-line no-shadow */
2
- export enum Status {
1
+ export const enum Status {
3
2
  Idle = 'IDLE',
4
3
  Resolving = 'RESOLVING',
5
4
  Error = 'ERROR',
@@ -0,0 +1,8 @@
1
+ export {
2
+ default as useEntityRecord,
3
+ __experimentalUseEntityRecord,
4
+ } from './use-entity-record';
5
+ export {
6
+ default as useEntityRecords,
7
+ __experimentalUseEntityRecords,
8
+ } from './use-entity-records';
@@ -145,8 +145,10 @@ describe( 'useQuerySelect', () => {
145
145
  } ),
146
146
  },
147
147
  resolvers: {
148
- getResolvedFoo: () => ( { dispatch } ) =>
149
- dispatch.receiveFoo( 5 ),
148
+ getResolvedFoo:
149
+ () =>
150
+ ( { dispatch } ) =>
151
+ dispatch.receiveFoo( 5 ),
150
152
  },
151
153
  selectors: {
152
154
  getResolvedFoo: ( state, arg ) => state.resolvedFoo + arg,