UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

98 lines 3.72 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import DirtyValueCalculator from "../../../dirty-value-calculator"; import Guard from "../../../guard"; import { EntityLoadConfiguration } from "../../querying/entity-load-configuration"; import { ChildRelationBase } from "../relation"; import { RelationRole } from "../relation-role"; export class ChildToManyParentsRelation extends ChildRelationBase { get isFullyLoaded() { return this.parentTotal == null || this._parents.length === this.parentTotal; } get isDirty() { if (!this.isTracking) { return false; } else { return this._dirtyValueCalculator.isDirty(this._parents); } } get parents() { return this._parents.slice(); } constructor(name, properties = null, client, parentTotal, inheritsSecurity) { super(name, properties, client, inheritsSecurity); this._parents = []; this.role = RelationRole.Child; this.isMultiValue = true; this.parentTotal = parentTotal; } getIds() { return this._parents.slice(); } setIds(ids) { Guard.validIds(ids); this._parents.splice(0, this._parents.length); this._parents.push(...ids); } clear() { this._parents.splice(0, this._parents.length); } add(id) { Guard.validId(id); if (!this._parents.includes(id)) { this._parents.push(id); } } addRange(ids) { Guard.validIds(ids); ids.forEach(id => { if (!this._parents.includes(id)) { this._parents.push(id); } }); } addAsync(identifier) { return __awaiter(this, void 0, void 0, function* () { Guard.notNullOrUndefined(this.client); Guard.stringNotNullOrEmpty(identifier); const entity = yield this.client.entities.getAsync(identifier, EntityLoadConfiguration.Minimal); if (entity && entity.id) { this.add(entity.id); } }); } addRangeAsync(identifiers) { return __awaiter(this, void 0, void 0, function* () { Guard.notNullOrUndefined(this.client); Guard.arrayNoneNullOrEmptyString(identifiers); const entities = yield this.client.entities.getManyAsync(identifiers, EntityLoadConfiguration.Minimal); if (entities) { this.addRange(entities.filter(x => x.id !== null).map(x => x.id)); } }); } startTracking() { if (this.isTracking) return; this.isTracking = true; this._dirtyValueCalculator = new DirtyValueCalculator(); this._dirtyValueCalculator.setOriginalValue(this._parents); } markClean() { if (this.isTracking) { this._dirtyValueCalculator.setOriginalValue(this._parents); } } getParentProperties(id) { return this.properties[id] == null ? {} : this.properties[id]; } } //# sourceMappingURL=child-to-many-parents-relation.js.map