UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

72 lines (71 loc) 3.29 kB
import { Nullable, NullableResultPromise } from "../../base-types"; import { IContentHubClient } from "../../clients/content-hub-client"; import { IRelationLoadOption } from "../querying/relation-load-option"; import { IEntity } from "./entity"; import { IRelation } from "./relation"; import { RelationRole } from "./relation-role"; export declare class RelationManager { private readonly _client; private readonly _entity; private readonly _relations; private _count; get count(): number; constructor(client: IContentHubClient, relations: Array<IRelation>, entity: IEntity); /** * Gets the relation for the specified name. If role is null and the relation is self-referencing, it will throw. * Returns null if there are no loaded relations. * @param relationName - The name of the relation * @param role - The role of the relation * @returns A relation or null. */ getRelation(relationName: string, role?: RelationRole): Nullable<IRelation>; /** * Gets a list of all loaded relations. */ getRelations(): Array<IRelation>; /** * Lazy loads a relation if it is not loaded yet, adds it to the loaded relations and returns it. * If the relation does not exist, null will be returned. * @param relationName - The name of the relation * @param role - The role of the relation * @param forceLoad - Forces the relation to be loaded even though it has already been loaded before * @returns A promise resolving to the relation or null. */ loadRelationAsync(relationName: string, role?: RelationRole, forceLoad?: boolean): NullableResultPromise<IRelation>; /** * Loads the specified relations. * It will only load if it is actually missing relations and does not overwrite existing relations. * @param relationLoadOption - Option specifying which relations to load * @returns True when something was loaded. */ loadRelationsAsync(relationLoadOption: IRelationLoadOption): Promise<boolean>; /** * Checks if the entity is missing relations that are specified in the {@link IRelationLoadOption}. * @param relationLoadOption - Option specifying which relations to load * @returns Boolean indicating if something is missing. */ hasMissingRelations(relationLoadOption: IRelationLoadOption): boolean; /** * Checks if the specified relation is loaded. If role is null, any loaded role will return true. * @param relationName - The name of the relation * @param role - The role of the relation * @returns Boolean indicating if the specified relation exists. */ exists(relationName: string, role?: Nullable<RelationRole>): boolean; /** * Imports missing relations from the entity. * @param tempEntity - An entity */ importMissingRelations(tempEntity: Nullable<IEntity>): void; /** * Fetches the relation from the server. * @param relationName - The name of the relation * @param role - The role of the relation */ private fetchRelationAsync; /** * Adds the relation to the loaded relations and updates the count (when the relation doesn't exist yet). * @param relation - Relation to add */ private addRelation; }