"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeNavigationResult = exports.ITreeSubscriptionCursorState = exports.moveToDetachedField = exports.rootAnchor = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
const tree_1 = require("../tree");
/**
 * @param field - defaults to {@link rootField}.
 * @returns anchor to `field`.
 */
function rootAnchor(field = tree_1.rootField) {
    return {
        parent: undefined,
        fieldKey: (0, tree_1.detachedFieldAsKey)(field),
    };
}
exports.rootAnchor = rootAnchor;
/**
 * @param field - defaults to {@link rootField}.
 * @returns anchor to `field`.
 */
function moveToDetachedField(forest, cursorToMove, field = tree_1.rootField) {
    const result = forest.tryMoveCursorToField(rootAnchor(field), cursorToMove);
    (0, core_utils_1.assert)(result === 1 /* TreeNavigationResult.Ok */, 0x42d /* Navigation to detached fields should never fail */);
}
exports.moveToDetachedField = moveToDetachedField;
/**
 * @alpha
 */
var ITreeSubscriptionCursorState;
(function (ITreeSubscriptionCursorState) {
    /**
     * On the current revision of the forest.
     */
    ITreeSubscriptionCursorState[ITreeSubscriptionCursorState["Current"] = 0] = "Current";
    /**
     * Empty, but can be reused.
     */
    ITreeSubscriptionCursorState[ITreeSubscriptionCursorState["Cleared"] = 1] = "Cleared";
    /**
     * Freed and must not be used.
     */
    ITreeSubscriptionCursorState[ITreeSubscriptionCursorState["Freed"] = 2] = "Freed";
})(ITreeSubscriptionCursorState || (exports.ITreeSubscriptionCursorState = ITreeSubscriptionCursorState = {}));
/**
 * @alpha
 */
var TreeNavigationResult;
(function (TreeNavigationResult) {
    /**
     * Attempt to navigate cursor to a key or index that is outside the client's view.
     */
    TreeNavigationResult[TreeNavigationResult["NotFound"] = -1] = "NotFound";
    /**
     * Attempt to navigate cursor to a portion of the tree that has not yet been loaded.
     */
    TreeNavigationResult[TreeNavigationResult["Pending"] = 0] = "Pending";
    /**
     * ITreeReader successfully navigated to the desired node.
     */
    TreeNavigationResult[TreeNavigationResult["Ok"] = 1] = "Ok";
})(TreeNavigationResult || (exports.TreeNavigationResult = TreeNavigationResult = {}));
//# sourceMappingURL=forest.js.map