"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeSchemaChangeCodecs = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../../codec/index.js");
const index_js_2 = require("../schema-index/index.js");
const schemaChangeFormat_js_1 = require("./schemaChangeFormat.js");
function makeSchemaChangeCodecs(options) {
    return (0, index_js_1.makeCodecFamily)([[0, makeSchemaChangeCodec(options)]]);
}
exports.makeSchemaChangeCodecs = makeSchemaChangeCodecs;
function makeSchemaChangeCodec({ jsonValidator: validator, }) {
    const schemaCodec = (0, index_js_2.makeSchemaCodec)({ jsonValidator: validator });
    const schemaChangeCodec = {
        encode: (schemaChange) => {
            (0, internal_1.assert)(!schemaChange.isInverse, "Inverse schema changes should never be transmitted");
            return {
                new: schemaCodec.encode(schemaChange.schema.new),
                old: schemaCodec.encode(schemaChange.schema.old),
            };
        },
        decode: (encoded) => {
            return {
                schema: {
                    new: schemaCodec.decode(encoded.new),
                    old: schemaCodec.decode(encoded.old),
                },
                isInverse: false,
            };
        },
        encodedSchema: schemaChangeFormat_js_1.EncodedSchemaChange,
    };
    return (0, index_js_1.withSchemaValidation)(schemaChangeFormat_js_1.EncodedSchemaChange, schemaChangeCodec, validator);
}
//# sourceMappingURL=schemaChangeCodecs.js.map