From 8d9ab6ddf2ef3da602ea82a969ef9526205b39d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 9 Feb 2022 13:34:14 +0100 Subject: [PATCH 01/73] Add types for core data entity records --- packages/core-data/src/types.ts | 1136 +++++++++++++++++++++++++++++++ 1 file changed, 1136 insertions(+) create mode 100644 packages/core-data/src/types.ts diff --git a/packages/core-data/src/types.ts b/packages/core-data/src/types.ts new file mode 100644 index 0000000000000..c5c585b8ccc94 --- /dev/null +++ b/packages/core-data/src/types.ts @@ -0,0 +1,1136 @@ +export interface Attachment { + /** + * The date the post was published, in the site's timezone. + */ + date?: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt?: string | null; + /** + * The globally unique identifier for the post. + */ + guid?: { + /** + * GUID for the post, as it exists in the database. + */ + raw?: string; + /** + * GUID for the post, transformed for display. + */ + rendered?: string; + }; + /** + * Unique identifier for the post. + */ + id?: number; + /** + * URL to the post. + */ + link?: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified?: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt?: string; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug?: string; + /** + * A named status for the post. + */ + status?: '0' | '1' | '2' | '3' | '4'; + /** + * Type of post. + */ + type?: string; + /** + * Permalink template for the post. + */ + permalink_template?: string; + /** + * Slug automatically generated from the post title. + */ + generated_slug?: string; + /** + * The title for the post. + */ + title?: { + /** + * Title for the post, as it exists in the database. + */ + raw?: string; + /** + * HTML title for the post, transformed for display. + */ + rendered?: string; + }; + /** + * The ID for the author of the post. + */ + author?: number; + /** + * Whether or not comments are open on the post. + */ + comment_status?: '0' | '1'; + /** + * Whether or not the post can be pinged. + */ + ping_status?: '0' | '1'; + /** + * Meta fields. + */ + meta?: {}; + /** + * The theme file to use to display the post. + */ + template?: string; + /** + * Alternative text to display when attachment is not displayed. + */ + alt_text?: string; + /** + * The attachment caption. + */ + caption?: { + /** + * Caption for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML caption for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * The attachment description. + */ + description?: { + /** + * Description for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML description for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * Attachment type. + */ + media_type?: '0' | '1'; + /** + * The attachment MIME type. + */ + mime_type?: string; + /** + * Details about the media file, specific to its type. + */ + media_details?: {}; + /** + * The ID for the associated post of the attachment. + */ + post?: number; + /** + * URL to the original attachment file. + */ + source_url?: string; + /** + * List of the missing image sizes of the attachment. + */ + missing_image_sizes?: string[]; +} + +export interface Comment { + /** + * Unique identifier for the comment. + */ + id?: number; + /** + * The ID of the user object, if author was a user. + */ + author?: number; + /** + * Email address for the comment author. + */ + author_email?: string; + /** + * IP address for the comment author. + */ + author_ip?: string; + /** + * Display name for the comment author. + */ + author_name?: string; + /** + * URL for the comment author. + */ + author_url?: string; + /** + * User agent for the comment author. + */ + author_user_agent?: string; + /** + * The content for the comment. + */ + content?: { + /** + * Content for the comment, as it exists in the database. + */ + raw?: string; + /** + * HTML content for the comment, transformed for display. + */ + rendered?: string; + }; + /** + * The date the comment was published, in the site's timezone. + */ + date?: string; + /** + * The date the comment was published, as GMT. + */ + date_gmt?: string; + /** + * URL to the comment. + */ + link?: string; + /** + * The ID for the parent of the comment. + */ + parent?: number; + /** + * The ID of the associated post object. + */ + post?: number; + /** + * State of the comment. + */ + status?: string; + /** + * Type of the comment. + */ + type?: string; + /** + * Avatar URLs for the comment author. + */ + author_avatar_urls?: { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + }; + /** + * Meta fields. + */ + meta?: {}; +} + +export interface MenuLocation { + /** + * The name of the menu location. + */ + name?: string; + /** + * The description of the menu location. + */ + description?: string; + /** + * The ID of the assigned menu. + */ + menu?: number; +} + +export interface NavMenu { + /** + * Unique identifier for the term. + */ + id?: number; + /** + * HTML description of the term. + */ + description?: string; + /** + * HTML title for the term. + */ + name?: string; + /** + * An alphanumeric identifier for the term unique to its type. + */ + slug?: string; + /** + * Meta fields. + */ + meta?: {}; + /** + * The locations assigned to the menu. + */ + locations?: string[]; + /** + * Whether to automatically add top level pages to this menu. + */ + auto_add?: boolean; +} + +export interface NavMenuItem { + /** + * The title for the object. + */ + title?: + | string + | { + /** + * Title for the object, as it exists in the database. + */ + raw?: string; + /** + * HTML title for the object, transformed for display. + */ + rendered?: string; + }; + /** + * Unique identifier for the object. + */ + id?: number; + /** + * The singular label used to describe this type of menu item. + */ + type_label?: string; + /** + * The family of objects originally represented, such as "post_type" or "taxonomy". + */ + type?: '0' | '1' | '2' | '3'; + /** + * A named status for the object. + */ + status?: '0' | '1' | '2' | '3' | '4'; + /** + * The ID for the parent of the object. + */ + parent?: number; + /** + * Text for the title attribute of the link element for this menu item. + */ + attr_title?: string; + /** + * Class names for the link element of this menu item. + */ + classes?: string[]; + /** + * The description of this menu item. + */ + description?: string; + /** + * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. + */ + menu_order?: number; + /** + * The type of object originally represented, such as "category," "post", or "attachment." + */ + object?: string; + /** + * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. + */ + object_id?: number; + /** + * The target attribute of the link element for this menu item. + */ + target?: '0' | '1'; + /** + * The URL to which this menu item points. + */ + url?: string; + /** + * The XFN relationship expressed in the link of this menu item. + */ + xfn?: string[]; + /** + * Whether the menu item represents an object that no longer exists. + */ + invalid?: boolean; + /** + * The terms assigned to the object in the nav_menu taxonomy. + */ + menus?: number; + /** + * Meta fields. + */ + meta?: {}; +} + +export interface NavigationArea { + /** + * The name of the navigation area. + */ + name?: string; + /** + * The description of the navigation area. + */ + description?: string; + /** + * The ID of the assigned navigation. + */ + navigation?: number; +} + +export interface Plugin { + /** + * The plugin file. + */ + plugin?: string; + /** + * The plugin activation status. + */ + status?: '0' | '1'; + /** + * The plugin name. + */ + name?: string; + /** + * The plugin's website address. + */ + plugin_uri?: string; + /** + * The plugin author. + */ + author?: {}; + /** + * Plugin author's website address. + */ + author_uri?: string; + /** + * The plugin description. + */ + description?: { + /** + * The raw plugin description. + */ + raw?: string; + /** + * The plugin description formatted for display. + */ + rendered?: string; + }; + /** + * The plugin version number. + */ + version?: string; + /** + * Whether the plugin can only be activated network-wide. + */ + network_only?: boolean; + /** + * Minimum required version of WordPress. + */ + requires_wp?: string; + /** + * Minimum required version of PHP. + */ + requires_php?: string; + /** + * The plugin's text domain. + */ + textdomain?: string; +} + +export interface Settings { + /** + * What to show on the front page + */ + show_on_front?: string; + /** + * The ID of the page that should be displayed on the front page + */ + page_on_front?: number; + /** + * Site title. + */ + title?: string; + /** + * Site tagline. + */ + description?: string; + /** + * Site URL. + */ + url?: string; + /** + * This address is used for admin purposes, like new user notification. + */ + email?: string; + /** + * A city in the same timezone as you. + */ + timezone?: string; + /** + * A date format for all date strings. + */ + date_format?: string; + /** + * A time format for all time strings. + */ + time_format?: string; + /** + * A day number of the week that the week should start on. + */ + start_of_week?: number; + /** + * WordPress locale code. + */ + language?: string; + /** + * Convert emoticons like :-) and :-P to graphics on display. + */ + use_smilies?: boolean; + /** + * Default post category. + */ + default_category?: number; + /** + * Default post format. + */ + default_post_format?: string; + /** + * Blog pages show at most. + */ + posts_per_page?: number; + /** + * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. + */ + default_ping_status?: '0' | '1'; + /** + * Allow people to submit comments on new posts. + */ + default_comment_status?: '0' | '1'; + /** + * Site logo. + */ + site_logo?: number; + /** + * Site icon. + */ + site_icon?: number; +} + +export interface Sidebar { + /** + * ID of sidebar. + */ + id?: string; + /** + * Unique name identifying the sidebar. + */ + name?: string; + /** + * Description of sidebar. + */ + description?: string; + /** + * Extra CSS class to assign to the sidebar in the Widgets interface. + */ + class?: string; + /** + * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. + */ + before_widget?: string; + /** + * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. + */ + after_widget?: string; + /** + * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. + */ + before_title?: string; + /** + * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. + */ + after_title?: string; + /** + * Status of sidebar. + */ + status?: '0' | '1'; + /** + * Nested widgets. + */ + widgets?: ( {} | string )[]; +} + +export interface Taxonomy { + /** + * All capabilities used by the taxonomy. + */ + capabilities?: {}; + /** + * A human-readable description of the taxonomy. + */ + description?: string; + /** + * Whether or not the taxonomy should have children. + */ + hierarchical?: boolean; + /** + * Human-readable labels for the taxonomy for various contexts. + */ + labels?: {}; + /** + * The title for the taxonomy. + */ + name?: string; + /** + * An alphanumeric identifier for the taxonomy. + */ + slug?: string; + /** + * Whether or not the term cloud should be displayed. + */ + show_cloud?: boolean; + /** + * Types associated with the taxonomy. + */ + types?: string[]; + /** + * REST base route for the taxonomy. + */ + rest_base?: string; + /** + * REST namespace route for the taxonomy. + */ + rest_namespace?: string; + /** + * The visibility settings for the taxonomy. + */ + visibility?: { + /** + * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. + */ + public?: boolean; + /** + * Whether the taxonomy is publicly queryable. + */ + publicly_queryable?: boolean; + /** + * Whether to generate a default UI for managing this taxonomy. + */ + show_ui?: boolean; + /** + * Whether to allow automatic creation of taxonomy columns on associated post-types table. + */ + show_admin_column?: boolean; + /** + * Whether to make the taxonomy available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + /** + * Whether to show the taxonomy in the quick/bulk edit panel. + */ + show_in_quick_edit?: boolean; + }; +} + +export interface Theme { + /** + * The theme's stylesheet. This uniquely identifies the theme. + */ + stylesheet?: string; + /** + * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. + */ + template?: string; + /** + * The theme author. + */ + author?: { + /** + * The theme author's name, as found in the theme header. + */ + raw?: string; + /** + * HTML for the theme author, transformed for display. + */ + rendered?: string; + }; + /** + * The website of the theme author. + */ + author_uri?: { + /** + * The website of the theme author, as found in the theme header. + */ + raw?: string; + /** + * The website of the theme author, transformed for display. + */ + rendered?: string; + }; + /** + * A description of the theme. + */ + description?: { + /** + * The theme description, as found in the theme header. + */ + raw?: string; + /** + * The theme description, transformed for display. + */ + rendered?: string; + }; + /** + * The name of the theme. + */ + name?: { + /** + * The theme name, as found in the theme header. + */ + raw?: string; + /** + * The theme name, transformed for display. + */ + rendered?: string; + }; + /** + * The minimum PHP version required for the theme to work. + */ + requires_php?: string; + /** + * The minimum WordPress version required for the theme to work. + */ + requires_wp?: string; + /** + * The theme's screenshot URL. + */ + screenshot?: string; + /** + * Tags indicating styles and features of the theme. + */ + tags?: { + /** + * The theme tags, as found in the theme header. + */ + raw?: string[]; + /** + * The theme tags, transformed for display. + */ + rendered?: string; + }; + /** + * The theme's text domain. + */ + textdomain?: string; + /** + * Features supported by this theme. + */ + theme_supports?: { + /** + * Whether theme opts in to wide alignment CSS class. + */ + 'align-wide'?: boolean; + /** + * Whether posts and comments RSS feed links are added to head. + */ + 'automatic-feed-links'?: boolean; + /** + * Custom background if defined by the theme. + */ + 'custom-background'?: + | boolean + | { + 'default-image'?: string; + 'default-preset'?: '0' | '1' | '2' | '3' | '4'; + 'default-position-x'?: '0' | '1' | '2'; + 'default-position-y'?: '0' | '1' | '2'; + 'default-size'?: '0' | '1' | '2'; + 'default-repeat'?: '0' | '1' | '2' | '3'; + 'default-attachment'?: '0' | '1'; + 'default-color'?: string; + }; + /** + * Custom header if defined by the theme. + */ + 'custom-header'?: + | boolean + | { + 'default-image'?: string; + 'random-default'?: boolean; + width?: number; + height?: number; + 'flex-height'?: boolean; + 'flex-width'?: boolean; + 'default-text-color'?: string; + 'header-text'?: boolean; + uploads?: boolean; + video?: boolean; + }; + /** + * Custom logo if defined by the theme. + */ + 'custom-logo'?: + | boolean + | { + width?: number; + height?: number; + 'flex-width'?: boolean; + 'flex-height'?: boolean; + 'header-text'?: string[]; + 'unlink-homepage-logo'?: boolean; + }; + /** + * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. + */ + 'customize-selective-refresh-widgets'?: boolean; + /** + * Whether theme opts in to the dark editor style UI. + */ + 'dark-editor-style'?: boolean; + /** + * Whether the theme disables custom colors. + */ + 'disable-custom-colors'?: boolean; + /** + * Whether the theme disables custom font sizes. + */ + 'disable-custom-font-sizes'?: boolean; + /** + * Whether the theme disables custom gradients. + */ + 'disable-custom-gradients'?: boolean; + /** + * Custom color palette if defined by the theme. + */ + 'editor-color-palette'?: + | boolean + | { + name?: string; + slug?: string; + color?: string; + }[]; + /** + * Custom font sizes if defined by the theme. + */ + 'editor-font-sizes'?: + | boolean + | { + name?: string; + size?: number; + slug?: string; + }[]; + /** + * Custom gradient presets if defined by the theme. + */ + 'editor-gradient-presets'?: + | boolean + | { + name?: string; + gradient?: string; + slug?: string; + }[]; + /** + * Whether theme opts in to the editor styles CSS wrapper. + */ + 'editor-styles'?: boolean; + /** + * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. + */ + html5?: boolean | ( '0' | '1' | '2' | '3' | '4' | '5' | '6' )[]; + /** + * Post formats supported. + */ + formats?: ( + | 'standard' + | 'aside' + | 'chat' + | 'gallery' + | 'link' + | 'image' + | 'quote' + | 'status' + | 'video' + | 'audio' + )[]; + /** + * The post types that support thumbnails or true if all post types are supported. + */ + 'post-thumbnails'?: boolean | string[]; + /** + * Whether the theme supports responsive embedded content. + */ + 'responsive-embeds'?: boolean; + /** + * Whether the theme can manage the document title tag. + */ + 'title-tag'?: boolean; + /** + * Whether theme opts in to default WordPress block styles for viewing. + */ + 'wp-block-styles'?: boolean; + }; + /** + * The URI of the theme's webpage. + */ + theme_uri?: { + /** + * The URI of the theme's webpage, as found in the theme header. + */ + raw?: string; + /** + * The URI of the theme's webpage, transformed for display. + */ + rendered?: string; + }; + /** + * The theme's current version. + */ + version?: string; + /** + * A named status for the theme. + */ + status?: '0' | '1'; +} + +export interface Type { + /** + * All capabilities used by the post type. + */ + capabilities?: {}; + /** + * A human-readable description of the post type. + */ + description?: string; + /** + * Whether or not the post type should have children. + */ + hierarchical?: boolean; + /** + * Whether or not the post type can be viewed. + */ + viewable?: boolean; + /** + * Human-readable labels for the post type for various contexts. + */ + labels?: {}; + /** + * The title for the post type. + */ + name?: string; + /** + * An alphanumeric identifier for the post type. + */ + slug?: string; + /** + * All features, supported by the post type. + */ + supports?: {}; + /** + * Taxonomies associated with post type. + */ + taxonomies?: string[]; + /** + * REST base route for the post type. + */ + rest_base?: string; + /** + * REST route's namespace for the post type. + */ + rest_namespace?: string; + /** + * The visibility settings for the post type. + */ + visibility?: { + /** + * Whether to generate a default UI for managing this post type. + */ + show_ui?: boolean; + /** + * Whether to make the post type is available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + }; +} + +export interface User { + /** + * Unique identifier for the user. + */ + id?: number; + /** + * Login name for the user. + */ + username?: string; + /** + * Display name for the user. + */ + name?: string; + /** + * First name for the user. + */ + first_name?: string; + /** + * Last name for the user. + */ + last_name?: string; + /** + * The email address for the user. + */ + email?: string; + /** + * URL of the user. + */ + url?: string; + /** + * Description of the user. + */ + description?: string; + /** + * Author URL of the user. + */ + link?: string; + /** + * Locale for the user. + */ + locale?: '0' | '1' | '2'; + /** + * The nickname for the user. + */ + nickname?: string; + /** + * An alphanumeric identifier for the user. + */ + slug?: string; + /** + * Registration date for the user. + */ + registered_date?: string; + /** + * Roles assigned to the user. + */ + roles?: string[]; + /** + * Password for the user (never included). + */ + password?: string; + /** + * All capabilities assigned to the user. + */ + capabilities?: {}; + /** + * Any extra capabilities assigned to the user. + */ + extra_capabilities?: {}; + /** + * Avatar URLs for the user. + */ + avatar_urls?: { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + }; + /** + * Meta fields. + */ + meta?: {}; +} + +export interface Widget { + /** + * Unique identifier for the widget. + */ + id?: string; + /** + * The type of the widget. Corresponds to ID in widget-types endpoint. + */ + id_base?: string; + /** + * The sidebar the widget belongs to. + */ + sidebar?: string; + /** + * HTML representation of the widget. + */ + rendered?: string; + /** + * HTML representation of the widget admin form. + */ + rendered_form?: string; + /** + * Instance settings of the widget, if supported. + */ + instance?: { + /** + * Base64 encoded representation of the instance settings. + */ + encoded?: string; + /** + * Cryptographic hash of the instance settings. + */ + hash?: string; + /** + * Unencoded instance settings, if supported. + */ + raw?: {}; + }; + /** + * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. + */ + form_data?: string; +} + +export interface WidgetType { + /** + * Unique slug identifying the widget type. + */ + id?: string; + /** + * Human-readable name identifying the widget type. + */ + name?: string; + /** + * Description of the widget. + */ + description?: string; + /** + * Whether the widget supports multiple instances + */ + is_multi?: boolean; + /** + * Class name + */ + classname?: string; +} + +export type EntityRecord = + | Settings + | Type + | Attachment + | Taxonomy + | Sidebar + | Widget + | WidgetType + | User + | Comment + | NavMenu + | NavMenuItem + | MenuLocation + | NavigationArea + | Theme + | Plugin; From 190ccdf53b322f7bf0118401e6b7ec9a3a6b44c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 9 Feb 2022 13:44:14 +0100 Subject: [PATCH 02/73] Use string enums instead of numeric ones --- packages/core-data/src/types.ts | 59 ++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/packages/core-data/src/types.ts b/packages/core-data/src/types.ts index c5c585b8ccc94..bc5ada82e532a 100644 --- a/packages/core-data/src/types.ts +++ b/packages/core-data/src/types.ts @@ -43,7 +43,7 @@ export interface Attachment { /** * A named status for the post. */ - status?: '0' | '1' | '2' | '3' | '4'; + status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; /** * Type of post. */ @@ -76,11 +76,11 @@ export interface Attachment { /** * Whether or not comments are open on the post. */ - comment_status?: '0' | '1'; + comment_status?: 'open' | 'closed'; /** * Whether or not the post can be pinged. */ - ping_status?: '0' | '1'; + ping_status?: 'open' | 'closed'; /** * Meta fields. */ @@ -122,7 +122,7 @@ export interface Attachment { /** * Attachment type. */ - media_type?: '0' | '1'; + media_type?: 'image' | 'file'; /** * The attachment MIME type. */ @@ -311,11 +311,11 @@ export interface NavMenuItem { /** * The family of objects originally represented, such as "post_type" or "taxonomy". */ - type?: '0' | '1' | '2' | '3'; + type?: 'taxonomy' | 'post_type' | 'post_type_archive' | 'custom'; /** * A named status for the object. */ - status?: '0' | '1' | '2' | '3' | '4'; + status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; /** * The ID for the parent of the object. */ @@ -347,7 +347,7 @@ export interface NavMenuItem { /** * The target attribute of the link element for this menu item. */ - target?: '0' | '1'; + target?: '_blank' | ''; /** * The URL to which this menu item points. */ @@ -393,7 +393,7 @@ export interface Plugin { /** * The plugin activation status. */ - status?: '0' | '1'; + status?: 'inactive' | 'active'; /** * The plugin name. */ @@ -509,11 +509,11 @@ export interface Settings { /** * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. */ - default_ping_status?: '0' | '1'; + default_ping_status?: 'open' | 'closed'; /** * Allow people to submit comments on new posts. */ - default_comment_status?: '0' | '1'; + default_comment_status?: 'open' | 'closed'; /** * Site logo. */ @@ -560,7 +560,7 @@ export interface Sidebar { /** * Status of sidebar. */ - status?: '0' | '1'; + status?: 'active' | 'inactive'; /** * Nested widgets. */ @@ -748,12 +748,21 @@ export interface Theme { | boolean | { 'default-image'?: string; - 'default-preset'?: '0' | '1' | '2' | '3' | '4'; - 'default-position-x'?: '0' | '1' | '2'; - 'default-position-y'?: '0' | '1' | '2'; - 'default-size'?: '0' | '1' | '2'; - 'default-repeat'?: '0' | '1' | '2' | '3'; - 'default-attachment'?: '0' | '1'; + 'default-preset'?: + | 'default' + | 'fill' + | 'fit' + | 'repeat' + | 'custom'; + 'default-position-x'?: 'left' | 'center' | 'right'; + 'default-position-y'?: 'left' | 'center' | 'right'; + 'default-size'?: 'auto' | 'contain' | 'cover'; + 'default-repeat'?: + | 'repeat-x' + | 'repeat-y' + | 'repeat' + | 'no-repeat'; + 'default-attachment'?: 'scroll' | 'fixed'; 'default-color'?: string; }; /** @@ -843,7 +852,17 @@ export interface Theme { /** * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. */ - html5?: boolean | ( '0' | '1' | '2' | '3' | '4' | '5' | '6' )[]; + html5?: + | boolean + | ( + | 'search-form' + | 'comment-form' + | 'comment-list' + | 'gallery' + | 'caption' + | 'script' + | 'style' + )[]; /** * Post formats supported. */ @@ -896,7 +915,7 @@ export interface Theme { /** * A named status for the theme. */ - status?: '0' | '1'; + status?: 'inactive' | 'active'; } export interface Type { @@ -999,7 +1018,7 @@ export interface User { /** * Locale for the user. */ - locale?: '0' | '1' | '2'; + locale?: '' | 'en_US' | 'en_AU'; /** * The nickname for the user. */ From 6d9687bae675eb4e2fe9d6313c38546b5fdabf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 13:55:43 +0100 Subject: [PATCH 03/73] Put each type in a separate file --- packages/core-data/src/types.ts | 1155 ----------------- packages/core-data/src/types/attachment.ts | 146 +++ packages/core-data/src/types/comment.ts | 93 ++ packages/core-data/src/types/menu-location.ts | 14 + packages/core-data/src/types/nav_menu.ts | 31 + packages/core-data/src/types/nav_menu_item.ts | 86 ++ packages/core-data/src/types/settings.ts | 78 ++ packages/core-data/src/types/sidebar.ts | 46 + packages/core-data/src/types/taxonomy.ts | 73 ++ packages/core-data/src/types/type.ts | 62 + packages/core-data/src/types/types.ts | 147 +++ packages/core-data/src/types/user.ts | 94 ++ packages/core-data/src/types/widget-type.ts | 22 + packages/core-data/src/types/widget.ts | 44 + 14 files changed, 936 insertions(+), 1155 deletions(-) delete mode 100644 packages/core-data/src/types.ts create mode 100644 packages/core-data/src/types/attachment.ts create mode 100644 packages/core-data/src/types/comment.ts create mode 100644 packages/core-data/src/types/menu-location.ts create mode 100644 packages/core-data/src/types/nav_menu.ts create mode 100644 packages/core-data/src/types/nav_menu_item.ts create mode 100644 packages/core-data/src/types/settings.ts create mode 100644 packages/core-data/src/types/sidebar.ts create mode 100644 packages/core-data/src/types/taxonomy.ts create mode 100644 packages/core-data/src/types/type.ts create mode 100644 packages/core-data/src/types/types.ts create mode 100644 packages/core-data/src/types/user.ts create mode 100644 packages/core-data/src/types/widget-type.ts create mode 100644 packages/core-data/src/types/widget.ts diff --git a/packages/core-data/src/types.ts b/packages/core-data/src/types.ts deleted file mode 100644 index bc5ada82e532a..0000000000000 --- a/packages/core-data/src/types.ts +++ /dev/null @@ -1,1155 +0,0 @@ -export interface Attachment { - /** - * The date the post was published, in the site's timezone. - */ - date?: string | null; - /** - * The date the post was published, as GMT. - */ - date_gmt?: string | null; - /** - * The globally unique identifier for the post. - */ - guid?: { - /** - * GUID for the post, as it exists in the database. - */ - raw?: string; - /** - * GUID for the post, transformed for display. - */ - rendered?: string; - }; - /** - * Unique identifier for the post. - */ - id?: number; - /** - * URL to the post. - */ - link?: string; - /** - * The date the post was last modified, in the site's timezone. - */ - modified?: string; - /** - * The date the post was last modified, as GMT. - */ - modified_gmt?: string; - /** - * An alphanumeric identifier for the post unique to its type. - */ - slug?: string; - /** - * A named status for the post. - */ - status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; - /** - * Type of post. - */ - type?: string; - /** - * Permalink template for the post. - */ - permalink_template?: string; - /** - * Slug automatically generated from the post title. - */ - generated_slug?: string; - /** - * The title for the post. - */ - title?: { - /** - * Title for the post, as it exists in the database. - */ - raw?: string; - /** - * HTML title for the post, transformed for display. - */ - rendered?: string; - }; - /** - * The ID for the author of the post. - */ - author?: number; - /** - * Whether or not comments are open on the post. - */ - comment_status?: 'open' | 'closed'; - /** - * Whether or not the post can be pinged. - */ - ping_status?: 'open' | 'closed'; - /** - * Meta fields. - */ - meta?: {}; - /** - * The theme file to use to display the post. - */ - template?: string; - /** - * Alternative text to display when attachment is not displayed. - */ - alt_text?: string; - /** - * The attachment caption. - */ - caption?: { - /** - * Caption for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML caption for the attachment, transformed for display. - */ - rendered?: string; - }; - /** - * The attachment description. - */ - description?: { - /** - * Description for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML description for the attachment, transformed for display. - */ - rendered?: string; - }; - /** - * Attachment type. - */ - media_type?: 'image' | 'file'; - /** - * The attachment MIME type. - */ - mime_type?: string; - /** - * Details about the media file, specific to its type. - */ - media_details?: {}; - /** - * The ID for the associated post of the attachment. - */ - post?: number; - /** - * URL to the original attachment file. - */ - source_url?: string; - /** - * List of the missing image sizes of the attachment. - */ - missing_image_sizes?: string[]; -} - -export interface Comment { - /** - * Unique identifier for the comment. - */ - id?: number; - /** - * The ID of the user object, if author was a user. - */ - author?: number; - /** - * Email address for the comment author. - */ - author_email?: string; - /** - * IP address for the comment author. - */ - author_ip?: string; - /** - * Display name for the comment author. - */ - author_name?: string; - /** - * URL for the comment author. - */ - author_url?: string; - /** - * User agent for the comment author. - */ - author_user_agent?: string; - /** - * The content for the comment. - */ - content?: { - /** - * Content for the comment, as it exists in the database. - */ - raw?: string; - /** - * HTML content for the comment, transformed for display. - */ - rendered?: string; - }; - /** - * The date the comment was published, in the site's timezone. - */ - date?: string; - /** - * The date the comment was published, as GMT. - */ - date_gmt?: string; - /** - * URL to the comment. - */ - link?: string; - /** - * The ID for the parent of the comment. - */ - parent?: number; - /** - * The ID of the associated post object. - */ - post?: number; - /** - * State of the comment. - */ - status?: string; - /** - * Type of the comment. - */ - type?: string; - /** - * Avatar URLs for the comment author. - */ - author_avatar_urls?: { - /** - * Avatar URL with image size of 24 pixels. - */ - '24'?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - '48'?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - '96'?: string; - }; - /** - * Meta fields. - */ - meta?: {}; -} - -export interface MenuLocation { - /** - * The name of the menu location. - */ - name?: string; - /** - * The description of the menu location. - */ - description?: string; - /** - * The ID of the assigned menu. - */ - menu?: number; -} - -export interface NavMenu { - /** - * Unique identifier for the term. - */ - id?: number; - /** - * HTML description of the term. - */ - description?: string; - /** - * HTML title for the term. - */ - name?: string; - /** - * An alphanumeric identifier for the term unique to its type. - */ - slug?: string; - /** - * Meta fields. - */ - meta?: {}; - /** - * The locations assigned to the menu. - */ - locations?: string[]; - /** - * Whether to automatically add top level pages to this menu. - */ - auto_add?: boolean; -} - -export interface NavMenuItem { - /** - * The title for the object. - */ - title?: - | string - | { - /** - * Title for the object, as it exists in the database. - */ - raw?: string; - /** - * HTML title for the object, transformed for display. - */ - rendered?: string; - }; - /** - * Unique identifier for the object. - */ - id?: number; - /** - * The singular label used to describe this type of menu item. - */ - type_label?: string; - /** - * The family of objects originally represented, such as "post_type" or "taxonomy". - */ - type?: 'taxonomy' | 'post_type' | 'post_type_archive' | 'custom'; - /** - * A named status for the object. - */ - status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; - /** - * The ID for the parent of the object. - */ - parent?: number; - /** - * Text for the title attribute of the link element for this menu item. - */ - attr_title?: string; - /** - * Class names for the link element of this menu item. - */ - classes?: string[]; - /** - * The description of this menu item. - */ - description?: string; - /** - * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. - */ - menu_order?: number; - /** - * The type of object originally represented, such as "category," "post", or "attachment." - */ - object?: string; - /** - * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. - */ - object_id?: number; - /** - * The target attribute of the link element for this menu item. - */ - target?: '_blank' | ''; - /** - * The URL to which this menu item points. - */ - url?: string; - /** - * The XFN relationship expressed in the link of this menu item. - */ - xfn?: string[]; - /** - * Whether the menu item represents an object that no longer exists. - */ - invalid?: boolean; - /** - * The terms assigned to the object in the nav_menu taxonomy. - */ - menus?: number; - /** - * Meta fields. - */ - meta?: {}; -} - -export interface NavigationArea { - /** - * The name of the navigation area. - */ - name?: string; - /** - * The description of the navigation area. - */ - description?: string; - /** - * The ID of the assigned navigation. - */ - navigation?: number; -} - -export interface Plugin { - /** - * The plugin file. - */ - plugin?: string; - /** - * The plugin activation status. - */ - status?: 'inactive' | 'active'; - /** - * The plugin name. - */ - name?: string; - /** - * The plugin's website address. - */ - plugin_uri?: string; - /** - * The plugin author. - */ - author?: {}; - /** - * Plugin author's website address. - */ - author_uri?: string; - /** - * The plugin description. - */ - description?: { - /** - * The raw plugin description. - */ - raw?: string; - /** - * The plugin description formatted for display. - */ - rendered?: string; - }; - /** - * The plugin version number. - */ - version?: string; - /** - * Whether the plugin can only be activated network-wide. - */ - network_only?: boolean; - /** - * Minimum required version of WordPress. - */ - requires_wp?: string; - /** - * Minimum required version of PHP. - */ - requires_php?: string; - /** - * The plugin's text domain. - */ - textdomain?: string; -} - -export interface Settings { - /** - * What to show on the front page - */ - show_on_front?: string; - /** - * The ID of the page that should be displayed on the front page - */ - page_on_front?: number; - /** - * Site title. - */ - title?: string; - /** - * Site tagline. - */ - description?: string; - /** - * Site URL. - */ - url?: string; - /** - * This address is used for admin purposes, like new user notification. - */ - email?: string; - /** - * A city in the same timezone as you. - */ - timezone?: string; - /** - * A date format for all date strings. - */ - date_format?: string; - /** - * A time format for all time strings. - */ - time_format?: string; - /** - * A day number of the week that the week should start on. - */ - start_of_week?: number; - /** - * WordPress locale code. - */ - language?: string; - /** - * Convert emoticons like :-) and :-P to graphics on display. - */ - use_smilies?: boolean; - /** - * Default post category. - */ - default_category?: number; - /** - * Default post format. - */ - default_post_format?: string; - /** - * Blog pages show at most. - */ - posts_per_page?: number; - /** - * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. - */ - default_ping_status?: 'open' | 'closed'; - /** - * Allow people to submit comments on new posts. - */ - default_comment_status?: 'open' | 'closed'; - /** - * Site logo. - */ - site_logo?: number; - /** - * Site icon. - */ - site_icon?: number; -} - -export interface Sidebar { - /** - * ID of sidebar. - */ - id?: string; - /** - * Unique name identifying the sidebar. - */ - name?: string; - /** - * Description of sidebar. - */ - description?: string; - /** - * Extra CSS class to assign to the sidebar in the Widgets interface. - */ - class?: string; - /** - * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. - */ - before_widget?: string; - /** - * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. - */ - after_widget?: string; - /** - * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. - */ - before_title?: string; - /** - * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. - */ - after_title?: string; - /** - * Status of sidebar. - */ - status?: 'active' | 'inactive'; - /** - * Nested widgets. - */ - widgets?: ( {} | string )[]; -} - -export interface Taxonomy { - /** - * All capabilities used by the taxonomy. - */ - capabilities?: {}; - /** - * A human-readable description of the taxonomy. - */ - description?: string; - /** - * Whether or not the taxonomy should have children. - */ - hierarchical?: boolean; - /** - * Human-readable labels for the taxonomy for various contexts. - */ - labels?: {}; - /** - * The title for the taxonomy. - */ - name?: string; - /** - * An alphanumeric identifier for the taxonomy. - */ - slug?: string; - /** - * Whether or not the term cloud should be displayed. - */ - show_cloud?: boolean; - /** - * Types associated with the taxonomy. - */ - types?: string[]; - /** - * REST base route for the taxonomy. - */ - rest_base?: string; - /** - * REST namespace route for the taxonomy. - */ - rest_namespace?: string; - /** - * The visibility settings for the taxonomy. - */ - visibility?: { - /** - * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. - */ - public?: boolean; - /** - * Whether the taxonomy is publicly queryable. - */ - publicly_queryable?: boolean; - /** - * Whether to generate a default UI for managing this taxonomy. - */ - show_ui?: boolean; - /** - * Whether to allow automatic creation of taxonomy columns on associated post-types table. - */ - show_admin_column?: boolean; - /** - * Whether to make the taxonomy available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - /** - * Whether to show the taxonomy in the quick/bulk edit panel. - */ - show_in_quick_edit?: boolean; - }; -} - -export interface Theme { - /** - * The theme's stylesheet. This uniquely identifies the theme. - */ - stylesheet?: string; - /** - * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. - */ - template?: string; - /** - * The theme author. - */ - author?: { - /** - * The theme author's name, as found in the theme header. - */ - raw?: string; - /** - * HTML for the theme author, transformed for display. - */ - rendered?: string; - }; - /** - * The website of the theme author. - */ - author_uri?: { - /** - * The website of the theme author, as found in the theme header. - */ - raw?: string; - /** - * The website of the theme author, transformed for display. - */ - rendered?: string; - }; - /** - * A description of the theme. - */ - description?: { - /** - * The theme description, as found in the theme header. - */ - raw?: string; - /** - * The theme description, transformed for display. - */ - rendered?: string; - }; - /** - * The name of the theme. - */ - name?: { - /** - * The theme name, as found in the theme header. - */ - raw?: string; - /** - * The theme name, transformed for display. - */ - rendered?: string; - }; - /** - * The minimum PHP version required for the theme to work. - */ - requires_php?: string; - /** - * The minimum WordPress version required for the theme to work. - */ - requires_wp?: string; - /** - * The theme's screenshot URL. - */ - screenshot?: string; - /** - * Tags indicating styles and features of the theme. - */ - tags?: { - /** - * The theme tags, as found in the theme header. - */ - raw?: string[]; - /** - * The theme tags, transformed for display. - */ - rendered?: string; - }; - /** - * The theme's text domain. - */ - textdomain?: string; - /** - * Features supported by this theme. - */ - theme_supports?: { - /** - * Whether theme opts in to wide alignment CSS class. - */ - 'align-wide'?: boolean; - /** - * Whether posts and comments RSS feed links are added to head. - */ - 'automatic-feed-links'?: boolean; - /** - * Custom background if defined by the theme. - */ - 'custom-background'?: - | boolean - | { - 'default-image'?: string; - 'default-preset'?: - | 'default' - | 'fill' - | 'fit' - | 'repeat' - | 'custom'; - 'default-position-x'?: 'left' | 'center' | 'right'; - 'default-position-y'?: 'left' | 'center' | 'right'; - 'default-size'?: 'auto' | 'contain' | 'cover'; - 'default-repeat'?: - | 'repeat-x' - | 'repeat-y' - | 'repeat' - | 'no-repeat'; - 'default-attachment'?: 'scroll' | 'fixed'; - 'default-color'?: string; - }; - /** - * Custom header if defined by the theme. - */ - 'custom-header'?: - | boolean - | { - 'default-image'?: string; - 'random-default'?: boolean; - width?: number; - height?: number; - 'flex-height'?: boolean; - 'flex-width'?: boolean; - 'default-text-color'?: string; - 'header-text'?: boolean; - uploads?: boolean; - video?: boolean; - }; - /** - * Custom logo if defined by the theme. - */ - 'custom-logo'?: - | boolean - | { - width?: number; - height?: number; - 'flex-width'?: boolean; - 'flex-height'?: boolean; - 'header-text'?: string[]; - 'unlink-homepage-logo'?: boolean; - }; - /** - * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. - */ - 'customize-selective-refresh-widgets'?: boolean; - /** - * Whether theme opts in to the dark editor style UI. - */ - 'dark-editor-style'?: boolean; - /** - * Whether the theme disables custom colors. - */ - 'disable-custom-colors'?: boolean; - /** - * Whether the theme disables custom font sizes. - */ - 'disable-custom-font-sizes'?: boolean; - /** - * Whether the theme disables custom gradients. - */ - 'disable-custom-gradients'?: boolean; - /** - * Custom color palette if defined by the theme. - */ - 'editor-color-palette'?: - | boolean - | { - name?: string; - slug?: string; - color?: string; - }[]; - /** - * Custom font sizes if defined by the theme. - */ - 'editor-font-sizes'?: - | boolean - | { - name?: string; - size?: number; - slug?: string; - }[]; - /** - * Custom gradient presets if defined by the theme. - */ - 'editor-gradient-presets'?: - | boolean - | { - name?: string; - gradient?: string; - slug?: string; - }[]; - /** - * Whether theme opts in to the editor styles CSS wrapper. - */ - 'editor-styles'?: boolean; - /** - * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. - */ - html5?: - | boolean - | ( - | 'search-form' - | 'comment-form' - | 'comment-list' - | 'gallery' - | 'caption' - | 'script' - | 'style' - )[]; - /** - * Post formats supported. - */ - formats?: ( - | 'standard' - | 'aside' - | 'chat' - | 'gallery' - | 'link' - | 'image' - | 'quote' - | 'status' - | 'video' - | 'audio' - )[]; - /** - * The post types that support thumbnails or true if all post types are supported. - */ - 'post-thumbnails'?: boolean | string[]; - /** - * Whether the theme supports responsive embedded content. - */ - 'responsive-embeds'?: boolean; - /** - * Whether the theme can manage the document title tag. - */ - 'title-tag'?: boolean; - /** - * Whether theme opts in to default WordPress block styles for viewing. - */ - 'wp-block-styles'?: boolean; - }; - /** - * The URI of the theme's webpage. - */ - theme_uri?: { - /** - * The URI of the theme's webpage, as found in the theme header. - */ - raw?: string; - /** - * The URI of the theme's webpage, transformed for display. - */ - rendered?: string; - }; - /** - * The theme's current version. - */ - version?: string; - /** - * A named status for the theme. - */ - status?: 'inactive' | 'active'; -} - -export interface Type { - /** - * All capabilities used by the post type. - */ - capabilities?: {}; - /** - * A human-readable description of the post type. - */ - description?: string; - /** - * Whether or not the post type should have children. - */ - hierarchical?: boolean; - /** - * Whether or not the post type can be viewed. - */ - viewable?: boolean; - /** - * Human-readable labels for the post type for various contexts. - */ - labels?: {}; - /** - * The title for the post type. - */ - name?: string; - /** - * An alphanumeric identifier for the post type. - */ - slug?: string; - /** - * All features, supported by the post type. - */ - supports?: {}; - /** - * Taxonomies associated with post type. - */ - taxonomies?: string[]; - /** - * REST base route for the post type. - */ - rest_base?: string; - /** - * REST route's namespace for the post type. - */ - rest_namespace?: string; - /** - * The visibility settings for the post type. - */ - visibility?: { - /** - * Whether to generate a default UI for managing this post type. - */ - show_ui?: boolean; - /** - * Whether to make the post type is available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - }; -} - -export interface User { - /** - * Unique identifier for the user. - */ - id?: number; - /** - * Login name for the user. - */ - username?: string; - /** - * Display name for the user. - */ - name?: string; - /** - * First name for the user. - */ - first_name?: string; - /** - * Last name for the user. - */ - last_name?: string; - /** - * The email address for the user. - */ - email?: string; - /** - * URL of the user. - */ - url?: string; - /** - * Description of the user. - */ - description?: string; - /** - * Author URL of the user. - */ - link?: string; - /** - * Locale for the user. - */ - locale?: '' | 'en_US' | 'en_AU'; - /** - * The nickname for the user. - */ - nickname?: string; - /** - * An alphanumeric identifier for the user. - */ - slug?: string; - /** - * Registration date for the user. - */ - registered_date?: string; - /** - * Roles assigned to the user. - */ - roles?: string[]; - /** - * Password for the user (never included). - */ - password?: string; - /** - * All capabilities assigned to the user. - */ - capabilities?: {}; - /** - * Any extra capabilities assigned to the user. - */ - extra_capabilities?: {}; - /** - * Avatar URLs for the user. - */ - avatar_urls?: { - /** - * Avatar URL with image size of 24 pixels. - */ - '24'?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - '48'?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - '96'?: string; - }; - /** - * Meta fields. - */ - meta?: {}; -} - -export interface Widget { - /** - * Unique identifier for the widget. - */ - id?: string; - /** - * The type of the widget. Corresponds to ID in widget-types endpoint. - */ - id_base?: string; - /** - * The sidebar the widget belongs to. - */ - sidebar?: string; - /** - * HTML representation of the widget. - */ - rendered?: string; - /** - * HTML representation of the widget admin form. - */ - rendered_form?: string; - /** - * Instance settings of the widget, if supported. - */ - instance?: { - /** - * Base64 encoded representation of the instance settings. - */ - encoded?: string; - /** - * Cryptographic hash of the instance settings. - */ - hash?: string; - /** - * Unencoded instance settings, if supported. - */ - raw?: {}; - }; - /** - * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. - */ - form_data?: string; -} - -export interface WidgetType { - /** - * Unique slug identifying the widget type. - */ - id?: string; - /** - * Human-readable name identifying the widget type. - */ - name?: string; - /** - * Description of the widget. - */ - description?: string; - /** - * Whether the widget supports multiple instances - */ - is_multi?: boolean; - /** - * Class name - */ - classname?: string; -} - -export type EntityRecord = - | Settings - | Type - | Attachment - | Taxonomy - | Sidebar - | Widget - | WidgetType - | User - | Comment - | NavMenu - | NavMenuItem - | MenuLocation - | NavigationArea - | Theme - | Plugin; diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts new file mode 100644 index 0000000000000..18c9c67b05f59 --- /dev/null +++ b/packages/core-data/src/types/attachment.ts @@ -0,0 +1,146 @@ +export interface Attachment { + /** + * The date the post was published, in the site's timezone. + */ + date?: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt?: string | null; + /** + * The globally unique identifier for the post. + */ + guid?: { + /** + * GUID for the post, as it exists in the database. + */ + raw?: string; + /** + * GUID for the post, transformed for display. + */ + rendered?: string; + }; + /** + * Unique identifier for the post. + */ + id?: number; + /** + * URL to the post. + */ + link?: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified?: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt?: string; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug?: string; + /** + * A named status for the post. + */ + status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; + /** + * Type of post. + */ + type?: string; + /** + * Permalink template for the post. + */ + permalink_template?: string; + /** + * Slug automatically generated from the post title. + */ + generated_slug?: string; + /** + * The title for the post. + */ + title?: { + /** + * Title for the post, as it exists in the database. + */ + raw?: string; + /** + * HTML title for the post, transformed for display. + */ + rendered?: string; + }; + /** + * The ID for the author of the post. + */ + author?: number; + /** + * Whether or not comments are open on the post. + */ + comment_status?: 'open' | 'closed'; + /** + * Whether or not the post can be pinged. + */ + ping_status?: 'open' | 'closed'; + /** + * Meta fields. + */ + meta?: {}; + /** + * The theme file to use to display the post. + */ + template?: string; + /** + * Alternative text to display when attachment is not displayed. + */ + alt_text?: string; + /** + * The attachment caption. + */ + caption?: { + /** + * Caption for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML caption for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * The attachment description. + */ + description?: { + /** + * Description for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML description for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * Attachment type. + */ + media_type?: 'image' | 'file'; + /** + * The attachment MIME type. + */ + mime_type?: string; + /** + * Details about the media file, specific to its type. + */ + media_details?: {}; + /** + * The ID for the associated post of the attachment. + */ + post?: number; + /** + * URL to the original attachment file. + */ + source_url?: string; + /** + * List of the missing image sizes of the attachment. + */ + missing_image_sizes?: string[]; +} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts new file mode 100644 index 0000000000000..7191c6d95aae1 --- /dev/null +++ b/packages/core-data/src/types/comment.ts @@ -0,0 +1,93 @@ +export interface Comment { + /** + * Unique identifier for the comment. + */ + id?: number; + /** + * The ID of the user object, if author was a user. + */ + author?: number; + /** + * Email address for the comment author. + */ + author_email?: string; + /** + * IP address for the comment author. + */ + author_ip?: string; + /** + * Display name for the comment author. + */ + author_name?: string; + /** + * URL for the comment author. + */ + author_url?: string; + /** + * User agent for the comment author. + */ + author_user_agent?: string; + /** + * The content for the comment. + */ + content?: { + /** + * Content for the comment, as it exists in the database. + */ + raw?: string; + /** + * HTML content for the comment, transformed for display. + */ + rendered?: string; + }; + /** + * The date the comment was published, in the site's timezone. + */ + date?: string; + /** + * The date the comment was published, as GMT. + */ + date_gmt?: string; + /** + * URL to the comment. + */ + link?: string; + /** + * The ID for the parent of the comment. + */ + parent?: number; + /** + * The ID of the associated post object. + */ + post?: number; + /** + * State of the comment. + */ + status?: string; + /** + * Type of the comment. + */ + type?: string; + /** + * Avatar URLs for the comment author. + */ + author_avatar_urls?: { + /** + * Avatar URL with image size of 24 pixels. + */ + "24"?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + "48"?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + "96"?: string; + }; + /** + * Meta fields. + */ + meta?: { + }; +} diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts new file mode 100644 index 0000000000000..a2552a25692cb --- /dev/null +++ b/packages/core-data/src/types/menu-location.ts @@ -0,0 +1,14 @@ +export interface MenuLocation { + /** + * The name of the menu location. + */ + name?: string; + /** + * The description of the menu location. + */ + description?: string; + /** + * The ID of the assigned menu. + */ + menu?: number; +} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts new file mode 100644 index 0000000000000..2a7c46c1070b7 --- /dev/null +++ b/packages/core-data/src/types/nav_menu.ts @@ -0,0 +1,31 @@ +export interface NavMenu { + /** + * Unique identifier for the term. + */ + id?: number; + /** + * HTML description of the term. + */ + description?: string; + /** + * HTML title for the term. + */ + name?: string; + /** + * An alphanumeric identifier for the term unique to its type. + */ + slug?: string; + /** + * Meta fields. + */ + meta?: { + }; + /** + * The locations assigned to the menu. + */ + locations?: string[]; + /** + * Whether to automatically add top level pages to this menu. + */ + auto_add?: boolean; +} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts new file mode 100644 index 0000000000000..ced9f40312b3d --- /dev/null +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -0,0 +1,86 @@ +export interface NavMenuItem { + /** + * The title for the object. + */ + title?: + | string + | { + /** + * Title for the object, as it exists in the database. + */ + raw?: string; + /** + * HTML title for the object, transformed for display. + */ + rendered?: string; + }; + /** + * Unique identifier for the object. + */ + id?: number; + /** + * The singular label used to describe this type of menu item. + */ + type_label?: string; + /** + * The family of objects originally represented, such as "post_type" or "taxonomy". + */ + type?: "taxonomy" | "post_type" | "post_type_archive" | "custom"; + /** + * A named status for the object. + */ + status?: "publish" | "future" | "draft" | "pending" | "private"; + /** + * The ID for the parent of the object. + */ + parent?: number; + /** + * Text for the title attribute of the link element for this menu item. + */ + attr_title?: string; + /** + * Class names for the link element of this menu item. + */ + classes?: string[]; + /** + * The description of this menu item. + */ + description?: string; + /** + * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. + */ + menu_order?: number; + /** + * The type of object originally represented, such as "category", "post", or "attachment". + */ + object?: string; + /** + * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. + */ + object_id?: number; + /** + * The target attribute of the link element for this menu item. + */ + target?: "_blank" | ""; + /** + * The URL to which this menu item points. + */ + url?: string; + /** + * The XFN relationship expressed in the link of this menu item. + */ + xfn?: string[]; + /** + * Whether the menu item represents an object that no longer exists. + */ + invalid?: boolean; + /** + * The terms assigned to the object in the nav_menu taxonomy. + */ + menus?: number; + /** + * Meta fields. + */ + meta?: { + }; +} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts new file mode 100644 index 0000000000000..93e76811b2c2e --- /dev/null +++ b/packages/core-data/src/types/settings.ts @@ -0,0 +1,78 @@ +export interface Settings { + /** + * What to show on the front page + */ + show_on_front?: string; + /** + * The ID of the page that should be displayed on the front page + */ + page_on_front?: number; + /** + * Site title. + */ + title?: string; + /** + * Site tagline. + */ + description?: string; + /** + * Site URL. + */ + url?: string; + /** + * This address is used for admin purposes, like new user notification. + */ + email?: string; + /** + * A city in the same timezone as you. + */ + timezone?: string; + /** + * A date format for all date strings. + */ + date_format?: string; + /** + * A time format for all time strings. + */ + time_format?: string; + /** + * A day number of the week that the week should start on. + */ + start_of_week?: number; + /** + * WordPress locale code. + */ + language?: string; + /** + * Convert emoticons like :-) and :-P to graphics on display. + */ + use_smilies?: boolean; + /** + * Default post category. + */ + default_category?: number; + /** + * Default post format. + */ + default_post_format?: string; + /** + * Blog pages show at most. + */ + posts_per_page?: number; + /** + * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. + */ + default_ping_status?: "open" | "closed"; + /** + * Allow people to submit comments on new posts. + */ + default_comment_status?: "open" | "closed"; + /** + * Site logo. + */ + site_logo?: number; + /** + * Site icon. + */ + site_icon?: number; +} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts new file mode 100644 index 0000000000000..164fa02a4ceb9 --- /dev/null +++ b/packages/core-data/src/types/sidebar.ts @@ -0,0 +1,46 @@ +export interface Sidebar { + /** + * ID of sidebar. + */ + id?: string; + /** + * Unique name identifying the sidebar. + */ + name?: string; + /** + * Description of sidebar. + */ + description?: string; + /** + * Extra CSS class to assign to the sidebar in the Widgets interface. + */ + class?: string; + /** + * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. + */ + before_widget?: string; + /** + * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. + */ + after_widget?: string; + /** + * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. + */ + before_title?: string; + /** + * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. + */ + after_title?: string; + /** + * Status of sidebar. + */ + status?: "active" | "inactive"; + /** + * Nested widgets. + */ + widgets?: ( + | { + } + | string + )[]; +} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts new file mode 100644 index 0000000000000..92c672f1cf8d2 --- /dev/null +++ b/packages/core-data/src/types/taxonomy.ts @@ -0,0 +1,73 @@ +export interface Taxonomy { + /** + * All capabilities used by the taxonomy. + */ + capabilities?: { + }; + /** + * A human-readable description of the taxonomy. + */ + description?: string; + /** + * Whether or not the taxonomy should have children. + */ + hierarchical?: boolean; + /** + * Human-readable labels for the taxonomy for various contexts. + */ + labels?: { + }; + /** + * The title for the taxonomy. + */ + name?: string; + /** + * An alphanumeric identifier for the taxonomy. + */ + slug?: string; + /** + * Whether or not the term cloud should be displayed. + */ + show_cloud?: boolean; + /** + * Types associated with the taxonomy. + */ + types?: string[]; + /** + * REST base route for the taxonomy. + */ + rest_base?: string; + /** + * REST namespace route for the taxonomy. + */ + rest_namespace?: string; + /** + * The visibility settings for the taxonomy. + */ + visibility?: { + /** + * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. + */ + public?: boolean; + /** + * Whether the taxonomy is publicly queryable. + */ + publicly_queryable?: boolean; + /** + * Whether to generate a default UI for managing this taxonomy. + */ + show_ui?: boolean; + /** + * Whether to allow automatic creation of taxonomy columns on associated post-types table. + */ + show_admin_column?: boolean; + /** + * Whether to make the taxonomy available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + /** + * Whether to show the taxonomy in the quick/bulk edit panel. + */ + show_in_quick_edit?: boolean; + }; +} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts new file mode 100644 index 0000000000000..ca89c56d02dcc --- /dev/null +++ b/packages/core-data/src/types/type.ts @@ -0,0 +1,62 @@ +export interface Type { + /** + * All capabilities used by the post type. + */ + capabilities?: { + }; + /** + * A human-readable description of the post type. + */ + description?: string; + /** + * Whether or not the post type should have children. + */ + hierarchical?: boolean; + /** + * Whether or not the post type can be viewed. + */ + viewable?: boolean; + /** + * Human-readable labels for the post type for various contexts. + */ + labels?: { + }; + /** + * The title for the post type. + */ + name?: string; + /** + * An alphanumeric identifier for the post type. + */ + slug?: string; + /** + * All features, supported by the post type. + */ + supports?: { + }; + /** + * Taxonomies associated with post type. + */ + taxonomies?: string[]; + /** + * REST base route for the post type. + */ + rest_base?: string; + /** + * REST route's namespace for the post type. + */ + rest_namespace?: string; + /** + * The visibility settings for the post type. + */ + visibility?: { + /** + * Whether to generate a default UI for managing this post type. + */ + show_ui?: boolean; + /** + * Whether to make the post type is available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + }; +} diff --git a/packages/core-data/src/types/types.ts b/packages/core-data/src/types/types.ts new file mode 100644 index 0000000000000..807fece931001 --- /dev/null +++ b/packages/core-data/src/types/types.ts @@ -0,0 +1,147 @@ +export interface Attachment { + /** + * The date the post was published, in the site's timezone. + */ + date?: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt?: string | null; + /** + * The globally unique identifier for the post. + */ + guid?: { + /** + * GUID for the post, as it exists in the database. + */ + raw?: string; + /** + * GUID for the post, transformed for display. + */ + rendered?: string; + }; + /** + * Unique identifier for the post. + */ + id?: number; + /** + * URL to the post. + */ + link?: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified?: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt?: string; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug?: string; + /** + * A named status for the post. + */ + status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; + /** + * Type of post. + */ + type?: string; + /** + * Permalink template for the post. + */ + permalink_template?: string; + /** + * Slug automatically generated from the post title. + */ + generated_slug?: string; + /** + * The title for the post. + */ + title?: { + /** + * Title for the post, as it exists in the database. + */ + raw?: string; + /** + * HTML title for the post, transformed for display. + */ + rendered?: string; + }; + /** + * The ID for the author of the post. + */ + author?: number; + /** + * Whether or not comments are open on the post. + */ + comment_status?: 'open' | 'closed'; + /** + * Whether or not the post can be pinged. + */ + ping_status?: 'open' | 'closed'; + /** + * Meta fields. + */ + meta?: {}; + /** + * The theme file to use to display the post. + */ + template?: string; + /** + * Alternative text to display when attachment is not displayed. + */ + alt_text?: string; + /** + * The attachment caption. + */ + caption?: { + /** + * Caption for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML caption for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * The attachment description. + */ + description?: { + /** + * Description for the attachment, as it exists in the database. + */ + raw?: string; + /** + * HTML description for the attachment, transformed for display. + */ + rendered?: string; + }; + /** + * Attachment type. + */ + media_type?: 'image' | 'file'; + /** + * The attachment MIME type. + */ + mime_type?: string; + /** + * Details about the media file, specific to its type. + */ + media_details?: {}; + /** + * The ID for the associated post of the attachment. + */ + post?: number; + /** + * URL to the original attachment file. + */ + source_url?: string; + /** + * List of the missing image sizes of the attachment. + */ + missing_image_sizes?: string[]; +} + diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts new file mode 100644 index 0000000000000..993e54e3a2854 --- /dev/null +++ b/packages/core-data/src/types/user.ts @@ -0,0 +1,94 @@ +export interface User { + /** + * Unique identifier for the user. + */ + id?: number; + /** + * Login name for the user. + */ + username?: string; + /** + * Display name for the user. + */ + name?: string; + /** + * First name for the user. + */ + first_name?: string; + /** + * Last name for the user. + */ + last_name?: string; + /** + * The email address for the user. + */ + email?: string; + /** + * URL of the user. + */ + url?: string; + /** + * Description of the user. + */ + description?: string; + /** + * Author URL of the user. + */ + link?: string; + /** + * Locale for the user. + */ + locale?: "" | "en_US"; + /** + * The nickname for the user. + */ + nickname?: string; + /** + * An alphanumeric identifier for the user. + */ + slug?: string; + /** + * Registration date for the user. + */ + registered_date?: string; + /** + * Roles assigned to the user. + */ + roles?: string[]; + /** + * Password for the user (never included). + */ + password?: string; + /** + * All capabilities assigned to the user. + */ + capabilities?: { + }; + /** + * Any extra capabilities assigned to the user. + */ + extra_capabilities?: { + }; + /** + * Avatar URLs for the user. + */ + avatar_urls?: { + /** + * Avatar URL with image size of 24 pixels. + */ + "24"?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + "48"?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + "96"?: string; + }; + /** + * Meta fields. + */ + meta?: { + }; +} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts new file mode 100644 index 0000000000000..3288bd9033235 --- /dev/null +++ b/packages/core-data/src/types/widget-type.ts @@ -0,0 +1,22 @@ +export interface WidgetType { + /** + * Unique slug identifying the widget type. + */ + id?: string; + /** + * Human-readable name identifying the widget type. + */ + name?: string; + /** + * Description of the widget. + */ + description?: string; + /** + * Whether the widget supports multiple instances + */ + is_multi?: boolean; + /** + * Class name + */ + classname?: string; +} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts new file mode 100644 index 0000000000000..42d2979a9dfc4 --- /dev/null +++ b/packages/core-data/src/types/widget.ts @@ -0,0 +1,44 @@ +export interface Widget { + /** + * Unique identifier for the widget. + */ + id?: string; + /** + * The type of the widget. Corresponds to ID in widget-types endpoint. + */ + id_base?: string; + /** + * The sidebar the widget belongs to. + */ + sidebar?: string; + /** + * HTML representation of the widget. + */ + rendered?: string; + /** + * HTML representation of the widget admin form. + */ + rendered_form?: string; + /** + * Instance settings of the widget, if supported. + */ + instance?: { + /** + * Base64 encoded representation of the instance settings. + */ + encoded?: string; + /** + * Cryptographic hash of the instance settings. + */ + hash?: string; + /** + * Unencoded instance settings, if supported. + */ + raw?: { + }; + }; + /** + * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. + */ + form_data?: string; +} From de331e09c808b474665710043d0ca1fda3f2d6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 15:29:09 +0100 Subject: [PATCH 04/73] Rond 2 of autogenerating types --- packages/core-data/src/types/attachment.ts | 86 +++---- packages/core-data/src/types/comment.ts | 189 +++++++------- packages/core-data/src/types/menu-location.ts | 24 +- packages/core-data/src/types/nav_menu.ts | 59 ++--- packages/core-data/src/types/nav_menu_item.ts | 172 +++++++------ .../core-data/src/types/navigation-area.ts | 14 + packages/core-data/src/types/plugin.ts | 66 +++++ packages/core-data/src/types/settings.ts | 152 +++++------ packages/core-data/src/types/sidebar.ts | 89 +++---- packages/core-data/src/types/taxonomy.ts | 145 +++++------ packages/core-data/src/types/theme.ts | 239 ++++++++++++++++++ packages/core-data/src/types/type.ts | 124 ++++----- packages/core-data/src/types/types.ts | 58 ++--- packages/core-data/src/types/user.ts | 188 +++++++------- packages/core-data/src/types/widget-type.ts | 40 +-- packages/core-data/src/types/widget.ts | 86 ++++--- 16 files changed, 1016 insertions(+), 715 deletions(-) create mode 100644 packages/core-data/src/types/navigation-area.ts create mode 100644 packages/core-data/src/types/plugin.ts create mode 100644 packages/core-data/src/types/theme.ts diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 18c9c67b05f59..9ba09ac983330 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -2,7 +2,7 @@ export interface Attachment { /** * The date the post was published, in the site's timezone. */ - date?: string | null; + date: string | null; /** * The date the post was published, as GMT. */ @@ -10,24 +10,15 @@ export interface Attachment { /** * The globally unique identifier for the post. */ - guid?: { - /** - * GUID for the post, as it exists in the database. - */ - raw?: string; - /** - * GUID for the post, transformed for display. - */ - rendered?: string; - }; + guid?: RawData; /** * Unique identifier for the post. */ - id?: number; + id: number; /** * URL to the post. */ - link?: string; + link: string; /** * The date the post was last modified, in the site's timezone. */ @@ -39,7 +30,7 @@ export interface Attachment { /** * An alphanumeric identifier for the post unique to its type. */ - slug?: string; + slug: string; /** * A named status for the post. */ @@ -47,7 +38,7 @@ export interface Attachment { /** * Type of post. */ - type?: string; + type: string; /** * Permalink template for the post. */ @@ -59,20 +50,11 @@ export interface Attachment { /** * The title for the post. */ - title?: { - /** - * Title for the post, as it exists in the database. - */ - raw?: string; - /** - * HTML title for the post, transformed for display. - */ - rendered?: string; - }; + title: RawData; /** * The ID for the author of the post. */ - author?: number; + author: number; /** * Whether or not comments are open on the post. */ @@ -84,7 +66,9 @@ export interface Attachment { /** * Meta fields. */ - meta?: {}; + meta?: { + [ k: string ]: unknown; + }; /** * The theme file to use to display the post. */ @@ -92,45 +76,29 @@ export interface Attachment { /** * Alternative text to display when attachment is not displayed. */ - alt_text?: string; + alt_text: string; /** * The attachment caption. */ - caption?: { - /** - * Caption for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML caption for the attachment, transformed for display. - */ - rendered?: string; - }; + caption: RawData; /** * The attachment description. */ - description?: { - /** - * Description for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML description for the attachment, transformed for display. - */ - rendered?: string; - }; + description?: RawData; /** * Attachment type. */ - media_type?: 'image' | 'file'; + media_type: 'image' | 'file'; /** * The attachment MIME type. */ - mime_type?: string; + mime_type: string; /** * Details about the media file, specific to its type. */ - media_details?: {}; + media_details: { + [ k: string ]: unknown; + }; /** * The ID for the associated post of the attachment. */ @@ -138,9 +106,23 @@ export interface Attachment { /** * URL to the original attachment file. */ - source_url?: string; + source_url: string; /** * List of the missing image sizes of the attachment. */ missing_image_sizes?: string[]; } + +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; +} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 7191c6d95aae1..c98ebb067c9ba 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,93 +1,100 @@ export interface Comment { - /** - * Unique identifier for the comment. - */ - id?: number; - /** - * The ID of the user object, if author was a user. - */ - author?: number; - /** - * Email address for the comment author. - */ - author_email?: string; - /** - * IP address for the comment author. - */ - author_ip?: string; - /** - * Display name for the comment author. - */ - author_name?: string; - /** - * URL for the comment author. - */ - author_url?: string; - /** - * User agent for the comment author. - */ - author_user_agent?: string; - /** - * The content for the comment. - */ - content?: { - /** - * Content for the comment, as it exists in the database. - */ - raw?: string; - /** - * HTML content for the comment, transformed for display. - */ - rendered?: string; - }; - /** - * The date the comment was published, in the site's timezone. - */ - date?: string; - /** - * The date the comment was published, as GMT. - */ - date_gmt?: string; - /** - * URL to the comment. - */ - link?: string; - /** - * The ID for the parent of the comment. - */ - parent?: number; - /** - * The ID of the associated post object. - */ - post?: number; - /** - * State of the comment. - */ - status?: string; - /** - * Type of the comment. - */ - type?: string; - /** - * Avatar URLs for the comment author. - */ - author_avatar_urls?: { - /** - * Avatar URL with image size of 24 pixels. - */ - "24"?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - "48"?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - "96"?: string; - }; - /** - * Meta fields. - */ - meta?: { - }; + /** + * Unique identifier for the comment. + */ + id: number; + /** + * The ID of the user object, if author was a user. + */ + author: number; + /** + * Email address for the comment author. + */ + author_email?: string; + /** + * IP address for the comment author. + */ + author_ip?: string; + /** + * Display name for the comment author. + */ + author_name: string; + /** + * URL for the comment author. + */ + author_url: string; + /** + * User agent for the comment author. + */ + author_user_agent?: string; + /** + * The content for the comment. + */ + content: RawData; + /** + * The date the comment was published, in the site's timezone. + */ + date: string; + /** + * The date the comment was published, as GMT. + */ + date_gmt?: string; + /** + * URL to the comment. + */ + link: string; + /** + * The ID for the parent of the comment. + */ + parent: number; + /** + * The ID of the associated post object. + */ + post?: number; + /** + * State of the comment. + */ + status?: string; + /** + * Type of the comment. + */ + type: string; + /** + * Avatar URLs for the comment author. + */ + author_avatar_urls: { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + [ k: string ]: unknown; + }; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: unknown; + }; +} + +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; } diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index a2552a25692cb..251d97aaceabb 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,14 +1,14 @@ export interface MenuLocation { - /** - * The name of the menu location. - */ - name?: string; - /** - * The description of the menu location. - */ - description?: string; - /** - * The ID of the assigned menu. - */ - menu?: number; + /** + * The name of the menu location. + */ + name: string; + /** + * The description of the menu location. + */ + description: string; + /** + * The ID of the assigned menu. + */ + menu: number; } diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 2a7c46c1070b7..79fae2aff09c4 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -1,31 +1,32 @@ export interface NavMenu { - /** - * Unique identifier for the term. - */ - id?: number; - /** - * HTML description of the term. - */ - description?: string; - /** - * HTML title for the term. - */ - name?: string; - /** - * An alphanumeric identifier for the term unique to its type. - */ - slug?: string; - /** - * Meta fields. - */ - meta?: { - }; - /** - * The locations assigned to the menu. - */ - locations?: string[]; - /** - * Whether to automatically add top level pages to this menu. - */ - auto_add?: boolean; + /** + * Unique identifier for the term. + */ + id: number; + /** + * HTML description of the term. + */ + description?: string; + /** + * HTML title for the term. + */ + name: string; + /** + * An alphanumeric identifier for the term unique to its type. + */ + slug: string; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: unknown; + }; + /** + * The locations assigned to the menu. + */ + locations?: string[]; + /** + * Whether to automatically add top level pages to this menu. + */ + auto_add?: boolean; } diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index ced9f40312b3d..3b443b6da776f 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,86 +1,90 @@ export interface NavMenuItem { - /** - * The title for the object. - */ - title?: - | string - | { - /** - * Title for the object, as it exists in the database. - */ - raw?: string; - /** - * HTML title for the object, transformed for display. - */ - rendered?: string; - }; - /** - * Unique identifier for the object. - */ - id?: number; - /** - * The singular label used to describe this type of menu item. - */ - type_label?: string; - /** - * The family of objects originally represented, such as "post_type" or "taxonomy". - */ - type?: "taxonomy" | "post_type" | "post_type_archive" | "custom"; - /** - * A named status for the object. - */ - status?: "publish" | "future" | "draft" | "pending" | "private"; - /** - * The ID for the parent of the object. - */ - parent?: number; - /** - * Text for the title attribute of the link element for this menu item. - */ - attr_title?: string; - /** - * Class names for the link element of this menu item. - */ - classes?: string[]; - /** - * The description of this menu item. - */ - description?: string; - /** - * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. - */ - menu_order?: number; - /** - * The type of object originally represented, such as "category", "post", or "attachment". - */ - object?: string; - /** - * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. - */ - object_id?: number; - /** - * The target attribute of the link element for this menu item. - */ - target?: "_blank" | ""; - /** - * The URL to which this menu item points. - */ - url?: string; - /** - * The XFN relationship expressed in the link of this menu item. - */ - xfn?: string[]; - /** - * Whether the menu item represents an object that no longer exists. - */ - invalid?: boolean; - /** - * The terms assigned to the object in the nav_menu taxonomy. - */ - menus?: number; - /** - * Meta fields. - */ - meta?: { - }; + /** + * The title for the object. + */ + title: RawData; + /** + * Unique identifier for the object. + */ + id: number; + /** + * The singular label used to describe this type of menu item. + */ + type_label: string; + /** + * The family of objects originally represented, such as "post_type" or "taxonomy". + */ + type: 'taxonomy' | 'post_type' | 'post_type_archive' | 'custom'; + /** + * A named status for the object. + */ + status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; + /** + * The ID for the parent of the object. + */ + parent: number; + /** + * Text for the title attribute of the link element for this menu item. + */ + attr_title: string; + /** + * Class names for the link element of this menu item. + */ + classes: string[]; + /** + * The description of this menu item. + */ + description: string; + /** + * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. + */ + menu_order: number; + /** + * The type of object originally represented, such as "category", "post", or "attachment". + */ + object: string; + /** + * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. + */ + object_id: number; + /** + * The target attribute of the link element for this menu item. + */ + target: '_blank' | ''; + /** + * The URL to which this menu item points. + */ + url: string; + /** + * The XFN relationship expressed in the link of this menu item. + */ + xfn: string[]; + /** + * Whether the menu item represents an object that no longer exists. + */ + invalid: boolean; + /** + * The terms assigned to the object in the nav_menu taxonomy. + */ + menus?: number; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: unknown; + }; +} + +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; } diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts new file mode 100644 index 0000000000000..5749e5f7db6ef --- /dev/null +++ b/packages/core-data/src/types/navigation-area.ts @@ -0,0 +1,14 @@ +export interface NavigationArea { + /** + * The name of the navigation area. + */ + name: string; + /** + * The description of the navigation area. + */ + description: string; + /** + * The ID of the assigned navigation. + */ + navigation: number; +} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts new file mode 100644 index 0000000000000..1a2130f4ffdf0 --- /dev/null +++ b/packages/core-data/src/types/plugin.ts @@ -0,0 +1,66 @@ +export interface Plugin { + /** + * The plugin file. + */ + plugin: string; + /** + * The plugin activation status. + */ + status: 'inactive' | 'active'; + /** + * The plugin name. + */ + name: string; + /** + * The plugin's website address. + */ + plugin_uri?: string; + /** + * The plugin author. + */ + author?: { + [ k: string ]: unknown; + }; + /** + * Plugin author's website address. + */ + author_uri?: string; + /** + * The plugin description. + */ + description?: RawData; + /** + * The plugin version number. + */ + version?: string; + /** + * Whether the plugin can only be activated network-wide. + */ + network_only: boolean; + /** + * Minimum required version of WordPress. + */ + requires_wp: string; + /** + * Minimum required version of PHP. + */ + requires_php: string; + /** + * The plugin's text domain. + */ + textdomain?: string; +} + +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; +} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 93e76811b2c2e..263647e85885c 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,78 +1,78 @@ export interface Settings { - /** - * What to show on the front page - */ - show_on_front?: string; - /** - * The ID of the page that should be displayed on the front page - */ - page_on_front?: number; - /** - * Site title. - */ - title?: string; - /** - * Site tagline. - */ - description?: string; - /** - * Site URL. - */ - url?: string; - /** - * This address is used for admin purposes, like new user notification. - */ - email?: string; - /** - * A city in the same timezone as you. - */ - timezone?: string; - /** - * A date format for all date strings. - */ - date_format?: string; - /** - * A time format for all time strings. - */ - time_format?: string; - /** - * A day number of the week that the week should start on. - */ - start_of_week?: number; - /** - * WordPress locale code. - */ - language?: string; - /** - * Convert emoticons like :-) and :-P to graphics on display. - */ - use_smilies?: boolean; - /** - * Default post category. - */ - default_category?: number; - /** - * Default post format. - */ - default_post_format?: string; - /** - * Blog pages show at most. - */ - posts_per_page?: number; - /** - * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. - */ - default_ping_status?: "open" | "closed"; - /** - * Allow people to submit comments on new posts. - */ - default_comment_status?: "open" | "closed"; - /** - * Site logo. - */ - site_logo?: number; - /** - * Site icon. - */ - site_icon?: number; + /** + * What to show on the front page + */ + show_on_front?: string; + /** + * The ID of the page that should be displayed on the front page + */ + page_on_front?: number; + /** + * Site title. + */ + title?: string; + /** + * Site tagline. + */ + description?: string; + /** + * Site URL. + */ + url?: string; + /** + * This address is used for admin purposes, like new user notification. + */ + email?: string; + /** + * A city in the same timezone as you. + */ + timezone?: string; + /** + * A date format for all date strings. + */ + date_format?: string; + /** + * A time format for all time strings. + */ + time_format?: string; + /** + * A day number of the week that the week should start on. + */ + start_of_week?: number; + /** + * WordPress locale code. + */ + language?: string; + /** + * Convert emoticons like :-) and :-P to graphics on display. + */ + use_smilies?: boolean; + /** + * Default post category. + */ + default_category?: number; + /** + * Default post format. + */ + default_post_format?: string; + /** + * Blog pages show at most. + */ + posts_per_page?: number; + /** + * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. + */ + default_ping_status?: 'open' | 'closed'; + /** + * Allow people to submit comments on new posts. + */ + default_comment_status?: 'open' | 'closed'; + /** + * Site logo. + */ + site_logo?: number; + /** + * Site icon. + */ + site_icon?: number; } diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 164fa02a4ceb9..f4e00bc3b6b7a 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -1,46 +1,47 @@ export interface Sidebar { - /** - * ID of sidebar. - */ - id?: string; - /** - * Unique name identifying the sidebar. - */ - name?: string; - /** - * Description of sidebar. - */ - description?: string; - /** - * Extra CSS class to assign to the sidebar in the Widgets interface. - */ - class?: string; - /** - * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. - */ - before_widget?: string; - /** - * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. - */ - after_widget?: string; - /** - * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. - */ - before_title?: string; - /** - * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. - */ - after_title?: string; - /** - * Status of sidebar. - */ - status?: "active" | "inactive"; - /** - * Nested widgets. - */ - widgets?: ( - | { - } - | string - )[]; + /** + * ID of sidebar. + */ + id: string; + /** + * Unique name identifying the sidebar. + */ + name: string; + /** + * Description of sidebar. + */ + description: string; + /** + * Extra CSS class to assign to the sidebar in the Widgets interface. + */ + class: string; + /** + * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. + */ + before_widget: string; + /** + * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. + */ + after_widget: string; + /** + * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. + */ + before_title: string; + /** + * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. + */ + after_title: string; + /** + * Status of sidebar. + */ + status: 'active' | 'inactive'; + /** + * Nested widgets. + */ + widgets: ( + | { + [ k: string ]: unknown; + } + | string + )[]; } diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 92c672f1cf8d2..6bca7dafe174b 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,73 +1,76 @@ export interface Taxonomy { - /** - * All capabilities used by the taxonomy. - */ - capabilities?: { - }; - /** - * A human-readable description of the taxonomy. - */ - description?: string; - /** - * Whether or not the taxonomy should have children. - */ - hierarchical?: boolean; - /** - * Human-readable labels for the taxonomy for various contexts. - */ - labels?: { - }; - /** - * The title for the taxonomy. - */ - name?: string; - /** - * An alphanumeric identifier for the taxonomy. - */ - slug?: string; - /** - * Whether or not the term cloud should be displayed. - */ - show_cloud?: boolean; - /** - * Types associated with the taxonomy. - */ - types?: string[]; - /** - * REST base route for the taxonomy. - */ - rest_base?: string; - /** - * REST namespace route for the taxonomy. - */ - rest_namespace?: string; - /** - * The visibility settings for the taxonomy. - */ - visibility?: { - /** - * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. - */ - public?: boolean; - /** - * Whether the taxonomy is publicly queryable. - */ - publicly_queryable?: boolean; - /** - * Whether to generate a default UI for managing this taxonomy. - */ - show_ui?: boolean; - /** - * Whether to allow automatic creation of taxonomy columns on associated post-types table. - */ - show_admin_column?: boolean; - /** - * Whether to make the taxonomy available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - /** - * Whether to show the taxonomy in the quick/bulk edit panel. - */ - show_in_quick_edit?: boolean; - }; + /** + * All capabilities used by the taxonomy. + */ + capabilities?: { + [ k: string ]: unknown; + }; + /** + * A human-readable description of the taxonomy. + */ + description?: string; + /** + * Whether or not the taxonomy should have children. + */ + hierarchical?: boolean; + /** + * Human-readable labels for the taxonomy for various contexts. + */ + labels?: { + [ k: string ]: unknown; + }; + /** + * The title for the taxonomy. + */ + name: string; + /** + * An alphanumeric identifier for the taxonomy. + */ + slug: string; + /** + * Whether or not the term cloud should be displayed. + */ + show_cloud?: boolean; + /** + * Types associated with the taxonomy. + */ + types?: string[]; + /** + * REST base route for the taxonomy. + */ + rest_base: string; + /** + * REST namespace route for the taxonomy. + */ + rest_namespace: string; + /** + * The visibility settings for the taxonomy. + */ + visibility?: { + /** + * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. + */ + public?: boolean; + /** + * Whether the taxonomy is publicly queryable. + */ + publicly_queryable?: boolean; + /** + * Whether to generate a default UI for managing this taxonomy. + */ + show_ui?: boolean; + /** + * Whether to allow automatic creation of taxonomy columns on associated post-types table. + */ + show_admin_column?: boolean; + /** + * Whether to make the taxonomy available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + /** + * Whether to show the taxonomy in the quick/bulk edit panel. + */ + show_in_quick_edit?: boolean; + [ k: string ]: unknown; + }; } diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts new file mode 100644 index 0000000000000..86e89dcd3b19e --- /dev/null +++ b/packages/core-data/src/types/theme.ts @@ -0,0 +1,239 @@ +export interface Theme { + /** + * The theme's stylesheet. This uniquely identifies the theme. + */ + stylesheet?: string; + /** + * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. + */ + template?: string; + /** + * The theme author. + */ + author?: RawData; + /** + * The website of the theme author. + */ + author_uri?: RawData; + /** + * A description of the theme. + */ + description?: RawData; + /** + * The name of the theme. + */ + name?: RawData; + /** + * The minimum PHP version required for the theme to work. + */ + requires_php?: string; + /** + * The minimum WordPress version required for the theme to work. + */ + requires_wp?: string; + /** + * The theme's screenshot URL. + */ + screenshot?: string; + /** + * Tags indicating styles and features of the theme. + */ + tags?: RawData; + /** + * The theme's text domain. + */ + textdomain?: string; + /** + * Features supported by this theme. + */ + theme_supports?: { + /** + * Whether theme opts in to wide alignment CSS class. + */ + 'align-wide'?: boolean; + /** + * Whether posts and comments RSS feed links are added to head. + */ + 'automatic-feed-links'?: boolean; + /** + * Custom background if defined by the theme. + */ + 'custom-background'?: + | boolean + | { + 'default-image'?: string; + 'default-preset'?: + | 'default' + | 'fill' + | 'fit' + | 'repeat' + | 'custom'; + 'default-position-x'?: 'left' | 'center' | 'right'; + 'default-position-y'?: 'left' | 'center' | 'right'; + 'default-size'?: 'auto' | 'contain' | 'cover'; + 'default-repeat'?: + | 'repeat-x' + | 'repeat-y' + | 'repeat' + | 'no-repeat'; + 'default-attachment'?: 'scroll' | 'fixed'; + 'default-color'?: string; + }; + /** + * Custom header if defined by the theme. + */ + 'custom-header'?: + | boolean + | { + 'default-image'?: string; + 'random-default'?: boolean; + width?: number; + height?: number; + 'flex-height'?: boolean; + 'flex-width'?: boolean; + 'default-text-color'?: string; + 'header-text'?: boolean; + uploads?: boolean; + video?: boolean; + }; + /** + * Custom logo if defined by the theme. + */ + 'custom-logo'?: + | boolean + | { + width?: number; + height?: number; + 'flex-width'?: boolean; + 'flex-height'?: boolean; + 'header-text'?: string[]; + 'unlink-homepage-logo'?: boolean; + }; + /** + * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. + */ + 'customize-selective-refresh-widgets'?: boolean; + /** + * Whether theme opts in to the dark editor style UI. + */ + 'dark-editor-style'?: boolean; + /** + * Whether the theme disables custom colors. + */ + 'disable-custom-colors'?: boolean; + /** + * Whether the theme disables custom font sizes. + */ + 'disable-custom-font-sizes'?: boolean; + /** + * Whether the theme disables custom gradients. + */ + 'disable-custom-gradients'?: boolean; + /** + * Custom color palette if defined by the theme. + */ + 'editor-color-palette'?: + | boolean + | { + name?: string; + slug?: string; + color?: string; + }[]; + /** + * Custom font sizes if defined by the theme. + */ + 'editor-font-sizes'?: + | boolean + | { + name?: string; + size?: number; + slug?: string; + }[]; + /** + * Custom gradient presets if defined by the theme. + */ + 'editor-gradient-presets'?: + | boolean + | { + name?: string; + gradient?: string; + slug?: string; + }[]; + /** + * Whether theme opts in to the editor styles CSS wrapper. + */ + 'editor-styles'?: boolean; + /** + * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. + */ + html5?: + | boolean + | ( + | 'search-form' + | 'comment-form' + | 'comment-list' + | 'gallery' + | 'caption' + | 'script' + | 'style' + )[]; + /** + * Post formats supported. + */ + formats?: ( + | 'standard' + | 'aside' + | 'chat' + | 'gallery' + | 'link' + | 'image' + | 'quote' + | 'status' + | 'video' + | 'audio' + )[]; + /** + * The post types that support thumbnails or true if all post types are supported. + */ + 'post-thumbnails'?: boolean | string[]; + /** + * Whether the theme supports responsive embedded content. + */ + 'responsive-embeds'?: boolean; + /** + * Whether the theme can manage the document title tag. + */ + 'title-tag'?: boolean; + /** + * Whether theme opts in to default WordPress block styles for viewing. + */ + 'wp-block-styles'?: boolean; + [ k: string ]: unknown; + }; + /** + * The URI of the theme's webpage. + */ + theme_uri?: RawData; + /** + * The theme's current version. + */ + version?: string; + /** + * A named status for the theme. + */ + status?: 'inactive' | 'active'; +} + +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; +} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index ca89c56d02dcc..3e8983236e96c 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,62 +1,66 @@ export interface Type { - /** - * All capabilities used by the post type. - */ - capabilities?: { - }; - /** - * A human-readable description of the post type. - */ - description?: string; - /** - * Whether or not the post type should have children. - */ - hierarchical?: boolean; - /** - * Whether or not the post type can be viewed. - */ - viewable?: boolean; - /** - * Human-readable labels for the post type for various contexts. - */ - labels?: { - }; - /** - * The title for the post type. - */ - name?: string; - /** - * An alphanumeric identifier for the post type. - */ - slug?: string; - /** - * All features, supported by the post type. - */ - supports?: { - }; - /** - * Taxonomies associated with post type. - */ - taxonomies?: string[]; - /** - * REST base route for the post type. - */ - rest_base?: string; - /** - * REST route's namespace for the post type. - */ - rest_namespace?: string; - /** - * The visibility settings for the post type. - */ - visibility?: { - /** - * Whether to generate a default UI for managing this post type. - */ - show_ui?: boolean; - /** - * Whether to make the post type is available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - }; + /** + * All capabilities used by the post type. + */ + capabilities?: { + [ k: string ]: unknown; + }; + /** + * A human-readable description of the post type. + */ + description?: string; + /** + * Whether or not the post type should have children. + */ + hierarchical?: boolean; + /** + * Whether or not the post type can be viewed. + */ + viewable?: boolean; + /** + * Human-readable labels for the post type for various contexts. + */ + labels?: { + [ k: string ]: unknown; + }; + /** + * The title for the post type. + */ + name: string; + /** + * An alphanumeric identifier for the post type. + */ + slug: string; + /** + * All features, supported by the post type. + */ + supports?: { + [ k: string ]: unknown; + }; + /** + * Taxonomies associated with post type. + */ + taxonomies?: string[]; + /** + * REST base route for the post type. + */ + rest_base: string; + /** + * REST route's namespace for the post type. + */ + rest_namespace: string; + /** + * The visibility settings for the post type. + */ + visibility?: { + /** + * Whether to generate a default UI for managing this post type. + */ + show_ui?: boolean; + /** + * Whether to make the post type is available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + [ k: string ]: unknown; + }; } diff --git a/packages/core-data/src/types/types.ts b/packages/core-data/src/types/types.ts index 807fece931001..c5b7b25053341 100644 --- a/packages/core-data/src/types/types.ts +++ b/packages/core-data/src/types/types.ts @@ -1,4 +1,15 @@ -export interface Attachment { +interface RawField { + /** + * The data, as it exists in the database. + */ + raw?: string; + /** + * The data, transformed for display. + */ + rendered?: string; +} + +export interface Attachment< RawType > { /** * The date the post was published, in the site's timezone. */ @@ -10,16 +21,7 @@ export interface Attachment { /** * The globally unique identifier for the post. */ - guid?: { - /** - * GUID for the post, as it exists in the database. - */ - raw?: string; - /** - * GUID for the post, transformed for display. - */ - rendered?: string; - }; + guid?: RawType; /** * Unique identifier for the post. */ @@ -59,16 +61,7 @@ export interface Attachment { /** * The title for the post. */ - title?: { - /** - * Title for the post, as it exists in the database. - */ - raw?: string; - /** - * HTML title for the post, transformed for display. - */ - rendered?: string; - }; + title?: RawType; /** * The ID for the author of the post. */ @@ -96,29 +89,11 @@ export interface Attachment { /** * The attachment caption. */ - caption?: { - /** - * Caption for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML caption for the attachment, transformed for display. - */ - rendered?: string; - }; + caption?: RawType; /** * The attachment description. */ - description?: { - /** - * Description for the attachment, as it exists in the database. - */ - raw?: string; - /** - * HTML description for the attachment, transformed for display. - */ - rendered?: string; - }; + description?: RawType; /** * Attachment type. */ @@ -144,4 +119,3 @@ export interface Attachment { */ missing_image_sizes?: string[]; } - diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 993e54e3a2854..a29310198ebb8 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,94 +1,98 @@ export interface User { - /** - * Unique identifier for the user. - */ - id?: number; - /** - * Login name for the user. - */ - username?: string; - /** - * Display name for the user. - */ - name?: string; - /** - * First name for the user. - */ - first_name?: string; - /** - * Last name for the user. - */ - last_name?: string; - /** - * The email address for the user. - */ - email?: string; - /** - * URL of the user. - */ - url?: string; - /** - * Description of the user. - */ - description?: string; - /** - * Author URL of the user. - */ - link?: string; - /** - * Locale for the user. - */ - locale?: "" | "en_US"; - /** - * The nickname for the user. - */ - nickname?: string; - /** - * An alphanumeric identifier for the user. - */ - slug?: string; - /** - * Registration date for the user. - */ - registered_date?: string; - /** - * Roles assigned to the user. - */ - roles?: string[]; - /** - * Password for the user (never included). - */ - password?: string; - /** - * All capabilities assigned to the user. - */ - capabilities?: { - }; - /** - * Any extra capabilities assigned to the user. - */ - extra_capabilities?: { - }; - /** - * Avatar URLs for the user. - */ - avatar_urls?: { - /** - * Avatar URL with image size of 24 pixels. - */ - "24"?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - "48"?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - "96"?: string; - }; - /** - * Meta fields. - */ - meta?: { - }; + /** + * Unique identifier for the user. + */ + id: number; + /** + * Login name for the user. + */ + username?: string; + /** + * Display name for the user. + */ + name: string; + /** + * First name for the user. + */ + first_name?: string; + /** + * Last name for the user. + */ + last_name?: string; + /** + * The email address for the user. + */ + email?: string; + /** + * URL of the user. + */ + url: string; + /** + * Description of the user. + */ + description: string; + /** + * Author URL of the user. + */ + link: string; + /** + * Locale for the user. + */ + locale?: '' | 'en_US'; + /** + * The nickname for the user. + */ + nickname?: string; + /** + * An alphanumeric identifier for the user. + */ + slug: string; + /** + * Registration date for the user. + */ + registered_date?: string; + /** + * Roles assigned to the user. + */ + roles?: string[]; + /** + * Password for the user (never included). + */ + password?: string; + /** + * All capabilities assigned to the user. + */ + capabilities?: { + [ k: string ]: unknown; + }; + /** + * Any extra capabilities assigned to the user. + */ + extra_capabilities?: { + [ k: string ]: unknown; + }; + /** + * Avatar URLs for the user. + */ + avatar_urls: { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + [ k: string ]: unknown; + }; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: unknown; + }; } diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 3288bd9033235..204de87b185c9 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -1,22 +1,22 @@ export interface WidgetType { - /** - * Unique slug identifying the widget type. - */ - id?: string; - /** - * Human-readable name identifying the widget type. - */ - name?: string; - /** - * Description of the widget. - */ - description?: string; - /** - * Whether the widget supports multiple instances - */ - is_multi?: boolean; - /** - * Class name - */ - classname?: string; + /** + * Unique slug identifying the widget type. + */ + id: string; + /** + * Human-readable name identifying the widget type. + */ + name: string; + /** + * Description of the widget. + */ + description: string; + /** + * Whether the widget supports multiple instances + */ + is_multi: boolean; + /** + * Class name + */ + classname: string; } diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 42d2979a9dfc4..32b656ffb04cd 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,44 +1,46 @@ export interface Widget { - /** - * Unique identifier for the widget. - */ - id?: string; - /** - * The type of the widget. Corresponds to ID in widget-types endpoint. - */ - id_base?: string; - /** - * The sidebar the widget belongs to. - */ - sidebar?: string; - /** - * HTML representation of the widget. - */ - rendered?: string; - /** - * HTML representation of the widget admin form. - */ - rendered_form?: string; - /** - * Instance settings of the widget, if supported. - */ - instance?: { - /** - * Base64 encoded representation of the instance settings. - */ - encoded?: string; - /** - * Cryptographic hash of the instance settings. - */ - hash?: string; - /** - * Unencoded instance settings, if supported. - */ - raw?: { - }; - }; - /** - * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. - */ - form_data?: string; + /** + * Unique identifier for the widget. + */ + id: string; + /** + * The type of the widget. Corresponds to ID in widget-types endpoint. + */ + id_base: string; + /** + * The sidebar the widget belongs to. + */ + sidebar: string; + /** + * HTML representation of the widget. + */ + rendered: string; + /** + * HTML representation of the widget admin form. + */ + rendered_form?: string; + /** + * Instance settings of the widget, if supported. + */ + instance?: { + /** + * Base64 encoded representation of the instance settings. + */ + encoded?: string; + /** + * Cryptographic hash of the instance settings. + */ + hash?: string; + /** + * Unencoded instance settings, if supported. + */ + raw?: { + [ k: string ]: unknown; + }; + [ k: string ]: unknown; + }; + /** + * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. + */ + form_data?: string; } From 1300f775587ae9e430bdb745c3af8eb29cbc5337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 15:35:59 +0100 Subject: [PATCH 05/73] Extract enum types --- packages/core-data/src/types/attachment.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 9ba09ac983330..a7f524c6f0c05 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -1,3 +1,7 @@ +type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; +type PingStatus = 'open' | 'closed'; +type CommentsStatus = 'open' | 'closed'; +type MediaType = 'image' | 'file'; export interface Attachment { /** * The date the post was published, in the site's timezone. @@ -34,7 +38,7 @@ export interface Attachment { /** * A named status for the post. */ - status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; + status?: PostStatus; /** * Type of post. */ @@ -58,11 +62,11 @@ export interface Attachment { /** * Whether or not comments are open on the post. */ - comment_status?: 'open' | 'closed'; + comment_status?: CommentsStatus; /** * Whether or not the post can be pinged. */ - ping_status?: 'open' | 'closed'; + ping_status?: PingStatus; /** * Meta fields. */ @@ -88,7 +92,7 @@ export interface Attachment { /** * Attachment type. */ - media_type: 'image' | 'file'; + media_type: MediaType; /** * The attachment MIME type. */ From 60d1c915b802eca2fe8ad6cc4c11e224cd23142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 16:26:04 +0100 Subject: [PATCH 06/73] Extract common interfaces --- packages/core-data/src/types/attachment.ts | 31 +- packages/core-data/src/types/comment.ts | 23 +- packages/core-data/src/types/common.ts | 18 + packages/core-data/src/types/nav_menu.ts | 2 +- packages/core-data/src/types/nav_menu_item.ts | 21 +- packages/core-data/src/types/plugin.ts | 23 +- packages/core-data/src/types/settings.ts | 9 +- packages/core-data/src/types/sidebar.ts | 17 +- packages/core-data/src/types/taxonomy.ts | 59 ++-- packages/core-data/src/types/theme.ts | 329 +++++++++--------- packages/core-data/src/types/type.ts | 29 +- packages/core-data/src/types/types.ts | 121 ------- packages/core-data/src/types/user.ts | 38 +- packages/core-data/src/types/widget.ts | 35 +- 14 files changed, 305 insertions(+), 450 deletions(-) create mode 100644 packages/core-data/src/types/common.ts delete mode 100644 packages/core-data/src/types/types.ts diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index a7f524c6f0c05..2e3be622ffbc1 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -1,7 +1,10 @@ -type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; -type PingStatus = 'open' | 'closed'; -type CommentsStatus = 'open' | 'closed'; +/** + * Internal dependencies + */ +import { RawData, PostStatus, OpenOrClosed } from './common'; + type MediaType = 'image' | 'file'; + export interface Attachment { /** * The date the post was published, in the site's timezone. @@ -62,16 +65,16 @@ export interface Attachment { /** * Whether or not comments are open on the post. */ - comment_status?: CommentsStatus; + comment_status?: OpenOrClosed; /** * Whether or not the post can be pinged. */ - ping_status?: PingStatus; + ping_status?: OpenOrClosed; /** * Meta fields. */ meta?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * The theme file to use to display the post. @@ -101,7 +104,7 @@ export interface Attachment { * Details about the media file, specific to its type. */ media_details: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * The ID for the associated post of the attachment. @@ -116,17 +119,3 @@ export interface Attachment { */ missing_image_sizes?: string[]; } - -/** - * The raw data representation. - */ -export interface RawData { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered?: string; -} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index c98ebb067c9ba..576462adc5c8b 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { RawData } from './common'; + export interface Comment { /** * Unique identifier for the comment. @@ -75,26 +80,12 @@ export interface Comment { * Avatar URL with image size of 96 pixels. */ '96'?: string; - [ k: string ]: unknown; + [ k: string ]: string; }; /** * Meta fields. */ meta?: { - [ k: string ]: unknown; + [ k: string ]: string; }; } - -/** - * The raw data representation. - */ -export interface RawData { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered?: string; -} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts new file mode 100644 index 0000000000000..47fc2da3583e9 --- /dev/null +++ b/packages/core-data/src/types/common.ts @@ -0,0 +1,18 @@ +/** + * The raw data representation. + */ +export interface RawData { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered?: string; +} + +export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; + +export type OpenOrClosed = 'open' | 'closed'; +export type ActiveOrInactive = 'active' | 'inactive'; diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 79fae2aff09c4..6bcdef64961c2 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -19,7 +19,7 @@ export interface NavMenu { * Meta fields. */ meta?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * The locations assigned to the menu. diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 3b443b6da776f..fa0c06979c920 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { RawData, PostStatus } from './common'; + export interface NavMenuItem { /** * The title for the object. @@ -71,20 +76,6 @@ export interface NavMenuItem { * Meta fields. */ meta?: { - [ k: string ]: unknown; + [ k: string ]: string; }; } - -/** - * The raw data representation. - */ -export interface RawData { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered?: string; -} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 1a2130f4ffdf0..f5b8656ff9fb3 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { ActiveOrInactive, RawData } from './common'; + export interface Plugin { /** * The plugin file. @@ -6,7 +11,7 @@ export interface Plugin { /** * The plugin activation status. */ - status: 'inactive' | 'active'; + status: ActiveOrInactive; /** * The plugin name. */ @@ -19,7 +24,7 @@ export interface Plugin { * The plugin author. */ author?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * Plugin author's website address. @@ -50,17 +55,3 @@ export interface Plugin { */ textdomain?: string; } - -/** - * The raw data representation. - */ -export interface RawData { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered?: string; -} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 263647e85885c..dc2c2155476e2 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { OpenOrClosed } from './common'; + export interface Settings { /** * What to show on the front page @@ -62,11 +67,11 @@ export interface Settings { /** * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. */ - default_ping_status?: 'open' | 'closed'; + default_ping_status?: OpenOrClosed; /** * Allow people to submit comments on new posts. */ - default_comment_status?: 'open' | 'closed'; + default_comment_status?: OpenOrClosed; /** * Site logo. */ diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index f4e00bc3b6b7a..ec145e9a86219 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -1,3 +1,9 @@ +/** + * Internal dependencies + */ +import { Widget } from './widget'; +import { ActiveOrInactive } from "./common"; + export interface Sidebar { /** * ID of sidebar. @@ -34,14 +40,11 @@ export interface Sidebar { /** * Status of sidebar. */ - status: 'active' | 'inactive'; + status: ActiveOrInactive; /** * Nested widgets. */ - widgets: ( - | { - [ k: string ]: unknown; - } - | string - )[]; + widgets: NestedWidget[]; } + +type NestedWidget = Widget | string; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 6bca7dafe174b..039bc71a76513 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -3,7 +3,7 @@ export interface Taxonomy { * All capabilities used by the taxonomy. */ capabilities?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * A human-readable description of the taxonomy. @@ -17,7 +17,7 @@ export interface Taxonomy { * Human-readable labels for the taxonomy for various contexts. */ labels?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * The title for the taxonomy. @@ -46,31 +46,32 @@ export interface Taxonomy { /** * The visibility settings for the taxonomy. */ - visibility?: { - /** - * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. - */ - public?: boolean; - /** - * Whether the taxonomy is publicly queryable. - */ - publicly_queryable?: boolean; - /** - * Whether to generate a default UI for managing this taxonomy. - */ - show_ui?: boolean; - /** - * Whether to allow automatic creation of taxonomy columns on associated post-types table. - */ - show_admin_column?: boolean; - /** - * Whether to make the taxonomy available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - /** - * Whether to show the taxonomy in the quick/bulk edit panel. - */ - show_in_quick_edit?: boolean; - [ k: string ]: unknown; - }; + visibility?: Visibility; +} + +interface Visibility { + /** + * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. + */ + public?: boolean; + /** + * Whether the taxonomy is publicly queryable. + */ + publicly_queryable?: boolean; + /** + * Whether to generate a default UI for managing this taxonomy. + */ + show_ui?: boolean; + /** + * Whether to allow automatic creation of taxonomy columns on associated post-types table. + */ + show_admin_column?: boolean; + /** + * Whether to make the taxonomy available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; + /** + * Whether to show the taxonomy in the quick/bulk edit panel. + */ + show_in_quick_edit?: boolean; } diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 86e89dcd3b19e..351ba8cd07cb3 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { RawData, ActiveOrInactive } from './common'; + export interface Theme { /** * The theme's stylesheet. This uniquely identifies the theme. @@ -46,170 +51,7 @@ export interface Theme { /** * Features supported by this theme. */ - theme_supports?: { - /** - * Whether theme opts in to wide alignment CSS class. - */ - 'align-wide'?: boolean; - /** - * Whether posts and comments RSS feed links are added to head. - */ - 'automatic-feed-links'?: boolean; - /** - * Custom background if defined by the theme. - */ - 'custom-background'?: - | boolean - | { - 'default-image'?: string; - 'default-preset'?: - | 'default' - | 'fill' - | 'fit' - | 'repeat' - | 'custom'; - 'default-position-x'?: 'left' | 'center' | 'right'; - 'default-position-y'?: 'left' | 'center' | 'right'; - 'default-size'?: 'auto' | 'contain' | 'cover'; - 'default-repeat'?: - | 'repeat-x' - | 'repeat-y' - | 'repeat' - | 'no-repeat'; - 'default-attachment'?: 'scroll' | 'fixed'; - 'default-color'?: string; - }; - /** - * Custom header if defined by the theme. - */ - 'custom-header'?: - | boolean - | { - 'default-image'?: string; - 'random-default'?: boolean; - width?: number; - height?: number; - 'flex-height'?: boolean; - 'flex-width'?: boolean; - 'default-text-color'?: string; - 'header-text'?: boolean; - uploads?: boolean; - video?: boolean; - }; - /** - * Custom logo if defined by the theme. - */ - 'custom-logo'?: - | boolean - | { - width?: number; - height?: number; - 'flex-width'?: boolean; - 'flex-height'?: boolean; - 'header-text'?: string[]; - 'unlink-homepage-logo'?: boolean; - }; - /** - * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. - */ - 'customize-selective-refresh-widgets'?: boolean; - /** - * Whether theme opts in to the dark editor style UI. - */ - 'dark-editor-style'?: boolean; - /** - * Whether the theme disables custom colors. - */ - 'disable-custom-colors'?: boolean; - /** - * Whether the theme disables custom font sizes. - */ - 'disable-custom-font-sizes'?: boolean; - /** - * Whether the theme disables custom gradients. - */ - 'disable-custom-gradients'?: boolean; - /** - * Custom color palette if defined by the theme. - */ - 'editor-color-palette'?: - | boolean - | { - name?: string; - slug?: string; - color?: string; - }[]; - /** - * Custom font sizes if defined by the theme. - */ - 'editor-font-sizes'?: - | boolean - | { - name?: string; - size?: number; - slug?: string; - }[]; - /** - * Custom gradient presets if defined by the theme. - */ - 'editor-gradient-presets'?: - | boolean - | { - name?: string; - gradient?: string; - slug?: string; - }[]; - /** - * Whether theme opts in to the editor styles CSS wrapper. - */ - 'editor-styles'?: boolean; - /** - * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. - */ - html5?: - | boolean - | ( - | 'search-form' - | 'comment-form' - | 'comment-list' - | 'gallery' - | 'caption' - | 'script' - | 'style' - )[]; - /** - * Post formats supported. - */ - formats?: ( - | 'standard' - | 'aside' - | 'chat' - | 'gallery' - | 'link' - | 'image' - | 'quote' - | 'status' - | 'video' - | 'audio' - )[]; - /** - * The post types that support thumbnails or true if all post types are supported. - */ - 'post-thumbnails'?: boolean | string[]; - /** - * Whether the theme supports responsive embedded content. - */ - 'responsive-embeds'?: boolean; - /** - * Whether the theme can manage the document title tag. - */ - 'title-tag'?: boolean; - /** - * Whether theme opts in to default WordPress block styles for viewing. - */ - 'wp-block-styles'?: boolean; - [ k: string ]: unknown; - }; + theme_supports?: ThemeSupports; /** * The URI of the theme's webpage. */ @@ -221,19 +63,160 @@ export interface Theme { /** * A named status for the theme. */ - status?: 'inactive' | 'active'; + status?: ActiveOrInactive; } -/** - * The raw data representation. - */ -export interface RawData { +interface ThemeSupports { + /** + * Whether theme opts in to wide alignment CSS class. + */ + 'align-wide'?: boolean; + /** + * Whether posts and comments RSS feed links are added to head. + */ + 'automatic-feed-links'?: boolean; + /** + * Custom background if defined by the theme. + */ + 'custom-background'?: boolean | CustomBackground; + /** + * Custom header if defined by the theme. + */ + 'custom-header'?: boolean | CustomHeader; + /** + * Custom logo if defined by the theme. + */ + 'custom-logo'?: boolean | CustomLogo; + /** + * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. + */ + 'customize-selective-refresh-widgets'?: boolean; + /** + * Whether theme opts in to the dark editor style UI. + */ + 'dark-editor-style'?: boolean; + /** + * Whether the theme disables custom colors. + */ + 'disable-custom-colors'?: boolean; + /** + * Whether the theme disables custom font sizes. + */ + 'disable-custom-font-sizes'?: boolean; + /** + * Whether the theme disables custom gradients. + */ + 'disable-custom-gradients'?: boolean; /** - * Data as it exists in the database. + * Custom color palette if defined by the theme. */ - raw?: string; + 'editor-color-palette'?: boolean | Color[]; /** - * Data transformed for display. + * Custom font sizes if defined by the theme. */ - rendered?: string; + 'editor-font-sizes'?: boolean | FontSize[]; + /** + * Custom gradient presets if defined by the theme. + */ + 'editor-gradient-presets'?: boolean | GradientPreset[]; + /** + * Whether theme opts in to the editor styles CSS wrapper. + */ + 'editor-styles'?: boolean; + /** + * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. + */ + html5?: boolean | Html5Option[]; + /** + * Post formats supported. + */ + formats?: PostFormat[]; + /** + * The post types that support thumbnails or true if all post types are supported. + */ + 'post-thumbnails'?: boolean | string[]; + /** + * Whether the theme supports responsive embedded content. + */ + 'responsive-embeds'?: boolean; + /** + * Whether the theme can manage the document title tag. + */ + 'title-tag'?: boolean; + /** + * Whether theme opts in to default WordPress block styles for viewing. + */ + 'wp-block-styles'?: boolean; } + +type PostFormat = + | 'standard' + | 'aside' + | 'chat' + | 'gallery' + | 'link' + | 'image' + | 'quote' + | 'status' + | 'video' + | 'audio'; + +type CustomBackground = { + 'default-image'?: string; + 'default-preset'?: 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; + 'default-position-x'?: 'left' | 'center' | 'right'; + 'default-position-y'?: 'left' | 'center' | 'right'; + 'default-size'?: 'auto' | 'contain' | 'cover'; + 'default-repeat'?: 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; + 'default-attachment'?: 'scroll' | 'fixed'; + 'default-color'?: string; +}; + +type CustomHeader = { + 'default-image'?: string; + 'random-default'?: boolean; + width?: number; + height?: number; + 'flex-height'?: boolean; + 'flex-width'?: boolean; + 'default-text-color'?: string; + 'header-text'?: boolean; + uploads?: boolean; + video?: boolean; +}; + +type CustomLogo = { + width?: number; + height?: number; + 'flex-width'?: boolean; + 'flex-height'?: boolean; + 'header-text'?: string[]; + 'unlink-homepage-logo'?: boolean; +}; + +type Color = { + name?: string; + slug?: string; + color?: string; +}; + +type FontSize = { + name?: string; + size?: number; + slug?: string; +}; + +type GradientPreset = { + name?: string; + gradient?: string; + slug?: string; +}; + +type Html5Option = + | 'search-form' + | 'comment-form' + | 'comment-list' + | 'gallery' + | 'caption' + | 'script' + | 'style'; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 3e8983236e96c..b7c3e31173c64 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,7 +3,7 @@ export interface Type { * All capabilities used by the post type. */ capabilities?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * A human-readable description of the post type. @@ -21,7 +21,7 @@ export interface Type { * Human-readable labels for the post type for various contexts. */ labels?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * The title for the post type. @@ -35,7 +35,7 @@ export interface Type { * All features, supported by the post type. */ supports?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * Taxonomies associated with post type. @@ -52,15 +52,16 @@ export interface Type { /** * The visibility settings for the post type. */ - visibility?: { - /** - * Whether to generate a default UI for managing this post type. - */ - show_ui?: boolean; - /** - * Whether to make the post type is available for selection in navigation menus. - */ - show_in_nav_menus?: boolean; - [ k: string ]: unknown; - }; + visibility?: Visibility; +} + +interface Visibility { + /** + * Whether to generate a default UI for managing this post type. + */ + show_ui?: boolean; + /** + * Whether to make the post type is available for selection in navigation menus. + */ + show_in_nav_menus?: boolean; } diff --git a/packages/core-data/src/types/types.ts b/packages/core-data/src/types/types.ts deleted file mode 100644 index c5b7b25053341..0000000000000 --- a/packages/core-data/src/types/types.ts +++ /dev/null @@ -1,121 +0,0 @@ -interface RawField { - /** - * The data, as it exists in the database. - */ - raw?: string; - /** - * The data, transformed for display. - */ - rendered?: string; -} - -export interface Attachment< RawType > { - /** - * The date the post was published, in the site's timezone. - */ - date?: string | null; - /** - * The date the post was published, as GMT. - */ - date_gmt?: string | null; - /** - * The globally unique identifier for the post. - */ - guid?: RawType; - /** - * Unique identifier for the post. - */ - id?: number; - /** - * URL to the post. - */ - link?: string; - /** - * The date the post was last modified, in the site's timezone. - */ - modified?: string; - /** - * The date the post was last modified, as GMT. - */ - modified_gmt?: string; - /** - * An alphanumeric identifier for the post unique to its type. - */ - slug?: string; - /** - * A named status for the post. - */ - status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; - /** - * Type of post. - */ - type?: string; - /** - * Permalink template for the post. - */ - permalink_template?: string; - /** - * Slug automatically generated from the post title. - */ - generated_slug?: string; - /** - * The title for the post. - */ - title?: RawType; - /** - * The ID for the author of the post. - */ - author?: number; - /** - * Whether or not comments are open on the post. - */ - comment_status?: 'open' | 'closed'; - /** - * Whether or not the post can be pinged. - */ - ping_status?: 'open' | 'closed'; - /** - * Meta fields. - */ - meta?: {}; - /** - * The theme file to use to display the post. - */ - template?: string; - /** - * Alternative text to display when attachment is not displayed. - */ - alt_text?: string; - /** - * The attachment caption. - */ - caption?: RawType; - /** - * The attachment description. - */ - description?: RawType; - /** - * Attachment type. - */ - media_type?: 'image' | 'file'; - /** - * The attachment MIME type. - */ - mime_type?: string; - /** - * Details about the media file, specific to its type. - */ - media_details?: {}; - /** - * The ID for the associated post of the attachment. - */ - post?: number; - /** - * URL to the original attachment file. - */ - source_url?: string; - /** - * List of the missing image sizes of the attachment. - */ - missing_image_sizes?: string[]; -} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index a29310198ebb8..3a7863ea8616a 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -63,36 +63,38 @@ export interface User { * All capabilities assigned to the user. */ capabilities?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * Any extra capabilities assigned to the user. */ extra_capabilities?: { - [ k: string ]: unknown; + [ k: string ]: string; }; /** * Avatar URLs for the user. */ - avatar_urls: { - /** - * Avatar URL with image size of 24 pixels. - */ - '24'?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - '48'?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - '96'?: string; - [ k: string ]: unknown; - }; + avatar_urls: AvatarUrls; /** * Meta fields. */ meta?: { - [ k: string ]: unknown; + [ k: string ]: string; }; } + +interface AvatarUrls { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + [ k: string ]: string; +} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 32b656ffb04cd..42d8da91ffe64 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -22,25 +22,26 @@ export interface Widget { /** * Instance settings of the widget, if supported. */ - instance?: { - /** - * Base64 encoded representation of the instance settings. - */ - encoded?: string; - /** - * Cryptographic hash of the instance settings. - */ - hash?: string; - /** - * Unencoded instance settings, if supported. - */ - raw?: { - [ k: string ]: unknown; - }; - [ k: string ]: unknown; - }; + instance?: WidgetInstance; /** * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. */ form_data?: string; } + +interface WidgetInstance { + /** + * Base64 encoded representation of the instance settings. + */ + encoded?: string; + /** + * Cryptographic hash of the instance settings. + */ + hash?: string; + /** + * Unencoded instance settings, if supported. + */ + raw?: { + [ k: string ]: string; + }; +} From 9cb67ca8e0f5139c0d27bf0728a62878195543c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 16:30:50 +0100 Subject: [PATCH 07/73] Add type definitions for posts and template parts --- packages/core-data/src/types/common.ts | 13 ++ packages/core-data/src/types/page.ts | 105 +++++++++++++++ packages/core-data/src/types/post.ts | 125 ++++++++++++++++++ packages/core-data/src/types/sidebar.ts | 2 +- packages/core-data/src/types/user.ts | 1 + packages/core-data/src/types/wp_template.ts | 67 ++++++++++ .../core-data/src/types/wp_template_part.ts | 65 +++++++++ 7 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 packages/core-data/src/types/page.ts create mode 100644 packages/core-data/src/types/post.ts create mode 100644 packages/core-data/src/types/wp_template.ts create mode 100644 packages/core-data/src/types/wp_template_part.ts diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 47fc2da3583e9..808cbd3899cac 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -16,3 +16,16 @@ export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; export type OpenOrClosed = 'open' | 'closed'; export type ActiveOrInactive = 'active' | 'inactive'; + +export type TemplateContent = + | { + /** + * Content for the template, as it exists in the database. + */ + raw?: string; + /** + * Version of the content block format used by the template. + */ + block_version?: number; + } + | string; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts new file mode 100644 index 0000000000000..8920c7c8d8bc3 --- /dev/null +++ b/packages/core-data/src/types/page.ts @@ -0,0 +1,105 @@ +/** + * Internal dependencies + */ +import { OpenOrClosed, PostStatus, RawData } from './common'; + +export interface Page { + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt?: string | null; + /** + * The globally unique identifier for the post. + */ + guid?: RawData; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified?: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt?: string; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status?: PostStatus; + /** + * Type of post. + */ + type: string; + /** + * A password to protect access to the content and excerpt. + */ + password?: string; + /** + * Permalink template for the post. + */ + permalink_template?: string; + /** + * Slug automatically generated from the post title. + */ + generated_slug?: string; + /** + * The ID for the parent of the post. + */ + parent?: number; + /** + * The title for the post. + */ + title: RawData; + /** + * The content for the post. + */ + content?: RawData; + /** + * The ID for the author of the post. + */ + author: number; + /** + * The excerpt for the post. + */ + excerpt: RawData; + /** + * The ID of the featured media for the post. + */ + featured_media: number; + /** + * Whether or not comments are open on the post. + */ + comment_status?: OpenOrClosed; + /** + * Whether or not the post can be pinged. + */ + ping_status?: OpenOrClosed; + /** + * The order of the post in relation to other posts. + */ + menu_order?: number; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: string; + }; + /** + * The theme file to use to display the post. + */ + template?: string; +} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts new file mode 100644 index 0000000000000..eddf7049fe8f4 --- /dev/null +++ b/packages/core-data/src/types/post.ts @@ -0,0 +1,125 @@ +/** + * Internal dependencies + */ +import { OpenOrClosed, PostStatus, RawData } from './common'; + +export interface Post { + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt?: string | null; + /** + * The globally unique identifier for the post. + */ + guid?: RawData; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified?: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt?: string; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status?: PostStatus; + /** + * Type of post. + */ + type: string; + /** + * A password to protect access to the content and excerpt. + */ + password?: string; + /** + * Permalink template for the post. + */ + permalink_template?: string; + /** + * Slug automatically generated from the post title. + */ + generated_slug?: string; + /** + * The title for the post. + */ + title: RawData; + /** + * The content for the post. + */ + content?: RawData; + /** + * The ID for the author of the post. + */ + author: number; + /** + * The excerpt for the post. + */ + excerpt: RawData; + /** + * The ID of the featured media for the post. + */ + featured_media: number; + /** + * Whether or not comments are open on the post. + */ + comment_status?: OpenOrClosed; + /** + * Whether or not the post can be pinged. + */ + ping_status?: OpenOrClosed; + /** + * The format for the post. + */ + format?: PostFormat; + /** + * Meta fields. + */ + meta?: { + [ k: string ]: string; + }; + /** + * Whether or not the post should be treated as sticky. + */ + sticky?: boolean; + /** + * The theme file to use to display the post. + */ + template?: string; + /** + * The terms assigned to the post in the category taxonomy. + */ + categories?: number[]; + /** + * The terms assigned to the post in the post_tag taxonomy. + */ + tags?: number[]; +} + +type PostFormat = + | 'standard' + | 'aside' + | 'chat' + | 'gallery' + | 'link' + | 'image' + | 'quote' + | 'status' + | 'video' + | 'audio'; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index ec145e9a86219..cb17fa0f3deca 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { Widget } from './widget'; -import { ActiveOrInactive } from "./common"; +import { ActiveOrInactive } from './common'; export interface Sidebar { /** diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 3a7863ea8616a..b0452dff295c6 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -96,5 +96,6 @@ interface AvatarUrls { * Avatar URL with image size of 96 pixels. */ '96'?: string; + [ k: string ]: string; } diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts new file mode 100644 index 0000000000000..dd6f4ce0cd0fc --- /dev/null +++ b/packages/core-data/src/types/wp_template.ts @@ -0,0 +1,67 @@ +/** + * Internal dependencies + */ +import { PostStatus, RawData, TemplateContent } from './common'; + +export interface WpTemplate { + /** + * ID of template. + */ + id: string; + /** + * Unique slug identifying the template. + */ + slug: string; + /** + * Theme identifier for the template. + */ + theme: string; + /** + * Type of template. + */ + type: string; + /** + * Source of template + */ + source: string; + /** + * Source of a customized template + */ + origin: string; + /** + * Content of template. + */ + content: TemplateContent; + /** + * Title of template. + */ + title: RawData; + /** + * Description of template. + */ + description: string; + /** + * Status of template. + */ + status: PostStatus; + /** + * Post ID. + */ + wp_id: number; + /** + * Theme file exists. + */ + has_theme_file: { + [ k: string ]: string; + }; + /** + * The ID for the author of the template. + */ + author: number; + /** + * Whether a template is a custom template. + */ + is_custom: { + [ k: string ]: string; + }; +} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts new file mode 100644 index 0000000000000..5e8ee202cc456 --- /dev/null +++ b/packages/core-data/src/types/wp_template_part.ts @@ -0,0 +1,65 @@ +/** + * Internal dependencies + */ +import { PostStatus, RawData, TemplateContent } from './common'; + +export interface WpTemplatePart { + /** + * ID of template. + */ + id: string; + /** + * Unique slug identifying the template. + */ + slug: string; + /** + * Theme identifier for the template. + */ + theme: string; + /** + * Type of template. + */ + type: string; + /** + * Source of template + */ + source: string; + /** + * Source of a customized template + */ + origin: string; + /** + * Content of template. + */ + content: TemplateContent; + /** + * Title of template. + */ + title: RawData; + /** + * Description of template. + */ + description: string; + /** + * Status of template. + */ + status: PostStatus; + /** + * Post ID. + */ + wp_id: number; + /** + * Theme file exists. + */ + has_theme_file: { + [ k: string ]: string; + }; + /** + * The ID for the author of the template. + */ + author: number; + /** + * Where the template part is intended for use (header, footer, etc.) + */ + area: string; +} From 08081f72e78f78c7dadd6f17621f27278b88723c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 16:53:01 +0100 Subject: [PATCH 08/73] Add Raw Data typings --- packages/core-data/src/types/attachment.ts | 12 ++++++------ packages/core-data/src/types/comment.ts | 6 +++--- packages/core-data/src/types/common.ts | 9 ++++++++- packages/core-data/src/types/nav_menu_item.ts | 3 +-- packages/core-data/src/types/page.ts | 12 ++++++------ packages/core-data/src/types/plugin.ts | 6 +++--- packages/core-data/src/types/post.ts | 12 ++++++------ packages/core-data/src/types/theme.ts | 16 ++++++++-------- packages/core-data/src/types/wp_template.ts | 6 +++--- packages/core-data/src/types/wp_template_part.ts | 6 +++--- 10 files changed, 47 insertions(+), 41 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 2e3be622ffbc1..ad412b8e4cb93 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -1,11 +1,11 @@ /** * Internal dependencies */ -import { RawData, PostStatus, OpenOrClosed } from './common'; +import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; type MediaType = 'image' | 'file'; -export interface Attachment { +export interface Attachment< RawType > extends EntityRecordWithRawData { /** * The date the post was published, in the site's timezone. */ @@ -17,7 +17,7 @@ export interface Attachment { /** * The globally unique identifier for the post. */ - guid?: RawData; + guid?: RawType; /** * Unique identifier for the post. */ @@ -57,7 +57,7 @@ export interface Attachment { /** * The title for the post. */ - title: RawData; + title: RawType; /** * The ID for the author of the post. */ @@ -87,11 +87,11 @@ export interface Attachment { /** * The attachment caption. */ - caption: RawData; + caption: RawType; /** * The attachment description. */ - description?: RawData; + description?: RawType; /** * Attachment type. */ diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 576462adc5c8b..3a3f5119ea650 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { RawData } from './common'; +import { EntityRecordWithRawData } from './common'; -export interface Comment { +export interface Comment< RawType > extends EntityRecordWithRawData { /** * Unique identifier for the comment. */ @@ -35,7 +35,7 @@ export interface Comment { /** * The content for the comment. */ - content: RawData; + content: RawType; /** * The date the comment was published, in the site's timezone. */ diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 808cbd3899cac..8f98d5e894563 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -1,7 +1,7 @@ /** * The raw data representation. */ -export interface RawData { +export interface RawObject { /** * Data as it exists in the database. */ @@ -12,6 +12,9 @@ export interface RawData { rendered?: string; } +export type RawString = string; +export type RawData = RawObject | RawString; + export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; export type OpenOrClosed = 'open' | 'closed'; @@ -29,3 +32,7 @@ export type TemplateContent = block_version?: number; } | string; + +export interface EntityRecordWithRawData< + RawType extends RawData = RawObject +> {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index fa0c06979c920..31f53d2c1ca66 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,13 +1,12 @@ /** * Internal dependencies */ -import { RawData, PostStatus } from './common'; export interface NavMenuItem { /** * The title for the object. */ - title: RawData; + title: RawType; /** * Unique identifier for the object. */ diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 8920c7c8d8bc3..01449770ed546 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { OpenOrClosed, PostStatus, RawData } from './common'; +import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; -export interface Page { +export interface Page< RawType > extends EntityRecordWithRawData { /** * The date the post was published, in the site's timezone. */ @@ -15,7 +15,7 @@ export interface Page { /** * The globally unique identifier for the post. */ - guid?: RawData; + guid?: RawType; /** * Unique identifier for the post. */ @@ -63,11 +63,11 @@ export interface Page { /** * The title for the post. */ - title: RawData; + title: RawType; /** * The content for the post. */ - content?: RawData; + content?: RawType; /** * The ID for the author of the post. */ @@ -75,7 +75,7 @@ export interface Page { /** * The excerpt for the post. */ - excerpt: RawData; + excerpt: RawType; /** * The ID of the featured media for the post. */ diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index f5b8656ff9fb3..b45df94b10f72 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { ActiveOrInactive, RawData } from './common'; +import { ActiveOrInactive, EntityRecordWithRawData } from './common'; -export interface Plugin { +export interface Plugin< RawType > extends EntityRecordWithRawData { /** * The plugin file. */ @@ -33,7 +33,7 @@ export interface Plugin { /** * The plugin description. */ - description?: RawData; + description?: RawType; /** * The plugin version number. */ diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index eddf7049fe8f4..db2cc949a160b 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { OpenOrClosed, PostStatus, RawData } from './common'; +import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; -export interface Post { +export interface Post< RawType > extends EntityRecordWithRawData { /** * The date the post was published, in the site's timezone. */ @@ -15,7 +15,7 @@ export interface Post { /** * The globally unique identifier for the post. */ - guid?: RawData; + guid?: RawType; /** * Unique identifier for the post. */ @@ -59,11 +59,11 @@ export interface Post { /** * The title for the post. */ - title: RawData; + title: RawType; /** * The content for the post. */ - content?: RawData; + content?: RawType; /** * The ID for the author of the post. */ @@ -71,7 +71,7 @@ export interface Post { /** * The excerpt for the post. */ - excerpt: RawData; + excerpt: RawType; /** * The ID of the featured media for the post. */ diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 351ba8cd07cb3..0882bcae5d7d9 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { RawData, ActiveOrInactive } from './common'; +import { ActiveOrInactive, EntityRecordWithRawData } from './common'; -export interface Theme { +export interface Theme< RawType > extends EntityRecordWithRawData { /** * The theme's stylesheet. This uniquely identifies the theme. */ @@ -15,19 +15,19 @@ export interface Theme { /** * The theme author. */ - author?: RawData; + author?: RawType; /** * The website of the theme author. */ - author_uri?: RawData; + author_uri?: RawType; /** * A description of the theme. */ - description?: RawData; + description?: RawType; /** * The name of the theme. */ - name?: RawData; + name?: RawType; /** * The minimum PHP version required for the theme to work. */ @@ -43,7 +43,7 @@ export interface Theme { /** * Tags indicating styles and features of the theme. */ - tags?: RawData; + tags?: RawType; /** * The theme's text domain. */ @@ -55,7 +55,7 @@ export interface Theme { /** * The URI of the theme's webpage. */ - theme_uri?: RawData; + theme_uri?: RawType; /** * The theme's current version. */ diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index dd6f4ce0cd0fc..569e7f14d5cb9 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { PostStatus, RawData, TemplateContent } from './common'; +import { EntityRecordWithRawData, PostStatus, TemplateContent } from './common'; -export interface WpTemplate { +export interface WpTemplate< RawType > extends EntityRecordWithRawData { /** * ID of template. */ @@ -35,7 +35,7 @@ export interface WpTemplate { /** * Title of template. */ - title: RawData; + title: RawType; /** * Description of template. */ diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 5e8ee202cc456..90bb7560b66a2 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { PostStatus, RawData, TemplateContent } from './common'; +import { EntityRecordWithRawData, PostStatus, TemplateContent } from './common'; -export interface WpTemplatePart { +export interface WpTemplatePart< RawType > extends EntityRecordWithRawData { /** * ID of template. */ @@ -35,7 +35,7 @@ export interface WpTemplatePart { /** * Title of template. */ - title: RawData; + title: RawType; /** * Description of template. */ From cd9b910bd8466e80a3f0647494b8c4e1bd48e285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 16:57:43 +0100 Subject: [PATCH 09/73] Extract AvatarUrls to common.js --- packages/core-data/src/types/comment.ts | 18 ++---------------- packages/core-data/src/types/common.ts | 17 +++++++++++++++++ packages/core-data/src/types/user.ts | 22 +++++----------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 3a3f5119ea650..c0db2063f6c86 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData } from './common'; +import { AvatarUrls, EntityRecordWithRawData } from './common'; export interface Comment< RawType > extends EntityRecordWithRawData { /** @@ -67,21 +67,7 @@ export interface Comment< RawType > extends EntityRecordWithRawData { /** * Avatar URLs for the comment author. */ - author_avatar_urls: { - /** - * Avatar URL with image size of 24 pixels. - */ - '24'?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - '48'?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - '96'?: string; - [ k: string ]: string; - }; + author_avatar_urls: AvatarUrls; /** * Meta fields. */ diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 8f98d5e894563..55e201d88c0e1 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -36,3 +36,20 @@ export type TemplateContent = export interface EntityRecordWithRawData< RawType extends RawData = RawObject > {} + +export interface AvatarUrls { + /** + * Avatar URL with image size of 24 pixels. + */ + '24'?: string; + /** + * Avatar URL with image size of 48 pixels. + */ + '48'?: string; + /** + * Avatar URL with image size of 96 pixels. + */ + '96'?: string; + + [ k: string ]: string; +} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index b0452dff295c6..9df2fb1114fdd 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { AvatarUrls } from './common'; + export interface User { /** * Unique identifier for the user. @@ -82,20 +87,3 @@ export interface User { [ k: string ]: string; }; } - -interface AvatarUrls { - /** - * Avatar URL with image size of 24 pixels. - */ - '24'?: string; - /** - * Avatar URL with image size of 48 pixels. - */ - '48'?: string; - /** - * Avatar URL with image size of 96 pixels. - */ - '96'?: string; - - [ k: string ]: string; -} From 2449089dd68105dec37820ba3943c6d3486c4f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Feb 2022 17:18:35 +0100 Subject: [PATCH 10/73] Try context-based entity types --- packages/core-data/src/types/attachment.ts | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index ad412b8e4cb93..5eea65479772d 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -1,7 +1,11 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; +import { + EntityRecordWithRawData, + OpenOrClosed, + PostStatus, +} from './common'; type MediaType = 'image' | 'file'; @@ -119,3 +123,21 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { */ missing_image_sizes?: string[]; } + +/* +type ViewContext = 'ViewContext'; +type EditContext = 'EditContext'; +type EmbedContext = 'EmbedContext'; +type EntityContext = ViewContext | EditContext | EmbedContext; + +type ViewProperties = 'date' | 'date_gmt'; +type EditProperties = 'date' | 'id'; + +export type Attachment< + Context extends EntityContext = EditContext, + RawType = RawObject +> = Pick< + BaseAttachment< RawType >, + Context extends ViewContext ? ViewProperties : EditProperties +>; +*/ From 5f35431c395537631ab7b05b18476378f8598915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 11 Feb 2022 16:18:58 +0100 Subject: [PATCH 11/73] Experimenting with different ways of contextualizing data types --- packages/core-data/src/types/attachment.ts | 136 +++++++++++++++++---- packages/core-data/src/types/common.ts | 69 +++++++++-- packages/core-data/src/types/post.ts | 95 ++++++++++---- 3 files changed, 242 insertions(+), 58 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 5eea65479772d..f0d915b461d0f 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -2,14 +2,18 @@ * Internal dependencies */ import { + EntityInContext, + EntityContext, EntityRecordWithRawData, OpenOrClosed, PostStatus, + RawObject, + RawString, } from './common'; type MediaType = 'image' | 'file'; -export interface Attachment< RawType > extends EntityRecordWithRawData { +export interface BaseAttachment< RawType > extends EntityRecordWithRawData { /** * The date the post was published, in the site's timezone. */ @@ -17,11 +21,11 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * The date the post was published, as GMT. */ - date_gmt?: string | null; + date_gmt: string | null; /** * The globally unique identifier for the post. */ - guid?: RawType; + guid: RawType; /** * Unique identifier for the post. */ @@ -33,11 +37,11 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * The date the post was last modified, in the site's timezone. */ - modified?: string; + modified: string; /** * The date the post was last modified, as GMT. */ - modified_gmt?: string; + modified_gmt: string; /** * An alphanumeric identifier for the post unique to its type. */ @@ -45,7 +49,7 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * A named status for the post. */ - status?: PostStatus; + status: PostStatus; /** * Type of post. */ @@ -53,11 +57,11 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * Permalink template for the post. */ - permalink_template?: string; + permalink_template: string; /** * Slug automatically generated from the post title. */ - generated_slug?: string; + generated_slug: string; /** * The title for the post. */ @@ -69,21 +73,21 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * Whether or not comments are open on the post. */ - comment_status?: OpenOrClosed; + comment_status: OpenOrClosed; /** * Whether or not the post can be pinged. */ - ping_status?: OpenOrClosed; + ping_status: OpenOrClosed; /** * Meta fields. */ - meta?: { + meta: { [ k: string ]: string; }; /** * The theme file to use to display the post. */ - template?: string; + template: string; /** * Alternative text to display when attachment is not displayed. */ @@ -95,7 +99,7 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * The attachment description. */ - description?: RawType; + description: RawType; /** * Attachment type. */ @@ -113,7 +117,7 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * The ID for the associated post of the attachment. */ - post?: number; + post: number; /** * URL to the original attachment file. */ @@ -121,23 +125,101 @@ export interface Attachment< RawType > extends EntityRecordWithRawData { /** * List of the missing image sizes of the attachment. */ - missing_image_sizes?: string[]; + missing_image_sizes: string[]; } -/* -type ViewContext = 'ViewContext'; -type EditContext = 'EditContext'; -type EmbedContext = 'EmbedContext'; -type EntityContext = ViewContext | EditContext | EmbedContext; +type ViewProperties = + | 'date' + | 'date_gmt' + | 'guid' + | 'id' + | 'link' + | 'modified' + | 'modified_gmt' + | 'slug' + | 'status' + | 'type' + | 'title' + | 'author' + | 'comment_status' + | 'ping_status' + | 'meta' + | 'template' + | 'alt_text' + | 'caption' + | 'description' + | 'media_type' + | 'mime_type' + | 'media_details' + | 'post' + | 'source_url'; -type ViewProperties = 'date' | 'date_gmt'; -type EditProperties = 'date' | 'id'; +type EditProperties = + | 'date' + | 'date_gmt' + | 'guid' + | 'id' + | 'link' + | 'modified' + | 'modified_gmt' + | 'slug' + | 'status' + | 'type' + | 'permalink_template' + | 'generated_slug' + | 'title' + | 'author' + | 'comment_status' + | 'ping_status' + | 'meta' + | 'template' + | 'alt_text' + | 'caption' + | 'description' + | 'media_type' + | 'mime_type' + | 'media_details' + | 'post' + | 'source_url' + | 'missing_image_sizes'; + +type EmbedProperties = + | 'date' + | 'id' + | 'link' + | 'slug' + | 'type' + | 'title' + | 'author' + | 'alt_text' + | 'caption' + | 'media_type' + | 'mime_type' + | 'media_details' + | 'source_url'; export type Attachment< - Context extends EntityContext = EditContext, - RawType = RawObject -> = Pick< + Context extends EntityContext = EntityContext.view, + RawType = RawObject< Context > +> = EntityInContext< BaseAttachment< RawType >, - Context extends ViewContext ? ViewProperties : EditProperties + Context, + ViewProperties, + EditProperties, + EmbedProperties +>; + +const attachmentInViewContext = ( {} as any ) as Attachment< EntityContext.view >; +// attachmentInViewContext.title is { rendered: string } + +const attachmentInEditContext = ( {} as any ) as Attachment< EntityContext.edit >; +// attachmentInEditContext.title is { raw: string, rendered: string } + +const attachmentInEmbedContext = ( {} as any ) as Attachment< EntityContext.embed >; +// attachmentInViewContext.title is { rendered: string } + +const editedAttachmentRecord = ( {} as any ) as Attachment< + EntityContext.edit, + RawString >; -*/ +// editedAttachmentRecord.title is string diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 55e201d88c0e1..d9fdd7b86fdb4 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -1,19 +1,26 @@ -/** - * The raw data representation. - */ -export interface RawObject { +export interface FullRawObject { /** * Data as it exists in the database. */ - raw?: string; + raw: string; /** * Data transformed for display. */ - rendered?: string; + rendered: string; } +/** + * The raw data representation. + */ +export type RawObject< Context extends EntityContext > = Pick< + FullRawObject, + Context extends EntityContext.edit ? 'raw' | 'rendered' : 'rendered' +>; + +type DefaultRawObject = RawObject< EntityContext.view >; + export type RawString = string; -export type RawData = RawObject | RawString; +export type RawData = Partial< DefaultRawObject > | RawString; export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; @@ -34,7 +41,7 @@ export type TemplateContent = | string; export interface EntityRecordWithRawData< - RawType extends RawData = RawObject + RawType extends RawData = DefaultRawObject > {} export interface AvatarUrls { @@ -53,3 +60,49 @@ export interface AvatarUrls { [ k: string ]: string; } + +export enum EntityContext { + view = 'view', + edit = 'edit', + embed = 'embed', +} +export type view = EntityContext.view; +export type edit = EntityContext.edit; +export type embed = EntityContext.embed; + +export type EntityInContext< + EntityType extends EntityRecordWithRawData, + Context extends EntityContext, + ViewProps extends keyof EntityType, + EditProps extends keyof EntityType, + EmbedProps extends keyof EntityType +> = Pick< + EntityType, + Context extends EntityContext.view + ? ViewProps + : Context extends EntityContext.edit + ? EditProps + : EmbedProps +>; + +export type RawField< + RawDataIsString extends boolean, + T +> = RawDataIsString extends true ? string : T; + +export type OnlyInContexts< + FieldType, + AvailableInContexts extends EntityContext, + Context extends EntityContext +> = AvailableInContexts extends Context ? FieldType : never; + +export type DifferentPerContext< + ViewType, + EditType, + EmbedType, + Context extends EntityContext +> = Context extends view + ? ViewType + : Context extends edit + ? EditType + : EmbedType; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index db2cc949a160b..3defb1bc10440 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -1,9 +1,22 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; +import { + edit, + EntityContext, + OnlyInContexts, + FullRawObject, + RawField, + view, + OpenOrClosed, + DifferentPerContext, + PostStatus, +} from './common'; -export interface Post< RawType > extends EntityRecordWithRawData { +export interface Post< + Context extends EntityContext, + RawDataIsString extends boolean = false +> { /** * The date the post was published, in the site's timezone. */ @@ -11,11 +24,19 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * The date the post was published, as GMT. */ - date_gmt?: string | null; + date_gmt: OnlyInContexts< string | null, view | edit, Context >; /** * The globally unique identifier for the post. */ - guid?: RawType; + guid: RawField< + RawDataIsString, + DifferentPerContext< + Pick< FullRawObject, 'rendered' >, + FullRawObject, + never, + Context + > + >; /** * Unique identifier for the post. */ @@ -27,11 +48,11 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * The date the post was last modified, in the site's timezone. */ - modified?: string; + modified: OnlyInContexts< string, view | edit, Context >; /** * The date the post was last modified, as GMT. */ - modified_gmt?: string; + modified_gmt: OnlyInContexts< string, view | edit, Context >; /** * An alphanumeric identifier for the post unique to its type. */ @@ -39,7 +60,7 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * A named status for the post. */ - status?: PostStatus; + status: OnlyInContexts< PostStatus, view | edit, Context >; /** * Type of post. */ @@ -47,23 +68,39 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * A password to protect access to the content and excerpt. */ - password?: string; + password: OnlyInContexts< string, edit, Context >; /** * Permalink template for the post. */ - permalink_template?: string; + permalink_template: OnlyInContexts< string, edit, Context >; /** * Slug automatically generated from the post title. */ - generated_slug?: string; + generated_slug: OnlyInContexts< string, edit, Context >; /** * The title for the post. */ - title: RawType; + title: RawField< + RawDataIsString, + DifferentPerContext< + Pick< FullRawObject, 'rendered' >, + FullRawObject, + Pick< FullRawObject, 'rendered' >, + Context + > + >; /** * The content for the post. */ - content?: RawType; + content: RawField< + RawDataIsString, + DifferentPerContext< + Pick< FullRawObject, 'rendered' > & { protected: boolean }, + FullRawObject & { block_version: number; protected: boolean }, + { protected: boolean }, + Context + > + >; /** * The ID for the author of the post. */ @@ -71,7 +108,15 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * The excerpt for the post. */ - excerpt: RawType; + excerpt: RawField< + RawDataIsString, + DifferentPerContext< + Pick< FullRawObject, 'rendered' >, + FullRawObject, + Pick< FullRawObject, 'rendered' >, + Context + > & { protected: boolean } + >; /** * The ID of the featured media for the post. */ @@ -79,37 +124,41 @@ export interface Post< RawType > extends EntityRecordWithRawData { /** * Whether or not comments are open on the post. */ - comment_status?: OpenOrClosed; + comment_status: OnlyInContexts< OpenOrClosed, view | edit, Context >; /** * Whether or not the post can be pinged. */ - ping_status?: OpenOrClosed; + ping_status: OnlyInContexts< OpenOrClosed, view | edit, Context >; /** * The format for the post. */ - format?: PostFormat; + format: OnlyInContexts< PostFormat, view | edit, Context >; /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta: OnlyInContexts< + { + [ k: string ]: string; + }, + view | edit, + Context + >; /** * Whether or not the post should be treated as sticky. */ - sticky?: boolean; + sticky: OnlyInContexts< boolean, view | edit, Context >; /** * The theme file to use to display the post. */ - template?: string; + template: OnlyInContexts< string, view | edit, Context >; /** * The terms assigned to the post in the category taxonomy. */ - categories?: number[]; + categories: OnlyInContexts< number[], view | edit, Context >; /** * The terms assigned to the post in the post_tag taxonomy. */ - tags?: number[]; + tags: OnlyInContexts< number[], view | edit, Context >; } type PostFormat = From 566c9547022d8d2baa4c315648cdef60404bb5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 11 Feb 2022 16:27:49 +0100 Subject: [PATCH 12/73] =?UTF-8?q?Remove=20EntityInContext=20=E2=80=93=20it?= =?UTF-8?q?=20isn't=20really=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core-data/src/types/attachment.ts | 13 ++++++++----- packages/core-data/src/types/common.ts | 14 -------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index f0d915b461d0f..2260594b09f71 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -201,12 +201,15 @@ type EmbedProperties = export type Attachment< Context extends EntityContext = EntityContext.view, RawType = RawObject< Context > -> = EntityInContext< +> = Pick< BaseAttachment< RawType >, - Context, - ViewProperties, - EditProperties, - EmbedProperties + Context extends EntityContext.view + ? ViewProperties + : Context extends EntityContext.edit + ? EditProperties + : Context extends EntityContext.embed + ? EmbedProperties + : never >; const attachmentInViewContext = ( {} as any ) as Attachment< EntityContext.view >; diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index d9fdd7b86fdb4..79b8301e515ec 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -70,20 +70,6 @@ export type view = EntityContext.view; export type edit = EntityContext.edit; export type embed = EntityContext.embed; -export type EntityInContext< - EntityType extends EntityRecordWithRawData, - Context extends EntityContext, - ViewProps extends keyof EntityType, - EditProps extends keyof EntityType, - EmbedProps extends keyof EntityType -> = Pick< - EntityType, - Context extends EntityContext.view - ? ViewProps - : Context extends EntityContext.edit - ? EditProps - : EmbedProps ->; export type RawField< RawDataIsString extends boolean, From 5969c127de72bb76b3439b3c988376ba9ed4d7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 11 Feb 2022 16:33:36 +0100 Subject: [PATCH 13/73] Rename RawDataIsString to RawDataOverride --- packages/core-data/src/types/common.ts | 8 ++++++-- packages/core-data/src/types/post.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 79b8301e515ec..375e85f14416f 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -70,11 +70,15 @@ export type view = EntityContext.view; export type edit = EntityContext.edit; export type embed = EntityContext.embed; +export enum RawDataType { + default, + RawDataIsString, +} export type RawField< - RawDataIsString extends boolean, + RawDataOverride extends RawDataType, T -> = RawDataIsString extends true ? string : T; +> = RawDataOverride extends RawDataType.RawDataIsString ? string : T; export type OnlyInContexts< FieldType, diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 3defb1bc10440..dfa968bd4de02 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -11,11 +11,13 @@ import { OpenOrClosed, DifferentPerContext, PostStatus, + embed, + RawDataType, } from './common'; export interface Post< Context extends EntityContext, - RawDataIsString extends boolean = false + RawDataOverride extends RawDataType = RawDataType.default > { /** * The date the post was published, in the site's timezone. @@ -29,7 +31,7 @@ export interface Post< * The globally unique identifier for the post. */ guid: RawField< - RawDataIsString, + RawDataOverride, DifferentPerContext< Pick< FullRawObject, 'rendered' >, FullRawObject, @@ -81,7 +83,7 @@ export interface Post< * The title for the post. */ title: RawField< - RawDataIsString, + RawDataOverride, DifferentPerContext< Pick< FullRawObject, 'rendered' >, FullRawObject, @@ -93,7 +95,7 @@ export interface Post< * The content for the post. */ content: RawField< - RawDataIsString, + RawDataOverride, DifferentPerContext< Pick< FullRawObject, 'rendered' > & { protected: boolean }, FullRawObject & { block_version: number; protected: boolean }, @@ -109,7 +111,7 @@ export interface Post< * The excerpt for the post. */ excerpt: RawField< - RawDataIsString, + RawDataOverride, DifferentPerContext< Pick< FullRawObject, 'rendered' >, FullRawObject, From 4d8ea955ec668ef5a52852d05e42200e4277f96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 15 Feb 2022 14:53:45 +0100 Subject: [PATCH 14/73] Use Entity and EntityWithEdits without distinguishing between different contexts --- packages/core-data/src/types/attachment.ts | 165 ++++++------------ packages/core-data/src/types/comment.ts | 8 +- packages/core-data/src/types/common.ts | 108 ++++-------- packages/core-data/src/types/index.ts | 64 +++++++ packages/core-data/src/types/menu-location.ts | 2 + packages/core-data/src/types/nav_menu.ts | 2 + packages/core-data/src/types/nav_menu_item.ts | 29 ++- .../core-data/src/types/navigation-area.ts | 2 + packages/core-data/src/types/page.ts | 30 +++- packages/core-data/src/types/plugin.ts | 11 +- packages/core-data/src/types/post.ts | 116 ++++-------- packages/core-data/src/types/settings.ts | 9 +- packages/core-data/src/types/sidebar.ts | 6 +- packages/core-data/src/types/taxonomy.ts | 12 +- packages/core-data/src/types/theme.ts | 64 ++++--- packages/core-data/src/types/type.ts | 10 +- packages/core-data/src/types/user.ts | 2 + packages/core-data/src/types/widget-type.ts | 2 + packages/core-data/src/types/widget.ts | 2 + packages/core-data/src/types/wp_template.ts | 21 ++- .../core-data/src/types/wp_template_part.ts | 22 ++- 21 files changed, 344 insertions(+), 343 deletions(-) create mode 100644 packages/core-data/src/types/index.ts diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 2260594b09f71..49c2cb53dd199 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -2,18 +2,14 @@ * Internal dependencies */ import { - EntityInContext, - EntityContext, - EntityRecordWithRawData, - OpenOrClosed, + CommentStatus, + MediaType, + PingStatus, PostStatus, - RawObject, - RawString, + WithEdits, } from './common'; -type MediaType = 'image' | 'file'; - -export interface BaseAttachment< RawType > extends EntityRecordWithRawData { +export interface Attachment { /** * The date the post was published, in the site's timezone. */ @@ -25,7 +21,16 @@ export interface BaseAttachment< RawType > extends EntityRecordWithRawData { /** * The globally unique identifier for the post. */ - guid: RawType; + guid?: { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered: string; + }; /** * Unique identifier for the post. */ @@ -65,7 +70,16 @@ export interface BaseAttachment< RawType > extends EntityRecordWithRawData { /** * The title for the post. */ - title: RawType; + title: { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered: string; + }; /** * The ID for the author of the post. */ @@ -73,11 +87,11 @@ export interface BaseAttachment< RawType > extends EntityRecordWithRawData { /** * Whether or not comments are open on the post. */ - comment_status: OpenOrClosed; + comment_status: CommentStatus; /** * Whether or not the post can be pinged. */ - ping_status: OpenOrClosed; + ping_status: PingStatus; /** * Meta fields. */ @@ -95,11 +109,29 @@ export interface BaseAttachment< RawType > extends EntityRecordWithRawData { /** * The attachment caption. */ - caption: RawType; + caption: { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered: string; + }; /** * The attachment description. */ - description: RawType; + description: { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered: string; + }; /** * Attachment type. */ @@ -128,101 +160,8 @@ export interface BaseAttachment< RawType > extends EntityRecordWithRawData { missing_image_sizes: string[]; } -type ViewProperties = - | 'date' - | 'date_gmt' - | 'guid' - | 'id' - | 'link' - | 'modified' - | 'modified_gmt' - | 'slug' - | 'status' - | 'type' - | 'title' - | 'author' - | 'comment_status' - | 'ping_status' - | 'meta' - | 'template' - | 'alt_text' - | 'caption' - | 'description' - | 'media_type' - | 'mime_type' - | 'media_details' - | 'post' - | 'source_url'; - -type EditProperties = - | 'date' - | 'date_gmt' - | 'guid' - | 'id' - | 'link' - | 'modified' - | 'modified_gmt' - | 'slug' - | 'status' - | 'type' - | 'permalink_template' - | 'generated_slug' - | 'title' - | 'author' - | 'comment_status' - | 'ping_status' - | 'meta' - | 'template' - | 'alt_text' - | 'caption' - | 'description' - | 'media_type' - | 'mime_type' - | 'media_details' - | 'post' - | 'source_url' - | 'missing_image_sizes'; - -type EmbedProperties = - | 'date' - | 'id' - | 'link' - | 'slug' - | 'type' - | 'title' - | 'author' - | 'alt_text' - | 'caption' - | 'media_type' - | 'mime_type' - | 'media_details' - | 'source_url'; - -export type Attachment< - Context extends EntityContext = EntityContext.view, - RawType = RawObject< Context > -> = Pick< - BaseAttachment< RawType >, - Context extends EntityContext.view - ? ViewProperties - : Context extends EntityContext.edit - ? EditProperties - : Context extends EntityContext.embed - ? EmbedProperties - : never ->; - -const attachmentInViewContext = ( {} as any ) as Attachment< EntityContext.view >; -// attachmentInViewContext.title is { rendered: string } - -const attachmentInEditContext = ( {} as any ) as Attachment< EntityContext.edit >; -// attachmentInEditContext.title is { raw: string, rendered: string } - -const attachmentInEmbedContext = ( {} as any ) as Attachment< EntityContext.embed >; -// attachmentInViewContext.title is { rendered: string } - -const editedAttachmentRecord = ( {} as any ) as Attachment< - EntityContext.edit, - RawString ->; -// editedAttachmentRecord.title is string +export interface AttachmentWithEdits + extends WithEdits< + Attachment, + 'guid' | 'title' | 'description' | 'caption' + > {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index c0db2063f6c86..e303a02870eb5 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { AvatarUrls, EntityRecordWithRawData } from './common'; +import { AvatarUrls, RawField, WithEdits } from './common'; -export interface Comment< RawType > extends EntityRecordWithRawData { +export interface Comment { /** * Unique identifier for the comment. */ @@ -35,7 +35,7 @@ export interface Comment< RawType > extends EntityRecordWithRawData { /** * The content for the comment. */ - content: RawType; + content: RawField; /** * The date the comment was published, in the site's timezone. */ @@ -75,3 +75,5 @@ export interface Comment< RawType > extends EntityRecordWithRawData { [ k: string ]: string; }; } + +export interface CommentWithEdits extends WithEdits< Comment, 'content' > {} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 375e85f14416f..d458895d547d4 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -1,48 +1,6 @@ -export interface FullRawObject { - /** - * Data as it exists in the database. - */ - raw: string; - /** - * Data transformed for display. - */ - rendered: string; -} - -/** - * The raw data representation. - */ -export type RawObject< Context extends EntityContext > = Pick< - FullRawObject, - Context extends EntityContext.edit ? 'raw' | 'rendered' : 'rendered' ->; - -type DefaultRawObject = RawObject< EntityContext.view >; - -export type RawString = string; -export type RawData = Partial< DefaultRawObject > | RawString; - -export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; - -export type OpenOrClosed = 'open' | 'closed'; -export type ActiveOrInactive = 'active' | 'inactive'; - -export type TemplateContent = - | { - /** - * Content for the template, as it exists in the database. - */ - raw?: string; - /** - * Version of the content block format used by the template. - */ - block_version?: number; - } - | string; - -export interface EntityRecordWithRawData< - RawType extends RawData = DefaultRawObject -> {} +export type WithEdits< T, Fields > = { + [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; +}; export interface AvatarUrls { /** @@ -61,38 +19,32 @@ export interface AvatarUrls { [ k: string ]: string; } -export enum EntityContext { - view = 'view', - edit = 'edit', - embed = 'embed', -} -export type view = EntityContext.view; -export type edit = EntityContext.edit; -export type embed = EntityContext.embed; +export type MediaType = 'image' | 'file'; +export type CommentStatus = 'open' | 'closed'; +export type PingStatus = 'open' | 'closed'; +export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; +export type PostFormat = + | 'standard' + | 'aside' + | 'chat' + | 'gallery' + | 'link' + | 'image' + | 'quote' + | 'status' + | 'video' + | 'audio'; -export enum RawDataType { - default, - RawDataIsString, +/** + * The raw data representation. + */ +export interface RawField { + /** + * Data as it exists in the database. + */ + raw?: string; + /** + * Data transformed for display. + */ + rendered: string; } - -export type RawField< - RawDataOverride extends RawDataType, - T -> = RawDataOverride extends RawDataType.RawDataIsString ? string : T; - -export type OnlyInContexts< - FieldType, - AvailableInContexts extends EntityContext, - Context extends EntityContext -> = AvailableInContexts extends Context ? FieldType : never; - -export type DifferentPerContext< - ViewType, - EditType, - EmbedType, - Context extends EntityContext -> = Context extends view - ? ViewType - : Context extends edit - ? EditType - : EmbedType; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts new file mode 100644 index 0000000000000..e5512ba78200b --- /dev/null +++ b/packages/core-data/src/types/index.ts @@ -0,0 +1,64 @@ +/** + * Internal dependencies + */ +import { Attachment, AttachmentWithEdits } from './attachment'; +import { Comment, CommentWithEdits } from './comment'; +import { MenuLocation, MenuLocationWithEdits } from './menu-location'; +import { NavMenu, NavMenuWithEdits } from './nav_menu'; +import { NavMenuItem, NavMenuItemWithEdits } from './nav_menu_item'; +import { NavigationArea, NavigationAreaWithEdits } from './navigation-area'; +import { Page, PageWithEdits } from './page'; +import { Plugin, PluginWithEdits } from './plugin'; +import { Post, PostWithEdits } from './post'; +import { Settings, SettingsWithEdits } from './settings'; +import { Sidebar, SidebarWithEdits } from './sidebar'; +import { Taxonomy, TaxonomyWithEdits } from './taxonomy'; +import { Theme, ThemeWithEdits } from './theme'; +import { User, UserWithEdits } from './user'; +import { Type, TypeWithEdits } from './type'; +import { Widget, WidgetWithEdits } from './widget'; +import { WidgetType, WidgetTypeWithEdits } from './widget-type'; +import { WpTemplate, WpTemplateWithEdits } from './wp_template'; +import { WpTemplatePart, WpTemplatePartWithEdits } from './wp_template_part'; + +export type EntityRecord = + | Attachment + | Comment + | MenuLocation + | NavMenu + | NavMenuItem + | NavigationArea + | Page + | Plugin + | Post + | Settings + | Sidebar + | Taxonomy + | Theme + | Type + | User + | Widget + | WidgetType + | WpTemplate + | WpTemplatePart; + +export type EntityRecordWithEdits = + | AttachmentWithEdits + | CommentWithEdits + | MenuLocationWithEdits + | NavMenuWithEdits + | NavMenuItemWithEdits + | NavigationAreaWithEdits + | PageWithEdits + | PluginWithEdits + | PostWithEdits + | SettingsWithEdits + | SidebarWithEdits + | TaxonomyWithEdits + | ThemeWithEdits + | TypeWithEdits + | UserWithEdits + | WidgetWithEdits + | WidgetTypeWithEdits + | WpTemplateWithEdits + | WpTemplatePartWithEdits; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 251d97aaceabb..22ec91218bfce 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -12,3 +12,5 @@ export interface MenuLocation { */ menu: number; } + +export interface MenuLocationWithEdits extends MenuLocation {} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 6bcdef64961c2..1a2c64d83d0ea 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -30,3 +30,5 @@ export interface NavMenu { */ auto_add?: boolean; } + +export interface NavMenuWithEdits extends NavMenu {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 31f53d2c1ca66..ca2e9aecb2162 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,12 +1,30 @@ /** * Internal dependencies */ +import { RawField, WithEdits } from './common'; + +/** + * Internal dependencies + */ + +export type NavMenuItemType = + | 'taxonomy' + | 'post_type' + | 'post_type_archive' + | 'custom'; +export type NavMenuItemStatus = + | 'publish' + | 'future' + | 'draft' + | 'pending' + | 'private'; +export type Target = '_blank' | ''; export interface NavMenuItem { /** * The title for the object. */ - title: RawType; + title: RawField; /** * Unique identifier for the object. */ @@ -18,11 +36,11 @@ export interface NavMenuItem { /** * The family of objects originally represented, such as "post_type" or "taxonomy". */ - type: 'taxonomy' | 'post_type' | 'post_type_archive' | 'custom'; + type: NavMenuItemType; /** * A named status for the object. */ - status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; + status: NavMenuItemStatus; /** * The ID for the parent of the object. */ @@ -54,7 +72,7 @@ export interface NavMenuItem { /** * The target attribute of the link element for this menu item. */ - target: '_blank' | ''; + target: Target; /** * The URL to which this menu item points. */ @@ -78,3 +96,6 @@ export interface NavMenuItem { [ k: string ]: string; }; } + +export interface NavMenuItemWithEdits + extends WithEdits< NavMenuItem, 'title' > {} diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 5749e5f7db6ef..5a007521cd13a 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -12,3 +12,5 @@ export interface NavigationArea { */ navigation: number; } + +export interface NavigationAreaWithEdits extends NavigationArea {} diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 01449770ed546..5682930635d78 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -1,9 +1,15 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData, OpenOrClosed, PostStatus } from './common'; +import { + CommentStatus, + PingStatus, + PostStatus, + RawField, + WithEdits, +} from './common'; -export interface Page< RawType > extends EntityRecordWithRawData { +export interface Page { /** * The date the post was published, in the site's timezone. */ @@ -15,7 +21,7 @@ export interface Page< RawType > extends EntityRecordWithRawData { /** * The globally unique identifier for the post. */ - guid?: RawType; + guid?: RawField; /** * Unique identifier for the post. */ @@ -63,11 +69,16 @@ export interface Page< RawType > extends EntityRecordWithRawData { /** * The title for the post. */ - title: RawType; + title: RawField; /** * The content for the post. */ - content?: RawType; + content?: RawField & { + /** Whether the content is protected with a password. */ + is_protected: boolean; + /** Version of the content block format used by the page. */ + block_version?: string; + }; /** * The ID for the author of the post. */ @@ -75,7 +86,7 @@ export interface Page< RawType > extends EntityRecordWithRawData { /** * The excerpt for the post. */ - excerpt: RawType; + excerpt: RawField; /** * The ID of the featured media for the post. */ @@ -83,11 +94,11 @@ export interface Page< RawType > extends EntityRecordWithRawData { /** * Whether or not comments are open on the post. */ - comment_status?: OpenOrClosed; + comment_status?: CommentStatus; /** * Whether or not the post can be pinged. */ - ping_status?: OpenOrClosed; + ping_status?: PingStatus; /** * The order of the post in relation to other posts. */ @@ -103,3 +114,6 @@ export interface Page< RawType > extends EntityRecordWithRawData { */ template?: string; } + +export interface PageWithEdits + extends WithEdits< Page, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index b45df94b10f72..decd2bfd50a73 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { ActiveOrInactive, EntityRecordWithRawData } from './common'; +import { RawField, WithEdits } from './common'; -export interface Plugin< RawType > extends EntityRecordWithRawData { +export interface Plugin { /** * The plugin file. */ @@ -11,7 +11,7 @@ export interface Plugin< RawType > extends EntityRecordWithRawData { /** * The plugin activation status. */ - status: ActiveOrInactive; + status: PluginStatus; /** * The plugin name. */ @@ -33,7 +33,7 @@ export interface Plugin< RawType > extends EntityRecordWithRawData { /** * The plugin description. */ - description?: RawType; + description?: RawField; /** * The plugin version number. */ @@ -55,3 +55,6 @@ export interface Plugin< RawType > extends EntityRecordWithRawData { */ textdomain?: string; } + +export type PluginStatus = 'active' | 'inactive'; +export interface PluginWithEdits extends WithEdits< Plugin, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index dfa968bd4de02..7dbfbc50104cd 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -2,23 +2,15 @@ * Internal dependencies */ import { - edit, - EntityContext, - OnlyInContexts, - FullRawObject, - RawField, - view, - OpenOrClosed, - DifferentPerContext, PostStatus, - embed, - RawDataType, + PingStatus, + CommentStatus, + RawField, + PostFormat, + WithEdits, } from './common'; -export interface Post< - Context extends EntityContext, - RawDataOverride extends RawDataType = RawDataType.default -> { +export interface Post { /** * The date the post was published, in the site's timezone. */ @@ -26,19 +18,11 @@ export interface Post< /** * The date the post was published, as GMT. */ - date_gmt: OnlyInContexts< string | null, view | edit, Context >; + date_gmt?: string | null; /** * The globally unique identifier for the post. */ - guid: RawField< - RawDataOverride, - DifferentPerContext< - Pick< FullRawObject, 'rendered' >, - FullRawObject, - never, - Context - > - >; + guid?: RawField; /** * Unique identifier for the post. */ @@ -50,11 +34,11 @@ export interface Post< /** * The date the post was last modified, in the site's timezone. */ - modified: OnlyInContexts< string, view | edit, Context >; + modified?: string; /** * The date the post was last modified, as GMT. */ - modified_gmt: OnlyInContexts< string, view | edit, Context >; + modified_gmt?: string; /** * An alphanumeric identifier for the post unique to its type. */ @@ -62,7 +46,7 @@ export interface Post< /** * A named status for the post. */ - status: OnlyInContexts< PostStatus, view | edit, Context >; + status?: PostStatus; /** * Type of post. */ @@ -70,39 +54,28 @@ export interface Post< /** * A password to protect access to the content and excerpt. */ - password: OnlyInContexts< string, edit, Context >; + password?: string; /** * Permalink template for the post. */ - permalink_template: OnlyInContexts< string, edit, Context >; + permalink_template?: string; /** * Slug automatically generated from the post title. */ - generated_slug: OnlyInContexts< string, edit, Context >; + generated_slug?: string; /** * The title for the post. */ - title: RawField< - RawDataOverride, - DifferentPerContext< - Pick< FullRawObject, 'rendered' >, - FullRawObject, - Pick< FullRawObject, 'rendered' >, - Context - > - >; + title: RawField; /** * The content for the post. */ - content: RawField< - RawDataOverride, - DifferentPerContext< - Pick< FullRawObject, 'rendered' > & { protected: boolean }, - FullRawObject & { block_version: number; protected: boolean }, - { protected: boolean }, - Context - > - >; + content?: RawField & { + /** Whether the content is protected with a password. */ + is_protected: boolean; + /** Version of the content block format used by the post. */ + block_version?: string; + }; /** * The ID for the author of the post. */ @@ -110,15 +83,7 @@ export interface Post< /** * The excerpt for the post. */ - excerpt: RawField< - RawDataOverride, - DifferentPerContext< - Pick< FullRawObject, 'rendered' >, - FullRawObject, - Pick< FullRawObject, 'rendered' >, - Context - > & { protected: boolean } - >; + excerpt: RawField; /** * The ID of the featured media for the post. */ @@ -126,51 +91,38 @@ export interface Post< /** * Whether or not comments are open on the post. */ - comment_status: OnlyInContexts< OpenOrClosed, view | edit, Context >; + comment_status?: CommentStatus; /** * Whether or not the post can be pinged. */ - ping_status: OnlyInContexts< OpenOrClosed, view | edit, Context >; + ping_status?: PingStatus; /** * The format for the post. */ - format: OnlyInContexts< PostFormat, view | edit, Context >; + format?: PostFormat; /** * Meta fields. */ - meta: OnlyInContexts< - { - [ k: string ]: string; - }, - view | edit, - Context - >; + meta?: { + [ k: string ]: string; + }; /** * Whether or not the post should be treated as sticky. */ - sticky: OnlyInContexts< boolean, view | edit, Context >; + sticky?: boolean; /** * The theme file to use to display the post. */ - template: OnlyInContexts< string, view | edit, Context >; + template?: string; /** * The terms assigned to the post in the category taxonomy. */ - categories: OnlyInContexts< number[], view | edit, Context >; + categories?: number[]; /** * The terms assigned to the post in the post_tag taxonomy. */ - tags: OnlyInContexts< number[], view | edit, Context >; + tags?: number[]; } -type PostFormat = - | 'standard' - | 'aside' - | 'chat' - | 'gallery' - | 'link' - | 'image' - | 'quote' - | 'status' - | 'video' - | 'audio'; +export interface PostWithEdits + extends WithEdits< Post, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index dc2c2155476e2..87642ed0d98a9 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { OpenOrClosed } from './common'; +import { CommentStatus, PingStatus, WithEdits } from './common'; export interface Settings { /** @@ -67,11 +67,11 @@ export interface Settings { /** * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. */ - default_ping_status?: OpenOrClosed; + default_ping_status?: PingStatus; /** * Allow people to submit comments on new posts. */ - default_comment_status?: OpenOrClosed; + default_comment_status?: CommentStatus; /** * Site logo. */ @@ -81,3 +81,6 @@ export interface Settings { */ site_icon?: number; } + +export interface SettingsWithEdits + extends WithEdits< Settings, 'description' > {} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index cb17fa0f3deca..b36dea7d82c1f 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,7 +2,6 @@ * Internal dependencies */ import { Widget } from './widget'; -import { ActiveOrInactive } from './common'; export interface Sidebar { /** @@ -40,11 +39,14 @@ export interface Sidebar { /** * Status of sidebar. */ - status: ActiveOrInactive; + status: SidebarStatus; /** * Nested widgets. */ widgets: NestedWidget[]; } +type SidebarStatus = 'active' | 'inactive'; type NestedWidget = Widget | string; + +export interface SidebarWithEdits extends Sidebar {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 039bc71a76513..da3ffe017c5a8 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,3 +1,8 @@ +/** + * Internal dependencies + */ +import { WithEdits } from './common'; + export interface Taxonomy { /** * All capabilities used by the taxonomy. @@ -46,10 +51,10 @@ export interface Taxonomy { /** * The visibility settings for the taxonomy. */ - visibility?: Visibility; + visibility?: TaxonomyVisibility; } -interface Visibility { +export interface TaxonomyVisibility { /** * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. */ @@ -75,3 +80,6 @@ interface Visibility { */ show_in_quick_edit?: boolean; } + +export interface TaxonomyWithEdits + extends WithEdits< Taxonomy, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 0882bcae5d7d9..faa0334482ead 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { ActiveOrInactive, EntityRecordWithRawData } from './common'; +import { PostFormat, RawField, WithEdits } from './common'; -export interface Theme< RawType > extends EntityRecordWithRawData { +export interface Theme { /** * The theme's stylesheet. This uniquely identifies the theme. */ @@ -15,19 +15,19 @@ export interface Theme< RawType > extends EntityRecordWithRawData { /** * The theme author. */ - author?: RawType; + author?: RawField; /** * The website of the theme author. */ - author_uri?: RawType; + author_uri?: RawField; /** * A description of the theme. */ - description?: RawType; + description?: RawField; /** * The name of the theme. */ - name?: RawType; + name?: RawField; /** * The minimum PHP version required for the theme to work. */ @@ -43,7 +43,7 @@ export interface Theme< RawType > extends EntityRecordWithRawData { /** * Tags indicating styles and features of the theme. */ - tags?: RawType; + tags?: RawField; /** * The theme's text domain. */ @@ -55,7 +55,7 @@ export interface Theme< RawType > extends EntityRecordWithRawData { /** * The URI of the theme's webpage. */ - theme_uri?: RawType; + theme_uri?: RawField; /** * The theme's current version. */ @@ -63,9 +63,11 @@ export interface Theme< RawType > extends EntityRecordWithRawData { /** * A named status for the theme. */ - status?: ActiveOrInactive; + status?: ThemeStatus; } +export type ThemeStatus = 'active' | 'inactive'; + interface ThemeSupports { /** * Whether theme opts in to wide alignment CSS class. @@ -149,19 +151,7 @@ interface ThemeSupports { 'wp-block-styles'?: boolean; } -type PostFormat = - | 'standard' - | 'aside' - | 'chat' - | 'gallery' - | 'link' - | 'image' - | 'quote' - | 'status' - | 'video' - | 'audio'; - -type CustomBackground = { +export interface CustomBackground { 'default-image'?: string; 'default-preset'?: 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; 'default-position-x'?: 'left' | 'center' | 'right'; @@ -170,9 +160,9 @@ type CustomBackground = { 'default-repeat'?: 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; 'default-attachment'?: 'scroll' | 'fixed'; 'default-color'?: string; -}; +} -type CustomHeader = { +export interface CustomHeader { 'default-image'?: string; 'random-default'?: boolean; width?: number; @@ -183,36 +173,36 @@ type CustomHeader = { 'header-text'?: boolean; uploads?: boolean; video?: boolean; -}; +} -type CustomLogo = { +export interface CustomLogo { width?: number; height?: number; 'flex-width'?: boolean; 'flex-height'?: boolean; 'header-text'?: string[]; 'unlink-homepage-logo'?: boolean; -}; +} -type Color = { +export interface Color { name?: string; slug?: string; color?: string; -}; +} -type FontSize = { +export interface FontSize { name?: string; size?: number; slug?: string; -}; +} -type GradientPreset = { +export interface GradientPreset { name?: string; gradient?: string; slug?: string; -}; +} -type Html5Option = +export type Html5Option = | 'search-form' | 'comment-form' | 'comment-list' @@ -220,3 +210,9 @@ type Html5Option = | 'caption' | 'script' | 'style'; + +export interface ThemeWithEdits + extends WithEdits< + Theme, + 'author' | 'author_uri' | 'description' | 'name' | 'tags' | 'theme_uri' + > {} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index b7c3e31173c64..e2cd9b7d06b5b 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,3 +1,7 @@ +/** + * Internal dependencies + */ + export interface Type { /** * All capabilities used by the post type. @@ -52,10 +56,10 @@ export interface Type { /** * The visibility settings for the post type. */ - visibility?: Visibility; + visibility?: TypeVisibility; } -interface Visibility { +interface TypeVisibility { /** * Whether to generate a default UI for managing this post type. */ @@ -65,3 +69,5 @@ interface Visibility { */ show_in_nav_menus?: boolean; } + +export interface TypeWithEdits extends Type {} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 9df2fb1114fdd..ea50126be4468 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -87,3 +87,5 @@ export interface User { [ k: string ]: string; }; } + +export interface UserWithEdits extends User {} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 204de87b185c9..0df083ae1f02c 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -20,3 +20,5 @@ export interface WidgetType { */ classname: string; } + +export interface WidgetTypeWithEdits extends WidgetType {} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 42d8da91ffe64..eb1bbb1896d7f 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -45,3 +45,5 @@ interface WidgetInstance { [ k: string ]: string; }; } + +export interface WidgetWithEdits extends Widget {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 569e7f14d5cb9..2ec4da780d289 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData, PostStatus, TemplateContent } from './common'; +import { PostStatus, RawField, WithEdits } from './common'; -export interface WpTemplate< RawType > extends EntityRecordWithRawData { +export interface WpTemplate { /** * ID of template. */ @@ -31,11 +31,22 @@ export interface WpTemplate< RawType > extends EntityRecordWithRawData { /** * Content of template. */ - content: TemplateContent; + content: + | { + /** + * Content for the template, as it exists in the database. + */ + raw?: string; + /** + * Version of the content block format used by the template. + */ + block_version?: number; + } + | string; /** * Title of template. */ - title: RawType; + title: RawField | string; /** * Description of template. */ @@ -65,3 +76,5 @@ export interface WpTemplate< RawType > extends EntityRecordWithRawData { [ k: string ]: string; }; } + +export interface WpTemplateWithEdits extends WithEdits< WpTemplate, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 90bb7560b66a2..af5389003e8cf 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { EntityRecordWithRawData, PostStatus, TemplateContent } from './common'; +import { PostStatus, RawField, WithEdits } from './common'; -export interface WpTemplatePart< RawType > extends EntityRecordWithRawData { +export interface WpTemplatePart { /** * ID of template. */ @@ -31,11 +31,22 @@ export interface WpTemplatePart< RawType > extends EntityRecordWithRawData { /** * Content of template. */ - content: TemplateContent; + content: + | { + /** + * Content for the template, as it exists in the database. + */ + raw?: string; + /** + * Version of the content block format used by the template. + */ + block_version?: number; + } + | string; /** * Title of template. */ - title: RawType; + title: RawField | string; /** * Description of template. */ @@ -63,3 +74,6 @@ export interface WpTemplatePart< RawType > extends EntityRecordWithRawData { */ area: string; } + +export interface WpTemplatePartWithEdits + extends WithEdits< WpTemplatePart, 'title' | 'content' > {} From 4ff84bb526175370df533be81df55559ff2ef7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 16 Feb 2022 17:32:12 +0100 Subject: [PATCH 15/73] Make all the fields contextual --- packages/core-data/src/types/attachment.ts | 90 ++++------- packages/core-data/src/types/comment.ts | 32 ++-- packages/core-data/src/types/common.ts | 30 +++- packages/core-data/src/types/index.ts | 119 +++++++------- packages/core-data/src/types/menu-location.ts | 12 +- packages/core-data/src/types/nav_menu.ts | 14 +- packages/core-data/src/types/nav_menu_item.ts | 26 +-- .../core-data/src/types/navigation-area.ts | 13 +- packages/core-data/src/types/page.ts | 78 +++++---- packages/core-data/src/types/plugin.ts | 28 ++-- packages/core-data/src/types/post.ts | 88 ++++++---- packages/core-data/src/types/settings.ts | 53 +++--- packages/core-data/src/types/sidebar.ts | 10 +- packages/core-data/src/types/taxonomy.ts | 42 ++--- packages/core-data/src/types/theme.ts | 152 +++++++++--------- packages/core-data/src/types/type.ts | 32 ++-- packages/core-data/src/types/user.ts | 37 ++--- packages/core-data/src/types/widget-type.ts | 12 +- packages/core-data/src/types/widget.ts | 16 +- packages/core-data/src/types/wp_template.ts | 26 +-- .../core-data/src/types/wp_template_part.ts | 23 ++- 21 files changed, 524 insertions(+), 409 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 49c2cb53dd199..3997b2a0e3f5b 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -2,14 +2,16 @@ * Internal dependencies */ import { - CommentStatus, + Context, + ContextualField, MediaType, - PingStatus, PostStatus, + RawField, WithEdits, + WithoutNevers, } from './common'; -export interface Attachment { +interface FullAttachment< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -17,20 +19,11 @@ export interface Attachment { /** * The date the post was published, as GMT. */ - date_gmt: string | null; + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; /** * The globally unique identifier for the post. */ - guid?: { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered: string; - }; + guid: ContextualField< RawField< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -42,11 +35,11 @@ export interface Attachment { /** * The date the post was last modified, in the site's timezone. */ - modified: string; + modified: ContextualField< string, 'view' | 'edit', C >; /** * The date the post was last modified, as GMT. */ - modified_gmt: string; + modified_gmt: ContextualField< string, 'view' | 'edit', C >; /** * An alphanumeric identifier for the post unique to its type. */ @@ -54,7 +47,7 @@ export interface Attachment { /** * A named status for the post. */ - status: PostStatus; + status: ContextualField< PostStatus, 'view' | 'edit', C >; /** * Type of post. */ @@ -62,24 +55,15 @@ export interface Attachment { /** * Permalink template for the post. */ - permalink_template: string; + permalink_template: ContextualField< string, 'edit', C >; /** * Slug automatically generated from the post title. */ - generated_slug: string; + generated_slug: ContextualField< string, 'edit', C >; /** * The title for the post. */ - title: { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered: string; - }; + title: RawField< C >; /** * The ID for the author of the post. */ @@ -87,21 +71,19 @@ export interface Attachment { /** * Whether or not comments are open on the post. */ - comment_status: CommentStatus; + comment_status: ContextualField< 'open' | 'closed', 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ - ping_status: PingStatus; + ping_status: ContextualField< 'open' | 'closed', 'view' | 'edit', C >; /** * Meta fields. */ - meta: { - [ k: string ]: string; - }; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; /** * The theme file to use to display the post. */ - template: string; + template: ContextualField< string, 'view' | 'edit', C >; /** * Alternative text to display when attachment is not displayed. */ @@ -109,29 +91,11 @@ export interface Attachment { /** * The attachment caption. */ - caption: { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered: string; - }; + caption: ContextualField< string, 'edit', C >; /** * The attachment description. */ - description: { - /** - * Data as it exists in the database. - */ - raw?: string; - /** - * Data transformed for display. - */ - rendered: string; - }; + description: ContextualField< RawField< C >, 'view' | 'edit', C >; /** * Attachment type. */ @@ -143,13 +107,11 @@ export interface Attachment { /** * Details about the media file, specific to its type. */ - media_details: { - [ k: string ]: string; - }; + media_details: Record< string, string >; /** * The ID for the associated post of the attachment. */ - post: number; + post: ContextualField< number, 'view' | 'edit', C >; /** * URL to the original attachment file. */ @@ -157,11 +119,15 @@ export interface Attachment { /** * List of the missing image sizes of the attachment. */ - missing_image_sizes: string[]; + missing_image_sizes: ContextualField< string[], 'edit', C >; } -export interface AttachmentWithEdits +export type Attachment< C extends Context > = WithoutNevers< + FullAttachment< C > +>; + +export interface EditedAttachment extends WithEdits< - Attachment, + Attachment< 'edit' >, 'guid' | 'title' | 'description' | 'caption' > {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index e303a02870eb5..08f79bcf0c676 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,9 +1,15 @@ /** * Internal dependencies */ -import { AvatarUrls, RawField, WithEdits } from './common'; +import { + AvatarUrls, + Context, + ContextualField, + RawField, + WithEdits, +} from './common'; -export interface Comment { +interface FullComment< C extends Context > { /** * Unique identifier for the comment. */ @@ -15,11 +21,11 @@ export interface Comment { /** * Email address for the comment author. */ - author_email?: string; + author_email: ContextualField< string, 'edit', C >; /** * IP address for the comment author. */ - author_ip?: string; + author_ip: ContextualField< string, 'edit', C >; /** * Display name for the comment author. */ @@ -31,11 +37,11 @@ export interface Comment { /** * User agent for the comment author. */ - author_user_agent?: string; + author_user_agent: ContextualField< string, 'edit', C >; /** * The content for the comment. */ - content: RawField; + content: RawField< C >; /** * The date the comment was published, in the site's timezone. */ @@ -43,7 +49,7 @@ export interface Comment { /** * The date the comment was published, as GMT. */ - date_gmt?: string; + date_gmt: ContextualField< string, 'view' | 'edit', C >; /** * URL to the comment. */ @@ -55,11 +61,11 @@ export interface Comment { /** * The ID of the associated post object. */ - post?: number; + post: ContextualField< number, 'view' | 'edit', C >; /** * State of the comment. */ - status?: string; + status: ContextualField< string, 'view' | 'edit', C >; /** * Type of the comment. */ @@ -71,9 +77,9 @@ export interface Comment { /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export interface CommentWithEdits extends WithEdits< Comment, 'content' > {} +export type Comment< C extends Context > = FullComment< C >; +export interface EditedComment + extends WithEdits< Comment< 'edit' >, 'content' > {} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index d458895d547d4..04f1c0a7d0045 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -35,14 +35,40 @@ export type PostFormat = | 'video' | 'audio'; +export type Context = 'view' | 'edit' | 'embed'; +export type ContextualField< + FieldType, + AvailableInContexts extends Context, + C extends Context +> = AvailableInContexts extends C ? FieldType : never; + +type Without< + T, + V, + WithNevers = { + [ K in keyof T ]: Exclude< T[ K ], undefined > extends V + ? never + : T[ K ] extends Record< string, unknown > + ? Without< T[ K ], V > + : T[ K ]; + } +> = Pick< + WithNevers, + { + [ K in keyof WithNevers ]: WithNevers[ K ] extends never ? never : K; + }[ keyof WithNevers ] +>; + +export type WithoutNevers< T > = Without< T, never >; + /** * The raw data representation. */ -export interface RawField { +export interface RawField< C extends Context > { /** * Data as it exists in the database. */ - raw?: string; + raw: ContextualField< string, 'edit', C >; /** * Data transformed for display. */ diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index e5512ba78200b..157ba80442338 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,64 +1,65 @@ /** * Internal dependencies */ -import { Attachment, AttachmentWithEdits } from './attachment'; -import { Comment, CommentWithEdits } from './comment'; -import { MenuLocation, MenuLocationWithEdits } from './menu-location'; -import { NavMenu, NavMenuWithEdits } from './nav_menu'; -import { NavMenuItem, NavMenuItemWithEdits } from './nav_menu_item'; -import { NavigationArea, NavigationAreaWithEdits } from './navigation-area'; -import { Page, PageWithEdits } from './page'; -import { Plugin, PluginWithEdits } from './plugin'; -import { Post, PostWithEdits } from './post'; -import { Settings, SettingsWithEdits } from './settings'; -import { Sidebar, SidebarWithEdits } from './sidebar'; -import { Taxonomy, TaxonomyWithEdits } from './taxonomy'; -import { Theme, ThemeWithEdits } from './theme'; -import { User, UserWithEdits } from './user'; -import { Type, TypeWithEdits } from './type'; -import { Widget, WidgetWithEdits } from './widget'; -import { WidgetType, WidgetTypeWithEdits } from './widget-type'; -import { WpTemplate, WpTemplateWithEdits } from './wp_template'; -import { WpTemplatePart, WpTemplatePartWithEdits } from './wp_template_part'; +import { Attachment, EditedAttachment } from './attachment'; +import { Comment, EditedComment } from './comment'; +import { MenuLocation, EditedMenuLocation } from './menu-location'; +import { NavMenu, EditedNavMenu } from './nav_menu'; +import { NavMenuItem, EditedNavMenuItem } from './nav_menu_item'; +import { NavigationArea, EditedNavigationArea } from './navigation-area'; +import { Page, EditedPage } from './page'; +import { Plugin, EditedPlugin } from './plugin'; +import { Post, EditedPost } from './post'; +import { Settings, EditedSettings } from './settings'; +import { Sidebar, EditedSidebar } from './sidebar'; +import { Taxonomy, EditedTaxonomy } from './taxonomy'; +import { Theme, EditedTheme } from './theme'; +import { User, EditedUser } from './user'; +import { Type, EditedType } from './type'; +import { Widget, EditedWidget } from './widget'; +import { WidgetType, EditedWidgetType } from './widget-type'; +import { WpTemplate, EditedWpTemplate } from './wp_template'; +import { WpTemplatePart, EditedWpTemplatePart } from './wp_template_part'; +import { Context } from './common'; -export type EntityRecord = - | Attachment - | Comment - | MenuLocation - | NavMenu - | NavMenuItem - | NavigationArea - | Page - | Plugin - | Post - | Settings - | Sidebar - | Taxonomy - | Theme - | Type - | User - | Widget - | WidgetType - | WpTemplate - | WpTemplatePart; +export type EntityRecord< C extends Context > = + | Attachment< C > + | Comment< C > + | MenuLocation< C > + | NavMenu< C > + | NavMenuItem< C > + | NavigationArea< C > + | Page< C > + | Plugin< C > + | Post< C > + | Settings< C > + | Sidebar< C > + | Taxonomy< C > + | Theme< C > + | Type< C > + | User< C > + | Widget< C > + | WidgetType< C > + | WpTemplate< C > + | WpTemplatePart< C >; -export type EntityRecordWithEdits = - | AttachmentWithEdits - | CommentWithEdits - | MenuLocationWithEdits - | NavMenuWithEdits - | NavMenuItemWithEdits - | NavigationAreaWithEdits - | PageWithEdits - | PluginWithEdits - | PostWithEdits - | SettingsWithEdits - | SidebarWithEdits - | TaxonomyWithEdits - | ThemeWithEdits - | TypeWithEdits - | UserWithEdits - | WidgetWithEdits - | WidgetTypeWithEdits - | WpTemplateWithEdits - | WpTemplatePartWithEdits; +export type EditedEntityRecord = + | EditedAttachment + | EditedComment + | EditedMenuLocation + | EditedNavMenu + | EditedNavMenuItem + | EditedNavigationArea + | EditedPage + | EditedPlugin + | EditedPost + | EditedSettings + | EditedSidebar + | EditedTaxonomy + | EditedTheme + | EditedType + | EditedUser + | EditedWidget + | EditedWidgetType + | EditedWpTemplate + | EditedWpTemplatePart; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 22ec91218bfce..eb61ee9264375 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,4 +1,9 @@ -export interface MenuLocation { +/** + * Internal dependencies + */ +import { Context, WithoutNevers } from './common'; + +interface FullMenuLocation< C extends Context > { /** * The name of the menu location. */ @@ -13,4 +18,7 @@ export interface MenuLocation { menu: number; } -export interface MenuLocationWithEdits extends MenuLocation {} +export type MenuLocation< C extends Context > = WithoutNevers< + FullMenuLocation< C > +>; +export interface EditedMenuLocation extends MenuLocation< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 1a2c64d83d0ea..6e6a8ad74d1e9 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -1,4 +1,9 @@ -export interface NavMenu { +/** + * Internal dependencies + */ +import { Context, WithoutNevers } from './common'; + +interface FullNavMenu< C extends Context > { /** * Unique identifier for the term. */ @@ -18,9 +23,7 @@ export interface NavMenu { /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta?: Record< string, string >; /** * The locations assigned to the menu. */ @@ -31,4 +34,5 @@ export interface NavMenu { auto_add?: boolean; } -export interface NavMenuWithEdits extends NavMenu {} +export type NavMenu< C extends Context > = WithoutNevers< FullNavMenu< C > >; +export interface EditedNavMenu extends NavMenu< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index ca2e9aecb2162..8d0d1e0a68465 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,7 +1,13 @@ /** * Internal dependencies */ -import { RawField, WithEdits } from './common'; +import { + RawField, + WithEdits, + Context, + ContextualField, + WithoutNevers, +} from './common'; /** * Internal dependencies @@ -20,11 +26,11 @@ export type NavMenuItemStatus = | 'private'; export type Target = '_blank' | ''; -export interface NavMenuItem { +interface FullNavMenuItem< C extends Context > { /** * The title for the object. */ - title: RawField; + title: RawField< C >; /** * Unique identifier for the object. */ @@ -88,14 +94,16 @@ export interface NavMenuItem { /** * The terms assigned to the object in the nav_menu taxonomy. */ - menus?: number; + menus: ContextualField< number, 'view' | 'edit', C >; /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export interface NavMenuItemWithEdits - extends WithEdits< NavMenuItem, 'title' > {} +export type NavMenuItem< C extends Context > = WithoutNevers< + FullNavMenuItem< C > +>; + +export interface EditedNavMenuItem + extends WithEdits< NavMenuItem< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 5a007521cd13a..8822e3e20e9c4 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -1,4 +1,9 @@ -export interface NavigationArea { +/** + * Internal dependencies + */ +import { Context, WithoutNevers } from './common'; + +interface FullNavigationArea< C extends Context > { /** * The name of the navigation area. */ @@ -13,4 +18,8 @@ export interface NavigationArea { navigation: number; } -export interface NavigationAreaWithEdits extends NavigationArea {} +export type NavigationArea< C extends Context > = WithoutNevers< + FullNavigationArea< C > +>; + +export interface EditedNavigationArea extends FullNavigationArea< 'edit' > {} diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 5682930635d78..ffa08da157fe8 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -3,13 +3,16 @@ */ import { CommentStatus, + Context, + ContextualField, PingStatus, PostStatus, RawField, WithEdits, + WithoutNevers, } from './common'; -export interface Page { +interface FullPage< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -17,11 +20,11 @@ export interface Page { /** * The date the post was published, as GMT. */ - date_gmt?: string | null; + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; /** * The globally unique identifier for the post. */ - guid?: RawField; + guid: ContextualField< RawField< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -33,11 +36,11 @@ export interface Page { /** * The date the post was last modified, in the site's timezone. */ - modified?: string; + modified: ContextualField< string, 'view' | 'edit', C >; /** * The date the post was last modified, as GMT. */ - modified_gmt?: string; + modified_gmt: ContextualField< string, 'view' | 'edit', C >; /** * An alphanumeric identifier for the post unique to its type. */ @@ -45,7 +48,7 @@ export interface Page { /** * A named status for the post. */ - status?: PostStatus; + status: ContextualField< PostStatus, 'view' | 'edit', C >; /** * Type of post. */ @@ -53,32 +56,48 @@ export interface Page { /** * A password to protect access to the content and excerpt. */ - password?: string; + password: ContextualField< string, 'edit', C >; /** * Permalink template for the post. */ - permalink_template?: string; + permalink_template: ContextualField< string, 'edit', C >; /** * Slug automatically generated from the post title. */ - generated_slug?: string; + generated_slug: ContextualField< string, 'edit', C >; /** * The ID for the parent of the post. */ - parent?: number; + parent: ContextualField< number, 'view' | 'edit', C >; /** * The title for the post. */ - title: RawField; + title: RawField< C >; /** * The content for the post. */ - content?: RawField & { - /** Whether the content is protected with a password. */ - is_protected: boolean; - /** Version of the content block format used by the page. */ - block_version?: string; - }; + content: ContextualField< + { + /** + * Data as it exists in the database. + */ + raw: ContextualField< string, 'edit', C >; + /** + * Data transformed for display. + */ + rendered: string; + /** + * Whether the content is protected with a password. + */ + is_protected: boolean; + /** + * Version of the content block format used by the page. + */ + block_version: ContextualField< string, 'edit', C >; + }, + 'view' | 'edit', + C + >; /** * The ID for the author of the post. */ @@ -86,7 +105,9 @@ export interface Page { /** * The excerpt for the post. */ - excerpt: RawField; + excerpt: RawField< C > & { + protected: boolean; + }; /** * The ID of the featured media for the post. */ @@ -94,26 +115,29 @@ export interface Page { /** * Whether or not comments are open on the post. */ - comment_status?: CommentStatus; + comment_status: ContextualField< CommentStatus, 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ - ping_status?: PingStatus; + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; /** * The order of the post in relation to other posts. */ - menu_order?: number; + menu_order: ContextualField< number, 'view' | 'edit', C >; /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; /** * The theme file to use to display the post. */ - template?: string; + template: ContextualField< string, 'view' | 'edit', C >; } -export interface PageWithEdits - extends WithEdits< Page, 'guid' | 'title' | 'content' | 'excerpt' > {} +export type Page< C extends Context > = WithoutNevers< FullPage< C > >; + +export interface EditedPage + extends WithEdits< + Page< 'edit' >, + 'guid' | 'title' | 'content' | 'excerpt' + > {} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index decd2bfd50a73..0b366cd956f89 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,9 +1,15 @@ /** * Internal dependencies */ -import { RawField, WithEdits } from './common'; +import { + Context, + ContextualField, + RawField, + WithEdits, + WithoutNevers, +} from './common'; -export interface Plugin { +interface FullPlugin< C extends Context > { /** * The plugin file. */ @@ -19,25 +25,23 @@ export interface Plugin { /** * The plugin's website address. */ - plugin_uri?: string; + plugin_uri: ContextualField< string, 'view' | 'edit', C >; /** * The plugin author. */ - author?: { - [ k: string ]: string; - }; + author: ContextualField< Record< string, string >, 'view' | 'edit', C >; /** * Plugin author's website address. */ - author_uri?: string; + author_uri: ContextualField< string, 'view' | 'edit', C >; /** * The plugin description. */ - description?: RawField; + description: ContextualField< RawField< 'edit' >, 'view' | 'edit', C >; /** * The plugin version number. */ - version?: string; + version: ContextualField< string, 'view' | 'edit', C >; /** * Whether the plugin can only be activated network-wide. */ @@ -53,8 +57,10 @@ export interface Plugin { /** * The plugin's text domain. */ - textdomain?: string; + textdomain: ContextualField< string, 'view' | 'edit', C >; } export type PluginStatus = 'active' | 'inactive'; -export interface PluginWithEdits extends WithEdits< Plugin, 'description' > {} +export type Plugin< C extends Context > = WithoutNevers< FullPlugin< C > >; +export interface EditedPlugin + extends WithEdits< Plugin< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 7dbfbc50104cd..b0c05cdaf2bbb 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -2,15 +2,18 @@ * Internal dependencies */ import { - PostStatus, - PingStatus, CommentStatus, - RawField, + Context, + ContextualField, + PingStatus, PostFormat, + PostStatus, + RawField, WithEdits, + WithoutNevers, } from './common'; -export interface Post { +interface FullPost< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -18,11 +21,11 @@ export interface Post { /** * The date the post was published, as GMT. */ - date_gmt?: string | null; + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; /** * The globally unique identifier for the post. */ - guid?: RawField; + guid: ContextualField< RawField< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -34,11 +37,11 @@ export interface Post { /** * The date the post was last modified, in the site's timezone. */ - modified?: string; + modified: ContextualField< string, 'view' | 'edit', C >; /** * The date the post was last modified, as GMT. */ - modified_gmt?: string; + modified_gmt: ContextualField< string, 'view' | 'edit', C >; /** * An alphanumeric identifier for the post unique to its type. */ @@ -46,7 +49,7 @@ export interface Post { /** * A named status for the post. */ - status?: PostStatus; + status: ContextualField< PostStatus, 'view' | 'edit', C >; /** * Type of post. */ @@ -54,28 +57,44 @@ export interface Post { /** * A password to protect access to the content and excerpt. */ - password?: string; + password: ContextualField< string, 'edit', C >; /** * Permalink template for the post. */ - permalink_template?: string; + permalink_template: ContextualField< string, 'edit', C >; /** * Slug automatically generated from the post title. */ - generated_slug?: string; + generated_slug: ContextualField< string, 'edit', C >; /** * The title for the post. */ - title: RawField; + title: RawField< C >; /** * The content for the post. */ - content?: RawField & { - /** Whether the content is protected with a password. */ - is_protected: boolean; - /** Version of the content block format used by the post. */ - block_version?: string; - }; + content: ContextualField< + { + /** + * Data as it exists in the database. + */ + raw: ContextualField< string, 'edit', C >; + /** + * Data transformed for display. + */ + rendered: string; + /** + * Whether the content is protected with a password. + */ + is_protected: boolean; + /** + * Version of the content block format used by the page. + */ + block_version: ContextualField< string, 'edit', C >; + }, + 'view' | 'edit', + C + >; /** * The ID for the author of the post. */ @@ -83,7 +102,9 @@ export interface Post { /** * The excerpt for the post. */ - excerpt: RawField; + excerpt: RawField< C > & { + protected: boolean; + }; /** * The ID of the featured media for the post. */ @@ -91,38 +112,41 @@ export interface Post { /** * Whether or not comments are open on the post. */ - comment_status?: CommentStatus; + comment_status: ContextualField< CommentStatus, 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ - ping_status?: PingStatus; + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; /** * The format for the post. */ - format?: PostFormat; + format: ContextualField< PostFormat, 'view' | 'edit', C >; /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta?: Record< string, string >; /** * Whether or not the post should be treated as sticky. */ - sticky?: boolean; + sticky: ContextualField< boolean, 'view' | 'edit', C >; /** * The theme file to use to display the post. */ - template?: string; + template: ContextualField< string, 'view' | 'edit', C >; /** * The terms assigned to the post in the category taxonomy. */ - categories?: number[]; + categories: ContextualField< number[], 'view' | 'edit', C >; /** * The terms assigned to the post in the post_tag taxonomy. */ - tags?: number[]; + tags: ContextualField< number[], 'view' | 'edit', C >; } -export interface PostWithEdits - extends WithEdits< Post, 'guid' | 'title' | 'content' | 'excerpt' > {} +export type Post< C extends Context > = WithoutNevers< FullPost< C > >; + +export interface EditedPost + extends WithEdits< + Post< 'edit' >, + 'guid' | 'title' | 'content' | 'excerpt' + > {} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 87642ed0d98a9..0ce28a6a10ba9 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,86 +1,93 @@ /** * Internal dependencies */ -import { CommentStatus, PingStatus, WithEdits } from './common'; +import { + CommentStatus, + Context, + PingStatus, + WithEdits, + WithoutNevers, +} from './common'; -export interface Settings { +interface FullSettings< C extends Context > { /** * What to show on the front page */ - show_on_front?: string; + show_on_front: string; /** * The ID of the page that should be displayed on the front page */ - page_on_front?: number; + page_on_front: number; /** * Site title. */ - title?: string; + title: string; /** * Site tagline. */ - description?: string; + description: string; /** * Site URL. */ - url?: string; + url: string; /** * This address is used for admin purposes, like new user notification. */ - email?: string; + email: string; /** * A city in the same timezone as you. */ - timezone?: string; + timezone: string; /** * A date format for all date strings. */ - date_format?: string; + date_format: string; /** * A time format for all time strings. */ - time_format?: string; + time_format: string; /** * A day number of the week that the week should start on. */ - start_of_week?: number; + start_of_week: number; /** * WordPress locale code. */ - language?: string; + language: string; /** * Convert emoticons like :-) and :-P to graphics on display. */ - use_smilies?: boolean; + use_smilies: boolean; /** * Default post category. */ - default_category?: number; + default_category: number; /** * Default post format. */ - default_post_format?: string; + default_post_format: string; /** * Blog pages show at most. */ - posts_per_page?: number; + posts_per_page: number; /** * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. */ - default_ping_status?: PingStatus; + default_ping_status: PingStatus; /** * Allow people to submit comments on new posts. */ - default_comment_status?: CommentStatus; + default_comment_status: CommentStatus; /** * Site logo. */ - site_logo?: number; + site_logo: number; /** * Site icon. */ - site_icon?: number; + site_icon: number; } -export interface SettingsWithEdits - extends WithEdits< Settings, 'description' > {} +export type Settings< C extends Context > = WithoutNevers< FullSettings< C > >; +export interface EditedSettings + extends WithEdits< Settings< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index b36dea7d82c1f..41d5b48e53693 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,8 +2,9 @@ * Internal dependencies */ import { Widget } from './widget'; +import { Context, WithoutNevers } from './common'; -export interface Sidebar { +interface FullSidebar< C extends Context > { /** * ID of sidebar. */ @@ -43,10 +44,11 @@ export interface Sidebar { /** * Nested widgets. */ - widgets: NestedWidget[]; + widgets: NestedWidget< C >[]; } type SidebarStatus = 'active' | 'inactive'; -type NestedWidget = Widget | string; +type NestedWidget< C extends Context > = Widget< C > | string; -export interface SidebarWithEdits extends Sidebar {} +export type Sidebar< C extends Context > = WithoutNevers< FullSidebar< C > >; +export interface EditedSidebar extends Sidebar< 'edit' > {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index da3ffe017c5a8..f2f38bbebba12 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,29 +1,28 @@ /** * Internal dependencies */ -import { WithEdits } from './common'; +/** + * Internal dependencies + */ +import { Context, ContextualField, WithEdits, WithoutNevers } from './common'; -export interface Taxonomy { +interface FullTaxonomy< C extends Context > { /** * All capabilities used by the taxonomy. */ - capabilities?: { - [ k: string ]: string; - }; + capabilities: ContextualField< Record< string, string >, 'edit', C >; /** * A human-readable description of the taxonomy. */ - description?: string; + description: ContextualField< string, 'view' | 'edit', C >; /** * Whether or not the taxonomy should have children. */ - hierarchical?: boolean; + hierarchical: ContextualField< boolean, 'view' | 'edit', C >; /** * Human-readable labels for the taxonomy for various contexts. */ - labels?: { - [ k: string ]: string; - }; + labels: ContextualField< Record< string, string >, 'edit', C >; /** * The title for the taxonomy. */ @@ -35,11 +34,11 @@ export interface Taxonomy { /** * Whether or not the term cloud should be displayed. */ - show_cloud?: boolean; + show_cloud: ContextualField< boolean, 'edit', C >; /** * Types associated with the taxonomy. */ - types?: string[]; + types: ContextualField< string[], 'view' | 'edit', C >; /** * REST base route for the taxonomy. */ @@ -51,35 +50,36 @@ export interface Taxonomy { /** * The visibility settings for the taxonomy. */ - visibility?: TaxonomyVisibility; + visibility: TaxonomyVisibility; } export interface TaxonomyVisibility { /** * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. */ - public?: boolean; + public: boolean; /** * Whether the taxonomy is publicly queryable. */ - publicly_queryable?: boolean; + publicly_queryable: boolean; /** * Whether to generate a default UI for managing this taxonomy. */ - show_ui?: boolean; + show_ui: boolean; /** * Whether to allow automatic creation of taxonomy columns on associated post-types table. */ - show_admin_column?: boolean; + show_admin_column: boolean; /** * Whether to make the taxonomy available for selection in navigation menus. */ - show_in_nav_menus?: boolean; + show_in_nav_menus: boolean; /** * Whether to show the taxonomy in the quick/bulk edit panel. */ - show_in_quick_edit?: boolean; + show_in_quick_edit: boolean; } -export interface TaxonomyWithEdits - extends WithEdits< Taxonomy, 'description' > {} +export type Taxonomy< C extends Context > = WithoutNevers< FullTaxonomy< C > >; +export interface EditedTaxonomy + extends WithEdits< Taxonomy< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index faa0334482ead..57981fd8eada1 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,69 +1,75 @@ /** * Internal dependencies */ -import { PostFormat, RawField, WithEdits } from './common'; +import { + Context, + PostFormat, + RawField, + WithEdits, + WithoutNevers, +} from './common'; -export interface Theme { +interface FullTheme< C extends Context > { /** * The theme's stylesheet. This uniquely identifies the theme. */ - stylesheet?: string; + stylesheet: string; /** * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. */ - template?: string; + template: string; /** * The theme author. */ - author?: RawField; + author: RawField< 'edit' >; /** * The website of the theme author. */ - author_uri?: RawField; + author_uri: RawField< 'edit' >; /** * A description of the theme. */ - description?: RawField; + description: RawField< 'edit' >; /** * The name of the theme. */ - name?: RawField; + name: RawField< 'edit' >; /** * The minimum PHP version required for the theme to work. */ - requires_php?: string; + requires_php: string; /** * The minimum WordPress version required for the theme to work. */ - requires_wp?: string; + requires_wp: string; /** * The theme's screenshot URL. */ - screenshot?: string; + screenshot: string; /** * Tags indicating styles and features of the theme. */ - tags?: RawField; + tags: RawField< 'edit' >; /** * The theme's text domain. */ - textdomain?: string; + textdomain: string; /** * Features supported by this theme. */ - theme_supports?: ThemeSupports; + theme_supports: ThemeSupports; /** * The URI of the theme's webpage. */ - theme_uri?: RawField; + theme_uri: RawField< 'edit' >; /** * The theme's current version. */ - version?: string; + version: string; /** * A named status for the theme. */ - status?: ThemeStatus; + status: ThemeStatus; } export type ThemeStatus = 'active' | 'inactive'; @@ -72,134 +78,134 @@ interface ThemeSupports { /** * Whether theme opts in to wide alignment CSS class. */ - 'align-wide'?: boolean; + 'align-wide': boolean; /** * Whether posts and comments RSS feed links are added to head. */ - 'automatic-feed-links'?: boolean; + 'automatic-feed-links': boolean; /** * Custom background if defined by the theme. */ - 'custom-background'?: boolean | CustomBackground; + 'custom-background': boolean | CustomBackground; /** * Custom header if defined by the theme. */ - 'custom-header'?: boolean | CustomHeader; + 'custom-header': boolean | CustomHeader; /** * Custom logo if defined by the theme. */ - 'custom-logo'?: boolean | CustomLogo; + 'custom-logo': boolean | CustomLogo; /** * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. */ - 'customize-selective-refresh-widgets'?: boolean; + 'customize-selective-refresh-widgets': boolean; /** * Whether theme opts in to the dark editor style UI. */ - 'dark-editor-style'?: boolean; + 'dark-editor-style': boolean; /** * Whether the theme disables custom colors. */ - 'disable-custom-colors'?: boolean; + 'disable-custom-colors': boolean; /** * Whether the theme disables custom font sizes. */ - 'disable-custom-font-sizes'?: boolean; + 'disable-custom-font-sizes': boolean; /** * Whether the theme disables custom gradients. */ - 'disable-custom-gradients'?: boolean; + 'disable-custom-gradients': boolean; /** * Custom color palette if defined by the theme. */ - 'editor-color-palette'?: boolean | Color[]; + 'editor-color-palette': boolean | Color[]; /** * Custom font sizes if defined by the theme. */ - 'editor-font-sizes'?: boolean | FontSize[]; + 'editor-font-sizes': boolean | FontSize[]; /** * Custom gradient presets if defined by the theme. */ - 'editor-gradient-presets'?: boolean | GradientPreset[]; + 'editor-gradient-presets': boolean | GradientPreset[]; /** * Whether theme opts in to the editor styles CSS wrapper. */ - 'editor-styles'?: boolean; + 'editor-styles': boolean; /** * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. */ - html5?: boolean | Html5Option[]; + html5: boolean | Html5Option[]; /** * Post formats supported. */ - formats?: PostFormat[]; + formats: PostFormat[]; /** * The post types that support thumbnails or true if all post types are supported. */ - 'post-thumbnails'?: boolean | string[]; + 'post-thumbnails': boolean | string[]; /** * Whether the theme supports responsive embedded content. */ - 'responsive-embeds'?: boolean; + 'responsive-embeds': boolean; /** * Whether the theme can manage the document title tag. */ - 'title-tag'?: boolean; + 'title-tag': boolean; /** * Whether theme opts in to default WordPress block styles for viewing. */ - 'wp-block-styles'?: boolean; + 'wp-block-styles': boolean; } export interface CustomBackground { - 'default-image'?: string; - 'default-preset'?: 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; - 'default-position-x'?: 'left' | 'center' | 'right'; - 'default-position-y'?: 'left' | 'center' | 'right'; - 'default-size'?: 'auto' | 'contain' | 'cover'; - 'default-repeat'?: 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; - 'default-attachment'?: 'scroll' | 'fixed'; - 'default-color'?: string; + 'default-image': string; + 'default-preset': 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; + 'default-position-x': 'left' | 'center' | 'right'; + 'default-position-y': 'left' | 'center' | 'right'; + 'default-size': 'auto' | 'contain' | 'cover'; + 'default-repeat': 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; + 'default-attachment': 'scroll' | 'fixed'; + 'default-color': string; } export interface CustomHeader { - 'default-image'?: string; - 'random-default'?: boolean; - width?: number; - height?: number; - 'flex-height'?: boolean; - 'flex-width'?: boolean; - 'default-text-color'?: string; - 'header-text'?: boolean; - uploads?: boolean; - video?: boolean; + 'default-image': string; + 'random-default': boolean; + width: number; + height: number; + 'flex-height': boolean; + 'flex-width': boolean; + 'default-text-color': string; + 'header-text': boolean; + uploads: boolean; + video: boolean; } export interface CustomLogo { - width?: number; - height?: number; - 'flex-width'?: boolean; - 'flex-height'?: boolean; - 'header-text'?: string[]; - 'unlink-homepage-logo'?: boolean; + width: number; + height: number; + 'flex-width': boolean; + 'flex-height': boolean; + 'header-text': string[]; + 'unlink-homepage-logo': boolean; } export interface Color { - name?: string; - slug?: string; - color?: string; + name: string; + slug: string; + color: string; } export interface FontSize { - name?: string; - size?: number; - slug?: string; + name: string; + size: number; + slug: string; } export interface GradientPreset { - name?: string; - gradient?: string; - slug?: string; + name: string; + gradient: string; + slug: string; } export type Html5Option = @@ -211,8 +217,10 @@ export type Html5Option = | 'script' | 'style'; -export interface ThemeWithEdits +export type Theme< C extends Context > = WithoutNevers< FullTheme< C > >; + +export interface EditedTheme extends WithEdits< - Theme, + Theme< 'edit' >, 'author' | 'author_uri' | 'description' | 'name' | 'tags' | 'theme_uri' > {} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index e2cd9b7d06b5b..131a0b09678b4 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,32 +1,29 @@ /** * Internal dependencies */ +import { Context, WithoutNevers, ContextualField } from './common'; -export interface Type { +interface FullType< C extends Context > { /** * All capabilities used by the post type. */ - capabilities?: { - [ k: string ]: string; - }; + capabilities: ContextualField< Record< string, string >, 'edit', C >; /** * A human-readable description of the post type. */ - description?: string; + description: ContextualField< string, 'view' | 'edit', C >; /** * Whether or not the post type should have children. */ - hierarchical?: boolean; + hierarchical: ContextualField< boolean, 'view' | 'edit', C >; /** * Whether or not the post type can be viewed. */ - viewable?: boolean; + viewable: ContextualField< boolean, 'edit', C >; /** * Human-readable labels for the post type for various contexts. */ - labels?: { - [ k: string ]: string; - }; + labels: ContextualField< Record< string, string >, 'edit', C >; /** * The title for the post type. */ @@ -38,13 +35,11 @@ export interface Type { /** * All features, supported by the post type. */ - supports?: { - [ k: string ]: string; - }; + supports: ContextualField< Record< string, string >, 'edit', C >; /** * Taxonomies associated with post type. */ - taxonomies?: string[]; + taxonomies: ContextualField< string[], 'view' | 'edit', C >; /** * REST base route for the post type. */ @@ -56,18 +51,19 @@ export interface Type { /** * The visibility settings for the post type. */ - visibility?: TypeVisibility; + visibility: ContextualField< TypeVisibility, 'edit', C >; } interface TypeVisibility { /** * Whether to generate a default UI for managing this post type. */ - show_ui?: boolean; + show_ui: boolean; /** * Whether to make the post type is available for selection in navigation menus. */ - show_in_nav_menus?: boolean; + show_in_nav_menus: boolean; } -export interface TypeWithEdits extends Type {} +export type Type< C extends Context > = WithoutNevers< FullType< C > >; +export interface EditedType extends Type< 'edit' > {} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index ea50126be4468..cf34a66e03be4 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { AvatarUrls } from './common'; +import { AvatarUrls, Context, ContextualField, WithoutNevers } from './common'; -export interface User { +interface FullUser< C extends Context > { /** * Unique identifier for the user. */ @@ -11,7 +11,7 @@ export interface User { /** * Login name for the user. */ - username?: string; + username: ContextualField< string, 'edit', C >; /** * Display name for the user. */ @@ -19,15 +19,15 @@ export interface User { /** * First name for the user. */ - first_name?: string; + first_name: ContextualField< string, 'edit', C >; /** * Last name for the user. */ - last_name?: string; + last_name: ContextualField< string, 'edit', C >; /** * The email address for the user. */ - email?: string; + email: ContextualField< string, 'edit', C >; /** * URL of the user. */ @@ -43,11 +43,11 @@ export interface User { /** * Locale for the user. */ - locale?: '' | 'en_US'; + locale: ContextualField< '' | 'en_US', 'edit', C >; /** * The nickname for the user. */ - nickname?: string; + nickname: ContextualField< string, 'edit', C >; /** * An alphanumeric identifier for the user. */ @@ -55,27 +55,23 @@ export interface User { /** * Registration date for the user. */ - registered_date?: string; + registered_date: ContextualField< string, 'edit', C >; /** * Roles assigned to the user. */ - roles?: string[]; + roles: ContextualField< string[], 'edit', C >; /** * Password for the user (never included). */ - password?: string; + password: string; /** * All capabilities assigned to the user. */ - capabilities?: { - [ k: string ]: string; - }; + capabilities: ContextualField< Record< string, string >, 'edit', C >; /** * Any extra capabilities assigned to the user. */ - extra_capabilities?: { - [ k: string ]: string; - }; + extra_capabilities: ContextualField< Record< string, string >, 'edit', C >; /** * Avatar URLs for the user. */ @@ -83,9 +79,8 @@ export interface User { /** * Meta fields. */ - meta?: { - [ k: string ]: string; - }; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export interface UserWithEdits extends User {} +export type User< C extends Context > = WithoutNevers< FullUser< C > >; +export interface EditedUser extends User< 'edit' > {} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 0df083ae1f02c..0c9e0f778866c 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -1,4 +1,9 @@ -export interface WidgetType { +/** + * Internal dependencies + */ +import { Context, WithoutNevers } from './common'; + +interface FullWidgetType< C extends Context > { /** * Unique slug identifying the widget type. */ @@ -21,4 +26,7 @@ export interface WidgetType { classname: string; } -export interface WidgetTypeWithEdits extends WidgetType {} +export type WidgetType< C extends Context > = WithoutNevers< + FullWidgetType< C > +>; +export interface EditedWidgetType extends WidgetType< 'edit' > {} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index eb1bbb1896d7f..269e53c26ff4e 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,4 +1,9 @@ -export interface Widget { +/** + * Internal dependencies + */ +import { Context, ContextualField, WithoutNevers } from './common'; + +interface FullWidget< C extends Context > { /** * Unique identifier for the widget. */ @@ -18,7 +23,7 @@ export interface Widget { /** * HTML representation of the widget admin form. */ - rendered_form?: string; + rendered_form: ContextualField< string, 'edit', C >; /** * Instance settings of the widget, if supported. */ @@ -41,9 +46,8 @@ interface WidgetInstance { /** * Unencoded instance settings, if supported. */ - raw?: { - [ k: string ]: string; - }; + raw?: Record< string, string >; } -export interface WidgetWithEdits extends Widget {} +export type Widget< C extends Context > = WithoutNevers< FullWidget< C > >; +export interface EditedWidget extends Widget< 'edit' > {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 2ec4da780d289..42b0233dafbf1 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,9 +1,15 @@ /** * Internal dependencies */ -import { PostStatus, RawField, WithEdits } from './common'; +import { + Context, + PostStatus, + RawField, + WithEdits, + WithoutNevers, +} from './common'; -export interface WpTemplate { +interface FullWpTemplate< C extends Context > { /** * ID of template. */ @@ -46,7 +52,7 @@ export interface WpTemplate { /** * Title of template. */ - title: RawField | string; + title: RawField< 'edit' > | string; /** * Description of template. */ @@ -62,9 +68,7 @@ export interface WpTemplate { /** * Theme file exists. */ - has_theme_file: { - [ k: string ]: string; - }; + has_theme_file: Record< string, string >; /** * The ID for the author of the template. */ @@ -72,9 +76,11 @@ export interface WpTemplate { /** * Whether a template is a custom template. */ - is_custom: { - [ k: string ]: string; - }; + is_custom: Record< string, string >; } -export interface WpTemplateWithEdits extends WithEdits< WpTemplate, 'title' > {} +export type WpTemplate< C extends Context > = WithoutNevers< + FullWpTemplate< C > +>; +export interface EditedWpTemplate + extends WithEdits< WpTemplate< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index af5389003e8cf..bd688719afc61 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,9 +1,15 @@ /** * Internal dependencies */ -import { PostStatus, RawField, WithEdits } from './common'; +import { + Context, + PostStatus, + RawField, + WithEdits, + WithoutNevers, +} from './common'; -export interface WpTemplatePart { +interface FullWpTemplatePart< C extends Context > { /** * ID of template. */ @@ -46,7 +52,7 @@ export interface WpTemplatePart { /** * Title of template. */ - title: RawField | string; + title: RawField< 'edit' > | string; /** * Description of template. */ @@ -62,9 +68,7 @@ export interface WpTemplatePart { /** * Theme file exists. */ - has_theme_file: { - [ k: string ]: string; - }; + has_theme_file: Record< string, string >; /** * The ID for the author of the template. */ @@ -75,5 +79,8 @@ export interface WpTemplatePart { area: string; } -export interface WpTemplatePartWithEdits - extends WithEdits< WpTemplatePart, 'title' | 'content' > {} +export type WpTemplatePart< C extends Context > = WithoutNevers< + FullWpTemplatePart< C > +>; +export interface EditedWpTemplatePart + extends WithEdits< WpTemplatePart< 'edit' >, 'title' | 'content' > {} From b73646beed3f609f13a22e3ec8ce97aac3f9ed12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 16 Feb 2022 17:34:10 +0100 Subject: [PATCH 16/73] Refactir WithEdits to EditedRecord --- packages/core-data/src/types/attachment.ts | 4 ++-- packages/core-data/src/types/comment.ts | 4 ++-- packages/core-data/src/types/common.ts | 8 ++++---- packages/core-data/src/types/nav_menu_item.ts | 4 ++-- packages/core-data/src/types/page.ts | 4 ++-- packages/core-data/src/types/plugin.ts | 4 ++-- packages/core-data/src/types/post.ts | 4 ++-- packages/core-data/src/types/settings.ts | 4 ++-- packages/core-data/src/types/taxonomy.ts | 12 +++++++----- packages/core-data/src/types/theme.ts | 4 ++-- packages/core-data/src/types/wp_template.ts | 4 ++-- packages/core-data/src/types/wp_template_part.ts | 4 ++-- 12 files changed, 31 insertions(+), 29 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 3997b2a0e3f5b..8fceee577b35c 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -7,7 +7,7 @@ import { MediaType, PostStatus, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -127,7 +127,7 @@ export type Attachment< C extends Context > = WithoutNevers< >; export interface EditedAttachment - extends WithEdits< + extends EditedRecord< Attachment< 'edit' >, 'guid' | 'title' | 'description' | 'caption' > {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 08f79bcf0c676..819d957e9e61b 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -6,7 +6,7 @@ import { Context, ContextualField, RawField, - WithEdits, + EditedRecord, } from './common'; interface FullComment< C extends Context > { @@ -82,4 +82,4 @@ interface FullComment< C extends Context > { export type Comment< C extends Context > = FullComment< C >; export interface EditedComment - extends WithEdits< Comment< 'edit' >, 'content' > {} + extends EditedRecord< Comment< 'edit' >, 'content' > {} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 04f1c0a7d0045..a0bf943978c5a 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -1,7 +1,3 @@ -export type WithEdits< T, Fields > = { - [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; -}; - export interface AvatarUrls { /** * Avatar URL with image size of 24 pixels. @@ -42,6 +38,10 @@ export type ContextualField< C extends Context > = AvailableInContexts extends C ? FieldType : never; +export type EditedRecord< T, Fields > = { + [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; +}; + type Without< T, V, diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 8d0d1e0a68465..820d6e82d7fab 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -3,7 +3,7 @@ */ import { RawField, - WithEdits, + EditedRecord, Context, ContextualField, WithoutNevers, @@ -106,4 +106,4 @@ export type NavMenuItem< C extends Context > = WithoutNevers< >; export interface EditedNavMenuItem - extends WithEdits< NavMenuItem< 'edit' >, 'title' > {} + extends EditedRecord< NavMenuItem< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index ffa08da157fe8..76c5329940c09 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -8,7 +8,7 @@ import { PingStatus, PostStatus, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -137,7 +137,7 @@ interface FullPage< C extends Context > { export type Page< C extends Context > = WithoutNevers< FullPage< C > >; export interface EditedPage - extends WithEdits< + extends EditedRecord< Page< 'edit' >, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 0b366cd956f89..a0ecd86652d89 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -5,7 +5,7 @@ import { Context, ContextualField, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -63,4 +63,4 @@ interface FullPlugin< C extends Context > { export type PluginStatus = 'active' | 'inactive'; export type Plugin< C extends Context > = WithoutNevers< FullPlugin< C > >; export interface EditedPlugin - extends WithEdits< Plugin< 'edit' >, 'description' > {} + extends EditedRecord< Plugin< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index b0c05cdaf2bbb..879b9ce087994 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -9,7 +9,7 @@ import { PostFormat, PostStatus, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -146,7 +146,7 @@ interface FullPost< C extends Context > { export type Post< C extends Context > = WithoutNevers< FullPost< C > >; export interface EditedPost - extends WithEdits< + extends EditedRecord< Post< 'edit' >, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 0ce28a6a10ba9..b78d24e43399c 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -5,7 +5,7 @@ import { CommentStatus, Context, PingStatus, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -90,4 +90,4 @@ interface FullSettings< C extends Context > { export type Settings< C extends Context > = WithoutNevers< FullSettings< C > >; export interface EditedSettings - extends WithEdits< Settings< 'edit' >, 'description' > {} + extends EditedRecord< Settings< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index f2f38bbebba12..3ad44b5b505ec 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,10 +1,12 @@ /** * Internal dependencies */ -/** - * Internal dependencies - */ -import { Context, ContextualField, WithEdits, WithoutNevers } from './common'; +import { + Context, + ContextualField, + EditedRecord, + WithoutNevers, +} from './common'; interface FullTaxonomy< C extends Context > { /** @@ -82,4 +84,4 @@ export interface TaxonomyVisibility { export type Taxonomy< C extends Context > = WithoutNevers< FullTaxonomy< C > >; export interface EditedTaxonomy - extends WithEdits< Taxonomy< 'edit' >, 'description' > {} + extends EditedRecord< Taxonomy< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 57981fd8eada1..71f8e7b8ae53f 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -5,7 +5,7 @@ import { Context, PostFormat, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -220,7 +220,7 @@ export type Html5Option = export type Theme< C extends Context > = WithoutNevers< FullTheme< C > >; export interface EditedTheme - extends WithEdits< + extends EditedRecord< Theme< 'edit' >, 'author' | 'author_uri' | 'description' | 'name' | 'tags' | 'theme_uri' > {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 42b0233dafbf1..9eb36edfc456d 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -5,7 +5,7 @@ import { Context, PostStatus, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -83,4 +83,4 @@ export type WpTemplate< C extends Context > = WithoutNevers< FullWpTemplate< C > >; export interface EditedWpTemplate - extends WithEdits< WpTemplate< 'edit' >, 'title' > {} + extends EditedRecord< WpTemplate< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index bd688719afc61..a49b15e2077a2 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -5,7 +5,7 @@ import { Context, PostStatus, RawField, - WithEdits, + EditedRecord, WithoutNevers, } from './common'; @@ -83,4 +83,4 @@ export type WpTemplatePart< C extends Context > = WithoutNevers< FullWpTemplatePart< C > >; export interface EditedWpTemplatePart - extends WithEdits< WpTemplatePart< 'edit' >, 'title' | 'content' > {} + extends EditedRecord< WpTemplatePart< 'edit' >, 'title' | 'content' > {} From a20c2a1d24cf5e4191b531ae25c86ce29951b289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:01:43 +0100 Subject: [PATCH 17/73] Rename "Edited" to "Updatable" --- packages/core-data/src/types/attachment.ts | 6 +- packages/core-data/src/types/comment.ts | 6 +- packages/core-data/src/types/common.ts | 2 +- packages/core-data/src/types/index.ts | 78 +++++++++---------- packages/core-data/src/types/menu-location.ts | 2 +- packages/core-data/src/types/nav_menu.ts | 2 +- packages/core-data/src/types/nav_menu_item.ts | 6 +- .../core-data/src/types/navigation-area.ts | 2 +- packages/core-data/src/types/page.ts | 6 +- packages/core-data/src/types/plugin.ts | 6 +- packages/core-data/src/types/post.ts | 6 +- packages/core-data/src/types/settings.ts | 6 +- packages/core-data/src/types/sidebar.ts | 2 +- packages/core-data/src/types/taxonomy.ts | 6 +- packages/core-data/src/types/theme.ts | 6 +- packages/core-data/src/types/type.ts | 2 +- packages/core-data/src/types/user.ts | 2 +- packages/core-data/src/types/widget-type.ts | 2 +- packages/core-data/src/types/widget.ts | 2 +- packages/core-data/src/types/wp_template.ts | 6 +- .../core-data/src/types/wp_template_part.ts | 6 +- 21 files changed, 81 insertions(+), 81 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 8fceee577b35c..0cab8480d8de4 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -7,7 +7,7 @@ import { MediaType, PostStatus, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -126,8 +126,8 @@ export type Attachment< C extends Context > = WithoutNevers< FullAttachment< C > >; -export interface EditedAttachment - extends EditedRecord< +export interface UpdatableAttachment + extends UpdatableRecord< Attachment< 'edit' >, 'guid' | 'title' | 'description' | 'caption' > {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 819d957e9e61b..131fd93d2d8be 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -6,7 +6,7 @@ import { Context, ContextualField, RawField, - EditedRecord, + UpdatableRecord, } from './common'; interface FullComment< C extends Context > { @@ -81,5 +81,5 @@ interface FullComment< C extends Context > { } export type Comment< C extends Context > = FullComment< C >; -export interface EditedComment - extends EditedRecord< Comment< 'edit' >, 'content' > {} +export interface UpdatableComment + extends UpdatableRecord< Comment< 'edit' >, 'content' > {} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index a0bf943978c5a..67be82547abc6 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -38,7 +38,7 @@ export type ContextualField< C extends Context > = AvailableInContexts extends C ? FieldType : never; -export type EditedRecord< T, Fields > = { +export type UpdatableRecord< T, Fields > = { [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; }; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 157ba80442338..517ec1cf60a75 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,25 +1,25 @@ /** * Internal dependencies */ -import { Attachment, EditedAttachment } from './attachment'; -import { Comment, EditedComment } from './comment'; -import { MenuLocation, EditedMenuLocation } from './menu-location'; -import { NavMenu, EditedNavMenu } from './nav_menu'; -import { NavMenuItem, EditedNavMenuItem } from './nav_menu_item'; -import { NavigationArea, EditedNavigationArea } from './navigation-area'; -import { Page, EditedPage } from './page'; -import { Plugin, EditedPlugin } from './plugin'; -import { Post, EditedPost } from './post'; -import { Settings, EditedSettings } from './settings'; -import { Sidebar, EditedSidebar } from './sidebar'; -import { Taxonomy, EditedTaxonomy } from './taxonomy'; -import { Theme, EditedTheme } from './theme'; -import { User, EditedUser } from './user'; -import { Type, EditedType } from './type'; -import { Widget, EditedWidget } from './widget'; -import { WidgetType, EditedWidgetType } from './widget-type'; -import { WpTemplate, EditedWpTemplate } from './wp_template'; -import { WpTemplatePart, EditedWpTemplatePart } from './wp_template_part'; +import { Attachment, UpdatableAttachment } from './attachment'; +import { Comment, UpdatableComment } from './comment'; +import { MenuLocation, UpdatableMenuLocation } from './menu-location'; +import { NavMenu, UpdatableNavMenu } from './nav_menu'; +import { NavMenuItem, UpdatableNavMenuItem } from './nav_menu_item'; +import { NavigationArea, UpdatableNavigationArea } from './navigation-area'; +import { Page, UpdatablePage } from './page'; +import { Plugin, UpdatablePlugin } from './plugin'; +import { Post, UpdatablePost } from './post'; +import { Settings, UpdatableSettings } from './settings'; +import { Sidebar, UpdatableSidebar } from './sidebar'; +import { Taxonomy, UpdatableTaxonomy } from './taxonomy'; +import { Theme, UpdatableTheme } from './theme'; +import { User, UpdatableUser } from './user'; +import { Type, UpdatableType } from './type'; +import { Widget, UpdatableWidget } from './widget'; +import { WidgetType, UpdatableWidgetType } from './widget-type'; +import { WpTemplate, UpdatableWpTemplate } from './wp_template'; +import { WpTemplatePart, UpdatableWpTemplatePart } from './wp_template_part'; import { Context } from './common'; export type EntityRecord< C extends Context > = @@ -43,23 +43,23 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; -export type EditedEntityRecord = - | EditedAttachment - | EditedComment - | EditedMenuLocation - | EditedNavMenu - | EditedNavMenuItem - | EditedNavigationArea - | EditedPage - | EditedPlugin - | EditedPost - | EditedSettings - | EditedSidebar - | EditedTaxonomy - | EditedTheme - | EditedType - | EditedUser - | EditedWidget - | EditedWidgetType - | EditedWpTemplate - | EditedWpTemplatePart; +export type UpdatableEntityRecord = + | UpdatableAttachment + | UpdatableComment + | UpdatableMenuLocation + | UpdatableNavMenu + | UpdatableNavMenuItem + | UpdatableNavigationArea + | UpdatablePage + | UpdatablePlugin + | UpdatablePost + | UpdatableSettings + | UpdatableSidebar + | UpdatableTaxonomy + | UpdatableTheme + | UpdatableType + | UpdatableUser + | UpdatableWidget + | UpdatableWidgetType + | UpdatableWpTemplate + | UpdatableWpTemplatePart; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index eb61ee9264375..931f315000b63 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -21,4 +21,4 @@ interface FullMenuLocation< C extends Context > { export type MenuLocation< C extends Context > = WithoutNevers< FullMenuLocation< C > >; -export interface EditedMenuLocation extends MenuLocation< 'edit' > {} +export interface UpdatableMenuLocation extends MenuLocation< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 6e6a8ad74d1e9..be08b18717b43 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -35,4 +35,4 @@ interface FullNavMenu< C extends Context > { } export type NavMenu< C extends Context > = WithoutNevers< FullNavMenu< C > >; -export interface EditedNavMenu extends NavMenu< 'edit' > {} +export interface UpdatableNavMenu extends NavMenu< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 820d6e82d7fab..d7976d5c6fa1e 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -3,7 +3,7 @@ */ import { RawField, - EditedRecord, + UpdatableRecord, Context, ContextualField, WithoutNevers, @@ -105,5 +105,5 @@ export type NavMenuItem< C extends Context > = WithoutNevers< FullNavMenuItem< C > >; -export interface EditedNavMenuItem - extends EditedRecord< NavMenuItem< 'edit' >, 'title' > {} +export interface UpdatableNavMenuItem + extends UpdatableRecord< NavMenuItem< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 8822e3e20e9c4..7669352cb4fa3 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -22,4 +22,4 @@ export type NavigationArea< C extends Context > = WithoutNevers< FullNavigationArea< C > >; -export interface EditedNavigationArea extends FullNavigationArea< 'edit' > {} +export interface UpdatableNavigationArea extends FullNavigationArea< 'edit' > {} diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 76c5329940c09..bf2bfafdaf4b8 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -8,7 +8,7 @@ import { PingStatus, PostStatus, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -136,8 +136,8 @@ interface FullPage< C extends Context > { export type Page< C extends Context > = WithoutNevers< FullPage< C > >; -export interface EditedPage - extends EditedRecord< +export interface UpdatablePage + extends UpdatableRecord< Page< 'edit' >, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index a0ecd86652d89..787097dce5e6d 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -5,7 +5,7 @@ import { Context, ContextualField, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -62,5 +62,5 @@ interface FullPlugin< C extends Context > { export type PluginStatus = 'active' | 'inactive'; export type Plugin< C extends Context > = WithoutNevers< FullPlugin< C > >; -export interface EditedPlugin - extends EditedRecord< Plugin< 'edit' >, 'description' > {} +export interface UpdatablePlugin + extends UpdatableRecord< Plugin< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 879b9ce087994..003e2eab31f89 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -9,7 +9,7 @@ import { PostFormat, PostStatus, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -145,8 +145,8 @@ interface FullPost< C extends Context > { export type Post< C extends Context > = WithoutNevers< FullPost< C > >; -export interface EditedPost - extends EditedRecord< +export interface UpdatablePost + extends UpdatableRecord< Post< 'edit' >, 'guid' | 'title' | 'content' | 'excerpt' > {} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index b78d24e43399c..2894a9f832cc1 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -5,7 +5,7 @@ import { CommentStatus, Context, PingStatus, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -89,5 +89,5 @@ interface FullSettings< C extends Context > { } export type Settings< C extends Context > = WithoutNevers< FullSettings< C > >; -export interface EditedSettings - extends EditedRecord< Settings< 'edit' >, 'description' > {} +export interface UpdatableSettings + extends UpdatableRecord< Settings< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 41d5b48e53693..1fe0409b3ac49 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -51,4 +51,4 @@ type SidebarStatus = 'active' | 'inactive'; type NestedWidget< C extends Context > = Widget< C > | string; export type Sidebar< C extends Context > = WithoutNevers< FullSidebar< C > >; -export interface EditedSidebar extends Sidebar< 'edit' > {} +export interface UpdatableSidebar extends Sidebar< 'edit' > {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 3ad44b5b505ec..c4433aec88d3a 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -4,7 +4,7 @@ import { Context, ContextualField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -83,5 +83,5 @@ export interface TaxonomyVisibility { } export type Taxonomy< C extends Context > = WithoutNevers< FullTaxonomy< C > >; -export interface EditedTaxonomy - extends EditedRecord< Taxonomy< 'edit' >, 'description' > {} +export interface UpdatableTaxonomy + extends UpdatableRecord< Taxonomy< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 71f8e7b8ae53f..822f9997acdb7 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -5,7 +5,7 @@ import { Context, PostFormat, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -219,8 +219,8 @@ export type Html5Option = export type Theme< C extends Context > = WithoutNevers< FullTheme< C > >; -export interface EditedTheme - extends EditedRecord< +export interface UpdatableTheme + extends UpdatableRecord< Theme< 'edit' >, 'author' | 'author_uri' | 'description' | 'name' | 'tags' | 'theme_uri' > {} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 131a0b09678b4..f33dba3d84b28 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -66,4 +66,4 @@ interface TypeVisibility { } export type Type< C extends Context > = WithoutNevers< FullType< C > >; -export interface EditedType extends Type< 'edit' > {} +export interface UpdatableType extends Type< 'edit' > {} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index cf34a66e03be4..877eb7ca6f0d5 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -83,4 +83,4 @@ interface FullUser< C extends Context > { } export type User< C extends Context > = WithoutNevers< FullUser< C > >; -export interface EditedUser extends User< 'edit' > {} +export interface UpdatableUser extends User< 'edit' > {} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 0c9e0f778866c..2e7a3ae6ade79 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -29,4 +29,4 @@ interface FullWidgetType< C extends Context > { export type WidgetType< C extends Context > = WithoutNevers< FullWidgetType< C > >; -export interface EditedWidgetType extends WidgetType< 'edit' > {} +export interface UpdatableWidgetType extends WidgetType< 'edit' > {} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 269e53c26ff4e..55a434c90ee78 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -50,4 +50,4 @@ interface WidgetInstance { } export type Widget< C extends Context > = WithoutNevers< FullWidget< C > >; -export interface EditedWidget extends Widget< 'edit' > {} +export interface UpdatableWidget extends Widget< 'edit' > {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 9eb36edfc456d..f00513d97e4cc 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -5,7 +5,7 @@ import { Context, PostStatus, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -82,5 +82,5 @@ interface FullWpTemplate< C extends Context > { export type WpTemplate< C extends Context > = WithoutNevers< FullWpTemplate< C > >; -export interface EditedWpTemplate - extends EditedRecord< WpTemplate< 'edit' >, 'title' > {} +export interface UpdatableWpTemplate + extends UpdatableRecord< WpTemplate< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index a49b15e2077a2..5839326ca2a51 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -5,7 +5,7 @@ import { Context, PostStatus, RawField, - EditedRecord, + UpdatableRecord, WithoutNevers, } from './common'; @@ -82,5 +82,5 @@ interface FullWpTemplatePart< C extends Context > { export type WpTemplatePart< C extends Context > = WithoutNevers< FullWpTemplatePart< C > >; -export interface EditedWpTemplatePart - extends EditedRecord< WpTemplatePart< 'edit' >, 'title' | 'content' > {} +export interface UpdatableWpTemplatePart + extends UpdatableRecord< WpTemplatePart< 'edit' >, 'title' | 'content' > {} From 539f7c2a6d1b8f9b7355f325b4d5f72ce8b22cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:33:59 +0100 Subject: [PATCH 18/73] Flatten Nevers and WithoutNevers to OmitNevers --- packages/core-data/src/types/attachment.ts | 6 ++---- packages/core-data/src/types/common.ts | 17 +++++++---------- packages/core-data/src/types/menu-location.ts | 4 ++-- packages/core-data/src/types/nav_menu.ts | 4 ++-- packages/core-data/src/types/nav_menu_item.ts | 4 ++-- packages/core-data/src/types/navigation-area.ts | 4 ++-- packages/core-data/src/types/page.ts | 4 ++-- packages/core-data/src/types/plugin.ts | 4 ++-- packages/core-data/src/types/post.ts | 4 ++-- packages/core-data/src/types/settings.ts | 4 ++-- packages/core-data/src/types/sidebar.ts | 4 ++-- packages/core-data/src/types/taxonomy.ts | 4 ++-- packages/core-data/src/types/theme.ts | 4 ++-- packages/core-data/src/types/type.ts | 4 ++-- packages/core-data/src/types/user.ts | 4 ++-- packages/core-data/src/types/widget-type.ts | 6 ++---- packages/core-data/src/types/widget.ts | 4 ++-- packages/core-data/src/types/wp_template.ts | 6 ++---- .../core-data/src/types/wp_template_part.ts | 4 ++-- 19 files changed, 43 insertions(+), 52 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 0cab8480d8de4..57d9dc934a731 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -8,7 +8,7 @@ import { PostStatus, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullAttachment< C extends Context > { @@ -122,9 +122,7 @@ interface FullAttachment< C extends Context > { missing_image_sizes: ContextualField< string[], 'edit', C >; } -export type Attachment< C extends Context > = WithoutNevers< - FullAttachment< C > ->; +export type Attachment< C extends Context > = OmitNevers< FullAttachment< C > >; export interface UpdatableAttachment extends UpdatableRecord< diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 67be82547abc6..b5cc64140094e 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -42,25 +42,22 @@ export type UpdatableRecord< T, Fields > = { [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; }; -type Without< +export type OmitNevers< T, - V, - WithNevers = { - [ K in keyof T ]: Exclude< T[ K ], undefined > extends V + Nevers = { + [ K in keyof T ]: Exclude< T[ K ], undefined > extends never ? never : T[ K ] extends Record< string, unknown > - ? Without< T[ K ], V > + ? OmitNevers< T[ K ] > : T[ K ]; } > = Pick< - WithNevers, + Nevers, { - [ K in keyof WithNevers ]: WithNevers[ K ] extends never ? never : K; - }[ keyof WithNevers ] + [ K in keyof Nevers ]: Nevers[ K ] extends never ? never : K; + }[ keyof Nevers ] >; -export type WithoutNevers< T > = Without< T, never >; - /** * The raw data representation. */ diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 931f315000b63..ba130dd7d8b4d 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, WithoutNevers } from './common'; +import { Context, OmitNevers } from './common'; interface FullMenuLocation< C extends Context > { /** @@ -18,7 +18,7 @@ interface FullMenuLocation< C extends Context > { menu: number; } -export type MenuLocation< C extends Context > = WithoutNevers< +export type MenuLocation< C extends Context > = OmitNevers< FullMenuLocation< C > >; export interface UpdatableMenuLocation extends MenuLocation< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index be08b18717b43..6b8696fa3d0ff 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, WithoutNevers } from './common'; +import { Context, OmitNevers } from './common'; interface FullNavMenu< C extends Context > { /** @@ -34,5 +34,5 @@ interface FullNavMenu< C extends Context > { auto_add?: boolean; } -export type NavMenu< C extends Context > = WithoutNevers< FullNavMenu< C > >; +export type NavMenu< C extends Context > = OmitNevers< FullNavMenu< C > >; export interface UpdatableNavMenu extends NavMenu< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index d7976d5c6fa1e..78deb2f2e3db7 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -6,7 +6,7 @@ import { UpdatableRecord, Context, ContextualField, - WithoutNevers, + OmitNevers, } from './common'; /** @@ -101,7 +101,7 @@ interface FullNavMenuItem< C extends Context > { meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export type NavMenuItem< C extends Context > = WithoutNevers< +export type NavMenuItem< C extends Context > = OmitNevers< FullNavMenuItem< C > >; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 7669352cb4fa3..6db36db2a144c 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, WithoutNevers } from './common'; +import { Context, OmitNevers } from './common'; interface FullNavigationArea< C extends Context > { /** @@ -18,7 +18,7 @@ interface FullNavigationArea< C extends Context > { navigation: number; } -export type NavigationArea< C extends Context > = WithoutNevers< +export type NavigationArea< C extends Context > = OmitNevers< FullNavigationArea< C > >; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index bf2bfafdaf4b8..2f5e9bbfac94f 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -9,7 +9,7 @@ import { PostStatus, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullPage< C extends Context > { @@ -134,7 +134,7 @@ interface FullPage< C extends Context > { template: ContextualField< string, 'view' | 'edit', C >; } -export type Page< C extends Context > = WithoutNevers< FullPage< C > >; +export type Page< C extends Context > = OmitNevers< FullPage< C > >; export interface UpdatablePage extends UpdatableRecord< diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 787097dce5e6d..08370e5624f92 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -6,7 +6,7 @@ import { ContextualField, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullPlugin< C extends Context > { @@ -61,6 +61,6 @@ interface FullPlugin< C extends Context > { } export type PluginStatus = 'active' | 'inactive'; -export type Plugin< C extends Context > = WithoutNevers< FullPlugin< C > >; +export type Plugin< C extends Context > = OmitNevers< FullPlugin< C > >; export interface UpdatablePlugin extends UpdatableRecord< Plugin< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 003e2eab31f89..8cb2f036d8919 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -10,7 +10,7 @@ import { PostStatus, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullPost< C extends Context > { @@ -143,7 +143,7 @@ interface FullPost< C extends Context > { tags: ContextualField< number[], 'view' | 'edit', C >; } -export type Post< C extends Context > = WithoutNevers< FullPost< C > >; +export type Post< C extends Context > = OmitNevers< FullPost< C > >; export interface UpdatablePost extends UpdatableRecord< diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 2894a9f832cc1..d6be27ee868ef 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -6,7 +6,7 @@ import { Context, PingStatus, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullSettings< C extends Context > { @@ -88,6 +88,6 @@ interface FullSettings< C extends Context > { site_icon: number; } -export type Settings< C extends Context > = WithoutNevers< FullSettings< C > >; +export type Settings< C extends Context > = OmitNevers< FullSettings< C > >; export interface UpdatableSettings extends UpdatableRecord< Settings< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 1fe0409b3ac49..deda6b0e3c96a 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { Widget } from './widget'; -import { Context, WithoutNevers } from './common'; +import { Context, OmitNevers } from './common'; interface FullSidebar< C extends Context > { /** @@ -50,5 +50,5 @@ interface FullSidebar< C extends Context > { type SidebarStatus = 'active' | 'inactive'; type NestedWidget< C extends Context > = Widget< C > | string; -export type Sidebar< C extends Context > = WithoutNevers< FullSidebar< C > >; +export type Sidebar< C extends Context > = OmitNevers< FullSidebar< C > >; export interface UpdatableSidebar extends Sidebar< 'edit' > {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index c4433aec88d3a..d0e6124c6cee0 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -5,7 +5,7 @@ import { Context, ContextualField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullTaxonomy< C extends Context > { @@ -82,6 +82,6 @@ export interface TaxonomyVisibility { show_in_quick_edit: boolean; } -export type Taxonomy< C extends Context > = WithoutNevers< FullTaxonomy< C > >; +export type Taxonomy< C extends Context > = OmitNevers< FullTaxonomy< C > >; export interface UpdatableTaxonomy extends UpdatableRecord< Taxonomy< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 822f9997acdb7..86740dd37dc72 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -6,7 +6,7 @@ import { PostFormat, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullTheme< C extends Context > { @@ -217,7 +217,7 @@ export type Html5Option = | 'script' | 'style'; -export type Theme< C extends Context > = WithoutNevers< FullTheme< C > >; +export type Theme< C extends Context > = OmitNevers< FullTheme< C > >; export interface UpdatableTheme extends UpdatableRecord< diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index f33dba3d84b28..ebdb98643ce66 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, WithoutNevers, ContextualField } from './common'; +import { Context, OmitNevers, ContextualField } from './common'; interface FullType< C extends Context > { /** @@ -65,5 +65,5 @@ interface TypeVisibility { show_in_nav_menus: boolean; } -export type Type< C extends Context > = WithoutNevers< FullType< C > >; +export type Type< C extends Context > = OmitNevers< FullType< C > >; export interface UpdatableType extends Type< 'edit' > {} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 877eb7ca6f0d5..7edb3003e1c5f 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField, WithoutNevers } from './common'; +import { AvatarUrls, Context, ContextualField, OmitNevers } from './common'; interface FullUser< C extends Context > { /** @@ -82,5 +82,5 @@ interface FullUser< C extends Context > { meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export type User< C extends Context > = WithoutNevers< FullUser< C > >; +export type User< C extends Context > = OmitNevers< FullUser< C > >; export interface UpdatableUser extends User< 'edit' > {} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 2e7a3ae6ade79..30f57240d9102 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, WithoutNevers } from './common'; +import { Context, OmitNevers } from './common'; interface FullWidgetType< C extends Context > { /** @@ -26,7 +26,5 @@ interface FullWidgetType< C extends Context > { classname: string; } -export type WidgetType< C extends Context > = WithoutNevers< - FullWidgetType< C > ->; +export type WidgetType< C extends Context > = OmitNevers< FullWidgetType< C > >; export interface UpdatableWidgetType extends WidgetType< 'edit' > {} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 55a434c90ee78..e16815728ec9b 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, WithoutNevers } from './common'; +import { Context, ContextualField, OmitNevers } from './common'; interface FullWidget< C extends Context > { /** @@ -49,5 +49,5 @@ interface WidgetInstance { raw?: Record< string, string >; } -export type Widget< C extends Context > = WithoutNevers< FullWidget< C > >; +export type Widget< C extends Context > = OmitNevers< FullWidget< C > >; export interface UpdatableWidget extends Widget< 'edit' > {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index f00513d97e4cc..551e47996e311 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -6,7 +6,7 @@ import { PostStatus, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullWpTemplate< C extends Context > { @@ -79,8 +79,6 @@ interface FullWpTemplate< C extends Context > { is_custom: Record< string, string >; } -export type WpTemplate< C extends Context > = WithoutNevers< - FullWpTemplate< C > ->; +export type WpTemplate< C extends Context > = OmitNevers< FullWpTemplate< C > >; export interface UpdatableWpTemplate extends UpdatableRecord< WpTemplate< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 5839326ca2a51..a6c43e4ae89b6 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -6,7 +6,7 @@ import { PostStatus, RawField, UpdatableRecord, - WithoutNevers, + OmitNevers, } from './common'; interface FullWpTemplatePart< C extends Context > { @@ -79,7 +79,7 @@ interface FullWpTemplatePart< C extends Context > { area: string; } -export type WpTemplatePart< C extends Context > = WithoutNevers< +export type WpTemplatePart< C extends Context > = OmitNevers< FullWpTemplatePart< C > >; export interface UpdatableWpTemplatePart From 1c420c085b992bc4a6e3dc61b948f6f9c0eebb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:38:03 +0100 Subject: [PATCH 19/73] Remove dedicated updatable fields in favor of an Updateble type wrapper --- packages/core-data/src/types/attachment.ts | 6 -- packages/core-data/src/types/comment.ts | 2 - packages/core-data/src/types/common.ts | 4 +- packages/core-data/src/types/index.ts | 59 ++++++------------- packages/core-data/src/types/menu-location.ts | 1 - packages/core-data/src/types/nav_menu.ts | 1 - packages/core-data/src/types/nav_menu_item.ts | 3 - .../core-data/src/types/navigation-area.ts | 2 - packages/core-data/src/types/page.ts | 6 -- packages/core-data/src/types/plugin.ts | 2 - packages/core-data/src/types/post.ts | 6 -- packages/core-data/src/types/settings.ts | 2 - packages/core-data/src/types/sidebar.ts | 1 - packages/core-data/src/types/taxonomy.ts | 2 - packages/core-data/src/types/theme.ts | 6 -- packages/core-data/src/types/type.ts | 1 - packages/core-data/src/types/user.ts | 1 - packages/core-data/src/types/widget-type.ts | 1 - packages/core-data/src/types/widget.ts | 1 - packages/core-data/src/types/wp_template.ts | 2 - .../core-data/src/types/wp_template_part.ts | 2 - 21 files changed, 21 insertions(+), 90 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 57d9dc934a731..1b34d0f40abce 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -123,9 +123,3 @@ interface FullAttachment< C extends Context > { } export type Attachment< C extends Context > = OmitNevers< FullAttachment< C > >; - -export interface UpdatableAttachment - extends UpdatableRecord< - Attachment< 'edit' >, - 'guid' | 'title' | 'description' | 'caption' - > {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 131fd93d2d8be..b3516b3a2eac1 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -81,5 +81,3 @@ interface FullComment< C extends Context > { } export type Comment< C extends Context > = FullComment< C >; -export interface UpdatableComment - extends UpdatableRecord< Comment< 'edit' >, 'content' > {} diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index b5cc64140094e..e1e02d9affcbf 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -38,8 +38,8 @@ export type ContextualField< C extends Context > = AvailableInContexts extends C ? FieldType : never; -export type UpdatableRecord< T, Fields > = { - [ Key in keyof T ]: Key extends Fields ? string : T[ Key ]; +export type UpdatableRecord< T > = { + [ K in keyof T ]: T[ K ] extends RawField< any > ? string : T[ K ]; }; export type OmitNevers< diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 517ec1cf60a75..07832797a77be 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,25 +1,25 @@ /** * Internal dependencies */ -import { Attachment, UpdatableAttachment } from './attachment'; -import { Comment, UpdatableComment } from './comment'; -import { MenuLocation, UpdatableMenuLocation } from './menu-location'; -import { NavMenu, UpdatableNavMenu } from './nav_menu'; -import { NavMenuItem, UpdatableNavMenuItem } from './nav_menu_item'; -import { NavigationArea, UpdatableNavigationArea } from './navigation-area'; -import { Page, UpdatablePage } from './page'; -import { Plugin, UpdatablePlugin } from './plugin'; -import { Post, UpdatablePost } from './post'; -import { Settings, UpdatableSettings } from './settings'; -import { Sidebar, UpdatableSidebar } from './sidebar'; -import { Taxonomy, UpdatableTaxonomy } from './taxonomy'; -import { Theme, UpdatableTheme } from './theme'; -import { User, UpdatableUser } from './user'; -import { Type, UpdatableType } from './type'; -import { Widget, UpdatableWidget } from './widget'; -import { WidgetType, UpdatableWidgetType } from './widget-type'; -import { WpTemplate, UpdatableWpTemplate } from './wp_template'; -import { WpTemplatePart, UpdatableWpTemplatePart } from './wp_template_part'; +import { Attachment } from './attachment'; +import { Comment } from './comment'; +import { MenuLocation } from './menu-location'; +import { NavMenu } from './nav_menu'; +import { NavMenuItem } from './nav_menu_item'; +import { NavigationArea } from './navigation-area'; +import { Page } from './page'; +import { Plugin } from './plugin'; +import { Post } from './post'; +import { Settings } from './settings'; +import { Sidebar } from './sidebar'; +import { Taxonomy } from './taxonomy'; +import { Theme } from './theme'; +import { User } from './user'; +import { Type } from './type'; +import { Widget } from './widget'; +import { WidgetType } from './widget-type'; +import { WpTemplate } from './wp_template'; +import { WpTemplatePart } from './wp_template_part'; import { Context } from './common'; export type EntityRecord< C extends Context > = @@ -42,24 +42,3 @@ export type EntityRecord< C extends Context > = | WidgetType< C > | WpTemplate< C > | WpTemplatePart< C >; - -export type UpdatableEntityRecord = - | UpdatableAttachment - | UpdatableComment - | UpdatableMenuLocation - | UpdatableNavMenu - | UpdatableNavMenuItem - | UpdatableNavigationArea - | UpdatablePage - | UpdatablePlugin - | UpdatablePost - | UpdatableSettings - | UpdatableSidebar - | UpdatableTaxonomy - | UpdatableTheme - | UpdatableType - | UpdatableUser - | UpdatableWidget - | UpdatableWidgetType - | UpdatableWpTemplate - | UpdatableWpTemplatePart; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index ba130dd7d8b4d..eebde64fe3401 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -21,4 +21,3 @@ interface FullMenuLocation< C extends Context > { export type MenuLocation< C extends Context > = OmitNevers< FullMenuLocation< C > >; -export interface UpdatableMenuLocation extends MenuLocation< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 6b8696fa3d0ff..893ff4e6ef763 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -35,4 +35,3 @@ interface FullNavMenu< C extends Context > { } export type NavMenu< C extends Context > = OmitNevers< FullNavMenu< C > >; -export interface UpdatableNavMenu extends NavMenu< 'edit' > {} diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 78deb2f2e3db7..aa5dd22554535 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -104,6 +104,3 @@ interface FullNavMenuItem< C extends Context > { export type NavMenuItem< C extends Context > = OmitNevers< FullNavMenuItem< C > >; - -export interface UpdatableNavMenuItem - extends UpdatableRecord< NavMenuItem< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 6db36db2a144c..10c239c09dd5c 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -21,5 +21,3 @@ interface FullNavigationArea< C extends Context > { export type NavigationArea< C extends Context > = OmitNevers< FullNavigationArea< C > >; - -export interface UpdatableNavigationArea extends FullNavigationArea< 'edit' > {} diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 2f5e9bbfac94f..9519918da096b 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -135,9 +135,3 @@ interface FullPage< C extends Context > { } export type Page< C extends Context > = OmitNevers< FullPage< C > >; - -export interface UpdatablePage - extends UpdatableRecord< - Page< 'edit' >, - 'guid' | 'title' | 'content' | 'excerpt' - > {} diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 08370e5624f92..3242d81677332 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -62,5 +62,3 @@ interface FullPlugin< C extends Context > { export type PluginStatus = 'active' | 'inactive'; export type Plugin< C extends Context > = OmitNevers< FullPlugin< C > >; -export interface UpdatablePlugin - extends UpdatableRecord< Plugin< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 8cb2f036d8919..25b9cc6c352a8 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -144,9 +144,3 @@ interface FullPost< C extends Context > { } export type Post< C extends Context > = OmitNevers< FullPost< C > >; - -export interface UpdatablePost - extends UpdatableRecord< - Post< 'edit' >, - 'guid' | 'title' | 'content' | 'excerpt' - > {} diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index d6be27ee868ef..54b056d2ab1a6 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -89,5 +89,3 @@ interface FullSettings< C extends Context > { } export type Settings< C extends Context > = OmitNevers< FullSettings< C > >; -export interface UpdatableSettings - extends UpdatableRecord< Settings< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index deda6b0e3c96a..4a444282d1f4f 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -51,4 +51,3 @@ type SidebarStatus = 'active' | 'inactive'; type NestedWidget< C extends Context > = Widget< C > | string; export type Sidebar< C extends Context > = OmitNevers< FullSidebar< C > >; -export interface UpdatableSidebar extends Sidebar< 'edit' > {} diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index d0e6124c6cee0..2f74e91171879 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -83,5 +83,3 @@ export interface TaxonomyVisibility { } export type Taxonomy< C extends Context > = OmitNevers< FullTaxonomy< C > >; -export interface UpdatableTaxonomy - extends UpdatableRecord< Taxonomy< 'edit' >, 'description' > {} diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 86740dd37dc72..83eda86f541f9 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -218,9 +218,3 @@ export type Html5Option = | 'style'; export type Theme< C extends Context > = OmitNevers< FullTheme< C > >; - -export interface UpdatableTheme - extends UpdatableRecord< - Theme< 'edit' >, - 'author' | 'author_uri' | 'description' | 'name' | 'tags' | 'theme_uri' - > {} diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index ebdb98643ce66..fb0ee05da9912 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -66,4 +66,3 @@ interface TypeVisibility { } export type Type< C extends Context > = OmitNevers< FullType< C > >; -export interface UpdatableType extends Type< 'edit' > {} diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 7edb3003e1c5f..b59af32ed790a 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -83,4 +83,3 @@ interface FullUser< C extends Context > { } export type User< C extends Context > = OmitNevers< FullUser< C > >; -export interface UpdatableUser extends User< 'edit' > {} diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 30f57240d9102..d7414445e3564 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -27,4 +27,3 @@ interface FullWidgetType< C extends Context > { } export type WidgetType< C extends Context > = OmitNevers< FullWidgetType< C > >; -export interface UpdatableWidgetType extends WidgetType< 'edit' > {} diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index e16815728ec9b..d6706cbeae6fe 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -50,4 +50,3 @@ interface WidgetInstance { } export type Widget< C extends Context > = OmitNevers< FullWidget< C > >; -export interface UpdatableWidget extends Widget< 'edit' > {} diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 551e47996e311..756c8851fc3c2 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -80,5 +80,3 @@ interface FullWpTemplate< C extends Context > { } export type WpTemplate< C extends Context > = OmitNevers< FullWpTemplate< C > >; -export interface UpdatableWpTemplate - extends UpdatableRecord< WpTemplate< 'edit' >, 'title' > {} diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index a6c43e4ae89b6..210b969260f80 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -82,5 +82,3 @@ interface FullWpTemplatePart< C extends Context > { export type WpTemplatePart< C extends Context > = OmitNevers< FullWpTemplatePart< C > >; -export interface UpdatableWpTemplatePart - extends UpdatableRecord< WpTemplatePart< 'edit' >, 'title' | 'content' > {} From 942f15245e4c1b99ab27cafa6f507d464e1979c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:44:02 +0100 Subject: [PATCH 20/73] Remove extra wrappers around types --- packages/core-data/src/types/attachment.ts | 1 - packages/core-data/src/types/comment.ts | 8 +------- packages/core-data/src/types/menu-location.ts | 8 ++------ packages/core-data/src/types/nav_menu.ts | 6 ++---- packages/core-data/src/types/nav_menu_item.ts | 8 +------- packages/core-data/src/types/navigation-area.ts | 8 ++------ packages/core-data/src/types/page.ts | 1 - packages/core-data/src/types/plugin.ts | 8 +------- packages/core-data/src/types/post.ts | 1 - packages/core-data/src/types/settings.ts | 12 ++---------- packages/core-data/src/types/sidebar.ts | 6 ++---- packages/core-data/src/types/taxonomy.ts | 11 ++--------- packages/core-data/src/types/theme.ts | 8 +------- packages/core-data/src/types/type.ts | 6 ++---- packages/core-data/src/types/user.ts | 6 ++---- packages/core-data/src/types/widget-type.ts | 4 +--- packages/core-data/src/types/widget.ts | 6 ++---- packages/core-data/src/types/wp_template.ts | 8 +------- packages/core-data/src/types/wp_template_part.ts | 8 +------- 19 files changed, 25 insertions(+), 99 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 1b34d0f40abce..ec8cb56fd52de 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -7,7 +7,6 @@ import { MediaType, PostStatus, RawField, - UpdatableRecord, OmitNevers, } from './common'; diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index b3516b3a2eac1..40418a03d4741 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - AvatarUrls, - Context, - ContextualField, - RawField, - UpdatableRecord, -} from './common'; +import { AvatarUrls, Context, ContextualField, RawField } from './common'; interface FullComment< C extends Context > { /** diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index eebde64fe3401..b75f535d40b1b 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, OmitNevers } from './common'; +import { Context } from './common'; -interface FullMenuLocation< C extends Context > { +export interface MenuLocation< C extends Context > { /** * The name of the menu location. */ @@ -17,7 +17,3 @@ interface FullMenuLocation< C extends Context > { */ menu: number; } - -export type MenuLocation< C extends Context > = OmitNevers< - FullMenuLocation< C > ->; diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index 893ff4e6ef763..d702d4b025a68 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, OmitNevers } from './common'; +import { Context } from './common'; -interface FullNavMenu< C extends Context > { +export interface NavMenu< C extends Context > { /** * Unique identifier for the term. */ @@ -33,5 +33,3 @@ interface FullNavMenu< C extends Context > { */ auto_add?: boolean; } - -export type NavMenu< C extends Context > = OmitNevers< FullNavMenu< C > >; diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index aa5dd22554535..42ef64a6ad632 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - RawField, - UpdatableRecord, - Context, - ContextualField, - OmitNevers, -} from './common'; +import { RawField, Context, ContextualField, OmitNevers } from './common'; /** * Internal dependencies diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 10c239c09dd5c..484c69a4411a2 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, OmitNevers } from './common'; +import { Context } from './common'; -interface FullNavigationArea< C extends Context > { +export interface NavigationArea< C extends Context > { /** * The name of the navigation area. */ @@ -17,7 +17,3 @@ interface FullNavigationArea< C extends Context > { */ navigation: number; } - -export type NavigationArea< C extends Context > = OmitNevers< - FullNavigationArea< C > ->; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 9519918da096b..9e0b4be8b3408 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -8,7 +8,6 @@ import { PingStatus, PostStatus, RawField, - UpdatableRecord, OmitNevers, } from './common'; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 3242d81677332..c6937b5433b86 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - Context, - ContextualField, - RawField, - UpdatableRecord, - OmitNevers, -} from './common'; +import { Context, ContextualField, RawField, OmitNevers } from './common'; interface FullPlugin< C extends Context > { /** diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 25b9cc6c352a8..be4520d15e602 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -9,7 +9,6 @@ import { PostFormat, PostStatus, RawField, - UpdatableRecord, OmitNevers, } from './common'; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 54b056d2ab1a6..1ab8f64d1f2b0 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,15 +1,9 @@ /** * Internal dependencies */ -import { - CommentStatus, - Context, - PingStatus, - UpdatableRecord, - OmitNevers, -} from './common'; +import { CommentStatus, Context, PingStatus } from './common'; -interface FullSettings< C extends Context > { +export interface Settings< C extends Context > { /** * What to show on the front page */ @@ -87,5 +81,3 @@ interface FullSettings< C extends Context > { */ site_icon: number; } - -export type Settings< C extends Context > = OmitNevers< FullSettings< C > >; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 4a444282d1f4f..98cf8b648055e 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,9 +2,9 @@ * Internal dependencies */ import { Widget } from './widget'; -import { Context, OmitNevers } from './common'; +import { Context } from './common'; -interface FullSidebar< C extends Context > { +export interface Sidebar< C extends Context > { /** * ID of sidebar. */ @@ -49,5 +49,3 @@ interface FullSidebar< C extends Context > { type SidebarStatus = 'active' | 'inactive'; type NestedWidget< C extends Context > = Widget< C > | string; - -export type Sidebar< C extends Context > = OmitNevers< FullSidebar< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 2f74e91171879..d5f32d79b0375 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,14 +1,9 @@ /** * Internal dependencies */ -import { - Context, - ContextualField, - UpdatableRecord, - OmitNevers, -} from './common'; +import { Context, ContextualField } from './common'; -interface FullTaxonomy< C extends Context > { +export interface Taxonomy< C extends Context > { /** * All capabilities used by the taxonomy. */ @@ -81,5 +76,3 @@ export interface TaxonomyVisibility { */ show_in_quick_edit: boolean; } - -export type Taxonomy< C extends Context > = OmitNevers< FullTaxonomy< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 83eda86f541f9..962cbdc8670ed 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - Context, - PostFormat, - RawField, - UpdatableRecord, - OmitNevers, -} from './common'; +import { Context, PostFormat, RawField, OmitNevers } from './common'; interface FullTheme< C extends Context > { /** diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index fb0ee05da9912..f4f8b8e869f43 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, OmitNevers, ContextualField } from './common'; +import { Context, ContextualField } from './common'; -interface FullType< C extends Context > { +export interface Type< C extends Context > { /** * All capabilities used by the post type. */ @@ -64,5 +64,3 @@ interface TypeVisibility { */ show_in_nav_menus: boolean; } - -export type Type< C extends Context > = OmitNevers< FullType< C > >; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index b59af32ed790a..5605aa7fe6782 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField, OmitNevers } from './common'; +import { AvatarUrls, Context, ContextualField } from './common'; -interface FullUser< C extends Context > { +export interface User< C extends Context > { /** * Unique identifier for the user. */ @@ -81,5 +81,3 @@ interface FullUser< C extends Context > { */ meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } - -export type User< C extends Context > = OmitNevers< FullUser< C > >; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index d7414445e3564..2f4f42616c349 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,7 +3,7 @@ */ import { Context, OmitNevers } from './common'; -interface FullWidgetType< C extends Context > { +export interface WidgetType< C extends Context > { /** * Unique slug identifying the widget type. */ @@ -25,5 +25,3 @@ interface FullWidgetType< C extends Context > { */ classname: string; } - -export type WidgetType< C extends Context > = OmitNevers< FullWidgetType< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index d6706cbeae6fe..9e5cd90fba283 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, ContextualField, OmitNevers } from './common'; +import { Context, ContextualField } from './common'; -interface FullWidget< C extends Context > { +export interface Widget< C extends Context > { /** * Unique identifier for the widget. */ @@ -48,5 +48,3 @@ interface WidgetInstance { */ raw?: Record< string, string >; } - -export type Widget< C extends Context > = OmitNevers< FullWidget< C > >; diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 756c8851fc3c2..88f8335bf6289 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - Context, - PostStatus, - RawField, - UpdatableRecord, - OmitNevers, -} from './common'; +import { Context, PostStatus, RawField, OmitNevers } from './common'; interface FullWpTemplate< C extends Context > { /** diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 210b969260f80..a2dd8e7fbe7e9 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,13 +1,7 @@ /** * Internal dependencies */ -import { - Context, - PostStatus, - RawField, - UpdatableRecord, - OmitNevers, -} from './common'; +import { Context, PostStatus, RawField, OmitNevers } from './common'; interface FullWpTemplatePart< C extends Context > { /** From f13eda1938802e66e1730383fe13d67b03ec5f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:45:03 +0100 Subject: [PATCH 21/73] Add missing definitions to NavMenu type --- packages/core-data/src/types/nav_menu.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav_menu.ts index d702d4b025a68..3fd3410398e00 100644 --- a/packages/core-data/src/types/nav_menu.ts +++ b/packages/core-data/src/types/nav_menu.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context } from './common'; +import { Context, ContextualField } from './common'; export interface NavMenu< C extends Context > { /** @@ -11,7 +11,7 @@ export interface NavMenu< C extends Context > { /** * HTML description of the term. */ - description?: string; + description: ContextualField< string, 'view' | 'edit', C >; /** * HTML title for the term. */ @@ -23,13 +23,17 @@ export interface NavMenu< C extends Context > { /** * Meta fields. */ - meta?: Record< string, string >; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; /** * The locations assigned to the menu. */ - locations?: string[]; + locations: ContextualField< string[], 'view' | 'edit', C >; + /** + * The DB ID of the original object this menu item represents, e . g . ID for posts and term_id for categories. + */ + object_id: number; /** * Whether to automatically add top level pages to this menu. */ - auto_add?: boolean; + auto_add: ContextualField< boolean, 'view' | 'edit', C >; } From 433be4f4bccadf7a99e1826bfda7c121b3df3c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:49:03 +0100 Subject: [PATCH 22/73] Use RawField in Page and Post types --- packages/core-data/src/types/page.ts | 10 +--------- packages/core-data/src/types/post.ts | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 9e0b4be8b3408..e9397ebd2c457 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -76,15 +76,7 @@ interface FullPage< C extends Context > { * The content for the post. */ content: ContextualField< - { - /** - * Data as it exists in the database. - */ - raw: ContextualField< string, 'edit', C >; - /** - * Data transformed for display. - */ - rendered: string; + RawField< C > & { /** * Whether the content is protected with a password. */ diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index be4520d15e602..e707ab7f35e72 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -73,15 +73,7 @@ interface FullPost< C extends Context > { * The content for the post. */ content: ContextualField< - { - /** - * Data as it exists in the database. - */ - raw: ContextualField< string, 'edit', C >; - /** - * Data transformed for display. - */ - rendered: string; + RawField< C > & { /** * Whether the content is protected with a password. */ From 62963d9fba96b41f805b68636cb34702b125cc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:52:50 +0100 Subject: [PATCH 23/73] Export UpdatableRecord type --- packages/core-data/src/types/common.ts | 4 ---- packages/core-data/src/types/index.ts | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index e1e02d9affcbf..776465b3f0fae 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -38,10 +38,6 @@ export type ContextualField< C extends Context > = AvailableInContexts extends C ? FieldType : never; -export type UpdatableRecord< T > = { - [ K in keyof T ]: T[ K ] extends RawField< any > ? string : T[ K ]; -}; - export type OmitNevers< T, Nevers = { diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 07832797a77be..5a54c3f396e63 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -20,7 +20,7 @@ import { Widget } from './widget'; import { WidgetType } from './widget-type'; import { WpTemplate } from './wp_template'; import { WpTemplatePart } from './wp_template_part'; -import { Context } from './common'; +import { Context, RawField } from './common'; export type EntityRecord< C extends Context > = | Attachment< C > @@ -42,3 +42,7 @@ export type EntityRecord< C extends Context > = | WidgetType< C > | WpTemplate< C > | WpTemplatePart< C >; + +export type UpdatableRecord< T extends EntityRecord< any > > = { + [ K in keyof T ]: T[ K ] extends RawField< any > ? string : T[ K ]; +}; From 655434228519a670e9654a3307359825c63668a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 13:54:12 +0100 Subject: [PATCH 24/73] Rename RawField to RenderedText --- packages/core-data/src/types/attachment.ts | 8 ++++---- packages/core-data/src/types/comment.ts | 4 ++-- packages/core-data/src/types/common.ts | 2 +- packages/core-data/src/types/index.ts | 4 ++-- packages/core-data/src/types/nav_menu_item.ts | 4 ++-- packages/core-data/src/types/page.ts | 10 +++++----- packages/core-data/src/types/plugin.ts | 4 ++-- packages/core-data/src/types/post.ts | 10 +++++----- packages/core-data/src/types/theme.ts | 14 +++++++------- packages/core-data/src/types/wp_template.ts | 4 ++-- packages/core-data/src/types/wp_template_part.ts | 4 ++-- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index ec8cb56fd52de..df35a28cd75f1 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -6,7 +6,7 @@ import { ContextualField, MediaType, PostStatus, - RawField, + RenderedText, OmitNevers, } from './common'; @@ -22,7 +22,7 @@ interface FullAttachment< C extends Context > { /** * The globally unique identifier for the post. */ - guid: ContextualField< RawField< C >, 'view' | 'edit', C >; + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -62,7 +62,7 @@ interface FullAttachment< C extends Context > { /** * The title for the post. */ - title: RawField< C >; + title: RenderedText< C >; /** * The ID for the author of the post. */ @@ -94,7 +94,7 @@ interface FullAttachment< C extends Context > { /** * The attachment description. */ - description: ContextualField< RawField< C >, 'view' | 'edit', C >; + description: ContextualField< RenderedText< C >, 'view' | 'edit', C >; /** * Attachment type. */ diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 40418a03d4741..b94e5f3b8559f 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField, RawField } from './common'; +import { AvatarUrls, Context, ContextualField, RenderedText } from './common'; interface FullComment< C extends Context > { /** @@ -35,7 +35,7 @@ interface FullComment< C extends Context > { /** * The content for the comment. */ - content: RawField< C >; + content: RenderedText< C >; /** * The date the comment was published, in the site's timezone. */ diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 776465b3f0fae..1699a0932fbb3 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -57,7 +57,7 @@ export type OmitNevers< /** * The raw data representation. */ -export interface RawField< C extends Context > { +export interface RenderedText< C extends Context > { /** * Data as it exists in the database. */ diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 5a54c3f396e63..c35c716cf1101 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -20,7 +20,7 @@ import { Widget } from './widget'; import { WidgetType } from './widget-type'; import { WpTemplate } from './wp_template'; import { WpTemplatePart } from './wp_template_part'; -import { Context, RawField } from './common'; +import { Context, RenderedText } from './common'; export type EntityRecord< C extends Context > = | Attachment< C > @@ -44,5 +44,5 @@ export type EntityRecord< C extends Context > = | WpTemplatePart< C >; export type UpdatableRecord< T extends EntityRecord< any > > = { - [ K in keyof T ]: T[ K ] extends RawField< any > ? string : T[ K ]; + [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ]; }; diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav_menu_item.ts index 42ef64a6ad632..12ef71fc15537 100644 --- a/packages/core-data/src/types/nav_menu_item.ts +++ b/packages/core-data/src/types/nav_menu_item.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { RawField, Context, ContextualField, OmitNevers } from './common'; +import { RenderedText, Context, ContextualField, OmitNevers } from './common'; /** * Internal dependencies @@ -24,7 +24,7 @@ interface FullNavMenuItem< C extends Context > { /** * The title for the object. */ - title: RawField< C >; + title: RenderedText< C >; /** * Unique identifier for the object. */ diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index e9397ebd2c457..1c10d01529ac6 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -7,7 +7,7 @@ import { ContextualField, PingStatus, PostStatus, - RawField, + RenderedText, OmitNevers, } from './common'; @@ -23,7 +23,7 @@ interface FullPage< C extends Context > { /** * The globally unique identifier for the post. */ - guid: ContextualField< RawField< C >, 'view' | 'edit', C >; + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -71,12 +71,12 @@ interface FullPage< C extends Context > { /** * The title for the post. */ - title: RawField< C >; + title: RenderedText< C >; /** * The content for the post. */ content: ContextualField< - RawField< C > & { + RenderedText< C > & { /** * Whether the content is protected with a password. */ @@ -96,7 +96,7 @@ interface FullPage< C extends Context > { /** * The excerpt for the post. */ - excerpt: RawField< C > & { + excerpt: RenderedText< C > & { protected: boolean; }; /** diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index c6937b5433b86..94e1b55e18882 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, RawField, OmitNevers } from './common'; +import { Context, ContextualField, RenderedText, OmitNevers } from './common'; interface FullPlugin< C extends Context > { /** @@ -31,7 +31,7 @@ interface FullPlugin< C extends Context > { /** * The plugin description. */ - description: ContextualField< RawField< 'edit' >, 'view' | 'edit', C >; + description: ContextualField< RenderedText< 'edit' >, 'view' | 'edit', C >; /** * The plugin version number. */ diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index e707ab7f35e72..da500b7fce7b5 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -8,7 +8,7 @@ import { PingStatus, PostFormat, PostStatus, - RawField, + RenderedText, OmitNevers, } from './common'; @@ -24,7 +24,7 @@ interface FullPost< C extends Context > { /** * The globally unique identifier for the post. */ - guid: ContextualField< RawField< C >, 'view' | 'edit', C >; + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; /** * Unique identifier for the post. */ @@ -68,12 +68,12 @@ interface FullPost< C extends Context > { /** * The title for the post. */ - title: RawField< C >; + title: RenderedText< C >; /** * The content for the post. */ content: ContextualField< - RawField< C > & { + RenderedText< C > & { /** * Whether the content is protected with a password. */ @@ -93,7 +93,7 @@ interface FullPost< C extends Context > { /** * The excerpt for the post. */ - excerpt: RawField< C > & { + excerpt: RenderedText< C > & { protected: boolean; }; /** diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 962cbdc8670ed..28d6a3a18ba33 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, PostFormat, RawField, OmitNevers } from './common'; +import { Context, PostFormat, RenderedText, OmitNevers } from './common'; interface FullTheme< C extends Context > { /** @@ -15,19 +15,19 @@ interface FullTheme< C extends Context > { /** * The theme author. */ - author: RawField< 'edit' >; + author: RenderedText< 'edit' >; /** * The website of the theme author. */ - author_uri: RawField< 'edit' >; + author_uri: RenderedText< 'edit' >; /** * A description of the theme. */ - description: RawField< 'edit' >; + description: RenderedText< 'edit' >; /** * The name of the theme. */ - name: RawField< 'edit' >; + name: RenderedText< 'edit' >; /** * The minimum PHP version required for the theme to work. */ @@ -43,7 +43,7 @@ interface FullTheme< C extends Context > { /** * Tags indicating styles and features of the theme. */ - tags: RawField< 'edit' >; + tags: RenderedText< 'edit' >; /** * The theme's text domain. */ @@ -55,7 +55,7 @@ interface FullTheme< C extends Context > { /** * The URI of the theme's webpage. */ - theme_uri: RawField< 'edit' >; + theme_uri: RenderedText< 'edit' >; /** * The theme's current version. */ diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 88f8335bf6289..9e33a7a3f4b2d 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, PostStatus, RawField, OmitNevers } from './common'; +import { Context, PostStatus, RenderedText, OmitNevers } from './common'; interface FullWpTemplate< C extends Context > { /** @@ -46,7 +46,7 @@ interface FullWpTemplate< C extends Context > { /** * Title of template. */ - title: RawField< 'edit' > | string; + title: RenderedText< 'edit' > | string; /** * Description of template. */ diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index a2dd8e7fbe7e9..037e7bcd04690 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, PostStatus, RawField, OmitNevers } from './common'; +import { Context, PostStatus, RenderedText, OmitNevers } from './common'; interface FullWpTemplatePart< C extends Context > { /** @@ -46,7 +46,7 @@ interface FullWpTemplatePart< C extends Context > { /** * Title of template. */ - title: RawField< 'edit' > | string; + title: RenderedText< 'edit' > | string; /** * Description of template. */ From ec99125c00908bd40f44efa60f81dfb0e0af06d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 14:16:29 +0100 Subject: [PATCH 25/73] Export updatable types --- packages/core-data/src/types/index.ts | 49 ++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index c35c716cf1101..57626d64450f4 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -22,6 +22,28 @@ import { WpTemplate } from './wp_template'; import { WpTemplatePart } from './wp_template_part'; import { Context, RenderedText } from './common'; +export { + Attachment, + Comment, + MenuLocation, + NavMenu, + NavMenuItem, + NavigationArea, + Page, + Plugin, + Post, + Settings, + Sidebar, + Taxonomy, + Theme, + User, + Type, + Widget, + WidgetType, + WpTemplate, + WpTemplatePart, +}; + export type EntityRecord< C extends Context > = | Attachment< C > | Comment< C > @@ -43,6 +65,31 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; -export type UpdatableRecord< T extends EntityRecord< any > > = { +export type UpdatableEntityRecord = UpdatableRecord< EntityRecord< 'edit' > >; +export type UpdatableRecord< T extends EntityRecord< 'edit' > > = { [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ]; }; + +export type UpdatableAttachment = UpdatableRecord< Attachment< 'edit' > >; +export type UpdatableComment = UpdatableRecord< Comment< 'edit' > >; +export type UpdatableMenuLocation = UpdatableRecord< MenuLocation< 'edit' > >; +export type UpdatableNavMenu = UpdatableRecord< NavMenu< 'edit' > >; +export type UpdatableNavMenuItem = UpdatableRecord< NavMenuItem< 'edit' > >; +export type UpdatableNavigationArea = UpdatableRecord< + NavigationArea< 'edit' > +>; +export type UpdatablePage = UpdatableRecord< Page< 'edit' > >; +export type UpdatablePlugin = UpdatableRecord< Plugin< 'edit' > >; +export type UpdatablePost = UpdatableRecord< Post< 'edit' > >; +export type UpdatableSettings = UpdatableRecord< Settings< 'edit' > >; +export type UpdatableSidebar = UpdatableRecord< Sidebar< 'edit' > >; +export type UpdatableTaxonomy = UpdatableRecord< Taxonomy< 'edit' > >; +export type UpdatableTheme = UpdatableRecord< Theme< 'edit' > >; +export type UpdatableUser = UpdatableRecord< User< 'edit' > >; +export type UpdatableType = UpdatableRecord< Type< 'edit' > >; +export type UpdatableWidget = UpdatableRecord< Widget< 'edit' > >; +export type UpdatableWidgetType = UpdatableRecord< WidgetType< 'edit' > >; +export type UpdatableWpTemplate = UpdatableRecord< WpTemplate< 'edit' > >; +export type UpdatableWpTemplatePart = UpdatableRecord< + WpTemplatePart< 'edit' > +>; From 4292622dc275792991c6f02dae283ab892e0efa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Feb 2022 14:18:42 +0100 Subject: [PATCH 26/73] Rename UpdatableRecord to Updatable --- packages/core-data/src/types/index.ts | 46 ++++++++++++--------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 57626d64450f4..e3f562999cc7f 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -65,31 +65,27 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; -export type UpdatableEntityRecord = UpdatableRecord< EntityRecord< 'edit' > >; -export type UpdatableRecord< T extends EntityRecord< 'edit' > > = { +export type Updatable< T extends EntityRecord< 'edit' > > = { [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ]; }; -export type UpdatableAttachment = UpdatableRecord< Attachment< 'edit' > >; -export type UpdatableComment = UpdatableRecord< Comment< 'edit' > >; -export type UpdatableMenuLocation = UpdatableRecord< MenuLocation< 'edit' > >; -export type UpdatableNavMenu = UpdatableRecord< NavMenu< 'edit' > >; -export type UpdatableNavMenuItem = UpdatableRecord< NavMenuItem< 'edit' > >; -export type UpdatableNavigationArea = UpdatableRecord< - NavigationArea< 'edit' > ->; -export type UpdatablePage = UpdatableRecord< Page< 'edit' > >; -export type UpdatablePlugin = UpdatableRecord< Plugin< 'edit' > >; -export type UpdatablePost = UpdatableRecord< Post< 'edit' > >; -export type UpdatableSettings = UpdatableRecord< Settings< 'edit' > >; -export type UpdatableSidebar = UpdatableRecord< Sidebar< 'edit' > >; -export type UpdatableTaxonomy = UpdatableRecord< Taxonomy< 'edit' > >; -export type UpdatableTheme = UpdatableRecord< Theme< 'edit' > >; -export type UpdatableUser = UpdatableRecord< User< 'edit' > >; -export type UpdatableType = UpdatableRecord< Type< 'edit' > >; -export type UpdatableWidget = UpdatableRecord< Widget< 'edit' > >; -export type UpdatableWidgetType = UpdatableRecord< WidgetType< 'edit' > >; -export type UpdatableWpTemplate = UpdatableRecord< WpTemplate< 'edit' > >; -export type UpdatableWpTemplatePart = UpdatableRecord< - WpTemplatePart< 'edit' > ->; +export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; +export type UpdatableAttachment = Updatable< Attachment< 'edit' > >; +export type UpdatableComment = Updatable< Comment< 'edit' > >; +export type UpdatableMenuLocation = Updatable< MenuLocation< 'edit' > >; +export type UpdatableNavMenu = Updatable< NavMenu< 'edit' > >; +export type UpdatableNavMenuItem = Updatable< NavMenuItem< 'edit' > >; +export type UpdatableNavigationArea = Updatable< NavigationArea< 'edit' > >; +export type UpdatablePage = Updatable< Page< 'edit' > >; +export type UpdatablePlugin = Updatable< Plugin< 'edit' > >; +export type UpdatablePost = Updatable< Post< 'edit' > >; +export type UpdatableSettings = Updatable< Settings< 'edit' > >; +export type UpdatableSidebar = Updatable< Sidebar< 'edit' > >; +export type UpdatableTaxonomy = Updatable< Taxonomy< 'edit' > >; +export type UpdatableTheme = Updatable< Theme< 'edit' > >; +export type UpdatableUser = Updatable< User< 'edit' > >; +export type UpdatableType = Updatable< Type< 'edit' > >; +export type UpdatableWidget = Updatable< Widget< 'edit' > >; +export type UpdatableWidgetType = Updatable< WidgetType< 'edit' > >; +export type UpdatableWpTemplate = Updatable< WpTemplate< 'edit' > >; +export type UpdatableWpTemplatePart = Updatable< WpTemplatePart< 'edit' > >; From dde6773c28f32906114e89d56cdf34ebda6f6c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 12:31:54 +0100 Subject: [PATCH 27/73] Remove atomic updatable types --- packages/core-data/src/types/index.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index e3f562999cc7f..4fffa8e0b4b6a 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -70,22 +70,3 @@ export type Updatable< T extends EntityRecord< 'edit' > > = { }; export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; -export type UpdatableAttachment = Updatable< Attachment< 'edit' > >; -export type UpdatableComment = Updatable< Comment< 'edit' > >; -export type UpdatableMenuLocation = Updatable< MenuLocation< 'edit' > >; -export type UpdatableNavMenu = Updatable< NavMenu< 'edit' > >; -export type UpdatableNavMenuItem = Updatable< NavMenuItem< 'edit' > >; -export type UpdatableNavigationArea = Updatable< NavigationArea< 'edit' > >; -export type UpdatablePage = Updatable< Page< 'edit' > >; -export type UpdatablePlugin = Updatable< Plugin< 'edit' > >; -export type UpdatablePost = Updatable< Post< 'edit' > >; -export type UpdatableSettings = Updatable< Settings< 'edit' > >; -export type UpdatableSidebar = Updatable< Sidebar< 'edit' > >; -export type UpdatableTaxonomy = Updatable< Taxonomy< 'edit' > >; -export type UpdatableTheme = Updatable< Theme< 'edit' > >; -export type UpdatableUser = Updatable< User< 'edit' > >; -export type UpdatableType = Updatable< Type< 'edit' > >; -export type UpdatableWidget = Updatable< Widget< 'edit' > >; -export type UpdatableWidgetType = Updatable< WidgetType< 'edit' > >; -export type UpdatableWpTemplate = Updatable< WpTemplate< 'edit' > >; -export type UpdatableWpTemplatePart = Updatable< WpTemplatePart< 'edit' > >; From e9ee4d0c71faae2abd4eda5df7bade6eaae1a542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 12:46:47 +0100 Subject: [PATCH 28/73] Adjust Comment status and User locale modeling --- packages/core-data/src/types/comment.ts | 3 ++- packages/core-data/src/types/user.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index b94e5f3b8559f..9d7d6a357eddf 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -3,6 +3,7 @@ */ import { AvatarUrls, Context, ContextualField, RenderedText } from './common'; +export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; interface FullComment< C extends Context > { /** * Unique identifier for the comment. @@ -59,7 +60,7 @@ interface FullComment< C extends Context > { /** * State of the comment. */ - status: ContextualField< string, 'view' | 'edit', C >; + status: ContextualField< CommentStatus, 'view' | 'edit', C >; /** * Type of the comment. */ diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 5605aa7fe6782..987629370ade7 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -43,7 +43,7 @@ export interface User< C extends Context > { /** * Locale for the user. */ - locale: ContextualField< '' | 'en_US', 'edit', C >; + locale: ContextualField< string, 'edit', C >; /** * The nickname for the user. */ From dcdabe5d6f65bdbdab691144d08988fa3ce12e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 12:47:58 +0100 Subject: [PATCH 29/73] Remove the NestedWidget name, declare the type inline in Sidebar --- packages/core-data/src/types/sidebar.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 98cf8b648055e..5f4e58a4f2679 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -44,8 +44,7 @@ export interface Sidebar< C extends Context > { /** * Nested widgets. */ - widgets: NestedWidget< C >[]; + widgets: ( Widget< C > | string )[]; } type SidebarStatus = 'active' | 'inactive'; -type NestedWidget< C extends Context > = Widget< C > | string; From 31e1ea910bc274c7addf16ddccda4a6341b046b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 13:37:51 +0100 Subject: [PATCH 30/73] Make User.password optional --- packages/core-data/src/types/user.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 987629370ade7..88aea56af8592 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -61,9 +61,13 @@ export interface User< C extends Context > { */ roles: ContextualField< string[], 'edit', C >; /** - * Password for the user (never included). + * Password for the user. + * + * This is never sent from the server to the client + * but exists because we might send an update to the + * server with a new password to set. */ - password: string; + password?: string; /** * All capabilities assigned to the user. */ From d81c259ab91b811e674673949dab97dd754641fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 14:24:39 +0100 Subject: [PATCH 31/73] Introduce StringWhenUpdatable type to model WP templates --- packages/core-data/src/types/index.ts | 8 ++++- packages/core-data/src/types/wp_template.ts | 33 +++++++++++-------- .../core-data/src/types/wp_template_part.ts | 33 +++++++++++-------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 4fffa8e0b4b6a..99587a4199fd0 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -65,8 +65,14 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; +export type StringWhenUpdatable< T > = T & { __brand: 'UpdatableAsString' }; + export type Updatable< T extends EntityRecord< 'edit' > > = { - [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ]; + [ K in keyof T ]: T[ K ] extends + | RenderedText< any > + | StringWhenUpdatable< any > + ? string + : T[ K ]; }; export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 9e33a7a3f4b2d..8062c1fb10eb1 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -1,7 +1,14 @@ /** * Internal dependencies */ -import { Context, PostStatus, RenderedText, OmitNevers } from './common'; +import { + Context, + PostStatus, + RenderedText, + OmitNevers, + ContextualField, +} from './common'; +import { StringWhenUpdatable } from './index'; interface FullWpTemplate< C extends Context > { /** @@ -31,22 +38,20 @@ interface FullWpTemplate< C extends Context > { /** * Content of template. */ - content: - | { - /** - * Content for the template, as it exists in the database. - */ - raw?: string; - /** - * Version of the content block format used by the template. - */ - block_version?: number; - } - | string; + content: StringWhenUpdatable< { + /** + * Content for the template, as it exists in the database. + */ + raw: ContextualField< string, 'view' | 'edit', C >; + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + } >; /** * Title of template. */ - title: RenderedText< 'edit' > | string; + title: RenderedText< 'edit' >; /** * Description of template. */ diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 037e7bcd04690..26a54b7c37999 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -1,7 +1,14 @@ /** * Internal dependencies */ -import { Context, PostStatus, RenderedText, OmitNevers } from './common'; +import { + Context, + PostStatus, + RenderedText, + OmitNevers, + ContextualField, +} from './common'; +import { StringWhenUpdatable } from './index'; interface FullWpTemplatePart< C extends Context > { /** @@ -31,22 +38,20 @@ interface FullWpTemplatePart< C extends Context > { /** * Content of template. */ - content: - | { - /** - * Content for the template, as it exists in the database. - */ - raw?: string; - /** - * Version of the content block format used by the template. - */ - block_version?: number; - } - | string; + content: StringWhenUpdatable< { + /** + * Content for the template, as it exists in the database. + */ + raw: ContextualField< string, 'view' | 'edit', C >; + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + } >; /** * Title of template. */ - title: RenderedText< 'edit' > | string; + title: RenderedText< 'edit' >; /** * Description of template. */ From e6193b22302b2db5dfe065bc482cf4c43a651695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 14:25:06 +0100 Subject: [PATCH 32/73] Document the Updatable type --- packages/core-data/src/types/index.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 99587a4199fd0..7f32c30d57f40 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -67,6 +67,33 @@ export type EntityRecord< C extends Context > = export type StringWhenUpdatable< T > = T & { __brand: 'UpdatableAsString' }; +/** + * Updatable is a type describing Edited Entity Records. They are like + * regular Entity Records, but they have all the local edits applied on top of the REST API data. + * + * This turns certain field from an object into a string. + * + * Entities like Post have fields that only be rendered on the server, like title, excerpt, + * and content. The REST API exposes both the raw markup and the rendered version of those fields. + * For example, in the block editor, content.rendered could used as a visual preview, and + * content.raw could be used to populate the code editor. + * + * When updating these rendered fields, Javascript is not be able to properly render arbitrary block + * markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string, + * the entire field becomes a string. + * + * @example + * ```ts + * type Post< C extends Context > { + * title: RenderedText< C >; + * } + * const post = {} as Post; + * // post.title is an object with raw and rendered properties + * + * const updatablePost = {} as Updatable< Post >; + * // updatablePost.title is a string + * ``` + */ export type Updatable< T extends EntityRecord< 'edit' > > = { [ K in keyof T ]: T[ K ] extends | RenderedText< any > From a95ba80df6cb169a89247a7be04c8b8b5033c2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 14:32:46 +0100 Subject: [PATCH 33/73] Document the RenderedText using @dmsnell's proposal --- packages/core-data/src/types/common.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 1699a0932fbb3..9e1f9449452f1 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -55,15 +55,21 @@ export type OmitNevers< >; /** - * The raw data representation. + * A string that the server renders which often involves + * modifications from the raw source string. + * + * For example, block HTML with the comment delimiters exists + * in `post_content` but those comments are stripped out when + * rendering to a page view. Similarly, plugins might modify + * content or replace shortcodes. */ export interface RenderedText< C extends Context > { /** - * Data as it exists in the database. + * The source string which will be rendered on page views. */ raw: ContextualField< string, 'edit', C >; /** - * Data transformed for display. + * The output of the raw source after processing and filtering on the server. */ rendered: string; } From 0e4c63e2f9f815e6b578a83b3dc52bc27446e005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 14:41:19 +0100 Subject: [PATCH 34/73] Document types in common.ts --- packages/core-data/src/types/common.ts | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 9e1f9449452f1..f0471583c26e2 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -31,13 +31,52 @@ export type PostFormat = | 'video' | 'audio'; +/** + * The REST API context parameter. + */ export type Context = 'view' | 'edit' | 'embed'; + +/** + * A wrapper that turns fields unavailable in the current REST API contexts into + * the type `never`. It is typically paired with OmitNevers. + * + * @example + * ```ts + * type MyType< C extends Context > = { + * good: ContextualField< string, 'view' | 'edit', C >; + * bad: ContextualField< string, 'edit', C >; + * } + * + * const a = {} as MyType<'view'>; + * // a.good is of type string + * // b.bad is of type never + * + * const b = {} as OmitNevers>; + * // a.good is of type string + * // there is no property b.bad + * ``` + */ export type ContextualField< FieldType, AvailableInContexts extends Context, C extends Context > = AvailableInContexts extends C ? FieldType : never; +/** + * Removes all the properties of type never, even the deeply nested ones. + * + * @example + * ```ts + * type MyType = { + * foo: string; + * bar: never; + * nested: { + * foo: string; + * bar: never; + * } + * } + * ``` + */ export type OmitNevers< T, Nevers = { From 09fe23a9b00eeeead9f4ab25be3f0e19f7310013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 15:51:58 +0100 Subject: [PATCH 35/73] Flatten the content prop of WpTemplate and WpTemplatePart into a string through a condition inside the Updatable type wrapper --- packages/core-data/src/types/index.ts | 15 ++++++++++----- packages/core-data/src/types/wp_template.ts | 7 ++++--- packages/core-data/src/types/wp_template_part.ts | 7 ++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 7f32c30d57f40..cd6a918e01ddc 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -65,8 +65,6 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; -export type StringWhenUpdatable< T > = T & { __brand: 'UpdatableAsString' }; - /** * Updatable is a type describing Edited Entity Records. They are like * regular Entity Records, but they have all the local edits applied on top of the REST API data. @@ -95,10 +93,17 @@ export type StringWhenUpdatable< T > = T & { __brand: 'UpdatableAsString' }; * ``` */ export type Updatable< T extends EntityRecord< 'edit' > > = { - [ K in keyof T ]: T[ K ] extends - | RenderedText< any > - | StringWhenUpdatable< any > + [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string + : /* + * Explicit handling for WpTemplate and WpTemplatePart. They both have a + * `content` field that needs to be collapsed into a string even though + * it doesn't match the RenderedText signature. + */ + T extends WpTemplate< any > | WpTemplatePart< any > + ? K extends 'content' + ? string + : T[ K ] : T[ K ]; }; diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp_template.ts index 8062c1fb10eb1..5f03023566165 100644 --- a/packages/core-data/src/types/wp_template.ts +++ b/packages/core-data/src/types/wp_template.ts @@ -8,7 +8,6 @@ import { OmitNevers, ContextualField, } from './common'; -import { StringWhenUpdatable } from './index'; interface FullWpTemplate< C extends Context > { /** @@ -37,8 +36,10 @@ interface FullWpTemplate< C extends Context > { origin: string; /** * Content of template. + * + * When used with the `Updatable` type wrapper, it is transformed to a string as a special case. */ - content: StringWhenUpdatable< { + content: { /** * Content for the template, as it exists in the database. */ @@ -47,7 +48,7 @@ interface FullWpTemplate< C extends Context > { * Version of the content block format used by the template. */ block_version: ContextualField< number, 'edit', C >; - } >; + }; /** * Title of template. */ diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp_template_part.ts index 26a54b7c37999..ece7a55b60e8f 100644 --- a/packages/core-data/src/types/wp_template_part.ts +++ b/packages/core-data/src/types/wp_template_part.ts @@ -8,7 +8,6 @@ import { OmitNevers, ContextualField, } from './common'; -import { StringWhenUpdatable } from './index'; interface FullWpTemplatePart< C extends Context > { /** @@ -37,8 +36,10 @@ interface FullWpTemplatePart< C extends Context > { origin: string; /** * Content of template. + * + * When used with the `Updatable` type wrapper, it is transformed to a string as a special case. */ - content: StringWhenUpdatable< { + content: { /** * Content for the template, as it exists in the database. */ @@ -47,7 +48,7 @@ interface FullWpTemplatePart< C extends Context > { * Version of the content block format used by the template. */ block_version: ContextualField< number, 'edit', C >; - } >; + }; /** * Title of template. */ From 4974607419a4384ec22370b7ca884115bbc7fd3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 15:57:48 +0100 Subject: [PATCH 36/73] Type the remaining optional fields more strictly --- packages/core-data/src/types/common.ts | 8 +++----- packages/core-data/src/types/post.ts | 2 +- packages/core-data/src/types/widget.ts | 14 +++++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index f0471583c26e2..4c566968b3344 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -2,17 +2,15 @@ export interface AvatarUrls { /** * Avatar URL with image size of 24 pixels. */ - '24'?: string; + '24': string; /** * Avatar URL with image size of 48 pixels. */ - '48'?: string; + '48': string; /** * Avatar URL with image size of 96 pixels. */ - '96'?: string; - - [ k: string ]: string; + '96': string; } export type MediaType = 'image' | 'file'; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index da500b7fce7b5..05082dba94a5f 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -115,7 +115,7 @@ interface FullPost< C extends Context > { /** * Meta fields. */ - meta?: Record< string, string >; + meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; /** * Whether or not the post should be treated as sticky. */ diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 9e5cd90fba283..7b7c0189ef5b5 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -27,9 +27,13 @@ export interface Widget< C extends Context > { /** * Instance settings of the widget, if supported. */ - instance?: WidgetInstance; + instance: ContextualField< WidgetInstance, 'edit', C >; /** - * URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. + * URL-encoded form data from the widget admin form. Used + * to update a widget that does not support instance. + * + * This is never sent from the server to the client but exists + * because we might send an update. */ form_data?: string; } @@ -38,13 +42,13 @@ interface WidgetInstance { /** * Base64 encoded representation of the instance settings. */ - encoded?: string; + encoded: string; /** * Cryptographic hash of the instance settings. */ - hash?: string; + hash: string; /** * Unencoded instance settings, if supported. */ - raw?: Record< string, string >; + raw: Record< string, string >; } From c086bab8d7123710958ab24d9082504af535168b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 16:11:41 +0100 Subject: [PATCH 37/73] Wrap Type with OmitNevers --- packages/core-data/src/types/type.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index f4f8b8e869f43..2a0e453ac612a 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, ContextualField } from './common'; +import { Context, ContextualField, OmitNevers } from './common'; -export interface Type< C extends Context > { +interface FullType< C extends Context > { /** * All capabilities used by the post type. */ @@ -64,3 +64,5 @@ interface TypeVisibility { */ show_in_nav_menus: boolean; } + +export type Type< C extends Context > = OmitNevers< FullType< C > >; From b4b0dd7e367e2f8a5c77b257a5e9432448170ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 16:12:28 +0100 Subject: [PATCH 38/73] Wrap the type user with OmitNevers --- packages/core-data/src/types/user.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 88aea56af8592..50fc44a01bb94 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField } from './common'; +import { AvatarUrls, Context, ContextualField, OmitNevers } from './common'; -export interface User< C extends Context > { +interface FullUser< C extends Context > { /** * Unique identifier for the user. */ @@ -85,3 +85,5 @@ export interface User< C extends Context > { */ meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } + +export type User< C extends Context > = OmitNevers< FullUser< C > >; From f153a3addd9610008ef8c907ba0f8299a0706f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 16:13:43 +0100 Subject: [PATCH 39/73] Use consistent kebab case in type files --- packages/core-data/src/types/index.ts | 8 ++++---- .../src/types/{nav_menu_item.ts => nav-menu-item.ts} | 0 packages/core-data/src/types/{nav_menu.ts => nav-menu.ts} | 0 .../types/{wp_template_part.ts => wp-template-part.ts} | 0 .../src/types/{wp_template.ts => wp-template.ts} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename packages/core-data/src/types/{nav_menu_item.ts => nav-menu-item.ts} (100%) rename packages/core-data/src/types/{nav_menu.ts => nav-menu.ts} (100%) rename packages/core-data/src/types/{wp_template_part.ts => wp-template-part.ts} (100%) rename packages/core-data/src/types/{wp_template.ts => wp-template.ts} (100%) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index cd6a918e01ddc..77fce4dc55017 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -4,8 +4,8 @@ import { Attachment } from './attachment'; import { Comment } from './comment'; import { MenuLocation } from './menu-location'; -import { NavMenu } from './nav_menu'; -import { NavMenuItem } from './nav_menu_item'; +import { NavMenu } from './nav-menu'; +import { NavMenuItem } from './nav-menu-item'; import { NavigationArea } from './navigation-area'; import { Page } from './page'; import { Plugin } from './plugin'; @@ -18,8 +18,8 @@ import { User } from './user'; import { Type } from './type'; import { Widget } from './widget'; import { WidgetType } from './widget-type'; -import { WpTemplate } from './wp_template'; -import { WpTemplatePart } from './wp_template_part'; +import { WpTemplate } from './wp-template'; +import { WpTemplatePart } from './wp-template-part'; import { Context, RenderedText } from './common'; export { diff --git a/packages/core-data/src/types/nav_menu_item.ts b/packages/core-data/src/types/nav-menu-item.ts similarity index 100% rename from packages/core-data/src/types/nav_menu_item.ts rename to packages/core-data/src/types/nav-menu-item.ts diff --git a/packages/core-data/src/types/nav_menu.ts b/packages/core-data/src/types/nav-menu.ts similarity index 100% rename from packages/core-data/src/types/nav_menu.ts rename to packages/core-data/src/types/nav-menu.ts diff --git a/packages/core-data/src/types/wp_template_part.ts b/packages/core-data/src/types/wp-template-part.ts similarity index 100% rename from packages/core-data/src/types/wp_template_part.ts rename to packages/core-data/src/types/wp-template-part.ts diff --git a/packages/core-data/src/types/wp_template.ts b/packages/core-data/src/types/wp-template.ts similarity index 100% rename from packages/core-data/src/types/wp_template.ts rename to packages/core-data/src/types/wp-template.ts From ee55c45b518d0129b3403a6d123830d4071d8a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 16:17:11 +0100 Subject: [PATCH 40/73] Wrap comment with OmitNevers --- packages/core-data/src/types/comment.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 9d7d6a357eddf..ca0cf5a9076bc 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -1,7 +1,13 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField, RenderedText } from './common'; +import { + AvatarUrls, + Context, + ContextualField, + OmitNevers, + RenderedText, +} from './common'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; interface FullComment< C extends Context > { @@ -75,4 +81,4 @@ interface FullComment< C extends Context > { meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export type Comment< C extends Context > = FullComment< C >; +export type Comment< C extends Context > = OmitNevers< FullComment< C > >; From 9ba701f5af062859605b4e43a76f835f9928144a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 16:19:24 +0100 Subject: [PATCH 41/73] Add the missing OmitNevers to types with contextual fields --- packages/core-data/src/types/nav-menu.ts | 6 ++++-- packages/core-data/src/types/taxonomy.ts | 7 +++++-- packages/core-data/src/types/widget.ts | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index 3fd3410398e00..a866908e741cf 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, ContextualField } from './common'; +import { Context, ContextualField, OmitNevers } from './common'; -export interface NavMenu< C extends Context > { +interface FullNavMenu< C extends Context > { /** * Unique identifier for the term. */ @@ -37,3 +37,5 @@ export interface NavMenu< C extends Context > { */ auto_add: ContextualField< boolean, 'view' | 'edit', C >; } + +export type NavMenu< C extends Context > = OmitNevers< FullNavMenu< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index d5f32d79b0375..8881db2e881bc 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,9 +1,10 @@ /** * Internal dependencies */ -import { Context, ContextualField } from './common'; +import { Context, ContextualField, OmitNevers } from './common'; +import { FullWidget } from "./widget"; -export interface Taxonomy< C extends Context > { +interface FullTaxonomy< C extends Context > { /** * All capabilities used by the taxonomy. */ @@ -76,3 +77,5 @@ export interface TaxonomyVisibility { */ show_in_quick_edit: boolean; } + +export type Taxonomy< C extends Context > = OmitNevers< FullTaxonomy< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 7b7c0189ef5b5..825c0446ee314 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context, ContextualField } from './common'; +import { Context, ContextualField, OmitNevers } from './common'; -export interface Widget< C extends Context > { +export interface FullWidget< C extends Context > { /** * Unique identifier for the widget. */ @@ -52,3 +52,5 @@ interface WidgetInstance { */ raw: Record< string, string >; } + +export type Widget< C extends Context > = OmitNevers< FullWidget< C > >; From b5560c1dc4c560fed8f4e120fe9ebadddd203f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 17:11:02 +0100 Subject: [PATCH 42/73] Add README.md --- packages/core-data/src/types/README.md | 211 +++++++++++++++++++++++ packages/core-data/src/types/common.ts | 3 + packages/core-data/src/types/taxonomy.ts | 2 +- 3 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 packages/core-data/src/types/README.md diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md new file mode 100644 index 0000000000000..31569200d0cb1 --- /dev/null +++ b/packages/core-data/src/types/README.md @@ -0,0 +1,211 @@ +# Entity Records Types + +!THIS IS WORK IN PROGRESS! I used bits of the GitHub discussion as the first draft here + +## Overview + +The types in this directory are designed to support the following use-cases: + +* Context-aware type checks for entity records. +* Static type checks for *edited* entity records, where certain fields become strings instead of objects. + +### Context-aware type checks for entity records + +WordPress REST API returns different responses based on the `context` query parameter, which typically is one of `view`, `edit`, or `embed`. + +For example, requesting `/wp/v2/posts/1?context=view` yields: + +```js +{ + "content": { + "protected": false, + "rendered": "\n

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

\n" + }, + "title": { + "rendered": "Hello world!" + } + // other fields +} +``` + +While requesting `/wp/v2/posts/1?context=edit`, yields: + +```js +{ + "content": { + "block_version": 1, + "protected": false, + "raw": "\n

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

\n", + "rendered": "\n

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

\n" + }, + "title": { + "raw": "Hello world!", + "rendered": "Hello world!" + } + // other fields +} +``` + +And, finally, requesting `/wp/v2/posts/1?context=embed` yields: + +```js +{ + // Note content is missing + "title": { + "rendered": "Hello world!" + } + // other fields +} +``` + +These contexts are supported by the core-data resolvers like `getEntityRecord()` and `getEntityRecords()` to retrieve the appropriate "flavor" of the data. + +The types describing different entity records must thus be aware of the relevant API context. This is implemented using the `Context` type parameter. For example, the implementation of the `Post` type resembles the following snippet: + +```ts +import { OmitNevers } from "./common"; + +interface BasePost { + /** + * A named status for the post. + */ + status: ContextualField< PostStatus, 'view' | 'edit', C >; + + // ... other fields ... +} + +export type Post = OmitNevers>; +``` + +The `status` field of the `BasePost` is either a `PostStatus` when the Context is `view` or `edit`, or it's `never` when the Context is `embed`. + +The derived type `Post` is stripped of all the `never` fields, and so `Post<'embed'>` does not have the `status` type at all. + +### Static type checks for *edited* entity records, where certain fields become strings instead of objects. + +When the `post` is retrieved using `getEntityRecord`, its `content` field is an object: + +```js +const post = wp.data.select('core').getEntityRecord( 'postType', 'post', 1, { context: 'view' } ) +// `post.content` is an object with two fields: protected and rendered +``` + +The block markup stored in `content` can only be rendered on the server so the REST API exposes both the raw markup and the rendered version. For example, `content.rendered` could used as a visual preview, and `content.raw` could be used to populate the code editor. + +The `content` field may still be updated via Javascript, but the updated content cannot be properly rendered without requesting the server. Therefore, it doesn't make sense to keep track the `rendered` when editing. The only remaining part is `raw`, and since that's a string, the entire edited `content` can be expressed a string. + +And this is exactly what you'll see after retrieving the editable version of the record using `getEditedEntityRecord`: + +```js +const post = wp.data.select('core').getEditedEntityRecord( 'postType', 'post', 1 ); +// `post.content` is a string +``` + +## Helpers + +@TODO – perhaps we could auto generate that from the docstrings in common.ts (to become helpers.ts?) + +### Context + +The REST API context parameter. + +### ContextualField + +A wrapper that turns fields unavailable in the current REST API contexts into the type `never`. It is typically paired with OmitNevers. + +Example: + +```ts +type MyType< C extends Context > = { + good: ContextualField< string, 'view' | 'edit', C >; + bad: ContextualField< string, 'edit', C >; +} + +const a = {} as MyType<'view'>; +// a.good is of type string +// b.bad is of type never + +const b = {} as OmitNevers>; +// a.good is of type string +// there is no property b.bad +``` + +### OmitNevers + +Removes all the properties of type never, even the deeply nested ones. + +```ts +type MyType = { + foo: string; + bar: never; + nested: { + foo: string; + bar: never; + } +} +const x = {} as OmitNevers; +// x is of type { foo: string; nested: { foo: string; }} +// The `never` properties were removed entirely +``` + +### Updatable + +Updatable is a type describing Edited Entity Records. They are like +regular Entity Records, but they have all the local edits applied on top of the REST API data. + +This turns certain field from an object into a string. + +Entities like Post have fields that only be rendered on the server, like title, excerpt, +and content. The REST API exposes both the raw markup and the rendered version of those fields. +For example, in the block editor, content.rendered could used as a visual preview, and +content.raw could be used to populate the code editor. + +When updating these rendered fields, Javascript is not be able to properly render arbitrary block +markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string, +the entire field becomes a string. + +```ts +type Post< C extends Context > { + title: RenderedText< C >; +} +const post = {} as Post; +// post.title is an object with raw and rendered properties + +const updatablePost = {} as Updatable< Post >; +// updatablePost.title is a string +``` + +### RenderedText + +A string that the server renders which often involves modifications from the raw source string. + +For example, block HTML with the comment delimiters exists in `post_content` but those comments are stripped out when rendering to a page view. Similarly, plugins might modify content or replace shortcodes. + +## Extending + +Talk about interface merging here + +Change the "full" version of these types to be inside a namespace `wpCoreData.BaseTypes` so that they can be extended. + +```ts +// In core-data +export namespace wpCoreData.BaseTypes { + export interface Comment< C extends Context > { + id: number; + // ... + } +} + +export type Comment< C extends Context > = OmitNevers< + wpCoreData.BaseTypes.Comment< C > +>; + +// In the plugin +namespace wpCoreData.BaseTypes { + interface Comment < C extends Context > { + newField: ContextualField; + } +} +``` + +Interface merging has a huge upside: core-data selectors would return the extended types out of the box. diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/common.ts index 4c566968b3344..c490ac5b66ee3 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/common.ts @@ -73,6 +73,9 @@ export type ContextualField< * bar: never; * } * } + * const x = {} as OmitNevers; + * // x is of type { foo: string; nested: { foo: string; }} + * // The `never` properties were removed entirely * ``` */ export type OmitNevers< diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 8881db2e881bc..535983ceb660f 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { Context, ContextualField, OmitNevers } from './common'; -import { FullWidget } from "./widget"; +import { FullWidget } from './widget'; interface FullTaxonomy< C extends Context > { /** From 8bd4641d20c3224505a3c0ea82e5e55fae4e8bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 18 Feb 2022 17:12:28 +0100 Subject: [PATCH 43/73] Rename common.ts to helpers.ts --- packages/core-data/src/types/README.md | 2 +- packages/core-data/src/types/attachment.ts | 2 +- packages/core-data/src/types/comment.ts | 2 +- .../src/types/{common.ts => helpers.ts} | 49 +++++++++++++++++++ packages/core-data/src/types/index.ts | 45 +---------------- packages/core-data/src/types/menu-location.ts | 2 +- packages/core-data/src/types/nav-menu-item.ts | 2 +- packages/core-data/src/types/nav-menu.ts | 2 +- .../core-data/src/types/navigation-area.ts | 2 +- packages/core-data/src/types/page.ts | 2 +- packages/core-data/src/types/plugin.ts | 2 +- packages/core-data/src/types/post.ts | 2 +- packages/core-data/src/types/settings.ts | 2 +- packages/core-data/src/types/sidebar.ts | 2 +- packages/core-data/src/types/taxonomy.ts | 2 +- packages/core-data/src/types/theme.ts | 2 +- packages/core-data/src/types/type.ts | 2 +- packages/core-data/src/types/user.ts | 2 +- packages/core-data/src/types/widget-type.ts | 2 +- packages/core-data/src/types/widget.ts | 2 +- .../core-data/src/types/wp-template-part.ts | 2 +- packages/core-data/src/types/wp-template.ts | 2 +- 22 files changed, 71 insertions(+), 63 deletions(-) rename packages/core-data/src/types/{common.ts => helpers.ts} (60%) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 31569200d0cb1..f332f409a8621 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -63,7 +63,7 @@ These contexts are supported by the core-data resolvers like `getEntityRecord()` The types describing different entity records must thus be aware of the relevant API context. This is implemented using the `Context` type parameter. For example, the implementation of the `Post` type resembles the following snippet: ```ts -import { OmitNevers } from "./common"; +import { OmitNevers } from "./helpers"; interface BasePost { /** diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index df35a28cd75f1..8524a0acde034 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -8,7 +8,7 @@ import { PostStatus, RenderedText, OmitNevers, -} from './common'; +} from './helpers'; interface FullAttachment< C extends Context > { /** diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index ca0cf5a9076bc..f2f101f5be5ce 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -7,7 +7,7 @@ import { ContextualField, OmitNevers, RenderedText, -} from './common'; +} from './helpers'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; interface FullComment< C extends Context > { diff --git a/packages/core-data/src/types/common.ts b/packages/core-data/src/types/helpers.ts similarity index 60% rename from packages/core-data/src/types/common.ts rename to packages/core-data/src/types/helpers.ts index c490ac5b66ee3..2354e18369978 100644 --- a/packages/core-data/src/types/common.ts +++ b/packages/core-data/src/types/helpers.ts @@ -1,3 +1,10 @@ +/** + * Internal dependencies + */ +import { WpTemplate } from './wp-template'; +import { WpTemplatePart } from './wp-template-part'; +import { EntityRecord } from './index'; + export interface AvatarUrls { /** * Avatar URL with image size of 24 pixels. @@ -113,3 +120,45 @@ export interface RenderedText< C extends Context > { */ rendered: string; } + +/** + * Updatable is a type describing Edited Entity Records. They are like + * regular Entity Records, but they have all the local edits applied on top of the REST API data. + * + * This turns certain field from an object into a string. + * + * Entities like Post have fields that only be rendered on the server, like title, excerpt, + * and content. The REST API exposes both the raw markup and the rendered version of those fields. + * For example, in the block editor, content.rendered could used as a visual preview, and + * content.raw could be used to populate the code editor. + * + * When updating these rendered fields, Javascript is not be able to properly render arbitrary block + * markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string, + * the entire field becomes a string. + * + * @example + * ```ts + * type Post< C extends Context > { + * title: RenderedText< C >; + * } + * const post = {} as Post; + * // post.title is an object with raw and rendered properties + * + * const updatablePost = {} as Updatable< Post >; + * // updatablePost.title is a string + * ``` + */ +export type Updatable< T extends EntityRecord< 'edit' > > = { + [ K in keyof T ]: T[ K ] extends RenderedText< any > + ? string + : /* + * Explicit handling for WpTemplate and WpTemplatePart. They both have a + * `content` field that needs to be collapsed into a string even though + * it doesn't match the RenderedText signature. + */ + T extends WpTemplate< any > | WpTemplatePart< any > + ? K extends 'content' + ? string + : T[ K ] + : T[ K ]; +}; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 77fce4dc55017..441928af65031 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -20,9 +20,10 @@ import { Widget } from './widget'; import { WidgetType } from './widget-type'; import { WpTemplate } from './wp-template'; import { WpTemplatePart } from './wp-template-part'; -import { Context, RenderedText } from './common'; +import { Context, Updatable } from './helpers'; export { + Updatable, Attachment, Comment, MenuLocation, @@ -65,46 +66,4 @@ export type EntityRecord< C extends Context > = | WpTemplate< C > | WpTemplatePart< C >; -/** - * Updatable is a type describing Edited Entity Records. They are like - * regular Entity Records, but they have all the local edits applied on top of the REST API data. - * - * This turns certain field from an object into a string. - * - * Entities like Post have fields that only be rendered on the server, like title, excerpt, - * and content. The REST API exposes both the raw markup and the rendered version of those fields. - * For example, in the block editor, content.rendered could used as a visual preview, and - * content.raw could be used to populate the code editor. - * - * When updating these rendered fields, Javascript is not be able to properly render arbitrary block - * markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string, - * the entire field becomes a string. - * - * @example - * ```ts - * type Post< C extends Context > { - * title: RenderedText< C >; - * } - * const post = {} as Post; - * // post.title is an object with raw and rendered properties - * - * const updatablePost = {} as Updatable< Post >; - * // updatablePost.title is a string - * ``` - */ -export type Updatable< T extends EntityRecord< 'edit' > > = { - [ K in keyof T ]: T[ K ] extends RenderedText< any > - ? string - : /* - * Explicit handling for WpTemplate and WpTemplatePart. They both have a - * `content` field that needs to be collapsed into a string even though - * it doesn't match the RenderedText signature. - */ - T extends WpTemplate< any > | WpTemplatePart< any > - ? K extends 'content' - ? string - : T[ K ] - : T[ K ]; -}; - export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index b75f535d40b1b..176ad601c22ce 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context } from './common'; +import { Context } from './helpers'; export interface MenuLocation< C extends Context > { /** diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index 12ef71fc15537..56a9225e26cde 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { RenderedText, Context, ContextualField, OmitNevers } from './common'; +import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; /** * Internal dependencies diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index a866908e741cf..ff511bf3d4e8f 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, OmitNevers } from './common'; +import { Context, ContextualField, OmitNevers } from './helpers'; interface FullNavMenu< C extends Context > { /** diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 484c69a4411a2..6df6c0afb13c8 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context } from './common'; +import { Context } from './helpers'; export interface NavigationArea< C extends Context > { /** diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 1c10d01529ac6..6aaf8bedb2efb 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -9,7 +9,7 @@ import { PostStatus, RenderedText, OmitNevers, -} from './common'; +} from './helpers'; interface FullPage< C extends Context > { /** diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 94e1b55e18882..e927420700d09 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, RenderedText, OmitNevers } from './common'; +import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; interface FullPlugin< C extends Context > { /** diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 05082dba94a5f..f9a2a4753587e 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -10,7 +10,7 @@ import { PostStatus, RenderedText, OmitNevers, -} from './common'; +} from './helpers'; interface FullPost< C extends Context > { /** diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 1ab8f64d1f2b0..c744743ef7138 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { CommentStatus, Context, PingStatus } from './common'; +import { CommentStatus, Context, PingStatus } from './helpers'; export interface Settings< C extends Context > { /** diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 5f4e58a4f2679..867348d394e88 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { Widget } from './widget'; -import { Context } from './common'; +import { Context } from './helpers'; export interface Sidebar< C extends Context > { /** diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 535983ceb660f..f9e9ef21e13c2 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, OmitNevers } from './common'; +import { Context, ContextualField, OmitNevers } from './helpers'; import { FullWidget } from './widget'; interface FullTaxonomy< C extends Context > { diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 28d6a3a18ba33..8e5b9e847bcaf 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, PostFormat, RenderedText, OmitNevers } from './common'; +import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; interface FullTheme< C extends Context > { /** diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 2a0e453ac612a..4ecbf3bb89357 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, OmitNevers } from './common'; +import { Context, ContextualField, OmitNevers } from './helpers'; interface FullType< C extends Context > { /** diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 50fc44a01bb94..b412c6223fdfc 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { AvatarUrls, Context, ContextualField, OmitNevers } from './common'; +import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; interface FullUser< C extends Context > { /** diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 2f4f42616c349..bf929cafdc0f5 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, OmitNevers } from './common'; +import { Context, OmitNevers } from './helpers'; export interface WidgetType< C extends Context > { /** diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 825c0446ee314..9809fb7da816d 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { Context, ContextualField, OmitNevers } from './common'; +import { Context, ContextualField, OmitNevers } from './helpers'; export interface FullWidget< C extends Context > { /** diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index ece7a55b60e8f..b31e76fe0f502 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -7,7 +7,7 @@ import { RenderedText, OmitNevers, ContextualField, -} from './common'; +} from './helpers'; interface FullWpTemplatePart< C extends Context > { /** diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index 5f03023566165..d56190b59de95 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -7,7 +7,7 @@ import { RenderedText, OmitNevers, ContextualField, -} from './common'; +} from './helpers'; interface FullWpTemplate< C extends Context > { /** From 184bbe46537d77d2cd75133ac5cf18a38a2a1124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 14:12:42 +0100 Subject: [PATCH 44/73] Model WpTemplate.content and WpTemplatePart.content as RenderableText --- packages/core-data/src/types/helpers.ts | 15 +---------- .../core-data/src/types/wp-template-part.ts | 26 +++++++++++-------- packages/core-data/src/types/wp-template.ts | 26 +++++++++++-------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/packages/core-data/src/types/helpers.ts b/packages/core-data/src/types/helpers.ts index 2354e18369978..04e1e65319bca 100644 --- a/packages/core-data/src/types/helpers.ts +++ b/packages/core-data/src/types/helpers.ts @@ -1,8 +1,6 @@ /** * Internal dependencies */ -import { WpTemplate } from './wp-template'; -import { WpTemplatePart } from './wp-template-part'; import { EntityRecord } from './index'; export interface AvatarUrls { @@ -149,16 +147,5 @@ export interface RenderedText< C extends Context > { * ``` */ export type Updatable< T extends EntityRecord< 'edit' > > = { - [ K in keyof T ]: T[ K ] extends RenderedText< any > - ? string - : /* - * Explicit handling for WpTemplate and WpTemplatePart. They both have a - * `content` field that needs to be collapsed into a string even though - * it doesn't match the RenderedText signature. - */ - T extends WpTemplate< any > | WpTemplatePart< any > - ? K extends 'content' - ? string - : T[ K ] - : T[ K ]; + [ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ]; }; diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index b31e76fe0f502..9ef981d299602 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -37,18 +37,22 @@ interface FullWpTemplatePart< C extends Context > { /** * Content of template. * - * When used with the `Updatable` type wrapper, it is transformed to a string as a special case. + * This field never has a `rendered` property when reading but still uses + * the RenderedText type so it can be set as a string when sending updates to + * the server. + * + * TODO: Figure out how to mesh this with `RenderedText` */ - content: { - /** - * Content for the template, as it exists in the database. - */ - raw: ContextualField< string, 'view' | 'edit', C >; - /** - * Version of the content block format used by the template. - */ - block_version: ContextualField< number, 'edit', C >; - }; + content: ContextualField< + RenderedText< C > & { + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + }, + 'view' | 'edit', + C + >; /** * Title of template. */ diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index d56190b59de95..9af9fdf14e2e5 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -37,18 +37,22 @@ interface FullWpTemplate< C extends Context > { /** * Content of template. * - * When used with the `Updatable` type wrapper, it is transformed to a string as a special case. + * This field never has a `rendered` property when reading but still uses + * the RenderedText type so it can be set as a string when sending updates to + * the server. + * + * TODO: Figure out how to mesh this with `RenderedText` */ - content: { - /** - * Content for the template, as it exists in the database. - */ - raw: ContextualField< string, 'view' | 'edit', C >; - /** - * Version of the content block format used by the template. - */ - block_version: ContextualField< number, 'edit', C >; - }; + content: ContextualField< + RenderedText< C > & { + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + }, + 'view' | 'edit', + C + >; /** * Title of template. */ From 185ecfd21437e094352dd3949faffdd9faeeb7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 14:15:26 +0100 Subject: [PATCH 45/73] Link to the REST API docs when explaining contexts --- packages/core-data/src/types/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index f332f409a8621..152a1f805b28b 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -11,7 +11,7 @@ The types in this directory are designed to support the following use-cases: ### Context-aware type checks for entity records -WordPress REST API returns different responses based on the `context` query parameter, which typically is one of `view`, `edit`, or `embed`. +WordPress REST API returns different responses based on the `context` query parameter, which typically is one of `view`, `edit`, or `embed`. See the [REST API documentation](https://developer.wordpress.org/rest-api/) to learn more. For example, requesting `/wp/v2/posts/1?context=view` yields: From 048607608134fe6e53567b84d067bd2877a5a517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 14:17:15 +0100 Subject: [PATCH 46/73] Explain the ContextualFields without meandering on the implementation details of `never` fields --- packages/core-data/src/types/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 152a1f805b28b..e3afeb24c05a8 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -63,9 +63,7 @@ These contexts are supported by the core-data resolvers like `getEntityRecord()` The types describing different entity records must thus be aware of the relevant API context. This is implemented using the `Context` type parameter. For example, the implementation of the `Post` type resembles the following snippet: ```ts -import { OmitNevers } from "./helpers"; - -interface BasePost { +interface Post { /** * A named status for the post. */ @@ -73,13 +71,9 @@ interface BasePost { // ... other fields ... } - -export type Post = OmitNevers>; ``` -The `status` field of the `BasePost` is either a `PostStatus` when the Context is `view` or `edit`, or it's `never` when the Context is `embed`. - -The derived type `Post` is stripped of all the `never` fields, and so `Post<'embed'>` does not have the `status` type at all. +The `status` field is a `PostStatus` when the requesting context is `view` or `edit`, but if requested with an `embed` context the field won't appear on the `Post` object at all. ### Static type checks for *edited* entity records, where certain fields become strings instead of objects. From 493050eda2c0a0379efd424966ca8c86c7e6b5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 14:18:12 +0100 Subject: [PATCH 47/73] Use the correct capitalization of the word javascript --- packages/core-data/src/types/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index e3afeb24c05a8..b2cc43898fdfb 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -86,7 +86,7 @@ const post = wp.data.select('core').getEntityRecord( 'postType', 'post', 1, { co The block markup stored in `content` can only be rendered on the server so the REST API exposes both the raw markup and the rendered version. For example, `content.rendered` could used as a visual preview, and `content.raw` could be used to populate the code editor. -The `content` field may still be updated via Javascript, but the updated content cannot be properly rendered without requesting the server. Therefore, it doesn't make sense to keep track the `rendered` when editing. The only remaining part is `raw`, and since that's a string, the entire edited `content` can be expressed a string. +The `content` field may still be updated via JavaScript, but the updated content cannot be properly rendered without requesting the server. Therefore, it doesn't make sense to keep track the `rendered` when editing. The only remaining part is `raw`, and since that's a string, the entire edited `content` can be expressed a string. And this is exactly what you'll see after retrieving the editable version of the record using `getEditedEntityRecord`: @@ -154,7 +154,7 @@ and content. The REST API exposes both the raw markup and the rendered version o For example, in the block editor, content.rendered could used as a visual preview, and content.raw could be used to populate the code editor. -When updating these rendered fields, Javascript is not be able to properly render arbitrary block +When updating these rendered fields, JavaScript is not be able to properly render arbitrary block markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string, the entire field becomes a string. From 222e2fa799db878712a7ad1673c742a0e637ae1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 14:56:17 +0100 Subject: [PATCH 48/73] Rename CommentStatus to CommentingStatus in context of comments container --- packages/core-data/src/types/helpers.ts | 2 +- packages/core-data/src/types/page.ts | 4 ++-- packages/core-data/src/types/post.ts | 4 ++-- packages/core-data/src/types/settings.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core-data/src/types/helpers.ts b/packages/core-data/src/types/helpers.ts index 04e1e65319bca..f39bf893d61da 100644 --- a/packages/core-data/src/types/helpers.ts +++ b/packages/core-data/src/types/helpers.ts @@ -19,7 +19,7 @@ export interface AvatarUrls { } export type MediaType = 'image' | 'file'; -export type CommentStatus = 'open' | 'closed'; +export type CommentingStatus = 'open' | 'closed'; export type PingStatus = 'open' | 'closed'; export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private'; export type PostFormat = diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 6aaf8bedb2efb..f5b6c6c240801 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { - CommentStatus, + CommentingStatus, Context, ContextualField, PingStatus, @@ -106,7 +106,7 @@ interface FullPage< C extends Context > { /** * Whether or not comments are open on the post. */ - comment_status: ContextualField< CommentStatus, 'view' | 'edit', C >; + comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index f9a2a4753587e..efcd2cca1f27f 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { - CommentStatus, + CommentingStatus, Context, ContextualField, PingStatus, @@ -103,7 +103,7 @@ interface FullPost< C extends Context > { /** * Whether or not comments are open on the post. */ - comment_status: ContextualField< CommentStatus, 'view' | 'edit', C >; + comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index c744743ef7138..3211f27f58d60 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { CommentStatus, Context, PingStatus } from './helpers'; +import { CommentingStatus, Context, PingStatus } from './helpers'; export interface Settings< C extends Context > { /** @@ -71,7 +71,7 @@ export interface Settings< C extends Context > { /** * Allow people to submit comments on new posts. */ - default_comment_status: CommentStatus; + default_comment_status: CommentingStatus; /** * Site logo. */ From fccae6796777f0709345b5098a80e5b45e540a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 15:00:45 +0100 Subject: [PATCH 49/73] Use Post as an example illustrating the usage of ContextualField --- packages/core-data/src/types/README.md | 20 +++++++++++--------- packages/core-data/src/types/helpers.ts | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index b2cc43898fdfb..76cad62abf4ef 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -110,18 +110,20 @@ A wrapper that turns fields unavailable in the current REST API contexts into th Example: ```ts -type MyType< C extends Context > = { - good: ContextualField< string, 'view' | 'edit', C >; - bad: ContextualField< string, 'edit', C >; +interface Post< C extends Context > { + … + modified: ContextualField< string, 'edit' | 'view', C >; + password: ContextualField< string, 'edit', C >; + … } -const a = {} as MyType<'view'>; -// a.good is of type string -// b.bad is of type never +const post: Post<'edit'> = … +// post.modified exists as a string +// post.password exists as a string -const b = {} as OmitNevers>; -// a.good is of type string -// there is no property b.bad +const post: Post<'view'> = … +// post.modified still exists as a string +// post.password is missing, undefined, because we're not in the `edit` context. ``` ### OmitNevers diff --git a/packages/core-data/src/types/helpers.ts b/packages/core-data/src/types/helpers.ts index f39bf893d61da..67c03b81fcf4f 100644 --- a/packages/core-data/src/types/helpers.ts +++ b/packages/core-data/src/types/helpers.ts @@ -45,18 +45,20 @@ export type Context = 'view' | 'edit' | 'embed'; * * @example * ```ts - * type MyType< C extends Context > = { - * good: ContextualField< string, 'view' | 'edit', C >; - * bad: ContextualField< string, 'edit', C >; + * interface Post< C extends Context > { + * … + * modified: ContextualField< string, 'edit' | 'view', C >; + * password: ContextualField< string, 'edit', C >; + * … * } * - * const a = {} as MyType<'view'>; - * // a.good is of type string - * // b.bad is of type never + * const post: Post<'edit'> = … + * // post.modified exists as a string + * // post.password exists as a string * - * const b = {} as OmitNevers>; - * // a.good is of type string - * // there is no property b.bad + * const post: Post<'view'> = … + * // post.modified still exists as a string + * // post.password is missing, undefined, because we're not in the `edit` context. * ``` */ export type ContextualField< From d8522e883994f0088ede63b29ae130daff4cae79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 15:02:33 +0100 Subject: [PATCH 50/73] Focus on the goal of the ContextualField in its documentation --- packages/core-data/src/types/README.md | 2 +- packages/core-data/src/types/helpers.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 76cad62abf4ef..7ea1cfe4ad61c 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -105,7 +105,7 @@ The REST API context parameter. ### ContextualField -A wrapper that turns fields unavailable in the current REST API contexts into the type `never`. It is typically paired with OmitNevers. +`ContextualField` makes the field available only in the specified given contexts, and ensure the field is absent from the object when in a different context. Example: diff --git a/packages/core-data/src/types/helpers.ts b/packages/core-data/src/types/helpers.ts index 67c03b81fcf4f..e3e60489bdaaf 100644 --- a/packages/core-data/src/types/helpers.ts +++ b/packages/core-data/src/types/helpers.ts @@ -40,8 +40,8 @@ export type PostFormat = export type Context = 'view' | 'edit' | 'embed'; /** - * A wrapper that turns fields unavailable in the current REST API contexts into - * the type `never`. It is typically paired with OmitNevers. + * ContextualField makes the field available only in the specified given contexts, + * and ensure the field is absent from the object when in a different context. * * @example * ```ts From 3fe22976a4cd322ad1e5e51051de8e3976c7a94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 15:08:45 +0100 Subject: [PATCH 51/73] Use a cleaner explanation of the Updatable type wrapper --- packages/core-data/src/types/README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 7ea1cfe4ad61c..9cd83048c2429 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -86,9 +86,26 @@ const post = wp.data.select('core').getEntityRecord( 'postType', 'post', 1, { co The block markup stored in `content` can only be rendered on the server so the REST API exposes both the raw markup and the rendered version. For example, `content.rendered` could used as a visual preview, and `content.raw` could be used to populate the code editor. -The `content` field may still be updated via JavaScript, but the updated content cannot be properly rendered without requesting the server. Therefore, it doesn't make sense to keep track the `rendered` when editing. The only remaining part is `raw`, and since that's a string, the entire edited `content` can be expressed a string. +When updating that field from the JavaScript code, however, all we can set is the raw value that the server will eventually render. The API expects us to send a much simpler `string` form which is the raw form that needs to be stored in the database. -And this is exactly what you'll see after retrieving the editable version of the record using `getEditedEntityRecord`: +The types reflect this through the `Updatable` wrapper: + +```ts +interface Post< C extends Context > { + title: { + raw: string; + rendered: string; + } +} + +const post : Post< 'edit' > = ... +// post.title is an object with properties `raw` and `rendered` + +const post : Updatable> = ... +// post.title is a string +``` + +The `getEditedEntityRecord` selector returns the Updatable version of the entity records: ```js const post = wp.data.select('core').getEditedEntityRecord( 'postType', 'post', 1 ); From c544fef3409e387ef16b578e80ca724fb4a2569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 15:17:39 +0100 Subject: [PATCH 52/73] Explain why the types do not provide full type safety --- packages/core-data/src/types/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 9cd83048c2429..32eb550f42b87 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -1,13 +1,13 @@ # Entity Records Types -!THIS IS WORK IN PROGRESS! I used bits of the GitHub discussion as the first draft here - ## Overview The types in this directory are designed to support the following use-cases: -* Context-aware type checks for entity records. -* Static type checks for *edited* entity records, where certain fields become strings instead of objects. +* Provide type-hinting and documentation for entity records fetched in the various REST API contexts. +* Type-check the values we use to *edit* entity records, the values that are sent back to the server as updates. + +**Warning:** The types model the _expected_ API responses which is **not** the same as having a full type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. ### Context-aware type checks for entity records From 1b7963e3971449862c04966013fdd3ec74bb3b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 15:29:27 +0100 Subject: [PATCH 53/73] Remove the TODO comments from the README and a section about extendability --- packages/core-data/src/types/README.md | 30 -------------------------- 1 file changed, 30 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 32eb550f42b87..b0620b0936d1a 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -114,8 +114,6 @@ const post = wp.data.select('core').getEditedEntityRecord( 'postType', 'post', 1 ## Helpers -@TODO – perhaps we could auto generate that from the docstrings in common.ts (to become helpers.ts?) - ### Context The REST API context parameter. @@ -194,31 +192,3 @@ A string that the server renders which often involves modifications from the raw For example, block HTML with the comment delimiters exists in `post_content` but those comments are stripped out when rendering to a page view. Similarly, plugins might modify content or replace shortcodes. -## Extending - -Talk about interface merging here - -Change the "full" version of these types to be inside a namespace `wpCoreData.BaseTypes` so that they can be extended. - -```ts -// In core-data -export namespace wpCoreData.BaseTypes { - export interface Comment< C extends Context > { - id: number; - // ... - } -} - -export type Comment< C extends Context > = OmitNevers< - wpCoreData.BaseTypes.Comment< C > ->; - -// In the plugin -namespace wpCoreData.BaseTypes { - interface Comment < C extends Context > { - newField: ContextualField; - } -} -``` - -Interface merging has a huge upside: core-data selectors would return the extended types out of the box. From b855db9c268780976c674e89b9cd40eb0ad73db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 21 Feb 2022 16:35:39 +0100 Subject: [PATCH 54/73] Add extensible type prefix --- packages/core-data/src/index.js | 1 + packages/core-data/src/types/README.md | 31 +++++++++- packages/core-data/src/types/attachment.ts | 6 +- packages/core-data/src/types/comment.ts | 5 +- packages/core-data/src/types/index.ts | 58 +++++++++++++------ packages/core-data/src/types/menu-location.ts | 8 ++- packages/core-data/src/types/nav-menu-item.ts | 8 +-- packages/core-data/src/types/nav-menu.ts | 4 +- .../core-data/src/types/navigation-area.ts | 8 ++- packages/core-data/src/types/page.ts | 4 +- packages/core-data/src/types/plugin.ts | 4 +- packages/core-data/src/types/post.ts | 4 +- packages/core-data/src/types/settings.ts | 8 ++- packages/core-data/src/types/sidebar.ts | 6 +- packages/core-data/src/types/taxonomy.ts | 7 ++- packages/core-data/src/types/theme.ts | 4 +- packages/core-data/src/types/type.ts | 4 +- packages/core-data/src/types/user.ts | 4 +- packages/core-data/src/types/widget-type.ts | 6 +- packages/core-data/src/types/widget.ts | 4 +- .../core-data/src/types/wp-template-part.ts | 4 +- packages/core-data/src/types/wp-template.ts | 6 +- 22 files changed, 132 insertions(+), 62 deletions(-) diff --git a/packages/core-data/src/index.js b/packages/core-data/src/index.js index 7821e2ecd4745..581fedcf43e1f 100644 --- a/packages/core-data/src/index.js +++ b/packages/core-data/src/index.js @@ -76,3 +76,4 @@ register( store ); export { default as EntityProvider } from './entity-provider'; export * from './entity-provider'; export * from './fetch'; +export * from './types'; diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index b0620b0936d1a..aca5e9ced26cd 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -7,7 +7,7 @@ The types in this directory are designed to support the following use-cases: * Provide type-hinting and documentation for entity records fetched in the various REST API contexts. * Type-check the values we use to *edit* entity records, the values that are sent back to the server as updates. -**Warning:** The types model the _expected_ API responses which is **not** the same as having a full type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. +**Warning:** The types model the _expected_ API responses which is **not** the same as having a Extensible type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. ### Context-aware type checks for entity records @@ -192,3 +192,32 @@ A string that the server renders which often involves modifications from the raw For example, block HTML with the comment delimiters exists in `post_content` but those comments are stripped out when rendering to a page view. Similarly, plugins might modify content or replace shortcodes. +## Extending + +You can extend the entity record definitions using [TypeScript's declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). + +For example, if you're building a plugin that displays a number of views of each comment, you can add a new `numberOfViews` field to the `Comment` type like this: + +```ts +// In core-data +export interface ExtensibleComment< C extends Context > { + id: number; + // ... +} + +export type Comment< C extends Context > = OmitNevers< + ExtensibleComment< C > +>; + +// In the plugin +import { ExtensibleComment, Comment } from '@wordpress/core-data'; +interface ExtensibleComment < C extends Context > { + numberOfViews: number; +} + +const c : Comment = ... + +// c.numberOfViews is a number +``` + +Of course you will also need to extend the REST API to expose the numberOfViews property. diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 8524a0acde034..4979ead85b17a 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -10,7 +10,7 @@ import { OmitNevers, } from './helpers'; -interface FullAttachment< C extends Context > { +export interface ExtensibleAttachment< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -121,4 +121,6 @@ interface FullAttachment< C extends Context > { missing_image_sizes: ContextualField< string[], 'edit', C >; } -export type Attachment< C extends Context > = OmitNevers< FullAttachment< C > >; +export type Attachment< C extends Context > = OmitNevers< + ExtensibleAttachment< C > +>; diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index f2f101f5be5ce..0d40e12708d4b 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -10,7 +10,8 @@ import { } from './helpers'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; -interface FullComment< C extends Context > { + +export interface ExtensibleComment< C extends Context > { /** * Unique identifier for the comment. */ @@ -81,4 +82,4 @@ interface FullComment< C extends Context > { meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export type Comment< C extends Context > = OmitNevers< FullComment< C > >; +export type Comment< C extends Context > = OmitNevers< ExtensibleComment< C > >; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 441928af65031..0125219c1f045 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,25 +1,25 @@ /** * Internal dependencies */ -import { Attachment } from './attachment'; -import { Comment } from './comment'; -import { MenuLocation } from './menu-location'; -import { NavMenu } from './nav-menu'; -import { NavMenuItem } from './nav-menu-item'; -import { NavigationArea } from './navigation-area'; -import { Page } from './page'; -import { Plugin } from './plugin'; -import { Post } from './post'; -import { Settings } from './settings'; -import { Sidebar } from './sidebar'; -import { Taxonomy } from './taxonomy'; -import { Theme } from './theme'; -import { User } from './user'; -import { Type } from './type'; -import { Widget } from './widget'; -import { WidgetType } from './widget-type'; -import { WpTemplate } from './wp-template'; -import { WpTemplatePart } from './wp-template-part'; +import { ExtensibleAttachment, Attachment } from './attachment'; +import { ExtensibleComment, Comment } from './comment'; +import { ExtensibleMenuLocation, MenuLocation } from './menu-location'; +import { ExtensibleNavMenu, NavMenu } from './nav-menu'; +import { ExtensibleNavMenuItem, NavMenuItem } from './nav-menu-item'; +import { ExtensibleNavigationArea, NavigationArea } from './navigation-area'; +import { ExtensiblePage, Page } from './page'; +import { ExtensiblePlugin, Plugin } from './plugin'; +import { ExtensiblePost, Post } from './post'; +import { ExtensibleSettings, Settings } from './settings'; +import { ExtensibleSidebar, Sidebar } from './sidebar'; +import { ExtensibleTaxonomy, Taxonomy } from './taxonomy'; +import { ExtensibleTheme, Theme } from './theme'; +import { ExtensibleUser, User } from './user'; +import { ExtensibleType, Type } from './type'; +import { ExtensibleWidget, Widget } from './widget'; +import { ExtensibleWidgetType, WidgetType } from './widget-type'; +import { ExtensibleWpTemplate, WpTemplate } from './wp-template'; +import { ExtensibleWpTemplatePart, WpTemplatePart } from './wp-template-part'; import { Context, Updatable } from './helpers'; export { @@ -67,3 +67,23 @@ export type EntityRecord< C extends Context > = | WpTemplatePart< C >; export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; + +export { ExtensibleAttachment } from './attachment'; +export { ExtensibleComment } from './comment'; +export { ExtensibleMenuLocation } from './menu-location'; +export { ExtensibleNavMenu } from './nav-menu'; +export { ExtensibleNavMenuItem } from './nav-menu-item'; +export { ExtensibleNavigationArea } from './navigation-area'; +export { ExtensiblePage } from './page'; +export { ExtensiblePlugin } from './plugin'; +export { ExtensiblePost } from './post'; +export { ExtensibleSettings } from './settings'; +export { ExtensibleSidebar } from './sidebar'; +export { ExtensibleTaxonomy } from './taxonomy'; +export { ExtensibleTheme } from './theme'; +export { ExtensibleUser } from './user'; +export { ExtensibleType } from './type'; +export { ExtensibleWidget } from './widget'; +export { ExtensibleWidgetType } from './widget-type'; +export { ExtensibleWpTemplate } from './wp-template'; +export { ExtensibleWpTemplatePart } from './wp-template-part'; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 176ad601c22ce..45062c98b1821 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context } from './helpers'; +import { Context, OmitNevers } from './helpers'; -export interface MenuLocation< C extends Context > { +export interface ExtensibleMenuLocation< C extends Context > { /** * The name of the menu location. */ @@ -17,3 +17,7 @@ export interface MenuLocation< C extends Context > { */ menu: number; } + +export type MenuLocation< C extends Context > = OmitNevers< + ExtensibleMenuLocation< C > +>; diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index 56a9225e26cde..111ccf30ccc7f 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -3,10 +3,6 @@ */ import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; -/** - * Internal dependencies - */ - export type NavMenuItemType = | 'taxonomy' | 'post_type' @@ -20,7 +16,7 @@ export type NavMenuItemStatus = | 'private'; export type Target = '_blank' | ''; -interface FullNavMenuItem< C extends Context > { +export interface ExtensibleNavMenuItem< C extends Context > { /** * The title for the object. */ @@ -96,5 +92,5 @@ interface FullNavMenuItem< C extends Context > { } export type NavMenuItem< C extends Context > = OmitNevers< - FullNavMenuItem< C > + ExtensibleNavMenuItem< C > >; diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index ff511bf3d4e8f..78a959aebb28b 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -3,7 +3,7 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -interface FullNavMenu< C extends Context > { +export interface ExtensibleNavMenu< C extends Context > { /** * Unique identifier for the term. */ @@ -38,4 +38,4 @@ interface FullNavMenu< C extends Context > { auto_add: ContextualField< boolean, 'view' | 'edit', C >; } -export type NavMenu< C extends Context > = OmitNevers< FullNavMenu< C > >; +export type NavMenu< C extends Context > = OmitNevers< ExtensibleNavMenu< C > >; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 6df6c0afb13c8..3ba97482d99d2 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { Context } from './helpers'; +import { Context, OmitNevers } from './helpers'; -export interface NavigationArea< C extends Context > { +export interface ExtensibleNavigationArea< C extends Context > { /** * The name of the navigation area. */ @@ -17,3 +17,7 @@ export interface NavigationArea< C extends Context > { */ navigation: number; } + +export type NavigationArea< C extends Context > = OmitNevers< + ExtensibleNavigationArea< C > +>; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index f5b6c6c240801..ef9daefd3f050 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -11,7 +11,7 @@ import { OmitNevers, } from './helpers'; -interface FullPage< C extends Context > { +export interface ExtensiblePage< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -125,4 +125,4 @@ interface FullPage< C extends Context > { template: ContextualField< string, 'view' | 'edit', C >; } -export type Page< C extends Context > = OmitNevers< FullPage< C > >; +export type Page< C extends Context > = OmitNevers< ExtensiblePage< C > >; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index e927420700d09..676a41f5e10e6 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -3,7 +3,7 @@ */ import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; -interface FullPlugin< C extends Context > { +export interface ExtensiblePlugin< C extends Context > { /** * The plugin file. */ @@ -55,4 +55,4 @@ interface FullPlugin< C extends Context > { } export type PluginStatus = 'active' | 'inactive'; -export type Plugin< C extends Context > = OmitNevers< FullPlugin< C > >; +export type Plugin< C extends Context > = OmitNevers< ExtensiblePlugin< C > >; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index efcd2cca1f27f..7119fcc5cb606 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -12,7 +12,7 @@ import { OmitNevers, } from './helpers'; -interface FullPost< C extends Context > { +export interface ExtensiblePost< C extends Context > { /** * The date the post was published, in the site's timezone. */ @@ -134,4 +134,4 @@ interface FullPost< C extends Context > { tags: ContextualField< number[], 'view' | 'edit', C >; } -export type Post< C extends Context > = OmitNevers< FullPost< C > >; +export type Post< C extends Context > = OmitNevers< ExtensiblePost< C > >; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index 3211f27f58d60..a8ad086e695d8 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -1,9 +1,9 @@ /** * Internal dependencies */ -import { CommentingStatus, Context, PingStatus } from './helpers'; +import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers'; -export interface Settings< C extends Context > { +export interface ExtensibleSettings< C extends Context > { /** * What to show on the front page */ @@ -81,3 +81,7 @@ export interface Settings< C extends Context > { */ site_icon: number; } + +export type Settings< C extends Context > = OmitNevers< + ExtensibleSettings< C > +>; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 867348d394e88..6cb60af3cafc4 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -2,9 +2,9 @@ * Internal dependencies */ import { Widget } from './widget'; -import { Context } from './helpers'; +import { Context, OmitNevers } from './helpers'; -export interface Sidebar< C extends Context > { +export interface ExtensibleSidebar< C extends Context > { /** * ID of sidebar. */ @@ -48,3 +48,5 @@ export interface Sidebar< C extends Context > { } type SidebarStatus = 'active' | 'inactive'; + +export type Sidebar< C extends Context > = OmitNevers< ExtensibleSidebar< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index f9e9ef21e13c2..a428fa59c5ff2 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -2,9 +2,8 @@ * Internal dependencies */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { FullWidget } from './widget'; -interface FullTaxonomy< C extends Context > { +export interface ExtensibleTaxonomy< C extends Context > { /** * All capabilities used by the taxonomy. */ @@ -78,4 +77,6 @@ export interface TaxonomyVisibility { show_in_quick_edit: boolean; } -export type Taxonomy< C extends Context > = OmitNevers< FullTaxonomy< C > >; +export type Taxonomy< C extends Context > = OmitNevers< + ExtensibleTaxonomy< C > +>; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 8e5b9e847bcaf..0b5fdc228bcf7 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -3,7 +3,7 @@ */ import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; -interface FullTheme< C extends Context > { +export interface ExtensibleTheme< C extends Context > { /** * The theme's stylesheet. This uniquely identifies the theme. */ @@ -211,4 +211,4 @@ export type Html5Option = | 'script' | 'style'; -export type Theme< C extends Context > = OmitNevers< FullTheme< C > >; +export type Theme< C extends Context > = OmitNevers< ExtensibleTheme< C > >; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 4ecbf3bb89357..fc86a62cef620 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,7 +3,7 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -interface FullType< C extends Context > { +export interface ExtensibleType< C extends Context > { /** * All capabilities used by the post type. */ @@ -65,4 +65,4 @@ interface TypeVisibility { show_in_nav_menus: boolean; } -export type Type< C extends Context > = OmitNevers< FullType< C > >; +export type Type< C extends Context > = OmitNevers< ExtensibleType< C > >; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index b412c6223fdfc..378bcd1618ae6 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -3,7 +3,7 @@ */ import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; -interface FullUser< C extends Context > { +export interface ExtensibleUser< C extends Context > { /** * Unique identifier for the user. */ @@ -86,4 +86,4 @@ interface FullUser< C extends Context > { meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; } -export type User< C extends Context > = OmitNevers< FullUser< C > >; +export type User< C extends Context > = OmitNevers< ExtensibleUser< C > >; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index bf929cafdc0f5..48d2307ab6b58 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,7 +3,7 @@ */ import { Context, OmitNevers } from './helpers'; -export interface WidgetType< C extends Context > { +export interface ExtensibleWidgetType< C extends Context > { /** * Unique slug identifying the widget type. */ @@ -25,3 +25,7 @@ export interface WidgetType< C extends Context > { */ classname: string; } + +export type WidgetType< C extends Context > = OmitNevers< + ExtensibleWidgetType< C > +>; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 9809fb7da816d..868f519e13e23 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -3,7 +3,7 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -export interface FullWidget< C extends Context > { +export interface ExtensibleWidget< C extends Context > { /** * Unique identifier for the widget. */ @@ -53,4 +53,4 @@ interface WidgetInstance { raw: Record< string, string >; } -export type Widget< C extends Context > = OmitNevers< FullWidget< C > >; +export type Widget< C extends Context > = OmitNevers< ExtensibleWidget< C > >; diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index 9ef981d299602..35fc065b11b29 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -9,7 +9,7 @@ import { ContextualField, } from './helpers'; -interface FullWpTemplatePart< C extends Context > { +export interface ExtensibleWpTemplatePart< C extends Context > { /** * ID of template. */ @@ -84,5 +84,5 @@ interface FullWpTemplatePart< C extends Context > { } export type WpTemplatePart< C extends Context > = OmitNevers< - FullWpTemplatePart< C > + ExtensibleWpTemplatePart< C > >; diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index 9af9fdf14e2e5..d7e81ae44d2c9 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -9,7 +9,7 @@ import { ContextualField, } from './helpers'; -interface FullWpTemplate< C extends Context > { +export interface ExtensibleWpTemplate< C extends Context > { /** * ID of template. */ @@ -83,4 +83,6 @@ interface FullWpTemplate< C extends Context > { is_custom: Record< string, string >; } -export type WpTemplate< C extends Context > = OmitNevers< FullWpTemplate< C > >; +export type WpTemplate< C extends Context > = OmitNevers< + ExtensibleWpTemplate< C > +>; From 5b2145d42b8a18753640673beacc8038aaa405ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 11:45:21 +0100 Subject: [PATCH 55/73] a -> an --- packages/core-data/src/types/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index aca5e9ced26cd..d02aad6f5f1cf 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -7,7 +7,7 @@ The types in this directory are designed to support the following use-cases: * Provide type-hinting and documentation for entity records fetched in the various REST API contexts. * Type-check the values we use to *edit* entity records, the values that are sent back to the server as updates. -**Warning:** The types model the _expected_ API responses which is **not** the same as having a Extensible type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. +**Warning:** The types model the _expected_ API responses which is **not** the same as having an extensible type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. ### Context-aware type checks for entity records From b23a08a40da9a801dba84d3296fbac22dae1a929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 11:47:07 +0100 Subject: [PATCH 56/73] Use export type and import type declarations --- packages/core-data/src/types/index.ts | 86 ++++++++++++++------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 0125219c1f045..8b40df7fffaf1 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,28 +1,34 @@ /** * Internal dependencies */ -import { ExtensibleAttachment, Attachment } from './attachment'; -import { ExtensibleComment, Comment } from './comment'; -import { ExtensibleMenuLocation, MenuLocation } from './menu-location'; -import { ExtensibleNavMenu, NavMenu } from './nav-menu'; -import { ExtensibleNavMenuItem, NavMenuItem } from './nav-menu-item'; -import { ExtensibleNavigationArea, NavigationArea } from './navigation-area'; -import { ExtensiblePage, Page } from './page'; -import { ExtensiblePlugin, Plugin } from './plugin'; -import { ExtensiblePost, Post } from './post'; -import { ExtensibleSettings, Settings } from './settings'; -import { ExtensibleSidebar, Sidebar } from './sidebar'; -import { ExtensibleTaxonomy, Taxonomy } from './taxonomy'; -import { ExtensibleTheme, Theme } from './theme'; -import { ExtensibleUser, User } from './user'; -import { ExtensibleType, Type } from './type'; -import { ExtensibleWidget, Widget } from './widget'; -import { ExtensibleWidgetType, WidgetType } from './widget-type'; -import { ExtensibleWpTemplate, WpTemplate } from './wp-template'; -import { ExtensibleWpTemplatePart, WpTemplatePart } from './wp-template-part'; -import { Context, Updatable } from './helpers'; +import type { ExtensibleAttachment, Attachment } from './attachment'; +import type { ExtensibleComment, Comment } from './comment'; +import type { ExtensibleMenuLocation, MenuLocation } from './menu-location'; +import type { ExtensibleNavMenu, NavMenu } from './nav-menu'; +import type { ExtensibleNavMenuItem, NavMenuItem } from './nav-menu-item'; +import type { + ExtensibleNavigationArea, + NavigationArea, +} from './navigation-area'; +import type { ExtensiblePage, Page } from './page'; +import type { ExtensiblePlugin, Plugin } from './plugin'; +import type { ExtensiblePost, Post } from './post'; +import type { ExtensibleSettings, Settings } from './settings'; +import type { ExtensibleSidebar, Sidebar } from './sidebar'; +import type { ExtensibleTaxonomy, Taxonomy } from './taxonomy'; +import type { ExtensibleTheme, Theme } from './theme'; +import type { ExtensibleUser, User } from './user'; +import type { ExtensibleType, Type } from './type'; +import type { ExtensibleWidget, Widget } from './widget'; +import type { ExtensibleWidgetType, WidgetType } from './widget-type'; +import type { ExtensibleWpTemplate, WpTemplate } from './wp-template'; +import type { + ExtensibleWpTemplatePart, + WpTemplatePart, +} from './wp-template-part'; +import type { Context, Updatable } from './helpers'; -export { +export type { Updatable, Attachment, Comment, @@ -68,22 +74,22 @@ export type EntityRecord< C extends Context > = export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; -export { ExtensibleAttachment } from './attachment'; -export { ExtensibleComment } from './comment'; -export { ExtensibleMenuLocation } from './menu-location'; -export { ExtensibleNavMenu } from './nav-menu'; -export { ExtensibleNavMenuItem } from './nav-menu-item'; -export { ExtensibleNavigationArea } from './navigation-area'; -export { ExtensiblePage } from './page'; -export { ExtensiblePlugin } from './plugin'; -export { ExtensiblePost } from './post'; -export { ExtensibleSettings } from './settings'; -export { ExtensibleSidebar } from './sidebar'; -export { ExtensibleTaxonomy } from './taxonomy'; -export { ExtensibleTheme } from './theme'; -export { ExtensibleUser } from './user'; -export { ExtensibleType } from './type'; -export { ExtensibleWidget } from './widget'; -export { ExtensibleWidgetType } from './widget-type'; -export { ExtensibleWpTemplate } from './wp-template'; -export { ExtensibleWpTemplatePart } from './wp-template-part'; +export type { ExtensibleAttachment } from './attachment'; +export type { ExtensibleComment } from './comment'; +export type { ExtensibleMenuLocation } from './menu-location'; +export type { ExtensibleNavMenu } from './nav-menu'; +export type { ExtensibleNavMenuItem } from './nav-menu-item'; +export type { ExtensibleNavigationArea } from './navigation-area'; +export type { ExtensiblePage } from './page'; +export type { ExtensiblePlugin } from './plugin'; +export type { ExtensiblePost } from './post'; +export type { ExtensibleSettings } from './settings'; +export type { ExtensibleSidebar } from './sidebar'; +export type { ExtensibleTaxonomy } from './taxonomy'; +export type { ExtensibleTheme } from './theme'; +export type { ExtensibleUser } from './user'; +export type { ExtensibleType } from './type'; +export type { ExtensibleWidget } from './widget'; +export type { ExtensibleWidgetType } from './widget-type'; +export type { ExtensibleWpTemplate } from './wp-template'; +export type { ExtensibleWpTemplatePart } from './wp-template-part'; From c98911e4d63a9f9567ddb56810e19996ededc6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 11:51:01 +0100 Subject: [PATCH 57/73] Note that Comment.id is still a field even after the Comment type has been extended --- packages/core-data/src/types/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index d02aad6f5f1cf..7d12746e49eba 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -218,6 +218,7 @@ interface ExtensibleComment < C extends Context > { const c : Comment = ... // c.numberOfViews is a number +// c.id is still present ``` Of course you will also need to extend the REST API to expose the numberOfViews property. From c02ddb3392917dde9e1aa57996747f941d21dc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 11:52:12 +0100 Subject: [PATCH 58/73] Use CommentingStatus and PingStatus in the Attachment type --- packages/core-data/src/types/attachment.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 4979ead85b17a..5d14c75f1da70 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -8,6 +8,8 @@ import { PostStatus, RenderedText, OmitNevers, + CommentingStatus, + PingStatus, } from './helpers'; export interface ExtensibleAttachment< C extends Context > { @@ -70,11 +72,11 @@ export interface ExtensibleAttachment< C extends Context > { /** * Whether or not comments are open on the post. */ - comment_status: ContextualField< 'open' | 'closed', 'view' | 'edit', C >; + comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; /** * Whether or not the post can be pinged. */ - ping_status: ContextualField< 'open' | 'closed', 'view' | 'edit', C >; + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; /** * Meta fields. */ From a0650ac90440983458126f4a41b946746acc5ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:18:20 +0100 Subject: [PATCH 59/73] Use a correct snippet of code to illustrate interface extending in README.md --- packages/core-data/package.json | 1 + packages/core-data/src/types/README.md | 11 +++++++---- packages/core-data/src/types/index.ts | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core-data/package.json b/packages/core-data/package.json index 053822e57e0ac..f48a62b7e4034 100644 --- a/packages/core-data/package.json +++ b/packages/core-data/package.json @@ -25,6 +25,7 @@ "main": "build/index.js", "module": "build-module/index.js", "react-native": "src/index", + "types": "src/types/index.ts", "sideEffects": [ "{src,build,build-module}/index.js" ], diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 7d12746e49eba..88e16531aff96 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -210,12 +210,15 @@ export type Comment< C extends Context > = OmitNevers< >; // In the plugin -import { ExtensibleComment, Comment } from '@wordpress/core-data'; -interface ExtensibleComment < C extends Context > { - numberOfViews: number; +import { Context } from '@wordpress/core-data'; +declare module '@wordpress/core-data' { + interface ExtensibleComment< C extends Context > { + numberOfViews: number; + } } -const c : Comment = ... +import type { Comment } from '@wordpress/core-data'; +const c : Comment< 'view' > = ...; // c.numberOfViews is a number // c.id is still present diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 8b40df7fffaf1..2da899144b727 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -29,6 +29,7 @@ import type { import type { Context, Updatable } from './helpers'; export type { + Context, Updatable, Attachment, Comment, From fec0432355ed064cf0479b2b83f03d3b53967094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:44:25 +0100 Subject: [PATCH 60/73] Use namespaced base types for extenders --- packages/core-data/src/types/README.md | 18 +- packages/core-data/src/types/attachment.ts | 238 +++++----- packages/core-data/src/types/base-types.ts | 1 + packages/core-data/src/types/comment.ts | 151 ++++--- packages/core-data/src/types/index.ts | 66 +-- packages/core-data/src/types/menu-location.ts | 34 +- packages/core-data/src/types/nav-menu-item.ts | 158 +++---- packages/core-data/src/types/nav-menu.ts | 80 ++-- .../core-data/src/types/navigation-area.ts | 34 +- packages/core-data/src/types/page.ts | 242 ++++++----- packages/core-data/src/types/plugin.ts | 116 ++--- packages/core-data/src/types/post.ts | 258 +++++------ packages/core-data/src/types/settings.ts | 162 +++---- packages/core-data/src/types/sidebar.ts | 92 ++-- packages/core-data/src/types/taxonomy.ts | 154 +++---- packages/core-data/src/types/theme.ts | 406 +++++++++--------- packages/core-data/src/types/type.ts | 132 +++--- packages/core-data/src/types/user.ts | 184 ++++---- packages/core-data/src/types/widget-type.ts | 50 ++- packages/core-data/src/types/widget.ts | 104 ++--- .../core-data/src/types/wp-template-part.ts | 148 ++++--- packages/core-data/src/types/wp-template.ts | 148 ++++--- 22 files changed, 1580 insertions(+), 1396 deletions(-) create mode 100644 packages/core-data/src/types/base-types.ts diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 88e16531aff96..ccfa8c8dfc8e4 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -200,20 +200,26 @@ For example, if you're building a plugin that displays a number of views of each ```ts // In core-data -export interface ExtensibleComment< C extends Context > { - id: number; - // ... +declare module './base-types' { + export namespace BaseTypes { + export interface Comment< C extends Context > { + id: number; + // ... + } + } } export type Comment< C extends Context > = OmitNevers< - ExtensibleComment< C > + BaseTypes.Comment< C > >; // In the plugin import { Context } from '@wordpress/core-data'; declare module '@wordpress/core-data' { - interface ExtensibleComment< C extends Context > { - numberOfViews: number; + export namespace BaseTypes { + export interface Comment< C extends Context > { + numberOfViews: number; + } } } diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 5d14c75f1da70..d3ad130c32d6a 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -12,117 +12,135 @@ import { PingStatus, } from './helpers'; -export interface ExtensibleAttachment< C extends Context > { - /** - * The date the post was published, in the site's timezone. - */ - date: string | null; - /** - * The date the post was published, as GMT. - */ - date_gmt: ContextualField< string | null, 'view' | 'edit', C >; - /** - * The globally unique identifier for the post. - */ - guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; - /** - * Unique identifier for the post. - */ - id: number; - /** - * URL to the post. - */ - link: string; - /** - * The date the post was last modified, in the site's timezone. - */ - modified: ContextualField< string, 'view' | 'edit', C >; - /** - * The date the post was last modified, as GMT. - */ - modified_gmt: ContextualField< string, 'view' | 'edit', C >; - /** - * An alphanumeric identifier for the post unique to its type. - */ - slug: string; - /** - * A named status for the post. - */ - status: ContextualField< PostStatus, 'view' | 'edit', C >; - /** - * Type of post. - */ - type: string; - /** - * Permalink template for the post. - */ - permalink_template: ContextualField< string, 'edit', C >; - /** - * Slug automatically generated from the post title. - */ - generated_slug: ContextualField< string, 'edit', C >; - /** - * The title for the post. - */ - title: RenderedText< C >; - /** - * The ID for the author of the post. - */ - author: number; - /** - * Whether or not comments are open on the post. - */ - comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; - /** - * Whether or not the post can be pinged. - */ - ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; - /** - * The theme file to use to display the post. - */ - template: ContextualField< string, 'view' | 'edit', C >; - /** - * Alternative text to display when attachment is not displayed. - */ - alt_text: string; - /** - * The attachment caption. - */ - caption: ContextualField< string, 'edit', C >; - /** - * The attachment description. - */ - description: ContextualField< RenderedText< C >, 'view' | 'edit', C >; - /** - * Attachment type. - */ - media_type: MediaType; - /** - * The attachment MIME type. - */ - mime_type: string; - /** - * Details about the media file, specific to its type. - */ - media_details: Record< string, string >; - /** - * The ID for the associated post of the attachment. - */ - post: ContextualField< number, 'view' | 'edit', C >; - /** - * URL to the original attachment file. - */ - source_url: string; - /** - * List of the missing image sizes of the attachment. - */ - missing_image_sizes: ContextualField< string[], 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Attachment< C extends Context > { + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; + /** + * The globally unique identifier for the post. + */ + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified: ContextualField< string, 'view' | 'edit', C >; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt: ContextualField< string, 'view' | 'edit', C >; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status: ContextualField< PostStatus, 'view' | 'edit', C >; + /** + * Type of post. + */ + type: string; + /** + * Permalink template for the post. + */ + permalink_template: ContextualField< string, 'edit', C >; + /** + * Slug automatically generated from the post title. + */ + generated_slug: ContextualField< string, 'edit', C >; + /** + * The title for the post. + */ + title: RenderedText< C >; + /** + * The ID for the author of the post. + */ + author: number; + /** + * Whether or not comments are open on the post. + */ + comment_status: ContextualField< + CommentingStatus, + 'view' | 'edit', + C + >; + /** + * Whether or not the post can be pinged. + */ + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + /** + * The theme file to use to display the post. + */ + template: ContextualField< string, 'view' | 'edit', C >; + /** + * Alternative text to display when attachment is not displayed. + */ + alt_text: string; + /** + * The attachment caption. + */ + caption: ContextualField< string, 'edit', C >; + /** + * The attachment description. + */ + description: ContextualField< + RenderedText< C >, + 'view' | 'edit', + C + >; + /** + * Attachment type. + */ + media_type: MediaType; + /** + * The attachment MIME type. + */ + mime_type: string; + /** + * Details about the media file, specific to its type. + */ + media_details: Record< string, string >; + /** + * The ID for the associated post of the attachment. + */ + post: ContextualField< number, 'view' | 'edit', C >; + /** + * URL to the original attachment file. + */ + source_url: string; + /** + * List of the missing image sizes of the attachment. + */ + missing_image_sizes: ContextualField< string[], 'edit', C >; + } + } } export type Attachment< C extends Context > = OmitNevers< - ExtensibleAttachment< C > + _BaseTypes.Attachment< C > >; diff --git a/packages/core-data/src/types/base-types.ts b/packages/core-data/src/types/base-types.ts new file mode 100644 index 0000000000000..1089f64a083a6 --- /dev/null +++ b/packages/core-data/src/types/base-types.ts @@ -0,0 +1 @@ +export namespace BaseTypes {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 0d40e12708d4b..a9a3bbb832d40 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -8,78 +8,89 @@ import { OmitNevers, RenderedText, } from './helpers'; +import { BaseTypes as _BaseTypes } from './base-types'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; -export interface ExtensibleComment< C extends Context > { - /** - * Unique identifier for the comment. - */ - id: number; - /** - * The ID of the user object, if author was a user. - */ - author: number; - /** - * Email address for the comment author. - */ - author_email: ContextualField< string, 'edit', C >; - /** - * IP address for the comment author. - */ - author_ip: ContextualField< string, 'edit', C >; - /** - * Display name for the comment author. - */ - author_name: string; - /** - * URL for the comment author. - */ - author_url: string; - /** - * User agent for the comment author. - */ - author_user_agent: ContextualField< string, 'edit', C >; - /** - * The content for the comment. - */ - content: RenderedText< C >; - /** - * The date the comment was published, in the site's timezone. - */ - date: string; - /** - * The date the comment was published, as GMT. - */ - date_gmt: ContextualField< string, 'view' | 'edit', C >; - /** - * URL to the comment. - */ - link: string; - /** - * The ID for the parent of the comment. - */ - parent: number; - /** - * The ID of the associated post object. - */ - post: ContextualField< number, 'view' | 'edit', C >; - /** - * State of the comment. - */ - status: ContextualField< CommentStatus, 'view' | 'edit', C >; - /** - * Type of the comment. - */ - type: string; - /** - * Avatar URLs for the comment author. - */ - author_avatar_urls: AvatarUrls; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; +declare module './base-types' { + export namespace BaseTypes { + export interface Comment< C extends Context > { + /** + * Unique identifier for the comment. + */ + id: number; + /** + * The ID of the user object, if author was a user. + */ + author: number; + /** + * Email address for the comment author. + */ + author_email: ContextualField< string, 'edit', C >; + /** + * IP address for the comment author. + */ + author_ip: ContextualField< string, 'edit', C >; + /** + * Display name for the comment author. + */ + author_name: string; + /** + * URL for the comment author. + */ + author_url: string; + /** + * User agent for the comment author. + */ + author_user_agent: ContextualField< string, 'edit', C >; + /** + * The content for the comment. + */ + content: RenderedText< C >; + /** + * The date the comment was published, in the site's timezone. + */ + date: string; + /** + * The date the comment was published, as GMT. + */ + date_gmt: ContextualField< string, 'view' | 'edit', C >; + /** + * URL to the comment. + */ + link: string; + /** + * The ID for the parent of the comment. + */ + parent: number; + /** + * The ID of the associated post object. + */ + post: ContextualField< number, 'view' | 'edit', C >; + /** + * State of the comment. + */ + status: ContextualField< CommentStatus, 'view' | 'edit', C >; + /** + * Type of the comment. + */ + type: string; + /** + * Avatar URLs for the comment author. + */ + author_avatar_urls: AvatarUrls; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + } + } } -export type Comment< C extends Context > = OmitNevers< ExtensibleComment< C > >; +export type Comment< C extends Context > = OmitNevers< + _BaseTypes.Comment< C > +>; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 2da899144b727..b2230aefeb4cc 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -1,33 +1,29 @@ /** * Internal dependencies */ -import type { ExtensibleAttachment, Attachment } from './attachment'; -import type { ExtensibleComment, Comment } from './comment'; -import type { ExtensibleMenuLocation, MenuLocation } from './menu-location'; -import type { ExtensibleNavMenu, NavMenu } from './nav-menu'; -import type { ExtensibleNavMenuItem, NavMenuItem } from './nav-menu-item'; -import type { - ExtensibleNavigationArea, - NavigationArea, -} from './navigation-area'; -import type { ExtensiblePage, Page } from './page'; -import type { ExtensiblePlugin, Plugin } from './plugin'; -import type { ExtensiblePost, Post } from './post'; -import type { ExtensibleSettings, Settings } from './settings'; -import type { ExtensibleSidebar, Sidebar } from './sidebar'; -import type { ExtensibleTaxonomy, Taxonomy } from './taxonomy'; -import type { ExtensibleTheme, Theme } from './theme'; -import type { ExtensibleUser, User } from './user'; -import type { ExtensibleType, Type } from './type'; -import type { ExtensibleWidget, Widget } from './widget'; -import type { ExtensibleWidgetType, WidgetType } from './widget-type'; -import type { ExtensibleWpTemplate, WpTemplate } from './wp-template'; -import type { - ExtensibleWpTemplatePart, - WpTemplatePart, -} from './wp-template-part'; +import type { Attachment } from './attachment'; +import type { Comment } from './comment'; +import type { MenuLocation } from './menu-location'; +import type { NavMenu } from './nav-menu'; +import type { NavMenuItem } from './nav-menu-item'; +import type { NavigationArea } from './navigation-area'; +import type { Page } from './page'; +import type { Plugin } from './plugin'; +import type { Post } from './post'; +import type { Settings } from './settings'; +import type { Sidebar } from './sidebar'; +import type { Taxonomy } from './taxonomy'; +import type { Theme } from './theme'; +import type { User } from './user'; +import type { Type } from './type'; +import type { Widget } from './widget'; +import type { WidgetType } from './widget-type'; +import type { WpTemplate } from './wp-template'; +import type { WpTemplatePart } from './wp-template-part'; import type { Context, Updatable } from './helpers'; +export type { BaseTypes } from './base-types'; + export type { Context, Updatable, @@ -74,23 +70,3 @@ export type EntityRecord< C extends Context > = | WpTemplatePart< C >; export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >; - -export type { ExtensibleAttachment } from './attachment'; -export type { ExtensibleComment } from './comment'; -export type { ExtensibleMenuLocation } from './menu-location'; -export type { ExtensibleNavMenu } from './nav-menu'; -export type { ExtensibleNavMenuItem } from './nav-menu-item'; -export type { ExtensibleNavigationArea } from './navigation-area'; -export type { ExtensiblePage } from './page'; -export type { ExtensiblePlugin } from './plugin'; -export type { ExtensiblePost } from './post'; -export type { ExtensibleSettings } from './settings'; -export type { ExtensibleSidebar } from './sidebar'; -export type { ExtensibleTaxonomy } from './taxonomy'; -export type { ExtensibleTheme } from './theme'; -export type { ExtensibleUser } from './user'; -export type { ExtensibleType } from './type'; -export type { ExtensibleWidget } from './widget'; -export type { ExtensibleWidgetType } from './widget-type'; -export type { ExtensibleWpTemplate } from './wp-template'; -export type { ExtensibleWpTemplatePart } from './wp-template-part'; diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 45062c98b1821..32dbd8e6fbaee 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -3,21 +3,27 @@ */ import { Context, OmitNevers } from './helpers'; -export interface ExtensibleMenuLocation< C extends Context > { - /** - * The name of the menu location. - */ - name: string; - /** - * The description of the menu location. - */ - description: string; - /** - * The ID of the assigned menu. - */ - menu: number; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface MenuLocation< C extends Context > { + /** + * The name of the menu location. + */ + name: string; + /** + * The description of the menu location. + */ + description: string; + /** + * The ID of the assigned menu. + */ + menu: number; + } + } } export type MenuLocation< C extends Context > = OmitNevers< - ExtensibleMenuLocation< C > + _BaseTypes.MenuLocation< C > >; diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index 111ccf30ccc7f..e9b0b6878a095 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -3,6 +3,8 @@ */ import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; +import { BaseTypes as _BaseTypes } from './base-types'; + export type NavMenuItemType = | 'taxonomy' | 'post_type' @@ -16,81 +18,89 @@ export type NavMenuItemStatus = | 'private'; export type Target = '_blank' | ''; -export interface ExtensibleNavMenuItem< C extends Context > { - /** - * The title for the object. - */ - title: RenderedText< C >; - /** - * Unique identifier for the object. - */ - id: number; - /** - * The singular label used to describe this type of menu item. - */ - type_label: string; - /** - * The family of objects originally represented, such as "post_type" or "taxonomy". - */ - type: NavMenuItemType; - /** - * A named status for the object. - */ - status: NavMenuItemStatus; - /** - * The ID for the parent of the object. - */ - parent: number; - /** - * Text for the title attribute of the link element for this menu item. - */ - attr_title: string; - /** - * Class names for the link element of this menu item. - */ - classes: string[]; - /** - * The description of this menu item. - */ - description: string; - /** - * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. - */ - menu_order: number; - /** - * The type of object originally represented, such as "category", "post", or "attachment". - */ - object: string; - /** - * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. - */ - object_id: number; - /** - * The target attribute of the link element for this menu item. - */ - target: Target; - /** - * The URL to which this menu item points. - */ - url: string; - /** - * The XFN relationship expressed in the link of this menu item. - */ - xfn: string[]; - /** - * Whether the menu item represents an object that no longer exists. - */ - invalid: boolean; - /** - * The terms assigned to the object in the nav_menu taxonomy. - */ - menus: ContextualField< number, 'view' | 'edit', C >; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; +declare module './base-types' { + export namespace BaseTypes { + export interface NavMenuItem< C extends Context > { + /** + * The title for the object. + */ + title: RenderedText< C >; + /** + * Unique identifier for the object. + */ + id: number; + /** + * The singular label used to describe this type of menu item. + */ + type_label: string; + /** + * The family of objects originally represented, such as "post_type" or "taxonomy". + */ + type: NavMenuItemType; + /** + * A named status for the object. + */ + status: NavMenuItemStatus; + /** + * The ID for the parent of the object. + */ + parent: number; + /** + * Text for the title attribute of the link element for this menu item. + */ + attr_title: string; + /** + * Class names for the link element of this menu item. + */ + classes: string[]; + /** + * The description of this menu item. + */ + description: string; + /** + * The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0. + */ + menu_order: number; + /** + * The type of object originally represented, such as "category", "post", or "attachment". + */ + object: string; + /** + * The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories. + */ + object_id: number; + /** + * The target attribute of the link element for this menu item. + */ + target: Target; + /** + * The URL to which this menu item points. + */ + url: string; + /** + * The XFN relationship expressed in the link of this menu item. + */ + xfn: string[]; + /** + * Whether the menu item represents an object that no longer exists. + */ + invalid: boolean; + /** + * The terms assigned to the object in the nav_menu taxonomy. + */ + menus: ContextualField< number, 'view' | 'edit', C >; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + } + } } export type NavMenuItem< C extends Context > = OmitNevers< - ExtensibleNavMenuItem< C > + _BaseTypes.NavMenuItem< C > >; diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index 78a959aebb28b..194a64c1d74b0 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -3,39 +3,51 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -export interface ExtensibleNavMenu< C extends Context > { - /** - * Unique identifier for the term. - */ - id: number; - /** - * HTML description of the term. - */ - description: ContextualField< string, 'view' | 'edit', C >; - /** - * HTML title for the term. - */ - name: string; - /** - * An alphanumeric identifier for the term unique to its type. - */ - slug: string; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; - /** - * The locations assigned to the menu. - */ - locations: ContextualField< string[], 'view' | 'edit', C >; - /** - * The DB ID of the original object this menu item represents, e . g . ID for posts and term_id for categories. - */ - object_id: number; - /** - * Whether to automatically add top level pages to this menu. - */ - auto_add: ContextualField< boolean, 'view' | 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface NavMenu< C extends Context > { + /** + * Unique identifier for the term. + */ + id: number; + /** + * HTML description of the term. + */ + description: ContextualField< string, 'view' | 'edit', C >; + /** + * HTML title for the term. + */ + name: string; + /** + * An alphanumeric identifier for the term unique to its type. + */ + slug: string; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + /** + * The locations assigned to the menu. + */ + locations: ContextualField< string[], 'view' | 'edit', C >; + /** + * The DB ID of the original object this menu item represents, e . g . ID for posts and term_id for categories. + */ + object_id: number; + /** + * Whether to automatically add top level pages to this menu. + */ + auto_add: ContextualField< boolean, 'view' | 'edit', C >; + } + } } -export type NavMenu< C extends Context > = OmitNevers< ExtensibleNavMenu< C > >; +export type NavMenu< C extends Context > = OmitNevers< + _BaseTypes.NavMenu< C > +>; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 3ba97482d99d2..8fc8e74b799a8 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -3,21 +3,27 @@ */ import { Context, OmitNevers } from './helpers'; -export interface ExtensibleNavigationArea< C extends Context > { - /** - * The name of the navigation area. - */ - name: string; - /** - * The description of the navigation area. - */ - description: string; - /** - * The ID of the assigned navigation. - */ - navigation: number; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface NavigationArea< C extends Context > { + /** + * The name of the navigation area. + */ + name: string; + /** + * The description of the navigation area. + */ + description: string; + /** + * The ID of the assigned navigation. + */ + navigation: number; + } + } } export type NavigationArea< C extends Context > = OmitNevers< - ExtensibleNavigationArea< C > + _BaseTypes.NavigationArea< C > >; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index ef9daefd3f050..f3016d246ee51 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -11,118 +11,134 @@ import { OmitNevers, } from './helpers'; -export interface ExtensiblePage< C extends Context > { - /** - * The date the post was published, in the site's timezone. - */ - date: string | null; - /** - * The date the post was published, as GMT. - */ - date_gmt: ContextualField< string | null, 'view' | 'edit', C >; - /** - * The globally unique identifier for the post. - */ - guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; - /** - * Unique identifier for the post. - */ - id: number; - /** - * URL to the post. - */ - link: string; - /** - * The date the post was last modified, in the site's timezone. - */ - modified: ContextualField< string, 'view' | 'edit', C >; - /** - * The date the post was last modified, as GMT. - */ - modified_gmt: ContextualField< string, 'view' | 'edit', C >; - /** - * An alphanumeric identifier for the post unique to its type. - */ - slug: string; - /** - * A named status for the post. - */ - status: ContextualField< PostStatus, 'view' | 'edit', C >; - /** - * Type of post. - */ - type: string; - /** - * A password to protect access to the content and excerpt. - */ - password: ContextualField< string, 'edit', C >; - /** - * Permalink template for the post. - */ - permalink_template: ContextualField< string, 'edit', C >; - /** - * Slug automatically generated from the post title. - */ - generated_slug: ContextualField< string, 'edit', C >; - /** - * The ID for the parent of the post. - */ - parent: ContextualField< number, 'view' | 'edit', C >; - /** - * The title for the post. - */ - title: RenderedText< C >; - /** - * The content for the post. - */ - content: ContextualField< - RenderedText< C > & { - /** - * Whether the content is protected with a password. - */ - is_protected: boolean; - /** - * Version of the content block format used by the page. - */ - block_version: ContextualField< string, 'edit', C >; - }, - 'view' | 'edit', - C - >; - /** - * The ID for the author of the post. - */ - author: number; - /** - * The excerpt for the post. - */ - excerpt: RenderedText< C > & { - protected: boolean; - }; - /** - * The ID of the featured media for the post. - */ - featured_media: number; - /** - * Whether or not comments are open on the post. - */ - comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; - /** - * Whether or not the post can be pinged. - */ - ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; - /** - * The order of the post in relation to other posts. - */ - menu_order: ContextualField< number, 'view' | 'edit', C >; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; - /** - * The theme file to use to display the post. - */ - template: ContextualField< string, 'view' | 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Page< C extends Context > { + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; + /** + * The globally unique identifier for the post. + */ + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified: ContextualField< string, 'view' | 'edit', C >; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt: ContextualField< string, 'view' | 'edit', C >; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status: ContextualField< PostStatus, 'view' | 'edit', C >; + /** + * Type of post. + */ + type: string; + /** + * A password to protect access to the content and excerpt. + */ + password: ContextualField< string, 'edit', C >; + /** + * Permalink template for the post. + */ + permalink_template: ContextualField< string, 'edit', C >; + /** + * Slug automatically generated from the post title. + */ + generated_slug: ContextualField< string, 'edit', C >; + /** + * The ID for the parent of the post. + */ + parent: ContextualField< number, 'view' | 'edit', C >; + /** + * The title for the post. + */ + title: RenderedText< C >; + /** + * The content for the post. + */ + content: ContextualField< + RenderedText< C > & { + /** + * Whether the content is protected with a password. + */ + is_protected: boolean; + /** + * Version of the content block format used by the page. + */ + block_version: ContextualField< string, 'edit', C >; + }, + 'view' | 'edit', + C + >; + /** + * The ID for the author of the post. + */ + author: number; + /** + * The excerpt for the post. + */ + excerpt: RenderedText< C > & { + protected: boolean; + }; + /** + * The ID of the featured media for the post. + */ + featured_media: number; + /** + * Whether or not comments are open on the post. + */ + comment_status: ContextualField< + CommentingStatus, + 'view' | 'edit', + C + >; + /** + * Whether or not the post can be pinged. + */ + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; + /** + * The order of the post in relation to other posts. + */ + menu_order: ContextualField< number, 'view' | 'edit', C >; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + /** + * The theme file to use to display the post. + */ + template: ContextualField< string, 'view' | 'edit', C >; + } + } } -export type Page< C extends Context > = OmitNevers< ExtensiblePage< C > >; +export type Page< C extends Context > = OmitNevers< + _BaseTypes.Page< C > +>; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 676a41f5e10e6..00a8fcc24dfda 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -3,56 +3,72 @@ */ import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; -export interface ExtensiblePlugin< C extends Context > { - /** - * The plugin file. - */ - plugin: string; - /** - * The plugin activation status. - */ - status: PluginStatus; - /** - * The plugin name. - */ - name: string; - /** - * The plugin's website address. - */ - plugin_uri: ContextualField< string, 'view' | 'edit', C >; - /** - * The plugin author. - */ - author: ContextualField< Record< string, string >, 'view' | 'edit', C >; - /** - * Plugin author's website address. - */ - author_uri: ContextualField< string, 'view' | 'edit', C >; - /** - * The plugin description. - */ - description: ContextualField< RenderedText< 'edit' >, 'view' | 'edit', C >; - /** - * The plugin version number. - */ - version: ContextualField< string, 'view' | 'edit', C >; - /** - * Whether the plugin can only be activated network-wide. - */ - network_only: boolean; - /** - * Minimum required version of WordPress. - */ - requires_wp: string; - /** - * Minimum required version of PHP. - */ - requires_php: string; - /** - * The plugin's text domain. - */ - textdomain: ContextualField< string, 'view' | 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Plugin< C extends Context > { + /** + * The plugin file. + */ + plugin: string; + /** + * The plugin activation status. + */ + status: PluginStatus; + /** + * The plugin name. + */ + name: string; + /** + * The plugin's website address. + */ + plugin_uri: ContextualField< string, 'view' | 'edit', C >; + /** + * The plugin author. + */ + author: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + /** + * Plugin author's website address. + */ + author_uri: ContextualField< string, 'view' | 'edit', C >; + /** + * The plugin description. + */ + description: ContextualField< + RenderedText< 'edit' >, + 'view' | 'edit', + C + >; + /** + * The plugin version number. + */ + version: ContextualField< string, 'view' | 'edit', C >; + /** + * Whether the plugin can only be activated network-wide. + */ + network_only: boolean; + /** + * Minimum required version of WordPress. + */ + requires_wp: string; + /** + * Minimum required version of PHP. + */ + requires_php: string; + /** + * The plugin's text domain. + */ + textdomain: ContextualField< string, 'view' | 'edit', C >; + } + } } export type PluginStatus = 'active' | 'inactive'; -export type Plugin< C extends Context > = OmitNevers< ExtensiblePlugin< C > >; +export type Plugin< C extends Context > = OmitNevers< + _BaseTypes.Plugin< C > +>; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 7119fcc5cb606..53a248a703566 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -12,126 +12,142 @@ import { OmitNevers, } from './helpers'; -export interface ExtensiblePost< C extends Context > { - /** - * The date the post was published, in the site's timezone. - */ - date: string | null; - /** - * The date the post was published, as GMT. - */ - date_gmt: ContextualField< string | null, 'view' | 'edit', C >; - /** - * The globally unique identifier for the post. - */ - guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; - /** - * Unique identifier for the post. - */ - id: number; - /** - * URL to the post. - */ - link: string; - /** - * The date the post was last modified, in the site's timezone. - */ - modified: ContextualField< string, 'view' | 'edit', C >; - /** - * The date the post was last modified, as GMT. - */ - modified_gmt: ContextualField< string, 'view' | 'edit', C >; - /** - * An alphanumeric identifier for the post unique to its type. - */ - slug: string; - /** - * A named status for the post. - */ - status: ContextualField< PostStatus, 'view' | 'edit', C >; - /** - * Type of post. - */ - type: string; - /** - * A password to protect access to the content and excerpt. - */ - password: ContextualField< string, 'edit', C >; - /** - * Permalink template for the post. - */ - permalink_template: ContextualField< string, 'edit', C >; - /** - * Slug automatically generated from the post title. - */ - generated_slug: ContextualField< string, 'edit', C >; - /** - * The title for the post. - */ - title: RenderedText< C >; - /** - * The content for the post. - */ - content: ContextualField< - RenderedText< C > & { - /** - * Whether the content is protected with a password. - */ - is_protected: boolean; - /** - * Version of the content block format used by the page. - */ - block_version: ContextualField< string, 'edit', C >; - }, - 'view' | 'edit', - C - >; - /** - * The ID for the author of the post. - */ - author: number; - /** - * The excerpt for the post. - */ - excerpt: RenderedText< C > & { - protected: boolean; - }; - /** - * The ID of the featured media for the post. - */ - featured_media: number; - /** - * Whether or not comments are open on the post. - */ - comment_status: ContextualField< CommentingStatus, 'view' | 'edit', C >; - /** - * Whether or not the post can be pinged. - */ - ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; - /** - * The format for the post. - */ - format: ContextualField< PostFormat, 'view' | 'edit', C >; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; - /** - * Whether or not the post should be treated as sticky. - */ - sticky: ContextualField< boolean, 'view' | 'edit', C >; - /** - * The theme file to use to display the post. - */ - template: ContextualField< string, 'view' | 'edit', C >; - /** - * The terms assigned to the post in the category taxonomy. - */ - categories: ContextualField< number[], 'view' | 'edit', C >; - /** - * The terms assigned to the post in the post_tag taxonomy. - */ - tags: ContextualField< number[], 'view' | 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Post< C extends Context > { + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt: ContextualField< string | null, 'view' | 'edit', C >; + /** + * The globally unique identifier for the post. + */ + guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * The date the post was last modified, in the site's timezone. + */ + modified: ContextualField< string, 'view' | 'edit', C >; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt: ContextualField< string, 'view' | 'edit', C >; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status: ContextualField< PostStatus, 'view' | 'edit', C >; + /** + * Type of post. + */ + type: string; + /** + * A password to protect access to the content and excerpt. + */ + password: ContextualField< string, 'edit', C >; + /** + * Permalink template for the post. + */ + permalink_template: ContextualField< string, 'edit', C >; + /** + * Slug automatically generated from the post title. + */ + generated_slug: ContextualField< string, 'edit', C >; + /** + * The title for the post. + */ + title: RenderedText< C >; + /** + * The content for the post. + */ + content: ContextualField< + RenderedText< C > & { + /** + * Whether the content is protected with a password. + */ + is_protected: boolean; + /** + * Version of the content block format used by the page. + */ + block_version: ContextualField< string, 'edit', C >; + }, + 'view' | 'edit', + C + >; + /** + * The ID for the author of the post. + */ + author: number; + /** + * The excerpt for the post. + */ + excerpt: RenderedText< C > & { + protected: boolean; + }; + /** + * The ID of the featured media for the post. + */ + featured_media: number; + /** + * Whether or not comments are open on the post. + */ + comment_status: ContextualField< + CommentingStatus, + 'view' | 'edit', + C + >; + /** + * Whether or not the post can be pinged. + */ + ping_status: ContextualField< PingStatus, 'view' | 'edit', C >; + /** + * The format for the post. + */ + format: ContextualField< PostFormat, 'view' | 'edit', C >; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + /** + * Whether or not the post should be treated as sticky. + */ + sticky: ContextualField< boolean, 'view' | 'edit', C >; + /** + * The theme file to use to display the post. + */ + template: ContextualField< string, 'view' | 'edit', C >; + /** + * The terms assigned to the post in the category taxonomy. + */ + categories: ContextualField< number[], 'view' | 'edit', C >; + /** + * The terms assigned to the post in the post_tag taxonomy. + */ + tags: ContextualField< number[], 'view' | 'edit', C >; + } + } } -export type Post< C extends Context > = OmitNevers< ExtensiblePost< C > >; +export type Post< C extends Context > = OmitNevers< + _BaseTypes.Post< C > +>; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index a8ad086e695d8..c4bea67af7b34 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -3,85 +3,91 @@ */ import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers'; -export interface ExtensibleSettings< C extends Context > { - /** - * What to show on the front page - */ - show_on_front: string; - /** - * The ID of the page that should be displayed on the front page - */ - page_on_front: number; - /** - * Site title. - */ - title: string; - /** - * Site tagline. - */ - description: string; - /** - * Site URL. - */ - url: string; - /** - * This address is used for admin purposes, like new user notification. - */ - email: string; - /** - * A city in the same timezone as you. - */ - timezone: string; - /** - * A date format for all date strings. - */ - date_format: string; - /** - * A time format for all time strings. - */ - time_format: string; - /** - * A day number of the week that the week should start on. - */ - start_of_week: number; - /** - * WordPress locale code. - */ - language: string; - /** - * Convert emoticons like :-) and :-P to graphics on display. - */ - use_smilies: boolean; - /** - * Default post category. - */ - default_category: number; - /** - * Default post format. - */ - default_post_format: string; - /** - * Blog pages show at most. - */ - posts_per_page: number; - /** - * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. - */ - default_ping_status: PingStatus; - /** - * Allow people to submit comments on new posts. - */ - default_comment_status: CommentingStatus; - /** - * Site logo. - */ - site_logo: number; - /** - * Site icon. - */ - site_icon: number; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Settings< C extends Context > { + /** + * What to show on the front page + */ + show_on_front: string; + /** + * The ID of the page that should be displayed on the front page + */ + page_on_front: number; + /** + * Site title. + */ + title: string; + /** + * Site tagline. + */ + description: string; + /** + * Site URL. + */ + url: string; + /** + * This address is used for admin purposes, like new user notification. + */ + email: string; + /** + * A city in the same timezone as you. + */ + timezone: string; + /** + * A date format for all date strings. + */ + date_format: string; + /** + * A time format for all time strings. + */ + time_format: string; + /** + * A day number of the week that the week should start on. + */ + start_of_week: number; + /** + * WordPress locale code. + */ + language: string; + /** + * Convert emoticons like :-) and :-P to graphics on display. + */ + use_smilies: boolean; + /** + * Default post category. + */ + default_category: number; + /** + * Default post format. + */ + default_post_format: string; + /** + * Blog pages show at most. + */ + posts_per_page: number; + /** + * Allow link notifications from other blogs (pingbacks and trackbacks) on new articles. + */ + default_ping_status: PingStatus; + /** + * Allow people to submit comments on new posts. + */ + default_comment_status: CommentingStatus; + /** + * Site logo. + */ + site_logo: number; + /** + * Site icon. + */ + site_icon: number; + } + } } export type Settings< C extends Context > = OmitNevers< - ExtensibleSettings< C > + _BaseTypes.Settings< C > >; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 6cb60af3cafc4..1bc3def698afd 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -4,49 +4,57 @@ import { Widget } from './widget'; import { Context, OmitNevers } from './helpers'; -export interface ExtensibleSidebar< C extends Context > { - /** - * ID of sidebar. - */ - id: string; - /** - * Unique name identifying the sidebar. - */ - name: string; - /** - * Description of sidebar. - */ - description: string; - /** - * Extra CSS class to assign to the sidebar in the Widgets interface. - */ - class: string; - /** - * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. - */ - before_widget: string; - /** - * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. - */ - after_widget: string; - /** - * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. - */ - before_title: string; - /** - * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. - */ - after_title: string; - /** - * Status of sidebar. - */ - status: SidebarStatus; - /** - * Nested widgets. - */ - widgets: ( Widget< C > | string )[]; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Sidebar< C extends Context > { + /** + * ID of sidebar. + */ + id: string; + /** + * Unique name identifying the sidebar. + */ + name: string; + /** + * Description of sidebar. + */ + description: string; + /** + * Extra CSS class to assign to the sidebar in the Widgets interface. + */ + class: string; + /** + * HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element. + */ + before_widget: string; + /** + * HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element. + */ + after_widget: string; + /** + * HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element. + */ + before_title: string; + /** + * HTML content to append to the sidebar title when displayed. Default is a closing h2 element. + */ + after_title: string; + /** + * Status of sidebar. + */ + status: SidebarStatus; + /** + * Nested widgets. + */ + widgets: ( Widget< C > | string )[]; + } + } } type SidebarStatus = 'active' | 'inactive'; -export type Sidebar< C extends Context > = OmitNevers< ExtensibleSidebar< C > >; +export type Sidebar< C extends Context > = OmitNevers< + _BaseTypes.Sidebar< C > +>; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index a428fa59c5ff2..e7c3e46256fcd 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -3,80 +3,90 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -export interface ExtensibleTaxonomy< C extends Context > { - /** - * All capabilities used by the taxonomy. - */ - capabilities: ContextualField< Record< string, string >, 'edit', C >; - /** - * A human-readable description of the taxonomy. - */ - description: ContextualField< string, 'view' | 'edit', C >; - /** - * Whether or not the taxonomy should have children. - */ - hierarchical: ContextualField< boolean, 'view' | 'edit', C >; - /** - * Human-readable labels for the taxonomy for various contexts. - */ - labels: ContextualField< Record< string, string >, 'edit', C >; - /** - * The title for the taxonomy. - */ - name: string; - /** - * An alphanumeric identifier for the taxonomy. - */ - slug: string; - /** - * Whether or not the term cloud should be displayed. - */ - show_cloud: ContextualField< boolean, 'edit', C >; - /** - * Types associated with the taxonomy. - */ - types: ContextualField< string[], 'view' | 'edit', C >; - /** - * REST base route for the taxonomy. - */ - rest_base: string; - /** - * REST namespace route for the taxonomy. - */ - rest_namespace: string; - /** - * The visibility settings for the taxonomy. - */ - visibility: TaxonomyVisibility; -} +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Taxonomy< C extends Context > { + /** + * All capabilities used by the taxonomy. + */ + capabilities: ContextualField< + Record< string, string >, + 'edit', + C + >; + /** + * A human-readable description of the taxonomy. + */ + description: ContextualField< string, 'view' | 'edit', C >; + /** + * Whether or not the taxonomy should have children. + */ + hierarchical: ContextualField< boolean, 'view' | 'edit', C >; + /** + * Human-readable labels for the taxonomy for various contexts. + */ + labels: ContextualField< Record< string, string >, 'edit', C >; + /** + * The title for the taxonomy. + */ + name: string; + /** + * An alphanumeric identifier for the taxonomy. + */ + slug: string; + /** + * Whether or not the term cloud should be displayed. + */ + show_cloud: ContextualField< boolean, 'edit', C >; + /** + * Types associated with the taxonomy. + */ + types: ContextualField< string[], 'view' | 'edit', C >; + /** + * REST base route for the taxonomy. + */ + rest_base: string; + /** + * REST namespace route for the taxonomy. + */ + rest_namespace: string; + /** + * The visibility settings for the taxonomy. + */ + visibility: TaxonomyVisibility; + } -export interface TaxonomyVisibility { - /** - * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. - */ - public: boolean; - /** - * Whether the taxonomy is publicly queryable. - */ - publicly_queryable: boolean; - /** - * Whether to generate a default UI for managing this taxonomy. - */ - show_ui: boolean; - /** - * Whether to allow automatic creation of taxonomy columns on associated post-types table. - */ - show_admin_column: boolean; - /** - * Whether to make the taxonomy available for selection in navigation menus. - */ - show_in_nav_menus: boolean; - /** - * Whether to show the taxonomy in the quick/bulk edit panel. - */ - show_in_quick_edit: boolean; + export interface TaxonomyVisibility { + /** + * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. + */ + public: boolean; + /** + * Whether the taxonomy is publicly queryable. + */ + publicly_queryable: boolean; + /** + * Whether to generate a default UI for managing this taxonomy. + */ + show_ui: boolean; + /** + * Whether to allow automatic creation of taxonomy columns on associated post-types table. + */ + show_admin_column: boolean; + /** + * Whether to make the taxonomy available for selection in navigation menus. + */ + show_in_nav_menus: boolean; + /** + * Whether to show the taxonomy in the quick/bulk edit panel. + */ + show_in_quick_edit: boolean; + } + } } export type Taxonomy< C extends Context > = OmitNevers< - ExtensibleTaxonomy< C > + _BaseTypes.Taxonomy< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 0b5fdc228bcf7..829efb2249f5c 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -3,212 +3,220 @@ */ import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; -export interface ExtensibleTheme< C extends Context > { - /** - * The theme's stylesheet. This uniquely identifies the theme. - */ - stylesheet: string; - /** - * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. - */ - template: string; - /** - * The theme author. - */ - author: RenderedText< 'edit' >; - /** - * The website of the theme author. - */ - author_uri: RenderedText< 'edit' >; - /** - * A description of the theme. - */ - description: RenderedText< 'edit' >; - /** - * The name of the theme. - */ - name: RenderedText< 'edit' >; - /** - * The minimum PHP version required for the theme to work. - */ - requires_php: string; - /** - * The minimum WordPress version required for the theme to work. - */ - requires_wp: string; - /** - * The theme's screenshot URL. - */ - screenshot: string; - /** - * Tags indicating styles and features of the theme. - */ - tags: RenderedText< 'edit' >; - /** - * The theme's text domain. - */ - textdomain: string; - /** - * Features supported by this theme. - */ - theme_supports: ThemeSupports; - /** - * The URI of the theme's webpage. - */ - theme_uri: RenderedText< 'edit' >; - /** - * The theme's current version. - */ - version: string; - /** - * A named status for the theme. - */ - status: ThemeStatus; -} +import { BaseTypes as _BaseTypes } from './base-types'; -export type ThemeStatus = 'active' | 'inactive'; +declare module './base-types' { + export namespace BaseTypes { + export interface Theme< C extends Context > { + /** + * The theme's stylesheet. This uniquely identifies the theme. + */ + stylesheet: string; + /** + * The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet. + */ + template: string; + /** + * The theme author. + */ + author: RenderedText< 'edit' >; + /** + * The website of the theme author. + */ + author_uri: RenderedText< 'edit' >; + /** + * A description of the theme. + */ + description: RenderedText< 'edit' >; + /** + * The name of the theme. + */ + name: RenderedText< 'edit' >; + /** + * The minimum PHP version required for the theme to work. + */ + requires_php: string; + /** + * The minimum WordPress version required for the theme to work. + */ + requires_wp: string; + /** + * The theme's screenshot URL. + */ + screenshot: string; + /** + * Tags indicating styles and features of the theme. + */ + tags: RenderedText< 'edit' >; + /** + * The theme's text domain. + */ + textdomain: string; + /** + * Features supported by this theme. + */ + theme_supports: ThemeSupports; + /** + * The URI of the theme's webpage. + */ + theme_uri: RenderedText< 'edit' >; + /** + * The theme's current version. + */ + version: string; + /** + * A named status for the theme. + */ + status: ThemeStatus; + } -interface ThemeSupports { - /** - * Whether theme opts in to wide alignment CSS class. - */ - 'align-wide': boolean; - /** - * Whether posts and comments RSS feed links are added to head. - */ - 'automatic-feed-links': boolean; - /** - * Custom background if defined by the theme. - */ - 'custom-background': boolean | CustomBackground; - /** - * Custom header if defined by the theme. - */ - 'custom-header': boolean | CustomHeader; - /** - * Custom logo if defined by the theme. - */ - 'custom-logo': boolean | CustomLogo; - /** - * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. - */ - 'customize-selective-refresh-widgets': boolean; - /** - * Whether theme opts in to the dark editor style UI. - */ - 'dark-editor-style': boolean; - /** - * Whether the theme disables custom colors. - */ - 'disable-custom-colors': boolean; - /** - * Whether the theme disables custom font sizes. - */ - 'disable-custom-font-sizes': boolean; - /** - * Whether the theme disables custom gradients. - */ - 'disable-custom-gradients': boolean; - /** - * Custom color palette if defined by the theme. - */ - 'editor-color-palette': boolean | Color[]; - /** - * Custom font sizes if defined by the theme. - */ - 'editor-font-sizes': boolean | FontSize[]; - /** - * Custom gradient presets if defined by the theme. - */ - 'editor-gradient-presets': boolean | GradientPreset[]; - /** - * Whether theme opts in to the editor styles CSS wrapper. - */ - 'editor-styles': boolean; - /** - * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. - */ - html5: boolean | Html5Option[]; - /** - * Post formats supported. - */ - formats: PostFormat[]; - /** - * The post types that support thumbnails or true if all post types are supported. - */ - 'post-thumbnails': boolean | string[]; - /** - * Whether the theme supports responsive embedded content. - */ - 'responsive-embeds': boolean; - /** - * Whether the theme can manage the document title tag. - */ - 'title-tag': boolean; - /** - * Whether theme opts in to default WordPress block styles for viewing. - */ - 'wp-block-styles': boolean; -} + export type ThemeStatus = 'active' | 'inactive'; -export interface CustomBackground { - 'default-image': string; - 'default-preset': 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; - 'default-position-x': 'left' | 'center' | 'right'; - 'default-position-y': 'left' | 'center' | 'right'; - 'default-size': 'auto' | 'contain' | 'cover'; - 'default-repeat': 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; - 'default-attachment': 'scroll' | 'fixed'; - 'default-color': string; -} + export interface ThemeSupports { + /** + * Whether theme opts in to wide alignment CSS class. + */ + 'align-wide': boolean; + /** + * Whether posts and comments RSS feed links are added to head. + */ + 'automatic-feed-links': boolean; + /** + * Custom background if defined by the theme. + */ + 'custom-background': boolean | CustomBackground; + /** + * Custom header if defined by the theme. + */ + 'custom-header': boolean | CustomHeader; + /** + * Custom logo if defined by the theme. + */ + 'custom-logo': boolean | CustomLogo; + /** + * Whether the theme enables Selective Refresh for Widgets being managed with the Customizer. + */ + 'customize-selective-refresh-widgets': boolean; + /** + * Whether theme opts in to the dark editor style UI. + */ + 'dark-editor-style': boolean; + /** + * Whether the theme disables custom colors. + */ + 'disable-custom-colors': boolean; + /** + * Whether the theme disables custom font sizes. + */ + 'disable-custom-font-sizes': boolean; + /** + * Whether the theme disables custom gradients. + */ + 'disable-custom-gradients': boolean; + /** + * Custom color palette if defined by the theme. + */ + 'editor-color-palette': boolean | Color[]; + /** + * Custom font sizes if defined by the theme. + */ + 'editor-font-sizes': boolean | FontSize[]; + /** + * Custom gradient presets if defined by the theme. + */ + 'editor-gradient-presets': boolean | GradientPreset[]; + /** + * Whether theme opts in to the editor styles CSS wrapper. + */ + 'editor-styles': boolean; + /** + * Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption. + */ + html5: boolean | Html5Option[]; + /** + * Post formats supported. + */ + formats: PostFormat[]; + /** + * The post types that support thumbnails or true if all post types are supported. + */ + 'post-thumbnails': boolean | string[]; + /** + * Whether the theme supports responsive embedded content. + */ + 'responsive-embeds': boolean; + /** + * Whether the theme can manage the document title tag. + */ + 'title-tag': boolean; + /** + * Whether theme opts in to default WordPress block styles for viewing. + */ + 'wp-block-styles': boolean; + } -export interface CustomHeader { - 'default-image': string; - 'random-default': boolean; - width: number; - height: number; - 'flex-height': boolean; - 'flex-width': boolean; - 'default-text-color': string; - 'header-text': boolean; - uploads: boolean; - video: boolean; -} + export interface CustomBackground { + 'default-image': string; + 'default-preset': 'default' | 'fill' | 'fit' | 'repeat' | 'custom'; + 'default-position-x': 'left' | 'center' | 'right'; + 'default-position-y': 'left' | 'center' | 'right'; + 'default-size': 'auto' | 'contain' | 'cover'; + 'default-repeat': 'repeat-x' | 'repeat-y' | 'repeat' | 'no-repeat'; + 'default-attachment': 'scroll' | 'fixed'; + 'default-color': string; + } -export interface CustomLogo { - width: number; - height: number; - 'flex-width': boolean; - 'flex-height': boolean; - 'header-text': string[]; - 'unlink-homepage-logo': boolean; -} + export interface CustomHeader { + 'default-image': string; + 'random-default': boolean; + width: number; + height: number; + 'flex-height': boolean; + 'flex-width': boolean; + 'default-text-color': string; + 'header-text': boolean; + uploads: boolean; + video: boolean; + } -export interface Color { - name: string; - slug: string; - color: string; -} + export interface CustomLogo { + width: number; + height: number; + 'flex-width': boolean; + 'flex-height': boolean; + 'header-text': string[]; + 'unlink-homepage-logo': boolean; + } -export interface FontSize { - name: string; - size: number; - slug: string; -} + export interface Color { + name: string; + slug: string; + color: string; + } -export interface GradientPreset { - name: string; - gradient: string; - slug: string; -} + export interface FontSize { + name: string; + size: number; + slug: string; + } -export type Html5Option = - | 'search-form' - | 'comment-form' - | 'comment-list' - | 'gallery' - | 'caption' - | 'script' - | 'style'; + export interface GradientPreset { + name: string; + gradient: string; + slug: string; + } + + export type Html5Option = + | 'search-form' + | 'comment-form' + | 'comment-list' + | 'gallery' + | 'caption' + | 'script' + | 'style'; + } +} -export type Theme< C extends Context > = OmitNevers< ExtensibleTheme< C > >; +export type Theme< C extends Context > = OmitNevers< + _BaseTypes.Theme< C > +>; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index fc86a62cef620..82cdb54b0a360 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,66 +3,78 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -export interface ExtensibleType< C extends Context > { - /** - * All capabilities used by the post type. - */ - capabilities: ContextualField< Record< string, string >, 'edit', C >; - /** - * A human-readable description of the post type. - */ - description: ContextualField< string, 'view' | 'edit', C >; - /** - * Whether or not the post type should have children. - */ - hierarchical: ContextualField< boolean, 'view' | 'edit', C >; - /** - * Whether or not the post type can be viewed. - */ - viewable: ContextualField< boolean, 'edit', C >; - /** - * Human-readable labels for the post type for various contexts. - */ - labels: ContextualField< Record< string, string >, 'edit', C >; - /** - * The title for the post type. - */ - name: string; - /** - * An alphanumeric identifier for the post type. - */ - slug: string; - /** - * All features, supported by the post type. - */ - supports: ContextualField< Record< string, string >, 'edit', C >; - /** - * Taxonomies associated with post type. - */ - taxonomies: ContextualField< string[], 'view' | 'edit', C >; - /** - * REST base route for the post type. - */ - rest_base: string; - /** - * REST route's namespace for the post type. - */ - rest_namespace: string; - /** - * The visibility settings for the post type. - */ - visibility: ContextualField< TypeVisibility, 'edit', C >; -} +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Type< C extends Context > { + /** + * All capabilities used by the post type. + */ + capabilities: ContextualField< + Record< string, string >, + 'edit', + C + >; + /** + * A human-readable description of the post type. + */ + description: ContextualField< string, 'view' | 'edit', C >; + /** + * Whether or not the post type should have children. + */ + hierarchical: ContextualField< boolean, 'view' | 'edit', C >; + /** + * Whether or not the post type can be viewed. + */ + viewable: ContextualField< boolean, 'edit', C >; + /** + * Human-readable labels for the post type for various contexts. + */ + labels: ContextualField< Record< string, string >, 'edit', C >; + /** + * The title for the post type. + */ + name: string; + /** + * An alphanumeric identifier for the post type. + */ + slug: string; + /** + * All features, supported by the post type. + */ + supports: ContextualField< Record< string, string >, 'edit', C >; + /** + * Taxonomies associated with post type. + */ + taxonomies: ContextualField< string[], 'view' | 'edit', C >; + /** + * REST base route for the post type. + */ + rest_base: string; + /** + * REST route's namespace for the post type. + */ + rest_namespace: string; + /** + * The visibility settings for the post type. + */ + visibility: ContextualField< TypeVisibility, 'edit', C >; + } -interface TypeVisibility { - /** - * Whether to generate a default UI for managing this post type. - */ - show_ui: boolean; - /** - * Whether to make the post type is available for selection in navigation menus. - */ - show_in_nav_menus: boolean; + interface TypeVisibility { + /** + * Whether to generate a default UI for managing this post type. + */ + show_ui: boolean; + /** + * Whether to make the post type is available for selection in navigation menus. + */ + show_in_nav_menus: boolean; + } + } } -export type Type< C extends Context > = OmitNevers< ExtensibleType< C > >; +export type Type< C extends Context > = OmitNevers< + _BaseTypes.Type< C > +>; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 378bcd1618ae6..f70477dfa50a3 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -3,87 +3,107 @@ */ import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; -export interface ExtensibleUser< C extends Context > { - /** - * Unique identifier for the user. - */ - id: number; - /** - * Login name for the user. - */ - username: ContextualField< string, 'edit', C >; - /** - * Display name for the user. - */ - name: string; - /** - * First name for the user. - */ - first_name: ContextualField< string, 'edit', C >; - /** - * Last name for the user. - */ - last_name: ContextualField< string, 'edit', C >; - /** - * The email address for the user. - */ - email: ContextualField< string, 'edit', C >; - /** - * URL of the user. - */ - url: string; - /** - * Description of the user. - */ - description: string; - /** - * Author URL of the user. - */ - link: string; - /** - * Locale for the user. - */ - locale: ContextualField< string, 'edit', C >; - /** - * The nickname for the user. - */ - nickname: ContextualField< string, 'edit', C >; - /** - * An alphanumeric identifier for the user. - */ - slug: string; - /** - * Registration date for the user. - */ - registered_date: ContextualField< string, 'edit', C >; - /** - * Roles assigned to the user. - */ - roles: ContextualField< string[], 'edit', C >; - /** - * Password for the user. - * - * This is never sent from the server to the client - * but exists because we might send an update to the - * server with a new password to set. - */ - password?: string; - /** - * All capabilities assigned to the user. - */ - capabilities: ContextualField< Record< string, string >, 'edit', C >; - /** - * Any extra capabilities assigned to the user. - */ - extra_capabilities: ContextualField< Record< string, string >, 'edit', C >; - /** - * Avatar URLs for the user. - */ - avatar_urls: AvatarUrls; - /** - * Meta fields. - */ - meta: ContextualField< Record< string, string >, 'view' | 'edit', C >; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface User< C extends Context > { + /** + * Unique identifier for the user. + */ + id: number; + /** + * Login name for the user. + */ + username: ContextualField< string, 'edit', C >; + /** + * Display name for the user. + */ + name: string; + /** + * First name for the user. + */ + first_name: ContextualField< string, 'edit', C >; + /** + * Last name for the user. + */ + last_name: ContextualField< string, 'edit', C >; + /** + * The email address for the user. + */ + email: ContextualField< string, 'edit', C >; + /** + * URL of the user. + */ + url: string; + /** + * Description of the user. + */ + description: string; + /** + * Author URL of the user. + */ + link: string; + /** + * Locale for the user. + */ + locale: ContextualField< string, 'edit', C >; + /** + * The nickname for the user. + */ + nickname: ContextualField< string, 'edit', C >; + /** + * An alphanumeric identifier for the user. + */ + slug: string; + /** + * Registration date for the user. + */ + registered_date: ContextualField< string, 'edit', C >; + /** + * Roles assigned to the user. + */ + roles: ContextualField< string[], 'edit', C >; + /** + * Password for the user. + * + * This is never sent from the server to the client + * but exists because we might send an update to the + * server with a new password to set. + */ + password?: string; + /** + * All capabilities assigned to the user. + */ + capabilities: ContextualField< + Record< string, string >, + 'edit', + C + >; + /** + * Any extra capabilities assigned to the user. + */ + extra_capabilities: ContextualField< + Record< string, string >, + 'edit', + C + >; + /** + * Avatar URLs for the user. + */ + avatar_urls: AvatarUrls; + /** + * Meta fields. + */ + meta: ContextualField< + Record< string, string >, + 'view' | 'edit', + C + >; + } + } } -export type User< C extends Context > = OmitNevers< ExtensibleUser< C > >; +export type User< C extends Context > = OmitNevers< + _BaseTypes.User< C > +>; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 48d2307ab6b58..8617593d39af9 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,29 +3,35 @@ */ import { Context, OmitNevers } from './helpers'; -export interface ExtensibleWidgetType< C extends Context > { - /** - * Unique slug identifying the widget type. - */ - id: string; - /** - * Human-readable name identifying the widget type. - */ - name: string; - /** - * Description of the widget. - */ - description: string; - /** - * Whether the widget supports multiple instances - */ - is_multi: boolean; - /** - * Class name - */ - classname: string; +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface WidgetType< C extends Context > { + /** + * Unique slug identifying the widget type. + */ + id: string; + /** + * Human-readable name identifying the widget type. + */ + name: string; + /** + * Description of the widget. + */ + description: string; + /** + * Whether the widget supports multiple instances + */ + is_multi: boolean; + /** + * Class name + */ + classname: string; + } + } } export type WidgetType< C extends Context > = OmitNevers< - ExtensibleWidgetType< C > + _BaseTypes.WidgetType< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 868f519e13e23..71d78be2372d6 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -3,54 +3,62 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -export interface ExtensibleWidget< C extends Context > { - /** - * Unique identifier for the widget. - */ - id: string; - /** - * The type of the widget. Corresponds to ID in widget-types endpoint. - */ - id_base: string; - /** - * The sidebar the widget belongs to. - */ - sidebar: string; - /** - * HTML representation of the widget. - */ - rendered: string; - /** - * HTML representation of the widget admin form. - */ - rendered_form: ContextualField< string, 'edit', C >; - /** - * Instance settings of the widget, if supported. - */ - instance: ContextualField< WidgetInstance, 'edit', C >; - /** - * URL-encoded form data from the widget admin form. Used - * to update a widget that does not support instance. - * - * This is never sent from the server to the client but exists - * because we might send an update. - */ - form_data?: string; -} +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface Widget< C extends Context > { + /** + * Unique identifier for the widget. + */ + id: string; + /** + * The type of the widget. Corresponds to ID in widget-types endpoint. + */ + id_base: string; + /** + * The sidebar the widget belongs to. + */ + sidebar: string; + /** + * HTML representation of the widget. + */ + rendered: string; + /** + * HTML representation of the widget admin form. + */ + rendered_form: ContextualField< string, 'edit', C >; + /** + * Instance settings of the widget, if supported. + */ + instance: ContextualField< WidgetInstance, 'edit', C >; + /** + * URL-encoded form data from the widget admin form. Used + * to update a widget that does not support instance. + * + * This is never sent from the server to the client but exists + * because we might send an update. + */ + form_data?: string; + } -interface WidgetInstance { - /** - * Base64 encoded representation of the instance settings. - */ - encoded: string; - /** - * Cryptographic hash of the instance settings. - */ - hash: string; - /** - * Unencoded instance settings, if supported. - */ - raw: Record< string, string >; + interface WidgetInstance { + /** + * Base64 encoded representation of the instance settings. + */ + encoded: string; + /** + * Cryptographic hash of the instance settings. + */ + hash: string; + /** + * Unencoded instance settings, if supported. + */ + raw: Record< string, string >; + } + } } -export type Widget< C extends Context > = OmitNevers< ExtensibleWidget< C > >; +export type Widget< C extends Context > = OmitNevers< + _BaseTypes.Widget< C > +>; diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index 35fc065b11b29..f8b8d1a53866d 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -9,80 +9,86 @@ import { ContextualField, } from './helpers'; -export interface ExtensibleWpTemplatePart< C extends Context > { - /** - * ID of template. - */ - id: string; - /** - * Unique slug identifying the template. - */ - slug: string; - /** - * Theme identifier for the template. - */ - theme: string; - /** - * Type of template. - */ - type: string; - /** - * Source of template - */ - source: string; - /** - * Source of a customized template - */ - origin: string; - /** - * Content of template. - * - * This field never has a `rendered` property when reading but still uses - * the RenderedText type so it can be set as a string when sending updates to - * the server. - * - * TODO: Figure out how to mesh this with `RenderedText` - */ - content: ContextualField< - RenderedText< C > & { +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface WpTemplatePart< C extends Context > { + /** + * ID of template. + */ + id: string; + /** + * Unique slug identifying the template. + */ + slug: string; + /** + * Theme identifier for the template. + */ + theme: string; + /** + * Type of template. + */ + type: string; + /** + * Source of template + */ + source: string; + /** + * Source of a customized template + */ + origin: string; + /** + * Content of template. + * + * This field never has a `rendered` property when reading but still uses + * the RenderedText type so it can be set as a string when sending updates to + * the server. + * + * TODO: Figure out how to mesh this with `RenderedText` + */ + content: ContextualField< + RenderedText< C > & { + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + }, + 'view' | 'edit', + C + >; + /** + * Title of template. + */ + title: RenderedText< 'edit' >; + /** + * Description of template. + */ + description: string; + /** + * Status of template. + */ + status: PostStatus; + /** + * Post ID. + */ + wp_id: number; + /** + * Theme file exists. + */ + has_theme_file: Record< string, string >; + /** + * The ID for the author of the template. + */ + author: number; /** - * Version of the content block format used by the template. + * Where the template part is intended for use (header, footer, etc.) */ - block_version: ContextualField< number, 'edit', C >; - }, - 'view' | 'edit', - C - >; - /** - * Title of template. - */ - title: RenderedText< 'edit' >; - /** - * Description of template. - */ - description: string; - /** - * Status of template. - */ - status: PostStatus; - /** - * Post ID. - */ - wp_id: number; - /** - * Theme file exists. - */ - has_theme_file: Record< string, string >; - /** - * The ID for the author of the template. - */ - author: number; - /** - * Where the template part is intended for use (header, footer, etc.) - */ - area: string; + area: string; + } + } } export type WpTemplatePart< C extends Context > = OmitNevers< - ExtensibleWpTemplatePart< C > + _BaseTypes.WpTemplatePart< C > >; diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index d7e81ae44d2c9..8b720758b9b3c 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -9,80 +9,86 @@ import { ContextualField, } from './helpers'; -export interface ExtensibleWpTemplate< C extends Context > { - /** - * ID of template. - */ - id: string; - /** - * Unique slug identifying the template. - */ - slug: string; - /** - * Theme identifier for the template. - */ - theme: string; - /** - * Type of template. - */ - type: string; - /** - * Source of template - */ - source: string; - /** - * Source of a customized template - */ - origin: string; - /** - * Content of template. - * - * This field never has a `rendered` property when reading but still uses - * the RenderedText type so it can be set as a string when sending updates to - * the server. - * - * TODO: Figure out how to mesh this with `RenderedText` - */ - content: ContextualField< - RenderedText< C > & { +import { BaseTypes as _BaseTypes } from './base-types'; + +declare module './base-types' { + export namespace BaseTypes { + export interface WpTemplate< C extends Context > { + /** + * ID of template. + */ + id: string; + /** + * Unique slug identifying the template. + */ + slug: string; + /** + * Theme identifier for the template. + */ + theme: string; + /** + * Type of template. + */ + type: string; + /** + * Source of template + */ + source: string; + /** + * Source of a customized template + */ + origin: string; + /** + * Content of template. + * + * This field never has a `rendered` property when reading but still uses + * the RenderedText type so it can be set as a string when sending updates to + * the server. + * + * TODO: Figure out how to mesh this with `RenderedText` + */ + content: ContextualField< + RenderedText< C > & { + /** + * Version of the content block format used by the template. + */ + block_version: ContextualField< number, 'edit', C >; + }, + 'view' | 'edit', + C + >; + /** + * Title of template. + */ + title: RenderedText< 'edit' >; + /** + * Description of template. + */ + description: string; + /** + * Status of template. + */ + status: PostStatus; + /** + * Post ID. + */ + wp_id: number; + /** + * Theme file exists. + */ + has_theme_file: Record< string, string >; + /** + * The ID for the author of the template. + */ + author: number; /** - * Version of the content block format used by the template. + * Whether a template is a custom template. */ - block_version: ContextualField< number, 'edit', C >; - }, - 'view' | 'edit', - C - >; - /** - * Title of template. - */ - title: RenderedText< 'edit' >; - /** - * Description of template. - */ - description: string; - /** - * Status of template. - */ - status: PostStatus; - /** - * Post ID. - */ - wp_id: number; - /** - * Theme file exists. - */ - has_theme_file: Record< string, string >; - /** - * The ID for the author of the template. - */ - author: number; - /** - * Whether a template is a custom template. - */ - is_custom: Record< string, string >; + is_custom: Record< string, string >; + } + } } export type WpTemplate< C extends Context > = OmitNevers< - ExtensibleWpTemplate< C > + _BaseTypes.WpTemplate< C > >; From df1080ccd733389f9790f2a137d8b5d87ae1a304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:54:01 +0100 Subject: [PATCH 61/73] Document the BaseTypes namespace --- packages/core-data/src/types/README.md | 2 +- packages/core-data/src/types/base-types.ts | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index ccfa8c8dfc8e4..43e7232571871 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -214,7 +214,7 @@ export type Comment< C extends Context > = OmitNevers< >; // In the plugin -import { Context } from '@wordpress/core-data'; +import type { Context } from '@wordpress/core-data'; declare module '@wordpress/core-data' { export namespace BaseTypes { export interface Comment< C extends Context > { diff --git a/packages/core-data/src/types/base-types.ts b/packages/core-data/src/types/base-types.ts index 1089f64a083a6..d8313f3d97b16 100644 --- a/packages/core-data/src/types/base-types.ts +++ b/packages/core-data/src/types/base-types.ts @@ -1 +1,36 @@ +/** + * This module exists solely to make the BaseTypes namespace extensible + * with declaration merging: + * + * ```ts + * declare module './base-types' { + * export namespace BaseTypes { + * export interface Comment< C extends Context > { + * id: number; + * // ... + * } + * } + * } + * ``` + * + * The huge upside is that consumers of @wordpress/core-data may extends the + * exported data types using interface merging as follows: + * + * ```ts + * import type { Context } from '@wordpress/core-data'; + * declare module '@wordpress/core-data' { + * export namespace BaseTypes { + * export interface Comment< C extends Context > { + * numberOfViews: number; + * } + * } + * } + * + * import type { Comment } from '@wordpress/core-data'; + * const c : Comment< 'view' > = ...; + * + * // c.numberOfViews is a number + * // c.id is still present + * ``` + */ export namespace BaseTypes {} From d1c4dfbaaff73c79cdc6f7718c6d6f9212b74aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:54:19 +0100 Subject: [PATCH 62/73] Lint --- packages/core-data/src/types/page.ts | 4 +--- packages/core-data/src/types/plugin.ts | 4 +--- packages/core-data/src/types/post.ts | 4 +--- packages/core-data/src/types/theme.ts | 4 +--- packages/core-data/src/types/type.ts | 4 +--- packages/core-data/src/types/user.ts | 4 +--- packages/core-data/src/types/widget.ts | 4 +--- 7 files changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index f3016d246ee51..36c3af4474037 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -139,6 +139,4 @@ declare module './base-types' { } } -export type Page< C extends Context > = OmitNevers< - _BaseTypes.Page< C > ->; +export type Page< C extends Context > = OmitNevers< _BaseTypes.Page< C > >; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 00a8fcc24dfda..5afe0620d875f 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -69,6 +69,4 @@ declare module './base-types' { } export type PluginStatus = 'active' | 'inactive'; -export type Plugin< C extends Context > = OmitNevers< - _BaseTypes.Plugin< C > ->; +export type Plugin< C extends Context > = OmitNevers< _BaseTypes.Plugin< C > >; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 53a248a703566..b8763c861cc8d 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -148,6 +148,4 @@ declare module './base-types' { } } -export type Post< C extends Context > = OmitNevers< - _BaseTypes.Post< C > ->; +export type Post< C extends Context > = OmitNevers< _BaseTypes.Post< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 829efb2249f5c..d69690131efeb 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -217,6 +217,4 @@ declare module './base-types' { } } -export type Theme< C extends Context > = OmitNevers< - _BaseTypes.Theme< C > ->; +export type Theme< C extends Context > = OmitNevers< _BaseTypes.Theme< C > >; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 82cdb54b0a360..2d582c8206eca 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -75,6 +75,4 @@ declare module './base-types' { } } -export type Type< C extends Context > = OmitNevers< - _BaseTypes.Type< C > ->; +export type Type< C extends Context > = OmitNevers< _BaseTypes.Type< C > >; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index f70477dfa50a3..41465145014c1 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -104,6 +104,4 @@ declare module './base-types' { } } -export type User< C extends Context > = OmitNevers< - _BaseTypes.User< C > ->; +export type User< C extends Context > = OmitNevers< _BaseTypes.User< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 71d78be2372d6..6673915b7f5ce 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -59,6 +59,4 @@ declare module './base-types' { } } -export type Widget< C extends Context > = OmitNevers< - _BaseTypes.Widget< C > ->; +export type Widget< C extends Context > = OmitNevers< _BaseTypes.Widget< C > >; From 97bc5537200e690cd3ed27d41eef582268ca8618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:54:45 +0100 Subject: [PATCH 63/73] Lint the docstring in base-types.ts --- packages/core-data/src/types/base-types.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core-data/src/types/base-types.ts b/packages/core-data/src/types/base-types.ts index d8313f3d97b16..ee1ac2cf8d356 100644 --- a/packages/core-data/src/types/base-types.ts +++ b/packages/core-data/src/types/base-types.ts @@ -19,11 +19,11 @@ * ```ts * import type { Context } from '@wordpress/core-data'; * declare module '@wordpress/core-data' { - * export namespace BaseTypes { - * export interface Comment< C extends Context > { - * numberOfViews: number; - * } - * } + * export namespace BaseTypes { + * export interface Comment< C extends Context > { + * numberOfViews: number; + * } + * } * } * * import type { Comment } from '@wordpress/core-data'; From 80b7610b8f65831b7b6fb0d2ab232dc24517d7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 12:57:08 +0100 Subject: [PATCH 64/73] Rename the BaseTypes namespace to WPBaseTypes --- packages/core-data/src/types/README.md | 8 ++++---- packages/core-data/src/types/attachment.ts | 8 ++++---- packages/core-data/src/types/comment.ts | 8 ++++---- packages/core-data/src/types/index.ts | 2 +- packages/core-data/src/types/menu-location.ts | 8 ++++---- packages/core-data/src/types/nav-menu-item.ts | 8 ++++---- packages/core-data/src/types/nav-menu.ts | 8 ++++---- packages/core-data/src/types/navigation-area.ts | 8 ++++---- packages/core-data/src/types/page.ts | 8 ++++---- packages/core-data/src/types/plugin.ts | 10 ++++++---- packages/core-data/src/types/post.ts | 8 ++++---- packages/core-data/src/types/settings.ts | 8 ++++---- packages/core-data/src/types/sidebar.ts | 8 ++++---- packages/core-data/src/types/taxonomy.ts | 8 ++++---- packages/core-data/src/types/theme.ts | 8 ++++---- packages/core-data/src/types/type.ts | 8 ++++---- packages/core-data/src/types/user.ts | 8 ++++---- packages/core-data/src/types/widget-type.ts | 8 ++++---- packages/core-data/src/types/widget.ts | 10 ++++++---- .../src/types/{base-types.ts => wp-base-types.ts} | 10 +++++----- packages/core-data/src/types/wp-template-part.ts | 8 ++++---- packages/core-data/src/types/wp-template.ts | 8 ++++---- 22 files changed, 90 insertions(+), 86 deletions(-) rename packages/core-data/src/types/{base-types.ts => wp-base-types.ts} (76%) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 43e7232571871..0fa6ca4a9a4d9 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -200,8 +200,8 @@ For example, if you're building a plugin that displays a number of views of each ```ts // In core-data -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Comment< C extends Context > { id: number; // ... @@ -210,13 +210,13 @@ declare module './base-types' { } export type Comment< C extends Context > = OmitNevers< - BaseTypes.Comment< C > + WPBaseTypes.Comment< C > >; // In the plugin import type { Context } from '@wordpress/core-data'; declare module '@wordpress/core-data' { - export namespace BaseTypes { + export namespace WPBaseTypes { export interface Comment< C extends Context > { numberOfViews: number; } diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index d3ad130c32d6a..c4dfe1436ef23 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -12,10 +12,10 @@ import { PingStatus, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Attachment< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -142,5 +142,5 @@ declare module './base-types' { } export type Attachment< C extends Context > = OmitNevers< - _BaseTypes.Attachment< C > + _WPBaseTypes.Attachment< C > >; diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index a9a3bbb832d40..ae2a183be683d 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -8,12 +8,12 @@ import { OmitNevers, RenderedText, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Comment< C extends Context > { /** * Unique identifier for the comment. @@ -92,5 +92,5 @@ declare module './base-types' { } export type Comment< C extends Context > = OmitNevers< - _BaseTypes.Comment< C > + _WPBaseTypes.Comment< C > >; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index b2230aefeb4cc..f1746fbadf26b 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -22,7 +22,7 @@ import type { WpTemplate } from './wp-template'; import type { WpTemplatePart } from './wp-template-part'; import type { Context, Updatable } from './helpers'; -export type { BaseTypes } from './base-types'; +export type { WPBaseTypes } from './wp-base-types'; export type { Context, diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 32dbd8e6fbaee..6f4f0498fca96 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface MenuLocation< C extends Context > { /** * The name of the menu location. @@ -25,5 +25,5 @@ declare module './base-types' { } export type MenuLocation< C extends Context > = OmitNevers< - _BaseTypes.MenuLocation< C > + _WPBaseTypes.MenuLocation< C > >; diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index e9b0b6878a095..b20e0564854f3 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -3,7 +3,7 @@ */ import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; export type NavMenuItemType = | 'taxonomy' @@ -18,8 +18,8 @@ export type NavMenuItemStatus = | 'private'; export type Target = '_blank' | ''; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface NavMenuItem< C extends Context > { /** * The title for the object. @@ -102,5 +102,5 @@ declare module './base-types' { } export type NavMenuItem< C extends Context > = OmitNevers< - _BaseTypes.NavMenuItem< C > + _WPBaseTypes.NavMenuItem< C > >; diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index 194a64c1d74b0..f16cb7a97b1f7 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface NavMenu< C extends Context > { /** * Unique identifier for the term. @@ -49,5 +49,5 @@ declare module './base-types' { } export type NavMenu< C extends Context > = OmitNevers< - _BaseTypes.NavMenu< C > + _WPBaseTypes.NavMenu< C > >; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 8fc8e74b799a8..d75e90eb1924d 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface NavigationArea< C extends Context > { /** * The name of the navigation area. @@ -25,5 +25,5 @@ declare module './base-types' { } export type NavigationArea< C extends Context > = OmitNevers< - _BaseTypes.NavigationArea< C > + _WPBaseTypes.NavigationArea< C > >; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 36c3af4474037..121ac30c107b2 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -11,10 +11,10 @@ import { OmitNevers, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Page< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -139,4 +139,4 @@ declare module './base-types' { } } -export type Page< C extends Context > = OmitNevers< _BaseTypes.Page< C > >; +export type Page< C extends Context > = OmitNevers< _WPBaseTypes.Page< C > >; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 5afe0620d875f..3e6c5051fa660 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Plugin< C extends Context > { /** * The plugin file. @@ -69,4 +69,6 @@ declare module './base-types' { } export type PluginStatus = 'active' | 'inactive'; -export type Plugin< C extends Context > = OmitNevers< _BaseTypes.Plugin< C > >; +export type Plugin< C extends Context > = OmitNevers< + _WPBaseTypes.Plugin< C > +>; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index b8763c861cc8d..7f3fb2223d4fa 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -12,10 +12,10 @@ import { OmitNevers, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Post< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -148,4 +148,4 @@ declare module './base-types' { } } -export type Post< C extends Context > = OmitNevers< _BaseTypes.Post< C > >; +export type Post< C extends Context > = OmitNevers< _WPBaseTypes.Post< C > >; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index c4bea67af7b34..a0a644a9d080a 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -3,10 +3,10 @@ */ import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Settings< C extends Context > { /** * What to show on the front page @@ -89,5 +89,5 @@ declare module './base-types' { } export type Settings< C extends Context > = OmitNevers< - _BaseTypes.Settings< C > + _WPBaseTypes.Settings< C > >; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 1bc3def698afd..0a8a674b3473d 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -4,10 +4,10 @@ import { Widget } from './widget'; import { Context, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Sidebar< C extends Context > { /** * ID of sidebar. @@ -56,5 +56,5 @@ declare module './base-types' { type SidebarStatus = 'active' | 'inactive'; export type Sidebar< C extends Context > = OmitNevers< - _BaseTypes.Sidebar< C > + _WPBaseTypes.Sidebar< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index e7c3e46256fcd..720951ecff1ae 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Taxonomy< C extends Context > { /** * All capabilities used by the taxonomy. @@ -88,5 +88,5 @@ declare module './base-types' { } export type Taxonomy< C extends Context > = OmitNevers< - _BaseTypes.Taxonomy< C > + _WPBaseTypes.Taxonomy< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index d69690131efeb..555c978d61c00 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -3,10 +3,10 @@ */ import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Theme< C extends Context > { /** * The theme's stylesheet. This uniquely identifies the theme. @@ -217,4 +217,4 @@ declare module './base-types' { } } -export type Theme< C extends Context > = OmitNevers< _BaseTypes.Theme< C > >; +export type Theme< C extends Context > = OmitNevers< _WPBaseTypes.Theme< C > >; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 2d582c8206eca..3e63190180e13 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Type< C extends Context > { /** * All capabilities used by the post type. @@ -75,4 +75,4 @@ declare module './base-types' { } } -export type Type< C extends Context > = OmitNevers< _BaseTypes.Type< C > >; +export type Type< C extends Context > = OmitNevers< _WPBaseTypes.Type< C > >; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 41465145014c1..63fdbcb03ecf4 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -3,10 +3,10 @@ */ import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface User< C extends Context > { /** * Unique identifier for the user. @@ -104,4 +104,4 @@ declare module './base-types' { } } -export type User< C extends Context > = OmitNevers< _BaseTypes.User< C > >; +export type User< C extends Context > = OmitNevers< _WPBaseTypes.User< C > >; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 8617593d39af9..3dfa5b8fe4675 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface WidgetType< C extends Context > { /** * Unique slug identifying the widget type. @@ -33,5 +33,5 @@ declare module './base-types' { } export type WidgetType< C extends Context > = OmitNevers< - _BaseTypes.WidgetType< C > + _WPBaseTypes.WidgetType< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 6673915b7f5ce..710c97f77958f 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface Widget< C extends Context > { /** * Unique identifier for the widget. @@ -59,4 +59,6 @@ declare module './base-types' { } } -export type Widget< C extends Context > = OmitNevers< _BaseTypes.Widget< C > >; +export type Widget< C extends Context > = OmitNevers< + _WPBaseTypes.Widget< C > +>; diff --git a/packages/core-data/src/types/base-types.ts b/packages/core-data/src/types/wp-base-types.ts similarity index 76% rename from packages/core-data/src/types/base-types.ts rename to packages/core-data/src/types/wp-base-types.ts index ee1ac2cf8d356..f1a0fa0bc96a8 100644 --- a/packages/core-data/src/types/base-types.ts +++ b/packages/core-data/src/types/wp-base-types.ts @@ -1,10 +1,10 @@ /** - * This module exists solely to make the BaseTypes namespace extensible + * This module exists solely to make the WPBaseTypes namespace extensible * with declaration merging: * * ```ts - * declare module './base-types' { - * export namespace BaseTypes { + * declare module './wp-base-types' { + * export namespace WPBaseTypes { * export interface Comment< C extends Context > { * id: number; * // ... @@ -19,7 +19,7 @@ * ```ts * import type { Context } from '@wordpress/core-data'; * declare module '@wordpress/core-data' { - * export namespace BaseTypes { + * export namespace WPBaseTypes { * export interface Comment< C extends Context > { * numberOfViews: number; * } @@ -33,4 +33,4 @@ * // c.id is still present * ``` */ -export namespace BaseTypes {} +export namespace WPBaseTypes {} diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index f8b8d1a53866d..db2c943c41984 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface WpTemplatePart< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './base-types' { } export type WpTemplatePart< C extends Context > = OmitNevers< - _BaseTypes.WpTemplatePart< C > + _WPBaseTypes.WpTemplatePart< C > >; diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index 8b720758b9b3c..87512a51821ce 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { BaseTypes as _BaseTypes } from './base-types'; +import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; -declare module './base-types' { - export namespace BaseTypes { +declare module './wp-base-types' { + export namespace WPBaseTypes { export interface WpTemplate< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './base-types' { } export type WpTemplate< C extends Context > = OmitNevers< - _BaseTypes.WpTemplate< C > + _WPBaseTypes.WpTemplate< C > >; From db67911e99509b2d513c3bf31999a22d830531d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 13:04:25 +0100 Subject: [PATCH 65/73] Add more commentary to the Extending section --- packages/core-data/src/types/README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 0fa6ca4a9a4d9..2940cad4807e1 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -200,23 +200,26 @@ For example, if you're building a plugin that displays a number of views of each ```ts // In core-data -declare module './wp-base-types' { - export namespace WPBaseTypes { - export interface Comment< C extends Context > { - id: number; - // ... - } +export namespace WPBaseTypes { + // This is the parent interface – it can be extended + export interface Comment< C extends Context > { + id: number; + // ... } } +// This the child type used in function signatures – it cannot be extended export type Comment< C extends Context > = OmitNevers< WPBaseTypes.Comment< C > >; // In the plugin import type { Context } from '@wordpress/core-data'; +// Target the core-data module declare module '@wordpress/core-data' { + // Extend the WPBaseTypes namespace through declaration merging export namespace WPBaseTypes { + // Extend the parent Commet interface through declaration merging export interface Comment< C extends Context > { numberOfViews: number; } @@ -224,8 +227,10 @@ declare module '@wordpress/core-data' { } import type { Comment } from '@wordpress/core-data'; +// Create an instance of the child type const c : Comment< 'view' > = ...; +// Extending the parent had the desired effect on the child type: // c.numberOfViews is a number // c.id is still present ``` From 4509bd2965a9dfff73c9d27377df0c72fcd975ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 13:04:55 +0100 Subject: [PATCH 66/73] Add a comma --- packages/core-data/src/types/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 2940cad4807e1..ddd1b3957377d 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -235,4 +235,4 @@ const c : Comment< 'view' > = ...; // c.id is still present ``` -Of course you will also need to extend the REST API to expose the numberOfViews property. +Of course, you will also need to extend the REST API to expose the numberOfViews property. From 466dd5f360d202a7bfb3f1676ff7b9ef0239d876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 13:06:33 +0100 Subject: [PATCH 67/73] Clarify the warning about type safety --- packages/core-data/src/types/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index ddd1b3957377d..5b5e4a92c8263 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -7,7 +7,7 @@ The types in this directory are designed to support the following use-cases: * Provide type-hinting and documentation for entity records fetched in the various REST API contexts. * Type-check the values we use to *edit* entity records, the values that are sent back to the server as updates. -**Warning:** The types model the _expected_ API responses which is **not** the same as having an extensible type safety for the API-related operations. The API responses are **not** used as-is and in many cases could disagree with the type definitions, for example a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. +**Warning:** The API responses are type-cast to these definitions and therefore may not match those expectations; for example, a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. ### Context-aware type checks for entity records From a84b420f762bc35c3ebc54adedbc1b94520f38b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 13:08:40 +0100 Subject: [PATCH 68/73] Restore the first sentence of the warning --- packages/core-data/src/types/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 5b5e4a92c8263..9494bf972c4ec 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -7,7 +7,7 @@ The types in this directory are designed to support the following use-cases: * Provide type-hinting and documentation for entity records fetched in the various REST API contexts. * Type-check the values we use to *edit* entity records, the values that are sent back to the server as updates. -**Warning:** The API responses are type-cast to these definitions and therefore may not match those expectations; for example, a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. +**Warning:** The types model the expected API responses which is **not** the same as having a full type safety for the API-related operations. The API responses are type-cast to these definitions and therefore may not match those expectations; for example, a plugin could modify the response, or the API endpoint could have a nuanced implementation in which strings are sometimes used instead of numbers. ### Context-aware type checks for entity records From 0ab8ed7527a52b8167e65e29a0a0bfec81434a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 14:45:41 +0100 Subject: [PATCH 69/73] Link to the types readme in core-data readme --- packages/core-data/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/README.md b/packages/core-data/README.md index eeead7b6a7efd..8e081eabec7ba 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -1,6 +1,6 @@ # Core Data -Core Data is a [data module](/packages/data/README.md) intended to simplify access to and manipulation of core WordPress entities. It registers its own store and provides a number of selectors which resolve data from the WordPress REST API automatically, along with dispatching action creators to manipulate data. +Core Data is a [data module](/packages/data/README.md) intended to simplify access to and manipulation of core WordPress entities. It registers its own store and provides a number of selectors which resolve data from the WordPress REST API automatically, along with dispatching action creators to manipulate data. This module is shipped with [`TypeScript definitions for WordPress data types`](/packages/core-data/src/types/README.md). Used in combination with features of the data module such as [`subscribe`](/packages/data/README.md#subscribe-function) or [higher-order components](/packages/data/README.md#higher-order-components), it enables a developer to easily add data into the logic and display of their plugin. From dde0888a5d80fe417f538d2d67b343841c716810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 14:53:25 +0100 Subject: [PATCH 70/73] Do not publish the data types --- packages/core-data/package.json | 1 - packages/core-data/src/types/README.md | 45 -------------------------- 2 files changed, 46 deletions(-) diff --git a/packages/core-data/package.json b/packages/core-data/package.json index 35c09308e7b98..b74e2920018ca 100644 --- a/packages/core-data/package.json +++ b/packages/core-data/package.json @@ -25,7 +25,6 @@ "main": "build/index.js", "module": "build-module/index.js", "react-native": "src/index", - "types": "src/types/index.ts", "sideEffects": [ "{src,build,build-module}/index.js" ], diff --git a/packages/core-data/src/types/README.md b/packages/core-data/src/types/README.md index 9494bf972c4ec..10d2a2be75e63 100644 --- a/packages/core-data/src/types/README.md +++ b/packages/core-data/src/types/README.md @@ -191,48 +191,3 @@ const updatablePost = {} as Updatable< Post >; A string that the server renders which often involves modifications from the raw source string. For example, block HTML with the comment delimiters exists in `post_content` but those comments are stripped out when rendering to a page view. Similarly, plugins might modify content or replace shortcodes. - -## Extending - -You can extend the entity record definitions using [TypeScript's declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). - -For example, if you're building a plugin that displays a number of views of each comment, you can add a new `numberOfViews` field to the `Comment` type like this: - -```ts -// In core-data -export namespace WPBaseTypes { - // This is the parent interface – it can be extended - export interface Comment< C extends Context > { - id: number; - // ... - } -} - -// This the child type used in function signatures – it cannot be extended -export type Comment< C extends Context > = OmitNevers< - WPBaseTypes.Comment< C > ->; - -// In the plugin -import type { Context } from '@wordpress/core-data'; -// Target the core-data module -declare module '@wordpress/core-data' { - // Extend the WPBaseTypes namespace through declaration merging - export namespace WPBaseTypes { - // Extend the parent Commet interface through declaration merging - export interface Comment< C extends Context > { - numberOfViews: number; - } - } -} - -import type { Comment } from '@wordpress/core-data'; -// Create an instance of the child type -const c : Comment< 'view' > = ...; - -// Extending the parent had the desired effect on the child type: -// c.numberOfViews is a number -// c.id is still present -``` - -Of course, you will also need to extend the REST API to expose the numberOfViews property. From 669f28944de82074e14eaa02429c0b8e3bb625fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 22:27:40 +0100 Subject: [PATCH 71/73] Rename WPBaseTypes to CoreBaseEntityTypes --- packages/core-data/src/types/attachment.ts | 6 +++--- packages/core-data/src/types/comment.ts | 6 +++--- packages/core-data/src/types/index.ts | 2 +- packages/core-data/src/types/menu-location.ts | 6 +++--- packages/core-data/src/types/nav-menu-item.ts | 6 +++--- packages/core-data/src/types/nav-menu.ts | 6 +++--- packages/core-data/src/types/navigation-area.ts | 6 +++--- packages/core-data/src/types/page.ts | 8 +++++--- packages/core-data/src/types/plugin.ts | 6 +++--- packages/core-data/src/types/post.ts | 8 +++++--- packages/core-data/src/types/settings.ts | 6 +++--- packages/core-data/src/types/sidebar.ts | 6 +++--- packages/core-data/src/types/taxonomy.ts | 6 +++--- packages/core-data/src/types/theme.ts | 8 +++++--- packages/core-data/src/types/type.ts | 8 +++++--- packages/core-data/src/types/user.ts | 8 +++++--- packages/core-data/src/types/widget-type.ts | 6 +++--- packages/core-data/src/types/widget.ts | 6 +++--- packages/core-data/src/types/wp-base-types.ts | 8 ++++---- packages/core-data/src/types/wp-template-part.ts | 6 +++--- packages/core-data/src/types/wp-template.ts | 6 +++--- 21 files changed, 72 insertions(+), 62 deletions(-) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index c4dfe1436ef23..32da17c8bdb63 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -12,10 +12,10 @@ import { PingStatus, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Attachment< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -142,5 +142,5 @@ declare module './wp-base-types' { } export type Attachment< C extends Context > = OmitNevers< - _WPBaseTypes.Attachment< C > + _CoreBaseEntityTypes.Attachment< C > >; diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index ae2a183be683d..923045ee95028 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -8,12 +8,12 @@ import { OmitNevers, RenderedText, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Comment< C extends Context > { /** * Unique identifier for the comment. @@ -92,5 +92,5 @@ declare module './wp-base-types' { } export type Comment< C extends Context > = OmitNevers< - _WPBaseTypes.Comment< C > + _CoreBaseEntityTypes.Comment< C > >; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index f1746fbadf26b..66424338522d8 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -22,7 +22,7 @@ import type { WpTemplate } from './wp-template'; import type { WpTemplatePart } from './wp-template-part'; import type { Context, Updatable } from './helpers'; -export type { WPBaseTypes } from './wp-base-types'; +export type { CoreBaseEntityTypes } from './wp-base-types'; export type { Context, diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 6f4f0498fca96..7f8719ba7e423 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface MenuLocation< C extends Context > { /** * The name of the menu location. @@ -25,5 +25,5 @@ declare module './wp-base-types' { } export type MenuLocation< C extends Context > = OmitNevers< - _WPBaseTypes.MenuLocation< C > + _CoreBaseEntityTypes.MenuLocation< C > >; diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index b20e0564854f3..2bd06053a4959 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -3,7 +3,7 @@ */ import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; export type NavMenuItemType = | 'taxonomy' @@ -19,7 +19,7 @@ export type NavMenuItemStatus = export type Target = '_blank' | ''; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface NavMenuItem< C extends Context > { /** * The title for the object. @@ -102,5 +102,5 @@ declare module './wp-base-types' { } export type NavMenuItem< C extends Context > = OmitNevers< - _WPBaseTypes.NavMenuItem< C > + _CoreBaseEntityTypes.NavMenuItem< C > >; diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index f16cb7a97b1f7..592d5ecc5b310 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface NavMenu< C extends Context > { /** * Unique identifier for the term. @@ -49,5 +49,5 @@ declare module './wp-base-types' { } export type NavMenu< C extends Context > = OmitNevers< - _WPBaseTypes.NavMenu< C > + _CoreBaseEntityTypes.NavMenu< C > >; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index d75e90eb1924d..218d435e76d0f 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface NavigationArea< C extends Context > { /** * The name of the navigation area. @@ -25,5 +25,5 @@ declare module './wp-base-types' { } export type NavigationArea< C extends Context > = OmitNevers< - _WPBaseTypes.NavigationArea< C > + _CoreBaseEntityTypes.NavigationArea< C > >; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index 121ac30c107b2..e004f49716699 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -11,10 +11,10 @@ import { OmitNevers, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Page< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -139,4 +139,6 @@ declare module './wp-base-types' { } } -export type Page< C extends Context > = OmitNevers< _WPBaseTypes.Page< C > >; +export type Page< C extends Context > = OmitNevers< + _CoreBaseEntityTypes.Page< C > +>; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 3e6c5051fa660..093b473fd6b08 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Plugin< C extends Context > { /** * The plugin file. @@ -70,5 +70,5 @@ declare module './wp-base-types' { export type PluginStatus = 'active' | 'inactive'; export type Plugin< C extends Context > = OmitNevers< - _WPBaseTypes.Plugin< C > + _CoreBaseEntityTypes.Plugin< C > >; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index 7f3fb2223d4fa..d4fa1c6b5e293 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -12,10 +12,10 @@ import { OmitNevers, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Post< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -148,4 +148,6 @@ declare module './wp-base-types' { } } -export type Post< C extends Context > = OmitNevers< _WPBaseTypes.Post< C > >; +export type Post< C extends Context > = OmitNevers< + _CoreBaseEntityTypes.Post< C > +>; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index a0a644a9d080a..c4e94cdd56940 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -3,10 +3,10 @@ */ import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Settings< C extends Context > { /** * What to show on the front page @@ -89,5 +89,5 @@ declare module './wp-base-types' { } export type Settings< C extends Context > = OmitNevers< - _WPBaseTypes.Settings< C > + _CoreBaseEntityTypes.Settings< C > >; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index 0a8a674b3473d..a82109ca4e01b 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -4,10 +4,10 @@ import { Widget } from './widget'; import { Context, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Sidebar< C extends Context > { /** * ID of sidebar. @@ -56,5 +56,5 @@ declare module './wp-base-types' { type SidebarStatus = 'active' | 'inactive'; export type Sidebar< C extends Context > = OmitNevers< - _WPBaseTypes.Sidebar< C > + _CoreBaseEntityTypes.Sidebar< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 720951ecff1ae..7fdbce3170a21 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Taxonomy< C extends Context > { /** * All capabilities used by the taxonomy. @@ -88,5 +88,5 @@ declare module './wp-base-types' { } export type Taxonomy< C extends Context > = OmitNevers< - _WPBaseTypes.Taxonomy< C > + _CoreBaseEntityTypes.Taxonomy< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 555c978d61c00..883206d332cee 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -3,10 +3,10 @@ */ import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Theme< C extends Context > { /** * The theme's stylesheet. This uniquely identifies the theme. @@ -217,4 +217,6 @@ declare module './wp-base-types' { } } -export type Theme< C extends Context > = OmitNevers< _WPBaseTypes.Theme< C > >; +export type Theme< C extends Context > = OmitNevers< + _CoreBaseEntityTypes.Theme< C > +>; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 3e63190180e13..998f43d5e8d6b 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Type< C extends Context > { /** * All capabilities used by the post type. @@ -75,4 +75,6 @@ declare module './wp-base-types' { } } -export type Type< C extends Context > = OmitNevers< _WPBaseTypes.Type< C > >; +export type Type< C extends Context > = OmitNevers< + _CoreBaseEntityTypes.Type< C > +>; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index 63fdbcb03ecf4..e3e1ef4912863 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -3,10 +3,10 @@ */ import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface User< C extends Context > { /** * Unique identifier for the user. @@ -104,4 +104,6 @@ declare module './wp-base-types' { } } -export type User< C extends Context > = OmitNevers< _WPBaseTypes.User< C > >; +export type User< C extends Context > = OmitNevers< + _CoreBaseEntityTypes.User< C > +>; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 3dfa5b8fe4675..285bfd2641a1a 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface WidgetType< C extends Context > { /** * Unique slug identifying the widget type. @@ -33,5 +33,5 @@ declare module './wp-base-types' { } export type WidgetType< C extends Context > = OmitNevers< - _WPBaseTypes.WidgetType< C > + _CoreBaseEntityTypes.WidgetType< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index 710c97f77958f..ca81f7091c36a 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface Widget< C extends Context > { /** * Unique identifier for the widget. @@ -60,5 +60,5 @@ declare module './wp-base-types' { } export type Widget< C extends Context > = OmitNevers< - _WPBaseTypes.Widget< C > + _CoreBaseEntityTypes.Widget< C > >; diff --git a/packages/core-data/src/types/wp-base-types.ts b/packages/core-data/src/types/wp-base-types.ts index f1a0fa0bc96a8..2fc46ee07e762 100644 --- a/packages/core-data/src/types/wp-base-types.ts +++ b/packages/core-data/src/types/wp-base-types.ts @@ -1,10 +1,10 @@ /** - * This module exists solely to make the WPBaseTypes namespace extensible + * This module exists solely to make the CoreBaseEntityTypes namespace extensible * with declaration merging: * * ```ts * declare module './wp-base-types' { - * export namespace WPBaseTypes { + * export namespace CoreBaseEntityTypes { * export interface Comment< C extends Context > { * id: number; * // ... @@ -19,7 +19,7 @@ * ```ts * import type { Context } from '@wordpress/core-data'; * declare module '@wordpress/core-data' { - * export namespace WPBaseTypes { + * export namespace CoreBaseEntityTypes { * export interface Comment< C extends Context > { * numberOfViews: number; * } @@ -33,4 +33,4 @@ * // c.id is still present * ``` */ -export namespace WPBaseTypes {} +export namespace CoreBaseEntityTypes {} diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index db2c943c41984..6164159579b93 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface WpTemplatePart< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './wp-base-types' { } export type WpTemplatePart< C extends Context > = OmitNevers< - _WPBaseTypes.WpTemplatePart< C > + _CoreBaseEntityTypes.WpTemplatePart< C > >; diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index 87512a51821ce..c985136130047 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { WPBaseTypes as _WPBaseTypes } from './wp-base-types'; +import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; declare module './wp-base-types' { - export namespace WPBaseTypes { + export namespace CoreBaseEntityTypes { export interface WpTemplate< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './wp-base-types' { } export type WpTemplate< C extends Context > = OmitNevers< - _WPBaseTypes.WpTemplate< C > + _CoreBaseEntityTypes.WpTemplate< C > >; From adfd612d23c7c3f35b9f248651e4dc6331da4fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 23:20:12 +0100 Subject: [PATCH 72/73] Rename CoreBaseEntityTypes to BaseEntityTypes --- packages/core-data/src/types/attachment.ts | 8 ++++---- .../types/{wp-base-types.ts => base-entity-types.ts} | 10 +++++----- packages/core-data/src/types/comment.ts | 8 ++++---- packages/core-data/src/types/index.ts | 2 +- packages/core-data/src/types/menu-location.ts | 8 ++++---- packages/core-data/src/types/nav-menu-item.ts | 8 ++++---- packages/core-data/src/types/nav-menu.ts | 8 ++++---- packages/core-data/src/types/navigation-area.ts | 8 ++++---- packages/core-data/src/types/page.ts | 8 ++++---- packages/core-data/src/types/plugin.ts | 8 ++++---- packages/core-data/src/types/post.ts | 8 ++++---- packages/core-data/src/types/settings.ts | 8 ++++---- packages/core-data/src/types/sidebar.ts | 8 ++++---- packages/core-data/src/types/taxonomy.ts | 8 ++++---- packages/core-data/src/types/theme.ts | 8 ++++---- packages/core-data/src/types/type.ts | 8 ++++---- packages/core-data/src/types/user.ts | 8 ++++---- packages/core-data/src/types/widget-type.ts | 8 ++++---- packages/core-data/src/types/widget.ts | 8 ++++---- packages/core-data/src/types/wp-template-part.ts | 8 ++++---- packages/core-data/src/types/wp-template.ts | 8 ++++---- 21 files changed, 82 insertions(+), 82 deletions(-) rename packages/core-data/src/types/{wp-base-types.ts => base-entity-types.ts} (74%) diff --git a/packages/core-data/src/types/attachment.ts b/packages/core-data/src/types/attachment.ts index 32da17c8bdb63..4ad94226f0a87 100644 --- a/packages/core-data/src/types/attachment.ts +++ b/packages/core-data/src/types/attachment.ts @@ -12,10 +12,10 @@ import { PingStatus, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Attachment< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -142,5 +142,5 @@ declare module './wp-base-types' { } export type Attachment< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Attachment< C > + _BaseEntityTypes.Attachment< C > >; diff --git a/packages/core-data/src/types/wp-base-types.ts b/packages/core-data/src/types/base-entity-types.ts similarity index 74% rename from packages/core-data/src/types/wp-base-types.ts rename to packages/core-data/src/types/base-entity-types.ts index 2fc46ee07e762..708d2b6887c6f 100644 --- a/packages/core-data/src/types/wp-base-types.ts +++ b/packages/core-data/src/types/base-entity-types.ts @@ -1,10 +1,10 @@ /** - * This module exists solely to make the CoreBaseEntityTypes namespace extensible + * This module exists solely to make the BaseEntityTypes namespace extensible * with declaration merging: * * ```ts - * declare module './wp-base-types' { - * export namespace CoreBaseEntityTypes { + * declare module './base-entity-types' { + * export namespace BaseEntityTypes { * export interface Comment< C extends Context > { * id: number; * // ... @@ -19,7 +19,7 @@ * ```ts * import type { Context } from '@wordpress/core-data'; * declare module '@wordpress/core-data' { - * export namespace CoreBaseEntityTypes { + * export namespace BaseEntityTypes { * export interface Comment< C extends Context > { * numberOfViews: number; * } @@ -33,4 +33,4 @@ * // c.id is still present * ``` */ -export namespace CoreBaseEntityTypes {} +export namespace BaseEntityTypes {} diff --git a/packages/core-data/src/types/comment.ts b/packages/core-data/src/types/comment.ts index 923045ee95028..56cd559780770 100644 --- a/packages/core-data/src/types/comment.ts +++ b/packages/core-data/src/types/comment.ts @@ -8,12 +8,12 @@ import { OmitNevers, RenderedText, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Comment< C extends Context > { /** * Unique identifier for the comment. @@ -92,5 +92,5 @@ declare module './wp-base-types' { } export type Comment< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Comment< C > + _BaseEntityTypes.Comment< C > >; diff --git a/packages/core-data/src/types/index.ts b/packages/core-data/src/types/index.ts index 66424338522d8..80a173862b58a 100644 --- a/packages/core-data/src/types/index.ts +++ b/packages/core-data/src/types/index.ts @@ -22,7 +22,7 @@ import type { WpTemplate } from './wp-template'; import type { WpTemplatePart } from './wp-template-part'; import type { Context, Updatable } from './helpers'; -export type { CoreBaseEntityTypes } from './wp-base-types'; +export type { BaseEntityTypes } from './base-entity-types'; export type { Context, diff --git a/packages/core-data/src/types/menu-location.ts b/packages/core-data/src/types/menu-location.ts index 7f8719ba7e423..71fb5abab8714 100644 --- a/packages/core-data/src/types/menu-location.ts +++ b/packages/core-data/src/types/menu-location.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface MenuLocation< C extends Context > { /** * The name of the menu location. @@ -25,5 +25,5 @@ declare module './wp-base-types' { } export type MenuLocation< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.MenuLocation< C > + _BaseEntityTypes.MenuLocation< C > >; diff --git a/packages/core-data/src/types/nav-menu-item.ts b/packages/core-data/src/types/nav-menu-item.ts index 2bd06053a4959..dab6b9ffad2f2 100644 --- a/packages/core-data/src/types/nav-menu-item.ts +++ b/packages/core-data/src/types/nav-menu-item.ts @@ -3,7 +3,7 @@ */ import { RenderedText, Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; export type NavMenuItemType = | 'taxonomy' @@ -18,8 +18,8 @@ export type NavMenuItemStatus = | 'private'; export type Target = '_blank' | ''; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface NavMenuItem< C extends Context > { /** * The title for the object. @@ -102,5 +102,5 @@ declare module './wp-base-types' { } export type NavMenuItem< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.NavMenuItem< C > + _BaseEntityTypes.NavMenuItem< C > >; diff --git a/packages/core-data/src/types/nav-menu.ts b/packages/core-data/src/types/nav-menu.ts index 592d5ecc5b310..aa3417ddba04b 100644 --- a/packages/core-data/src/types/nav-menu.ts +++ b/packages/core-data/src/types/nav-menu.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface NavMenu< C extends Context > { /** * Unique identifier for the term. @@ -49,5 +49,5 @@ declare module './wp-base-types' { } export type NavMenu< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.NavMenu< C > + _BaseEntityTypes.NavMenu< C > >; diff --git a/packages/core-data/src/types/navigation-area.ts b/packages/core-data/src/types/navigation-area.ts index 218d435e76d0f..ed5ae88769207 100644 --- a/packages/core-data/src/types/navigation-area.ts +++ b/packages/core-data/src/types/navigation-area.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface NavigationArea< C extends Context > { /** * The name of the navigation area. @@ -25,5 +25,5 @@ declare module './wp-base-types' { } export type NavigationArea< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.NavigationArea< C > + _BaseEntityTypes.NavigationArea< C > >; diff --git a/packages/core-data/src/types/page.ts b/packages/core-data/src/types/page.ts index e004f49716699..eb95206b8424e 100644 --- a/packages/core-data/src/types/page.ts +++ b/packages/core-data/src/types/page.ts @@ -11,10 +11,10 @@ import { OmitNevers, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Page< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -140,5 +140,5 @@ declare module './wp-base-types' { } export type Page< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Page< C > + _BaseEntityTypes.Page< C > >; diff --git a/packages/core-data/src/types/plugin.ts b/packages/core-data/src/types/plugin.ts index 093b473fd6b08..968f71f7a5bb7 100644 --- a/packages/core-data/src/types/plugin.ts +++ b/packages/core-data/src/types/plugin.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, RenderedText, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Plugin< C extends Context > { /** * The plugin file. @@ -70,5 +70,5 @@ declare module './wp-base-types' { export type PluginStatus = 'active' | 'inactive'; export type Plugin< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Plugin< C > + _BaseEntityTypes.Plugin< C > >; diff --git a/packages/core-data/src/types/post.ts b/packages/core-data/src/types/post.ts index d4fa1c6b5e293..2c7ed4287f183 100644 --- a/packages/core-data/src/types/post.ts +++ b/packages/core-data/src/types/post.ts @@ -12,10 +12,10 @@ import { OmitNevers, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Post< C extends Context > { /** * The date the post was published, in the site's timezone. @@ -149,5 +149,5 @@ declare module './wp-base-types' { } export type Post< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Post< C > + _BaseEntityTypes.Post< C > >; diff --git a/packages/core-data/src/types/settings.ts b/packages/core-data/src/types/settings.ts index c4e94cdd56940..978ce32e9b416 100644 --- a/packages/core-data/src/types/settings.ts +++ b/packages/core-data/src/types/settings.ts @@ -3,10 +3,10 @@ */ import { CommentingStatus, Context, OmitNevers, PingStatus } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Settings< C extends Context > { /** * What to show on the front page @@ -89,5 +89,5 @@ declare module './wp-base-types' { } export type Settings< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Settings< C > + _BaseEntityTypes.Settings< C > >; diff --git a/packages/core-data/src/types/sidebar.ts b/packages/core-data/src/types/sidebar.ts index a82109ca4e01b..7ff4b209ea3ce 100644 --- a/packages/core-data/src/types/sidebar.ts +++ b/packages/core-data/src/types/sidebar.ts @@ -4,10 +4,10 @@ import { Widget } from './widget'; import { Context, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Sidebar< C extends Context > { /** * ID of sidebar. @@ -56,5 +56,5 @@ declare module './wp-base-types' { type SidebarStatus = 'active' | 'inactive'; export type Sidebar< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Sidebar< C > + _BaseEntityTypes.Sidebar< C > >; diff --git a/packages/core-data/src/types/taxonomy.ts b/packages/core-data/src/types/taxonomy.ts index 7fdbce3170a21..120831dbd7acf 100644 --- a/packages/core-data/src/types/taxonomy.ts +++ b/packages/core-data/src/types/taxonomy.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Taxonomy< C extends Context > { /** * All capabilities used by the taxonomy. @@ -88,5 +88,5 @@ declare module './wp-base-types' { } export type Taxonomy< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Taxonomy< C > + _BaseEntityTypes.Taxonomy< C > >; diff --git a/packages/core-data/src/types/theme.ts b/packages/core-data/src/types/theme.ts index 883206d332cee..d3e58fb994861 100644 --- a/packages/core-data/src/types/theme.ts +++ b/packages/core-data/src/types/theme.ts @@ -3,10 +3,10 @@ */ import { Context, PostFormat, RenderedText, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Theme< C extends Context > { /** * The theme's stylesheet. This uniquely identifies the theme. @@ -218,5 +218,5 @@ declare module './wp-base-types' { } export type Theme< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Theme< C > + _BaseEntityTypes.Theme< C > >; diff --git a/packages/core-data/src/types/type.ts b/packages/core-data/src/types/type.ts index 998f43d5e8d6b..2841559eb1139 100644 --- a/packages/core-data/src/types/type.ts +++ b/packages/core-data/src/types/type.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Type< C extends Context > { /** * All capabilities used by the post type. @@ -76,5 +76,5 @@ declare module './wp-base-types' { } export type Type< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Type< C > + _BaseEntityTypes.Type< C > >; diff --git a/packages/core-data/src/types/user.ts b/packages/core-data/src/types/user.ts index e3e1ef4912863..172d369b44bbb 100644 --- a/packages/core-data/src/types/user.ts +++ b/packages/core-data/src/types/user.ts @@ -3,10 +3,10 @@ */ import { AvatarUrls, Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface User< C extends Context > { /** * Unique identifier for the user. @@ -105,5 +105,5 @@ declare module './wp-base-types' { } export type User< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.User< C > + _BaseEntityTypes.User< C > >; diff --git a/packages/core-data/src/types/widget-type.ts b/packages/core-data/src/types/widget-type.ts index 285bfd2641a1a..82f65ea493141 100644 --- a/packages/core-data/src/types/widget-type.ts +++ b/packages/core-data/src/types/widget-type.ts @@ -3,10 +3,10 @@ */ import { Context, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface WidgetType< C extends Context > { /** * Unique slug identifying the widget type. @@ -33,5 +33,5 @@ declare module './wp-base-types' { } export type WidgetType< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.WidgetType< C > + _BaseEntityTypes.WidgetType< C > >; diff --git a/packages/core-data/src/types/widget.ts b/packages/core-data/src/types/widget.ts index ca81f7091c36a..f1b5a489e9297 100644 --- a/packages/core-data/src/types/widget.ts +++ b/packages/core-data/src/types/widget.ts @@ -3,10 +3,10 @@ */ import { Context, ContextualField, OmitNevers } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface Widget< C extends Context > { /** * Unique identifier for the widget. @@ -60,5 +60,5 @@ declare module './wp-base-types' { } export type Widget< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.Widget< C > + _BaseEntityTypes.Widget< C > >; diff --git a/packages/core-data/src/types/wp-template-part.ts b/packages/core-data/src/types/wp-template-part.ts index 6164159579b93..36fc050900338 100644 --- a/packages/core-data/src/types/wp-template-part.ts +++ b/packages/core-data/src/types/wp-template-part.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface WpTemplatePart< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './wp-base-types' { } export type WpTemplatePart< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.WpTemplatePart< C > + _BaseEntityTypes.WpTemplatePart< C > >; diff --git a/packages/core-data/src/types/wp-template.ts b/packages/core-data/src/types/wp-template.ts index c985136130047..33fa31787792a 100644 --- a/packages/core-data/src/types/wp-template.ts +++ b/packages/core-data/src/types/wp-template.ts @@ -9,10 +9,10 @@ import { ContextualField, } from './helpers'; -import { CoreBaseEntityTypes as _CoreBaseEntityTypes } from './wp-base-types'; +import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types'; -declare module './wp-base-types' { - export namespace CoreBaseEntityTypes { +declare module './base-entity-types' { + export namespace BaseEntityTypes { export interface WpTemplate< C extends Context > { /** * ID of template. @@ -90,5 +90,5 @@ declare module './wp-base-types' { } export type WpTemplate< C extends Context > = OmitNevers< - _CoreBaseEntityTypes.WpTemplate< C > + _BaseEntityTypes.WpTemplate< C > >; From 0fbd96f4f0cbf468a4bec7f9c027981ab923dcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 22 Feb 2022 23:57:43 +0100 Subject: [PATCH 73/73] Fix a typo (extends -> extend) --- packages/core-data/src/types/base-entity-types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types/base-entity-types.ts b/packages/core-data/src/types/base-entity-types.ts index 708d2b6887c6f..790eaa63cfc9d 100644 --- a/packages/core-data/src/types/base-entity-types.ts +++ b/packages/core-data/src/types/base-entity-types.ts @@ -13,7 +13,7 @@ * } * ``` * - * The huge upside is that consumers of @wordpress/core-data may extends the + * The huge upside is that consumers of @wordpress/core-data may extend the * exported data types using interface merging as follows: * * ```ts