@wordpress/abilities 0.1.1-next.dc3f6d3c1.0 → 0.2.1-next.6deb34194.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 (97) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +32 -40
  3. package/build/api.js +19 -66
  4. package/build/api.js.map +3 -3
  5. package/build/index.js.map +2 -2
  6. package/build/store/actions.js +41 -31
  7. package/build/store/actions.js.map +2 -2
  8. package/build/store/constants.js +6 -15
  9. package/build/store/constants.js.map +2 -2
  10. package/build/store/index.js +1 -27
  11. package/build/store/index.js.map +3 -3
  12. package/build/store/reducer.js +2 -22
  13. package/build/store/reducer.js.map +2 -2
  14. package/build/store/selectors.js +1 -1
  15. package/build/store/selectors.js.map +2 -2
  16. package/build/store/types.js +19 -0
  17. package/build/store/types.js.map +7 -0
  18. package/build/types.js.map +1 -1
  19. package/build-module/api.js +20 -57
  20. package/build-module/api.js.map +2 -2
  21. package/build-module/index.js.map +2 -2
  22. package/build-module/store/actions.js +43 -32
  23. package/build-module/store/actions.js.map +2 -2
  24. package/build-module/store/constants.js +4 -10
  25. package/build-module/store/constants.js.map +2 -2
  26. package/build-module/store/index.js +3 -34
  27. package/build-module/store/index.js.map +2 -2
  28. package/build-module/store/reducer.js +2 -24
  29. package/build-module/store/reducer.js.map +2 -2
  30. package/build-module/store/selectors.js +1 -1
  31. package/build-module/store/selectors.js.map +2 -2
  32. package/build-module/store/types.js +1 -0
  33. package/build-module/store/types.js.map +7 -0
  34. package/build-types/api.d.ts +16 -23
  35. package/build-types/api.d.ts.map +1 -1
  36. package/build-types/index.d.ts +1 -1
  37. package/build-types/index.d.ts.map +1 -1
  38. package/build-types/store/actions.d.ts +5 -27
  39. package/build-types/store/actions.d.ts.map +1 -1
  40. package/build-types/store/constants.d.ts +2 -5
  41. package/build-types/store/constants.d.ts.map +1 -1
  42. package/build-types/store/index.d.ts +1 -1
  43. package/build-types/store/index.d.ts.map +1 -1
  44. package/build-types/store/reducer.d.ts +21 -11
  45. package/build-types/store/reducer.d.ts.map +1 -1
  46. package/build-types/store/selectors.d.ts +2 -1
  47. package/build-types/store/selectors.d.ts.map +1 -1
  48. package/build-types/store/types.d.ts +18 -0
  49. package/build-types/store/types.d.ts.map +1 -0
  50. package/build-types/types.d.ts +14 -24
  51. package/build-types/types.d.ts.map +1 -1
  52. package/package.json +15 -9
  53. package/src/api.ts +43 -123
  54. package/src/index.ts +0 -1
  55. package/src/store/actions.ts +61 -46
  56. package/src/store/constants.ts +4 -5
  57. package/src/store/index.ts +2 -34
  58. package/src/store/reducer.ts +27 -33
  59. package/src/store/selectors.ts +3 -7
  60. package/src/store/tests/actions.test.ts +100 -244
  61. package/src/store/tests/reducer.test.ts +0 -451
  62. package/src/store/tests/selectors.test.ts +1 -1
  63. package/src/store/types.ts +19 -0
  64. package/src/tests/api.test.ts +112 -158
  65. package/src/types.ts +14 -26
  66. package/build/store/resolvers.js +0 -107
  67. package/build/store/resolvers.js.map +0 -7
  68. package/build/store/tests/actions.test.js +0 -792
  69. package/build/store/tests/actions.test.js.map +0 -7
  70. package/build/store/tests/reducer.test.js +0 -743
  71. package/build/store/tests/reducer.test.js.map +0 -7
  72. package/build/store/tests/resolvers.test.js +0 -520
  73. package/build/store/tests/resolvers.test.js.map +0 -7
  74. package/build/store/tests/selectors.test.js +0 -349
  75. package/build/store/tests/selectors.test.js.map +0 -7
  76. package/build/tests/api.test.js +0 -546
  77. package/build/tests/api.test.js.map +0 -7
  78. package/build/tests/validation.test.js +0 -453
  79. package/build/tests/validation.test.js.map +0 -7
  80. package/build-module/store/resolvers.js +0 -84
  81. package/build-module/store/resolvers.js.map +0 -7
  82. package/build-module/store/tests/actions.test.js +0 -804
  83. package/build-module/store/tests/actions.test.js.map +0 -7
  84. package/build-module/store/tests/reducer.test.js +0 -726
  85. package/build-module/store/tests/reducer.test.js.map +0 -7
  86. package/build-module/store/tests/resolvers.test.js +0 -523
  87. package/build-module/store/tests/resolvers.test.js.map +0 -7
  88. package/build-module/store/tests/selectors.test.js +0 -352
  89. package/build-module/store/tests/selectors.test.js.map +0 -7
  90. package/build-module/tests/api.test.js +0 -530
  91. package/build-module/tests/api.test.js.map +0 -7
  92. package/build-module/tests/validation.test.js +0 -451
  93. package/build-module/tests/validation.test.js.map +0 -7
  94. package/build-types/store/resolvers.d.ts +0 -47
  95. package/build-types/store/resolvers.d.ts.map +0 -1
  96. package/src/store/resolvers.ts +0 -151
  97. package/src/store/tests/resolvers.test.ts +0 -642
@@ -1,107 +0,0 @@
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
@@ -1,7 +0,0 @@
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,aAAa;AAK9C,UAAM,qBAAqB,kBAAkB;AAAA,MAC5C,CAAE,YAAsB,CAAE,QAAQ;AAAA,IACnC;AAEA,QAAK,oBAAqB;AACzB;AAAA,IACD;AAEA,UAAM,YAAY,MAAM,SACtB,cAAe,iBAAAA,KAAU,EACzB,iBAAkB,8BAAa,8BAAa;AAAA,MAC5C,UAAU;AAAA,IACX,CAAE;AAEH,iBAAU,iCAAkB,aAAa,CAAC,CAAE,CAAE;AAAA,EAC/C;AACD;AAQO,SAAS,WAAY,MAAe;AAE1C,SAAO,OAAQ,EAAE,UAAU,UAAU,OAAO,MAAO;AAElD,UAAM,kBAAkB,OAAO,WAAY,IAAK;AAChD,QAAK,iBAAkB;AACtB;AAAA,IACD;AAEA,QAAI;AACH,YAAM,UAAU,MAAM,SACpB,cAAe,iBAAAA,KAAU,EACzB,gBAAiB,8BAAa,8BAAa,IAAK;AAElD,UAAK,SAAU;AACd,cAAM,aA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