/*!
 * 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) {
    return withSchemaValidation(Message(changesetCodec.encodedSchema ?? Type.Any()), {
        encode: ({ commit, sessionId }) => {
            const message = {
                revision: commit.revision,
                originatorId: sessionId,
                changeset: changesetCodec.encode(commit.change),
            };
            return message;
        },
        decode: (encoded) => {
            const { revision, originatorId, changeset } = encoded;
            return {
                commit: {
                    revision,
                    change: changesetCodec.decode(changeset),
                },
                sessionId: originatorId,
            };
        },
    });
}
//# sourceMappingURL=messageCodecs.js.map