@wordpress/core-data 4.13.0 → 5.0.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/CHANGELOG.md +12 -0
- package/README.md +148 -65
- package/build/entities.js +38 -51
- package/build/entities.js.map +1 -1
- package/build/hooks/index.js +14 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-record.js +10 -6
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -0
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +5 -2
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +74 -11
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -30
- package/build/index.js.map +1 -1
- package/build/resolvers.js +59 -39
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +9 -46
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +38 -52
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +10 -6
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -0
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +4 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +70 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -5
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +59 -39
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +7 -44
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +188 -0
- package/build-types/actions.d.ts.map +1 -0
- package/build-types/batch/create-batch.d.ts +71 -0
- package/build-types/batch/create-batch.d.ts.map +1 -0
- package/build-types/batch/default-processor.d.ts +11 -0
- package/build-types/batch/default-processor.d.ts.map +1 -0
- package/build-types/batch/index.d.ts +3 -0
- package/build-types/batch/index.d.ts.map +1 -0
- package/build-types/entities.d.ts +128 -0
- package/build-types/entities.d.ts.map +1 -0
- package/build-types/entity-provider.d.ts +68 -0
- package/build-types/entity-provider.d.ts.map +1 -0
- package/build-types/entity-types/attachment.d.ts +121 -0
- package/build-types/entity-types/attachment.d.ts.map +1 -0
- package/build-types/entity-types/base-entity-records.d.ts +37 -0
- package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
- package/build-types/entity-types/comment.d.ts +82 -0
- package/build-types/entity-types/comment.d.ts.map +1 -0
- package/build-types/entity-types/helpers.d.ts +123 -0
- package/build-types/entity-types/helpers.d.ts.map +1 -0
- package/build-types/entity-types/index.d.ts +64 -0
- package/build-types/entity-types/index.d.ts.map +1 -0
- package/build-types/entity-types/menu-location.d.ts +25 -0
- package/build-types/entity-types/menu-location.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu-item.d.ts +88 -0
- package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu.d.ts +45 -0
- package/build-types/entity-types/nav-menu.d.ts.map +1 -0
- package/build-types/entity-types/page.d.ts +120 -0
- package/build-types/entity-types/page.d.ts.map +1 -0
- package/build-types/entity-types/plugin.d.ts +62 -0
- package/build-types/entity-types/plugin.d.ts.map +1 -0
- package/build-types/entity-types/post.d.ts +128 -0
- package/build-types/entity-types/post.d.ts.map +1 -0
- package/build-types/entity-types/settings.d.ts +89 -0
- package/build-types/entity-types/settings.d.ts.map +1 -0
- package/build-types/entity-types/sidebar.d.ts +55 -0
- package/build-types/entity-types/sidebar.d.ts.map +1 -0
- package/build-types/entity-types/taxonomy.d.ts +83 -0
- package/build-types/entity-types/taxonomy.d.ts.map +1 -0
- package/build-types/entity-types/theme.d.ts +206 -0
- package/build-types/entity-types/theme.d.ts.map +1 -0
- package/build-types/entity-types/type.d.ts +71 -0
- package/build-types/entity-types/type.d.ts.map +1 -0
- package/build-types/entity-types/user.d.ts +93 -0
- package/build-types/entity-types/user.d.ts.map +1 -0
- package/build-types/entity-types/widget-type.d.ts +33 -0
- package/build-types/entity-types/widget-type.d.ts.map +1 -0
- package/build-types/entity-types/widget.d.ts +59 -0
- package/build-types/entity-types/widget.d.ts.map +1 -0
- package/build-types/entity-types/wp-template-part.d.ts +80 -0
- package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
- package/build-types/entity-types/wp-template.d.ts +80 -0
- package/build-types/entity-types/wp-template.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
- package/build-types/fetch/index.d.ts +3 -0
- package/build-types/fetch/index.d.ts.map +1 -0
- package/build-types/hooks/constants.d.ts +7 -0
- package/build-types/hooks/constants.d.ts.map +1 -0
- package/build-types/hooks/index.d.ts +4 -0
- package/build-types/hooks/index.d.ts.map +1 -0
- package/build-types/hooks/memoize.d.ts +3 -0
- package/build-types/hooks/memoize.d.ts.map +1 -0
- package/build-types/hooks/use-entity-record.d.ts +124 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -0
- package/build-types/hooks/use-entity-records.d.ts +49 -0
- package/build-types/hooks/use-entity-records.d.ts.map +1 -0
- package/build-types/hooks/use-query-select.d.ts +46 -0
- package/build-types/hooks/use-query-select.d.ts.map +1 -0
- package/build-types/hooks/use-resource-permissions.d.ts +99 -0
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
- package/build-types/index.d.ts +131 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/locks/actions.d.ts +7 -0
- package/build-types/locks/actions.d.ts.map +1 -0
- package/build-types/locks/engine.d.ts +5 -0
- package/build-types/locks/engine.d.ts.map +1 -0
- package/build-types/locks/reducer.d.ts +10 -0
- package/build-types/locks/reducer.d.ts.map +1 -0
- package/build-types/locks/selectors.d.ts +5 -0
- package/build-types/locks/selectors.d.ts.map +1 -0
- package/build-types/locks/utils.d.ts +8 -0
- package/build-types/locks/utils.d.ts.map +1 -0
- package/build-types/name.d.ts +8 -0
- package/build-types/name.d.ts.map +1 -0
- package/build-types/queried-data/actions.d.ts +32 -0
- package/build-types/queried-data/actions.d.ts.map +1 -0
- package/build-types/queried-data/get-query-parts.d.ts +60 -0
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
- package/build-types/queried-data/index.d.ts +4 -0
- package/build-types/queried-data/index.d.ts.map +1 -0
- package/build-types/queried-data/reducer.d.ts +54 -0
- package/build-types/queried-data/reducer.d.ts.map +1 -0
- package/build-types/queried-data/selectors.d.ts +16 -0
- package/build-types/queried-data/selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +156 -0
- package/build-types/reducer.d.ts.map +1 -0
- package/build-types/resolvers.d.ts +75 -0
- package/build-types/resolvers.d.ts.map +1 -0
- package/build-types/selectors.d.ts +524 -0
- package/build-types/selectors.d.ts.map +1 -0
- package/build-types/types.d.ts +4 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/conservative-map-item.d.ts +12 -0
- package/build-types/utils/conservative-map-item.d.ts.map +1 -0
- package/build-types/utils/forward-resolver.d.ts +10 -0
- package/build-types/utils/forward-resolver.d.ts.map +1 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
- package/build-types/utils/if-matching-action.d.ts +14 -0
- package/build-types/utils/if-matching-action.d.ts.map +1 -0
- package/build-types/utils/index.d.ts +9 -0
- package/build-types/utils/index.d.ts.map +1 -0
- package/build-types/utils/is-raw-attribute.d.ts +10 -0
- package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
- package/build-types/utils/on-sub-key.d.ts +4 -0
- package/build-types/utils/on-sub-key.d.ts.map +1 -0
- package/build-types/utils/replace-action.d.ts +13 -0
- package/build-types/utils/replace-action.d.ts.map +1 -0
- package/build-types/utils/with-weak-map-cache.d.ts +12 -0
- package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
- package/package.json +13 -11
- package/src/entities.js +325 -0
- package/src/entity-types/attachment.ts +3 -4
- package/src/entity-types/comment.ts +3 -4
- package/src/entity-types/index.ts +31 -88
- package/src/entity-types/menu-location.ts +3 -4
- package/src/entity-types/nav-menu-item.ts +3 -4
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +3 -4
- package/src/entity-types/taxonomy.ts +3 -4
- package/src/entity-types/theme.ts +7 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +3 -4
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +3 -4
- package/src/entity-types/wp-template.ts +3 -4
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +41 -1
- package/src/hooks/test/use-resource-permissions.js +32 -36
- package/src/hooks/use-entity-record.ts +18 -6
- package/src/hooks/use-entity-records.ts +2 -0
- package/src/hooks/use-query-select.ts +4 -1
- package/src/hooks/use-resource-permissions.ts +84 -20
- package/src/index.js +0 -5
- package/src/resolvers.js +80 -45
- package/src/selectors.ts +202 -341
- package/src/test/resolvers.js +118 -4
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/entity-types/entities.js +0 -6
- package/build/entity-types/entities.js.map +0 -1
- package/build-module/entity-types/entities.js +0 -2
- package/build-module/entity-types/entities.js.map +0 -1
- package/src/entities.ts +0 -548
- package/src/entity-types/entities.ts +0 -130
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAqDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AAvEA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA2BJ,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,EAAmDC,KAAnD,CADD;;AAEAN,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,KAA3B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;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,MAA3B,CAAF,CAAN,GAAkDE,GAAF,IAC/CY,OAAO,CAACC,gBAAR,CAA0BhB,IAA1B,EAAgCC,IAAhC,EAAsCE,GAAtC,CADD;;AAEAL,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,QAA3B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Bc,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|
package/build/resolvers.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getThemeSupports = exports.getRawEntityRecord = exports.getEntityRecords = exports.getEntityRecord = exports.getEmbedPreview = exports.getEditedEntityRecord = exports.getCurrentUser = exports.getCurrentTheme = exports.getBlockPatterns = exports.getBlockPatternCategories = exports.getAutosaves = exports.getAutosave = exports.getAuthors = exports.canUserEditEntityRecord = exports.canUser = exports.__experimentalGetTemplateForLink = exports.__experimentalGetCurrentThemeGlobalStylesVariations = exports.__experimentalGetCurrentThemeBaseGlobalStyles = exports.__experimentalGetCurrentGlobalStylesId = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _changeCase = require("change-case");
|
|
11
11
|
|
|
12
12
|
var _url = require("@wordpress/url");
|
|
13
13
|
|
|
@@ -86,10 +86,7 @@ const getEntityRecord = function (kind, name) {
|
|
|
86
86
|
dispatch
|
|
87
87
|
} = _ref3;
|
|
88
88
|
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
89
|
-
const entityConfig = (
|
|
90
|
-
kind,
|
|
91
|
-
name
|
|
92
|
-
});
|
|
89
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
93
90
|
|
|
94
91
|
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
95
92
|
return;
|
|
@@ -105,7 +102,7 @@ const getEntityRecord = function (kind, name) {
|
|
|
105
102
|
// records are stored by ID reference. Thus, fields must always include
|
|
106
103
|
// the ID.
|
|
107
104
|
query = { ...query,
|
|
108
|
-
_fields:
|
|
105
|
+
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
109
106
|
};
|
|
110
107
|
} // Disable reason: While true that an early return could leave `path`
|
|
111
108
|
// unused, it's important that path is derived using the query prior to
|
|
@@ -173,10 +170,7 @@ const getEntityRecords = function (kind, name) {
|
|
|
173
170
|
dispatch
|
|
174
171
|
} = _ref4;
|
|
175
172
|
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
176
|
-
const entityConfig = (
|
|
177
|
-
kind,
|
|
178
|
-
name
|
|
179
|
-
});
|
|
173
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
180
174
|
|
|
181
175
|
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
182
176
|
return;
|
|
@@ -194,7 +188,7 @@ const getEntityRecords = function (kind, name) {
|
|
|
194
188
|
// records are stored by ID reference. Thus, fields must always include
|
|
195
189
|
// the ID.
|
|
196
190
|
query = { ...query,
|
|
197
|
-
_fields:
|
|
191
|
+
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
198
192
|
};
|
|
199
193
|
}
|
|
200
194
|
|
|
@@ -299,39 +293,50 @@ const getEmbedPreview = url => async _ref6 => {
|
|
|
299
293
|
* Checks whether the current user can perform the given action on the given
|
|
300
294
|
* REST resource.
|
|
301
295
|
*
|
|
302
|
-
* @param {string}
|
|
303
|
-
*
|
|
304
|
-
* @param {string} resource
|
|
305
|
-
* @param {?string} id
|
|
296
|
+
* @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',
|
|
297
|
+
* 'delete'.
|
|
298
|
+
* @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
|
|
299
|
+
* @param {?string} id ID of the rest resource to check.
|
|
306
300
|
*/
|
|
307
301
|
|
|
308
302
|
|
|
309
303
|
exports.getEmbedPreview = getEmbedPreview;
|
|
310
304
|
|
|
311
|
-
const canUser = (
|
|
305
|
+
const canUser = (requestedAction, resource, id) => async _ref7 => {
|
|
312
306
|
var _response$headers;
|
|
313
307
|
|
|
314
308
|
let {
|
|
315
|
-
dispatch
|
|
309
|
+
dispatch,
|
|
310
|
+
registry
|
|
316
311
|
} = _ref7;
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
312
|
+
const {
|
|
313
|
+
hasStartedResolution
|
|
314
|
+
} = registry.select(_name.STORE_NAME);
|
|
315
|
+
const resourcePath = id ? `${resource}/${id}` : resource;
|
|
316
|
+
const retrievedActions = ['create', 'read', 'update', 'delete'];
|
|
317
|
+
|
|
318
|
+
if (!retrievedActions.includes(requestedAction)) {
|
|
319
|
+
throw new Error(`'${requestedAction}' is not a valid action.`);
|
|
320
|
+
} // Prevent resolving the same resource twice.
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
for (const relatedAction of retrievedActions) {
|
|
324
|
+
if (relatedAction === requestedAction) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
324
327
|
|
|
325
|
-
|
|
326
|
-
|
|
328
|
+
const isAlreadyResolving = hasStartedResolution('canUser', [relatedAction, resource, id]);
|
|
329
|
+
|
|
330
|
+
if (isAlreadyResolving) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
327
333
|
}
|
|
328
334
|
|
|
329
|
-
const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`;
|
|
330
335
|
let response;
|
|
331
336
|
|
|
332
337
|
try {
|
|
333
338
|
response = await (0, _apiFetch.default)({
|
|
334
|
-
path
|
|
339
|
+
path: `/wp/v2/${resourcePath}`,
|
|
335
340
|
method: 'OPTIONS',
|
|
336
341
|
parse: false
|
|
337
342
|
});
|
|
@@ -345,9 +350,22 @@ const canUser = (action, resource, id) => async _ref7 => {
|
|
|
345
350
|
|
|
346
351
|
|
|
347
352
|
const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
|
|
348
|
-
const
|
|
349
|
-
const
|
|
350
|
-
|
|
353
|
+
const allowedMethods = (allowHeader === null || allowHeader === void 0 ? void 0 : allowHeader.allow) || allowHeader || '';
|
|
354
|
+
const permissions = {};
|
|
355
|
+
const methods = {
|
|
356
|
+
create: 'POST',
|
|
357
|
+
read: 'GET',
|
|
358
|
+
update: 'PUT',
|
|
359
|
+
delete: 'DELETE'
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
for (const [actionName, methodName] of Object.entries(methods)) {
|
|
363
|
+
permissions[actionName] = allowedMethods.includes(methodName);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
for (const action of retrievedActions) {
|
|
367
|
+
dispatch.receiveUserPermission(`${action}/${resourcePath}`, permissions[action]);
|
|
368
|
+
}
|
|
351
369
|
};
|
|
352
370
|
/**
|
|
353
371
|
* Checks whether the current user can perform the given action on the given
|
|
@@ -366,10 +384,7 @@ const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
|
|
|
366
384
|
dispatch
|
|
367
385
|
} = _ref8;
|
|
368
386
|
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
369
|
-
const entityConfig = (
|
|
370
|
-
kind,
|
|
371
|
-
name
|
|
372
|
-
});
|
|
387
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
373
388
|
|
|
374
389
|
if (!entityConfig) {
|
|
375
390
|
return;
|
|
@@ -475,6 +490,8 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
|
475
490
|
};
|
|
476
491
|
|
|
477
492
|
const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
493
|
+
var _activeThemes$, _activeThemes$$_links, _activeThemes$$_links2, _activeThemes$$_links3;
|
|
494
|
+
|
|
478
495
|
let {
|
|
479
496
|
dispatch,
|
|
480
497
|
resolveSelect
|
|
@@ -482,7 +499,7 @@ const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
|
482
499
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
483
500
|
status: 'active'
|
|
484
501
|
});
|
|
485
|
-
const globalStylesURL =
|
|
502
|
+
const globalStylesURL = activeThemes === null || activeThemes === void 0 ? void 0 : (_activeThemes$ = activeThemes[0]) === null || _activeThemes$ === void 0 ? void 0 : (_activeThemes$$_links = _activeThemes$._links) === null || _activeThemes$$_links === void 0 ? void 0 : (_activeThemes$$_links2 = _activeThemes$$_links['wp:user-global-styles']) === null || _activeThemes$$_links2 === void 0 ? void 0 : (_activeThemes$$_links3 = _activeThemes$$_links2[0]) === null || _activeThemes$$_links3 === void 0 ? void 0 : _activeThemes$$_links3.href;
|
|
486
503
|
|
|
487
504
|
if (globalStylesURL) {
|
|
488
505
|
const globalStylesObject = await (0, _apiFetch.default)({
|
|
@@ -532,7 +549,10 @@ const getBlockPatterns = () => async _ref16 => {
|
|
|
532
549
|
const restPatterns = await (0, _apiFetch.default)({
|
|
533
550
|
path: '/wp/v2/block-patterns/patterns'
|
|
534
551
|
});
|
|
535
|
-
const patterns =
|
|
552
|
+
const patterns = restPatterns === null || restPatterns === void 0 ? void 0 : restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(_ref17 => {
|
|
553
|
+
let [key, value] = _ref17;
|
|
554
|
+
return [(0, _changeCase.camelCase)(key), value];
|
|
555
|
+
})));
|
|
536
556
|
dispatch({
|
|
537
557
|
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
538
558
|
patterns
|
|
@@ -541,10 +561,10 @@ const getBlockPatterns = () => async _ref16 => {
|
|
|
541
561
|
|
|
542
562
|
exports.getBlockPatterns = getBlockPatterns;
|
|
543
563
|
|
|
544
|
-
const getBlockPatternCategories = () => async
|
|
564
|
+
const getBlockPatternCategories = () => async _ref18 => {
|
|
545
565
|
let {
|
|
546
566
|
dispatch
|
|
547
|
-
} =
|
|
567
|
+
} = _ref18;
|
|
548
568
|
const categories = await (0, _apiFetch.default)({
|
|
549
569
|
path: '/wp/v2/block-patterns/categories'
|
|
550
570
|
});
|
package/build/resolvers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","DEFAULT_ENTITY_KEY","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","error","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","get","Boolean","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getBlockPatterns","restPatterns","patterns","pattern","value","getBlockPatternCategories","categories"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GACpBC,KAAF,IACA,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AACzB,QAAMC,IAAI,GAAG,uBACZ,wCADY,EAEZF,KAFY,CAAb;AAIA,QAAM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AAAF,GAAkB;AACzB,QAAMsH,YAAY,GAAG,MAAM,uBAAU;AACpCrH,IAAAA,IAAI,EAAE;AAD8B,GAAV,CAA3B;AAGA,QAAMsH,QAAQ,GAAG,iBAAKD,YAAL,EAAqBE,OAAF,IACnC,qBAASA,OAAT,EAAkB,CAAEC,KAAF,EAAS/G,GAAT,KAAkB,uBAAWA,GAAX,CAApC,CADgB,CAAjB;AAGAV,EAAAA,QAAQ,CAAE;AAAE6C,IAAAA,IAAI,EAAE,wBAAR;AAAkC0E,IAAAA;AAAlC,GAAF,CAAR;AACA,CAVK;;;;AAYA,MAAMG,yBAAyB,GACrC,MACA,gBAA0B;AAAA,MAAlB;AAAE1H,IAAAA;AAAF,GAAkB;AACzB,QAAM2H,UAAU,GAAG,MAAM,uBAAU;AAClC1H,IAAAA,IAAI,EAAE;AAD4B,GAAV,CAAzB;AAGAD,EAAAA,QAAQ,CAAE;AAAE6C,IAAAA,IAAI,EAAE,kCAAR;AAA4C8E,IAAAA;AAA5C,GAAF,CAAR;AACA,CAPK","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase, find, get, includes, map, mapKeys, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: uniq( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ).join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Disable reason: While true that an early return could leave `path`\n\t\t\t// unused, it's important that path is derived using the query prior to\n\t\t\t// additional query modifications in the condition below, since those\n\t\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t\t// for how the request is made to the REST API.\n\n\t\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.baseURL + ( key ? '/' + key : '' ),\n\t\t\t\t{\n\t\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t\t...query,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( query !== undefined ) {\n\t\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\t\tif ( hasRecords ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst record = await apiFetch( { path } );\n\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object. If requesting specific fields, fields\n * must always include the ID.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: uniq( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ).join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( entityConfig.baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitely set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fullfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t\t// When requesting all fields, the list of results can be used to\n\t\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch ( error ) {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( action, resource, id ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst methods = {\n\t\t\tcreate: 'POST',\n\t\t\tread: 'GET',\n\t\t\tupdate: 'PUT',\n\t\t\tdelete: 'DELETE',\n\t\t};\n\n\t\tconst method = methods[ action ];\n\t\tif ( ! method ) {\n\t\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t\t}\n\n\t\tconst path = id\n\t\t\t? `/wp/v2/${ resource }/${ id }`\n\t\t\t: `/wp/v2/${ resource }`;\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst allowHeader = response.headers?.get( 'allow' );\n\t\tconst key = [ action, resource, id ].filter( Boolean ).join( '/' );\n\t\tconst isAllowed = includes( allowHeader, method );\n\t\tdispatch.receiveUserPermission( key, isAllowed );\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst resource = entityConfig.__unstable_rest_base;\n\t\tawait dispatch( canUser( 'update', resource, recordId ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =\n\t\t\tawait resolveSelect.getPostType( postType );\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink =\n\t( link ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\t// Ideally this should be using an apiFetch call\n\t\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t\t// Also it seems the returned object is not a regular REST API post type.\n\t\tlet template;\n\t\ttry {\n\t\t\ttemplate = await window\n\t\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t\t.then( ( res ) => res.json() )\n\t\t\t\t.then( ( { data } ) => data );\n\t\t} catch ( e ) {\n\t\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t\t}\n\n\t\tif ( ! template ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = await resolveSelect.getEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\ttemplate.id\n\t\t);\n\n\t\tif ( record ) {\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t[ record ],\n\t\t\t\t{\n\t\t\t\t\t'find-template': link,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL = get( activeThemes, [\n\t\t\t0,\n\t\t\t'_links',\n\t\t\t'wp:user-global-styles',\n\t\t\t0,\n\t\t\t'href',\n\t\t] );\n\t\tif ( globalStylesURL ) {\n\t\t\tconst globalStylesObject = await apiFetch( {\n\t\t\t\turl: globalStylesURL,\n\t\t\t} );\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\t\tglobalStylesObject.id\n\t\t\t);\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst restPatterns = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/patterns',\n\t\t} );\n\t\tconst patterns = map( restPatterns, ( pattern ) =>\n\t\t\tmapKeys( pattern, ( value, key ) => camelCase( key ) )\n\t\t);\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","find","config","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","Set","DEFAULT_ENTITY_KEY","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","error","canUser","requestedAction","resource","id","registry","hasStartedResolution","resourcePath","retrievedActions","includes","Error","relatedAction","isAlreadyResolving","response","method","parse","allowHeader","headers","get","allowedMethods","allow","permissions","methods","create","read","update","delete","actionName","methodName","entries","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","_links","href","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getBlockPatterns","restPatterns","patterns","pattern","fromEntries","value","getBlockPatternCategories","categories"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GACpBC,KAAF,IACA,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AACzB,QAAMC,IAAI,GAAG,uBACZ,wCADY,EAEZF,KAFY,CAAb;AAIA,QAAMG,KAAK,GAAG,MAAM,uBAAU;AAAED,IAAAA;AAAF,GAAV,CAApB;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CATK;AAWP;AACA;AACA;;;;;AACO,MAAME,cAAc,GAC1B,MACA,eAA0B;AAAA,MAAlB;AAAEJ,IAAAA;AAAF,GAAkB;AACzB,QAAMK,WAAW,GAAG,MAAM,uBAAU;AAAEJ,IAAAA,IAAI,EAAE;AAAR,GAAV,CAA1B;AACAD,EAAAA,QAAQ,CAACM,kBAAT,CAA6BD,WAA7B;AACA,CALK;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAME,eAAe,GAC3B,UAAEC,IAAF,EAAQC,IAAR;AAAA,MAAcC,GAAd,uEAAoB,EAApB;AAAA,MAAwBX,KAAxB;AAAA,SACA,eAAkC;AAAA,QAA1B;AAAEY,MAAAA,MAAF;AAAUX,MAAAA;AAAV,KAA0B;AACjC,UAAMY,OAAO,GAAG,MAAMZ,QAAQ,CAAE,uCAAyBQ,IAAzB,CAAF,CAA9B;AACA,UAAMK,YAAY,GAAGD,OAAO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,QAAM8E,UAAU,GAAG,MAAM,uBAAU;AAClCnI,IAAAA,IAAI,EAAG,+BAA+B8H,YAAY,CAACE,UAAY;AAD7B,GAAV,CAAzB;;AAGAjI,EAAAA,QAAQ,CAACqI,+CAAT,CACCN,YAAY,CAACE,UADd,EAECG,UAFD;AAIA,CAXK;;;;AAaA,MAAME,gBAAgB,GAC5B,MACA,gBAA0B;AAAA,MAAlB;AAAEtI,IAAAA;AAAF,GAAkB;AACzB,QAAMuI,YAAY,GAAG,MAAM,uBAAU;AACpCtI,IAAAA,IAAI,EAAE;AAD8B,GAAV,CAA3B;AAGA,QAAMuI,QAAQ,GAAGD,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAE/F,GAAd,CAAqBiG,OAAF,IACnCnG,MAAM,CAACoG,WAAP,CACCpG,MAAM,CAACuD,OAAP,CAAgB4C,OAAhB,EAA0BjG,GAA1B,CAA+B;AAAA,QAAE,CAAE9B,GAAF,EAAOiI,KAAP,CAAF;AAAA,WAAsB,CACpD,2BAAWjI,GAAX,CADoD,EAEpDiI,KAFoD,CAAtB;AAAA,GAA/B,CADD,CADgB,CAAjB;AAQA3I,EAAAA,QAAQ,CAAE;AAAEgD,IAAAA,IAAI,EAAE,wBAAR;AAAkCwF,IAAAA;AAAlC,GAAF,CAAR;AACA,CAfK;;;;AAiBA,MAAMI,yBAAyB,GACrC,MACA,gBAA0B;AAAA,MAAlB;AAAE5I,IAAAA;AAAF,GAAkB;AACzB,QAAM6I,UAAU,GAAG,MAAM,uBAAU;AAClC5I,IAAAA,IAAI,EAAE;AAD4B,GAAV,CAAzB;AAGAD,EAAAA,QAAQ,CAAE;AAAEgD,IAAAA,IAAI,EAAE,kCAAR;AAA4C6F,IAAAA;AAA5C,GAAF,CAAR;AACA,CAPK","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Disable reason: While true that an early return could leave `path`\n\t\t\t// unused, it's important that path is derived using the query prior to\n\t\t\t// additional query modifications in the condition below, since those\n\t\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t\t// for how the request is made to the REST API.\n\n\t\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.baseURL + ( key ? '/' + key : '' ),\n\t\t\t\t{\n\t\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t\t...query,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( query !== undefined ) {\n\t\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\t\tif ( hasRecords ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst record = await apiFetch( { path } );\n\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object. If requesting specific fields, fields\n * must always include the ID.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( entityConfig.baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitely set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fullfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t\t// When requesting all fields, the list of results can be used to\n\t\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch ( error ) {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( requestedAction, resource, id ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst { hasStartedResolution } = registry.select( STORE_NAME );\n\n\t\tconst resourcePath = id ? `${ resource }/${ id }` : resource;\n\t\tconst retrievedActions = [ 'create', 'read', 'update', 'delete' ];\n\n\t\tif ( ! retrievedActions.includes( requestedAction ) ) {\n\t\t\tthrow new Error( `'${ requestedAction }' is not a valid action.` );\n\t\t}\n\n\t\t// Prevent resolving the same resource twice.\n\t\tfor ( const relatedAction of retrievedActions ) {\n\t\t\tif ( relatedAction === requestedAction ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isAlreadyResolving = hasStartedResolution( 'canUser', [\n\t\t\t\trelatedAction,\n\t\t\t\tresource,\n\t\t\t\tid,\n\t\t\t] );\n\t\t\tif ( isAlreadyResolving ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath: `/wp/v2/${ resourcePath }`,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst allowHeader = response.headers?.get( 'allow' );\n\t\tconst allowedMethods = allowHeader?.allow || allowHeader || '';\n\n\t\tconst permissions = {};\n\t\tconst methods = {\n\t\t\tcreate: 'POST',\n\t\t\tread: 'GET',\n\t\t\tupdate: 'PUT',\n\t\t\tdelete: 'DELETE',\n\t\t};\n\t\tfor ( const [ actionName, methodName ] of Object.entries( methods ) ) {\n\t\t\tpermissions[ actionName ] = allowedMethods.includes( methodName );\n\t\t}\n\n\t\tfor ( const action of retrievedActions ) {\n\t\t\tdispatch.receiveUserPermission(\n\t\t\t\t`${ action }/${ resourcePath }`,\n\t\t\t\tpermissions[ action ]\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst resource = entityConfig.__unstable_rest_base;\n\t\tawait dispatch( canUser( 'update', resource, recordId ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =\n\t\t\tawait resolveSelect.getPostType( postType );\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink =\n\t( link ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\t// Ideally this should be using an apiFetch call\n\t\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t\t// Also it seems the returned object is not a regular REST API post type.\n\t\tlet template;\n\t\ttry {\n\t\t\ttemplate = await window\n\t\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t\t.then( ( res ) => res.json() )\n\t\t\t\t.then( ( { data } ) => data );\n\t\t} catch ( e ) {\n\t\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t\t}\n\n\t\tif ( ! template ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = await resolveSelect.getEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\ttemplate.id\n\t\t);\n\n\t\tif ( record ) {\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t[ record ],\n\t\t\t\t{\n\t\t\t\t\t'find-template': link,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL =\n\t\t\tactiveThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]\n\t\t\t\t?.href;\n\t\tif ( globalStylesURL ) {\n\t\t\tconst globalStylesObject = await apiFetch( {\n\t\t\t\turl: globalStylesURL,\n\t\t\t} );\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\t\tglobalStylesObject.id\n\t\t\t);\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst restPatterns = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/patterns',\n\t\t} );\n\t\tconst patterns = restPatterns?.map( ( pattern ) =>\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( pattern ).map( ( [ key, value ] ) => [\n\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\tvalue,\n\t\t\t\t] )\n\t\t\t)\n\t\t);\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n"]}
|
package/build/selectors.js
CHANGED
|
@@ -216,26 +216,6 @@ function getEntityConfig(state, kind, name) {
|
|
|
216
216
|
name
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
|
-
/**
|
|
220
|
-
* GetEntityRecord is declared as an *interface*, but it actually describes
|
|
221
|
-
* the specifies the getEntityRecord *function* signature. It may seem unusual,
|
|
222
|
-
* but it's just how TypeScript implements function overloading.
|
|
223
|
-
*
|
|
224
|
-
* More accurately, GetEntityRecord distinguishes between two different signatures
|
|
225
|
-
* the getEntityRecord selector has:
|
|
226
|
-
*
|
|
227
|
-
* 1. When query._fields is not given, the returned type is EntityRecordOf< K, N, C >
|
|
228
|
-
* 2. When query._fields is given, the returned type is Partial<EntityRecordOf< K, N, C >>
|
|
229
|
-
*
|
|
230
|
-
* Unfortunately, due to a TypeScript limitation (https://github.com/microsoft/TypeScript/issues/23132)
|
|
231
|
-
* we can't use a single function signature with a return type such as:
|
|
232
|
-
*
|
|
233
|
-
* Fields extends undefined
|
|
234
|
-
* ? EntityRecordOf< K, N, C >
|
|
235
|
-
* : Partial< EntityRecordOf< K, N, C > >
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
219
|
/**
|
|
240
220
|
* Returns the Entity's record object by key. Returns `null` if the value is not
|
|
241
221
|
* yet received, undefined if the value entity is known to not exist, or the
|
|
@@ -250,6 +230,8 @@ function getEntityConfig(state, kind, name) {
|
|
|
250
230
|
*
|
|
251
231
|
* @return Record.
|
|
252
232
|
*/
|
|
233
|
+
|
|
234
|
+
|
|
253
235
|
const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) => {
|
|
254
236
|
var _query$context, _queriedState$items$c;
|
|
255
237
|
|
|
@@ -362,26 +344,6 @@ exports.getRawEntityRecord = getRawEntityRecord;
|
|
|
362
344
|
function hasEntityRecords(state, kind, name, query) {
|
|
363
345
|
return Array.isArray(getEntityRecords(state, kind, name, query));
|
|
364
346
|
}
|
|
365
|
-
/**
|
|
366
|
-
* GetEntityRecord is declared as an *interface*, but it actually describes
|
|
367
|
-
* the specifies the getEntityRecord *function* signature. It may seem unusual,
|
|
368
|
-
* but it's just how TypeScript implements function overloading.
|
|
369
|
-
*
|
|
370
|
-
* More accurately, GetEntityRecord distinguishes between two different signatures
|
|
371
|
-
* the getEntityRecord selector has:
|
|
372
|
-
*
|
|
373
|
-
* 1. When query._fields is not given, the returned type is EntityRecordOf< K, N, C >[]
|
|
374
|
-
* 2. When query._fields is given, the returned type is Partial<EntityRecordOf< K, N, C >>[]
|
|
375
|
-
*
|
|
376
|
-
* Unfortunately, due to a TypeScript limitation (https://github.com/microsoft/TypeScript/issues/23132)
|
|
377
|
-
* we can't use a single function signature with a return type such as:
|
|
378
|
-
*
|
|
379
|
-
* Fields extends undefined
|
|
380
|
-
* ? EntityRecordOf< K, N, C >[]
|
|
381
|
-
* : Partial< EntityRecordOf< K, N, C > >[]
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
347
|
/**
|
|
386
348
|
* Returns the Entity's records.
|
|
387
349
|
*
|
|
@@ -393,6 +355,8 @@ function hasEntityRecords(state, kind, name, query) {
|
|
|
393
355
|
*
|
|
394
356
|
* @return Records.
|
|
395
357
|
*/
|
|
358
|
+
|
|
359
|
+
|
|
396
360
|
const getEntityRecords = (state, kind, name, query) => {
|
|
397
361
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
398
362
|
// assigned for the given parameters, then it is known to not exist.
|
|
@@ -436,7 +400,7 @@ const __experimentalGetDirtyEntityRecords = (0, _rememo.default)(state => {
|
|
|
436
400
|
dirtyRecords.push({
|
|
437
401
|
// We avoid using primaryKey because it's transformed into a string
|
|
438
402
|
// when it's used as an object key.
|
|
439
|
-
key: entityRecord[entityConfig.key || _entities.DEFAULT_ENTITY_KEY],
|
|
403
|
+
key: entityRecord ? entityRecord[entityConfig.key || _entities.DEFAULT_ENTITY_KEY] : undefined,
|
|
440
404
|
title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl = entityConfig.getTitle) === null || _entityConfig$getTitl === void 0 ? void 0 : _entityConfig$getTitl.call(entityConfig, entityRecord)) || '',
|
|
441
405
|
name,
|
|
442
406
|
kind
|
|
@@ -478,7 +442,7 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
|
|
|
478
442
|
recordsBeingSaved.push({
|
|
479
443
|
// We avoid using primaryKey because it's transformed into a string
|
|
480
444
|
// when it's used as an object key.
|
|
481
|
-
key: entityRecord[entityConfig.key || _entities.DEFAULT_ENTITY_KEY],
|
|
445
|
+
key: entityRecord ? entityRecord[entityConfig.key || _entities.DEFAULT_ENTITY_KEY] : undefined,
|
|
482
446
|
title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl2 = entityConfig.getTitle) === null || _entityConfig$getTitl2 === void 0 ? void 0 : _entityConfig$getTitl2.call(entityConfig, entityRecord)) || '',
|
|
483
447
|
name,
|
|
484
448
|
kind
|
|
@@ -940,13 +904,12 @@ function __experimentalGetTemplateForLink(state, link) {
|
|
|
940
904
|
const records = getEntityRecords(state, 'postType', 'wp_template', {
|
|
941
905
|
'find-template': link
|
|
942
906
|
});
|
|
943
|
-
const template = records !== null && records !== void 0 && records.length ? records[0] : null;
|
|
944
907
|
|
|
945
|
-
if (
|
|
946
|
-
return getEditedEntityRecord(state, 'postType', 'wp_template',
|
|
908
|
+
if (records !== null && records !== void 0 && records.length) {
|
|
909
|
+
return getEditedEntityRecord(state, 'postType', 'wp_template', records[0].id);
|
|
947
910
|
}
|
|
948
911
|
|
|
949
|
-
return
|
|
912
|
+
return null;
|
|
950
913
|
}
|
|
951
914
|
/**
|
|
952
915
|
* Retrieve the current theme's base global styles
|