@wordpress/core-data 4.2.0-next.e230fbab09.0 → 4.3.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 (118) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +41 -8
  3. package/build/actions.js +61 -41
  4. package/build/actions.js.map +1 -1
  5. package/build/entities.js +36 -23
  6. package/build/entities.js.map +1 -1
  7. package/build/entity-provider.js +46 -44
  8. package/build/entity-provider.js.map +1 -1
  9. package/build/entity-types/{base-entity-types.js → base-entity-records.js} +9 -9
  10. package/build/entity-types/base-entity-records.js.map +1 -0
  11. package/build/fetch/__experimental-fetch-link-suggestions.js +1 -1
  12. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  13. package/build/fetch/__experimental-fetch-url-data.js +1 -1
  14. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  15. package/build/hooks/use-entity-record.js +15 -5
  16. package/build/hooks/use-entity-record.js.map +1 -1
  17. package/build/hooks/use-entity-records.js +17 -5
  18. package/build/hooks/use-entity-records.js.map +1 -1
  19. package/build/index.js +9 -21
  20. package/build/index.js.map +1 -1
  21. package/build/queried-data/actions.js +4 -4
  22. package/build/queried-data/actions.js.map +1 -1
  23. package/build/queried-data/get-query-parts.js +7 -3
  24. package/build/queried-data/get-query-parts.js.map +1 -1
  25. package/build/queried-data/reducer.js +8 -6
  26. package/build/queried-data/reducer.js.map +1 -1
  27. package/build/reducer.js +16 -16
  28. package/build/reducer.js.map +1 -1
  29. package/build/resolvers.js +17 -23
  30. package/build/resolvers.js.map +1 -1
  31. package/build/selectors.js +92 -51
  32. package/build/selectors.js.map +1 -1
  33. package/build/utils/conservative-map-item.js +1 -1
  34. package/build/utils/conservative-map-item.js.map +1 -1
  35. package/build/utils/is-raw-attribute.js +1 -1
  36. package/build/utils/is-raw-attribute.js.map +1 -1
  37. package/build-module/actions.js +62 -42
  38. package/build-module/actions.js.map +1 -1
  39. package/build-module/entities.js +32 -19
  40. package/build-module/entities.js.map +1 -1
  41. package/build-module/entity-provider.js +47 -45
  42. package/build-module/entity-provider.js.map +1 -1
  43. package/build-module/entity-types/{base-entity-types.js → base-entity-records.js} +7 -7
  44. package/build-module/entity-types/base-entity-records.js.map +1 -0
  45. package/build-module/fetch/__experimental-fetch-link-suggestions.js +1 -1
  46. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  47. package/build-module/fetch/__experimental-fetch-url-data.js +1 -1
  48. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  49. package/build-module/hooks/use-entity-record.js +15 -5
  50. package/build-module/hooks/use-entity-record.js.map +1 -1
  51. package/build-module/hooks/use-entity-records.js +17 -5
  52. package/build-module/hooks/use-entity-records.js.map +1 -1
  53. package/build-module/index.js +10 -22
  54. package/build-module/index.js.map +1 -1
  55. package/build-module/queried-data/actions.js +4 -4
  56. package/build-module/queried-data/actions.js.map +1 -1
  57. package/build-module/queried-data/get-query-parts.js +7 -3
  58. package/build-module/queried-data/get-query-parts.js.map +1 -1
  59. package/build-module/queried-data/reducer.js +8 -6
  60. package/build-module/queried-data/reducer.js.map +1 -1
  61. package/build-module/reducer.js +17 -17
  62. package/build-module/reducer.js.map +1 -1
  63. package/build-module/resolvers.js +18 -24
  64. package/build-module/resolvers.js.map +1 -1
  65. package/build-module/selectors.js +88 -51
  66. package/build-module/selectors.js.map +1 -1
  67. package/build-module/utils/conservative-map-item.js +1 -1
  68. package/build-module/utils/conservative-map-item.js.map +1 -1
  69. package/build-module/utils/is-raw-attribute.js +1 -1
  70. package/build-module/utils/is-raw-attribute.js.map +1 -1
  71. package/package.json +11 -11
  72. package/src/actions.js +62 -42
  73. package/src/entities.js +43 -17
  74. package/src/entity-provider.js +50 -44
  75. package/src/entity-types/attachment.ts +5 -5
  76. package/src/entity-types/{base-entity-types.ts → base-entity-records.ts} +5 -5
  77. package/src/entity-types/comment.ts +5 -5
  78. package/src/entity-types/helpers.ts +1 -1
  79. package/src/entity-types/index.ts +4 -4
  80. package/src/entity-types/menu-location.ts +5 -5
  81. package/src/entity-types/nav-menu-item.ts +10 -5
  82. package/src/entity-types/nav-menu.ts +5 -5
  83. package/src/entity-types/navigation-area.ts +5 -5
  84. package/src/entity-types/page.ts +5 -5
  85. package/src/entity-types/plugin.ts +10 -5
  86. package/src/entity-types/post.ts +5 -5
  87. package/src/entity-types/settings.ts +10 -5
  88. package/src/entity-types/sidebar.ts +6 -7
  89. package/src/entity-types/taxonomy.ts +5 -5
  90. package/src/entity-types/theme.ts +5 -5
  91. package/src/entity-types/type.ts +5 -5
  92. package/src/entity-types/user.ts +10 -5
  93. package/src/entity-types/widget-type.ts +5 -5
  94. package/src/entity-types/widget.ts +5 -5
  95. package/src/entity-types/wp-template-part.ts +5 -5
  96. package/src/entity-types/wp-template.ts +5 -5
  97. package/src/fetch/__experimental-fetch-link-suggestions.js +1 -1
  98. package/src/fetch/__experimental-fetch-url-data.js +1 -0
  99. package/src/hooks/use-entity-record.ts +19 -8
  100. package/src/hooks/use-entity-records.ts +26 -9
  101. package/src/index.js +10 -15
  102. package/src/locks/test/selectors.js +4 -4
  103. package/src/queried-data/actions.js +4 -4
  104. package/src/queried-data/get-query-parts.js +5 -5
  105. package/src/queried-data/reducer.js +6 -6
  106. package/src/reducer.js +17 -17
  107. package/src/resolvers.js +25 -30
  108. package/src/selectors.js +92 -53
  109. package/src/test/actions.js +138 -33
  110. package/src/test/entities.js +11 -11
  111. package/src/test/reducer.js +4 -4
  112. package/src/test/resolvers.js +5 -5
  113. package/src/test/selectors.js +22 -22
  114. package/src/utils/conservative-map-item.js +1 -1
  115. package/src/utils/is-raw-attribute.js +1 -1
  116. package/src/utils/test/is-raw-attribute.js +4 -4
  117. package/build/entity-types/base-entity-types.js.map +0 -1
  118. package/build-module/entity-types/base-entity-types.js.map +0 -1
@@ -13,7 +13,7 @@ import apiFetch from '@wordpress/api-fetch';
13
13
  */
14
14
 
15
15
  import { STORE_NAME } from './name';
16
- import { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';
16
+ import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
17
17
  import { forwardResolver, getNormalizedCommaSeparable } from './utils';
18
18
  /**
19
19
  * Requests authors from the REST API.
@@ -63,17 +63,17 @@ export const getEntityRecord = function (kind, name) {
63
63
  select,
64
64
  dispatch
65
65
  } = _ref3;
66
- const entities = await dispatch(getKindEntities(kind));
67
- const entity = find(entities, {
66
+ const configs = await dispatch(getOrLoadEntitiesConfig(kind));
67
+ const entityConfig = find(configs, {
68
68
  kind,
69
69
  name
70
70
  });
71
71
 
72
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
72
+ if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
73
73
  return;
74
74
  }
75
75
 
76
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
76
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
77
77
  exclusive: false
78
78
  });
79
79
 
@@ -83,7 +83,7 @@ export const getEntityRecord = function (kind, name) {
83
83
  // records are stored by ID reference. Thus, fields must always include
84
84
  // the ID.
85
85
  query = { ...query,
86
- _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
86
+ _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY]).join()
87
87
  };
88
88
  } // Disable reason: While true that an early return could leave `path`
89
89
  // unused, it's important that path is derived using the query prior to
@@ -93,7 +93,7 @@ export const getEntityRecord = function (kind, name) {
93
93
  // eslint-disable-next-line @wordpress/no-unused-vars-before-return
94
94
 
95
95
 
96
- const path = addQueryArgs(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
96
+ const path = addQueryArgs(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
97
97
  ...query
98
98
  });
99
99
 
@@ -115,9 +115,6 @@ export const getEntityRecord = function (kind, name) {
115
115
  path
116
116
  });
117
117
  dispatch.receiveEntityRecords(kind, name, record, query);
118
- } catch (error) {// We need a way to handle and access REST API errors in state
119
- // Until then, catching the error ensures the resolver is marked as resolved.
120
- // See similar implementation in `getEntityRecords()`.
121
118
  } finally {
122
119
  dispatch.__unstableReleaseStoreLock(lock);
123
120
  }
@@ -147,17 +144,17 @@ export const getEntityRecords = function (kind, name) {
147
144
  let {
148
145
  dispatch
149
146
  } = _ref4;
150
- const entities = await dispatch(getKindEntities(kind));
151
- const entity = find(entities, {
147
+ const configs = await dispatch(getOrLoadEntitiesConfig(kind));
148
+ const entityConfig = find(configs, {
152
149
  kind,
153
150
  name
154
151
  });
155
152
 
156
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
153
+ if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
157
154
  return;
158
155
  }
159
156
 
160
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
157
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
161
158
  exclusive: false
162
159
  });
163
160
 
@@ -169,11 +166,11 @@ export const getEntityRecords = function (kind, name) {
169
166
  // records are stored by ID reference. Thus, fields must always include
170
167
  // the ID.
171
168
  query = { ...query,
172
- _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
169
+ _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY]).join()
173
170
  };
174
171
  }
175
172
 
176
- const path = addQueryArgs(entity.baseURL, { ...entity.baseURLParams,
173
+ const path = addQueryArgs(entityConfig.baseURL, { ...entityConfig.baseURLParams,
177
174
  ...query
178
175
  });
179
176
  let records = Object.values(await apiFetch({
@@ -199,7 +196,7 @@ export const getEntityRecords = function (kind, name) {
199
196
  // See https://github.com/WordPress/gutenberg/pull/26575
200
197
 
201
198
  if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
202
- const key = entity.key || DEFAULT_ENTITY_KEY;
199
+ const key = entityConfig.key || DEFAULT_ENTITY_KEY;
203
200
  const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
204
201
  dispatch({
205
202
  type: 'START_RESOLUTIONS',
@@ -212,9 +209,6 @@ export const getEntityRecords = function (kind, name) {
212
209
  args: resolutionsArgs
213
210
  });
214
211
  }
215
- } catch (error) {// We need a way to handle and access REST API errors in state
216
- // Until then, catching the error ensures the resolver is marked as resolved.
217
- // See similar implementation in `getEntityRecord()`.
218
212
  } finally {
219
213
  dispatch.__unstableReleaseStoreLock(lock);
220
214
  }
@@ -331,17 +325,17 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 =>
331
325
  let {
332
326
  dispatch
333
327
  } = _ref8;
334
- const entities = await dispatch(getKindEntities(kind));
335
- const entity = find(entities, {
328
+ const configs = await dispatch(getOrLoadEntitiesConfig(kind));
329
+ const entityConfig = find(configs, {
336
330
  kind,
337
331
  name
338
332
  });
339
333
 
340
- if (!entity) {
334
+ if (!entityConfig) {
341
335
  return;
342
336
  }
343
337
 
344
- const resource = entity.__unstable_rest_base;
338
+ const resource = entityConfig.__unstable_rest_base;
345
339
  await dispatch(canUser('update', resource, recordId));
346
340
  };
347
341
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__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","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,OAA9B,EAAuCC,IAAvC,QAAmD,QAAnD;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAKC,KAAF,IAAa,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AAChE,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,G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YAAY,GAAG,MAAMrD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAM2D,UAAU,GAAG,MAAMrH,QAAQ,CAAE;AAClCS,IAAAA,IAAI,EAAG,+BAA+BuG,YAAY,CAACE,UAAY;AAD7B,GAAF,CAAjC;;AAGA1G,EAAAA,QAAQ,CAAC8G,+CAAT,CACCN,YAAY,CAACE,UADd,EAECG,UAFD;AAIA,CAZM","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, compact, 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 { getKindEntities, 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 = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\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.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + ( key ? '/' + key : '' ), {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecords()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\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.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecord()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\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 = () => async ( { dispatch, resolveSelect } ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\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 = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\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 = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\tmethod: 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\t// Optional chaining operator is used here because the API requests don't\n\t// return the expected result in the native version. Instead, API requests\n\t// only return the result, without including response properties like the headers.\n\tconst allowHeader = response.headers?.get( 'allow' );\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\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 = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\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 = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\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 = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\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 = () => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\tconst globalStylesURL = get( activeThemes, [\n\t\t0,\n\t\t'_links',\n\t\t'wp:user-global-styles',\n\t\t0,\n\t\t'href',\n\t] );\n\tif ( globalStylesURL ) {\n\t\tconst globalStylesObject = await apiFetch( {\n\t\t\turl: globalStylesURL,\n\t\t} );\n\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\tglobalStylesObject.id\n\t\t);\n\t}\n};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst themeGlobalStyles = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t} );\n\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\tcurrentTheme.stylesheet,\n\t\tthemeGlobalStyles\n\t);\n};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst variations = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t} );\n\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\tcurrentTheme.stylesheet,\n\t\tvariations\n\t);\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getOrLoadEntitiesConfig","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","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","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,OAA9B,EAAuCC,IAAvC,QAAmD,QAAnD;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,uBAAT,EAAkCC,kBAAlC,QAA4D,YAA5D;A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,CAAC2G,0CAAT,CACCH,YAAY,CAACE,UADd,EAECD,iBAFD;AAIA,CAZM;AAcP,OAAO,MAAMG,mDAAmD,GAAG,MAAM,gBAGlE;AAAA,MAH0E;AAChF1D,IAAAA,aADgF;AAEhFlD,IAAAA;AAFgF,GAG1E;AACN,QAAMwG,YAAY,GAAG,MAAMtD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAM4D,UAAU,GAAG,MAAMrH,QAAQ,CAAE;AAClCS,IAAAA,IAAI,EAAG,+BAA+BuG,YAAY,CAACE,UAAY;AAD7B,GAAF,CAAjC;;AAGA1G,EAAAA,QAAQ,CAAC8G,+CAAT,CACCN,YAAY,CAACE,UADd,EAECG,UAFD;AAIA,CAZM","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, compact, 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 = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\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.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\tconst entityConfig = find( configs, { kind, name } );\n\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'records', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs(\n\t\t\tentityConfig.baseURL + ( key ? '/' + key : '' ),\n\t\t\t{\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t}\n\t\t);\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\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.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\tconst entityConfig = find( configs, { kind, name } );\n\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'records', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entityConfig.baseURL, {\n\t\t\t...entityConfig.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\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 = () => async ( { dispatch, resolveSelect } ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\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 = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\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 = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\tmethod: 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\t// Optional chaining operator is used here because the API requests don't\n\t// return the expected result in the native version. Instead, API requests\n\t// only return the result, without including response properties like the headers.\n\tconst allowHeader = response.headers?.get( 'allow' );\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\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 = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\tconst entityConfig = find( configs, { kind, name } );\n\tif ( ! entityConfig ) {\n\t\treturn;\n\t}\n\n\tconst resource = entityConfig.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\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 = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\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 = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\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 = () => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\tconst globalStylesURL = get( activeThemes, [\n\t\t0,\n\t\t'_links',\n\t\t'wp:user-global-styles',\n\t\t0,\n\t\t'href',\n\t] );\n\tif ( globalStylesURL ) {\n\t\tconst globalStylesObject = await apiFetch( {\n\t\t\turl: globalStylesURL,\n\t\t} );\n\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\tglobalStylesObject.id\n\t\t);\n\t}\n};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst themeGlobalStyles = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t} );\n\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\tcurrentTheme.stylesheet,\n\t\tthemeGlobalStyles\n\t);\n};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst variations = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t} );\n\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\tcurrentTheme.stylesheet,\n\t\tvariations\n\t);\n};\n"]}
@@ -84,8 +84,9 @@ export const getUserQueryResults = createSelector((state, queryID) => {
84
84
  return map(queryResults, id => state.users.byId[id]);
85
85
  }, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
86
86
  /**
87
- * Returns whether the entities for the give kind are loaded.
87
+ * Returns the loaded entities for the given kind.
88
88
  *
89
+ * @deprecated since WordPress 6.0. Use getEntitiesConfig instead
89
90
  * @param {Object} state Data state.
90
91
  * @param {string} kind Entity kind.
91
92
  *
@@ -93,21 +94,55 @@ export const getUserQueryResults = createSelector((state, queryID) => {
93
94
  */
94
95
 
95
96
  export function getEntitiesByKind(state, kind) {
97
+ deprecated("wp.data.select( 'core' ).getEntitiesByKind()", {
98
+ since: '6.0',
99
+ alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
100
+ });
101
+ return getEntitiesConfig(state, kind);
102
+ }
103
+ /**
104
+ * Returns the loaded entities for the given kind.
105
+ *
106
+ * @param {Object} state Data state.
107
+ * @param {string} kind Entity kind.
108
+ *
109
+ * @return {Array<Object>} Array of entities with config matching kind.
110
+ */
111
+
112
+ export function getEntitiesConfig(state, kind) {
96
113
  return filter(state.entities.config, {
97
114
  kind
98
115
  });
99
116
  }
100
117
  /**
101
- * Returns the entity object given its kind and name.
118
+ * Returns the entity config given its kind and name.
102
119
  *
120
+ * @deprecated since WordPress 6.0. Use getEntityConfig instead
103
121
  * @param {Object} state Data state.
104
122
  * @param {string} kind Entity kind.
105
123
  * @param {string} name Entity name.
106
124
  *
107
- * @return {Object} Entity
125
+ * @return {Object} Entity config
108
126
  */
109
127
 
110
128
  export function getEntity(state, kind, name) {
129
+ deprecated("wp.data.select( 'core' ).getEntity()", {
130
+ since: '6.0',
131
+ alternative: "wp.data.select( 'core' ).getEntityConfig()"
132
+ });
133
+ return getEntityConfig(state, kind, name);
134
+ }
135
+ /**
136
+ * Returns the entity config given its kind and name.
137
+ *
138
+ * @param {Object} state Data state.
139
+ * @param {string} kind Entity kind.
140
+ * @param {string} name Entity name.
141
+ *
142
+ * @return {Object} Entity config
143
+ */
144
+
145
+ export function getEntityConfig(state, kind, name) {
111
146
  return find(state.entities.config, {
112
147
  kind,
113
148
  name
@@ -124,13 +159,13 @@ export function getEntity(state, kind, name) {
124
159
  * @param {number} key Record's key
125
160
  * @param {?Object} query Optional query.
126
161
  *
127
- * @return {Object?} Record.
162
+ * @return {Object|undefined} Record.
128
163
  */
129
164
 
130
165
  export const getEntityRecord = createSelector((state, kind, name, key, query) => {
131
166
  var _query$context, _queriedState$items$c;
132
167
 
133
- const queriedState = get(state.entities.data, [kind, name, 'queriedData']);
168
+ const queriedState = get(state.entities.records, [kind, name, 'queriedData']);
134
169
 
135
170
  if (!queriedState) {
136
171
  return undefined;
@@ -152,8 +187,10 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
152
187
  const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key];
153
188
 
154
189
  if (item && query._fields) {
190
+ var _getNormalizedCommaSe;
191
+
155
192
  const filteredItem = {};
156
- const fields = getNormalizedCommaSeparable(query._fields);
193
+ const fields = (_getNormalizedCommaSe = getNormalizedCommaSeparable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
157
194
 
158
195
  for (let f = 0; f < fields.length; f++) {
159
196
  const field = fields[f].split('.');
@@ -169,10 +206,10 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
169
206
  var _query$context2;
170
207
 
171
208
  const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
172
- return [get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
209
+ return [get(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
173
210
  });
174
211
  /**
175
- * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.
212
+ * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
176
213
  *
177
214
  * @param {Object} state State tree
178
215
  * @param {string} kind Entity kind.
@@ -200,7 +237,7 @@ export function __experimentalGetEntityRecordNoResolver(state, kind, name, key)
200
237
  export const getRawEntityRecord = createSelector((state, kind, name, key) => {
201
238
  const record = getEntityRecord(state, kind, name, key);
202
239
  return record && Object.keys(record).reduce((accumulator, _key) => {
203
- if (isRawAttribute(getEntity(state, kind, name), _key)) {
240
+ if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
204
241
  // Because edits are the "raw" attribute values,
205
242
  // we return those from record selectors to make rendering,
206
243
  // comparisons, and joins with edits easier.
@@ -215,7 +252,7 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
215
252
  var _query$context3;
216
253
 
217
254
  const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
218
- return [state.entities.config, get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
255
+ return [state.entities.config, get(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
219
256
  });
220
257
  /**
221
258
  * Returns true if records have been received for the given set of parameters,
@@ -246,7 +283,7 @@ export function hasEntityRecords(state, kind, name, query) {
246
283
  export function getEntityRecords(state, kind, name, query) {
247
284
  // Queried data state is prepopulated for all known entities. If this is not
248
285
  // assigned for the given parameters, then it is known to not exist.
249
- const queriedState = get(state.entities.data, [kind, name, 'queriedData']);
286
+ const queriedState = get(state.entities.records, [kind, name, 'queriedData']);
250
287
 
251
288
  if (!queriedState) {
252
289
  return null;
@@ -265,27 +302,27 @@ export function getEntityRecords(state, kind, name, query) {
265
302
  export const __experimentalGetDirtyEntityRecords = createSelector(state => {
266
303
  const {
267
304
  entities: {
268
- data
305
+ records
269
306
  }
270
307
  } = state;
271
308
  const dirtyRecords = [];
272
- Object.keys(data).forEach(kind => {
273
- Object.keys(data[kind]).forEach(name => {
274
- const primaryKeys = Object.keys(data[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
309
+ Object.keys(records).forEach(kind => {
310
+ Object.keys(records[kind]).forEach(name => {
311
+ const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
275
312
  // and it must have edits.
276
313
  getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey));
277
314
 
278
315
  if (primaryKeys.length) {
279
- const entity = getEntity(state, kind, name);
316
+ const entityConfig = getEntityConfig(state, kind, name);
280
317
  primaryKeys.forEach(primaryKey => {
281
- var _entity$getTitle;
318
+ var _entityConfig$getTitl;
282
319
 
283
320
  const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
284
321
  dirtyRecords.push({
285
322
  // We avoid using primaryKey because it's transformed into a string
286
323
  // when it's used as an object key.
287
- key: entityRecord[entity.key || DEFAULT_ENTITY_KEY],
288
- title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle = entity.getTitle) === null || _entity$getTitle === void 0 ? void 0 : _entity$getTitle.call(entity, entityRecord)) || '',
324
+ key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY],
325
+ title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl = entityConfig.getTitle) === null || _entityConfig$getTitl === void 0 ? void 0 : _entityConfig$getTitl.call(entityConfig, entityRecord)) || '',
289
326
  name,
290
327
  kind
291
328
  });
@@ -294,7 +331,7 @@ export const __experimentalGetDirtyEntityRecords = createSelector(state => {
294
331
  });
295
332
  });
296
333
  return dirtyRecords;
297
- }, state => [state.entities.data]);
334
+ }, state => [state.entities.records]);
298
335
  /**
299
336
  * Returns the list of entities currently being saved.
300
337
  *
@@ -306,25 +343,25 @@ export const __experimentalGetDirtyEntityRecords = createSelector(state => {
306
343
  export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
307
344
  const {
308
345
  entities: {
309
- data
346
+ records
310
347
  }
311
348
  } = state;
312
349
  const recordsBeingSaved = [];
313
- Object.keys(data).forEach(kind => {
314
- Object.keys(data[kind]).forEach(name => {
315
- const primaryKeys = Object.keys(data[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
350
+ Object.keys(records).forEach(kind => {
351
+ Object.keys(records[kind]).forEach(name => {
352
+ const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
316
353
 
317
354
  if (primaryKeys.length) {
318
- const entity = getEntity(state, kind, name);
355
+ const entityConfig = getEntityConfig(state, kind, name);
319
356
  primaryKeys.forEach(primaryKey => {
320
- var _entity$getTitle2;
357
+ var _entityConfig$getTitl2;
321
358
 
322
359
  const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
323
360
  recordsBeingSaved.push({
324
361
  // We avoid using primaryKey because it's transformed into a string
325
362
  // when it's used as an object key.
326
- key: entityRecord[entity.key || DEFAULT_ENTITY_KEY],
327
- title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle2 = entity.getTitle) === null || _entity$getTitle2 === void 0 ? void 0 : _entity$getTitle2.call(entity, entityRecord)) || '',
363
+ key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY],
364
+ title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl2 = entityConfig.getTitle) === null || _entityConfig$getTitl2 === void 0 ? void 0 : _entityConfig$getTitl2.call(entityConfig, entityRecord)) || '',
328
365
  name,
329
366
  kind
330
367
  });
@@ -333,7 +370,7 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
333
370
  });
334
371
  });
335
372
  return recordsBeingSaved;
336
- }, state => [state.entities.data]);
373
+ }, state => [state.entities.records]);
337
374
  /**
338
375
  * Returns the specified entity record's edits.
339
376
  *
@@ -346,7 +383,7 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
346
383
  */
347
384
 
348
385
  export function getEntityRecordEdits(state, kind, name, recordId) {
349
- return get(state.entities.data, [kind, name, 'edits', recordId]);
386
+ return get(state.entities.records, [kind, name, 'edits', recordId]);
350
387
  }
351
388
  /**
352
389
  * Returns the specified entity record's non transient edits.
@@ -366,7 +403,7 @@ export function getEntityRecordEdits(state, kind, name, recordId) {
366
403
  export const getEntityRecordNonTransientEdits = createSelector((state, kind, name, recordId) => {
367
404
  const {
368
405
  transientEdits
369
- } = getEntity(state, kind, name) || {};
406
+ } = getEntityConfig(state, kind, name) || {};
370
407
  const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
371
408
 
372
409
  if (!transientEdits) {
@@ -380,7 +417,7 @@ export const getEntityRecordNonTransientEdits = createSelector((state, kind, nam
380
417
 
381
418
  return acc;
382
419
  }, {});
383
- }, (state, kind, name, recordId) => [state.entities.config, get(state.entities.data, [kind, name, 'edits', recordId])]);
420
+ }, (state, kind, name, recordId) => [state.entities.config, get(state.entities.records, [kind, name, 'edits', recordId])]);
384
421
  /**
385
422
  * Returns true if the specified entity record has edits,
386
423
  * and false otherwise.
@@ -399,10 +436,10 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
399
436
  /**
400
437
  * Returns the specified entity record, merged with its edits.
401
438
  *
402
- * @param {Object} state State tree.
403
- * @param {string} kind Entity kind.
404
- * @param {string} name Entity name.
405
- * @param {number} recordId Record ID.
439
+ * @param {Object} state State tree.
440
+ * @param {string} kind Entity kind.
441
+ * @param {string} name Entity name.
442
+ * @param {number|string} recordId Record ID.
406
443
  *
407
444
  * @return {Object?} The entity record, merged with its edits.
408
445
  */
@@ -413,7 +450,7 @@ export const getEditedEntityRecord = createSelector((state, kind, name, recordId
413
450
  var _query$context4;
414
451
 
415
452
  const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
416
- return [state.entities.config, get(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), get(state.entities.data, [kind, name, 'edits', recordId])];
453
+ return [state.entities.config, get(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), get(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), get(state.entities.records, [kind, name, 'edits', recordId])];
417
454
  });
418
455
  /**
419
456
  * Returns true if the specified entity record is autosaving, and false otherwise.
@@ -430,22 +467,22 @@ export function isAutosavingEntityRecord(state, kind, name, recordId) {
430
467
  const {
431
468
  pending,
432
469
  isAutosave
433
- } = get(state.entities.data, [kind, name, 'saving', recordId], {});
470
+ } = get(state.entities.records, [kind, name, 'saving', recordId], {});
434
471
  return Boolean(pending && isAutosave);
435
472
  }
436
473
  /**
437
474
  * Returns true if the specified entity record is saving, and false otherwise.
438
475
  *
439
- * @param {Object} state State tree.
440
- * @param {string} kind Entity kind.
441
- * @param {string} name Entity name.
442
- * @param {number} recordId Record ID.
476
+ * @param {Object} state State tree.
477
+ * @param {string} kind Entity kind.
478
+ * @param {string} name Entity name.
479
+ * @param {number|string} recordId Record ID.
443
480
  *
444
481
  * @return {boolean} Whether the entity record is saving or not.
445
482
  */
446
483
 
447
484
  export function isSavingEntityRecord(state, kind, name, recordId) {
448
- return get(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false);
485
+ return get(state.entities.records, [kind, name, 'saving', recordId, 'pending'], false);
449
486
  }
450
487
  /**
451
488
  * Returns true if the specified entity record is deleting, and false otherwise.
@@ -459,7 +496,7 @@ export function isSavingEntityRecord(state, kind, name, recordId) {
459
496
  */
460
497
 
461
498
  export function isDeletingEntityRecord(state, kind, name, recordId) {
462
- return get(state.entities.data, [kind, name, 'deleting', recordId, 'pending'], false);
499
+ return get(state.entities.records, [kind, name, 'deleting', recordId, 'pending'], false);
463
500
  }
464
501
  /**
465
502
  * Returns the specified entity record's last save error.
@@ -473,7 +510,7 @@ export function isDeletingEntityRecord(state, kind, name, recordId) {
473
510
  */
474
511
 
475
512
  export function getLastEntitySaveError(state, kind, name, recordId) {
476
- return get(state.entities.data, [kind, name, 'saving', recordId, 'error']);
513
+ return get(state.entities.records, [kind, name, 'saving', recordId, 'error']);
477
514
  }
478
515
  /**
479
516
  * Returns the specified entity record's last delete error.
@@ -487,7 +524,7 @@ export function getLastEntitySaveError(state, kind, name, recordId) {
487
524
  */
488
525
 
489
526
  export function getLastEntityDeleteError(state, kind, name, recordId) {
490
- return get(state.entities.data, [kind, name, 'deleting', recordId, 'error']);
527
+ return get(state.entities.records, [kind, name, 'deleting', recordId, 'error']);
491
528
  }
492
529
  /**
493
530
  * Returns the current undo offset for the
@@ -662,13 +699,13 @@ export function canUser(state, action, resource, id) {
662
699
  */
663
700
 
664
701
  export function canUserEditEntityRecord(state, kind, name, recordId) {
665
- const entity = getEntity(state, kind, name);
702
+ const entityConfig = getEntityConfig(state, kind, name);
666
703
 
667
- if (!entity) {
704
+ if (!entityConfig) {
668
705
  return false;
669
706
  }
670
707
 
671
- const resource = entity.__unstable_rest_base;
708
+ const resource = entityConfig.__unstable_rest_base;
672
709
  return canUser(state, 'update', resource, recordId);
673
710
  }
674
711
  /**
@@ -767,7 +804,7 @@ export function __experimentalGetTemplateForLink(state, link) {
767
804
  *
768
805
  * @param {Object} state Editor state.
769
806
  *
770
- * @return {Object?} The Global Styles object.
807
+ * @return {Object|null} The Global Styles object.
771
808
  */
772
809
 
773
810
  export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
@@ -784,7 +821,7 @@ export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
784
821
  *
785
822
  * @param {Object} state Data state.
786
823
  *
787
- * @return {string} The current global styles ID.
824
+ * @return {string|null} The current global styles ID.
788
825
  */
789
826
 
790
827
  export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {