@wordpress/abilities 0.2.1-next.8b30e05b0.0 → 0.2.1-next.8fd3f8831.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/README.md +32 -40
- package/build/{api.js → api.cjs} +22 -69
- package/build/api.cjs.map +7 -0
- package/build/{index.js → index.cjs} +4 -4
- package/build/{index.js.map → index.cjs.map} +2 -2
- package/build/store/{actions.js → actions.cjs} +43 -33
- package/build/store/actions.cjs.map +7 -0
- package/build/store/{constants.js → constants.cjs} +7 -16
- package/build/store/constants.cjs.map +7 -0
- package/build/store/{index.js → index.cjs} +6 -32
- package/build/store/index.cjs.map +7 -0
- package/build/store/{reducer.js → reducer.cjs} +4 -24
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/{selectors.js → selectors.cjs} +2 -2
- package/build/store/selectors.cjs.map +7 -0
- package/build/store/types.cjs +19 -0
- package/build/store/types.cjs.map +7 -0
- package/build/{types.js → types.cjs} +1 -1
- package/build/types.cjs.map +7 -0
- package/build/{validation.js → validation.cjs} +3 -3
- package/build-module/api.js +22 -59
- package/build-module/api.js.map +2 -2
- package/build-module/index.js +3 -3
- package/build-module/index.js.map +2 -2
- package/build-module/store/actions.js +44 -33
- package/build-module/store/actions.js.map +2 -2
- package/build-module/store/constants.js +4 -10
- package/build-module/store/constants.js.map +2 -2
- package/build-module/store/index.js +6 -37
- package/build-module/store/index.js.map +2 -2
- package/build-module/store/reducer.js +3 -25
- package/build-module/store/reducer.js.map +2 -2
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/store/types.js +1 -0
- package/build-module/store/types.js.map +7 -0
- package/build-types/api.d.ts +16 -23
- package/build-types/api.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +5 -27
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/constants.d.ts +2 -5
- package/build-types/store/constants.d.ts.map +1 -1
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +21 -11
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +2 -1
- package/build-types/store/selectors.d.ts.map +1 -1
- package/build-types/store/types.d.ts +18 -0
- package/build-types/store/types.d.ts.map +1 -0
- package/build-types/types.d.ts +14 -24
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -10
- package/src/api.ts +43 -123
- package/src/index.ts +0 -1
- package/src/store/actions.ts +61 -46
- package/src/store/constants.ts +4 -5
- package/src/store/index.ts +2 -34
- package/src/store/reducer.ts +27 -33
- package/src/store/selectors.ts +3 -7
- package/src/store/tests/actions.test.ts +100 -244
- package/src/store/tests/reducer.test.ts +0 -451
- package/src/store/tests/selectors.test.ts +1 -1
- package/src/store/types.ts +19 -0
- package/src/tests/api.test.ts +112 -158
- package/src/types.ts +14 -26
- package/build/api.js.map +0 -7
- package/build/store/actions.js.map +0 -7
- package/build/store/constants.js.map +0 -7
- package/build/store/index.js.map +0 -7
- package/build/store/reducer.js.map +0 -7
- package/build/store/resolvers.js +0 -107
- package/build/store/resolvers.js.map +0 -7
- package/build/store/selectors.js.map +0 -7
- package/build/types.js.map +0 -7
- package/build-module/store/resolvers.js +0 -84
- package/build-module/store/resolvers.js.map +0 -7
- package/build-types/store/resolvers.d.ts +0 -47
- package/build-types/store/resolvers.d.ts.map +0 -1
- package/src/store/resolvers.ts +0 -151
- package/src/store/tests/resolvers.test.ts +0 -642
- /package/build/{validation.js.map → validation.cjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/actions.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { sprintf } from '@wordpress/i18n';\
|
|
5
|
-
"mappings": ";AAGA,SAAS,eAAe;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\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, i.e. \"my-plugin/my-ability\". 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 = { annotations };\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 = { annotations };\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"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,eAAe;AAMxB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAWP,SAAS,kBACR,mBACA,aACoC;AACpC,QAAM,cAAiD,CAAC;AAExD,MAAK,mBAAoB;AACxB,eAAY,OAAO,aAAc;AAChC,UAAK,kBAAmB,GAAI,MAAM,QAAY;AAC7C,oBAAa,GAAI,IAAI,kBAAmB,GAAI;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAYO,SAAS,gBAAiB,SAAmB;AAEnD,SAAO,CAAE,EAAE,QAAQ,SAA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mB;AACrC,kBAAY,mBAAmB;AAAA,IAChC;AAEA,UAAM,OAAO,EAAE,YAAY;AAC3B,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
// packages/abilities/src/store/constants.ts
|
|
2
2
|
var STORE_NAME = "core/abilities";
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var ENTITY_NAME_CATEGORIES = "ability-categories";
|
|
6
|
-
var RECEIVE_ABILITIES = "RECEIVE_ABILITIES";
|
|
3
|
+
var ABILITY_NAME_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
4
|
+
var CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
7
5
|
var REGISTER_ABILITY = "REGISTER_ABILITY";
|
|
8
6
|
var UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
|
|
9
|
-
var RECEIVE_CATEGORIES = "RECEIVE_CATEGORIES";
|
|
10
7
|
var REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
|
|
11
8
|
var UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
|
|
12
9
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
ENTITY_NAME_CATEGORIES,
|
|
16
|
-
RECEIVE_ABILITIES,
|
|
17
|
-
RECEIVE_CATEGORIES,
|
|
10
|
+
ABILITY_NAME_PATTERN,
|
|
11
|
+
CATEGORY_SLUG_PATTERN,
|
|
18
12
|
REGISTER_ABILITY,
|
|
19
13
|
REGISTER_ABILITY_CATEGORY,
|
|
20
14
|
STORE_NAME,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/constants.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\
|
|
5
|
-
"mappings": ";AAGO,IAAM,aAAa;
|
|
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-]+$/;\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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,46 +1,15 @@
|
|
|
1
1
|
// packages/abilities/src/store/index.ts
|
|
2
|
-
import { createReduxStore, register
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import * as selectors from "./selectors";
|
|
8
|
-
import * as resolvers from "./resolvers";
|
|
9
|
-
import {
|
|
10
|
-
STORE_NAME,
|
|
11
|
-
ENTITY_KIND,
|
|
12
|
-
ENTITY_NAME,
|
|
13
|
-
ENTITY_NAME_CATEGORIES
|
|
14
|
-
} from "./constants";
|
|
2
|
+
import { createReduxStore, register } from "@wordpress/data";
|
|
3
|
+
import reducer from "./reducer.js";
|
|
4
|
+
import * as actions from "./actions.js";
|
|
5
|
+
import * as selectors from "./selectors.js";
|
|
6
|
+
import { STORE_NAME } from "./constants.js";
|
|
15
7
|
var store = createReduxStore(STORE_NAME, {
|
|
16
8
|
reducer,
|
|
17
9
|
actions,
|
|
18
|
-
selectors
|
|
19
|
-
resolvers
|
|
10
|
+
selectors
|
|
20
11
|
});
|
|
21
12
|
register(store);
|
|
22
|
-
dispatch(coreStore).addEntities([
|
|
23
|
-
{
|
|
24
|
-
name: ENTITY_NAME,
|
|
25
|
-
kind: ENTITY_KIND,
|
|
26
|
-
key: "name",
|
|
27
|
-
baseURL: "/wp-abilities/v1/abilities",
|
|
28
|
-
baseURLParams: { context: "edit" },
|
|
29
|
-
plural: "abilities",
|
|
30
|
-
label: __("Abilities"),
|
|
31
|
-
supportsPagination: true
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: ENTITY_NAME_CATEGORIES,
|
|
35
|
-
kind: ENTITY_KIND,
|
|
36
|
-
key: "slug",
|
|
37
|
-
baseURL: "/wp-abilities/v1/categories",
|
|
38
|
-
baseURLParams: { context: "edit" },
|
|
39
|
-
plural: "ability-categories",
|
|
40
|
-
label: __("Ability Categories"),
|
|
41
|
-
supportsPagination: true
|
|
42
|
-
}
|
|
43
|
-
]);
|
|
44
13
|
export {
|
|
45
14
|
store
|
|
46
15
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register
|
|
5
|
-
"mappings": ";AAGA,SAAS,kBAAkB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\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": ";AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// packages/abilities/src/store/reducer.ts
|
|
2
2
|
import { combineReducers } from "@wordpress/data";
|
|
3
3
|
import {
|
|
4
|
-
RECEIVE_ABILITIES,
|
|
5
4
|
REGISTER_ABILITY,
|
|
6
5
|
UNREGISTER_ABILITY,
|
|
7
|
-
RECEIVE_CATEGORIES,
|
|
8
6
|
REGISTER_ABILITY_CATEGORY,
|
|
9
7
|
UNREGISTER_ABILITY_CATEGORY
|
|
10
|
-
} from "./constants";
|
|
8
|
+
} from "./constants.js";
|
|
11
9
|
var ABILITY_KEYS = [
|
|
12
10
|
"name",
|
|
13
11
|
"label",
|
|
@@ -39,16 +37,6 @@ function sanitizeCategory(category) {
|
|
|
39
37
|
var DEFAULT_STATE = {};
|
|
40
38
|
function abilitiesByName(state = DEFAULT_STATE, action) {
|
|
41
39
|
switch (action.type) {
|
|
42
|
-
case RECEIVE_ABILITIES: {
|
|
43
|
-
if (!action.abilities) {
|
|
44
|
-
return state;
|
|
45
|
-
}
|
|
46
|
-
const newState = {};
|
|
47
|
-
action.abilities.forEach((ability) => {
|
|
48
|
-
newState[ability.name] = sanitizeAbility(ability);
|
|
49
|
-
});
|
|
50
|
-
return newState;
|
|
51
|
-
}
|
|
52
40
|
case REGISTER_ABILITY: {
|
|
53
41
|
if (!action.ability) {
|
|
54
42
|
return state;
|
|
@@ -59,7 +47,7 @@ function abilitiesByName(state = DEFAULT_STATE, action) {
|
|
|
59
47
|
};
|
|
60
48
|
}
|
|
61
49
|
case UNREGISTER_ABILITY: {
|
|
62
|
-
if (!
|
|
50
|
+
if (!state[action.name]) {
|
|
63
51
|
return state;
|
|
64
52
|
}
|
|
65
53
|
const { [action.name]: _, ...newState } = state;
|
|
@@ -72,16 +60,6 @@ function abilitiesByName(state = DEFAULT_STATE, action) {
|
|
|
72
60
|
var DEFAULT_CATEGORIES_STATE = {};
|
|
73
61
|
function categoriesBySlug(state = DEFAULT_CATEGORIES_STATE, action) {
|
|
74
62
|
switch (action.type) {
|
|
75
|
-
case RECEIVE_CATEGORIES: {
|
|
76
|
-
if (!action.categories) {
|
|
77
|
-
return state;
|
|
78
|
-
}
|
|
79
|
-
const newState = {};
|
|
80
|
-
action.categories.forEach((category) => {
|
|
81
|
-
newState[category.slug] = sanitizeCategory(category);
|
|
82
|
-
});
|
|
83
|
-
return newState;
|
|
84
|
-
}
|
|
85
63
|
case REGISTER_ABILITY_CATEGORY: {
|
|
86
64
|
if (!action.category) {
|
|
87
65
|
return state;
|
|
@@ -92,7 +70,7 @@ function categoriesBySlug(state = DEFAULT_CATEGORIES_STATE, action) {
|
|
|
92
70
|
};
|
|
93
71
|
}
|
|
94
72
|
case UNREGISTER_ABILITY_CATEGORY: {
|
|
95
|
-
if (!
|
|
73
|
+
if (!state[action.slug]) {
|
|
96
74
|
return state;
|
|
97
75
|
}
|
|
98
76
|
const { [action.slug]: _, ...newState } = state;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/reducer.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory } from '../types';\nimport {\n\
|
|
5
|
-
"mappings": ";AAGA,SAAS,uBAAuB;AAMhC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n} from './constants';\n\n/**\n * Valid keys for an Ability object.\n * Used to filter out non-standard properties from server responses.\n */\nconst ABILITY_KEYS = [\n\t'name',\n\t'label',\n\t'description',\n\t'category',\n\t'input_schema',\n\t'output_schema',\n\t'meta',\n\t'callback',\n\t'permissionCallback',\n] as const;\n\n/**\n * Valid keys for an AbilityCategory object.\n * Used to filter out non-standard properties from server responses.\n */\nconst CATEGORY_KEYS = [ 'slug', 'label', 'description', 'meta' ] as const;\n\n/**\n * Sanitizes an ability object to only include valid properties.\n * This ensures consistent shape regardless of source (server/client).\n *\n * @param ability Raw ability object that may contain extra properties.\n * @return Sanitized ability with only valid properties.\n */\nfunction sanitizeAbility( ability: any ): Ability {\n\treturn Object.keys( ability )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tABILITY_KEYS.includes( key as any ) &&\n\t\t\t\tability[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: ability[ key ] } ),\n\t\t\t{} as Ability\n\t\t);\n}\n\n/**\n * Sanitizes a category object to only include valid properties.\n * This ensures consistent shape regardless of source.\n *\n * @param category Raw category object that may contain extra properties.\n * @return Sanitized category with only valid properties.\n */\nfunction sanitizeCategory( category: any ): AbilityCategory {\n\treturn Object.keys( category )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tCATEGORY_KEYS.includes( key as any ) &&\n\t\t\t\tcategory[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: category[ key ] } ),\n\t\t\t{} as AbilityCategory\n\t\t);\n}\n\ninterface RegisterAbilityAction {\n\ttype: typeof REGISTER_ABILITY;\n\tability: Ability;\n}\n\ninterface UnregisterAbilityAction {\n\ttype: typeof UNREGISTER_ABILITY;\n\tname: string;\n}\n\ninterface RegisterAbilityCategoryAction {\n\ttype: typeof REGISTER_ABILITY_CATEGORY;\n\tcategory: AbilityCategory;\n}\n\ninterface UnregisterAbilityCategoryAction {\n\ttype: typeof UNREGISTER_ABILITY_CATEGORY;\n\tslug: string;\n}\n\ntype AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;\n\ntype AbilitiesCategoryAction =\n\t| RegisterAbilityCategoryAction\n\t| UnregisterAbilityCategoryAction;\n\nconst DEFAULT_STATE: Record< string, Ability > = {};\n\n/**\n * Reducer managing the abilities by name.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction abilitiesByName(\n\tstate: Record< string, Ability > = DEFAULT_STATE,\n\taction: AbilitiesAction\n): Record< string, Ability > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY: {\n\t\t\tif ( ! action.ability ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.ability.name ]: sanitizeAbility( action.ability ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY: {\n\t\t\tif ( ! state[ action.name ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.name ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nconst DEFAULT_CATEGORIES_STATE: Record< string, AbilityCategory > = {};\n\n/**\n * Reducer managing the categories by slug.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction categoriesBySlug(\n\tstate: Record< string, AbilityCategory > = DEFAULT_CATEGORIES_STATE,\n\taction: AbilitiesCategoryAction\n): Record< string, AbilityCategory > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! action.category ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.category.slug ]: sanitizeCategory( action.category ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! state[ action.slug ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.slug ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nexport default combineReducers( {\n\tabilitiesByName,\n\tcategoriesBySlug,\n} );\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,uBAAuB;AAMhC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAMP,IAAM,eAAe;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAMA,IAAM,gBAAgB,CAAE,QAAQ,SAAS,eAAe,MAAO;AAS/D,SAAS,gBAAiB,SAAwB;AACjD,SAAO,OAAO,KAAM,OAAQ,EAC1B;AAAA,IACA,CAAE,QACD,aAAa,SAAU,GAAW,KAClC,QAAS,GAAI,MAAM;AAAA,EACrB,EACC;AAAA,IACA,CAAE,KAAK,SAAW,EAAE,GAAG,KAAK,CAAE,GAAI,GAAG,QAAS,GAAI,EAAE;AAAA,IACpD,CAAC;AAAA,EACF;AACF;AASA,SAAS,iBAAkB,UAAiC;AAC3D,SAAO,OAAO,KAAM,QAAS,EAC3B;AAAA,IACA,CAAE,QACD,cAAc,SAAU,GAAW,KACnC,SAAU,GAAI,MAAM;AAAA,EACtB,EACC;AAAA,IACA,CAAE,KAAK,SAAW,EAAE,GAAG,KAAK,CAAE,GAAI,GAAG,SAAU,GAAI,EAAE;AAAA,IACrD,CAAC;AAAA,EACF;AACF;AA4BA,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ependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type {
|
|
5
|
-
"mappings": ";AAGA,SAAS,sBAAsB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';\nimport type { AbilitiesState } from './types';\n\n/**\n * Returns all registered abilities.\n * Optionally filters by query arguments.\n *\n * @param state Store state.\n * @param args Optional query arguments to filter. Defaults to empty object.\n * @return Array of abilities.\n */\nexport const getAbilities = createSelector(\n\t(\n\t\tstate: AbilitiesState,\n\t\t{ category }: AbilitiesQueryArgs = {}\n\t): Ability[] => {\n\t\tconst abilities = Object.values( state.abilitiesByName );\n\t\tif ( category ) {\n\t\t\treturn abilities.filter(\n\t\t\t\t( ability ) => ability.category === category\n\t\t\t);\n\t\t}\n\t\treturn abilities;\n\t},\n\t( state: AbilitiesState, { category }: AbilitiesQueryArgs = {} ) => [\n\t\tstate.abilitiesByName,\n\t\tcategory,\n\t]\n);\n\n/**\n * Returns a specific ability by name.\n *\n * @param state Store state.\n * @param name Ability name.\n * @return Ability object or undefined if not found.\n */\nexport function getAbility(\n\tstate: AbilitiesState,\n\tname: string\n): Ability | undefined {\n\treturn state.abilitiesByName[ name ];\n}\n\n/**\n * Returns all registered ability categories.\n *\n * @param state Store state.\n * @return Array of categories.\n */\nexport const getAbilityCategories = createSelector(\n\t( state: AbilitiesState ): AbilityCategory[] => {\n\t\treturn Object.values( state.categoriesBySlug );\n\t},\n\t( state: AbilitiesState ) => [ state.categoriesBySlug ]\n);\n\n/**\n * Returns a specific ability category by slug.\n *\n * @param state Store state.\n * @param slug Category slug.\n * @return Category object or undefined if not found.\n */\nexport function getAbilityCategory(\n\tstate: AbilitiesState,\n\tslug: string\n): AbilityCategory | undefined {\n\treturn state.categoriesBySlug[ slug ];\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,sBAAsB;AAgBxB,IAAM,eAAe;AAAA,EAC3B,CACC,OACA,EAAE,SAAS,IAAwB,CAAC,MACrB;AACf,UAAM,YAAY,OAAO,OAAQ,MAAM,eAAgB;AACvD,QAAK,UAAW;AACf,aAAO,UAAU;AAAA,QAChB,CAAE,YAAa,QAAQ,aAAa;AAAA,MACrC;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EACA,CAAE,OAAuB,EAAE,SAAS,IAAwB,CAAC,MAAO;AAAA,IACnE,MAAM;AAAA,IACN;AAAA,EACD;AACD;AASO,SAAS,WACf,OACA,MACsB;AACtB,SAAO,MAAM,gBAAiB,IAAK;AACpC;AAQO,IAAM,uBAAuB;AAAA,EACnC,CAAE,UAA8C;AAC/C,WAAO,OAAO,OAAQ,MAAM,gBAAiB;AAAA,EAC9C;AAAA,EACA,CAAE,UAA2B,CAAE,MAAM,gBAAiB;AACvD;AASO,SAAS,mBACf,OACA,MAC8B;AAC9B,SAAO,MAAM,iBAAkB,IAAK;AACrC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
package/build-types/api.d.ts
CHANGED
|
@@ -3,29 +3,29 @@ import type { Ability, AbilityCategory, AbilityCategoryArgs, AbilitiesQueryArgs,
|
|
|
3
3
|
* Get all available abilities with optional filtering.
|
|
4
4
|
*
|
|
5
5
|
* @param args Optional query arguments to filter. Defaults to empty object.
|
|
6
|
-
* @return
|
|
6
|
+
* @return Array of abilities.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getAbilities(args?: AbilitiesQueryArgs):
|
|
8
|
+
export declare function getAbilities(args?: AbilitiesQueryArgs): Ability[];
|
|
9
9
|
/**
|
|
10
10
|
* Get a specific ability by name.
|
|
11
11
|
*
|
|
12
12
|
* @param name The ability name.
|
|
13
|
-
* @return
|
|
13
|
+
* @return The ability or undefined if not found.
|
|
14
14
|
*/
|
|
15
|
-
export declare function getAbility(name: string):
|
|
15
|
+
export declare function getAbility(name: string): Ability | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* Get all available ability categories.
|
|
18
18
|
*
|
|
19
|
-
* @return
|
|
19
|
+
* @return Array of categories.
|
|
20
20
|
*/
|
|
21
|
-
export declare function getAbilityCategories():
|
|
21
|
+
export declare function getAbilityCategories(): AbilityCategory[];
|
|
22
22
|
/**
|
|
23
23
|
* Get a specific ability category by slug.
|
|
24
24
|
*
|
|
25
25
|
* @param slug The category slug.
|
|
26
|
-
* @return
|
|
26
|
+
* @return The category or undefined if not found.
|
|
27
27
|
*/
|
|
28
|
-
export declare function getAbilityCategory(slug: string):
|
|
28
|
+
export declare function getAbilityCategory(slug: string): AbilityCategory | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* Register a client-side ability.
|
|
31
31
|
*
|
|
@@ -33,17 +33,14 @@ export declare function getAbilityCategory(slug: string): Promise<AbilityCategor
|
|
|
33
33
|
* a callback function. The ability will be validated by the store action,
|
|
34
34
|
* and an error will be thrown if validation fails.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
* haven't been loaded yet, so you don't need to call getAbilityCategories()
|
|
38
|
-
* before registering abilities.
|
|
36
|
+
* The category must already be registered before registering abilities.
|
|
39
37
|
*
|
|
40
38
|
* @param ability The ability definition including callback.
|
|
41
|
-
* @return Promise that resolves when registration is complete.
|
|
42
39
|
* @throws {Error} If the ability fails validation.
|
|
43
40
|
*
|
|
44
41
|
* @example
|
|
45
42
|
* ```js
|
|
46
|
-
*
|
|
43
|
+
* registerAbility({
|
|
47
44
|
* name: 'my-plugin/navigate',
|
|
48
45
|
* label: 'Navigate to URL',
|
|
49
46
|
* description: 'Navigates to a URL within WordPress admin',
|
|
@@ -62,7 +59,7 @@ export declare function getAbilityCategory(slug: string): Promise<AbilityCategor
|
|
|
62
59
|
* });
|
|
63
60
|
* ```
|
|
64
61
|
*/
|
|
65
|
-
export declare function registerAbility(ability: Ability):
|
|
62
|
+
export declare function registerAbility(ability: Ability): void;
|
|
66
63
|
/**
|
|
67
64
|
* Unregister an ability from the store.
|
|
68
65
|
*
|
|
@@ -80,24 +77,20 @@ export declare function unregisterAbility(name: string): void;
|
|
|
80
77
|
* This is useful when registering client-side abilities that introduce new
|
|
81
78
|
* categories not defined by the server.
|
|
82
79
|
*
|
|
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
80
|
* @param slug Category slug (lowercase alphanumeric with dashes only).
|
|
87
81
|
* @param args Category arguments (label, description, optional meta).
|
|
88
|
-
* @return Promise that resolves when registration is complete.
|
|
89
82
|
* @throws {Error} If the category fails validation.
|
|
90
83
|
*
|
|
91
84
|
* @example
|
|
92
85
|
* ```js
|
|
93
86
|
* // Register a new category for block editor abilities
|
|
94
|
-
*
|
|
87
|
+
* registerAbilityCategory('block-editor', {
|
|
95
88
|
* label: 'Block Editor',
|
|
96
89
|
* description: 'Abilities for interacting with the WordPress block editor'
|
|
97
90
|
* });
|
|
98
91
|
*
|
|
99
92
|
* // Then register abilities using this category
|
|
100
|
-
*
|
|
93
|
+
* registerAbility({
|
|
101
94
|
* name: 'my-plugin/insert-block',
|
|
102
95
|
* label: 'Insert Block',
|
|
103
96
|
* description: 'Inserts a block into the editor',
|
|
@@ -109,7 +102,7 @@ export declare function unregisterAbility(name: string): void;
|
|
|
109
102
|
* });
|
|
110
103
|
* ```
|
|
111
104
|
*/
|
|
112
|
-
export declare function registerAbilityCategory(slug: string, args: AbilityCategoryArgs):
|
|
105
|
+
export declare function registerAbilityCategory(slug: string, args: AbilityCategoryArgs): void;
|
|
113
106
|
/**
|
|
114
107
|
* Unregister an ability category.
|
|
115
108
|
*
|
|
@@ -126,8 +119,8 @@ export declare function unregisterAbilityCategory(slug: string): void;
|
|
|
126
119
|
/**
|
|
127
120
|
* Execute an ability.
|
|
128
121
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
122
|
+
* Executes abilities with validation for client-side abilities only.
|
|
123
|
+
* Server abilities bypass validation as it's handled on the server.
|
|
131
124
|
*
|
|
132
125
|
* @param name The ability name.
|
|
133
126
|
* @param input Optional input parameters for the ability.
|
package/build-types/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACX,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAgB,YAAY,CAAE,IAAI,GAAE,kBAAuB,GAAI,OAAO,EAAE,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAE,IAAI,EAAE,MAAM,GAAI,OAAO,GAAG,SAAS,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,EAAE,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,MAAM,GACV,eAAe,GAAG,SAAS,CAE7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAE,OAAO,EAAE,OAAO,GAAI,IAAI,CAExD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,MAAM,GAAI,IAAI,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,mBAAmB,GACvB,IAAI,CAEN;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,MAAM,GAAI,IAAI,CAE9D;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,YAAY,GAClB,OAAO,CAAE,aAAa,CAAE,CA8E1B"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export { store } from './store';
|
|
|
33
33
|
/**
|
|
34
34
|
* Type definitions
|
|
35
35
|
*/
|
|
36
|
-
export type { Ability, AbilityCategory, AbilityCategoryArgs,
|
|
36
|
+
export type { Ability, AbilityCategory, AbilityCategoryArgs, AbilitiesQueryArgs, AbilityCallback, PermissionCallback, AbilityInput, AbilityOutput, ValidationError, } from './types';
|
|
37
37
|
/**
|
|
38
38
|
* Validation utilities
|
|
39
39
|
*/
|
|
@@ -1 +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,
|
|
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,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"}
|
|
@@ -1,33 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { Ability,
|
|
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
|
-
};
|
|
4
|
+
import type { Ability, AbilityCategoryArgs } from '../types';
|
|
25
5
|
/**
|
|
26
6
|
* Registers an ability in the store.
|
|
27
7
|
*
|
|
28
8
|
* This action validates the ability before registration. If validation fails,
|
|
29
|
-
* an error will be thrown.
|
|
30
|
-
* REST API if they haven't been loaded yet.
|
|
9
|
+
* an error will be thrown.
|
|
31
10
|
*
|
|
32
11
|
* @param ability The ability to register.
|
|
33
12
|
* @return Action object or function.
|
|
@@ -36,7 +15,7 @@ export declare function receiveCategories(categories: AbilityCategory[]): {
|
|
|
36
15
|
export declare function registerAbility(ability: Ability): ({ select, dispatch }: {
|
|
37
16
|
select: any;
|
|
38
17
|
dispatch: any;
|
|
39
|
-
}) =>
|
|
18
|
+
}) => void;
|
|
40
19
|
/**
|
|
41
20
|
* Returns an action object used to unregister a client-side ability.
|
|
42
21
|
*
|
|
@@ -51,8 +30,7 @@ export declare function unregisterAbility(name: string): {
|
|
|
51
30
|
* Registers a client-side ability category in the store.
|
|
52
31
|
*
|
|
53
32
|
* This action validates the category before registration. If validation fails,
|
|
54
|
-
* an error will be thrown.
|
|
55
|
-
* REST API if they haven't been loaded yet to check for duplicates.
|
|
33
|
+
* an error will be thrown.
|
|
56
34
|
*
|
|
57
35
|
* @param slug The unique category slug identifier.
|
|
58
36
|
* @param args Category arguments (label, description, optional meta).
|
|
@@ -62,7 +40,7 @@ export declare function unregisterAbility(name: string): {
|
|
|
62
40
|
export declare function registerAbilityCategory(slug: string, args: AbilityCategoryArgs): ({ select, dispatch }: {
|
|
63
41
|
select: any;
|
|
64
42
|
dispatch: any;
|
|
65
|
-
}) =>
|
|
43
|
+
}) => void;
|
|
66
44
|
/**
|
|
67
45
|
* Returns an action object used to unregister a client-side ability category.
|
|
68
46
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAmB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAmC9E;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAE,OAAO,EAAE,OAAO,IAEvC;;;CAAoB,UAiG7B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,MAAM;;;EAK9C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,mBAAmB,IAGhB;;;CAAoB,UAiE7B;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,MAAM;;;EAKtD"}
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* Store constants
|
|
3
3
|
*/
|
|
4
4
|
export declare const STORE_NAME = "core/abilities";
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const ENTITY_NAME_CATEGORIES = "ability-categories";
|
|
8
|
-
export declare const RECEIVE_ABILITIES = "RECEIVE_ABILITIES";
|
|
5
|
+
export declare const ABILITY_NAME_PATTERN: RegExp;
|
|
6
|
+
export declare const CATEGORY_SLUG_PATTERN: RegExp;
|
|
9
7
|
export declare const REGISTER_ABILITY = "REGISTER_ABILITY";
|
|
10
8
|
export declare const UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
|
|
11
|
-
export declare const RECEIVE_CATEGORIES = "RECEIVE_CATEGORIES";
|
|
12
9
|
export declare const REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
|
|
13
10
|
export declare const UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
|
|
14
11
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,mBAAmB,CAAC;AAG3C,eAAO,MAAM,oBAAoB,QAA6B,CAAC;AAC/D,eAAO,MAAM,qBAAqB,QAA+B,CAAC;AAGlE,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,2BAA2B,gCAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC;;GAEG;AACH,eAAO,MAAM,KAAK,kIAIf,CAAC"}
|
|
@@ -2,21 +2,31 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import type { Ability, AbilityCategory } from '../types';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ability
|
|
9
|
-
categories?: AbilityCategory[];
|
|
10
|
-
category?: AbilityCategory;
|
|
11
|
-
name?: string;
|
|
12
|
-
slug?: string;
|
|
5
|
+
import { REGISTER_ABILITY, UNREGISTER_ABILITY, REGISTER_ABILITY_CATEGORY, UNREGISTER_ABILITY_CATEGORY } from './constants';
|
|
6
|
+
interface RegisterAbilityAction {
|
|
7
|
+
type: typeof REGISTER_ABILITY;
|
|
8
|
+
ability: Ability;
|
|
13
9
|
}
|
|
10
|
+
interface UnregisterAbilityAction {
|
|
11
|
+
type: typeof UNREGISTER_ABILITY;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
interface RegisterAbilityCategoryAction {
|
|
15
|
+
type: typeof REGISTER_ABILITY_CATEGORY;
|
|
16
|
+
category: AbilityCategory;
|
|
17
|
+
}
|
|
18
|
+
interface UnregisterAbilityCategoryAction {
|
|
19
|
+
type: typeof UNREGISTER_ABILITY_CATEGORY;
|
|
20
|
+
slug: string;
|
|
21
|
+
}
|
|
22
|
+
type AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;
|
|
23
|
+
type AbilitiesCategoryAction = RegisterAbilityCategoryAction | UnregisterAbilityCategoryAction;
|
|
14
24
|
declare const _default: import("redux").Reducer<{
|
|
15
25
|
abilitiesByName: Record<string, Ability>;
|
|
16
26
|
categoriesBySlug: Record<string, AbilityCategory>;
|
|
17
|
-
}, AbilitiesAction, Partial<{
|
|
18
|
-
abilitiesByName:
|
|
19
|
-
categoriesBySlug:
|
|
27
|
+
}, AbilitiesAction | AbilitiesCategoryAction, Partial<{
|
|
28
|
+
abilitiesByName: never;
|
|
29
|
+
categoriesBySlug: never;
|
|
20
30
|
}>>;
|
|
21
31
|
export default _default;
|
|
22
32
|
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -1 +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;
|
|
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;AACzD,OAAO,EACN,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC3B,MAAM,aAAa,CAAC;AAgErB,UAAU,qBAAqB;IAC9B,IAAI,EAAE,OAAO,gBAAgB,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,uBAAuB;IAChC,IAAI,EAAE,OAAO,kBAAkB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACb;AAED,UAAU,6BAA6B;IACtC,IAAI,EAAE,OAAO,yBAAyB,CAAC;IACvC,QAAQ,EAAE,eAAe,CAAC;CAC1B;AAED,UAAU,+BAA+B;IACxC,IAAI,EAAE,OAAO,2BAA2B,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;CACb;AAED,KAAK,eAAe,GAAG,qBAAqB,GAAG,uBAAuB,CAAC;AAEvE,KAAK,uBAAuB,GACzB,6BAA6B,GAC7B,+BAA+B,CAAC;;;;;;;;AAwEnC,wBAGI"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { Ability, AbilityCategory, AbilitiesQueryArgs
|
|
4
|
+
import type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';
|
|
5
|
+
import type { AbilitiesState } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* Returns all registered abilities.
|
|
7
8
|
* Optionally filters by query arguments.
|