@wordpress/core-data 4.2.1 → 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 +5 -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
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,gBAAQC,GAAR,EAA+B;AAAA,MAAlBC,OAAkB,uEAAR,EAAQ;AACnD,QAAMC,QAAQ,GAAG,iCAAjB;AAEA,QAAMC,IAAI,GAAG;AACZH,IAAAA,GAAG,EAAE,sBAAaA,GAAb;AADO,GAAb;;AAIA,MAAK,CAAE,gBAAOA,GAAP,CAAP,EAAsB;AACrB,WAAOI,OAAO,CAACC,MAAR,CAAiB,GAAGL,GAAK,sBAAzB,CAAP;AACA,GATkD,CAWnD;AACA;;;AACA,QAAMM,QAAQ,GAAG,sBAAaN,GAAb,CAAjB;;AAEA,MACC,CAAE,0BAAiBM,QAAjB,CAAF,IACA,CAAEA,QAAQ,CAACC,UAAT,CAAqB,MAArB,CADF,IAEA,CAAE,uBAAuBC,IAAvB,CAA6BR,GAA7B,CAHH,EAIE;AACD,WAAOI,OAAO,CAACC,MAAR,CACL,GAAGL,GAAK,4DADH,CAAP;AAGA;;AAED,MAAKH,KAAK,CAACY,GAAN,CAAWT,GAAX,CAAL,EAAwB;AACvB,WAAOH,KAAK,CAACa,GAAN,CAAWV,GAAX,CAAP;AACA;;AAED,SAAO,uBAAU;AAChBW,IAAAA,IAAI,EAAE,uBAAcT,QAAd,EAAwBC,IAAxB,CADU;AAEhB,OAAGF;AAFa,GAAV,EAGHW,IAHG,CAGKC,GAAF,IAAW;AACpBhB,IAAAA,KAAK,CAACiB,GAAN,CAAWd,GAAX,EAAgBa,GAAhB;AACA,WAAOA,GAAP;AACA,GANM,CAAP;AAOA,CApCD;;eAsCed,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\taddQueryArgs,\n\tprependHTTP,\n\tisURL,\n\tgetProtocol,\n\tisValidProtocol,\n} from '@wordpress/url';\n\n/**\n * A simple in-memory cache for requests.\n * This avoids repeat HTTP requests which may be beneficial\n * for those wishing to preserve low-bandwidth.\n */\nconst CACHE = new Map();\n\n/**\n * @typedef WPRemoteUrlData\n *\n * @property {string} title contents of the remote URL's `<title>` tag.\n */\n\n/**\n * Fetches data about a remote URL.\n * eg: <title> tag, favicon...etc.\n *\n * @async\n * @param {string} url the URL to request details from.\n * @param {Object?} options any options to pass to the underlying fetch.\n * @example\n * ```js\n * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchUrlData = (\n * url\n * ) => fetchUrlData( url );\n * ```\n * @return {Promise< WPRemoteUrlData[] >} Remote URL data.\n */\nconst fetchUrlData = async ( url, options = {} ) => {\n\tconst endpoint = '/wp-block-editor/v1/url-details';\n\n\tconst args = {\n\t\turl: prependHTTP( url ),\n\t};\n\n\tif ( ! isURL( url ) ) {\n\t\treturn Promise.reject( `${ url } is not a valid URL.` );\n\t}\n\n\t// Test for \"http\" based URL as it is possible for valid\n\t// yet unusable URLs such as `tel:123456` to be passed.\n\tconst protocol = getProtocol( url );\n\n\tif (\n\t\t! isValidProtocol( protocol ) ||\n\t\t! protocol.startsWith( 'http' ) ||\n\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( url )\n\t) {\n\t\treturn Promise.reject(\n\t\t\t`${ url } does not have a valid protocol. URLs must be \"http\" based`\n\t\t);\n\t}\n\n\tif ( CACHE.has( url ) ) {\n\t\treturn CACHE.get( url );\n\t}\n\n\treturn apiFetch( {\n\t\tpath: addQueryArgs( endpoint, args ),\n\t\t...options,\n\t} ).then( ( res ) => {\n\t\tCACHE.set( url, res );\n\t\treturn res;\n\t} );\n};\n\nexport default fetchUrlData;\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,gBAAQC,GAAR,EAA+B;AAAA,MAAlBC,OAAkB,uEAAR,EAAQ;AACnD,QAAMC,QAAQ,GAAG,iCAAjB;AAEA,QAAMC,IAAI,GAAG;AACZH,IAAAA,GAAG,EAAE,sBAAaA,GAAb;AADO,GAAb;;AAIA,MAAK,CAAE,gBAAOA,GAAP,CAAP,EAAsB;AACrB,WAAOI,OAAO,CAACC,MAAR,CAAiB,GAAGL,GAAK,sBAAzB,CAAP;AACA,GATkD,CAWnD;AACA;;;AACA,QAAMM,QAAQ,GAAG,sBAAaN,GAAb,CAAjB;;AAEA,MACC,CAAEM,QAAF,IACA,CAAE,0BAAiBA,QAAjB,CADF,IAEA,CAAEA,QAAQ,CAACC,UAAT,CAAqB,MAArB,CAFF,IAGA,CAAE,uBAAuBC,IAAvB,CAA6BR,GAA7B,CAJH,EAKE;AACD,WAAOI,OAAO,CAACC,MAAR,CACL,GAAGL,GAAK,4DADH,CAAP;AAGA;;AAED,MAAKH,KAAK,CAACY,GAAN,CAAWT,GAAX,CAAL,EAAwB;AACvB,WAAOH,KAAK,CAACa,GAAN,CAAWV,GAAX,CAAP;AACA;;AAED,SAAO,uBAAU;AAChBW,IAAAA,IAAI,EAAE,uBAAcT,QAAd,EAAwBC,IAAxB,CADU;AAEhB,OAAGF;AAFa,GAAV,EAGHW,IAHG,CAGKC,GAAF,IAAW;AACpBhB,IAAAA,KAAK,CAACiB,GAAN,CAAWd,GAAX,EAAgBa,GAAhB;AACA,WAAOA,GAAP;AACA,GANM,CAAP;AAOA,CArCD;;eAuCed,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\taddQueryArgs,\n\tprependHTTP,\n\tisURL,\n\tgetProtocol,\n\tisValidProtocol,\n} from '@wordpress/url';\n\n/**\n * A simple in-memory cache for requests.\n * This avoids repeat HTTP requests which may be beneficial\n * for those wishing to preserve low-bandwidth.\n */\nconst CACHE = new Map();\n\n/**\n * @typedef WPRemoteUrlData\n *\n * @property {string} title contents of the remote URL's `<title>` tag.\n */\n\n/**\n * Fetches data about a remote URL.\n * eg: <title> tag, favicon...etc.\n *\n * @async\n * @param {string} url the URL to request details from.\n * @param {Object?} options any options to pass to the underlying fetch.\n * @example\n * ```js\n * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchUrlData = (\n * url\n * ) => fetchUrlData( url );\n * ```\n * @return {Promise< WPRemoteUrlData[] >} Remote URL data.\n */\nconst fetchUrlData = async ( url, options = {} ) => {\n\tconst endpoint = '/wp-block-editor/v1/url-details';\n\n\tconst args = {\n\t\turl: prependHTTP( url ),\n\t};\n\n\tif ( ! isURL( url ) ) {\n\t\treturn Promise.reject( `${ url } is not a valid URL.` );\n\t}\n\n\t// Test for \"http\" based URL as it is possible for valid\n\t// yet unusable URLs such as `tel:123456` to be passed.\n\tconst protocol = getProtocol( url );\n\n\tif (\n\t\t! protocol ||\n\t\t! isValidProtocol( protocol ) ||\n\t\t! protocol.startsWith( 'http' ) ||\n\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( url )\n\t) {\n\t\treturn Promise.reject(\n\t\t\t`${ url } does not have a valid protocol. URLs must be \"http\" based`\n\t\t);\n\t}\n\n\tif ( CACHE.has( url ) ) {\n\t\treturn CACHE.get( url );\n\t}\n\n\treturn apiFetch( {\n\t\tpath: addQueryArgs( endpoint, args ),\n\t\t...options,\n\t} ).then( ( res ) => {\n\t\tCACHE.set( url, res );\n\t\treturn res;\n\t} );\n};\n\nexport default fetchUrlData;\n"]}
@@ -18,10 +18,11 @@ var _ = require("../");
18
18
  /**
19
19
  * Resolves the specified entity record.
20
20
  *
21
- * @param kind Kind of the requested entity.
22
- * @param name Name of the requested entity.
23
- * @param recordId Record ID of the requested entity.
24
- *
21
+ * @param kind Kind of the requested entity.
22
+ * @param name Name of the requested entity.
23
+ * @param recordId Record ID of the requested entity.
24
+ * @param options Hook options.
25
+ * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
25
26
  * @example
26
27
  * ```js
27
28
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -48,10 +49,19 @@ var _ = require("../");
48
49
  * @template RecordType
49
50
  */
50
51
  function __experimentalUseEntityRecord(kind, name, recordId) {
52
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
53
+ enabled: true
54
+ };
51
55
  const {
52
56
  data: record,
53
57
  ...rest
54
- } = (0, _useQuerySelect.default)(query => query(_.store).getEntityRecord(kind, name, recordId), [kind, name, recordId]);
58
+ } = (0, _useQuerySelect.default)(query => {
59
+ if (!options.enabled) {
60
+ return null;
61
+ }
62
+
63
+ return query(_.store).getEntityRecord(kind, name, recordId);
64
+ }, [kind, name, recordId, options.enabled]);
55
65
  return {
56
66
  record,
57
67
  ...rest
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAuBA;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;AACe,SAASA,6BAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAIyB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAaA,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCR,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CADoB,EAEjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,CAFiC,CAAlC;AAKA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\n\ninterface 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\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the requested entity.\n * @param name Name of the requested entity.\n * @param recordId Record ID of the requested entity.\n *\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 {EntityRecordResolution<RecordType>} Entity record data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => query( coreStore ).getEntityRecord( kind, name, recordId ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AA2BA;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;AACe,SAASA,6BAAT,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,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\ninterface 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\ninterface Options {\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the requested entity.\n * @param name Name of the requested entity.\n * @param recordId Record ID of the requested entity.\n * @param options Hook options.\n * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.\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 {EntityRecordResolution<RecordType>} Entity record data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecord< 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"]}
@@ -24,9 +24,10 @@ var _ = require("../");
24
24
  /**
25
25
  * Resolves the specified entity records.
26
26
  *
27
- * @param kind Kind of the requested entities.
28
- * @param name Name of the requested entities.
29
- * @param queryArgs HTTP query for the requested entities.
27
+ * @param kind Kind of the requested entities.
28
+ * @param name Name of the requested entities.
29
+ * @param queryArgs HTTP query for the requested entities.
30
+ * @param options Hook options.
30
31
  * @example
31
32
  * ```js
32
33
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -55,11 +56,14 @@ var _ = require("../");
55
56
  * application, the list of records and the resolution details will be retrieved from
56
57
  * the store state using `getEntityRecords()`, or resolved if missing.
57
58
  *
58
- * @return {EntityRecordsResolution<RecordType>} Entity records data.
59
+ * @return Entity records data.
59
60
  * @template RecordType
60
61
  */
61
62
  function __experimentalUseEntityRecords(kind, name) {
62
63
  let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
64
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
65
+ enabled: true
66
+ };
63
67
  // Serialize queryArgs to a string that can be safely used as a React dep.
64
68
  // We can't just pass queryArgs as one of the deps, because if it is passed
65
69
  // as an object literal, then it will be a different object on each call even
@@ -68,7 +72,15 @@ function __experimentalUseEntityRecords(kind, name) {
68
72
  const {
69
73
  data: records,
70
74
  ...rest
71
- } = (0, _useQuerySelect.default)(query => query(_.store).getEntityRecords(kind, name, queryArgs), [kind, name, queryAsString]);
75
+ } = (0, _useQuerySelect.default)(query => {
76
+ if (!options.enabled) {
77
+ return {
78
+ data: []
79
+ };
80
+ }
81
+
82
+ return query(_.store).getEntityRecords(kind, name, queryArgs);
83
+ }, [kind, name, queryAsString, options.enabled]);
72
84
  return {
73
85
  records,
74
86
  ...rest
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAuBA;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;AACe,SAASA,8BAAT,CACdC,IADc,EAEdC,IAFc,EAI0B;AAAA,MADxCC,SACwC,uEADnB,EACmB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBD,SAAlB,CAAtB;AAEA,QAAM;AAAEE,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IACCA,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCT,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAFiC,EAGlC,CAAEF,IAAF,EAAQC,IAAR,EAAcE,aAAd,CAHkC,CAAnC;AAMA,SAAO;AACNE,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: 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\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the requested entities.\n * @param name Name of the requested entities.\n * @param queryArgs HTTP query for the requested entities.\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 {EntityRecordsResolution<RecordType>} Entity records data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: unknown = {}\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\tquery( coreStore ).getEntityRecords( kind, name, queryArgs ),\n\t\t[ kind, name, queryAsString ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAgCA;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;AACe,SAASA,8BAAT,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,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACNE,QAAAA,IAAI,EAAE;AADA,OAAP;AAGA;;AACD,WAAOG,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GARiC,EASlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CATkC,CAAnC;AAYA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: 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\ninterface 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 records.\n *\n * @param kind Kind of the requested entities.\n * @param name Name of the requested entities.\n * @param queryArgs HTTP query for the requested entities.\n * @param options 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 __experimentalUseEntityRecords< 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\tdata: [],\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"]}
package/build/index.js CHANGED
@@ -105,10 +105,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
105
105
  * Internal dependencies
106
106
  */
107
107
  // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
108
- // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
109
- // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...
108
+ // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
109
+ // Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
110
110
  // The "kind" and the "name" of the entity are combined to generate these shortcuts.
111
- const entitySelectors = _entities.defaultEntities.reduce((result, entity) => {
111
+ const entitySelectors = _entities.rootEntitiesConfig.reduce((result, entity) => {
112
112
  const {
113
113
  kind,
114
114
  name
@@ -116,18 +116,12 @@ const entitySelectors = _entities.defaultEntities.reduce((result, entity) => {
116
116
 
117
117
  result[(0, _entities.getMethodName)(kind, name)] = (state, key, query) => selectors.getEntityRecord(state, kind, name, key, query);
118
118
 
119
- result[(0, _entities.getMethodName)(kind, name, 'get', true)] = function (state) {
120
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
121
- args[_key - 1] = arguments[_key];
122
- }
123
-
124
- return selectors.getEntityRecords(state, kind, name, ...args);
125
- };
119
+ result[(0, _entities.getMethodName)(kind, name, 'get', true)] = (state, query) => selectors.getEntityRecords(state, kind, name, query);
126
120
 
127
121
  return result;
128
122
  }, {});
129
123
 
130
- const entityResolvers = _entities.defaultEntities.reduce((result, entity) => {
124
+ const entityResolvers = _entities.rootEntitiesConfig.reduce((result, entity) => {
131
125
  const {
132
126
  kind,
133
127
  name
@@ -138,25 +132,19 @@ const entityResolvers = _entities.defaultEntities.reduce((result, entity) => {
138
132
  const pluralMethodName = (0, _entities.getMethodName)(kind, name, 'get', true);
139
133
 
140
134
  result[pluralMethodName] = function () {
141
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
142
- args[_key2] = arguments[_key2];
135
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
136
+ args[_key] = arguments[_key];
143
137
  }
144
138
 
145
139
  return resolvers.getEntityRecords(kind, name, ...args);
146
140
  };
147
141
 
148
- result[pluralMethodName].shouldInvalidate = function (action) {
149
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
150
- args[_key3 - 1] = arguments[_key3];
151
- }
152
-
153
- return resolvers.getEntityRecords.shouldInvalidate(action, kind, name, ...args);
154
- };
142
+ result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
155
143
 
156
144
  return result;
157
145
  }, {});
158
146
 
159
- const entityActions = _entities.defaultEntities.reduce((result, entity) => {
147
+ const entityActions = _entities.rootEntitiesConfig.reduce((result, entity) => {
160
148
  const {
161
149
  kind,
162
150
  name
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","defaultEntities","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","args","getEntityRecords","entityResolvers","resolvers","pluralMethodName","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA4DA;;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAFA;;AACA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA/EA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,0BAAgBC,MAAhB,CAAwB,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACrE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA2BJ,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,EAAmDC,KAAnD,CADD;;AAEAN,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,KAA3B,EAAkC,IAAlC,CAAF,CAAN,GAAqD,UAAEC,KAAF;AAAA,sCAAYK,IAAZ;AAAYA,MAAAA,IAAZ;AAAA;;AAAA,WACpDF,SAAS,CAACG,gBAAV,CAA4BN,KAA5B,EAAmCF,IAAnC,EAAyCC,IAAzC,EAA+C,GAAGM,IAAlD,CADoD;AAAA,GAArD;;AAEA,SAAOT,MAAP;AACA,CAPuB,EAOrB,EAPqB,CAAxB;;AASA,MAAMW,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IAA1B,EAAgCC,IAAhC,EAAsCE,GAAtC,CADD;;AAEAL,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,QAA3B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Be,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMW,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { defaultEntities, 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, updateEntityRecordss)\n// Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = defaultEntities.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, ...args ) =>\n\t\tselectors.getEntityRecords( state, kind, name, ...args );\n\treturn result;\n}, {} );\n\nconst entityResolvers = defaultEntities.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, ...args ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate(\n\t\t\taction,\n\t\t\tkind,\n\t\t\tname,\n\t\t\t...args\n\t\t);\n\treturn result;\n}, {} );\n\nconst entityActions = defaultEntities.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 { default as __experimentalUseEntityRecord } from './hooks/use-entity-record';\nexport { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';\nexport * from './entity-provider';\nexport * from './fetch';\nexport * from './entity-types';\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAFA;;AACA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA1EA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA2BJ,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,EAAmDC,KAAnD,CADD;;AAEAN,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,KAA3B,EAAkC,IAAlC,CAAF,CAAN,GAAqD,CAAEC,KAAF,EAASE,KAAT,KACpDC,SAAS,CAACE,gBAAV,CAA4BL,KAA5B,EAAmCF,IAAnC,EAAyCC,IAAzC,EAA+CG,KAA/C,CADD;;AAEA,SAAON,MAAP;AACA,CAPuB,EA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AAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,QAA3B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Bc,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport { default as __experimentalUseEntityRecord } from './hooks/use-entity-record';\nexport { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';\nexport * from './entity-provider';\nexport * from './fetch';\nexport * from './entity-types';\n"]}
@@ -32,10 +32,10 @@ function receiveItems(items, edits) {
32
32
  * Returns an action object used in signalling that entity records have been
33
33
  * deleted and they need to be removed from entities state.
34
34
  *
35
- * @param {string} kind Kind of the removed entities.
36
- * @param {string} name Name of the removed entities.
37
- * @param {Array|number} records Record IDs of the removed entities.
38
- * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
35
+ * @param {string} kind Kind of the removed entities.
36
+ * @param {string} name Name of the removed entities.
37
+ * @param {Array|number|string} records Record IDs of the removed entities.
38
+ * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
39
39
  * @return {Object} Action object.
40
40
  */
41
41
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAE,uBAAWA,KAAX,CAFD;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,EAAqE;AAAA,MAA1BC,eAA0B,uEAAR,KAAQ;AAC3E,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENO,IAAAA,OAAO,EAAE,uBAAWF,OAAX,CAFH;AAGNF,IAAAA,IAHM;AAINC,IAAAA,IAJM;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,mBAAT,CAA8BV,KAA9B,EAAyD;AAAA,MAApBW,KAAoB,uEAAZ,EAAY;AAAA,MAARV,KAAQ;AAC/D,SAAO,EACN,GAAGF,YAAY,CAAEC,KAAF,EAASC,KAAT,CADT;AAENU,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { castArray } from 'lodash';\n\n/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: castArray( items ),\n\t\tpersistedEdits: edits,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: castArray( records ),\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits ) {\n\treturn {\n\t\t...receiveItems( items, edits ),\n\t\tquery,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAE,uBAAWA,KAAX,CAFD;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,EAAqE;AAAA,MAA1BC,eAA0B,uEAAR,KAAQ;AAC3E,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENO,IAAAA,OAAO,EAAE,uBAAWF,OAAX,CAFH;AAGNF,IAAAA,IAHM;AAINC,IAAAA,IAJM;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,mBAAT,CAA8BV,KAA9B,EAAyD;AAAA,MAApBW,KAAoB,uEAAZ,EAAY;AAAA,MAARV,KAAQ;AAC/D,SAAO,EACN,GAAGF,YAAY,CAAEC,KAAF,EAASC,KAAT,CADT;AAENU,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { castArray } from 'lodash';\n\n/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: castArray( items ),\n\t\tpersistedEdits: edits,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number|string} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: castArray( records ),\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits ) {\n\treturn {\n\t\t...receiveItems( items, edits ),\n\t\tquery,\n\t};\n}\n"]}
@@ -79,17 +79,21 @@ function getQueryParts(query) {
79
79
  // While in theory, we could exclude "_fields" from the stableKey
80
80
  // because two request with different fields have the same results
81
81
  // We're not able to ensure that because the server can decide to omit
82
- // fields from the response even if we explicitely asked for it.
82
+ // fields from the response even if we explicitly asked for it.
83
83
  // Example: Asking for titles in posts without title support.
84
84
  if (key === '_fields') {
85
- parts.fields = (0, _utils.getNormalizedCommaSeparable)(value); // Make sure to normalize value for `stableKey`
85
+ var _getNormalizedCommaSe;
86
+
87
+ parts.fields = (_getNormalizedCommaSe = (0, _utils.getNormalizedCommaSeparable)(value)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; // Make sure to normalize value for `stableKey`
86
88
 
87
89
  value = parts.fields.join();
88
90
  } // Two requests with different include values cannot have same results.
89
91
 
90
92
 
91
93
  if (key === 'include') {
92
- parts.include = (0, _utils.getNormalizedCommaSeparable)(value).map(Number); // Normalize value for `stableKey`.
94
+ var _getNormalizedCommaSe2;
95
+
96
+ parts.include = ((_getNormalizedCommaSe2 = (0, _utils.getNormalizedCommaSeparable)(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number); // Normalize value for `stableKey`.
93
97
 
94
98
  value = parts.include.join();
95
99
  } // While it could be any deterministic string, for simplicity's
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":";;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SA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AGb,KAAK,CAACK,OAAN,CAAcU,IAAd,EAAR;AACA,SAnBF,CAqBC;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAf,QAAAA,KAAK,CAACC,SAAN,IACC,CAAED,KAAK,CAACC,SAAN,GAAkB,GAAlB,GAAwB,EAA1B,IACA,uBAAc,EAAd,EAAkB;AAAE,WAAEW,GAAF,GAASC;AAAX,SAAlB,EAAuCI,KAAvC,CAA8C,CAA9C,CAFD;AAzCF;AA6CA;;AAED,SAAOjB,KAAP;AACA;;eAEc,6BAAkBF,aAAlB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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 explicitely 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\tparts.include = getNormalizedCommaSeparable( value ).map(\n\t\t\t\t\t\tNumber\n\t\t\t\t\t);\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"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":";;;;;;;;AAG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Ab,EAAR;AACA,SAVF,CAYC;;;AACA,YAAKH,GAAG,KAAK,SAAb,EAAyB;AAAA;;AACxBZ,UAAAA,KAAK,CAACK,OAAN,GAAgB,2BACf,wCAA6BQ,KAA7B,CADe,2EACyB,EADzB,EAEdG,GAFc,CAETF,MAFS,CAAhB,CADwB,CAIxB;;AACAD,UAAAA,KAAK,GAAGb,KAAK,CAACK,OAAN,CAAcU,IAAd,EAAR;AACA,SAnBF,CAqBC;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAf,QAAAA,KAAK,CAACC,SAAN,IACC,CAAED,KAAK,CAACC,SAAN,GAAkB,GAAlB,GAAwB,EAA1B,IACA,uBAAc,EAAd,EAAkB;AAAE,WAAEW,GAAF,GAASC;AAAX,SAAlB,EAAuCI,KAAvC,CAA8C,CAA9C,CAFD;AAzCF;AA6CA;;AAED,SAAOjB,KAAP;AACA;;eAEc,6BAAkBF,aAAlB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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\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"]}
@@ -57,6 +57,8 @@ function getContextFromAction(action) {
57
57
 
58
58
 
59
59
  function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
60
+ var _itemIds$length;
61
+
60
62
  const receivedAllIds = page === 1 && perPage === -1;
61
63
 
62
64
  if (receivedAllIds) {
@@ -66,14 +68,14 @@ function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
66
68
  const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known
67
69
  // size of the existing array, else calculate as extending the existing.
68
70
 
69
- const size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
71
+ const size = Math.max((_itemIds$length = itemIds === null || itemIds === void 0 ? void 0 : itemIds.length) !== null && _itemIds$length !== void 0 ? _itemIds$length : 0, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
70
72
 
71
73
  const mergedItemIds = new Array(size);
72
74
 
73
75
  for (let i = 0; i < size; i++) {
74
76
  // Preserve existing item ID except for subset of range of next items.
75
77
  const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length;
76
- mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i];
78
+ mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds === null || itemIds === void 0 ? void 0 : itemIds[i];
77
79
  }
78
80
 
79
81
  return mergedItemIds;
@@ -124,10 +126,10 @@ function items() {
124
126
  * In such cases, completeness is used as an indication of whether it would be
125
127
  * safe to use queried data for a non-`_fields`-limited request.
126
128
  *
127
- * @param {Object<string,boolean>} state Current state.
128
- * @param {Object} action Dispatched action.
129
+ * @param {Object<string,Object<string,boolean>>} state Current state.
130
+ * @param {Object} action Dispatched action.
129
131
  *
130
- * @return {Object<string,boolean>} Next state.
132
+ * @return {Object<string,Object<string,boolean>>} Next state.
131
133
  */
132
134
 
133
135
 
@@ -145,7 +147,7 @@ function itemIsComplete() {
145
147
  } = action; // An item is considered complete if it is received without an associated
146
148
  // fields query. Ideally, this would be implemented in such a way where the
147
149
  // complete aggregate of all fields would satisfy completeness. Since the
148
- // fields are not consistent across all entity types, this would require
150
+ // fields are not consistent across all entities, this would require
149
151
  // introspection on the REST schema for each entity to know which fields
150
152
  // compose a complete item for that entity.
151
153
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AAKA;;AAMA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oBAAT,CAA+BC,MAA/B,EAAwC;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAYD,MAAlB;;AACA,MAAK,CAAEC,KAAP,EAAe;AACd,WAAO,SAAP;AACA;;AAED,QAAMC,UAAU,GAAG,4BAAeD,KAAf,CAAnB;AACA,SAAOC,UAAU,CAACC,OAAlB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BC,OAA3B,EAAoCC,WAApC,EAAiDC,IAAjD,EAAuDC,OAAvD,EAAiE;AACvE,QAAMC,cAAc,GAAGF,IAAI,KAAK,CAAT,IAAcC,OAAO,KAAK,CAAC,CAAlD;;AACA,MAAKC,cAAL,EAAsB;AACrB,WAAOH,WAAP;AACA;;AACD,QAAMI,qBAAqB,GAAG,C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,EAAgB;AAAA,MAAZpB,MAAY;;AACzC,UAASA,MAAM,CAACqB,IAAhB;AACC,SAAK,eAAL;AACC,aAAOc,cAAc,CAAEf,KAAF,EAASpB,MAAT,CAArB;;AACD,SAAK,cAAL;AACC,YAAMqC,YAAY,GAAGrC,MAAM,CAACK,OAAP,CAAemB,MAAf,CAAuB,CAAES,MAAF,EAAUN,MAAV,KAAsB;AACjEM,QAAAA,MAAM,CAAEN,MAAF,CAAN,GAAmB,IAAnB;AACA,eAAOM,MAAP;AACA,OAHoB,EAGlB,EAHkB,CAArB;AAKA,aAAO,uBAAWb,KAAX,EAAoBkB,cAAF,IAAsB;AAC9C,eAAO,uBAAWA,cAAX,EAA6BC,UAAF,IAAkB;AACnD,iBAAO,oBAAQA,UAAR,EAAsBC,OAAF,IAAe;AACzC,mBAAO,CAAEH,YAAY,CAAEG,OAAF,CAArB;AACA,WAFM,CAAP;AAGA,SAJM,CAAP;AAKA,OANM,CAAP;;AAOD;AACC,aAAOpB,KAAP;AAjBF;AAmBA,CApBD;;eAsBe,2BAAiB;AAC/BD,EAAAA,KAD+B;AAE/BU,EAAAA,cAF+B;AAG/BO,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} 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 {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds[ i ];\n\t}\n\n\treturn mergedItemIds;\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\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...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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,boolean>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {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\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 entity types, 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...action.items.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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 `onSubKey` 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. `onSubKey` 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\tonSubKey( '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\tonSubKey( 'stableKey' ),\n] )( ( state = null, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AAKA;;AAMA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oBAAT,CAA+BC,MAA/B,EAAwC;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAYD,MAAlB;;AACA,MAAK,CAAEC,KAAP,EAAe;AACd,WAAO,SAAP;AACA;;AAED,QAAMC,UAAU,GAAG,4BAAeD,KAAf,CAAnB;AACA,SAAOC,UAAU,CAACC,OAAlB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BC,OAA3B,EAAoCC,WAApC,EAAiDC,IAAjD,EAAuDC,OAAvD,EAAiE;AAAA;;AACvE,QAAMC,cAAc,GAAGF,IAAI,KAAK,CAAT,IAAcC,OAAO,KAAK,CAAC,CAAlD;;AACA,MAAKC,cAAL,EAAsB;AACrB,WAAOH,WAAP;AACA;;AACD,QAAMI,qBAAqB,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A;AACA;AACA;;AACA,MAAM4B,OAAO,GAAG,YAA0B;AAAA,MAAxBhB,KAAwB,uEAAhB,EAAgB;AAAA,MAAZpB,MAAY;;AACzC,UAASA,MAAM,CAACqB,IAAhB;AACC,SAAK,eAAL;AACC,aAAOc,cAAc,CAAEf,KAAF,EAASpB,MAAT,CAArB;;AACD,SAAK,cAAL;AACC,YAAMqC,YAAY,GAAGrC,MAAM,CAACK,OAAP,CAAemB,MAAf,CAAuB,CAAES,MAAF,EAAUN,MAAV,KAAsB;AACjEM,QAAAA,MAAM,CAAEN,MAAF,CAAN,GAAmB,IAAnB;AACA,eAAOM,MAAP;AACA,OAHoB,EAGlB,EAHkB,CAArB;AAKA,aAAO,uBAAWb,KAAX,EAAoBkB,cAAF,IAAsB;AAC9C,eAAO,uBAAWA,cAAX,EAA6BC,UAAF,IAAkB;AACnD,iBAAO,oBAAQA,UAAR,EAAsBC,OAAF,IAAe;AACzC,mBAAO,CAAEH,YAAY,CAAEG,OAAF,CAArB;AACA,WAFM,CAAP;AAGA,SAJM,CAAP;AAKA,OANM,CAAP;;AAOD;AACC,aAAOpB,KAAP;AAjBF;AAmBA,CApBD;;eAsBe,2BAAiB;AAC/BD,EAAAA,KAD+B;AAE/BU,EAAAA,cAF+B;AAG/BO,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} 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 {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\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 ?? 0,\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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\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\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...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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\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...action.items.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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 `onSubKey` 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. `onSubKey` 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\tonSubKey( '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\tonSubKey( 'stableKey' ),\n] )( ( state = null, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
package/build/reducer.js CHANGED
@@ -145,10 +145,10 @@ function taxonomies() {
145
145
  /**
146
146
  * Reducer managing the current theme.
147
147
  *
148
- * @param {string} state Current state.
149
- * @param {Object} action Dispatched action.
148
+ * @param {string|undefined} state Current state.
149
+ * @param {Object} action Dispatched action.
150
150
  *
151
- * @return {string} Updated state.
151
+ * @return {string|undefined} Updated state.
152
152
  */
153
153
 
154
154
 
@@ -166,10 +166,10 @@ function currentTheme() {
166
166
  /**
167
167
  * Reducer managing the current global styles id.
168
168
  *
169
- * @param {string} state Current state.
170
- * @param {Object} action Dispatched action.
169
+ * @param {string|undefined} state Current state.
170
+ * @param {Object} action Dispatched action.
171
171
  *
172
- * @return {string} Updated state.
172
+ * @return {string|undefined} Updated state.
173
173
  */
174
174
 
175
175
 
@@ -187,10 +187,10 @@ function currentGlobalStylesId() {
187
187
  /**
188
188
  * Reducer managing the theme base global styles.
189
189
  *
190
- * @param {string} state Current state.
191
- * @param {Object} action Dispatched action.
190
+ * @param {Record<string, object>} state Current state.
191
+ * @param {Object} action Dispatched action.
192
192
  *
193
- * @return {string} Updated state.
193
+ * @return {Record<string, object>} Updated state.
194
194
  */
195
195
 
196
196
 
@@ -210,10 +210,10 @@ function themeBaseGlobalStyles() {
210
210
  /**
211
211
  * Reducer managing the theme global styles variations.
212
212
  *
213
- * @param {string} state Current state.
214
- * @param {Object} action Dispatched action.
213
+ * @param {Record<string, object>} state Current state.
214
+ * @param {Object} action Dispatched action.
215
215
  *
216
- * @return {string} Updated state.
216
+ * @return {Record<string, object>} Updated state.
217
217
  */
218
218
 
219
219
 
@@ -368,7 +368,7 @@ function entity(entityConfig) {
368
368
 
369
369
 
370
370
  function entitiesConfig() {
371
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _entities.defaultEntities;
371
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _entities.rootEntitiesConfig;
372
372
  let action = arguments.length > 1 ? arguments[1] : undefined;
373
373
 
374
374
  switch (action.type) {
@@ -407,15 +407,15 @@ const entities = function () {
407
407
  }, {}));
408
408
  }
409
409
 
410
- const newData = entitiesDataReducer(state.data, action);
410
+ const newData = entitiesDataReducer(state.records, action);
411
411
 
412
- if (newData === state.data && newConfig === state.config && entitiesDataReducer === state.reducer) {
412
+ if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) {
413
413
  return state;
414
414
  }
415
415
 
416
416
  return {
417
417
  reducer: entitiesDataReducer,
418
- data: newData,
418
+ records: newData,
419
419
  config: newConfig
420
420
  };
421
421
  };