@wordpress/core-data 4.13.0 → 5.0.1-next.957ca95e4c.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +148 -65
- package/build/entities.js +38 -51
- package/build/entities.js.map +1 -1
- package/build/hooks/index.js +14 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-record.js +10 -6
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -0
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +5 -2
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +74 -11
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -30
- package/build/index.js.map +1 -1
- package/build/resolvers.js +17 -21
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +9 -46
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +38 -52
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +10 -6
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -0
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +4 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +70 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -5
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +17 -21
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +7 -44
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +188 -0
- package/build-types/actions.d.ts.map +1 -0
- package/build-types/batch/create-batch.d.ts +71 -0
- package/build-types/batch/create-batch.d.ts.map +1 -0
- package/build-types/batch/default-processor.d.ts +11 -0
- package/build-types/batch/default-processor.d.ts.map +1 -0
- package/build-types/batch/index.d.ts +3 -0
- package/build-types/batch/index.d.ts.map +1 -0
- package/build-types/entities.d.ts +128 -0
- package/build-types/entities.d.ts.map +1 -0
- package/build-types/entity-provider.d.ts +68 -0
- package/build-types/entity-provider.d.ts.map +1 -0
- package/build-types/entity-types/attachment.d.ts +121 -0
- package/build-types/entity-types/attachment.d.ts.map +1 -0
- package/build-types/entity-types/base-entity-records.d.ts +37 -0
- package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
- package/build-types/entity-types/comment.d.ts +82 -0
- package/build-types/entity-types/comment.d.ts.map +1 -0
- package/build-types/entity-types/helpers.d.ts +123 -0
- package/build-types/entity-types/helpers.d.ts.map +1 -0
- package/build-types/entity-types/index.d.ts +64 -0
- package/build-types/entity-types/index.d.ts.map +1 -0
- package/build-types/entity-types/menu-location.d.ts +25 -0
- package/build-types/entity-types/menu-location.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu-item.d.ts +88 -0
- package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu.d.ts +45 -0
- package/build-types/entity-types/nav-menu.d.ts.map +1 -0
- package/build-types/entity-types/page.d.ts +120 -0
- package/build-types/entity-types/page.d.ts.map +1 -0
- package/build-types/entity-types/plugin.d.ts +62 -0
- package/build-types/entity-types/plugin.d.ts.map +1 -0
- package/build-types/entity-types/post.d.ts +128 -0
- package/build-types/entity-types/post.d.ts.map +1 -0
- package/build-types/entity-types/settings.d.ts +89 -0
- package/build-types/entity-types/settings.d.ts.map +1 -0
- package/build-types/entity-types/sidebar.d.ts +55 -0
- package/build-types/entity-types/sidebar.d.ts.map +1 -0
- package/build-types/entity-types/taxonomy.d.ts +83 -0
- package/build-types/entity-types/taxonomy.d.ts.map +1 -0
- package/build-types/entity-types/theme.d.ts +206 -0
- package/build-types/entity-types/theme.d.ts.map +1 -0
- package/build-types/entity-types/type.d.ts +71 -0
- package/build-types/entity-types/type.d.ts.map +1 -0
- package/build-types/entity-types/user.d.ts +93 -0
- package/build-types/entity-types/user.d.ts.map +1 -0
- package/build-types/entity-types/widget-type.d.ts +33 -0
- package/build-types/entity-types/widget-type.d.ts.map +1 -0
- package/build-types/entity-types/widget.d.ts +59 -0
- package/build-types/entity-types/widget.d.ts.map +1 -0
- package/build-types/entity-types/wp-template-part.d.ts +80 -0
- package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
- package/build-types/entity-types/wp-template.d.ts +80 -0
- package/build-types/entity-types/wp-template.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
- package/build-types/fetch/index.d.ts +3 -0
- package/build-types/fetch/index.d.ts.map +1 -0
- package/build-types/hooks/constants.d.ts +7 -0
- package/build-types/hooks/constants.d.ts.map +1 -0
- package/build-types/hooks/index.d.ts +4 -0
- package/build-types/hooks/index.d.ts.map +1 -0
- package/build-types/hooks/memoize.d.ts +3 -0
- package/build-types/hooks/memoize.d.ts.map +1 -0
- package/build-types/hooks/use-entity-record.d.ts +124 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -0
- package/build-types/hooks/use-entity-records.d.ts +49 -0
- package/build-types/hooks/use-entity-records.d.ts.map +1 -0
- package/build-types/hooks/use-query-select.d.ts +46 -0
- package/build-types/hooks/use-query-select.d.ts.map +1 -0
- package/build-types/hooks/use-resource-permissions.d.ts +99 -0
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
- package/build-types/index.d.ts +131 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/locks/actions.d.ts +7 -0
- package/build-types/locks/actions.d.ts.map +1 -0
- package/build-types/locks/engine.d.ts +5 -0
- package/build-types/locks/engine.d.ts.map +1 -0
- package/build-types/locks/reducer.d.ts +10 -0
- package/build-types/locks/reducer.d.ts.map +1 -0
- package/build-types/locks/selectors.d.ts +5 -0
- package/build-types/locks/selectors.d.ts.map +1 -0
- package/build-types/locks/utils.d.ts +8 -0
- package/build-types/locks/utils.d.ts.map +1 -0
- package/build-types/name.d.ts +8 -0
- package/build-types/name.d.ts.map +1 -0
- package/build-types/queried-data/actions.d.ts +32 -0
- package/build-types/queried-data/actions.d.ts.map +1 -0
- package/build-types/queried-data/get-query-parts.d.ts +60 -0
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
- package/build-types/queried-data/index.d.ts +4 -0
- package/build-types/queried-data/index.d.ts.map +1 -0
- package/build-types/queried-data/reducer.d.ts +54 -0
- package/build-types/queried-data/reducer.d.ts.map +1 -0
- package/build-types/queried-data/selectors.d.ts +16 -0
- package/build-types/queried-data/selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +156 -0
- package/build-types/reducer.d.ts.map +1 -0
- package/build-types/resolvers.d.ts +74 -0
- package/build-types/resolvers.d.ts.map +1 -0
- package/build-types/selectors.d.ts +524 -0
- package/build-types/selectors.d.ts.map +1 -0
- package/build-types/types.d.ts +4 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/conservative-map-item.d.ts +12 -0
- package/build-types/utils/conservative-map-item.d.ts.map +1 -0
- package/build-types/utils/forward-resolver.d.ts +10 -0
- package/build-types/utils/forward-resolver.d.ts.map +1 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
- package/build-types/utils/if-matching-action.d.ts +14 -0
- package/build-types/utils/if-matching-action.d.ts.map +1 -0
- package/build-types/utils/index.d.ts +9 -0
- package/build-types/utils/index.d.ts.map +1 -0
- package/build-types/utils/is-raw-attribute.d.ts +10 -0
- package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
- package/build-types/utils/on-sub-key.d.ts +4 -0
- package/build-types/utils/on-sub-key.d.ts.map +1 -0
- package/build-types/utils/replace-action.d.ts +13 -0
- package/build-types/utils/replace-action.d.ts.map +1 -0
- package/build-types/utils/with-weak-map-cache.d.ts +12 -0
- package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
- package/package.json +13 -11
- package/src/entities.js +325 -0
- package/src/entity-types/attachment.ts +3 -4
- package/src/entity-types/comment.ts +3 -4
- package/src/entity-types/index.ts +31 -88
- package/src/entity-types/menu-location.ts +3 -4
- package/src/entity-types/nav-menu-item.ts +3 -4
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +3 -4
- package/src/entity-types/taxonomy.ts +3 -4
- package/src/entity-types/theme.ts +7 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +3 -4
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +3 -4
- package/src/entity-types/wp-template.ts +3 -4
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +41 -1
- package/src/hooks/test/use-resource-permissions.js +32 -36
- package/src/hooks/use-entity-record.ts +18 -6
- package/src/hooks/use-entity-records.ts +2 -0
- package/src/hooks/use-query-select.ts +4 -1
- package/src/hooks/use-resource-permissions.ts +84 -20
- package/src/index.js +0 -5
- package/src/resolvers.js +36 -24
- package/src/selectors.ts +202 -341
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/entity-types/entities.js +0 -6
- package/build/entity-types/entities.js.map +0 -1
- package/build-module/entity-types/entities.js +0 -2
- package/build-module/entity-types/entities.js.map +0 -1
- package/src/entities.ts +0 -548
- package/src/entity-types/entities.ts +0 -130
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
}
|