diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 61d0f8bd30f26..d543014dca2d7 100644 --- a/docs/reference-guides/data/data-core.md +++ b/docs/reference-guides/data/data-core.md @@ -21,7 +21,7 @@ _Parameters_ - _state_ `State`: Data state. - _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'. - _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'. -- _id_ `GenericRecordKey`: Optional ID of the rest resource to check. +- _id_ `EntityRecordKey`: Optional ID of the rest resource to check. _Returns_ @@ -39,9 +39,9 @@ Calling this may trigger an OPTIONS request to the REST API via the _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record's id. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record's id. _Returns_ @@ -56,11 +56,11 @@ Returns all available authors. _Parameters_ - _state_ `State`: Data state. -- _query_ `EntityQuery< any >`: Optional object of query parameters to include with request. +- _query_ `EntityQuery`: Optional object of query parameters to include with request. _Returns_ -- `User< 'edit' >[]`: Authors list. +- `User[]`: Authors list. ### getAutosave @@ -70,8 +70,8 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. -- _authorId_ `GenericRecordKey`: The id of the author. +- _postId_ `EntityRecordKey`: The id of the parent post. +- _authorId_ `EntityRecordKey`: The id of the author. _Returns_ @@ -88,7 +88,7 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. +- _postId_ `EntityRecordKey`: The id of the parent post. _Returns_ @@ -149,9 +149,9 @@ Returns the specified entity record, merged with its edits. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -179,7 +179,7 @@ Returns the loaded entities for the given kind. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. +- _kind_ `string`: Entity kind. _Returns_ @@ -192,7 +192,7 @@ Returns the loaded entities for the given kind. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. +- _kind_ `string`: Entity kind. _Returns_ @@ -207,8 +207,8 @@ Returns the entity config given its kind and name. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. _Returns_ @@ -221,8 +221,8 @@ Returns the entity config given its kind and name. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. _Returns_ @@ -237,10 +237,10 @@ entity object if it exists and is received. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _key_ `KeyOf< R >`: Record's key -- _query_ Optional query. If requesting specific fields, fields must always include the ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _key_ `EntityRecordKey`: Record's key +- _query_ `EntityQuery`: Optional query. If requesting specific fields, fields must always include the ID. _Returns_ @@ -253,9 +253,9 @@ Returns the specified entity record's edits. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -272,9 +272,9 @@ They are defined in the entity's config. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -287,13 +287,13 @@ Returns the Entity's records. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _query_ Optional terms query. If requesting specific fields, fields must always include the ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _query_ `EntityQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. _Returns_ -- Records. +- `EntityRecord[] | null`: Records. ### getLastEntityDeleteError @@ -302,9 +302,9 @@ Returns the specified entity record's last delete error. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -317,9 +317,9 @@ Returns the specified entity record's last save error. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -333,9 +333,9 @@ with its attributes mapped to their raw values. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _key_ `KeyOf< K, N >`: Record's key. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _key_ `EntityRecordKey`: Record's key. _Returns_ @@ -421,9 +421,9 @@ and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -437,9 +437,9 @@ or false otherwise. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _query_ `EntityQuery< C >`: Optional terms query. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _query_ `EntityQuery`: Optional terms query. _Returns_ @@ -453,7 +453,7 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. +- _postId_ `EntityRecordKey`: The id of the parent post. _Returns_ @@ -492,9 +492,9 @@ Returns true if the specified entity record is autosaving, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -507,9 +507,9 @@ Returns true if the specified entity record is deleting, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -553,9 +553,9 @@ Returns true if the specified entity record is saving, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ diff --git a/packages/core-data/README.md b/packages/core-data/README.md index 6001ee7a6ba14..f2535ffd4127a 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -189,7 +189,7 @@ _Parameters_ - _state_ `State`: Data state. - _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'. - _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'. -- _id_ `GenericRecordKey`: Optional ID of the rest resource to check. +- _id_ `EntityRecordKey`: Optional ID of the rest resource to check. _Returns_ @@ -207,9 +207,9 @@ Calling this may trigger an OPTIONS request to the REST API via the _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record's id. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record's id. _Returns_ @@ -224,11 +224,11 @@ Returns all available authors. _Parameters_ - _state_ `State`: Data state. -- _query_ `EntityQuery< any >`: Optional object of query parameters to include with request. +- _query_ `EntityQuery`: Optional object of query parameters to include with request. _Returns_ -- `User< 'edit' >[]`: Authors list. +- `User[]`: Authors list. ### getAutosave @@ -238,8 +238,8 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. -- _authorId_ `GenericRecordKey`: The id of the author. +- _postId_ `EntityRecordKey`: The id of the parent post. +- _authorId_ `EntityRecordKey`: The id of the author. _Returns_ @@ -256,7 +256,7 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. +- _postId_ `EntityRecordKey`: The id of the parent post. _Returns_ @@ -317,9 +317,9 @@ Returns the specified entity record, merged with its edits. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -347,7 +347,7 @@ Returns the loaded entities for the given kind. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. +- _kind_ `string`: Entity kind. _Returns_ @@ -360,7 +360,7 @@ Returns the loaded entities for the given kind. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. +- _kind_ `string`: Entity kind. _Returns_ @@ -375,8 +375,8 @@ Returns the entity config given its kind and name. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. _Returns_ @@ -389,8 +389,8 @@ Returns the entity config given its kind and name. _Parameters_ - _state_ `State`: Data state. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. _Returns_ @@ -405,10 +405,10 @@ entity object if it exists and is received. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _key_ `KeyOf< R >`: Record's key -- _query_ Optional query. If requesting specific fields, fields must always include the ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _key_ `EntityRecordKey`: Record's key +- _query_ `EntityQuery`: Optional query. If requesting specific fields, fields must always include the ID. _Returns_ @@ -421,9 +421,9 @@ Returns the specified entity record's edits. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -440,9 +440,9 @@ They are defined in the entity's config. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -455,13 +455,13 @@ Returns the Entity's records. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _query_ Optional terms query. If requesting specific fields, fields must always include the ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _query_ `EntityQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. _Returns_ -- Records. +- `EntityRecord[] | null`: Records. ### getLastEntityDeleteError @@ -470,9 +470,9 @@ Returns the specified entity record's last delete error. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -485,9 +485,9 @@ Returns the specified entity record's last save error. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -501,9 +501,9 @@ with its attributes mapped to their raw values. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _key_ `KeyOf< K, N >`: Record's key. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _key_ `EntityRecordKey`: Record's key. _Returns_ @@ -589,9 +589,9 @@ and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -605,9 +605,9 @@ or false otherwise. _Parameters_ - _state_ `State`: State tree -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _query_ `EntityQuery< C >`: Optional terms query. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _query_ `EntityQuery`: Optional terms query. _Returns_ @@ -621,7 +621,7 @@ _Parameters_ - _state_ `State`: State tree. - _postType_ `string`: The type of the parent post. -- _postId_ `GenericRecordKey`: The id of the parent post. +- _postId_ `EntityRecordKey`: The id of the parent post. _Returns_ @@ -660,9 +660,9 @@ Returns true if the specified entity record is autosaving, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -675,9 +675,9 @@ Returns true if the specified entity record is deleting, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `Kind`: Entity kind. -- _name_ `Name`: Entity name. -- _recordId_ `GenericRecordKey`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ @@ -721,9 +721,9 @@ Returns true if the specified entity record is saving, and false otherwise. _Parameters_ - _state_ `State`: State tree. -- _kind_ `K`: Entity kind. -- _name_ `N`: Entity name. -- _recordId_ `KeyOf< K, N >`: Record ID. +- _kind_ `string`: Entity kind. +- _name_ `string`: Entity name. +- _recordId_ `EntityRecordKey`: Record ID. _Returns_ diff --git a/packages/core-data/src/index.js b/packages/core-data/src/index.js index 05cace07c992b..43fa4a0b3cd07 100644 --- a/packages/core-data/src/index.js +++ b/packages/core-data/src/index.js @@ -60,8 +60,6 @@ const storeConfig = () => ( { * Store definition for the code data namespace. * * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore - * - * @type {Object} */ export const store = createReduxStore( STORE_NAME, storeConfig() ); diff --git a/packages/core-data/src/selectors.ts b/packages/core-data/src/selectors.ts index d81ab8980251a..757a756585e73 100644 --- a/packages/core-data/src/selectors.ts +++ b/packages/core-data/src/selectors.ts @@ -93,7 +93,7 @@ const EMPTY_OBJECT = {}; * @return Whether a request is in progress for an embed preview. */ export const isRequestingEmbedPreview = createRegistrySelector( - ( select ) => + ( select: any ) => ( state: State, url: string ): boolean => { return select( STORE_NAME ).isResolving( 'getEmbedPreview', [ url, @@ -433,8 +433,8 @@ export const getEntityRecords = < state: State, kind: string, name: string, - query -): EntityRecord[] => { + query?: EntityQuery +): EntityRecord[] | null => { // Queried data state is prepopulated for all known entities. If this is not // assigned for the given parameters, then it is known to not exist. const queriedState = get( state.entities.records, [ @@ -491,9 +491,11 @@ export const __experimentalGetDirtyEntityRecords = createSelector( dirtyRecords.push( { // We avoid using primaryKey because it's transformed into a string // when it's used as an object key. - key: entityRecord[ - entityConfig.key || DEFAULT_ENTITY_KEY - ], + key: entityRecord + ? entityRecord[ + entityConfig.key || DEFAULT_ENTITY_KEY + ] + : undefined, title: entityConfig?.getTitle?.( entityRecord ) || '', name, @@ -542,9 +544,11 @@ export const __experimentalGetEntitiesBeingSaved = createSelector( recordsBeingSaved.push( { // We avoid using primaryKey because it's transformed into a string // when it's used as an object key. - key: entityRecord[ - entityConfig.key || DEFAULT_ENTITY_KEY - ], + key: entityRecord + ? entityRecord[ + entityConfig.key || DEFAULT_ENTITY_KEY + ] + : undefined, title: entityConfig?.getTitle?.( entityRecord ) || '', name, @@ -1116,7 +1120,7 @@ export const getReferenceByDistinctEdits = createSelector( export function __experimentalGetTemplateForLink( state: State, link: string -): WpTemplate | null { +): Optional< WpTemplate > | null { const records = getEntityRecords< WpTemplate >( state, 'postType', @@ -1128,7 +1132,7 @@ export function __experimentalGetTemplateForLink( const template = records?.length ? records[ 0 ] : null; if ( template ) { - return getEditedEntityRecord( + return getEditedEntityRecord< WpTemplate, 'edit' >( state, 'postType', 'wp_template', diff --git a/packages/core-data/tsconfig.json b/packages/core-data/tsconfig.json deleted file mode 100644 index 9611fb6f1b64f..0000000000000 --- a/packages/core-data/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "rootDir": "src", - "declarationDir": "build-types", - "noUnusedParameters": false, - "checkJs": false - }, - "references": [ - { "path": "../api-fetch" }, - { "path": "../data" }, - { "path": "../deprecated" }, - { "path": "../element" }, - { "path": "../html-entities" }, - { "path": "../i18n" }, - { "path": "../is-shallow-equal" }, - { "path": "../url" } - ], - "include": [ - "src/**/*.ts", - "src/**/*.js" - ] -}