UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

103 lines 4.89 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.LoadOptionsMapper = void 0; const entity_load_configuration_1 = require("../contracts/querying/entity-load-configuration"); const load_options_1 = require("../contracts/querying/load-options"); const query_load_configuration_1 = require("../contracts/querying/query-load-configuration"); const guard_1 = __importDefault(require("../guard")); class LoadOptionsMapper { static toEntityLoadConfiguration(loadConfiguration) { var _a, _b, _c; if (loadConfiguration == null) { return null; } return new entity_load_configuration_1.EntityLoadConfiguration(((_a = loadConfiguration.cultureLoadOption) === null || _a === void 0 ? void 0 : _a.deepClone()) || undefined, ((_b = loadConfiguration.propertyLoadOption) === null || _b === void 0 ? void 0 : _b.deepClone()) || undefined, ((_c = loadConfiguration.relationLoadOption) === null || _c === void 0 ? void 0 : _c.deepClone()) || undefined); } static toQueryLoadConfiguration(loadConfiguration) { var _a, _b, _c; if (loadConfiguration == null) { return null; } return new query_load_configuration_1.QueryLoadConfiguration({ cultureLoadOption: ((_a = loadConfiguration.cultureLoadOption) === null || _a === void 0 ? void 0 : _a.deepClone()) || undefined, propertyLoadOption: ((_b = loadConfiguration.propertyLoadOption) === null || _b === void 0 ? void 0 : _b.deepClone()) || undefined, relationLoadOption: ((_c = loadConfiguration.relationLoadOption) === null || _c === void 0 ? void 0 : _c.deepClone()) || undefined, }); } static mapPropertyLoadOptions(options) { if (options == null) { return []; } let result = []; switch (options.loadOption) { case load_options_1.LoadOption.All: result = null; break; case load_options_1.LoadOption.Custom: if (options.properties != null) { result = options.properties; } break; } return result; } static mapRelationLoadOptions(options) { if (options == null) { return []; } let result = []; switch (options.loadOption) { case load_options_1.LoadOption.All: result = null; break; case load_options_1.LoadOption.Custom: if (options.relations != null) { result = options.relations.map(relationSpecification => relationSpecification.name); } break; } return result; } static mapCultureLoadOptionsAsync(options, loader) { return __awaiter(this, void 0, void 0, function* () { if (options == null) { return []; } let result = []; switch (options.loadOption) { case load_options_1.LoadOption.All: guard_1.default.notNullOrUndefined(loader); result = yield loader.getAllCulturesCachedAsync(); break; case load_options_1.LoadOption.Default: guard_1.default.notNullOrUndefined(loader); if (this.defaultCultures == null) { const defaultCulture = yield loader.getDefaultCultureCachedAsync(); this.defaultCultures = defaultCulture != null ? [defaultCulture] : []; } result = this.defaultCultures; break; case load_options_1.LoadOption.Custom: if (options.cultures != null) { result = options.cultures; } break; } return result; }); } } exports.LoadOptionsMapper = LoadOptionsMapper; //# sourceMappingURL=load-options-mapper.js.map