"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.mintCommit = exports.asChangeAtomId = exports.makeChangeAtomId = exports.areEqualChangeAtomIds = exports.RevisionTagSchema = exports.SessionIdSchema = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../../util/index.js");
/**
 * The identifier for a particular session/user/client that can generate `GraphCommit`s
 */
exports.SessionIdSchema = (0, index_js_1.brandedStringType)();
exports.RevisionTagSchema = typebox_1.Type.Union([
    typebox_1.Type.Literal("root"),
    (0, index_js_1.brandedNumberType)(),
]);
/**
 * @returns true iff `a` and `b` are the same.
 */
function areEqualChangeAtomIds(a, b) {
    return a.localId === b.localId && a.revision === b.revision;
}
exports.areEqualChangeAtomIds = areEqualChangeAtomIds;
/**
 * @returns a ChangeAtomId with the given revision and local ID.
 */
function makeChangeAtomId(localId, revision) {
    return revision === undefined ? { localId } : { localId, revision };
}
exports.makeChangeAtomId = makeChangeAtomId;
function asChangeAtomId(id) {
    return typeof id === "object" ? id : { localId: id };
}
exports.asChangeAtomId = asChangeAtomId;
/**
 * Creates a new graph commit object. This is useful for creating copies of commits with different parentage.
 * @param parent - the parent of the new commit
 * @param commit - the contents of the new commit object
 * @returns the new commit object
 */
// Note that this function is synchronous, and therefore it is not a Promise.
// However, it is still a strong commit-mint.
function mintCommit(parent, commit) {
    const { revision, change } = commit;
    return {
        revision,
        change,
        parent,
    };
}
exports.mintCommit = mintCommit;
//# sourceMappingURL=types.js.map