UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

96 lines 4.38 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 { EntityLoadConfiguration } from "../contracts/querying/entity-load-configuration"; import { LoadOption } from "../contracts/querying/load-options"; import { QueryLoadConfiguration } from "../contracts/querying/query-load-configuration"; import Guard from "../guard"; export class LoadOptionsMapper { static toEntityLoadConfiguration(loadConfiguration) { var _a, _b, _c; if (loadConfiguration == null) { return null; } return new 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 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 LoadOption.All: result = null; break; case 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 LoadOption.All: result = null; break; case 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 LoadOption.All: Guard.notNullOrUndefined(loader); result = yield loader.getAllCulturesCachedAsync(); break; case LoadOption.Default: Guard.notNullOrUndefined(loader); if (this.defaultCultures == null) { const defaultCulture = yield loader.getDefaultCultureCachedAsync(); this.defaultCultures = defaultCulture != null ? [defaultCulture] : []; } result = this.defaultCultures; break; case LoadOption.Custom: if (options.cultures != null) { result = options.cultures; } break; } return result; }); } } //# sourceMappingURL=load-options-mapper.js.map