/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Type } from "@sinclair/typebox";
import { withSchemaValidation } from "../codec";
import { Message } from "./messageFormat";
export function makeMessageCodec(changesetCodec, revisionTagCodec, options) {
    return withSchemaValidation(Message(changesetCodec.encodedSchema ?? Type.Any()), {
        encode: ({ commit, sessionId }) => {
            const message = {
                revision: revisionTagCodec.encode(commit.revision),
                originatorId: sessionId,
                changeset: changesetCodec.encode(commit.change),
            };
            return message;
        },
        decode: (encoded) => {
            const { revision, originatorId, changeset } = encoded;
            return {
                commit: {
                    revision: revisionTagCodec.decode(revision),
                    change: changesetCodec.decode(changeset),
                },
                sessionId: originatorId,
            };
        },
    }, options.jsonValidator);
}
//# sourceMappingURL=messageCodecs.js.map