Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Commit 0759075

Browse files
committed
Regenerate types in the client build
1 parent c5b5b1b commit 0759075

9 files changed

Lines changed: 408 additions & 0 deletions

File tree

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import type { Ability, AbilityCategory, AbilityCategoryArgs, AbilitiesQueryArgs, AbilityInput, AbilityOutput } from './types';
2+
/**
3+
* Get all available abilities with optional filtering.
4+
*
5+
* @param args Optional query arguments to filter. Defaults to empty object.
6+
* @return Promise resolving to array of abilities.
7+
*/
8+
export declare function getAbilities(args?: AbilitiesQueryArgs): Promise<Ability[]>;
9+
/**
10+
* Get a specific ability by name.
11+
*
12+
* @param name The ability name.
13+
* @return Promise resolving to the ability or null if not found.
14+
*/
15+
export declare function getAbility(name: string): Promise<Ability | null>;
16+
/**
17+
* Get all available ability categories.
18+
*
19+
* @return Promise resolving to array of categories.
20+
*/
21+
export declare function getAbilityCategories(): Promise<AbilityCategory[]>;
22+
/**
23+
* Get a specific ability category by slug.
24+
*
25+
* @param slug The category slug.
26+
* @return Promise resolving to the category or null if not found.
27+
*/
28+
export declare function getAbilityCategory(slug: string): Promise<AbilityCategory | null>;
29+
/**
30+
* Register a client-side ability.
31+
*
32+
* Client abilities are executed locally in the browser and must include
33+
* a callback function. The ability will be validated by the store action,
34+
* and an error will be thrown if validation fails.
35+
*
36+
* Categories will be automatically fetched from the REST API if they
37+
* haven't been loaded yet, so you don't need to call getAbilityCategories()
38+
* before registering abilities.
39+
*
40+
* @param ability The ability definition including callback.
41+
* @return Promise that resolves when registration is complete.
42+
* @throws {Error} If the ability fails validation.
43+
*
44+
* @example
45+
* ```js
46+
* await registerAbility({
47+
* name: 'my-plugin/navigate',
48+
* label: 'Navigate to URL',
49+
* description: 'Navigates to a URL within WordPress admin',
50+
* category: 'navigation',
51+
* input_schema: {
52+
* type: 'object',
53+
* properties: {
54+
* url: { type: 'string' }
55+
* },
56+
* required: ['url']
57+
* },
58+
* callback: async ({ url }) => {
59+
* window.location.href = url;
60+
* return { success: true };
61+
* }
62+
* });
63+
* ```
64+
*/
65+
export declare function registerAbility(ability: Ability): Promise<void>;
66+
/**
67+
* Unregister an ability from the store.
68+
*
69+
* Remove a client-side ability from the store.
70+
* Note: This will return an error for server-side abilities.
71+
*
72+
* @param name The ability name to unregister.
73+
*/
74+
export declare function unregisterAbility(name: string): void;
75+
/**
76+
* Register a client-side ability category.
77+
*
78+
* Categories registered on the client are stored alongside server-side categories
79+
* in the same store and can be used when registering client side abilities.
80+
* This is useful when registering client-side abilities that introduce new
81+
* categories not defined by the server.
82+
*
83+
* Categories will be automatically fetched from the REST API if they haven't been
84+
* loaded yet to check for duplicates against server-side categories.
85+
*
86+
* @param slug Category slug (lowercase alphanumeric with dashes only).
87+
* @param args Category arguments (label, description, optional meta).
88+
* @return Promise that resolves when registration is complete.
89+
* @throws {Error} If the category fails validation.
90+
*
91+
* @example
92+
* ```js
93+
* // Register a new category for block editor abilities
94+
* await registerAbilityCategory('block-editor', {
95+
* label: 'Block Editor',
96+
* description: 'Abilities for interacting with the WordPress block editor'
97+
* });
98+
*
99+
* // Then register abilities using this category
100+
* await registerAbility({
101+
* name: 'my-plugin/insert-block',
102+
* label: 'Insert Block',
103+
* description: 'Inserts a block into the editor',
104+
* category: 'block-editor',
105+
* callback: async ({ blockType }) => {
106+
* // Implementation
107+
* return { success: true };
108+
* }
109+
* });
110+
* ```
111+
*/
112+
export declare function registerAbilityCategory(slug: string, args: AbilityCategoryArgs): Promise<void>;
113+
/**
114+
* Unregister an ability category.
115+
*
116+
* Removes a category from the store.
117+
*
118+
* @param slug The category slug to unregister.
119+
*
120+
* @example
121+
* ```js
122+
* unregisterAbilityCategory('block-editor');
123+
* ```
124+
*/
125+
export declare function unregisterAbilityCategory(slug: string): void;
126+
/**
127+
* Execute an ability.
128+
*
129+
* Determines whether to execute locally (client abilities) or remotely (server abilities)
130+
* based on whether the ability has a callback function.
131+
*
132+
* @param name The ability name.
133+
* @param input Optional input parameters for the ability.
134+
* @return Promise resolving to the ability execution result.
135+
* @throws Error if the ability is not found or execution fails.
136+
*/
137+
export declare function executeAbility(name: string, input?: AbilityInput): Promise<AbilityOutput>;
138+
//# sourceMappingURL=api.d.ts.map
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* WordPress Abilities API Client
3+
*
4+
* This package provides a client for interacting with the
5+
* WordPress Abilities API, allowing you to list, retrieve, and execute
6+
* abilities from client-side code.
7+
*
8+
* @package
9+
*/
10+
import * as api from './api';
11+
import { store } from './store';
12+
/**
13+
* TypeScript declaration for the global wp object
14+
*/
15+
declare global {
16+
interface Window {
17+
wp: {
18+
abilities?: typeof api & {
19+
store: typeof store;
20+
};
21+
[key: string]: any;
22+
};
23+
}
24+
}
25+
/**
26+
* Public API functions
27+
*/
28+
export { getAbilities, getAbility, getAbilityCategories, getAbilityCategory, executeAbility, registerAbility, unregisterAbility, registerAbilityCategory, unregisterAbilityCategory, } from './api';
29+
/**
30+
* The store can be used directly with @wordpress/data via selectors
31+
* in React components with useSelect.
32+
*
33+
* @example
34+
* ```js
35+
* import { useSelect } from '@wordpress/data';
36+
* import { store as abilitiesStore } from '@wordpress/abilities';
37+
*
38+
* function MyComponent() {
39+
* const abilities = useSelect(
40+
* (select) => select(abilitiesStore).getAbilities(),
41+
* []
42+
* );
43+
* // Use abilities...
44+
* }
45+
* ```
46+
*/
47+
export { store } from './store';
48+
/**
49+
* Type definitions
50+
*/
51+
export type { Ability, AbilityCategory, AbilityCategoryArgs, AbilitiesState, AbilitiesQueryArgs, AbilityCallback, PermissionCallback, AbilityInput, AbilityOutput, ValidationError, } from './types';
52+
/**
53+
* Validation utilities
54+
*/
55+
export { validateValueFromSchema } from './validation';
56+
//# sourceMappingURL=index.d.ts.map
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';
5+
/**
6+
* Returns an action object used to receive abilities into the store.
7+
*
8+
* @param abilities Array of abilities to store.
9+
* @return Action object.
10+
*/
11+
export declare function receiveAbilities(abilities: Ability[]): {
12+
type: string;
13+
abilities: Ability[];
14+
};
15+
/**
16+
* Returns an action object used to receive categories into the store.
17+
*
18+
* @param categories Array of categories to store.
19+
* @return Action object.
20+
*/
21+
export declare function receiveCategories(categories: AbilityCategory[]): {
22+
type: string;
23+
categories: AbilityCategory[];
24+
};
25+
/**
26+
* Registers an ability in the store.
27+
*
28+
* This action validates the ability before registration. If validation fails,
29+
* an error will be thrown. Categories will be automatically fetched from the
30+
* REST API if they haven't been loaded yet.
31+
*
32+
* @param ability The ability to register.
33+
* @return Action object or function.
34+
* @throws {Error} If validation fails.
35+
*/
36+
export declare function registerAbility(ability: Ability): ({ select, dispatch }: {
37+
select: any;
38+
dispatch: any;
39+
}) => Promise<void>;
40+
/**
41+
* Returns an action object used to unregister a client-side ability.
42+
*
43+
* @param name The name of the ability to unregister.
44+
* @return Action object.
45+
*/
46+
export declare function unregisterAbility(name: string): {
47+
type: string;
48+
name: string;
49+
};
50+
/**
51+
* Registers a client-side ability category in the store.
52+
*
53+
* This action validates the category before registration. If validation fails,
54+
* an error will be thrown. Categories will be automatically fetched from the
55+
* REST API if they haven't been loaded yet to check for duplicates.
56+
*
57+
* @param slug The unique category slug identifier.
58+
* @param args Category arguments (label, description, optional meta).
59+
* @return Action object or function.
60+
* @throws {Error} If validation fails.
61+
*/
62+
export declare function registerAbilityCategory(slug: string, args: AbilityCategoryArgs): ({ select, dispatch }: {
63+
select: any;
64+
dispatch: any;
65+
}) => Promise<void>;
66+
/**
67+
* Returns an action object used to unregister a client-side ability category.
68+
*
69+
* @param slug The slug of the category to unregister.
70+
* @return Action object.
71+
*/
72+
export declare function unregisterAbilityCategory(slug: string): {
73+
type: string;
74+
slug: string;
75+
};
76+
//# sourceMappingURL=actions.d.ts.map
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Store constants
3+
*/
4+
export declare const STORE_NAME = "abilities-api/abilities";
5+
export declare const ENTITY_KIND = "root";
6+
export declare const ENTITY_NAME = "abilities";
7+
export declare const ENTITY_NAME_CATEGORIES = "ability-categories";
8+
export declare const RECEIVE_ABILITIES = "RECEIVE_ABILITIES";
9+
export declare const REGISTER_ABILITY = "REGISTER_ABILITY";
10+
export declare const UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
11+
export declare const RECEIVE_CATEGORIES = "RECEIVE_CATEGORIES";
12+
export declare const REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
13+
export declare const UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
14+
//# sourceMappingURL=constants.d.ts.map
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as actions from './actions';
2+
import * as selectors from './selectors';
3+
/**
4+
* The abilities store definition.
5+
*/
6+
export declare const store: import("@wordpress/data/build-types/types").StoreDescriptor<import("@wordpress/data/build-types/types").ReduxStoreConfig<unknown, typeof actions, typeof selectors>>;
7+
//# sourceMappingURL=index.d.ts.map
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import type { Ability, AbilityCategory } from '../types';
5+
interface AbilitiesAction {
6+
type: string;
7+
abilities?: Ability[];
8+
ability?: Ability;
9+
categories?: AbilityCategory[];
10+
category?: AbilityCategory;
11+
name?: string;
12+
slug?: string;
13+
}
14+
declare const _default: import("redux").Reducer<{
15+
abilitiesByName: Record<string, Ability>;
16+
categoriesBySlug: Record<string, AbilityCategory>;
17+
}, AbilitiesAction, Partial<{
18+
abilitiesByName: Record<string, Ability> | undefined;
19+
categoriesBySlug: Record<string, AbilityCategory> | undefined;
20+
}>>;
21+
export default _default;
22+
//# sourceMappingURL=reducer.d.ts.map
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Resolver for getAbilities selector.
3+
* Fetches all abilities from the server.
4+
*
5+
* The resolver only fetches once (without query args filter) and stores all abilities.
6+
* Query args filtering handled client-side by the selector for better performance
7+
* and to avoid multiple API requests when filtering by different categories.
8+
*/
9+
export declare function getAbilities(): ({ dispatch, registry, select }: {
10+
dispatch: any;
11+
registry: any;
12+
select: any;
13+
}) => Promise<void>;
14+
/**
15+
* Resolver for getAbility selector.
16+
* Fetches a specific ability from the server if not already in store.
17+
*
18+
* @param name Ability name.
19+
*/
20+
export declare function getAbility(name: string): ({ dispatch, registry, select }: {
21+
dispatch: any;
22+
registry: any;
23+
select: any;
24+
}) => Promise<void>;
25+
/**
26+
* Resolver for getAbilityCategories selector.
27+
* Fetches all categories from the server.
28+
*
29+
* The resolver only fetches once and stores all categories.
30+
*/
31+
export declare function getAbilityCategories(): ({ dispatch, registry, select }: {
32+
dispatch: any;
33+
registry: any;
34+
select: any;
35+
}) => Promise<void>;
36+
/**
37+
* Resolver for getAbilityCategory selector.
38+
* Fetches a specific category from the server if not already in store.
39+
*
40+
* @param slug Category slug.
41+
*/
42+
export declare function getAbilityCategory(slug: string): ({ dispatch, registry, select }: {
43+
dispatch: any;
44+
registry: any;
45+
select: any;
46+
}) => Promise<void>;
47+
//# sourceMappingURL=resolvers.d.ts.map

0 commit comments

Comments
 (0)