"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.EncodedModularChangeset = exports.EncodedNodeChangeset = exports.EncodedChangeAtomId = exports.ChangesetLocalIdSchema = void 0;
const typebox_1 = require("@sinclair/typebox");
const core_1 = require("../../core");
const util_1 = require("../../util");
const noAdditionalProps = { additionalProperties: false };
exports.ChangesetLocalIdSchema = (0, util_1.brandedNumberType)();
exports.EncodedChangeAtomId = typebox_1.Type.Object({
    /**
     * Uniquely identifies the changeset within which the change was made.
     */
    revision: typebox_1.Type.Optional(core_1.RevisionTagSchema),
    /**
     * Uniquely identifies, in the scope of the changeset, the change made to the field.
     */
    localId: exports.ChangesetLocalIdSchema,
}, noAdditionalProps);
const EncodedValueChange = typebox_1.Type.Object({
    revision: typebox_1.Type.Optional(core_1.RevisionTagSchema),
    value: typebox_1.Type.Optional(util_1.JsonCompatibleReadOnlySchema),
}, noAdditionalProps);
const EncodedValueConstraint = typebox_1.Type.Object({
    value: typebox_1.Type.Optional(util_1.JsonCompatibleReadOnlySchema),
    violated: typebox_1.Type.Boolean(),
}, noAdditionalProps);
const EncodedFieldChange = typebox_1.Type.Object({
    fieldKey: core_1.FieldKeySchema,
    fieldKind: core_1.FieldKindIdentifierSchema,
    // Implementation note: node and field change encoding is mutually recursive.
    // This field marks a boundary in that recursion to avoid constructing excessively complex
    // recursive types. Encoded changes are validated at this boundary at runtime--see modularChangeCodecs.ts.
    change: util_1.JsonCompatibleReadOnlySchema,
}, noAdditionalProps);
const EncodedFieldChangeMap = typebox_1.Type.Array(EncodedFieldChange);
const EncodedNodeExistsConstraint = typebox_1.Type.Object({
    violated: typebox_1.Type.Boolean(),
});
exports.EncodedNodeChangeset = typebox_1.Type.Object({
    valueChange: typebox_1.Type.Optional(EncodedValueChange),
    fieldChanges: typebox_1.Type.Optional(EncodedFieldChangeMap),
    valueConstraint: typebox_1.Type.Optional(EncodedValueConstraint),
    nodeExistsConstraint: typebox_1.Type.Optional(EncodedNodeExistsConstraint),
}, noAdditionalProps);
const EncodedRevisionInfo = typebox_1.Type.Object({
    revision: typebox_1.Type.Readonly(core_1.RevisionTagSchema),
    rollbackOf: typebox_1.Type.ReadonlyOptional(core_1.RevisionTagSchema),
}, noAdditionalProps);
exports.EncodedModularChangeset = typebox_1.Type.Object({
    maxId: typebox_1.Type.Optional(exports.ChangesetLocalIdSchema),
    changes: EncodedFieldChangeMap,
    revisions: typebox_1.Type.ReadonlyOptional(typebox_1.Type.Array(EncodedRevisionInfo)),
}, noAdditionalProps);
//# sourceMappingURL=modularChangeFormat.js.map