@wordpress/abilities 0.1.1-next.dc3f6d3c1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +302 -0
  4. package/build/api.js +189 -0
  5. package/build/api.js.map +7 -0
  6. package/build/index.js +53 -0
  7. package/build/index.js.map +7 -0
  8. package/build/store/actions.js +183 -0
  9. package/build/store/actions.js.map +7 -0
  10. package/build/store/constants.js +58 -0
  11. package/build/store/constants.js.map +7 -0
  12. package/build/store/index.js +77 -0
  13. package/build/store/index.js.map +7 -0
  14. package/build/store/reducer.js +126 -0
  15. package/build/store/reducer.js.map +7 -0
  16. package/build/store/resolvers.js +107 -0
  17. package/build/store/resolvers.js.map +7 -0
  18. package/build/store/selectors.js +64 -0
  19. package/build/store/selectors.js.map +7 -0
  20. package/build/store/tests/actions.test.js +792 -0
  21. package/build/store/tests/actions.test.js.map +7 -0
  22. package/build/store/tests/reducer.test.js +743 -0
  23. package/build/store/tests/reducer.test.js.map +7 -0
  24. package/build/store/tests/resolvers.test.js +520 -0
  25. package/build/store/tests/resolvers.test.js.map +7 -0
  26. package/build/store/tests/selectors.test.js +349 -0
  27. package/build/store/tests/selectors.test.js.map +7 -0
  28. package/build/tests/api.test.js +546 -0
  29. package/build/tests/api.test.js.map +7 -0
  30. package/build/tests/validation.test.js +453 -0
  31. package/build/tests/validation.test.js.map +7 -0
  32. package/build/types.js +19 -0
  33. package/build/types.js.map +7 -0
  34. package/build/validation.js +144 -0
  35. package/build/validation.js.map +7 -0
  36. package/build-module/api.js +146 -0
  37. package/build-module/api.js.map +7 -0
  38. package/build-module/index.js +28 -0
  39. package/build-module/index.js.map +7 -0
  40. package/build-module/store/actions.js +161 -0
  41. package/build-module/store/actions.js.map +7 -0
  42. package/build-module/store/constants.js +24 -0
  43. package/build-module/store/constants.js.map +7 -0
  44. package/build-module/store/index.js +47 -0
  45. package/build-module/store/index.js.map +7 -0
  46. package/build-module/store/reducer.js +112 -0
  47. package/build-module/store/reducer.js.map +7 -0
  48. package/build-module/store/resolvers.js +84 -0
  49. package/build-module/store/resolvers.js.map +7 -0
  50. package/build-module/store/selectors.js +36 -0
  51. package/build-module/store/selectors.js.map +7 -0
  52. package/build-module/store/tests/actions.test.js +804 -0
  53. package/build-module/store/tests/actions.test.js.map +7 -0
  54. package/build-module/store/tests/reducer.test.js +726 -0
  55. package/build-module/store/tests/reducer.test.js.map +7 -0
  56. package/build-module/store/tests/resolvers.test.js +523 -0
  57. package/build-module/store/tests/resolvers.test.js.map +7 -0
  58. package/build-module/store/tests/selectors.test.js +352 -0
  59. package/build-module/store/tests/selectors.test.js.map +7 -0
  60. package/build-module/tests/api.test.js +530 -0
  61. package/build-module/tests/api.test.js.map +7 -0
  62. package/build-module/tests/validation.test.js +451 -0
  63. package/build-module/tests/validation.test.js.map +7 -0
  64. package/build-module/types.js +1 -0
  65. package/build-module/types.js.map +7 -0
  66. package/build-module/validation.js +109 -0
  67. package/build-module/validation.js.map +7 -0
  68. package/build-types/api.d.ts +138 -0
  69. package/build-types/api.d.ts.map +1 -0
  70. package/build-types/index.d.ts +41 -0
  71. package/build-types/index.d.ts.map +1 -0
  72. package/build-types/store/actions.d.ts +76 -0
  73. package/build-types/store/actions.d.ts.map +1 -0
  74. package/build-types/store/constants.d.ts +14 -0
  75. package/build-types/store/constants.d.ts.map +1 -0
  76. package/build-types/store/index.d.ts +7 -0
  77. package/build-types/store/index.d.ts.map +1 -0
  78. package/build-types/store/reducer.d.ts +22 -0
  79. package/build-types/store/reducer.d.ts.map +1 -0
  80. package/build-types/store/resolvers.d.ts +47 -0
  81. package/build-types/store/resolvers.d.ts.map +1 -0
  82. package/build-types/store/selectors.d.ts +37 -0
  83. package/build-types/store/selectors.d.ts.map +1 -0
  84. package/build-types/types.d.ts +163 -0
  85. package/build-types/types.d.ts.map +1 -0
  86. package/build-types/validation.d.ts +23 -0
  87. package/build-types/validation.d.ts.map +1 -0
  88. package/package.json +52 -0
  89. package/src/api.ts +339 -0
  90. package/src/index.ts +65 -0
  91. package/src/store/actions.ts +247 -0
  92. package/src/store/constants.ts +15 -0
  93. package/src/store/index.ts +55 -0
  94. package/src/store/reducer.ts +184 -0
  95. package/src/store/resolvers.ts +151 -0
  96. package/src/store/selectors.ts +82 -0
  97. package/src/store/tests/actions.test.ts +950 -0
  98. package/src/store/tests/reducer.test.ts +861 -0
  99. package/src/store/tests/resolvers.test.ts +642 -0
  100. package/src/store/tests/selectors.test.ts +412 -0
  101. package/src/tests/api.test.ts +655 -0
  102. package/src/tests/validation.test.ts +532 -0
  103. package/src/types.ts +190 -0
  104. package/src/validation.ts +207 -0
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/abilities/src/store/actions.ts
21
+ var actions_exports = {};
22
+ __export(actions_exports, {
23
+ receiveAbilities: () => receiveAbilities,
24
+ receiveCategories: () => receiveCategories,
25
+ registerAbility: () => registerAbility,
26
+ registerAbilityCategory: () => registerAbilityCategory,
27
+ unregisterAbility: () => unregisterAbility,
28
+ unregisterAbilityCategory: () => unregisterAbilityCategory
29
+ });
30
+ module.exports = __toCommonJS(actions_exports);
31
+ var import_i18n = require("@wordpress/i18n");
32
+ var import_data = require("@wordpress/data");
33
+ var import_constants = require("./constants");
34
+ function receiveAbilities(abilities) {
35
+ return {
36
+ type: import_constants.RECEIVE_ABILITIES,
37
+ abilities
38
+ };
39
+ }
40
+ function receiveCategories(categories) {
41
+ return {
42
+ type: import_constants.RECEIVE_CATEGORIES,
43
+ categories
44
+ };
45
+ }
46
+ function registerAbility(ability) {
47
+ return async ({ select, dispatch }) => {
48
+ if (!ability.name) {
49
+ throw new Error("Ability name is required");
50
+ }
51
+ if (!/^[a-z0-9-]+\/[a-z0-9-]+$/.test(ability.name)) {
52
+ throw new Error(
53
+ '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.'
54
+ );
55
+ }
56
+ if (!ability.label) {
57
+ throw new Error(
58
+ (0, import_i18n.sprintf)('Ability "%s" must have a label', ability.name)
59
+ );
60
+ }
61
+ if (!ability.description) {
62
+ throw new Error(
63
+ (0, import_i18n.sprintf)('Ability "%s" must have a description', ability.name)
64
+ );
65
+ }
66
+ if (!ability.category) {
67
+ throw new Error(
68
+ (0, import_i18n.sprintf)('Ability "%s" must have a category', ability.name)
69
+ );
70
+ }
71
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(ability.category)) {
72
+ throw new Error(
73
+ (0, import_i18n.sprintf)(
74
+ 'Ability "%1$s" has an invalid category. Category must be lowercase alphanumeric with dashes only Got: "%2$s"',
75
+ ability.name,
76
+ ability.category
77
+ )
78
+ );
79
+ }
80
+ const categories = await (0, import_data.resolveSelect)(import_constants.STORE_NAME).getAbilityCategories();
81
+ const existingCategory = categories.find(
82
+ (cat) => cat.slug === ability.category
83
+ );
84
+ if (!existingCategory) {
85
+ throw new Error(
86
+ (0, import_i18n.sprintf)(
87
+ 'Ability "%1$s" references non-existent category "%2$s". Please register the category first.',
88
+ ability.name,
89
+ ability.category
90
+ )
91
+ );
92
+ }
93
+ if (ability.callback && typeof ability.callback !== "function") {
94
+ throw new Error(
95
+ (0, import_i18n.sprintf)(
96
+ 'Ability "%s" has an invalid callback. Callback must be a function',
97
+ ability.name
98
+ )
99
+ );
100
+ }
101
+ const existingAbility = select.getAbility(ability.name);
102
+ if (existingAbility) {
103
+ throw new Error(
104
+ (0, import_i18n.sprintf)('Ability "%s" is already registered', ability.name)
105
+ );
106
+ }
107
+ dispatch({
108
+ type: import_constants.REGISTER_ABILITY,
109
+ ability
110
+ });
111
+ };
112
+ }
113
+ function unregisterAbility(name) {
114
+ return {
115
+ type: import_constants.UNREGISTER_ABILITY,
116
+ name
117
+ };
118
+ }
119
+ function registerAbilityCategory(slug, args) {
120
+ return async ({ select, dispatch }) => {
121
+ if (!slug) {
122
+ throw new Error("Category slug is required");
123
+ }
124
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) {
125
+ throw new Error(
126
+ "Category slug must contain only lowercase alphanumeric characters and dashes."
127
+ );
128
+ }
129
+ await (0, import_data.resolveSelect)(import_constants.STORE_NAME).getAbilityCategories();
130
+ const existingCategory = select.getAbilityCategory(slug);
131
+ if (existingCategory) {
132
+ throw new Error(
133
+ (0, import_i18n.sprintf)('Category "%s" is already registered.', slug)
134
+ );
135
+ }
136
+ if (!args.label || typeof args.label !== "string") {
137
+ throw new Error(
138
+ "The category properties must contain a `label` string."
139
+ );
140
+ }
141
+ if (!args.description || typeof args.description !== "string") {
142
+ throw new Error(
143
+ "The category properties must contain a `description` string."
144
+ );
145
+ }
146
+ if (args.meta !== void 0 && (typeof args.meta !== "object" || Array.isArray(args.meta))) {
147
+ throw new Error(
148
+ "The category properties should provide a valid `meta` object."
149
+ );
150
+ }
151
+ const category = {
152
+ slug,
153
+ label: args.label,
154
+ description: args.description,
155
+ meta: {
156
+ ...args.meta || {},
157
+ // Internal implementation note: Client-registered categories will have `meta._clientRegistered` set to `true` to differentiate them from server-fetched categories.
158
+ // This is used internally by the resolver to determine whether to fetch categories from the server.
159
+ _clientRegistered: true
160
+ }
161
+ };
162
+ dispatch({
163
+ type: import_constants.REGISTER_ABILITY_CATEGORY,
164
+ category
165
+ });
166
+ };
167
+ }
168
+ function unregisterAbilityCategory(slug) {
169
+ return {
170
+ type: import_constants.UNREGISTER_ABILITY_CATEGORY,
171
+ slug
172
+ };
173
+ }
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 && (module.exports = {
176
+ receiveAbilities,
177
+ receiveCategories,
178
+ registerAbility,
179
+ registerAbilityCategory,
180
+ unregisterAbility,
181
+ unregisterAbilityCategory
182
+ });
183
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/actions.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { sprintf } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';\nimport {\n\tRECEIVE_ABILITIES,\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tRECEIVE_CATEGORIES,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n\tSTORE_NAME,\n} from './constants';\n\n/**\n * Returns an action object used to receive abilities into the store.\n *\n * @param abilities Array of abilities to store.\n * @return Action object.\n */\nexport function receiveAbilities( abilities: Ability[] ) {\n\treturn {\n\t\ttype: RECEIVE_ABILITIES,\n\t\tabilities,\n\t};\n}\n\n/**\n * Returns an action object used to receive categories into the store.\n *\n * @param categories Array of categories to store.\n * @return Action object.\n */\nexport function receiveCategories( categories: AbilityCategory[] ) {\n\treturn {\n\t\ttype: RECEIVE_CATEGORIES,\n\t\tcategories,\n\t};\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. Categories will be automatically fetched from the\n * REST API if they haven't been loaded yet.\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 async ( { 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 ( ! /^[a-z0-9-]+\\/[a-z0-9-]+$/.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 ( ! /^[a-z0-9]+(?:-[a-z0-9]+)*$/.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// Ensure categories are loaded before validating\n\t\tconst categories =\n\t\t\tawait resolveSelect( STORE_NAME ).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\t// All validation passed, dispatch the registration action\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY,\n\t\t\tability,\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. Categories will be automatically fetched from the\n * REST API if they haven't been loaded yet to check for duplicates.\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 async ( { 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 ( ! /^[a-z0-9]+(?:-[a-z0-9]+)*$/.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// Ensure categories are loaded before checking for duplicates\n\t\tawait resolveSelect( STORE_NAME ).getAbilityCategories();\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 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\t\t...( args.meta || {} ),\n\t\t\t\t// Internal implementation note: Client-registered categories will have `meta._clientRegistered` set to `true` to differentiate them from server-fetched categories.\n\t\t\t\t// This is used internally by the resolver to determine whether to fetch categories from the server.\n\t\t\t\t_clientRegistered: true,\n\t\t\t},\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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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,MACA,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB,MAAM;AAAA,QACL,GAAK,KAAK,QAAQ,CAAC;AAAA;AAAA;AAAA,QAGnB,mBAAmB;AAAA,MACpB;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
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/abilities/src/store/constants.ts
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ ENTITY_KIND: () => ENTITY_KIND,
24
+ ENTITY_NAME: () => ENTITY_NAME,
25
+ ENTITY_NAME_CATEGORIES: () => ENTITY_NAME_CATEGORIES,
26
+ RECEIVE_ABILITIES: () => RECEIVE_ABILITIES,
27
+ RECEIVE_CATEGORIES: () => RECEIVE_CATEGORIES,
28
+ REGISTER_ABILITY: () => REGISTER_ABILITY,
29
+ REGISTER_ABILITY_CATEGORY: () => REGISTER_ABILITY_CATEGORY,
30
+ STORE_NAME: () => STORE_NAME,
31
+ UNREGISTER_ABILITY: () => UNREGISTER_ABILITY,
32
+ UNREGISTER_ABILITY_CATEGORY: () => UNREGISTER_ABILITY_CATEGORY
33
+ });
34
+ module.exports = __toCommonJS(constants_exports);
35
+ var STORE_NAME = "core/abilities";
36
+ var ENTITY_KIND = "root";
37
+ var ENTITY_NAME = "abilities";
38
+ var ENTITY_NAME_CATEGORIES = "ability-categories";
39
+ var RECEIVE_ABILITIES = "RECEIVE_ABILITIES";
40
+ var REGISTER_ABILITY = "REGISTER_ABILITY";
41
+ var UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
42
+ var RECEIVE_CATEGORIES = "RECEIVE_CATEGORIES";
43
+ var REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
44
+ var UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ ENTITY_KIND,
48
+ ENTITY_NAME,
49
+ ENTITY_NAME_CATEGORIES,
50
+ RECEIVE_ABILITIES,
51
+ RECEIVE_CATEGORIES,
52
+ REGISTER_ABILITY,
53
+ REGISTER_ABILITY_CATEGORY,
54
+ STORE_NAME,
55
+ UNREGISTER_ABILITY,
56
+ UNREGISTER_ABILITY_CATEGORY
57
+ });
58
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/constants.ts"],
4
+ "sourcesContent": ["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\nexport const ENTITY_KIND = 'root';\nexport const ENTITY_NAME = 'abilities';\nexport const ENTITY_NAME_CATEGORIES = 'ability-categories';\n\n// Action types\nexport const RECEIVE_ABILITIES = 'RECEIVE_ABILITIES';\nexport const REGISTER_ABILITY = 'REGISTER_ABILITY';\nexport const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';\nexport const RECEIVE_CATEGORIES = 'RECEIVE_CATEGORIES';\nexport const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';\nexport const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,aAAa;AACnB,IAAM,cAAc;AACpB,IAAM,cAAc;AACpB,IAAM,yBAAyB;AAG/B,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAC3B,IAAM,4BAA4B;AAClC,IAAM,8BAA8B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/abilities/src/store/index.ts
31
+ var store_exports = {};
32
+ __export(store_exports, {
33
+ store: () => store
34
+ });
35
+ module.exports = __toCommonJS(store_exports);
36
+ var import_data = require("@wordpress/data");
37
+ var import_core_data = require("@wordpress/core-data");
38
+ var import_i18n = require("@wordpress/i18n");
39
+ var import_reducer = __toESM(require("./reducer"));
40
+ var actions = __toESM(require("./actions"));
41
+ var selectors = __toESM(require("./selectors"));
42
+ var resolvers = __toESM(require("./resolvers"));
43
+ var import_constants = require("./constants");
44
+ var store = (0, import_data.createReduxStore)(import_constants.STORE_NAME, {
45
+ reducer: import_reducer.default,
46
+ actions,
47
+ selectors,
48
+ resolvers
49
+ });
50
+ (0, import_data.register)(store);
51
+ (0, import_data.dispatch)(import_core_data.store).addEntities([
52
+ {
53
+ name: import_constants.ENTITY_NAME,
54
+ kind: import_constants.ENTITY_KIND,
55
+ key: "name",
56
+ baseURL: "/wp-abilities/v1/abilities",
57
+ baseURLParams: { context: "edit" },
58
+ plural: "abilities",
59
+ label: (0, import_i18n.__)("Abilities"),
60
+ supportsPagination: true
61
+ },
62
+ {
63
+ name: import_constants.ENTITY_NAME_CATEGORIES,
64
+ kind: import_constants.ENTITY_KIND,
65
+ key: "slug",
66
+ baseURL: "/wp-abilities/v1/categories",
67
+ baseURLParams: { context: "edit" },
68
+ plural: "ability-categories",
69
+ label: (0, import_i18n.__)("Ability Categories"),
70
+ supportsPagination: true
71
+ }
72
+ ]);
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ store
76
+ });
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register, dispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport * as resolvers from './resolvers';\nimport {\n\tSTORE_NAME,\n\tENTITY_KIND,\n\tENTITY_NAME,\n\tENTITY_NAME_CATEGORIES,\n} from './constants';\n\n/**\n * The abilities store definition.\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n\tresolvers,\n} );\n\nregister( store );\n\ndispatch( coreStore ).addEntities( [\n\t{\n\t\tname: ENTITY_NAME,\n\t\tkind: ENTITY_KIND,\n\t\tkey: 'name',\n\t\tbaseURL: '/wp-abilities/v1/abilities',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'abilities',\n\t\tlabel: __( 'Abilities' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: ENTITY_NAME_CATEGORIES,\n\t\tkind: ENTITY_KIND,\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp-abilities/v1/categories',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'ability-categories',\n\t\tlabel: __( 'Ability Categories' ),\n\t\tsupportsPagination: true,\n\t},\n] );\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAqD;AACrD,uBAAmC;AACnC,kBAAmB;AAKnB,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,gBAA2B;AAC3B,uBAKO;AAKA,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;AAAA,IAEhB,sBAAU,iBAAAC,KAAU,EAAE,YAAa;AAAA,EAClC;AAAA,IACC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,WAAO,gBAAI,WAAY;AAAA,IACvB,oBAAoB;AAAA,EACrB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,WAAO,gBAAI,oBAAqB;AAAA,IAChC,oBAAoB;AAAA,EACrB;AACD,CAAE;",
6
+ "names": ["reducer", "coreStore"]
7
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/abilities/src/store/reducer.ts
21
+ var reducer_exports = {};
22
+ __export(reducer_exports, {
23
+ default: () => reducer_default
24
+ });
25
+ module.exports = __toCommonJS(reducer_exports);
26
+ var import_data = require("@wordpress/data");
27
+ var import_constants = require("./constants");
28
+ var ABILITY_KEYS = [
29
+ "name",
30
+ "label",
31
+ "description",
32
+ "category",
33
+ "input_schema",
34
+ "output_schema",
35
+ "meta",
36
+ "callback",
37
+ "permissionCallback"
38
+ ];
39
+ var CATEGORY_KEYS = ["slug", "label", "description", "meta"];
40
+ function sanitizeAbility(ability) {
41
+ return Object.keys(ability).filter(
42
+ (key) => ABILITY_KEYS.includes(key) && ability[key] !== void 0
43
+ ).reduce(
44
+ (obj, key) => ({ ...obj, [key]: ability[key] }),
45
+ {}
46
+ );
47
+ }
48
+ function sanitizeCategory(category) {
49
+ return Object.keys(category).filter(
50
+ (key) => CATEGORY_KEYS.includes(key) && category[key] !== void 0
51
+ ).reduce(
52
+ (obj, key) => ({ ...obj, [key]: category[key] }),
53
+ {}
54
+ );
55
+ }
56
+ var DEFAULT_STATE = {};
57
+ function abilitiesByName(state = DEFAULT_STATE, action) {
58
+ switch (action.type) {
59
+ case import_constants.RECEIVE_ABILITIES: {
60
+ if (!action.abilities) {
61
+ return state;
62
+ }
63
+ const newState = {};
64
+ action.abilities.forEach((ability) => {
65
+ newState[ability.name] = sanitizeAbility(ability);
66
+ });
67
+ return newState;
68
+ }
69
+ case import_constants.REGISTER_ABILITY: {
70
+ if (!action.ability) {
71
+ return state;
72
+ }
73
+ return {
74
+ ...state,
75
+ [action.ability.name]: sanitizeAbility(action.ability)
76
+ };
77
+ }
78
+ case import_constants.UNREGISTER_ABILITY: {
79
+ if (!action.name || !state[action.name]) {
80
+ return state;
81
+ }
82
+ const { [action.name]: _, ...newState } = state;
83
+ return newState;
84
+ }
85
+ default:
86
+ return state;
87
+ }
88
+ }
89
+ var DEFAULT_CATEGORIES_STATE = {};
90
+ function categoriesBySlug(state = DEFAULT_CATEGORIES_STATE, action) {
91
+ switch (action.type) {
92
+ case import_constants.RECEIVE_CATEGORIES: {
93
+ if (!action.categories) {
94
+ return state;
95
+ }
96
+ const newState = {};
97
+ action.categories.forEach((category) => {
98
+ newState[category.slug] = sanitizeCategory(category);
99
+ });
100
+ return newState;
101
+ }
102
+ case import_constants.REGISTER_ABILITY_CATEGORY: {
103
+ if (!action.category) {
104
+ return state;
105
+ }
106
+ return {
107
+ ...state,
108
+ [action.category.slug]: sanitizeCategory(action.category)
109
+ };
110
+ }
111
+ case import_constants.UNREGISTER_ABILITY_CATEGORY: {
112
+ if (!action.slug || !state[action.slug]) {
113
+ return state;
114
+ }
115
+ const { [action.slug]: _, ...newState } = state;
116
+ return newState;
117
+ }
118
+ default:
119
+ return state;
120
+ }
121
+ }
122
+ var reducer_default = (0, import_data.combineReducers)({
123
+ abilitiesByName,
124
+ categoriesBySlug
125
+ });
126
+ //# sourceMappingURL=reducer.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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\tRECEIVE_ABILITIES,\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tRECEIVE_CATEGORIES,\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 AbilitiesAction {\n\ttype: string;\n\tabilities?: Ability[];\n\tability?: Ability;\n\tcategories?: AbilityCategory[];\n\tcategory?: AbilityCategory;\n\tname?: string;\n\tslug?: string;\n}\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 RECEIVE_ABILITIES: {\n\t\t\tif ( ! action.abilities ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst newState: Record< string, Ability > = {};\n\t\t\taction.abilities.forEach( ( ability ) => {\n\t\t\t\tnewState[ ability.name ] = sanitizeAbility( ability );\n\t\t\t} );\n\t\t\treturn newState;\n\t\t}\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 ( ! action.name || ! 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: AbilitiesAction\n): Record< string, AbilityCategory > {\n\tswitch ( action.type ) {\n\t\tcase RECEIVE_CATEGORIES: {\n\t\t\tif ( ! action.categories ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst newState: Record< string, AbilityCategory > = {};\n\t\t\taction.categories.forEach( ( category ) => {\n\t\t\t\tnewState[ category.slug ] = sanitizeCategory( category );\n\t\t\t} );\n\t\t\treturn newState;\n\t\t}\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 ( ! action.slug || ! 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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAMhC,uBAOO;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,S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0BAC3C,QACoC;AACpC,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,qCAAoB;AACxB,UAAK,CAAE,OAAO,YAAa;AAC1B,eAAO;AAAA,MACR;AACA,YAAM,WAA8C,CAAC;AACrD,aAAO,WAAW,QAAS,CAAE,aAAc;AAC1C,iBAAU,SAAS,IAAK,IAAI,iBAAkB,QAAS;AAAA,MACxD,CAAE;AACF,aAAO;AAAA,IACR;AAAA,IACA,KAAK,4CAA2B;AAC/B,UAAK,CAAE,OAAO,UAAW;AACxB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,OAAO,SAAS,IAAK,GAAG,iBAAkB,OAAO,QAAS;AAAA,MAC7D;AAAA,IACD;AAAA,IACA,KAAK,8CAA6B;AACjC,UAAK,CAAE,OAAO,QAAQ,CAAE,MAAO,OAAO,IAAK,GAAI;AAC9C,eAAO;AAAA,MACR;AACA,YAAM,EAAE,CAAE,OAAO,IAAK,GAAG,GAAG,GAAG,SAAS,IAAI;AAC5C,aAAO;AAAA,IACR;AAAA,IACA;AACC,aAAO;AAAA,EACT;AACD;AAEA,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AAAA,EACA;AACD,CAAE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/abilities/src/store/resolvers.ts
21
+ var resolvers_exports = {};
22
+ __export(resolvers_exports, {
23
+ getAbilities: () => getAbilities,
24
+ getAbility: () => getAbility,
25
+ getAbilityCategories: () => getAbilityCategories,
26
+ getAbilityCategory: () => getAbilityCategory
27
+ });
28
+ module.exports = __toCommonJS(resolvers_exports);
29
+ var import_core_data = require("@wordpress/core-data");
30
+ var import_constants = require("./constants");
31
+ var import_actions = require("./actions");
32
+ function getAbilities() {
33
+ return async ({ dispatch, registry, select }) => {
34
+ const existingAbilities = select.getAbilities();
35
+ const hasServerAbilities = existingAbilities.some(
36
+ (ability) => !ability.callback
37
+ );
38
+ if (hasServerAbilities) {
39
+ return;
40
+ }
41
+ const abilities = await registry.resolveSelect(import_core_data.store).getEntityRecords(import_constants.ENTITY_KIND, import_constants.ENTITY_NAME, {
42
+ per_page: -1
43
+ });
44
+ dispatch((0, import_actions.receiveAbilities)(abilities || []));
45
+ };
46
+ }
47
+ function getAbility(name) {
48
+ return async ({ dispatch, registry, select }) => {
49
+ const existingAbility = select.getAbility(name);
50
+ if (existingAbility) {
51
+ return;
52
+ }
53
+ try {
54
+ const ability = await registry.resolveSelect(import_core_data.store).getEntityRecord(import_constants.ENTITY_KIND, import_constants.ENTITY_NAME, name);
55
+ if (ability) {
56
+ await dispatch((0, import_actions.registerAbility)(ability));
57
+ }
58
+ } catch (error) {
59
+ console.debug(`Ability not found: ${name}`);
60
+ }
61
+ };
62
+ }
63
+ function getAbilityCategories() {
64
+ return async ({ dispatch, registry, select }) => {
65
+ const existingCategories = select.getAbilityCategories();
66
+ const hasServerCategories = existingCategories.some(
67
+ (category) => !category.meta?._clientRegistered
68
+ );
69
+ if (hasServerCategories) {
70
+ return;
71
+ }
72
+ const categories = await registry.resolveSelect(import_core_data.store).getEntityRecords(import_constants.ENTITY_KIND, import_constants.ENTITY_NAME_CATEGORIES, {
73
+ per_page: -1
74
+ });
75
+ dispatch((0, import_actions.receiveCategories)(categories || []));
76
+ };
77
+ }
78
+ function getAbilityCategory(slug) {
79
+ return async ({ dispatch, registry, select }) => {
80
+ const existingCategory = select.getAbilityCategory(slug);
81
+ if (existingCategory) {
82
+ return;
83
+ }
84
+ try {
85
+ const category = await registry.resolveSelect(import_core_data.store).getEntityRecord(import_constants.ENTITY_KIND, import_constants.ENTITY_NAME_CATEGORIES, slug);
86
+ if (category) {
87
+ await dispatch(
88
+ (0, import_actions.registerAbilityCategory)(category.slug, {
89
+ label: category.label,
90
+ description: category.description,
91
+ meta: category.meta
92
+ })
93
+ );
94
+ }
95
+ } catch (error) {
96
+ console.debug(`Category not found: ${slug}`);
97
+ }
98
+ };
99
+ }
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ getAbilities,
103
+ getAbility,
104
+ getAbilityCategories,
105
+ getAbilityCategory
106
+ });
107
+ //# sourceMappingURL=resolvers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/resolvers.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory } from '../types';\nimport { ENTITY_KIND, ENTITY_NAME, ENTITY_NAME_CATEGORIES } from './constants';\nimport {\n\treceiveAbilities,\n\treceiveCategories,\n\tregisterAbility,\n\tregisterAbilityCategory,\n} from './actions';\n\n/**\n * Resolver for getAbilities selector.\n * Fetches all abilities from the server.\n *\n * The resolver only fetches once (without query args filter) and stores all abilities.\n * Query args filtering handled client-side by the selector for better performance\n * and to avoid multiple API requests when filtering by different categories.\n */\nexport function getAbilities() {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\tconst existingAbilities = select.getAbilities();\n\n\t\t// Check if we have any server-side abilities (abilities without callbacks)\n\t\t// Client abilities have callbacks and are registered immediately on page load\n\t\t// We only want to skip fetching if we've already fetched server abilities\n\t\tconst hasServerAbilities = existingAbilities.some(\n\t\t\t( ability: Ability ) => ! ability.callback\n\t\t);\n\n\t\tif ( hasServerAbilities ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst abilities = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( ENTITY_KIND, ENTITY_NAME, {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\n\t\tdispatch( receiveAbilities( abilities || [] ) );\n\t};\n}\n\n/**\n * Resolver for getAbility selector.\n * Fetches a specific ability from the server if not already in store.\n *\n * @param name Ability name.\n */\nexport function getAbility( name: string ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\t// Check if ability already exists in store (i.e. client ability or already fetched)\n\t\tconst existingAbility = select.getAbility( name );\n\t\tif ( existingAbility ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst ability = await registry\n\t\t\t\t.resolveSelect( coreStore )\n\t\t\t\t.getEntityRecord( ENTITY_KIND, ENTITY_NAME, name );\n\n\t\t\tif ( ability ) {\n\t\t\t\tawait dispatch( registerAbility( ability ) );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// If ability doesn't exist or error, we'll return undefined from the selector\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.debug( `Ability not found: ${ name }` );\n\t\t}\n\t};\n}\n\n/**\n * Resolver for getAbilityCategories selector.\n * Fetches all categories from the server.\n *\n * The resolver only fetches once and stores all categories.\n */\nexport function getAbilityCategories() {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\tconst existingCategories = select.getAbilityCategories();\n\n\t\t// Check if we have any server-side categories (categories without meta._clientRegistered flag)\n\t\t// Client categories have meta._clientRegistered=true and might be registered immediately\n\t\t// We only want to skip fetching if we've already fetched server categories\n\t\tconst hasServerCategories = existingCategories.some(\n\t\t\t( category: AbilityCategory ) => ! category.meta?._clientRegistered\n\t\t);\n\n\t\tif ( hasServerCategories ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst categories = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( ENTITY_KIND, ENTITY_NAME_CATEGORIES, {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\n\t\tdispatch( receiveCategories( categories || [] ) );\n\t};\n}\n\n/**\n * Resolver for getAbilityCategory selector.\n * Fetches a specific category from the server if not already in store.\n *\n * @param slug Category slug.\n */\nexport function getAbilityCategory( slug: string ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\t// Check if category already exists in store (either client-registered or server-fetched).\n\t\t// This prevents unnecessary network requests while allowing client-side categories\n\t\t// to be retrieved immediately without hitting the API.\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst category = await registry\n\t\t\t\t.resolveSelect( coreStore )\n\t\t\t\t.getEntityRecord( ENTITY_KIND, ENTITY_NAME_CATEGORIES, slug );\n\n\t\t\tif ( category ) {\n\t\t\t\tawait dispatch(\n\t\t\t\t\tregisterAbilityCategory( category.slug, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tdescription: category.description,\n\t\t\t\t\t\tmeta: category.meta,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.debug( `Category not found: ${ slug }` );\n\t\t}\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AAMnC,uBAAiE;AACjE,qBAKO;AAUA,SAAS,eAAe;AAE9B,SAAO,OAAQ,EAAE,UAAU,UAAU,OAAO,MAAO;AAClD,UAAM,oBAAoB,OAAO,aA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