@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
93 lines (92 loc) • 4.5 kB
TypeScript
import { MapNumberTo, MapStringTo, Nullable, Object_Unknown, Optional } from "../..";
import { IContentHubClient } from "../../clients/content-hub-client";
import DirtyValueCalculator from "../../dirty-value-calculator";
import { IMember, MemberBase } from "./member";
import { RelationRole } from "./relation-role";
import { ChildToManyParentsRelation, IChildToManyParentsRelation } from "./relations/child-to-many-parents-relation";
import { ChildToOneParentRelation, IChildToOneParentRelation } from "./relations/child-to-one-parent-relation";
import { IParentToManyChildrenRelation, ParentToManyChildrenRelation } from "./relations/parent-to-many-children-relation";
import { IParentToOneChildRelation, ParentToOneChildRelation } from "./relations/parent-to-one-child-relation";
/**
* Interface for relations.
*/
export interface IRelation extends IMember {
/**
* The role of this instance in the relation.
*/
readonly role: RelationRole;
/**
* Indicates if multiple values can be linked in the relation's direction.
*/
readonly isMultiValue: boolean;
/**
* Linked entities properties.
*/
readonly properties: MapNumberTo<MapStringTo<Object_Unknown>>;
/**
* Gets the ids of the linked entities.
*
* In case of an {@link IToManyRelation} the result will contain all ids on the relation.
* In case of an {@link IToOneRelation} the list can contain 1 id (maximum) if an id was set on the relation.
*
* If no id was set on the relation, an empty list is returned.
*/
getIds(): Array<number>;
/**
* Sets the related entities. The values should be strictly positive.
*
* In case of an {@link IToManyRelation}, the list of ids will be set on the relation.
* In case of an {@link IToOneRelation}, ids can have at most one value.
*
* If the list is empty then the value will be set to null.
* @param ids - The ids of the entities to link
*/
setIds(ids: Array<number>): void;
/**
* Sets the related entities.
*
* In case of an {@link IToManyRelation}, the list of ids will be set on the relation.
* In case of an {@link IToOneRelation}, ids can have at most one value.
*
* If the list is empty then the value will be set to null.
* @param identifiers - The identifiers of the entities to link
*/
setIdentifiersAsync(identifiers: Array<string>): Promise<void>;
/**
* Clears the value(s) of the relation.
*/
clear(): void;
}
export declare abstract class RelationBase extends MemberBase implements IRelation {
abstract readonly role: RelationRole;
abstract readonly isMultiValue: boolean;
readonly properties: MapNumberTo<MapStringTo<Object_Unknown>>;
protected _dirtyValueCalculator: DirtyValueCalculator;
protected client: Optional<IContentHubClient>;
protected constructor(name: string, properties?: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient);
abstract getIds(): Array<number>;
abstract setIds(ids: Array<number>): void;
setIdentifiersAsync(identifiers: Array<string>): Promise<void>;
abstract clear(): void;
protected getTypeName(): string;
static isChildRelation(r: IRelation): r is IChildRelation;
static isChildToOneParentRelation(r: IRelation): r is IChildToOneParentRelation;
static isChildToManyParentsRelation(r: IRelation): r is IChildToManyParentsRelation;
static isParentRelation(r: IRelation): r is IParentRelation;
static isParentToOneChildRelation(r: IRelation): r is IParentToOneChildRelation;
static isParentToManyChildrenRelation(r: IRelation): r is IParentToManyChildrenRelation;
}
/** Base interface for all child relations. */
export interface IChildRelation extends IRelation {
/** Indicates if this relation is used to inherit any security
* related metadata (from the parents towards the children).
*/
inheritsSecurity: boolean;
}
export declare abstract class ChildRelationBase extends RelationBase implements IChildRelation {
inheritsSecurity: boolean;
constructor(name: string, properties: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient, inheritsSecurity?: boolean);
}
/** Base interface for all parent relations. */
export type IParentRelation = IRelation;
export type RelationType = ChildToManyParentsRelation | ChildToOneParentRelation | ParentToManyChildrenRelation | ParentToOneChildRelation;