Skip to content

Commit

Permalink
Core Data: add type for term entity (WordPress#69151)
Browse files Browse the repository at this point in the history
Follow-up to WordPress#67668, makes it easy to use term types with `getEntityRecords` and the like
  • Loading branch information
swissspidy authored Feb 11, 2025
1 parent dc40184 commit fe2195e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core-data/src/dynamic-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type WPEntityTypes< C extends ET.Context = 'edit' > = {
Site: ET.Settings< C >;
Status: ET.PostStatusObject< C >;
Taxonomy: ET.Taxonomy< C >;
Term: ET.Term< C >;
Theme: ET.Theme< C >;
UnstableBase: ET.UnstableBase< C >;
User: ET.User< C >;
Expand Down
3 changes: 3 additions & 0 deletions packages/core-data/src/entity-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { PostRevision } from './post-revision';
import type { Settings } from './settings';
import type { Sidebar } from './sidebar';
import type { Taxonomy } from './taxonomy';
import type { Term } from './term';
import type { Theme } from './theme';
import type { User } from './user';
import type { Type } from './type';
Expand Down Expand Up @@ -46,6 +47,7 @@ export type {
Taxonomy,
TemplatePartArea,
TemplateType,
Term,
Theme,
Type,
Updatable,
Expand Down Expand Up @@ -105,6 +107,7 @@ export interface PerPackageEntityRecords< C extends Context > {
| Settings< C >
| Sidebar< C >
| Taxonomy< C >
| Term< C >
| Theme< C >
| User< C >
| Type< C >
Expand Down
57 changes: 57 additions & 0 deletions packages/core-data/src/entity-types/term.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Internal dependencies
*/
import type { Context, ContextualField, OmitNevers } from './helpers';

import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';

declare module './base-entity-records' {
export namespace BaseEntityRecords {
export interface Term< C extends Context > {
/**
* Unique identifier for the term.
*/
id: number;
/**
* Number of published posts for the term.
*/
count: ContextualField< number, 'view' | 'edit', C >;
/**
* HTML description of the term.
*/
description: ContextualField< string, 'view' | 'edit', C >;
/**
* URL of the term.
*/
link: string;
/**
* HTML title for the term.
*/
name: string;
/**
* An alphanumeric identifier for the term unique to its type.
*/
slug: string;
/**
* Type attribution for the term.
*/
taxonomy: string;
/**
* The parent term ID. Only present for hierarchical taxonomies.
*/
parent?: number;
/**
* Meta fields.
*/
meta: ContextualField<
Record< string, string >,
'view' | 'edit',
C
>;
}
}
}

export type Term< C extends Context = 'edit' > = OmitNevers<
_BaseEntityRecords.Term< C >
>;

0 comments on commit fe2195e

Please sign in to comment.