UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

113 lines 4.91 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConditionMapper = void 0; const condition_1 = require("../contracts/policies/condition"); const condition_resource_1 = require("../models/policies/condition-resource"); class ConditionMapper { /** * Map condition resources to conditions. * @param client - An instance of an extended Content Hub client * @param conditionResources - A collection of resources to map * @returns An array of conditions. */ static mapToConditionsAsync(client, conditionResources) { return __awaiter(this, void 0, void 0, function* () { if (conditionResources == null || conditionResources.length === 0) { return []; } const list = []; for (const conditionResource of conditionResources) { const condition = yield this.mapToConditionAsync(client, conditionResource); if (condition != null) { list.push(condition); } } return list; }); } /** * Map a condition resource to a condition instance. * @param client - An instance of an extended Content Hub client * @param conditionResource - A condition resource * @returns A condition or null. */ static mapToConditionAsync(client, conditionResource) { return __awaiter(this, void 0, void 0, function* () { if (conditionResource == null) { return null; } const condition = new condition_1.Condition(); condition.directEntityIds = yield this.mapIdAsync(client, conditionResource.directEntities); condition.entityIds = yield this.mapIdAsync(client, conditionResource.entities); return condition; }); } /** * Map condition instances to condition resources. * @param client - An instance of an extended Content Hub client * @param conditions - A collection of conditions * @returns An array of condition resources. */ static mapToConditionResourcesAsync(client, conditions) { return __awaiter(this, void 0, void 0, function* () { if (conditions == null || conditions.length === 0) { return []; } const resources = []; for (const condition of conditions) { const conditionResource = yield this.mapToConditionResourceAsync(client, condition); if (conditionResource != null) { resources.push(conditionResource); } } return resources; }); } /** * Map a condition to a condition resource. * @param client - An instance of an extended Content Hub client * @param condition - A condition instance * @returns A condition resource or null. */ static mapToConditionResourceAsync(client, condition) { return __awaiter(this, void 0, void 0, function* () { if (condition == null) { return null; } const conditionResource = new condition_resource_1.ConditionResource(); conditionResource.directEntities = yield this.mapEntityLinksAsync(client, condition.directEntityIds); conditionResource.entities = yield this.mapEntityLinksAsync(client, condition.entityIds); return conditionResource; }); } //#region Private methods static mapIdAsync(client, idLinks) { return __awaiter(this, void 0, void 0, function* () { if (idLinks == null) { return []; } const list = yield client.linkHelper.idsFromEntitiesAsync(idLinks); return list; }); } static mapEntityLinksAsync(client, entityLinks) { return __awaiter(this, void 0, void 0, function* () { if (entityLinks == null) { return []; } const list = yield client.linkHelper.entitiesToLinksAsync(entityLinks); return list; }); } } exports.ConditionMapper = ConditionMapper; //# sourceMappingURL=condition-mapper.js.map