@wordpress/abilities 0.24.0 → 0.25.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.
- package/build/api.cjs +176 -122
- package/build/api.cjs.map +1 -7
- package/build/index.cjs +73 -52
- package/build/store/actions.cjs +119 -187
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +23 -47
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +36 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +102 -94
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +49 -58
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/types.cjs +4 -18
- package/build/types.cjs +4 -18
- package/build/validation.cjs +122 -137
- package/build/validation.cjs.map +1 -7
- package/build-module/api.mjs +161 -87
- package/build-module/api.mjs.map +1 -7
- package/build-module/index.mjs +2 -26
- package/build-module/store/actions.mjs +112 -167
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +13 -17
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +11 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +97 -78
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +42 -31
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/types.mjs +0 -1
- package/build-module/types.mjs +0 -1
- package/build-module/validation.mjs +101 -109
- package/build-module/validation.mjs.map +1 -7
- package/package.json +5 -5
- package/build/index.cjs.map +0 -7
- package/build/store/types.cjs.map +0 -7
- package/build/types.cjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/store/types.mjs.map +0 -7
- package/build-module/types.mjs.map +0 -7
package/build-module/api.mjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/api.ts"],
|
|
4
|
-
"sourcesContent": ["import { dispatch, select } from '@wordpress/data';\nimport { sprintf } from '@wordpress/i18n';\nimport { store } from './store';\nimport type {\n\tAbility,\n\tAbilityCategory,\n\tAbilityCategoryArgs,\n\tAbilitiesQueryArgs,\n\tAbilityInput,\n\tAbilityOutput,\n} from './types';\nimport { validateValueFromSchema } from './validation';\n\n/**\n * Get all available abilities with optional filtering.\n *\n * @param args Optional query arguments for filtering abilities.\n * @return Array of matching abilities.\n */\nexport function getAbilities( args: AbilitiesQueryArgs = {} ): Ability[] {\n\treturn select( store ).getAbilities( args );\n}\n\n/**\n * Get a specific ability by name.\n *\n * @param name The ability name.\n * @return The ability or undefined if not found.\n */\nexport function getAbility( name: string ): Ability | undefined {\n\treturn select( store ).getAbility( name );\n}\n\n/**\n * Get all available ability categories.\n *\n * @return Array of categories.\n */\nexport function getAbilityCategories(): AbilityCategory[] {\n\treturn select( store ).getAbilityCategories();\n}\n\n/**\n * Get a specific ability category by slug.\n *\n * @param slug The category slug.\n * @return The category or undefined if not found.\n */\nexport function getAbilityCategory(\n\tslug: string\n): AbilityCategory | undefined {\n\treturn select( store ).getAbilityCategory( slug );\n}\n\n/**\n * Register a client-side ability.\n *\n * Client-side abilities are executed locally in the browser and must include\n * a callback function. The ability's category must already be registered.\n *\n * @param ability The ability definition including callback.\n * @throws {Error} If the ability fails validation.\n *\n * @example\n * ```js\n * registerAbility({\n * name: 'my-plugin/navigate',\n * label: 'Navigate to URL',\n * description: 'Navigates to a URL within WordPress admin',\n * category: 'navigation',\n * input_schema: {\n * type: 'object',\n * properties: {\n * url: { type: 'string' }\n * },\n * required: ['url']\n * },\n * callback: async ({ url }) => {\n * window.location.href = url;\n * return { success: true };\n * }\n * });\n * ```\n */\nexport function registerAbility( ability: Ability ): void {\n\tdispatch( store ).registerAbility( ability );\n}\n\n/**\n * Unregister a client-side ability from the store.\n *\n * @param name The ability name to unregister.\n * @throws {Error} If the ability is server-side and cannot be unregistered.\n */\nexport function unregisterAbility( name: string ): void {\n\tdispatch( store ).unregisterAbility( name );\n}\n\n/**\n * Register a client-side ability category.\n *\n * Use this when registering client-side abilities that belong to a category\n * not already defined by the server. Client-side categories are stored\n * alongside server-side categories in the same store.\n *\n * @param slug Category slug (lowercase alphanumeric with dashes only).\n * @param args Category arguments (label, description, optional meta).\n * @throws {Error} If the category fails validation.\n *\n * @example\n * ```js\n * // Register a new category for block editor abilities\n * registerAbilityCategory('block-editor', {\n * label: 'Block Editor',\n * description: 'Abilities for interacting with the WordPress block editor'\n * });\n *\n * // Then register abilities using this category\n * registerAbility({\n * name: 'my-plugin/insert-block',\n * label: 'Insert Block',\n * description: 'Inserts a block into the editor',\n * category: 'block-editor',\n * callback: async ({ blockType }) => {\n * // Implementation\n * return { success: true };\n * }\n * });\n * ```\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n): void {\n\tdispatch( store ).registerAbilityCategory( slug, args );\n}\n\n/**\n * Unregister an ability category.\n *\n * @param slug The category slug to unregister.\n *\n * @example\n * ```js\n * unregisterAbilityCategory('block-editor');\n * ```\n */\nexport function unregisterAbilityCategory( slug: string ): void {\n\tdispatch( store ).unregisterAbilityCategory( slug );\n}\n\n/**\n * Execute an ability.\n *\n * Validates input and output against their schemas when defined. For\n * server-side abilities, input is validated on the client first to avoid\n * unnecessary network roundtrips, then both input and output are validated on\n * the server. The client also re-validates the output to ensure data\n * compatibility between server and client.\n *\n * @param name The ability name.\n * @param input Optional input parameters for the ability.\n * @return Promise resolving to the ability execution result.\n * @throws {Error} If the ability is not found, permission is denied, input or output validation fails, or execution throws.\n */\nexport async function executeAbility(\n\tname: string,\n\tinput?: AbilityInput\n): Promise< AbilityOutput > {\n\tconst ability = getAbility( name );\n\tif ( ! ability ) {\n\t\tthrow new Error( sprintf( 'Ability not found: %s', name ) );\n\t}\n\n\tif ( ! ability.callback ) {\n\t\tthrow new Error(\n\t\t\tsprintf(\n\t\t\t\t'Ability \"%s\" is missing callback. Please ensure the ability is properly registered.',\n\t\t\t\tability.name\n\t\t\t)\n\t\t);\n\t}\n\n\t// Check permission callback if defined\n\tif ( ability.permissionCallback ) {\n\t\tconst hasPermission = await ability.permissionCallback( input );\n\t\tif ( ! hasPermission ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf( 'Permission denied for ability: %s', ability.name )\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_permission_denied';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Validate input\n\tif ( ability.input_schema ) {\n\t\tconst inputValidation = validateValueFromSchema(\n\t\t\tinput,\n\t\t\tability.input_schema,\n\t\t\t'input'\n\t\t);\n\t\tif ( inputValidation !== true ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has invalid input. Reason: %2$s',\n\t\t\t\t\tability.name,\n\t\t\t\t\tinputValidation\n\t\t\t\t)\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_invalid_input';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Execute the ability\n\tlet result: AbilityOutput;\n\ttry {\n\t\tresult = await ability.callback( input );\n\t} catch ( error ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( `Error executing ability ${ ability.name }:`, error );\n\t\tthrow error;\n\t}\n\n\t// Validate output\n\tif ( ability.output_schema ) {\n\t\tconst outputValidation = validateValueFromSchema(\n\t\t\tresult,\n\t\t\tability.output_schema,\n\t\t\t'output'\n\t\t);\n\t\tif ( outputValidation !== true ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has invalid output. Reason: %2$s',\n\t\t\t\t\tability.name,\n\t\t\t\t\toutputValidation\n\t\t\t\t)\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_invalid_output';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\treturn result;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,UAAU,cAAc;AACjC,SAAS,eAAe;AACxB,SAAS,aAAa;AAStB,SAAS,+BAA+B;AAQ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oB,MAAO;AAC/B,YAAM,QAAQ,IAAI;AAAA,QACjB;AAAA,UACC;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,QACD;AAAA,MACD;AACA,MAAE,MAAe,OAAO;AACxB,YAAM;AAAA,IACP;AAAA,EACD;AAGA,MAAI;AACJ,MAAI;AACH,aAAS,MAAM,QAAQ,SAAU,KAAM;AAAA,EACxC,SAAU,OAAQ;AAEjB,YAAQ,MAAO,2BAA4B,QAAQ,IAAK,KAAK,KAAM;AACnE,UAAM;AAAA,EACP;AAGA,MAAK,QAAQ,eAAgB;AAC5B,UAAM,mBAAmB;AAAA,MACxB;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACD;AACA,QAAK,qBAAqB,MAAO;AAChC,YAAM,QAAQ,IAAI;AAAA,QACjB;AAAA,UACC;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,QACD;AAAA,MACD;AACA,MAAE,MAAe,OAAO;AACxB,YAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"api.mjs","names":[],"sources":["../src/api.ts"],"sourcesContent":["import { dispatch, select } from '@wordpress/data';\nimport { sprintf } from '@wordpress/i18n';\nimport { store } from './store';\nimport type {\n\tAbility,\n\tAbilityCategory,\n\tAbilityCategoryArgs,\n\tAbilitiesQueryArgs,\n\tAbilityInput,\n\tAbilityOutput,\n} from './types';\nimport { validateValueFromSchema } from './validation';\n\n/**\n * Get all available abilities with optional filtering.\n *\n * @param args Optional query arguments for filtering abilities.\n * @return Array of matching abilities.\n */\nexport function getAbilities( args: AbilitiesQueryArgs = {} ): Ability[] {\n\treturn select( store ).getAbilities( args );\n}\n\n/**\n * Get a specific ability by name.\n *\n * @param name The ability name.\n * @return The ability or undefined if not found.\n */\nexport function getAbility( name: string ): Ability | undefined {\n\treturn select( store ).getAbility( name );\n}\n\n/**\n * Get all available ability categories.\n *\n * @return Array of categories.\n */\nexport function getAbilityCategories(): AbilityCategory[] {\n\treturn select( store ).getAbilityCategories();\n}\n\n/**\n * Get a specific ability category by slug.\n *\n * @param slug The category slug.\n * @return The category or undefined if not found.\n */\nexport function getAbilityCategory(\n\tslug: string\n): AbilityCategory | undefined {\n\treturn select( store ).getAbilityCategory( slug );\n}\n\n/**\n * Register a client-side ability.\n *\n * Client-side abilities are executed locally in the browser and must include\n * a callback function. The ability's category must already be registered.\n *\n * @param ability The ability definition including callback.\n * @throws {Error} If the ability fails validation.\n *\n * @example\n * ```js\n * registerAbility({\n * name: 'my-plugin/navigate',\n * label: 'Navigate to URL',\n * description: 'Navigates to a URL within WordPress admin',\n * category: 'navigation',\n * input_schema: {\n * type: 'object',\n * properties: {\n * url: { type: 'string' }\n * },\n * required: ['url']\n * },\n * callback: async ({ url }) => {\n * window.location.href = url;\n * return { success: true };\n * }\n * });\n * ```\n */\nexport function registerAbility( ability: Ability ): void {\n\tdispatch( store ).registerAbility( ability );\n}\n\n/**\n * Unregister a client-side ability from the store.\n *\n * @param name The ability name to unregister.\n * @throws {Error} If the ability is server-side and cannot be unregistered.\n */\nexport function unregisterAbility( name: string ): void {\n\tdispatch( store ).unregisterAbility( name );\n}\n\n/**\n * Register a client-side ability category.\n *\n * Use this when registering client-side abilities that belong to a category\n * not already defined by the server. Client-side categories are stored\n * alongside server-side categories in the same store.\n *\n * @param slug Category slug (lowercase alphanumeric with dashes only).\n * @param args Category arguments (label, description, optional meta).\n * @throws {Error} If the category fails validation.\n *\n * @example\n * ```js\n * // Register a new category for block editor abilities\n * registerAbilityCategory('block-editor', {\n * label: 'Block Editor',\n * description: 'Abilities for interacting with the WordPress block editor'\n * });\n *\n * // Then register abilities using this category\n * registerAbility({\n * name: 'my-plugin/insert-block',\n * label: 'Insert Block',\n * description: 'Inserts a block into the editor',\n * category: 'block-editor',\n * callback: async ({ blockType }) => {\n * // Implementation\n * return { success: true };\n * }\n * });\n * ```\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n): void {\n\tdispatch( store ).registerAbilityCategory( slug, args );\n}\n\n/**\n * Unregister an ability category.\n *\n * @param slug The category slug to unregister.\n *\n * @example\n * ```js\n * unregisterAbilityCategory('block-editor');\n * ```\n */\nexport function unregisterAbilityCategory( slug: string ): void {\n\tdispatch( store ).unregisterAbilityCategory( slug );\n}\n\n/**\n * Execute an ability.\n *\n * Validates input and output against their schemas when defined. For\n * server-side abilities, input is validated on the client first to avoid\n * unnecessary network roundtrips, then both input and output are validated on\n * the server. The client also re-validates the output to ensure data\n * compatibility between server and client.\n *\n * @param name The ability name.\n * @param input Optional input parameters for the ability.\n * @return Promise resolving to the ability execution result.\n * @throws {Error} If the ability is not found, permission is denied, input or output validation fails, or execution throws.\n */\nexport async function executeAbility(\n\tname: string,\n\tinput?: AbilityInput\n): Promise< AbilityOutput > {\n\tconst ability = getAbility( name );\n\tif ( ! ability ) {\n\t\tthrow new Error( sprintf( 'Ability not found: %s', name ) );\n\t}\n\n\tif ( ! ability.callback ) {\n\t\tthrow new Error(\n\t\t\tsprintf(\n\t\t\t\t'Ability \"%s\" is missing callback. Please ensure the ability is properly registered.',\n\t\t\t\tability.name\n\t\t\t)\n\t\t);\n\t}\n\n\t// Check permission callback if defined\n\tif ( ability.permissionCallback ) {\n\t\tconst hasPermission = await ability.permissionCallback( input );\n\t\tif ( ! hasPermission ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf( 'Permission denied for ability: %s', ability.name )\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_permission_denied';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Validate input\n\tif ( ability.input_schema ) {\n\t\tconst inputValidation = validateValueFromSchema(\n\t\t\tinput,\n\t\t\tability.input_schema,\n\t\t\t'input'\n\t\t);\n\t\tif ( inputValidation !== true ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has invalid input. Reason: %2$s',\n\t\t\t\t\tability.name,\n\t\t\t\t\tinputValidation\n\t\t\t\t)\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_invalid_input';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Execute the ability\n\tlet result: AbilityOutput;\n\ttry {\n\t\tresult = await ability.callback( input );\n\t} catch ( error ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( `Error executing ability ${ ability.name }:`, error );\n\t\tthrow error;\n\t}\n\n\t// Validate output\n\tif ( ability.output_schema ) {\n\t\tconst outputValidation = validateValueFromSchema(\n\t\t\tresult,\n\t\t\tability.output_schema,\n\t\t\t'output'\n\t\t);\n\t\tif ( outputValidation !== true ) {\n\t\t\tconst error = new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has invalid output. Reason: %2$s',\n\t\t\t\t\tability.name,\n\t\t\t\t\toutputValidation\n\t\t\t\t)\n\t\t\t);\n\t\t\t( error as any ).code = 'ability_invalid_output';\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAgB,aAAc,OAA2B,CAAC,GAAe;CACxE,OAAO,OAAQ,KAAM,CAAC,CAAC,aAAc,IAAK;AAC3C;;;;;;;AAQA,SAAgB,WAAY,MAAoC;CAC/D,OAAO,OAAQ,KAAM,CAAC,CAAC,WAAY,IAAK;AACzC;;;;;;AAOA,SAAgB,uBAA0C;CACzD,OAAO,OAAQ,KAAM,CAAC,CAAC,qBAAqB;AAC7C;;;;;;;AAQA,SAAgB,mBACf,MAC8B;CAC9B,OAAO,OAAQ,KAAM,CAAC,CAAC,mBAAoB,IAAK;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAAiB,SAAyB;CACzD,SAAU,KAAM,CAAC,CAAC,gBAAiB,OAAQ;AAC5C;;;;;;;AAQA,SAAgB,kBAAmB,MAAqB;CACvD,SAAU,KAAM,CAAC,CAAC,kBAAmB,IAAK;AAC3C;;;;;;;;;;;;;;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1
|
-
|
|
2
|
-
import {
|
|
3
|
-
getAbilities,
|
|
4
|
-
getAbility,
|
|
5
|
-
getAbilityCategories,
|
|
6
|
-
getAbilityCategory,
|
|
7
|
-
executeAbility,
|
|
8
|
-
registerAbility,
|
|
9
|
-
unregisterAbility,
|
|
10
|
-
registerAbilityCategory,
|
|
11
|
-
unregisterAbilityCategory
|
|
12
|
-
} from "./api.mjs";
|
|
1
|
+
import { executeAbility, getAbilities, getAbility, getAbilityCategories, getAbilityCategory, registerAbility, registerAbilityCategory, unregisterAbility, unregisterAbilityCategory } from "./api.mjs";
|
|
13
2
|
import { store } from "./store/index.mjs";
|
|
14
3
|
import { validateValueFromSchema } from "./validation.mjs";
|
|
15
|
-
export {
|
|
16
|
-
executeAbility,
|
|
17
|
-
getAbilities,
|
|
18
|
-
getAbility,
|
|
19
|
-
getAbilityCategories,
|
|
20
|
-
getAbilityCategory,
|
|
21
|
-
registerAbility,
|
|
22
|
-
registerAbilityCategory,
|
|
23
|
-
store,
|
|
24
|
-
unregisterAbility,
|
|
25
|
-
unregisterAbilityCategory,
|
|
26
|
-
validateValueFromSchema
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=index.mjs.map
|
|
4
|
+
export { executeAbility, getAbilities, getAbility, getAbilityCategories, getAbilityCategory, registerAbility, registerAbilityCategory, store, unregisterAbility, unregisterAbilityCategory, validateValueFromSchema };
|
|
@@ -1,178 +1,123 @@
|
|
|
1
|
-
// packages/abilities/src/store/actions.ts
|
|
2
1
|
import { sprintf } from "@wordpress/i18n";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { ABILITY_NAME_PATTERN, CATEGORY_SLUG_PATTERN, REGISTER_ABILITY, REGISTER_ABILITY_CATEGORY, UNREGISTER_ABILITY, UNREGISTER_ABILITY_CATEGORY } from "./constants.mjs";
|
|
3
|
+
// packages/abilities/src/store/actions.ts
|
|
4
|
+
/**
|
|
5
|
+
* Filters annotations to only include allowed keys with non-null values.
|
|
6
|
+
*
|
|
7
|
+
* @param sourceAnnotations The source annotations object to filter.
|
|
8
|
+
* @param allowedKeys Array of annotation keys to include.
|
|
9
|
+
* @return Filtered annotations object.
|
|
10
|
+
*/
|
|
11
11
|
function filterAnnotations(sourceAnnotations, allowedKeys) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return annotations;
|
|
12
|
+
const annotations = {};
|
|
13
|
+
if (sourceAnnotations) {
|
|
14
|
+
for (const key of allowedKeys) if (sourceAnnotations[key] !== void 0) annotations[key] = sourceAnnotations[key];
|
|
15
|
+
}
|
|
16
|
+
return annotations;
|
|
21
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Registers an ability in the store.
|
|
20
|
+
*
|
|
21
|
+
* This action validates the ability before registration. If validation fails,
|
|
22
|
+
* an error will be thrown.
|
|
23
|
+
*
|
|
24
|
+
* @param ability The ability to register.
|
|
25
|
+
* @return Action object or function.
|
|
26
|
+
* @throws {Error} If validation fails.
|
|
27
|
+
*/
|
|
22
28
|
function registerAbility(ability) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
const categories = select.getAbilityCategories();
|
|
57
|
-
const existingCategory = categories.find(
|
|
58
|
-
(cat) => cat.slug === ability.category
|
|
59
|
-
);
|
|
60
|
-
if (!existingCategory) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
sprintf(
|
|
63
|
-
'Ability "%1$s" references non-existent category "%2$s". Please register the category first.',
|
|
64
|
-
ability.name,
|
|
65
|
-
ability.category
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (ability.callback && typeof ability.callback !== "function") {
|
|
70
|
-
throw new Error(
|
|
71
|
-
sprintf(
|
|
72
|
-
'Ability "%s" has an invalid callback. Callback must be a function',
|
|
73
|
-
ability.name
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
const existingAbility = select.getAbility(ability.name);
|
|
78
|
-
if (existingAbility) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
sprintf('Ability "%s" is already registered', ability.name)
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
const annotations = filterAnnotations(ability.meta?.annotations, [
|
|
84
|
-
"readonly",
|
|
85
|
-
"destructive",
|
|
86
|
-
"idempotent",
|
|
87
|
-
"serverRegistered",
|
|
88
|
-
"clientRegistered"
|
|
89
|
-
]);
|
|
90
|
-
if (!annotations.serverRegistered) {
|
|
91
|
-
annotations.clientRegistered = true;
|
|
92
|
-
}
|
|
93
|
-
const meta = {
|
|
94
|
-
...ability.meta || {},
|
|
95
|
-
annotations
|
|
96
|
-
};
|
|
97
|
-
dispatch({
|
|
98
|
-
type: REGISTER_ABILITY,
|
|
99
|
-
ability: {
|
|
100
|
-
...ability,
|
|
101
|
-
meta
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|
|
29
|
+
return ({ select, dispatch }) => {
|
|
30
|
+
if (!ability.name) throw new Error("Ability name is required");
|
|
31
|
+
if (!ABILITY_NAME_PATTERN.test(ability.name)) throw new Error("Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.");
|
|
32
|
+
if (!ability.label) throw new Error(sprintf("Ability \"%s\" must have a label", ability.name));
|
|
33
|
+
if (!ability.description) throw new Error(sprintf("Ability \"%s\" must have a description", ability.name));
|
|
34
|
+
if (!ability.category) throw new Error(sprintf("Ability \"%s\" must have a category", ability.name));
|
|
35
|
+
if (!CATEGORY_SLUG_PATTERN.test(ability.category)) throw new Error(sprintf("Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"", ability.name, ability.category));
|
|
36
|
+
if (!select.getAbilityCategories().find((cat) => cat.slug === ability.category)) throw new Error(sprintf("Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.", ability.name, ability.category));
|
|
37
|
+
if (ability.callback && typeof ability.callback !== "function") throw new Error(sprintf("Ability \"%s\" has an invalid callback. Callback must be a function", ability.name));
|
|
38
|
+
if (select.getAbility(ability.name)) throw new Error(sprintf("Ability \"%s\" is already registered", ability.name));
|
|
39
|
+
const annotations = filterAnnotations(ability.meta?.annotations, [
|
|
40
|
+
"readonly",
|
|
41
|
+
"destructive",
|
|
42
|
+
"idempotent",
|
|
43
|
+
"serverRegistered",
|
|
44
|
+
"clientRegistered"
|
|
45
|
+
]);
|
|
46
|
+
if (!annotations.serverRegistered) annotations.clientRegistered = true;
|
|
47
|
+
const meta = {
|
|
48
|
+
...ability.meta || {},
|
|
49
|
+
annotations
|
|
50
|
+
};
|
|
51
|
+
dispatch({
|
|
52
|
+
type: REGISTER_ABILITY,
|
|
53
|
+
ability: {
|
|
54
|
+
...ability,
|
|
55
|
+
meta
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
105
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns an action object used to unregister a client-side ability.
|
|
62
|
+
*
|
|
63
|
+
* @param name The name of the ability to unregister.
|
|
64
|
+
* @return Action object.
|
|
65
|
+
*/
|
|
106
66
|
function unregisterAbility(name) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
67
|
+
return {
|
|
68
|
+
type: UNREGISTER_ABILITY,
|
|
69
|
+
name
|
|
70
|
+
};
|
|
111
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Registers a client-side ability category in the store.
|
|
74
|
+
*
|
|
75
|
+
* This action validates the category before registration. If validation fails,
|
|
76
|
+
* an error will be thrown.
|
|
77
|
+
*
|
|
78
|
+
* @param slug The unique category slug identifier.
|
|
79
|
+
* @param args Category arguments (label, description, optional meta).
|
|
80
|
+
* @return Action object or function.
|
|
81
|
+
* @throws {Error} If validation fails.
|
|
82
|
+
*/
|
|
112
83
|
function registerAbilityCategory(slug, args) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
if (args.meta !== void 0 && (typeof args.meta !== "object" || Array.isArray(args.meta))) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
"The category properties should provide a valid `meta` object."
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
const annotations = filterAnnotations(args.meta?.annotations, [
|
|
144
|
-
"serverRegistered",
|
|
145
|
-
"clientRegistered"
|
|
146
|
-
]);
|
|
147
|
-
if (!annotations.serverRegistered) {
|
|
148
|
-
annotations.clientRegistered = true;
|
|
149
|
-
}
|
|
150
|
-
const meta = {
|
|
151
|
-
...args.meta || {},
|
|
152
|
-
annotations
|
|
153
|
-
};
|
|
154
|
-
const category = {
|
|
155
|
-
slug,
|
|
156
|
-
label: args.label,
|
|
157
|
-
description: args.description,
|
|
158
|
-
meta
|
|
159
|
-
};
|
|
160
|
-
dispatch({
|
|
161
|
-
type: REGISTER_ABILITY_CATEGORY,
|
|
162
|
-
category
|
|
163
|
-
});
|
|
164
|
-
};
|
|
84
|
+
return ({ select, dispatch }) => {
|
|
85
|
+
if (!slug) throw new Error("Category slug is required");
|
|
86
|
+
if (!CATEGORY_SLUG_PATTERN.test(slug)) throw new Error("Category slug must contain only lowercase alphanumeric characters and dashes.");
|
|
87
|
+
if (select.getAbilityCategory(slug)) throw new Error(sprintf("Category \"%s\" is already registered.", slug));
|
|
88
|
+
if (!args.label || typeof args.label !== "string") throw new Error("The category properties must contain a `label` string.");
|
|
89
|
+
if (!args.description || typeof args.description !== "string") throw new Error("The category properties must contain a `description` string.");
|
|
90
|
+
if (args.meta !== void 0 && (typeof args.meta !== "object" || Array.isArray(args.meta))) throw new Error("The category properties should provide a valid `meta` object.");
|
|
91
|
+
const annotations = filterAnnotations(args.meta?.annotations, ["serverRegistered", "clientRegistered"]);
|
|
92
|
+
if (!annotations.serverRegistered) annotations.clientRegistered = true;
|
|
93
|
+
const meta = {
|
|
94
|
+
...args.meta || {},
|
|
95
|
+
annotations
|
|
96
|
+
};
|
|
97
|
+
const category = {
|
|
98
|
+
slug,
|
|
99
|
+
label: args.label,
|
|
100
|
+
description: args.description,
|
|
101
|
+
meta
|
|
102
|
+
};
|
|
103
|
+
dispatch({
|
|
104
|
+
type: REGISTER_ABILITY_CATEGORY,
|
|
105
|
+
category
|
|
106
|
+
});
|
|
107
|
+
};
|
|
165
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns an action object used to unregister a client-side ability category.
|
|
111
|
+
*
|
|
112
|
+
* @param slug The slug of the category to unregister.
|
|
113
|
+
* @return Action object.
|
|
114
|
+
*/
|
|
166
115
|
function unregisterAbilityCategory(slug) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
116
|
+
return {
|
|
117
|
+
type: UNREGISTER_ABILITY_CATEGORY,
|
|
118
|
+
slug
|
|
119
|
+
};
|
|
171
120
|
}
|
|
172
|
-
export {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
unregisterAbility,
|
|
176
|
-
unregisterAbilityCategory
|
|
177
|
-
};
|
|
178
|
-
//# sourceMappingURL=actions.mjs.map
|
|
121
|
+
export { registerAbility, registerAbilityCategory, unregisterAbility, unregisterAbilityCategory };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=actions.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/actions.ts"],
|
|
4
|
-
"sourcesContent": ["import { sprintf } from '@wordpress/i18n';\nimport type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n\tABILITY_NAME_PATTERN,\n\tCATEGORY_SLUG_PATTERN,\n} from './constants';\n\ntype AbilityAnnotations = NonNullable< Ability[ 'meta' ] >[ 'annotations' ];\n\n/**\n * Filters annotations to only include allowed keys with non-null values.\n *\n * @param sourceAnnotations The source annotations object to filter.\n * @param allowedKeys Array of annotation keys to include.\n * @return Filtered annotations object.\n */\nfunction filterAnnotations< K extends keyof NonNullable< AbilityAnnotations > >(\n\tsourceAnnotations: Record< string, boolean > | undefined,\n\tallowedKeys: readonly K[]\n): NonNullable< AbilityAnnotations > {\n\tconst annotations: NonNullable< AbilityAnnotations > = {};\n\n\tif ( sourceAnnotations ) {\n\t\tfor ( const key of allowedKeys ) {\n\t\t\tif ( sourceAnnotations[ key ] !== undefined ) {\n\t\t\t\tannotations[ key ] = sourceAnnotations[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn annotations;\n}\n\n/**\n * Registers an ability in the store.\n *\n * This action validates the ability before registration. If validation fails,\n * an error will be thrown.\n *\n * @param ability The ability to register.\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbility( ability: Ability ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! ability.name ) {\n\t\t\tthrow new Error( 'Ability name is required' );\n\t\t}\n\n\t\t// Validate name format matches server implementation\n\t\tif ( ! ABILITY_NAME_PATTERN.test( ability.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.'\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.label ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a label', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.description ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a description', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.category ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a category', ability.name )\n\t\t\t);\n\t\t}\n\n\t\t// Validate category format\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( ability.category ) ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check that the category exists\n\t\tconst categories = select.getAbilityCategories();\n\t\tconst existingCategory = categories.find(\n\t\t\t( cat: AbilityCategory ) => cat.slug === ability.category\n\t\t);\n\t\tif ( ! existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Client-side abilities must have a callback\n\t\tif ( ability.callback && typeof ability.callback !== 'function' ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%s\" has an invalid callback. Callback must be a function',\n\t\t\t\t\tability.name\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check if ability is already registered\n\t\tconst existingAbility = select.getAbility( ability.name );\n\t\tif ( existingAbility ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" is already registered', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( ability.meta?.annotations, [\n\t\t\t'readonly',\n\t\t\t'destructive',\n\t\t\t'idempotent',\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( ability.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\n\t\t// All validation passed, dispatch the registration action\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY,\n\t\t\tability: {\n\t\t\t\t...ability,\n\t\t\t\tmeta,\n\t\t\t},\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability.\n *\n * @param name The name of the ability to unregister.\n * @return Action object.\n */\nexport function unregisterAbility( name: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY,\n\t\tname,\n\t};\n}\n\n/**\n * Registers a client-side ability category in the store.\n *\n * This action validates the category before registration. If validation fails,\n * an error will be thrown.\n *\n * @param slug The unique category slug identifier.\n * @param args Category arguments (label, description, optional meta).\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! slug ) {\n\t\t\tthrow new Error( 'Category slug is required' );\n\t\t}\n\n\t\t// Validate slug format matches server implementation\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( slug ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Category slug must contain only lowercase alphanumeric characters and dashes.'\n\t\t\t);\n\t\t}\n\n\t\t// Check for duplicates\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Category \"%s\" is already registered.', slug )\n\t\t\t);\n\t\t}\n\n\t\t// Validate label presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.label || typeof args.label !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `label` string.'\n\t\t\t);\n\t\t}\n\n\t\t// Validate description presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.description || typeof args.description !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `description` string.'\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\targs.meta !== undefined &&\n\t\t\t( typeof args.meta !== 'object' || Array.isArray( args.meta ) )\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties should provide a valid `meta` object.'\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( args.meta?.annotations, [\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( args.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\t\tconst category: AbilityCategory = {\n\t\t\tslug,\n\t\t\tlabel: args.label,\n\t\t\tdescription: args.description,\n\t\t\tmeta,\n\t\t};\n\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY_CATEGORY,\n\t\t\tcategory,\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability category.\n *\n * @param slug The slug of the category to unregister.\n * @return Action object.\n */\nexport function unregisterAbilityCategory( slug: string ) {\n\tretur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,YAAM,IAAI;AAAA,QACT,QAAS,wCAAwC,IAAK;AAAA,MACvD;AAAA,IACD;AAGA,QAAK,CAAE,KAAK,SAAS,OAAO,KAAK,UAAU,UAAW;AACrD,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAGA,QAAK,CAAE,KAAK,eAAe,OAAO,KAAK,gBAAgB,UAAW;AACjE,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,QACC,KAAK,SAAS,WACZ,OAAO,KAAK,SAAS,YAAY,MAAM,QAAS,KAAK,IAAK,IAC3D;AACD,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,UAAM,cAAc,kBAAmB,KAAK,MAAM,aAAa;AAAA,MAC9D;AAAA,MACA;AAAA,IACD,CAAE;AAEF,QAAK,CAAE,YAAY,kBAAmB;AACrC,kBAAY,mBAAmB;AAAA,IAChC;AAEA,UAAM,OAAO;AAAA,MACZ,GAAK,KAAK,QAAQ,CAAC;AAAA,MACnB;AAAA,IACD;AACA,UAAM,WAA4B;AAAA,MACjC;AAAA,MACA,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB;AAAA,IACD;AAEA,aAAU;AAAA,MACT,MAAM;AAAA,MACN;AAAA,IACD,CAAE;AAAA,EACH;AACD;AAQO,SAAS,0BAA2B,MAAe;AACzD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"actions.mjs","names":[],"sources":["../../src/store/actions.ts"],"sourcesContent":["import { sprintf } from '@wordpress/i18n';\nimport type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n\tABILITY_NAME_PATTERN,\n\tCATEGORY_SLUG_PATTERN,\n} from './constants';\n\ntype AbilityAnnotations = NonNullable< Ability[ 'meta' ] >[ 'annotations' ];\n\n/**\n * Filters annotations to only include allowed keys with non-null values.\n *\n * @param sourceAnnotations The source annotations object to filter.\n * @param allowedKeys Array of annotation keys to include.\n * @return Filtered annotations object.\n */\nfunction filterAnnotations< K extends keyof NonNullable< AbilityAnnotations > >(\n\tsourceAnnotations: Record< string, boolean > | undefined,\n\tallowedKeys: readonly K[]\n): NonNullable< AbilityAnnotations > {\n\tconst annotations: NonNullable< AbilityAnnotations > = {};\n\n\tif ( sourceAnnotations ) {\n\t\tfor ( const key of allowedKeys ) {\n\t\t\tif ( sourceAnnotations[ key ] !== undefined ) {\n\t\t\t\tannotations[ key ] = sourceAnnotations[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn annotations;\n}\n\n/**\n * Registers an ability in the store.\n *\n * This action validates the ability before registration. If validation fails,\n * an error will be thrown.\n *\n * @param ability The ability to register.\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbility( ability: Ability ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! ability.name ) {\n\t\t\tthrow new Error( 'Ability name is required' );\n\t\t}\n\n\t\t// Validate name format matches server implementation\n\t\tif ( ! ABILITY_NAME_PATTERN.test( ability.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.'\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.label ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a label', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.description ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a description', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.category ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a category', ability.name )\n\t\t\t);\n\t\t}\n\n\t\t// Validate category format\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( ability.category ) ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check that the category exists\n\t\tconst categories = select.getAbilityCategories();\n\t\tconst existingCategory = categories.find(\n\t\t\t( cat: AbilityCategory ) => cat.slug === ability.category\n\t\t);\n\t\tif ( ! existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Client-side abilities must have a callback\n\t\tif ( ability.callback && typeof ability.callback !== 'function' ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%s\" has an invalid callback. Callback must be a function',\n\t\t\t\t\tability.name\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check if ability is already registered\n\t\tconst existingAbility = select.getAbility( ability.name );\n\t\tif ( existingAbility ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" is already registered', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( ability.meta?.annotations, [\n\t\t\t'readonly',\n\t\t\t'destructive',\n\t\t\t'idempotent',\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( ability.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\n\t\t// All validation passed, dispatch the registration action\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY,\n\t\t\tability: {\n\t\t\t\t...ability,\n\t\t\t\tmeta,\n\t\t\t},\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability.\n *\n * @param name The name of the ability to unregister.\n * @return Action object.\n */\nexport function unregisterAbility( name: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY,\n\t\tname,\n\t};\n}\n\n/**\n * Registers a client-side ability category in the store.\n *\n * This action validates the category before registration. If validation fails,\n * an error will be thrown.\n *\n * @param slug The unique category slug identifier.\n * @param args Category arguments (label, description, optional meta).\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! slug ) {\n\t\t\tthrow new Error( 'Category slug is required' );\n\t\t}\n\n\t\t// Validate slug format matches server implementation\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( slug ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Category slug must contain only lowercase alphanumeric characters and dashes.'\n\t\t\t);\n\t\t}\n\n\t\t// Check for duplicates\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Category \"%s\" is already registered.', slug )\n\t\t\t);\n\t\t}\n\n\t\t// Validate label presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.label || typeof args.label !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `label` string.'\n\t\t\t);\n\t\t}\n\n\t\t// Validate description presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.description || typeof args.description !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `description` string.'\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\targs.meta !== undefined &&\n\t\t\t( typeof args.meta !== 'object' || Array.isArray( args.meta ) )\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties should provide a valid `meta` object.'\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( args.meta?.annotations, [\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( args.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\t\tconst category: AbilityCategory = {\n\t\t\tslug,\n\t\t\tlabel: args.label,\n\t\t\tdescription: args.description,\n\t\t\tmeta,\n\t\t};\n\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY_CATEGORY,\n\t\t\tcategory,\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability category.\n *\n * @param slug The slug of the category to unregister.\n * @return Action object.\n */\nexport function unregisterAbilityCategory( slug: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY_CATEGORY,\n\t\tslug,\n\t};\n}\n"],"mappings":";;;;;;;;;;AAoBA,SAAS,kBACR,mBACA,aACoC;CACpC,MAAM,cAAiD,CAAC;CAExD,IAAK,mBACE;OAAA,MAAM,OAAO,aAClB,IAAK,kBAAmB,SAAU,KAAA,GACjC,YAAa,OAAQ,kBAAmB;CAAA;CAI3C,OAAO;AACR;;;;;;;;;;;AAYA,SAAgB,gBAAiB,SAAmB;CAEnD,QAAS,EAAE,QAAQ,eAAgB;EAClC,IAAK,CAAE,QAAQ,MACd,MAAM,IAAI,MAAO,0BAA2B;EAI7C,IAAK,CAAE,qBAAqB,KAAM,QAAQ,IAAK,GAC9C,MAAM,IAAI,MACT,2NACD;EAGD,IAAK,CAAE,QAAQ,OACd,MAAM,IAAI,MACT,QAAS,oCAAkC,QAAQ,IAAK,CACzD;EAGD,IAAK,CAAE,QAAQ,aACd,MAAM,IAAI,MACT,QAAS,0CAAwC,QAAQ,IAAK,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E,KAAK,eAAe,OAAO,KAAK,gBAAgB,UACtD,MAAM,IAAI,MACT,8DACD;EAGD,IACC,KAAK,SAAS,KAAA,MACZ,OAAO,KAAK,SAAS,YAAY,MAAM,QAAS,KAAK,IAAK,IAE5D,MAAM,IAAI,MACT,+DACD;EAGD,MAAM,cAAc,kBAAmB,KAAK,MAAM,aAAa,CAC9D,oBACA,kBACD,CAAE;EAEF,IAAK,CAAE,YAAY,kBAClB,YAAY,mBAAmB;EAGhC,MAAM,OAAO;GACZ,GAAK,KAAK,QAAQ,CAAC;GACnB;EACD;EACA,MAAM,WAA4B;GACjC;GACA,OAAO,KAAK;GACZ,aAAa,KAAK;GAClB;EACD;EAEA,SAAU;GACT,MAAM;GACN;EACD,CAAE;CACH;AACD;;;;;;;AAQA,SAAgB,0BAA2B,MAAe;CACzD,OAAO;EACN,MAAM;EACN;CACD;AACD"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
// packages/abilities/src/store/constants.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
UNREGISTER_ABILITY,
|
|
16
|
-
UNREGISTER_ABILITY_CATEGORY
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=constants.mjs.map
|
|
2
|
+
/**
|
|
3
|
+
* Store constants
|
|
4
|
+
*/
|
|
5
|
+
const STORE_NAME = "core/abilities";
|
|
6
|
+
const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\/[a-z0-9-]+){1,3}$/;
|
|
7
|
+
const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
|
+
const REGISTER_ABILITY = "REGISTER_ABILITY";
|
|
9
|
+
const UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
|
|
10
|
+
const REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
|
|
11
|
+
const UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
|
|
12
|
+
export { ABILITY_NAME_PATTERN, CATEGORY_SLUG_PATTERN, REGISTER_ABILITY, REGISTER_ABILITY_CATEGORY, STORE_NAME, UNREGISTER_ABILITY, UNREGISTER_ABILITY_CATEGORY };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/constants.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\n\n// Validation patterns\nexport const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\\/[a-z0-9-]+){1,3}$/;\nexport const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n// Action types\nexport const REGISTER_ABILITY = 'REGISTER_ABILITY';\nexport const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';\nexport const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';\nexport const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';\n"],
|
|
5
|
-
"mappings": ";AAGO,IAAM,aAAa;AAGnB,IAAM,uBAAuB;AAC7B,IAAM,wBAAwB;AAG9B,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,4BAA4B;AAClC,IAAM,8BAA8B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/store/constants.ts"],"sourcesContent":["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\n\n// Validation patterns\nexport const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\\/[a-z0-9-]+){1,3}$/;\nexport const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n// Action types\nexport const REGISTER_ABILITY = 'REGISTER_ABILITY';\nexport const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';\nexport const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';\nexport const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';\n"],"mappings":";;;;AAGA,MAAa,aAAa;AAG1B,MAAa,uBAAuB;AACpC,MAAa,wBAAwB;AAGrC,MAAa,mBAAmB;AAChC,MAAa,qBAAqB;AAClC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// packages/abilities/src/store/index.ts
|
|
2
1
|
import { createReduxStore, register } from "@wordpress/data";
|
|
3
2
|
import reducer from "./reducer.mjs";
|
|
4
3
|
import * as actions from "./actions.mjs";
|
|
5
4
|
import * as selectors from "./selectors.mjs";
|
|
6
5
|
import { STORE_NAME } from "./constants.mjs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
// packages/abilities/src/store/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* The abilities store definition.
|
|
9
|
+
*/
|
|
10
|
+
const store = createReduxStore(STORE_NAME, {
|
|
11
|
+
reducer,
|
|
12
|
+
actions,
|
|
13
|
+
selectors
|
|
11
14
|
});
|
|
12
15
|
register(store);
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=index.mjs.map
|
|
16
|
+
export { store };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\n/**\n * The abilities store definition.\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,kBAAkB,gBAAgB;AAC3C,OAAO,aAAa;AACpB,YAAY,aAAa;AACzB,YAAY,eAAe;AAC3B,SAAS,kBAAkB;AAKpB,IAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,SAAU,KAAM;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/store/index.ts"],"sourcesContent":["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\n/**\n * The abilities store definition.\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],"mappings":";;;;;;;;;AASA,MAAa,QAAQ,iBAAkB,YAAY;CAClD;CACA;CACA;AACD,CAAE;AAEF,SAAU,KAAM"}
|