UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

43 lines (42 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); function mapSliceZone(sliceZone, mappers, context) { return Promise.all(sliceZone.map(async (slice, index, slices) => { const isRestSliceType = "slice_type" in slice; const sliceType = isRestSliceType ? slice.slice_type : slice.type; const mapper = mappers[sliceType]; if (!mapper) { return slice; } const mapperArgs = { slice, slices, index, context }; let result = await mapper( // @ts-expect-error - I don't know how to fix this type mapperArgs ); if ( // `mapper.length < 1` ensures the given // function is something of the form: // `() => import(...)` mapper.length < 1 && (typeof result === "function" || typeof result === "object" && "default" in result) ) { result = "default" in result ? result.default : result; result = await result(mapperArgs); } if (isRestSliceType) { return { __mapped: true, id: slice.id, slice_type: sliceType, ...result }; } else { return { __mapped: true, type: sliceType, ...result }; } })); } exports.mapSliceZone = mapSliceZone; //# sourceMappingURL=mapSliceZone.cjs.map