Skip to content

Commit 02901b9

Browse files
gziolojorgefilipecostajsnajdr
authored
Improve JSDoc for abilities API (#76824)
Clarify descriptions, fix redundancy, and align tag style across all functions in `packages/abilities/src/api.ts`. Notably, corrects the `executeAbility` description to accurately reflect that input and output validation runs on the client for all abilities, with server-side abilities also validated on the server for both. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
1 parent bc627d8 commit 02901b9

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

packages/abilities/src/api.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { validateValueFromSchema } from './validation';
2121
/**
2222
* Get all available abilities with optional filtering.
2323
*
24-
* @param args Optional query arguments to filter. Defaults to empty object.
25-
* @return Array of abilities.
24+
* @param args Optional query arguments for filtering abilities.
25+
* @return Array of matching abilities.
2626
*/
2727
export function getAbilities( args: AbilitiesQueryArgs = {} ): Ability[] {
2828
return select( store ).getAbilities( args );
@@ -62,11 +62,8 @@ export function getAbilityCategory(
6262
/**
6363
* Register a client-side ability.
6464
*
65-
* Client abilities are executed locally in the browser and must include
66-
* a callback function. The ability will be validated by the store action,
67-
* and an error will be thrown if validation fails.
68-
*
69-
* The category must already be registered before registering abilities.
65+
* Client-side abilities are executed locally in the browser and must include
66+
* a callback function. The ability's category must already be registered.
7067
*
7168
* @param ability The ability definition including callback.
7269
* @throws {Error} If the ability fails validation.
@@ -97,12 +94,10 @@ export function registerAbility( ability: Ability ): void {
9794
}
9895

9996
/**
100-
* Unregister an ability from the store.
101-
*
102-
* Remove a client-side ability from the store.
103-
* Note: This will return an error for server-side abilities.
97+
* Unregister a client-side ability from the store.
10498
*
105-
* @param name The ability name to unregister.
99+
* @param name The ability name to unregister.
100+
* @throws {Error} If the ability is server-side and cannot be unregistered.
106101
*/
107102
export function unregisterAbility( name: string ): void {
108103
dispatch( store ).unregisterAbility( name );
@@ -111,10 +106,9 @@ export function unregisterAbility( name: string ): void {
111106
/**
112107
* Register a client-side ability category.
113108
*
114-
* Categories registered on the client are stored alongside server-side categories
115-
* in the same store and can be used when registering client side abilities.
116-
* This is useful when registering client-side abilities that introduce new
117-
* categories not defined by the server.
109+
* Use this when registering client-side abilities that belong to a category
110+
* not already defined by the server. Client-side categories are stored
111+
* alongside server-side categories in the same store.
118112
*
119113
* @param slug Category slug (lowercase alphanumeric with dashes only).
120114
* @param args Category arguments (label, description, optional meta).
@@ -151,8 +145,6 @@ export function registerAbilityCategory(
151145
/**
152146
* Unregister an ability category.
153147
*
154-
* Removes a category from the store.
155-
*
156148
* @param slug The category slug to unregister.
157149
*
158150
* @example
@@ -167,13 +159,16 @@ export function unregisterAbilityCategory( slug: string ): void {
167159
/**
168160
* Execute an ability.
169161
*
170-
* Executes abilities with validation for client-side abilities only.
171-
* Server abilities bypass validation as it's handled on the server.
162+
* Validates input and output against their schemas when defined. For
163+
* server-side abilities, input is validated on the client first to avoid
164+
* unnecessary network roundtrips, then both input and output are validated on
165+
* the server. The client also re-validates the output to ensure data
166+
* compatibility between server and client.
172167
*
173-
* @param name The ability name.
174-
* @param input Optional input parameters for the ability.
168+
* @param name The ability name.
169+
* @param input Optional input parameters for the ability.
175170
* @return Promise resolving to the ability execution result.
176-
* @throws Error if the ability is not found or execution fails.
171+
* @throws {Error} If the ability is not found, permission is denied, input or output validation fails, or execution throws.
177172
*/
178173
export async function executeAbility(
179174
name: string,

0 commit comments

Comments
 (0)