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