"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.mintRevisionTag = exports.isRevisionTag = exports.assertIsRevisionTag = exports.areEqualChangeAtomIds = exports.RevisionTagSchema = exports.SessionIdSchema = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
const id_compressor_1 = require("@fluidframework/id-compressor");
const util_1 = require("../../util");
exports.SessionIdSchema = (0, util_1.brandedStringType)();
exports.RevisionTagSchema = (0, util_1.brandedStringType)();
/**
 * @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 `RevisionTag` from the given string, or fails if the string is not a valid `RevisionTag`
 */
function assertIsRevisionTag(revision) {
    (0, core_utils_1.assert)(isRevisionTag(revision), 0x577 /* Expected revision to be valid RevisionTag */);
    return revision;
}
exports.assertIsRevisionTag = assertIsRevisionTag;
/**
 * @returns true iff the given string is a valid `RevisionTag`
 */
function isRevisionTag(revision) {
    return (0, id_compressor_1.isStableId)(revision);
}
exports.isRevisionTag = isRevisionTag;
/**
 * @returns a random, universally unique `RevisionTag`
 */
function mintRevisionTag() {
    return (0, util_1.generateStableId)();
}
exports.mintRevisionTag = mintRevisionTag;
/**
 * 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