UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

47 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AllFacetValuesChildrenConverter = void 0; const ta_json_1 = require("ta-json"); const invalid_operation_error_1 = require("../errors/invalid-operation-error"); const facet_response_resource_1 = require("../models/search/facet-response-resource"); class AllFacetValuesChildrenConverter { /** * Serializes a mapping of strings to array of FacetResponseResource into a JSON object. * * @param value - A mapping of strings to array of FacetResponseResource * * @returns The serialized value. */ serialize(children) { const result = Object.keys(children).reduce((serialized, key) => { var _a; // eslint-disable-next-line @typescript-eslint/no-unsafe-return const entries = (_a = children[key]) === null || _a === void 0 ? void 0 : _a.map(entry => ta_json_1.TaJson.serialize(entry)); return Object.assign(Object.assign({}, serialized), { [key]: entries }); }, {}); return result; } /** * Deserializes a JSON object into a mapping of strings to array of FacetResponseResource. * * @param value - The serialized value * * @returns A mapping of strings to array of FacetResponseResource. */ deserialize(value) { if (!value) { return {}; } else if (typeof value !== "object") { throw new invalid_operation_error_1.InvalidOperationError(`Expected a value of type 'JSON object', but value was of type '${typeof value}'.`); } const result = Object.keys(value).reduce((current, key) => { var _a; const entries = (_a = value[key]) === null || _a === void 0 ? void 0 : _a.map(entry => ta_json_1.TaJson.deserialize(entry, facet_response_resource_1.FacetResponseResource)); return Object.assign(Object.assign({}, current), { [key]: entries }); }, {}); return result; } } exports.AllFacetValuesChildrenConverter = AllFacetValuesChildrenConverter; //# sourceMappingURL=all-facet-values-children-converter.js.map