UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

221 lines (220 loc) 11.5 kB
import { Nullable, NullableResultPromise } from "../base-types"; import { IEntity } from "../contracts/base/entity"; import { IEntityIterator } from "../contracts/querying/entity-iterator"; import { IEntityLoadConfiguration } from "../contracts/querying/entity-load-configuration"; import { IEntityQueryResult } from "../contracts/querying/entity-query-result"; import { IIdIterator } from "../contracts/querying/id-iterator"; import { IIdQueryResult } from "../contracts/querying/id-query-result"; import { Sorting } from "../contracts/querying/sorting"; import CultureInfo from "../culture-info"; import { IEntityCopyOptions } from "../models/content/entity-copy-options"; import { IExtendedContentHubClient } from "./extended-client"; import { CancelCallback } from "./internal-client"; /** * Interface for the client responsible for getting, saving and deleting entities. * * @remarks * When possible, always include the specific properties and relations that are required when fetching entities. */ export interface IEntitiesClient { /** * Gets the {@link IEntity} instance with the specified `id`. * @param id - The id of the entity to get * @param loadConfiguration - The loading configuration for the entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns The entity or `null` when it was not found. */ getAsync(id: number, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): NullableResultPromise<IEntity>; /** * Gets the {@link IEntity} instance with the specified `identifier`. * @param identifier - The identifier of the entity to get * @param loadConfiguration - The loading configuration for the entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns The entity or `null` when it was not found. */ getAsync(identifier: string, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): NullableResultPromise<IEntity>; /** * Gets the {@link IEntity} instance with the specified `id` or `identifier`. * @param param - The id or identifier of the entity to get * @param loadConfiguration - The loading configuration for the entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns The entity or `null` when it was not found. */ getAsync(param: number | string, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): NullableResultPromise<IEntity>; /** * Gets the {@link IEntity} instances with the specified `ids`. * * @remarks * The returned list of entities can be empty or contain fewer items than the list of ids. * The order of the entities in the returned list can be different than the order of the requested ids. * * @param ids - The ids of the entities to get * @param loadConfiguration - The loading configuration for an entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns List of entities. */ getManyAsync(ids: Array<number>, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): Promise<Array<IEntity>>; /** * Gets the {@link IEntity} instances with the specified `identifiers`. * * @remarks * The returned list of entities can be empty or contain fewer items than the list of identifiers. * The order of the entities in the returned list can be different than the order of the requested identifiers. * * @param identifiers - The identifiers of the entities to get * @param loadConfiguration - The loading configuration for an entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns List of entities. */ getManyAsync(identifiers: Array<string>, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): Promise<Array<IEntity>>; /** * Gets the {@link IEntity} instances with the specified `ids` or `identifiers`. * * @remarks * The returned list of entities can be empty or contain fewer items than the list of identifiers. * The order of the entities in the returned list can be different than the order of the requested identifiers. * * @param param - The ids or identifiers of the entities to get * @param loadConfiguration - The loading configuration for an entity * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns List of entities. */ getManyAsync(param: Array<number> | Array<string>, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): Promise<Array<IEntity>>; /** * Queries the {@link IEntity} instances for the specified `definitionName`. * * @param definitionName - The name of the definition to get entities for (case insensitive) * @param loadConfiguration - The loading configuration for an entity * @param skip - Skip the specified number of entities (optional) * @param take - Take only the specified number of entities (optional, default: {@link ENTITIES.take}) * @param sorting - Sorting options * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns List of entities. */ getByDefinitionAsync(definitionName: string, loadConfiguration?: Nullable<IEntityLoadConfiguration>, skip?: number, take?: number, sorting?: Array<Sorting>, cancelCallback?: CancelCallback): Promise<IEntityQueryResult>; /** * Queries the {@link IEntity} ids for the specified `definitionName`. * * @param definitionName - The name of the definition to get entity ids for (case insensitive) * @param skip - Skip the specified number of entities (optional) * @param take - Take only the specified number of entities (optional, default: {@link ENTITIES.take}) * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @returns List of entity ids. */ getIdsByDefinitionAsync(definitionName: string, skip?: number, take?: number, cancelCallback?: CancelCallback): Promise<IIdQueryResult>; /** * Creates an {@link IEntityIterator} instance for the specified definition that returns instances. * Results are sorted ascending on creation date. * * @param definition - The name of the definition to get entities for * @param loadConfiguration - Load configuration * @returns The iterator. */ getEntityIterator(definition: string, loadConfiguration?: Nullable<IEntityLoadConfiguration>): IEntityIterator; /** * Creates an {@link IIdIterator} instance for the specified definition that returns instances. * Results are sorted ascending on creation date. * * @param definition - The name of the definition to get entity ids for * @returns The iterator. */ getEntityIdIterator(definition: string): IIdIterator; /** * Save the specified {@link IEntity}. * * @remarks * The existing {@link IEntity} will not be updated in any way. * If any information is needed that was generated on the server after persisting, the entity will need to be * fetched again. * * @param entity - Entity to save * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @param culture - The culture to update the entity in * @returns The id of the entity. */ saveAsync(entity: IEntity, cancelCallback?: CancelCallback, culture?: CultureInfo): Promise<number>; /** * Deletes the {@link IEntity} with specified id. * * @param entityId - The id of the entity to delete * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided */ deleteAsync(entityId: number, cancelCallback?: CancelCallback): Promise<void>; /** * Copies an {@link IEntity} by id to a new or existing entity. * * @param entityId - The id of the entity to delete * @param copyOptions - The copy options. * * @returns The id of the copied entity. * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided */ copyAsync(entityId: number, copyOptions: IEntityCopyOptions, cancelCallback?: CancelCallback): Promise<number>; } /** * The client responsible for getting, saving and deleting entities. */ export declare class EntitiesClient implements IEntitiesClient { private readonly _client; constructor(client: IExtendedContentHubClient); /** * {@inheritDoc} */ getAsync(param: string | number, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): NullableResultPromise<IEntity>; /** * {@inheritDoc} */ getManyAsync(param: Array<number> | Array<string>, loadConfiguration?: Nullable<IEntityLoadConfiguration>, cancelCallback?: CancelCallback): Promise<Array<IEntity>>; /** * {@inheritDoc} */ getByDefinitionAsync(definitionName: string, loadConfiguration?: Nullable<IEntityLoadConfiguration>, skip?: number, take?: number, sorting?: Array<Sorting>, cancelCallback?: CancelCallback): Promise<IEntityQueryResult>; /** * {@inheritDoc} */ getIdsByDefinitionAsync(definitionName: string, skip?: number, take?: number, cancelCallback?: CancelCallback): Promise<IIdQueryResult>; /** * {@inheritDoc} */ getEntityIterator(definition: string, loadConfiguration?: Nullable<IEntityLoadConfiguration>): IEntityIterator; /** * {@inheritDoc} */ getEntityIdIterator(definition: string): IIdIterator; /** * {@inheritDoc} */ saveAsync(entity: IEntity, cancelCallback?: CancelCallback, culture?: CultureInfo): Promise<number>; /** * {@inheritDoc} */ deleteAsync(entityId: number, cancelCallback?: CancelCallback): Promise<void>; /** * {@inheritDoc} */ copyAsync(entityId: number, copyOptions: IEntityCopyOptions, cancelCallback?: CancelCallback): Promise<number>; /** * Creates the specified {@link IEntity} in the system. * * @param entity - The entity to create/save in the system */ private createEntityAsync; /** * Update the specified {@link IEntity}. * * @param entity - The entity to update * @param cancelCallback - A {@link CancelCallback} that will be placed in an Axios {@link CancelToken} if provided * @param cultureParam - The culture to update the entity in */ private updateEntityAsync; /** * Get an {@link IEntity} or `null` from the specified {@link IEntityQueryResult}. * * @remarks * Throws an {@link InternalError} if multiple results where available. * * @param queryResult - The query result (should contain one or no items) * @returns An {@link IEntity} or `null`. */ private static single; }