@wordpress/core-data 4.5.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/README.md +175 -85
- package/build/entities.js +49 -46
- package/build/entities.js.map +1 -1
- package/build/entity-types/{navigation-area.js → entities.js} +1 -1
- package/build/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
- package/build/hooks/constants.js +0 -2
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +38 -0
- package/build/hooks/index.js.map +1 -0
- package/build/hooks/use-entity-record.js +22 -8
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +21 -8
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/index.js +17 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/get-query-parts.js +4 -0
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/selectors.js +163 -163
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +49 -46
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
- package/build-module/hooks/constants.js +0 -1
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js +3 -0
- package/build-module/hooks/index.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +18 -7
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +17 -7
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/index.js +2 -3
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +4 -0
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/selectors.js +164 -163
- package/build-module/selectors.js.map +1 -1
- package/package.json +12 -12
- package/src/entities.ts +342 -129
- package/src/entity-types/entities.ts +127 -0
- package/src/entity-types/index.ts +1 -3
- package/src/hooks/constants.ts +1 -2
- package/src/hooks/index.ts +8 -0
- package/src/hooks/test/use-entity-record.js +1 -0
- package/src/hooks/test/use-entity-records.js +1 -0
- package/src/hooks/test/use-query-select.js +1 -0
- package/src/hooks/use-entity-record.ts +32 -9
- package/src/hooks/use-entity-records.ts +28 -30
- package/src/index.js +2 -3
- package/src/queried-data/get-query-parts.js +3 -0
- package/src/queried-data/test/get-query-parts.js +4 -0
- package/src/selectors.ts +406 -216
- package/src/test/actions.js +30 -14
- package/src/test/entities.js +5 -0
- package/src/test/resolvers.js +11 -0
- package/build-module/entity-types/navigation-area.js +0 -2
- package/src/entity-types/navigation-area.ts +0 -29
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deprecated from '@wordpress/deprecated';
|
|
1
5
|
/**
|
|
2
6
|
* Internal dependencies
|
|
3
7
|
*/
|
|
8
|
+
|
|
4
9
|
import useQuerySelect from './use-query-select';
|
|
5
10
|
import { store as coreStore } from '../';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Resolves the specified entity record.
|
|
9
14
|
*
|
|
10
|
-
* @param kind
|
|
11
|
-
* @param name
|
|
12
|
-
* @param recordId
|
|
13
|
-
* @param options
|
|
14
|
-
* @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
|
|
15
|
+
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
|
|
16
|
+
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
|
|
17
|
+
* @param recordId ID of the requested entity record.
|
|
18
|
+
* @param options Optional hook options.
|
|
15
19
|
* @example
|
|
16
20
|
* ```js
|
|
17
21
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -34,10 +38,10 @@ import { store as coreStore } from '../';
|
|
|
34
38
|
* application, the page and the resolution details will be retrieved from
|
|
35
39
|
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
36
40
|
*
|
|
37
|
-
* @return
|
|
41
|
+
* @return Entity record data.
|
|
38
42
|
* @template RecordType
|
|
39
43
|
*/
|
|
40
|
-
export default function
|
|
44
|
+
export default function useEntityRecord(kind, name, recordId) {
|
|
41
45
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
42
46
|
enabled: true
|
|
43
47
|
};
|
|
@@ -56,4 +60,11 @@ export default function __experimentalUseEntityRecord(kind, name, recordId) {
|
|
|
56
60
|
...rest
|
|
57
61
|
};
|
|
58
62
|
}
|
|
63
|
+
export function __experimentalUseEntityRecord(kind, name, recordId, options) {
|
|
64
|
+
deprecated(`wp.data.__experimentalUseEntityRecord`, {
|
|
65
|
+
alternative: 'wp.data.useEntityRecord',
|
|
66
|
+
since: '6.1'
|
|
67
|
+
});
|
|
68
|
+
return useEntityRecord(kind, name, recordId, options);
|
|
69
|
+
}
|
|
59
70
|
//# sourceMappingURL=use-entity-record.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useQuerySelect","store","coreStore","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["deprecated","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;;AA+BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4BX,cAAc,CAC7CY,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEV,SAAF,CAAL,CAAmBW,eAAnB,CAAoCT,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GAN8C,EAO/C,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAP+C,CAAhD;AAUA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA;AAED,OAAO,SAASG,6BAAT,CACNV,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACDR,EAAAA,UAAU,CAAG,uCAAH,EAA2C;AACpDgB,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAA3C,CAAV;AAIA,SAAOb,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\nimport useEntityRecords from './use-entity-records';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { addQueryArgs } from '@wordpress/url';
|
|
5
|
+
import deprecated from '@wordpress/deprecated';
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import useQuerySelect from './use-query-select';
|
|
10
11
|
import { store as coreStore } from '../';
|
|
11
|
-
|
|
12
|
+
const EMPTY_ARRAY = [];
|
|
12
13
|
/**
|
|
13
14
|
* Resolves the specified entity records.
|
|
14
15
|
*
|
|
15
|
-
* @param kind Kind of the
|
|
16
|
-
* @param name Name of the
|
|
17
|
-
* @param queryArgs HTTP query for the requested
|
|
18
|
-
* @param options
|
|
16
|
+
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
|
|
17
|
+
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
|
|
18
|
+
* @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
|
|
19
|
+
* @param options Optional hook options.
|
|
19
20
|
* @example
|
|
20
21
|
* ```js
|
|
21
22
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -47,7 +48,8 @@ import { store as coreStore } from '../';
|
|
|
47
48
|
* @return Entity records data.
|
|
48
49
|
* @template RecordType
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
+
|
|
52
|
+
export default function useEntityRecords(kind, name) {
|
|
51
53
|
let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
52
54
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
53
55
|
enabled: true
|
|
@@ -63,7 +65,8 @@ export default function __experimentalUseEntityRecords(kind, name) {
|
|
|
63
65
|
} = useQuerySelect(query => {
|
|
64
66
|
if (!options.enabled) {
|
|
65
67
|
return {
|
|
66
|
-
|
|
68
|
+
// Avoiding returning a new reference on every execution.
|
|
69
|
+
data: EMPTY_ARRAY
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
|
|
@@ -74,4 +77,11 @@ export default function __experimentalUseEntityRecords(kind, name) {
|
|
|
74
77
|
...rest
|
|
75
78
|
};
|
|
76
79
|
}
|
|
80
|
+
export function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
|
|
81
|
+
deprecated(`wp.data.__experimentalUseEntityRecords`, {
|
|
82
|
+
alternative: 'wp.data.useEntityRecords',
|
|
83
|
+
since: '6.1'
|
|
84
|
+
});
|
|
85
|
+
return useEntityRecords(kind, name, queryArgs, options);
|
|
86
|
+
}
|
|
77
87
|
//# sourceMappingURL=use-entity-records.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["addQueryArgs","useQuerySelect","store","coreStore","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AAWA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAGZ,YAAY,CAAE,EAAF,EAAMS,SAAN,CAAlC;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6Bb,cAAc,CAC9Cc,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEZ,SAAF,CAAL,CAAmBa,gBAAnB,CAAqCV,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GAT+C,EAUhD,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVgD,CAAjD;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;AAED,OAAO,SAASG,8BAAT,CACNX,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,wCAAH,EAA4C;AACrDkB,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAA5C,CAAV;AAIA,SAAOd,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options, EntityRecordResolution } from './use-entity-record';\n\ntype EntityRecordsResolution< RecordType > = Omit<\n\tEntityRecordResolution< RecordType >,\n\t'record'\n> & {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n};\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -89,9 +89,8 @@ const storeConfig = () => ({
|
|
|
89
89
|
export const store = createReduxStore(STORE_NAME, storeConfig());
|
|
90
90
|
register(store);
|
|
91
91
|
export { default as EntityProvider } from './entity-provider';
|
|
92
|
-
export { default as __experimentalUseEntityRecord } from './hooks/use-entity-record';
|
|
93
|
-
export { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';
|
|
94
92
|
export * from './entity-provider';
|
|
95
|
-
export * from './fetch';
|
|
96
93
|
export * from './entity-types';
|
|
94
|
+
export * from './fetch';
|
|
95
|
+
export * from './hooks';
|
|
97
96
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAOC,kBAAP,MAA+B,iBAA/B;AACA,SAASC,kBAA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,OAAGO;AAAnB,GAHgB;AAI3BL,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGgB;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMS,KAAK,GAAG9B,gBAAgB,CAAES,UAAF,EAAcoB,WAAW,EAAzB,CAA9B;AAEP5B,QAAQ,CAAE6B,KAAF,CAAR;AAEA,SAASC,OAAO,IAAIC,cAApB,QAA0C,mBAA1C;AACA,cAAc,mBAAd;AACA,cAAc,gBAAd;AACA,cAAc,SAAd;AACA,cAAc,SAAd","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|
|
@@ -83,6 +83,10 @@ export function getQueryParts(query) {
|
|
|
83
83
|
if (key === 'include') {
|
|
84
84
|
var _getNormalizedCommaSe2;
|
|
85
85
|
|
|
86
|
+
if (typeof value === 'number') {
|
|
87
|
+
value = value.toString();
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
parts.include = ((_getNormalizedCommaSe2 = getNormalizedCommaSeparable(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number); // Normalize value for `stableKey`.
|
|
87
91
|
|
|
88
92
|
value = parts.include.join();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,2BAA3B,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC;AACD;AACA;AACC,QAAMC,KAAK,GAAG;AACbC,IAAAA,SAAS,EAAE,EADE;AAEbC,IAAAA,IAAI,EAAE,CAFO;AAGbC,IAAAA,OAAO,EAAE,EAHI;AAIbC,IAAAA,MAAM,EAAE,IAJK;AAKbC,IAAAA,OAAO,EAAE,IALI;AAMbC,IAAAA,OAAO,EAAE;AANI,GAAd,CAJsC,CAatC;;AACA,QAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAaR,KAAb,EAAqBU,IAArB,EAAb;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,GAAG,GAAGL,IAAI,CAAEG,CAAF,CAAhB;AACA,QAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAF,CAAjB;;AAEA,YAASA,GAAT;AACC,WAAK,MAAL;AACCZ,QAAAA,KAAK,CAAEY,GAAF,CAAL,GAAeE,MAAM,CAAED,KAAF,CAArB;AACA;;AAED,WAAK,UAAL;AACCb,QAAAA,KAAK,CAACG,OAAN,GAAgBW,MAAM,CAAED,KAAF,CAAtB;AACA;;AAED,WAAK,SAAL;AACCb,QAAAA,KAAK,CAACM,OAAN,GAAgBO,KAAhB;AACA;;AAED;AACC;AACA;AACA;AACA;AACA;AACA,YAAKD,GAAG,KAAK,SAAb,EAAyB;AAAA;;AACxBZ,UAAAA,KAAK,CAACI,MAAN,4BAAeP,2BAA2B,CAAEgB,KAAF,CAA1C,yEAAuD,EAAvD,CADwB,CAExB;;AACAA,UAAAA,KAAK,GAAGb,KAAK,CAACI,MAAN,CAAaW,IAAb,EAAR;AACA,SAVF,CAYC;;;AACA,YAAKH,GAAG,KAAK,SAAb,EAAyB;AAAA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","toString","map","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,2BAA3B,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC;AACD;AACA;AACC,QAAMC,KAAK,GAAG;AACbC,IAAAA,SAAS,EAAE,EADE;AAEbC,IAAAA,IAAI,EAAE,CAFO;AAGbC,IAAAA,OAAO,EAAE,EAHI;AAIbC,IAAAA,MAAM,EAAE,IAJK;AAKbC,IAAAA,OAAO,EAAE,IALI;AAMbC,IAAAA,OAAO,EAAE;AANI,GAAd,CAJsC,CAatC;;AACA,QAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAaR,KAAb,EAAqBU,IAArB,EAAb;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,GAAG,GAAGL,IAAI,CAAEG,CAAF,CAAhB;AACA,QAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAF,CAAjB;;AAEA,YAASA,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{ addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"]}
|