"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeVersionedValidatedCodec = exports.makeVersionedCodec = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
const codec_js_1 = require("../codec.js");
const format_js_1 = require("./format.js");
function makeVersionedCodec(supportedVersions, { jsonValidator: validator }, inner) {
    return (0, codec_js_1.withSchemaValidation)(format_js_1.Versioned, {
        encode: (data, context) => {
            const encoded = inner.encode(data, context);
            (0, core_utils_1.assert)(supportedVersions.has(encoded.version), 0x88b /* version being encoded should be supported */);
            return encoded;
        },
        decode: (data, context) => {
            const versioned = data; // Validated by withSchemaValidation
            (0, core_utils_1.assert)(supportedVersions.has(versioned.version), 0x88c /* version being decoded is not supported */);
            const decoded = inner.decode(data, context);
            return decoded;
        },
    }, validator);
}
exports.makeVersionedCodec = makeVersionedCodec;
function makeVersionedValidatedCodec(options, supportedVersions, schema, codec) {
    return makeVersionedCodec(supportedVersions, options, (0, codec_js_1.withSchemaValidation)(schema, codec, options.jsonValidator));
}
exports.makeVersionedValidatedCodec = makeVersionedValidatedCodec;
//# sourceMappingURL=codec.js.map