@wordpress/abilities 0.1.1-next.dc3f6d3c1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +302 -0
  4. package/build/api.js +189 -0
  5. package/build/api.js.map +7 -0
  6. package/build/index.js +53 -0
  7. package/build/index.js.map +7 -0
  8. package/build/store/actions.js +183 -0
  9. package/build/store/actions.js.map +7 -0
  10. package/build/store/constants.js +58 -0
  11. package/build/store/constants.js.map +7 -0
  12. package/build/store/index.js +77 -0
  13. package/build/store/index.js.map +7 -0
  14. package/build/store/reducer.js +126 -0
  15. package/build/store/reducer.js.map +7 -0
  16. package/build/store/resolvers.js +107 -0
  17. package/build/store/resolvers.js.map +7 -0
  18. package/build/store/selectors.js +64 -0
  19. package/build/store/selectors.js.map +7 -0
  20. package/build/store/tests/actions.test.js +792 -0
  21. package/build/store/tests/actions.test.js.map +7 -0
  22. package/build/store/tests/reducer.test.js +743 -0
  23. package/build/store/tests/reducer.test.js.map +7 -0
  24. package/build/store/tests/resolvers.test.js +520 -0
  25. package/build/store/tests/resolvers.test.js.map +7 -0
  26. package/build/store/tests/selectors.test.js +349 -0
  27. package/build/store/tests/selectors.test.js.map +7 -0
  28. package/build/tests/api.test.js +546 -0
  29. package/build/tests/api.test.js.map +7 -0
  30. package/build/tests/validation.test.js +453 -0
  31. package/build/tests/validation.test.js.map +7 -0
  32. package/build/types.js +19 -0
  33. package/build/types.js.map +7 -0
  34. package/build/validation.js +144 -0
  35. package/build/validation.js.map +7 -0
  36. package/build-module/api.js +146 -0
  37. package/build-module/api.js.map +7 -0
  38. package/build-module/index.js +28 -0
  39. package/build-module/index.js.map +7 -0
  40. package/build-module/store/actions.js +161 -0
  41. package/build-module/store/actions.js.map +7 -0
  42. package/build-module/store/constants.js +24 -0
  43. package/build-module/store/constants.js.map +7 -0
  44. package/build-module/store/index.js +47 -0
  45. package/build-module/store/index.js.map +7 -0
  46. package/build-module/store/reducer.js +112 -0
  47. package/build-module/store/reducer.js.map +7 -0
  48. package/build-module/store/resolvers.js +84 -0
  49. package/build-module/store/resolvers.js.map +7 -0
  50. package/build-module/store/selectors.js +36 -0
  51. package/build-module/store/selectors.js.map +7 -0
  52. package/build-module/store/tests/actions.test.js +804 -0
  53. package/build-module/store/tests/actions.test.js.map +7 -0
  54. package/build-module/store/tests/reducer.test.js +726 -0
  55. package/build-module/store/tests/reducer.test.js.map +7 -0
  56. package/build-module/store/tests/resolvers.test.js +523 -0
  57. package/build-module/store/tests/resolvers.test.js.map +7 -0
  58. package/build-module/store/tests/selectors.test.js +352 -0
  59. package/build-module/store/tests/selectors.test.js.map +7 -0
  60. package/build-module/tests/api.test.js +530 -0
  61. package/build-module/tests/api.test.js.map +7 -0
  62. package/build-module/tests/validation.test.js +451 -0
  63. package/build-module/tests/validation.test.js.map +7 -0
  64. package/build-module/types.js +1 -0
  65. package/build-module/types.js.map +7 -0
  66. package/build-module/validation.js +109 -0
  67. package/build-module/validation.js.map +7 -0
  68. package/build-types/api.d.ts +138 -0
  69. package/build-types/api.d.ts.map +1 -0
  70. package/build-types/index.d.ts +41 -0
  71. package/build-types/index.d.ts.map +1 -0
  72. package/build-types/store/actions.d.ts +76 -0
  73. package/build-types/store/actions.d.ts.map +1 -0
  74. package/build-types/store/constants.d.ts +14 -0
  75. package/build-types/store/constants.d.ts.map +1 -0
  76. package/build-types/store/index.d.ts +7 -0
  77. package/build-types/store/index.d.ts.map +1 -0
  78. package/build-types/store/reducer.d.ts +22 -0
  79. package/build-types/store/reducer.d.ts.map +1 -0
  80. package/build-types/store/resolvers.d.ts +47 -0
  81. package/build-types/store/resolvers.d.ts.map +1 -0
  82. package/build-types/store/selectors.d.ts +37 -0
  83. package/build-types/store/selectors.d.ts.map +1 -0
  84. package/build-types/types.d.ts +163 -0
  85. package/build-types/types.d.ts.map +1 -0
  86. package/build-types/validation.d.ts +23 -0
  87. package/build-types/validation.d.ts.map +1 -0
  88. package/package.json +52 -0
  89. package/src/api.ts +339 -0
  90. package/src/index.ts +65 -0
  91. package/src/store/actions.ts +247 -0
  92. package/src/store/constants.ts +15 -0
  93. package/src/store/index.ts +55 -0
  94. package/src/store/reducer.ts +184 -0
  95. package/src/store/resolvers.ts +151 -0
  96. package/src/store/selectors.ts +82 -0
  97. package/src/store/tests/actions.test.ts +950 -0
  98. package/src/store/tests/reducer.test.ts +861 -0
  99. package/src/store/tests/resolvers.test.ts +642 -0
  100. package/src/store/tests/selectors.test.ts +412 -0
  101. package/src/tests/api.test.ts +655 -0
  102. package/src/tests/validation.test.ts +532 -0
  103. package/src/types.ts +190 -0
  104. package/src/validation.ts +207 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/validation.ts"],
4
+ "sourcesContent": ["/**\n * Schema validation for client-side ability input and output schemas using AJV and ajv-formats.\n *\n * This utility provides validation for JSON Schema draft-04.\n * Rules are configured to support the intersection of common rules between JSON Schema draft-04, WordPress (a subset of JSON Schema draft-04),\n * and various providers like OpenAI and Anthropic.\n *\n * @see https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#json-schema-basics\n */\n\n/**\n * External dependencies\n */\nimport Ajv from 'ajv-draft-04';\nimport addFormats from 'ajv-formats';\n\n/**\n * Internal dependencies\n */\nimport type { ValidationError } from './types';\n\nconst ajv = new Ajv( {\n\tcoerceTypes: false, // No type coercion - AI should send proper JSON\n\tuseDefaults: true,\n\tremoveAdditional: false, // Keep additional properties\n\tallErrors: true,\n\tverbose: true,\n\tallowUnionTypes: true, // Allow anyOf without explicit type\n} );\n\naddFormats( ajv, [ 'date-time', 'email', 'hostname', 'ipv4', 'ipv6', 'uuid' ] );\n\n/**\n * Formats AJV errors into a simple error message.\n * The Abilities API will wrap this with ability_invalid_input/output to match the server side format.\n *\n * @param ajvError The AJV validation error.\n * @param param The base parameter name.\n * @return Simple error message string.\n */\nfunction formatAjvError( ajvError: any, param: string ): string {\n\t// Convert AJV's instancePath format (/0/prop) to an array like format to better match WordPress ([0][prop])\n\tconst instancePath = ajvError.instancePath\n\t\t? ajvError.instancePath.replace( /\\//g, '][' ).replace( /^\\]\\[/, '[' ) +\n\t\t ']'\n\t\t: '';\n\tconst fullParam = param + instancePath;\n\n\tswitch ( ajvError.keyword ) {\n\t\tcase 'type':\n\t\t\treturn `${ fullParam } is not of type ${ ajvError.params.type }.`;\n\n\t\tcase 'required':\n\t\t\treturn `${ ajvError.params.missingProperty } is a required property of ${ fullParam }.`;\n\n\t\tcase 'additionalProperties':\n\t\t\treturn `${ ajvError.params.additionalProperty } is not a valid property of Object.`;\n\n\t\tcase 'enum':\n\t\t\tconst enumValues = ajvError.params.allowedValues\n\t\t\t\t.map( ( v: any ) =>\n\t\t\t\t\ttypeof v === 'string' ? v : JSON.stringify( v )\n\t\t\t\t)\n\t\t\t\t.join( ', ' );\n\t\t\treturn ajvError.params.allowedValues.length === 1\n\t\t\t\t? `${ fullParam } is not ${ enumValues }.`\n\t\t\t\t: `${ fullParam } is not one of ${ enumValues }.`;\n\n\t\tcase 'pattern':\n\t\t\treturn `${ fullParam } does not match pattern ${ ajvError.params.pattern }.`;\n\n\t\tcase 'format':\n\t\t\tconst format = ajvError.params.format;\n\t\t\tconst formatMessages: Record< string, string > = {\n\t\t\t\temail: 'Invalid email address.',\n\t\t\t\t'date-time': 'Invalid date.',\n\t\t\t\tuuid: `${ fullParam } is not a valid UUID.`,\n\t\t\t\tipv4: `${ fullParam } is not a valid IP address.`,\n\t\t\t\tipv6: `${ fullParam } is not a valid IP address.`,\n\t\t\t\thostname: `${ fullParam } is not a valid hostname.`,\n\t\t\t};\n\t\t\treturn formatMessages[ format ] || `Invalid ${ format }.`;\n\n\t\tcase 'minimum':\n\t\tcase 'exclusiveMinimum':\n\t\t\treturn ajvError.keyword === 'exclusiveMinimum'\n\t\t\t\t? `${ fullParam } must be greater than ${ ajvError.params.limit }`\n\t\t\t\t: `${ fullParam } must be greater than or equal to ${ ajvError.params.limit }`;\n\n\t\tcase 'maximum':\n\t\tcase 'exclusiveMaximum':\n\t\t\treturn ajvError.keyword === 'exclusiveMaximum'\n\t\t\t\t? `${ fullParam } must be less than ${ ajvError.params.limit }`\n\t\t\t\t: `${ fullParam } must be less than or equal to ${ ajvError.params.limit }`;\n\n\t\tcase 'multipleOf':\n\t\t\treturn `${ fullParam } must be a multiple of ${ ajvError.params.multipleOf }.`;\n\n\t\tcase 'anyOf':\n\t\tcase 'oneOf':\n\t\t\treturn `${ fullParam } is invalid (failed ${ ajvError.keyword } validation).`;\n\n\t\tcase 'minLength':\n\t\t\treturn `${ fullParam } must be at least ${\n\t\t\t\tajvError.params.limit\n\t\t\t} character${ ajvError.params.limit === 1 ? '' : 's' } long.`;\n\n\t\tcase 'maxLength':\n\t\t\treturn `${ fullParam } must be at most ${\n\t\t\t\tajvError.params.limit\n\t\t\t} character${ ajvError.params.limit === 1 ? '' : 's' } long.`;\n\n\t\tcase 'minItems':\n\t\t\treturn `${ fullParam } must contain at least ${\n\t\t\t\tajvError.params.limit\n\t\t\t} item${ ajvError.params.limit === 1 ? '' : 's' }.`;\n\n\t\tcase 'maxItems':\n\t\t\treturn `${ fullParam } must contain at most ${\n\t\t\t\tajvError.params.limit\n\t\t\t} item${ ajvError.params.limit === 1 ? '' : 's' }.`;\n\n\t\tcase 'uniqueItems':\n\t\t\treturn `${ fullParam } has duplicate items.`;\n\n\t\tcase 'minProperties':\n\t\t\treturn `${ fullParam } must contain at least ${\n\t\t\t\tajvError.params.limit\n\t\t\t} propert${ ajvError.params.limit === 1 ? 'y' : 'ies' }.`;\n\n\t\tcase 'maxProperties':\n\t\t\treturn `${ fullParam } must contain at most ${\n\t\t\t\tajvError.params.limit\n\t\t\t} propert${ ajvError.params.limit === 1 ? 'y' : 'ies' }.`;\n\n\t\tdefault:\n\t\t\t// Fallback for any unhandled validation keywords\n\t\t\treturn (\n\t\t\t\tajvError.message ||\n\t\t\t\t`${ fullParam } is invalid (failed ${ ajvError.keyword } validation).`\n\t\t\t);\n\t}\n}\n\n/**\n * Validates a value against a JSON Schema.\n *\n * @param value The value to validate.\n * @param args The JSON Schema to validate against.\n * @param param Optional parameter name for error messages.\n * @return True if valid, error message string if invalid.\n */\nexport function validateValueFromSchema(\n\tvalue: any,\n\targs: Record< string, any >,\n\tparam = ''\n): true | ValidationError {\n\t// WordPress server expects schema to be an array/object\n\tif ( ! args || typeof args !== 'object' ) {\n\t\t// WordPress issues a _doing_it_wrong for invalid schema\n\t\t// Match this behavior with console.warn on client-side\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.warn( `Schema must be an object. Received ${ typeof args }.` );\n\t\t// Continue validation, treating as valid (matching server behavior)\n\t\treturn true;\n\t}\n\n\t// Type validation - WordPress REST API requires type to be set\n\tif ( ! args.type && ! args.anyOf && ! args.oneOf ) {\n\t\t// WordPress issues a _doing_it_wrong but continues\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.warn(\n\t\t\t`The \"type\" schema keyword for ${ param || 'value' } is required.`\n\t\t);\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst { default: defaultValue, ...schemaWithoutDefault } = args;\n\t\tconst validate = ajv.compile( schemaWithoutDefault );\n\t\tconst valid = validate( value === undefined ? defaultValue : value );\n\n\t\tif ( valid ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Return the first error as a simple message string\n\t\t// The API will wrap this with ability_invalid_input/output\n\t\tif ( validate.errors && validate.errors.length > 0 ) {\n\t\t\t// For anyOf/oneOf, look for the more specific error\n\t\t\tconst anyOfError = validate.errors.find(\n\t\t\t\t( e ) => e.keyword === 'anyOf' || e.keyword === 'oneOf'\n\t\t\t);\n\t\t\tif ( anyOfError ) {\n\t\t\t\treturn formatAjvError( anyOfError, param );\n\t\t\t}\n\t\t\treturn formatAjvError( validate.errors[ 0 ], param );\n\t\t}\n\n\t\treturn `${ param } is invalid.`;\n\t} catch ( error ) {\n\t\t// Handle schema compilation errors\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'Schema compilation error:', error );\n\t\treturn 'Invalid schema provided for validation.';\n\t}\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACX,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAsB,YAAY,CACjC,IAAI,GAAE,kBAAuB,GAC3B,OAAO,CAAE,OAAO,EAAE,CAAE,CAEtB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAE,IAAI,EAAE,MAAM,GAAI,OAAO,CAAE,OAAO,GAAG,IAAI,CAAE,CAE1E;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAE,eAAe,EAAE,CAAE,CAEzE;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,MAAM,GACV,OAAO,CAAE,eAAe,GAAG,IAAI,CAAE,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,eAAe,CAAE,OAAO,EAAE,OAAO,GAAI,OAAO,CAAE,IAAI,CAAE,CAEzE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,MAAM,GAAI,IAAI,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,uBAAuB,CAC5C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,mBAAmB,GACvB,OAAO,CAAE,IAAI,CAAE,CAEjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,MAAM,GAAI,IAAI,CAE9D;AA0ID;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,YAAY,GAClB,OAAO,CAAE,aAAa,CAAE,CAW1B"}
@@ -0,0 +1,41 @@
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
+ /**
11
+ * Public API functions
12
+ */
13
+ export { getAbilities, getAbility, getAbilityCategories, getAbilityCategory, executeAbility, registerAbility, unregisterAbility, registerAbilityCategory, unregisterAbilityCategory, } from './api';
14
+ /**
15
+ * The store can be used directly with @wordpress/data via selectors
16
+ * in React components with useSelect.
17
+ *
18
+ * @example
19
+ * ```js
20
+ * import { useSelect } from '@wordpress/data';
21
+ * import { store as abilitiesStore } from '@wordpress/abilities';
22
+ *
23
+ * function MyComponent() {
24
+ * const abilities = useSelect(
25
+ * (select) => select(abilitiesStore).getAbilities(),
26
+ * []
27
+ * );
28
+ * // Use abilities...
29
+ * }
30
+ * ```
31
+ */
32
+ export { store } from './store';
33
+ /**
34
+ * Type definitions
35
+ */
36
+ export type { Ability, AbilityCategory, AbilityCategoryArgs, AbilitiesState, AbilitiesQueryArgs, AbilityCallback, PermissionCallback, AbilityInput, AbilityOutput, ValidationError, } from './types';
37
+ /**
38
+ * Validation utilities
39
+ */
40
+ export { validateValueFromSchema } from './validation';
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,OAAO,EACN,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,GACzB,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;GAEG;AACH,YAAY,EACX,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,eAAe,GACf,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC"}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAW9E;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAE,SAAS,EAAE,OAAO,EAAE;;;EAKrD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,eAAe,EAAE;;;EAK/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAE,OAAO,EAAE,OAAO,IAEjC;;;CAAoB,mBAiFnC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,MAAM;;;EAK9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,mBAAmB,IAGV;;;CAAoB,mBA6DnC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,MAAM;;;EAKtD"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Store constants
3
+ */
4
+ export declare const STORE_NAME = "core/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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,mBAAmB,CAAC;AAC3C,eAAO,MAAM,WAAW,SAAS,CAAC;AAClC,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,sBAAsB,uBAAuB,CAAC;AAG3D,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AACrD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,2BAA2B,gCAAgC,CAAC"}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AASzC;;GAEG;AACH,eAAO,MAAM,KAAK,sKAKf,CAAC"}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAwEzD,UAAU,eAAe;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;;;;;;;;AA4FD,wBAGI"}
@@ -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,0 +1 @@
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/store/resolvers.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AACH,wBAAgB,YAAY,KAEZ;;;;CAA8B,mBAsB7C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAE,IAAI,EAAE,MAAM,IAExB;;;;CAA8B,mBAqB7C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,KAEpB;;;;CAA8B,mBAsB7C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAE,IAAI,EAAE,MAAM,IAEhC;;;;CAA8B,mBA4B7C"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Ability, AbilityCategory, AbilitiesQueryArgs, AbilitiesState } from '../types';
5
+ /**
6
+ * Returns all registered abilities.
7
+ * Optionally filters by query arguments.
8
+ *
9
+ * @param state Store state.
10
+ * @param args Optional query arguments to filter. Defaults to empty object.
11
+ * @return Array of abilities.
12
+ */
13
+ export declare const getAbilities: ((state: AbilitiesState, { category }?: AbilitiesQueryArgs) => Ability[]) & import("rememo").EnhancedSelector;
14
+ /**
15
+ * Returns a specific ability by name.
16
+ *
17
+ * @param state Store state.
18
+ * @param name Ability name.
19
+ * @return Ability object or undefined if not found.
20
+ */
21
+ export declare function getAbility(state: AbilitiesState, name: string): Ability | undefined;
22
+ /**
23
+ * Returns all registered ability categories.
24
+ *
25
+ * @param state Store state.
26
+ * @return Array of categories.
27
+ */
28
+ export declare const getAbilityCategories: ((state: AbilitiesState) => AbilityCategory[]) & import("rememo").EnhancedSelector;
29
+ /**
30
+ * Returns a specific ability category by slug.
31
+ *
32
+ * @param state Store state.
33
+ * @param slug Category slug.
34
+ * @return Category object or undefined if not found.
35
+ */
36
+ export declare function getAbilityCategory(state: AbilitiesState, slug: string): AbilityCategory | undefined;
37
+ //# sourceMappingURL=selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,MAAM,UAAU,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,WAEhB,cAAc,iBACP,kBAAkB,KAC9B,OAAO,EAAE,qCAaZ,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,GACV,OAAO,GAAG,SAAS,CAErB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,WACvB,cAAc,KAAI,eAAe,EAAE,qCAI5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,GACV,eAAe,GAAG,SAAS,CAE7B"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * WordPress Abilities API Types
3
+ */
4
+ /**
5
+ * Callback function for client-side abilities.
6
+ */
7
+ export type AbilityCallback = (input: AbilityInput) => AbilityOutput | Promise<AbilityOutput>;
8
+ /**
9
+ * Permission callback function for client-side abilities.
10
+ * Returns true if the ability can be executed, false otherwise.
11
+ */
12
+ export type PermissionCallback = (input?: AbilityInput) => boolean | Promise<boolean>;
13
+ /**
14
+ * Represents an ability in the WordPress Abilities API.
15
+ *
16
+ * @see WP_Ability
17
+ */
18
+ export interface Ability {
19
+ /**
20
+ * The unique name/identifier of the ability, with its namespace.
21
+ * Example: 'my-plugin/my-ability'
22
+ * @see WP_Ability::get_name()
23
+ */
24
+ name: string;
25
+ /**
26
+ * The human-readable label for the ability.
27
+ * @see WP_Ability::get_label()
28
+ */
29
+ label: string;
30
+ /**
31
+ * The detailed description of the ability.
32
+ * @see WP_Ability::get_description()
33
+ */
34
+ description: string;
35
+ /**
36
+ * The category this ability belongs to.
37
+ * Must be a valid category slug (lowercase alphanumeric with dashes).
38
+ * Example: 'data-retrieval', 'user-management'
39
+ * @see WP_Ability::get_category()
40
+ */
41
+ category: string;
42
+ /**
43
+ * JSON Schema for the ability's input parameters.
44
+ * @see WP_Ability::get_input_schema()
45
+ */
46
+ input_schema?: Record<string, any>;
47
+ /**
48
+ * JSON Schema for the ability's output format.
49
+ * @see WP_Ability::get_output_schema()
50
+ */
51
+ output_schema?: Record<string, any>;
52
+ /**
53
+ * Callback function for client-side abilities.
54
+ * If present, the ability will be executed locally in the browser.
55
+ * If not present, the ability will be executed via REST API on the server.
56
+ */
57
+ callback?: AbilityCallback;
58
+ /**
59
+ * Client Permission callback for abilities.
60
+ * Called before executing the ability to check if it's allowed.
61
+ * If it returns false, the ability execution will be denied.
62
+ */
63
+ permissionCallback?: PermissionCallback;
64
+ /**
65
+ * Metadata about the ability.
66
+ * @see WP_Ability::get_meta()
67
+ */
68
+ meta?: {
69
+ annotations?: {
70
+ readonly?: boolean | null;
71
+ destructive?: boolean | null;
72
+ idempotent?: boolean | null;
73
+ };
74
+ [key: string]: any;
75
+ };
76
+ }
77
+ /**
78
+ * The shape of the arguments for querying abilities.
79
+ */
80
+ export interface AbilitiesQueryArgs {
81
+ /**
82
+ * Optional category slug to filter abilities.
83
+ */
84
+ category?: string;
85
+ }
86
+ /**
87
+ * Represents an ability category in the WordPress Abilities API.
88
+ *
89
+ * @see WP_Ability_Category
90
+ */
91
+ export interface AbilityCategory {
92
+ /**
93
+ * The unique slug identifier for the category.
94
+ * Must be lowercase alphanumeric with dashes only.
95
+ * Example: 'data-retrieval', 'user-management'
96
+ * @see WP_Ability_Category::get_slug()
97
+ */
98
+ slug: string;
99
+ /**
100
+ * The human-readable label for the category.
101
+ * @see WP_Ability_Category::get_label()
102
+ */
103
+ label: string;
104
+ /**
105
+ * The detailed description of the category.
106
+ * @see WP_Ability_Category::get_description()
107
+ */
108
+ description: string;
109
+ /**
110
+ * Metadata about the category.
111
+ * @see WP_Ability_Category::get_meta()
112
+ */
113
+ meta?: Record<string, any>;
114
+ }
115
+ /**
116
+ * Arguments for registering an ability category.
117
+ * Matches the server-side wp_register_ability_category() $args parameter.
118
+ *
119
+ * @see wp_register_ability_category()
120
+ */
121
+ export interface AbilityCategoryArgs {
122
+ /**
123
+ * The human-readable label for the category.
124
+ */
125
+ label: string;
126
+ /**
127
+ * The detailed description of the category.
128
+ */
129
+ description: string;
130
+ /**
131
+ * Optional metadata about the category.
132
+ */
133
+ meta?: Record<string, any>;
134
+ }
135
+ /**
136
+ * The state shape for the abilities store.
137
+ */
138
+ export interface AbilitiesState {
139
+ /**
140
+ * Map of ability names to ability objects.
141
+ */
142
+ abilitiesByName: Record<string, Ability>;
143
+ /**
144
+ * Map of category slugs to category objects.
145
+ */
146
+ categoriesBySlug: Record<string, AbilityCategory>;
147
+ }
148
+ /**
149
+ * Input parameters for ability execution.
150
+ * Can be any JSON-serializable value: primitive, array, object, or null.
151
+ */
152
+ export type AbilityInput = any;
153
+ /**
154
+ * Result from ability execution.
155
+ * The actual shape depends on the ability's output schema.
156
+ */
157
+ export type AbilityOutput = any;
158
+ /**
159
+ * Validation error - just a message string.
160
+ * The Abilities API wraps this with the appropriate error code.
161
+ */
162
+ export type ValidationError = string;
163
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,KAAK,EAAE,YAAY,KACf,aAAa,GAAG,OAAO,CAAE,aAAa,CAAE,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAChC,KAAK,CAAC,EAAE,YAAY,KAChB,OAAO,GAAG,OAAO,CAAE,OAAO,CAAE,CAAC;AAElC;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACvB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,CAAC;IAErC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAE3B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC;;;OAGG;IACH,IAAI,CAAC,EAAE;QACN,WAAW,CAAC,EAAE;YACb,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;YAC1B,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;YAC7B,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;SAC5B,CAAC;QACF,CAAE,GAAG,EAAE,MAAM,GAAI,GAAG,CAAC;KACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;IAE3C;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAE,MAAM,EAAE,eAAe,CAAE,CAAC;CACpD;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC;AAEhC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Schema validation for client-side ability input and output schemas using AJV and ajv-formats.
3
+ *
4
+ * This utility provides validation for JSON Schema draft-04.
5
+ * Rules are configured to support the intersection of common rules between JSON Schema draft-04, WordPress (a subset of JSON Schema draft-04),
6
+ * and various providers like OpenAI and Anthropic.
7
+ *
8
+ * @see https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#json-schema-basics
9
+ */
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import type { ValidationError } from './types';
14
+ /**
15
+ * Validates a value against a JSON Schema.
16
+ *
17
+ * @param value The value to validate.
18
+ * @param args The JSON Schema to validate against.
19
+ * @param param Optional parameter name for error messages.
20
+ * @return True if valid, error message string if invalid.
21
+ */
22
+ export declare function validateValueFromSchema(value: any, args: Record<string, any>, param?: string): true | ValidationError;
23
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH;;GAEG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA6H/C;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,EAC3B,KAAK,SAAK,GACR,IAAI,GAAG,eAAe,CAkDxB"}