@@ -4,11 +4,11 @@ Client library for the WordPress Abilities API, providing a standardized way to
44
55## Table of Contents
66
7- - [ Installation] ( #installation )
8- - [ Usage] ( #usage )
9- - [ API Reference] ( #api-reference )
10- - [ Development] ( #development )
11- - [ Testing] ( #testing )
7+ - [ Installation] ( #installation )
8+ - [ Usage] ( #usage )
9+ - [ API Reference] ( #api-reference )
10+ - [ Development] ( #development )
11+ - [ Testing] ( #testing )
1212
1313## Installation
1414
@@ -67,13 +67,13 @@ const { listAbilities, getAbility, executeAbility } = wp.abilities;
6767const abilities = await listAbilities ();
6868
6969// Get a specific ability
70- const ability = await getAbility ( ' my-plugin/my-ability' );
70+ const ability = await getAbility (' my-plugin/my-ability' );
7171
7272// Execute an ability
73- const result = await executeAbility ( ' my-plugin/my-ability' , {
74- param1: ' value1' ,
75- param2: ' value2'
76- } );
73+ const result = await executeAbility (' my-plugin/my-ability' , {
74+ param1: ' value1' ,
75+ param2: ' value2' ,
76+ });
7777```
7878
7979### Using with React and WordPress Data
@@ -85,28 +85,28 @@ import { useSelect } from '@wordpress/data';
8585import { store as abilitiesStore } from ' @wordpress/abilities' ;
8686
8787function MyComponent () {
88- const abilities = useSelect (
89- ( select ) => select ( abilitiesStore ).getAbilities (),
90- []
91- );
92-
93- const specificAbility = useSelect (
94- ( select ) => select ( abilitiesStore ).getAbility ( ' my-plugin/my-ability' ),
95- []
96- );
97-
98- return (
99- < div>
100- < h2> All Abilities< / h2>
101- < ul>
102- { abilities .map ( ( ability ) => (
103- < li key= { ability .name }>
104- < strong> { ability .label }< / strong> : { ability .description }
105- < / li>
106- ) ) }
107- < / ul>
108- < / div>
109- );
88+ const abilities = useSelect (
89+ ( select ) => select (abilitiesStore).getAbilities (),
90+ []
91+ );
92+
93+ const specificAbility = useSelect (
94+ ( select ) => select (abilitiesStore).getAbility (' my-plugin/my-ability' ),
95+ []
96+ );
97+
98+ return (
99+ < div>
100+ < h2> All Abilities< / h2>
101+ < ul>
102+ { abilities .map (( ability ) => (
103+ < li key= {ability .name }>
104+ < strong> {ability .label }< / strong> : {ability .description }
105+ < / li>
106+ )) }
107+ < / ul>
108+ < / div>
109+ );
110110}
111111```
112112
@@ -120,46 +120,46 @@ Returns all registered abilities. Automatically handles pagination to fetch all
120120
121121``` javascript
122122const abilities = await listAbilities ();
123- console .log ( ` Found ${ abilities .length } abilities` );
123+ console .log (` Found ${ abilities .length } abilities` );
124124```
125125
126126#### ` getAbility(name: string): Promise<Ability | null> `
127127
128128Returns a specific ability by name, or null if not found.
129129
130130``` javascript
131- const ability = await getAbility ( ' my-plugin/create-post' );
132- if ( ability ) {
133- console .log ( ` Found ability: ${ ability .label } ` );
131+ const ability = await getAbility (' my-plugin/create-post' );
132+ if (ability) {
133+ console .log (` Found ability: ${ ability .label } ` );
134134}
135135```
136136
137137#### ` executeAbility(name: string, input?: Record<string, any>): Promise<any> `
138138
139139Executes an ability with optional input parameters. The HTTP method is automatically determined based on the ability's type:
140140
141- - ` resource ` type abilities use GET (read-only operations)
142- - ` tool ` type abilities use POST (write operations)
141+ - ` resource ` type abilities use GET (read-only operations)
142+ - ` tool ` type abilities use POST (write operations)
143143
144144``` javascript
145145// Execute a resource ability (GET)
146- const data = await executeAbility ( ' my-plugin/get-data' , {
147- id: 123
148- } );
146+ const data = await executeAbility (' my-plugin/get-data' , {
147+ id: 123 ,
148+ });
149149
150150// Execute a tool ability (POST)
151- const result = await executeAbility ( ' my-plugin/create-item' , {
152- title: ' New Item' ,
153- content: ' Item content'
154- } );
151+ const result = await executeAbility (' my-plugin/create-item' , {
152+ title: ' New Item' ,
153+ content: ' Item content' ,
154+ });
155155```
156156
157157### Store Selectors
158158
159159When using with ` @wordpress/data ` :
160160
161- - ` getAbilities() ` - Returns all abilities from the store
162- - ` getAbility(name) ` - Returns a specific ability from the store
161+ - ` getAbilities() ` - Returns all abilities from the store
162+ - ` getAbility(name) ` - Returns a specific ability from the store
163163
164164## Development
165165
@@ -201,7 +201,7 @@ npm run test:unit:debug
201201
202202Tests are organized following WordPress conventions:
203203
204- - Unit tests are located in ` src/__tests__/ `
205- - Store tests are located in ` src/store/__tests__/ `
206- - Test files use ` .test.ts ` or ` .test.js ` extension
207- - Tests use Jest with ` @wordpress/jest-preset-default ` configuration
204+ - Unit tests are located in ` src/__tests__/ `
205+ - Store tests are located in ` src/store/__tests__/ `
206+ - Test files use ` .test.ts ` or ` .test.js ` extension
207+ - Tests use Jest with ` @wordpress/jest-preset-default ` configuration
0 commit comments