/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { type TreeStatus } from "../../feature-libraries/index.js";
import { type TreeLeafValue, type ImplicitAllowedTypes, type TreeNodeFromImplicitAllowedTypes } from "../schemaTypes.js";
import { type TreeNodeSchema, type TreeNode, type TreeChangeEvents } from "../core/index.js";
/**
 * Provides various functions for analyzing {@link TreeNode}s.
 * * @remarks
 * This type should only be used via the public `Tree` export.
 * @privateRemarks
 * Due to limitations of API-Extractor link resolution, this type can't be moved into internalTypes but should be considered just an implementation detail of the `Tree` export.
 *
 * Inlining the typing of this interface onto the `Tree` object provides slightly different .d.ts generation,
 * which avoids typescript expanding the type of TreeNodeSchema and thus encountering
 * https://github.com/microsoft/rushstack/issues/1958.
 * @sealed @public
 */
export interface TreeNodeApi {
    /**
     * The schema information for this node.
     */
    schema(node: TreeNode | TreeLeafValue): TreeNodeSchema;
    /**
     * Narrow the type of the given value if it satisfies the given schema.
     * @example
     * ```ts
     * if (node.is(myNode, Point)) {
     *     const y = myNode.y; // `myNode` is now known to satisfy the `Point` schema and therefore has a `y` coordinate.
     * }
     * ```
     */
    is<TSchema extends ImplicitAllowedTypes>(value: unknown, schema: TSchema): value is TreeNodeFromImplicitAllowedTypes<TSchema>;
    /**
     * Return the node under which this node resides in the tree (or undefined if this is a root node of the tree).
     */
    parent(node: TreeNode): TreeNode | undefined;
    /**
     * The key of the given node under its parent.
     * @remarks
     * If `node` is an element in a {@link (TreeArrayNode:interface)}, this returns the index of `node` in the array node (a `number`).
     * Otherwise, this returns the key of the field that it is under (a `string`).
     */
    key(node: TreeNode): string | number;
    /**
     * Register an event listener on the given node.
     * @param node - The node whose events should be subscribed to.
     * @param eventName - Which event to subscribe to.
     * @param listener - The callback to trigger for the event. The tree can be read during the callback, but it is invalid to modify the tree during this callback.
     * @returns A callback function which will deregister the event.
     * This callback should be called only once.
     */
    on<K extends keyof TreeChangeEvents>(node: TreeNode, eventName: K, listener: TreeChangeEvents[K]): () => void;
    /**
     * Returns the {@link TreeStatus} of the given node.
     */
    status(node: TreeNode): TreeStatus;
    /**
     * Returns the {@link SchemaFactory.identifier | identifier} of the given node in the most compressed form possible.
     * @remarks
     * If the node's identifier is a valid UUID that was automatically generated by the SharedTree, then this will return a process-unique integer corresponding to that identifier.
     * Note that the node must already have been inserted into the tree in order to retrieve a generated UUID (or shortId will error).
     * This is useful for performance-sensitive scenarios involving many nodes with identifiers that need to be compactly retained in memory or used for efficient lookup.
     *
     * If the node's identifier is any other user-provided string, then this will return that string.
     *
     * If the node has no identifier (that is, it has no {@link SchemaFactory.identifier | identifier} field), then this returns `undefined`.
     *
     * If the node has more than one identifier, then this will throw an error.
     *
     * The returned integer must not be serialized or preserved outside of the current process.
     * Its lifetime is that of the current in-memory instance of the FF container for this client, and it is not guaranteed to be unique or stable outside of that context.
     * The same node's identifier may, for example, be different across multiple sessions for the same client and document, or different across two clients in the same session.
     */
    shortId(node: TreeNode): number | string | undefined;
}
/**
 * The `Tree` object holds various functions for analyzing {@link TreeNode}s.
 */
export declare const treeNodeApi: TreeNodeApi;
/**
 * Returns a schema for a value if the value is a {@link TreeNode} or a {@link TreeLeafValue}.
 * Returns undefined for other values.
 */
export declare function tryGetSchema(value: unknown): undefined | TreeNodeSchema;
//# sourceMappingURL=treeNodeApi.d.ts.map