UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

326 lines (325 loc) 14.4 kB
import { Nullable, NullableResultPromise, type Optional } from "../../base-types"; import type { IExtendedContentHubClient } from "../../clients/extended-client"; import { IPropertyLoadOption } from "../../contracts/querying/property-load-option"; import CultureInfo from "../../culture-info"; import Link from "../../link"; import { EntityPath } from "../../models/entity-path"; import { IDirtyTracking } from "../dirty-tracking/dirty-tracking"; import { MemberLoadOption } from "../querying/member-load-option"; import { IRelationLoadOption } from "../querying/relation-load-option"; import DataType, { PropertyValue } from "./data-type"; import { EntityBase } from "./entity-base"; import { EntityConstructionArgs } from "./entity-construction-args"; import { IEntityDefinition } from "./entity-definition"; import { IProperty } from "./property"; import { IRelatedPath } from "./related-path"; import { IRelation } from "./relation"; import { RelationRole } from "./relation-role"; import { IRendition } from "./rendition"; import IResource from "./resource"; /** * Interface for an entity. */ export interface IEntity extends IResource, IDirtyTracking { /** * Gets the id of the entity. * The id is an automatically assigned, read only, unique and strictly positive number identifying the entity. * The id is null if the entity has not been persisted yet. */ id?: number; /** * Gets the identifier of the entity. * The identifier can be set on a new entities, until it is persisted. It must be unique. * The identifier will be auto generated when it is null when persisting. */ identifier: Nullable<string>; /** * Gets a value indicating whether the entity is new (id is null). */ isNew: boolean; /** * Gets the name of the {@link IEntityDefinition} that defines this entity. */ definitionName: string; /** * Gets the id of the user who locked this entity or null if it hasn't been locked. */ lockedBy: Nullable<number>; /** * Gets the date on which this entity was locked or null if it hasn't been locked. */ lockedOn: Nullable<Date>; /** * Gets or sets a value indicating whether this entity is a top level facet. */ isRootTaxonomyItem: boolean; /** * Gets or sets a value indicating whether this entity is a top level path. */ isPathRoot: boolean; /** * Gets or sets a value indicating whether the entity inherits security * from its ancestors connected via relations with */ inheritsSecurity: boolean; /** * Gets or sets a value indicating whether the entity is owned by the system * and cannot be modified or deleted by the regular users. */ isSystemOwned: boolean; /** * Gets the current version of the entity. * Version is a monotonically increasing number (from 1 up). * Any change(s) of the entity propagated to the persistent storage will cause this number to be incremented. */ version: number; /** * Gets a list of all cultures that the entity was loaded with. Never returns null. * All {@link ICultureSensitiveProperty} properties can only contains values for these cultures. */ cultures: ReadonlyArray<CultureInfo>; /** * Gets or sets a value indicating whether the entity is the default for the given entity definition for the current user. */ isCurrentUserDefault?: boolean; /** * Gets or sets a value indicating whether this language is supported ootb or not. * This value will only be set for Portal.Language entities. */ languageSupportedOotb?: boolean; /** * Gets or sets a value indicating whether this entity has at least one public link. */ hasPublicLink?: boolean; /** * Gets the modification date of the related MasterFile entity. */ masterFileModifiedOn?: Date; /** * The name of the page that the saved selection should redirect too. */ savedSelectionPageName?: string; /** * Gets or sets a dictionary of gateway links per rendition link name. */ gatewayLinks?: Record<string, Link>; /** * Gets the public link of the entity. */ publicLink?: string; /** * Gets the public collection link of the entity. */ publicCollectionLink?: string; /** * Gets or sets a value indicating whether the entity is enabled or not. */ isEnabled?: boolean; /** * Gets a list of modules. */ modules?: Array<string>; /** * Gets the path. */ path?: Array<EntityPath>; /** * Gets a list of all properties that are currently loaded on the entity. Never returns null. * New properties can still be added by lazy loading them. */ properties: ReadonlyArray<IProperty>; /** * Gets a list of all relations that are currently loaded on the entity. Never returns null. * New relations can still be added by lazy loading them. */ relations: ReadonlyArray<IRelation>; /** * Gets a list of all renditions for this entity. Never returns null. */ renditions: ReadonlyArray<IRendition>; /** * Gets the related paths for this entity. */ relatedPaths?: ReadonlyArray<IRelatedPath>; /** * Checks if lazy loading is possible. Lazy loading is only possible on persisted entities. */ readonly canDoLazyLoading: boolean; /** * Gets the link to fetch the roles for this entity. */ roles?: Link; /** * Gets the link to fetch the permissions for this entity. */ permissions?: Link; /** * Gets or sets the combined publish status. */ combinedPublishStatus?: string; /** * Gets or sets the combined publish status details. */ combinedPublishStatusDetails?: string; /** * Gets or sets the number of annotations for this entity. */ annotationCount?: number; /** * Gets or sets the external data identifier of an entity that belongs to a definition with the * usage type value of 'External' */ externalDataIdentifier?: string; /** * Gets property by its name. * @param name - The name of the property * @returns The property. * @throws A {@link NotLoadedError} when the property is not found. */ getProperty(name: string): Nullable<IProperty>; getProperty<T extends IProperty>(name: string): Nullable<T>; /** * Gets property by its name. * If the property is not present, it can be lazy loaded when specifying the correct load option. * @param name - The name of the property * @param loadOption - The option to load the members with * @param culture - The culture for which to get the property * @returns The property. * @throws A {@link SchemaError} when the property is not found. */ getPropertyAsync(name: string, loadOption: MemberLoadOption, culture: Optional<CultureInfo>): NullableResultPromise<IProperty>; getPropertyAsync<T extends IProperty>(name: string, loadOption: MemberLoadOption, culture: Optional<CultureInfo>): NullableResultPromise<T>; /** * Gets the value of the specified culture insensitive property. * @param name - The name of the property * @returns The property's value. * @throws A {@link NotLoadedError} when the property is not found. */ getPropertyValue(name: string): Nullable<unknown>; getPropertyValue<T extends DataType, B extends boolean = false>(name: string): PropertyValue<T, B>; /** * Gets the value for the specified culture of the specified culture sensitive property. * @param name - The name of the property * @param culture - The culture for which to get the value * @returns The property's value. * @throws A {@link NotLoadedError} when the property is not found. */ getPropertyValue(name: string, culture: CultureInfo): Nullable<unknown>; getPropertyValue<T extends DataType, B extends boolean = false>(name: string, culture: CultureInfo): PropertyValue<T, B>; /** * Gets the value of the specified culture insensitive property. * If the property is not present, it can be lazy loaded when specifying the correct load option. * @param name - The name of the property * @param loadOption - The option to load the members with * @returns A promise which resolves to the property's value. * @throws A {@link SchemaError} when the property is not found. */ getPropertyValueAsync(name: string, loadOption: MemberLoadOption): Nullable<unknown>; getPropertyValueAsync<T extends DataType, B extends boolean = false>(name: string, loadOption: MemberLoadOption): NullableResultPromise<PropertyValue<T, B>>; /** * Gets the value for the specified culture of the specified culture sensitive property. * If the property is not present, it can be lazy loaded when specifying the correct load option. * @param name - The name of the property * @param loadOption - The option to load the members with * @param culture - The culture for which to get the value * @returns A promise which resolves to the property's value. * @throws A {@link SchemaError} when the property is not found. */ getPropertyValueAsync(name: string, loadOption: MemberLoadOption, culture: CultureInfo): Nullable<unknown>; getPropertyValueAsync<T extends DataType, B extends boolean = false>(name: string, loadOption: MemberLoadOption, culture: CultureInfo): NullableResultPromise<PropertyValue<T, B>>; /** * Sets the value of specified culture insensitive property. * @param name - The name of the property * @param value - The value to set * @throws A {@link NotLoadedError} when the property is not found. */ setPropertyValue(name: string, value: unknown): void; setPropertyValue<T extends DataType, B extends boolean = false>(name: string, value: PropertyValue<T, B>): void; /** * Sets the value for the specified culture and culture sensitive property. * @param name - The name of the property * @param value - The value to set * @param culture - The culture for which to set the value * @throws A {@link NotLoadedError} when the property is not found. */ setPropertyValue(name: string, value: unknown, culture: CultureInfo): void; setPropertyValue<T extends DataType, B extends boolean = false>(name: string, value: PropertyValue<T, B>, culture: CultureInfo): void; /** * Gets a relation by name. * @param name - The name of the relation * @param role - The role of the relation * @returns The relation. * @throws A {@link NotLoadedError} when the relation is not found. */ getRelation(name: string, role?: RelationRole): Nullable<IRelation>; /** * Gets a relation by name. * If the relation is not present, it can be lazy loaded when specifying the correct load option. * @param name - The name of the relation * @param role - The role of the relation * @param loadOption - The load option, defaults to LazyLoading * @returns A promise which resolves to the relation. * @throws A {@link SchemaError} when the relation is not found. */ getRelationAsync(name: string, role?: RelationRole, loadOption?: MemberLoadOption): NullableResultPromise<IRelation>; /** * Loads the specified properties on the current entity. * It will only load if it is actually missing properties and does not overwrite existing properties. * Culture sensitive properties will only be loaded in the current cultures. * Lazy loading is only possible on entities that are not new. * @param propertyLoadOption - The properties to load * @param culture - The culture for which to load the properties * @returns Promise which resolves to true when the properties were added. */ loadPropertiesAsync(propertyLoadOption: IPropertyLoadOption, culture: Optional<CultureInfo>): Promise<boolean>; /** * Loads the specified relations on the current entity. * It will only load if it is actually missing relations and does not overwrite existing relations. * Lazy loading is only possible on entities that are not new. * @param relationLoadOption - The relations to load * @returns Promise which resolves to true when the relations were loaded. */ loadRelationsAsync(relationLoadOption: IRelationLoadOption): Promise<boolean>; /** * Loads the specified members on the current entity. * It will only load if it is actually missing members and does not overwrite existing members. * @param propertyLoadOption - The properties to load * @param relationLoadOption - The relations to load * @returns Promise which resolves to true when the members were loaded. */ loadMembersAsync(propertyLoadOption: IPropertyLoadOption, relationLoadOption: IRelationLoadOption): Promise<boolean>; /** * Gets an {@link IRendition} by name. * @param name - The name of the rendition * @returns Rendition. */ getRendition(name: string): Nullable<IRendition>; /** * Gets an {@link IRelatedPath} by name. * @param name - The name of the related path * @returns Related path. */ getRelatedPath(name: string): Nullable<IRelatedPath>; /** * Gets the {@link IEntityDefinition} of the entity. * @returns Promise which resolves to the entity definition. */ getEntityDefinitionAsync(): Promise<IEntityDefinition>; /** * Gets the permissions the current user has on this entity. * Note: Entity should be saved at least once. * @returns Promise which resolves to a list of permissions. */ getPermissionsAsync(): Promise<Array<string>>; } export declare class Entity extends EntityBase { _client: IExtendedContentHubClient; private readonly _renditions; private readonly _relatedPaths; get renditions(): Array<IRendition>; get relatedPaths(): Array<IRelatedPath>; constructor(client: IExtendedContentHubClient, args: EntityConstructionArgs); getRendition(name: string): Nullable<IRendition>; getRelatedPath(name: string): Nullable<IRelatedPath>; getPermissionsAsync(): Promise<Array<string>>; }