@wordpress/core-data 7.44.0 → 7.44.1-next.v.202604201441.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/build/queried-data/reducer.cjs +3 -3
- package/build/queried-data/reducer.cjs.map +2 -2
- package/build/utils/index.cjs +0 -3
- package/build/utils/index.cjs.map +2 -2
- package/build-module/queried-data/reducer.mjs +5 -10
- package/build-module/queried-data/reducer.mjs.map +2 -2
- package/build-module/utils/index.mjs +12 -14
- package/build-module/utils/index.mjs.map +2 -2
- package/build-types/queried-data/reducer.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/queried-data/reducer.js +6 -11
- package/src/utils/index.js +0 -1
- package/build/utils/on-sub-key.cjs +0 -46
- package/build/utils/on-sub-key.cjs.map +0 -7
- package/build-module/utils/on-sub-key.mjs +0 -21
- package/build-module/utils/on-sub-key.mjs.map +0 -7
- package/build-types/utils/on-sub-key.d.ts +0 -4
- package/build-types/utils/on-sub-key.d.ts.map +0 -1
- package/src/utils/on-sub-key.js +0 -35
- package/src/utils/test/on-sub-key.js +0 -46
|
@@ -148,7 +148,7 @@ var receiveQueries = (0, import_compose.compose)([
|
|
|
148
148
|
// Limit to matching action type so we don't attempt to replace action on
|
|
149
149
|
// an unhandled action.
|
|
150
150
|
(0, import_utils.ifMatchingAction)((action) => "query" in action),
|
|
151
|
-
// Inject query parts into action for use both in `
|
|
151
|
+
// Inject query parts into action for use both in `keyedReducer` and reducer.
|
|
152
152
|
(0, import_utils.replaceAction)((action) => {
|
|
153
153
|
if (action.query) {
|
|
154
154
|
return {
|
|
@@ -158,10 +158,10 @@ var receiveQueries = (0, import_compose.compose)([
|
|
|
158
158
|
}
|
|
159
159
|
return action;
|
|
160
160
|
}),
|
|
161
|
-
(0,
|
|
161
|
+
(0, import_data.keyedReducer)("context"),
|
|
162
162
|
// Queries shape is shared, but keyed by query `stableKey` part. Original
|
|
163
163
|
// reducer tracks only a single query object.
|
|
164
|
-
(0,
|
|
164
|
+
(0, import_data.keyedReducer)("stableKey")
|
|
165
165
|
])((state = {}, action) => {
|
|
166
166
|
if (action.type !== "RECEIVE_ITEMS") {
|
|
167
167
|
return state;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queried-data/reducer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers, keyedReducer } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { conservativeMapItem, ifMatchingAction, replaceAction } from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {number[]|undefined} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {Object} options Options object.\n * @param {number} [options.page] Page of items merged.\n * @param {number} [options.offset] Offset of items merged.\n * @param {number} options.perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds(\n\titemIds = [],\n\tnextItemIds,\n\t// The defaults for `page` and `perPage` are the same as in `getQueryParts`.\n\t{ page = 1, offset, perPage = 10 } = {}\n) {\n\t// If the query is unbounded, then `nextItemIds` is a complete replacement.\n\tif ( perPage === -1 ) {\n\t\treturn nextItemIds;\n\t}\n\n\tconst nextItemIdsStartIndex = offset ?? ( page - 1 ) * perPage;\n\tconst nextItemIdsRange = Math.max( perPage, nextItemIds.length );\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds.length,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIdsRange;\n\t\tif ( isInNextItemsRange ) {\n\t\t\tmergedItemIds[ i ] = nextItemIds[ i - nextItemIdsStartIndex ];\n\t\t} else {\n\t\t\tmergedItemIds[ i ] = itemIds[ i ];\n\t\t}\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\titemsList.map( ( item ) => [\n\t\t\t\t\t\t\titem?.[ key ],\n\t\t\t\t\t\t\tconservativeMapItem(\n\t\t\t\t\t\t\t\tstate?.[ context ]?.[ item?.[ key ] ],\n\t\t\t\t\t\t\t\titem\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t] )\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...itemsList.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `keyedReducer` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `keyedReducer` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tkeyedReducer( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tkeyedReducer( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tif ( action.type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\t// Single items don't have page or total count metadata\n\t// (only collection query responses do), so skip updating itemIds.\n\tif ( ! Array.isArray( action.items ) ) {\n\t\treturn state;\n\t}\n\n\tconst key = action.key ?? DEFAULT_ENTITY_KEY;\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate.itemIds,\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\t{\n\t\t\t\tpage: action.page,\n\t\t\t\toffset: action.offset,\n\t\t\t\tperPage: action.perPage,\n\t\t\t}\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA8C;AAC9C,qBAAwB;AAKxB,mBAAqE;AACrE,sBAAmC;AACnC,6BAA0B;AAE1B,SAAS,qBAAsB,QAAS;AACvC,QAAM,EAAE,MAAM,IAAI;AAClB,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,iBAAa,uBAAAA,SAAe,KAAM;AACxC,SAAO,WAAW;AACnB;AAeO,SAAS,iBACf,UAAU,CAAC,GACX,aAEA,EAAE,OAAO,GAAG,QAAQ,UAAU,GAAG,IAAI,CAAC,GACrC;AAED,MAAK,YAAY,IAAK;AACrB,WAAO;AAAA,EACR;AAEA,QAAM,wBAAwB,WAAY,OAAO,KAAM;AACvD,QAAM,mBAAmB,KAAK,IAAK,SAAS,YAAY,MAAO;AAI/D,QAAM,OAAO,KAAK;AAAA,IACjB,QAAQ;AAAA,IACR,wBAAwB,YAAY;AAAA,EACrC;AAGA,QAAM,gBAAgB,IAAI,MAAO,IAAK;AAEtC,WAAU,IAAI,GAAG,IAAI,MAAM,KAAM;AAIhC,UAAM,qBACL,KAAK,yBACL,IAAI,wBAAwB;AAC7B,QAAK,oBAAqB;AACzB,oBA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AACD,CAAE;",
|
|
6
6
|
"names": ["getQueryParts"]
|
|
7
7
|
}
|
package/build/utils/index.cjs
CHANGED
|
@@ -41,7 +41,6 @@ __export(utils_exports, {
|
|
|
41
41
|
ifMatchingAction: () => import_if_matching_action.default,
|
|
42
42
|
isNumericID: () => import_is_numeric_id.default,
|
|
43
43
|
normalizeQueryForResolution: () => import_normalize_query_for_resolution.default,
|
|
44
|
-
onSubKey: () => import_on_sub_key.default,
|
|
45
44
|
replaceAction: () => import_replace_action.default,
|
|
46
45
|
setNestedValue: () => import_set_nested_value.default,
|
|
47
46
|
withWeakMapCache: () => import_with_weak_map_cache.default
|
|
@@ -51,7 +50,6 @@ var import_conservative_map_item = __toESM(require("./conservative-map-item.cjs"
|
|
|
51
50
|
var import_get_normalized_comma_separable = __toESM(require("./get-normalized-comma-separable.cjs"));
|
|
52
51
|
var import_if_matching_action = __toESM(require("./if-matching-action.cjs"));
|
|
53
52
|
var import_forward_resolver = __toESM(require("./forward-resolver.cjs"));
|
|
54
|
-
var import_on_sub_key = __toESM(require("./on-sub-key.cjs"));
|
|
55
53
|
var import_replace_action = __toESM(require("./replace-action.cjs"));
|
|
56
54
|
var import_with_weak_map_cache = __toESM(require("./with-weak-map-cache.cjs"));
|
|
57
55
|
var import_set_nested_value = __toESM(require("./set-nested-value.cjs"));
|
|
@@ -73,7 +71,6 @@ var import_normalize_query_for_resolution = __toESM(require("./normalize-query-f
|
|
|
73
71
|
ifMatchingAction,
|
|
74
72
|
isNumericID,
|
|
75
73
|
normalizeQueryForResolution,
|
|
76
|
-
onSubKey,
|
|
77
74
|
replaceAction,
|
|
78
75
|
setNestedValue,
|
|
79
76
|
withWeakMapCache
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/index.js"],
|
|
4
|
-
"sourcesContent": ["export { default as conservativeMapItem } from './conservative-map-item';\nexport { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';\nexport { default as ifMatchingAction } from './if-matching-action';\nexport { default as forwardResolver } from './forward-resolver';\nexport { default as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["export { default as conservativeMapItem } from './conservative-map-item';\nexport { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';\nexport { default as ifMatchingAction } from './if-matching-action';\nexport { default as forwardResolver } from './forward-resolver';\nexport { default as replaceAction } from './replace-action';\nexport { default as withWeakMapCache } from './with-weak-map-cache';\nexport { default as setNestedValue } from './set-nested-value';\nexport { default as getNestedValue } from './get-nested-value';\nexport { default as isNumericID } from './is-numeric-id';\nexport {\n\tgetUserPermissionCacheKey,\n\tgetUserPermissionsFromAllowHeader,\n\tALLOWED_RESOURCE_ACTIONS,\n} from './user-permissions';\nexport { RECEIVE_INTERMEDIATE_RESULTS } from './receive-intermediate-results';\nexport { default as normalizeQueryForResolution } from './normalize-query-for-resolution';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAA+C;AAC/C,4CAAuD;AACvD,gCAA4C;AAC5C,8BAA2C;AAC3C,4BAAyC;AACzC,iCAA4C;AAC5C,8BAA0C;AAC1C,8BAA0C;AAC1C,2BAAuC;AACvC,8BAIO;AACP,0CAA6C;AAC7C,4CAAuD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
// packages/core-data/src/queried-data/reducer.js
|
|
2
|
-
import { combineReducers } from "@wordpress/data";
|
|
2
|
+
import { combineReducers, keyedReducer } from "@wordpress/data";
|
|
3
3
|
import { compose } from "@wordpress/compose";
|
|
4
|
-
import {
|
|
5
|
-
conservativeMapItem,
|
|
6
|
-
ifMatchingAction,
|
|
7
|
-
replaceAction,
|
|
8
|
-
onSubKey
|
|
9
|
-
} from "../utils/index.mjs";
|
|
4
|
+
import { conservativeMapItem, ifMatchingAction, replaceAction } from "../utils/index.mjs";
|
|
10
5
|
import { DEFAULT_ENTITY_KEY } from "../entities.mjs";
|
|
11
6
|
import getQueryParts from "./get-query-parts.mjs";
|
|
12
7
|
function getContextFromAction(action) {
|
|
@@ -116,7 +111,7 @@ var receiveQueries = compose([
|
|
|
116
111
|
// Limit to matching action type so we don't attempt to replace action on
|
|
117
112
|
// an unhandled action.
|
|
118
113
|
ifMatchingAction((action) => "query" in action),
|
|
119
|
-
// Inject query parts into action for use both in `
|
|
114
|
+
// Inject query parts into action for use both in `keyedReducer` and reducer.
|
|
120
115
|
replaceAction((action) => {
|
|
121
116
|
if (action.query) {
|
|
122
117
|
return {
|
|
@@ -126,10 +121,10 @@ var receiveQueries = compose([
|
|
|
126
121
|
}
|
|
127
122
|
return action;
|
|
128
123
|
}),
|
|
129
|
-
|
|
124
|
+
keyedReducer("context"),
|
|
130
125
|
// Queries shape is shared, but keyed by query `stableKey` part. Original
|
|
131
126
|
// reducer tracks only a single query object.
|
|
132
|
-
|
|
127
|
+
keyedReducer("stableKey")
|
|
133
128
|
])((state = {}, action) => {
|
|
134
129
|
if (action.type !== "RECEIVE_ITEMS") {
|
|
135
130
|
return state;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queried-data/reducer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers, keyedReducer } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { conservativeMapItem, ifMatchingAction, replaceAction } from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {number[]|undefined} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {Object} options Options object.\n * @param {number} [options.page] Page of items merged.\n * @param {number} [options.offset] Offset of items merged.\n * @param {number} options.perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds(\n\titemIds = [],\n\tnextItemIds,\n\t// The defaults for `page` and `perPage` are the same as in `getQueryParts`.\n\t{ page = 1, offset, perPage = 10 } = {}\n) {\n\t// If the query is unbounded, then `nextItemIds` is a complete replacement.\n\tif ( perPage === -1 ) {\n\t\treturn nextItemIds;\n\t}\n\n\tconst nextItemIdsStartIndex = offset ?? ( page - 1 ) * perPage;\n\tconst nextItemIdsRange = Math.max( perPage, nextItemIds.length );\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds.length,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIdsRange;\n\t\tif ( isInNextItemsRange ) {\n\t\t\tmergedItemIds[ i ] = nextItemIds[ i - nextItemIdsStartIndex ];\n\t\t} else {\n\t\t\tmergedItemIds[ i ] = itemIds[ i ];\n\t\t}\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\titemsList.map( ( item ) => [\n\t\t\t\t\t\t\titem?.[ key ],\n\t\t\t\t\t\t\tconservativeMapItem(\n\t\t\t\t\t\t\t\tstate?.[ context ]?.[ item?.[ key ] ],\n\t\t\t\t\t\t\t\titem\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t] )\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...itemsList.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `keyedReducer` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `keyedReducer` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tkeyedReducer( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tkeyedReducer( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tif ( action.type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\t// Single items don't have page or total count metadata\n\t// (only collection query responses do), so skip updating itemIds.\n\tif ( ! Array.isArray( action.items ) ) {\n\t\treturn state;\n\t}\n\n\tconst key = action.key ?? DEFAULT_ENTITY_KEY;\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate.itemIds,\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\t{\n\t\t\t\tpage: action.page,\n\t\t\t\toffset: action.offset,\n\t\t\t\tperPage: action.perPage,\n\t\t\t}\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,iBAAiB,oBAAoB;AAC9C,SAAS,eAAe;AAKxB,SAAS,qBAAqB,kBAAkB,qBAA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IACtC,KAAK;AACJ,YAAM,eAAe,OAAO,QAAQ,OAAQ,CAAE,QAAQ,WAAY;AACjE,eAAQ,MAAO,IAAI;AACnB,eAAO;AAAA,MACR,GAAG,CAAC,CAAE;AAEN,aAAO,OAAO;AAAA,QACb,OAAO,QAAS,KAAM,EAAE;AAAA,UACvB,CAAE,CAAE,YAAY,cAAe,MAAO;AAAA,YACrC;AAAA,YACA,OAAO;AAAA,cACN,OAAO,QAAS,cAAe,EAAE;AAAA,gBAChC,CAAE,CAAE,OAAO,UAAW,MAAO;AAAA,kBAC5B;AAAA,kBACA;AAAA,oBACC,GAAG;AAAA,oBACH,SAAS,WAAW,QAAQ;AAAA,sBAC3B,CAAE,YACD,CAAE,aAAc,OAAQ;AAAA,oBAC1B;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACC,aAAO;AAAA,EACT;AACD;AAEA,IAAO,kBAAQ,gBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,34 +3,32 @@ import { default as default2 } from "./conservative-map-item.mjs";
|
|
|
3
3
|
import { default as default3 } from "./get-normalized-comma-separable.mjs";
|
|
4
4
|
import { default as default4 } from "./if-matching-action.mjs";
|
|
5
5
|
import { default as default5 } from "./forward-resolver.mjs";
|
|
6
|
-
import { default as default6 } from "./
|
|
7
|
-
import { default as default7 } from "./
|
|
8
|
-
import { default as default8 } from "./
|
|
9
|
-
import { default as default9 } from "./
|
|
10
|
-
import { default as default10 } from "./
|
|
11
|
-
import { default as default11 } from "./is-numeric-id.mjs";
|
|
6
|
+
import { default as default6 } from "./replace-action.mjs";
|
|
7
|
+
import { default as default7 } from "./with-weak-map-cache.mjs";
|
|
8
|
+
import { default as default8 } from "./set-nested-value.mjs";
|
|
9
|
+
import { default as default9 } from "./get-nested-value.mjs";
|
|
10
|
+
import { default as default10 } from "./is-numeric-id.mjs";
|
|
12
11
|
import {
|
|
13
12
|
getUserPermissionCacheKey,
|
|
14
13
|
getUserPermissionsFromAllowHeader,
|
|
15
14
|
ALLOWED_RESOURCE_ACTIONS
|
|
16
15
|
} from "./user-permissions.mjs";
|
|
17
16
|
import { RECEIVE_INTERMEDIATE_RESULTS } from "./receive-intermediate-results.mjs";
|
|
18
|
-
import { default as
|
|
17
|
+
import { default as default11 } from "./normalize-query-for-resolution.mjs";
|
|
19
18
|
export {
|
|
20
19
|
ALLOWED_RESOURCE_ACTIONS,
|
|
21
20
|
RECEIVE_INTERMEDIATE_RESULTS,
|
|
22
21
|
default2 as conservativeMapItem,
|
|
23
22
|
default5 as forwardResolver,
|
|
24
|
-
|
|
23
|
+
default9 as getNestedValue,
|
|
25
24
|
default3 as getNormalizedCommaSeparable,
|
|
26
25
|
getUserPermissionCacheKey,
|
|
27
26
|
getUserPermissionsFromAllowHeader,
|
|
28
27
|
default4 as ifMatchingAction,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
default6 as
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
default8 as withWeakMapCache
|
|
28
|
+
default10 as isNumericID,
|
|
29
|
+
default11 as normalizeQueryForResolution,
|
|
30
|
+
default6 as replaceAction,
|
|
31
|
+
default8 as setNestedValue,
|
|
32
|
+
default7 as withWeakMapCache
|
|
35
33
|
};
|
|
36
34
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/index.js"],
|
|
4
|
-
"sourcesContent": ["export { default as conservativeMapItem } from './conservative-map-item';\nexport { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';\nexport { default as ifMatchingAction } from './if-matching-action';\nexport { default as forwardResolver } from './forward-resolver';\nexport { default as
|
|
5
|
-
"mappings": ";AAAA,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAA8C;AACvD,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAkC;AAC3C,SAAoB,WAAXA,
|
|
4
|
+
"sourcesContent": ["export { default as conservativeMapItem } from './conservative-map-item';\nexport { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';\nexport { default as ifMatchingAction } from './if-matching-action';\nexport { default as forwardResolver } from './forward-resolver';\nexport { default as replaceAction } from './replace-action';\nexport { default as withWeakMapCache } from './with-weak-map-cache';\nexport { default as setNestedValue } from './set-nested-value';\nexport { default as getNestedValue } from './get-nested-value';\nexport { default as isNumericID } from './is-numeric-id';\nexport {\n\tgetUserPermissionCacheKey,\n\tgetUserPermissionsFromAllowHeader,\n\tALLOWED_RESOURCE_ACTIONS,\n} from './user-permissions';\nexport { RECEIVE_INTERMEDIATE_RESULTS } from './receive-intermediate-results';\nexport { default as normalizeQueryForResolution } from './normalize-query-for-resolution';\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAA8C;AACvD,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAkC;AAC3C,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,iBAA8B;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oCAAoC;AAC7C,SAAoB,WAAXA,iBAA8C;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/queried-data/reducer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/queried-data/reducer.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;GAYG;AACH,0CATW,MAAM,EAAE,GAAC,SAAS,eAClB,MAAM,EAAE,8BAEhB;IAAqC,IAAI;IACJ,MAAM;IACP,OAAO,EAAnC,MAAM;CAEd,GAAS,MAAM,EAAE,CAyCnB;AAyBD;;;;;;;;GAQG;AACH,oDAiCC;AAED;;;;;;;;;;;GAWG;AACH;;;;;;;;EA8CC"}
|
|
@@ -2,7 +2,6 @@ export { default as conservativeMapItem } from "./conservative-map-item";
|
|
|
2
2
|
export { default as getNormalizedCommaSeparable } from "./get-normalized-comma-separable";
|
|
3
3
|
export { default as ifMatchingAction } from "./if-matching-action";
|
|
4
4
|
export { default as forwardResolver } from "./forward-resolver";
|
|
5
|
-
export { default as onSubKey } from "./on-sub-key";
|
|
6
5
|
export { default as replaceAction } from "./replace-action";
|
|
7
6
|
export { default as withWeakMapCache } from "./with-weak-map-cache";
|
|
8
7
|
export { default as setNestedValue } from "./set-nested-value";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.44.0",
|
|
3
|
+
"version": "7.44.1-next.v.202604201441.0+dab6d8c07",
|
|
4
4
|
"description": "Access to and manipulation of core WordPress entities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -49,22 +49,22 @@
|
|
|
49
49
|
"build-module/index.mjs"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@wordpress/api-fetch": "^7.44.0",
|
|
53
|
-
"@wordpress/block-editor": "^15.
|
|
54
|
-
"@wordpress/blocks": "^15.17.0",
|
|
55
|
-
"@wordpress/compose": "^7.44.0",
|
|
56
|
-
"@wordpress/data": "^10.
|
|
57
|
-
"@wordpress/deprecated": "^4.44.0",
|
|
58
|
-
"@wordpress/element": "^6.44.0",
|
|
59
|
-
"@wordpress/html-entities": "^4.44.0",
|
|
60
|
-
"@wordpress/i18n": "^6.17.0",
|
|
61
|
-
"@wordpress/is-shallow-equal": "^5.44.0",
|
|
62
|
-
"@wordpress/private-apis": "^1.44.0",
|
|
63
|
-
"@wordpress/rich-text": "^7.44.0",
|
|
64
|
-
"@wordpress/sync": "^1.44.0",
|
|
65
|
-
"@wordpress/undo-manager": "^1.44.0",
|
|
66
|
-
"@wordpress/url": "^4.44.0",
|
|
67
|
-
"@wordpress/warning": "^3.44.0",
|
|
52
|
+
"@wordpress/api-fetch": "^7.44.1-next.v.202604201441.0+dab6d8c07",
|
|
53
|
+
"@wordpress/block-editor": "^15.18.1-next.v.202604201441.0+dab6d8c07",
|
|
54
|
+
"@wordpress/blocks": "^15.17.2-next.v.202604201441.0+dab6d8c07",
|
|
55
|
+
"@wordpress/compose": "^7.44.1-next.v.202604201441.0+dab6d8c07",
|
|
56
|
+
"@wordpress/data": "^10.45.1-next.v.202604201441.0+dab6d8c07",
|
|
57
|
+
"@wordpress/deprecated": "^4.44.1-next.v.202604201441.0+dab6d8c07",
|
|
58
|
+
"@wordpress/element": "^6.44.1-next.v.202604201441.0+dab6d8c07",
|
|
59
|
+
"@wordpress/html-entities": "^4.44.1-next.v.202604201441.0+dab6d8c07",
|
|
60
|
+
"@wordpress/i18n": "^6.17.1-next.v.202604201441.0+dab6d8c07",
|
|
61
|
+
"@wordpress/is-shallow-equal": "^5.44.1-next.v.202604201441.0+dab6d8c07",
|
|
62
|
+
"@wordpress/private-apis": "^1.44.1-next.v.202604201441.0+dab6d8c07",
|
|
63
|
+
"@wordpress/rich-text": "^7.44.1-next.v.202604201441.0+dab6d8c07",
|
|
64
|
+
"@wordpress/sync": "^1.44.1-next.v.202604201441.0+dab6d8c07",
|
|
65
|
+
"@wordpress/undo-manager": "^1.44.1-next.v.202604201441.0+dab6d8c07",
|
|
66
|
+
"@wordpress/url": "^4.44.1-next.v.202604201441.0+dab6d8c07",
|
|
67
|
+
"@wordpress/warning": "^3.44.1-next.v.202604201441.0+dab6d8c07",
|
|
68
68
|
"change-case": "^4.1.2",
|
|
69
69
|
"equivalent-key-map": "^0.2.2",
|
|
70
70
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "c788005ba4ee2a34851c1217c51602656aa7c3a6"
|
|
88
88
|
}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { combineReducers } from '@wordpress/data';
|
|
4
|
+
import { combineReducers, keyedReducer } from '@wordpress/data';
|
|
5
5
|
import { compose } from '@wordpress/compose';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
conservativeMapItem,
|
|
12
|
-
ifMatchingAction,
|
|
13
|
-
replaceAction,
|
|
14
|
-
onSubKey,
|
|
15
|
-
} from '../utils';
|
|
10
|
+
import { conservativeMapItem, ifMatchingAction, replaceAction } from '../utils';
|
|
16
11
|
import { DEFAULT_ENTITY_KEY } from '../entities';
|
|
17
12
|
import getQueryParts from './get-query-parts';
|
|
18
13
|
|
|
@@ -221,11 +216,11 @@ const receiveQueries = compose( [
|
|
|
221
216
|
// an unhandled action.
|
|
222
217
|
ifMatchingAction( ( action ) => 'query' in action ),
|
|
223
218
|
|
|
224
|
-
// Inject query parts into action for use both in `
|
|
219
|
+
// Inject query parts into action for use both in `keyedReducer` and reducer.
|
|
225
220
|
replaceAction( ( action ) => {
|
|
226
221
|
// `ifMatchingAction` still passes on initialization, where state is
|
|
227
222
|
// undefined and a query is not assigned. Avoid attempting to parse
|
|
228
|
-
// parts. `
|
|
223
|
+
// parts. `keyedReducer` will omit by lack of `stableKey`.
|
|
229
224
|
if ( action.query ) {
|
|
230
225
|
return {
|
|
231
226
|
...action,
|
|
@@ -236,11 +231,11 @@ const receiveQueries = compose( [
|
|
|
236
231
|
return action;
|
|
237
232
|
} ),
|
|
238
233
|
|
|
239
|
-
|
|
234
|
+
keyedReducer( 'context' ),
|
|
240
235
|
|
|
241
236
|
// Queries shape is shared, but keyed by query `stableKey` part. Original
|
|
242
237
|
// reducer tracks only a single query object.
|
|
243
|
-
|
|
238
|
+
keyedReducer( 'stableKey' ),
|
|
244
239
|
] )( ( state = {}, action ) => {
|
|
245
240
|
if ( action.type !== 'RECEIVE_ITEMS' ) {
|
|
246
241
|
return state;
|
package/src/utils/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export { default as conservativeMapItem } from './conservative-map-item';
|
|
|
2
2
|
export { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';
|
|
3
3
|
export { default as ifMatchingAction } from './if-matching-action';
|
|
4
4
|
export { default as forwardResolver } from './forward-resolver';
|
|
5
|
-
export { default as onSubKey } from './on-sub-key';
|
|
6
5
|
export { default as replaceAction } from './replace-action';
|
|
7
6
|
export { default as withWeakMapCache } from './with-weak-map-cache';
|
|
8
7
|
export { default as setNestedValue } from './set-nested-value';
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/core-data/src/utils/on-sub-key.js
|
|
21
|
-
var on_sub_key_exports = {};
|
|
22
|
-
__export(on_sub_key_exports, {
|
|
23
|
-
default: () => on_sub_key_default,
|
|
24
|
-
onSubKey: () => onSubKey
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(on_sub_key_exports);
|
|
27
|
-
var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
|
|
28
|
-
const key = action[actionProperty];
|
|
29
|
-
if (key === void 0) {
|
|
30
|
-
return state;
|
|
31
|
-
}
|
|
32
|
-
const nextKeyState = reducer(state[key], action);
|
|
33
|
-
if (nextKeyState === state[key]) {
|
|
34
|
-
return state;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
...state,
|
|
38
|
-
[key]: nextKeyState
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
var on_sub_key_default = onSubKey;
|
|
42
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
-
0 && (module.exports = {
|
|
44
|
-
onSubKey
|
|
45
|
-
});
|
|
46
|
-
//# sourceMappingURL=on-sub-key.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/on-sub-key.js"],
|
|
4
|
-
"sourcesContent": ["/** @typedef {import('../types').AnyFunction} AnyFunction */\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param {string} actionProperty Action property by which to key object.\n *\n * @return {AnyFunction} Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty ) =>\n\t( reducer ) =>\n\t( state = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,IAAM,WACZ,CAAE,mBACF,CAAE,YACF,CAAE,QAAQ,CAAC,GAAG,WAAY;AAGzB,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AAED,IAAO,qBAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// packages/core-data/src/utils/on-sub-key.js
|
|
2
|
-
var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
|
|
3
|
-
const key = action[actionProperty];
|
|
4
|
-
if (key === void 0) {
|
|
5
|
-
return state;
|
|
6
|
-
}
|
|
7
|
-
const nextKeyState = reducer(state[key], action);
|
|
8
|
-
if (nextKeyState === state[key]) {
|
|
9
|
-
return state;
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
...state,
|
|
13
|
-
[key]: nextKeyState
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
var on_sub_key_default = onSubKey;
|
|
17
|
-
export {
|
|
18
|
-
on_sub_key_default as default,
|
|
19
|
-
onSubKey
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=on-sub-key.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/on-sub-key.js"],
|
|
4
|
-
"sourcesContent": ["/** @typedef {import('../types').AnyFunction} AnyFunction */\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param {string} actionProperty Action property by which to key object.\n *\n * @return {AnyFunction} Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty ) =>\n\t( reducer ) =>\n\t( state = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"],
|
|
5
|
-
"mappings": ";AAUO,IAAM,WACZ,CAAE,mBACF,CAAE,YACF,CAAE,QAAQ,CAAC,GAAG,WAAY;AAGzB,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AAED,IAAO,qBAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"on-sub-key.d.ts","sourceRoot":"","sources":["../../src/utils/on-sub-key.js"],"names":[],"mappings":"AAUO,yCAJI,MAAM,GAEL,WAAW,CAwBrB;;0BAhCY,OAAO,UAAU,EAAE,WAAW"}
|
package/src/utils/on-sub-key.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Higher-order reducer creator which creates a combined reducer object, keyed
|
|
5
|
-
* by a property on the action object.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} actionProperty Action property by which to key object.
|
|
8
|
-
*
|
|
9
|
-
* @return {AnyFunction} Higher-order reducer.
|
|
10
|
-
*/
|
|
11
|
-
export const onSubKey =
|
|
12
|
-
( actionProperty ) =>
|
|
13
|
-
( reducer ) =>
|
|
14
|
-
( state = {}, action ) => {
|
|
15
|
-
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
16
|
-
// where reducer is scoped by action shape.
|
|
17
|
-
const key = action[ actionProperty ];
|
|
18
|
-
if ( key === undefined ) {
|
|
19
|
-
return state;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Avoid updating state if unchanged. Note that this also accounts for a
|
|
23
|
-
// reducer which returns undefined on a key which is not yet tracked.
|
|
24
|
-
const nextKeyState = reducer( state[ key ], action );
|
|
25
|
-
if ( nextKeyState === state[ key ] ) {
|
|
26
|
-
return state;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...state,
|
|
31
|
-
[ key ]: nextKeyState,
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default onSubKey;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import deepFreeze from 'deep-freeze';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import onSubKey from '../on-sub-key';
|
|
10
|
-
|
|
11
|
-
describe( 'onSubKey', () => {
|
|
12
|
-
function createEnhancedReducer( actionProperty ) {
|
|
13
|
-
const enhanceReducer = onSubKey( actionProperty );
|
|
14
|
-
return enhanceReducer(
|
|
15
|
-
( state, action ) => 'Called by ' + action.caller
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
it( 'should default to an empty object', () => {
|
|
20
|
-
const reducer = createEnhancedReducer( 'caller' );
|
|
21
|
-
const nextState = reducer( undefined, { type: '@@INIT' } );
|
|
22
|
-
|
|
23
|
-
expect( nextState ).toEqual( {} );
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
it( 'should ignore actions where property not present', () => {
|
|
27
|
-
const state = deepFreeze( {} );
|
|
28
|
-
const reducer = createEnhancedReducer( 'caller' );
|
|
29
|
-
const nextState = reducer( state, { type: 'DO_FOO' } );
|
|
30
|
-
|
|
31
|
-
expect( nextState ).toBe( state );
|
|
32
|
-
} );
|
|
33
|
-
|
|
34
|
-
it( 'should key by action property', () => {
|
|
35
|
-
const reducer = createEnhancedReducer( 'caller' );
|
|
36
|
-
|
|
37
|
-
let state = deepFreeze( {} );
|
|
38
|
-
state = reducer( state, { type: 'DO_FOO', caller: 1 } );
|
|
39
|
-
state = reducer( state, { type: 'DO_FOO', caller: 2 } );
|
|
40
|
-
|
|
41
|
-
expect( state ).toEqual( {
|
|
42
|
-
1: 'Called by 1',
|
|
43
|
-
2: 'Called by 2',
|
|
44
|
-
} );
|
|
45
|
-
} );
|
|
46
|
-
} );
|