"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeUncompressedCodec = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
const util_1 = require("../../../util");
const format_1 = require("./format");
const chunkDecoding_1 = require("./chunkDecoding");
const uncompressedEncode_1 = require("./uncompressedEncode");
function makeUncompressedCodec({ jsonValidator: validator, }) {
    const versionedValidator = validator.compile(format_1.Versioned);
    const formatValidator = validator.compile(format_1.EncodedChunk);
    return {
        encode: (data) => {
            const encoded = (0, uncompressedEncode_1.uncompressedEncode)(data);
            (0, core_utils_1.assert)(versionedValidator.check(encoded), 0x78e /* Encoded schema should be versioned */);
            (0, core_utils_1.assert)(formatValidator.check(encoded), 0x78f /* Encoded schema should validate */);
            return encoded;
        },
        decode: (data) => {
            if (!versionedValidator.check(data)) {
                (0, util_1.fail)("invalid serialized schema: did not have a version");
            }
            if (!formatValidator.check(data)) {
                (0, util_1.fail)("Serialized schema failed validation");
            }
            if (!format_1.validVersions.has(data.version)) {
                (0, util_1.fail)("Unexpected version for schema");
            }
            return (0, chunkDecoding_1.decode)(data).cursor();
        },
    };
}
exports.makeUncompressedCodec = makeUncompressedCodec;
//# sourceMappingURL=uncompressedCodecs.js.map