UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

105 lines 3.84 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChildToOneParentRelation = void 0; const dirty_value_calculator_1 = __importDefault(require("../../../dirty-value-calculator")); const guard_1 = __importDefault(require("../../../guard")); const entity_load_configuration_1 = require("../../querying/entity-load-configuration"); const relation_1 = require("../relation"); const relation_role_1 = require("../relation-role"); class ChildToOneParentRelation extends relation_1.ChildRelationBase { get isDirty() { if (!this.isTracking) { return false; } else { return this._dirtyValueCalculator.isDirty(this._parent); } } get parent() { return this._parent; } set parent(id) { guard_1.default.validIdOrNull(id); this._parent = id; } constructor(name, properties = null, client, inheritsSecurity) { super(name, properties, client, inheritsSecurity); this._parent = null; this.role = relation_role_1.RelationRole.Child; this.isMultiValue = false; } getIds() { if (this._parent !== 0 && this._parent !== null) { return [this._parent]; } else { return []; } } setIds(ids) { guard_1.default.arrayMaxOne(ids); if (ids.length > 0) { guard_1.default.validId(ids[0]); this._parent = ids[0]; } else { this._parent = null; } } clear() { this._parent = null; } getId() { return this._parent; } setId(id) { guard_1.default.validIdOrNull(id); this._parent = id; } setIdentifierAsync(identifier) { return __awaiter(this, void 0, void 0, function* () { guard_1.default.notNullOrUndefined(this.client); guard_1.default.stringNotNullOrEmpty(identifier); if (identifier) { const entity = yield this.client.entities.getAsync(identifier, entity_load_configuration_1.EntityLoadConfiguration.Minimal); if (entity && entity.id) { this.setId(entity.id); return; } } this.setId(null); }); } startTracking() { if (this.isTracking) return; this.isTracking = true; this._dirtyValueCalculator = new dirty_value_calculator_1.default(); this._dirtyValueCalculator.setOriginalValue(this._parent); } markClean() { if (this.isTracking) { this._dirtyValueCalculator.setOriginalValue(this._parent); } } getParentProperties() { if (this._parent == null) { return {}; } return this.properties[this._parent] == null ? {} : this.properties[this._parent]; } } exports.ChildToOneParentRelation = ChildToOneParentRelation; //# sourceMappingURL=child-to-one-parent-relation.js.map