/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { ErasedType } from "@fluidframework/core-interfaces/internal";
import type { IChannelAttributes, IChannelFactory, IFluidDataStoreRuntime, IChannelServices, IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
import type { ISharedObject } from "@fluidframework/shared-object-base/internal";
import { type ICodecOptions } from "../codec/index.js";
import { type GraphCommit, type IEditableForest, type JsonableTree, type TreeStoredSchema, TreeStoredSchemaRepository, type TreeStoredSchemaSubscription } from "../core/index.js";
import { TreeCompressionStrategy } from "../feature-libraries/index.js";
import { type ClonableSchemaAndPolicy, SharedTreeCore } from "../shared-tree-core/index.js";
import { type ITree, type ImplicitFieldSchema, type ReadSchema, type SimpleTreeSchema, type TreeView, type TreeViewAlpha, type TreeViewConfiguration, type UnsafeUnknownSchema, type VerboseTree } from "../simple-tree/index.js";
import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
import type { SharedTreeChange } from "./sharedTreeChangeTypes.js";
import type { SharedTreeEditBuilder } from "./sharedTreeEditBuilder.js";
import { type TreeCheckout, type BranchableTree } from "./treeCheckout.js";
import type { IIdCompressor } from "@fluidframework/id-compressor";
/**
 * Copy of data from an {@link ISharedTree} at some point in time.
 * @remarks
 * This is unrelated to Fluids concept of "snapshots".
 */
export interface SharedTreeContentSnapshot {
    /**
     * The schema stored in the document.
     *
     * @remarks
     * Edits to the schema can mutate the schema stored of the tree which took this snapshot (but this snapshot will remain the same)
     * This is mainly useful for debugging cases where schematize reports an incompatible view schema.
     */
    readonly schema: TreeStoredSchema;
    /**
     * All {@link TreeStatus.InDocument} content.
     */
    readonly tree: JsonableTree[];
    /**
     * All {@link TreeStatus.Removed} content.
     */
    readonly removed: [string | number | undefined, number, JsonableTree][];
}
/**
 * {@link ITree} extended with some non-public APIs.
 * @internal
 */
export interface ITreeInternal extends ISharedObject, ITree {
    /**
     * Exports root in the same format as {@link TreeAlpha.(exportVerbose:1)} using stored keys.
     * @privateRemarks
     * TODO:
     * This should probably get promoted to a public API on ITree eventually.
     */
    exportVerbose(): VerboseTree | undefined;
    /**
     * Exports the SimpleTreeSchema that is stored in the tree, using stored keys for object fields.
     * @remarks
     * To get the schema using property keys, use {@link getSimpleSchema} on the view schema.
     */
    exportSimpleSchema(): SimpleTreeSchema;
}
/**
 * {@link ITreeInternal} extended with some non-exported APIs.
 */
export interface ISharedTree extends ISharedObject, ITreeInternal {
    /**
     * Provides a copy of the current content of the tree.
     * This can be useful for inspecting the tree when no suitable view schema is available.
     * This is only intended for use in testing and exceptional code paths: it is not performant.
     *
     * This does not include everything that is included in a tree summary, since information about how to merge future edits is omitted.
     */
    contentSnapshot(): SharedTreeContentSnapshot;
}
/**
 * Shared tree, configured with a good set of indexes and field kinds which will maintain compatibility over time.
 *
 * TODO: detail compatibility requirements.
 */
export declare class SharedTree extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange> implements ISharedTree {
    readonly checkout: TreeCheckout;
    get storedSchema(): TreeStoredSchemaRepository;
    constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, optionsParam: SharedTreeOptionsInternal, telemetryContextPrefix?: string);
    exportVerbose(): VerboseTree | undefined;
    exportSimpleSchema(): SimpleTreeSchema;
    contentSnapshot(): SharedTreeContentSnapshot;
    viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(config: TreeViewConfiguration<ReadSchema<TRoot>>): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;
    viewWith<TRoot extends ImplicitFieldSchema>(config: TreeViewConfiguration<TRoot>): SchematizingSimpleTreeView<TRoot> & TreeView<TRoot>;
    protected loadCore(services: IChannelStorageService): Promise<void>;
    protected didAttach(): void;
    protected applyStashedOp(...args: Parameters<SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>["applyStashedOp"]>): void;
    protected submitCommit(commit: GraphCommit<SharedTreeChange>, schemaAndPolicy: ClonableSchemaAndPolicy, isResubmit: boolean): void;
}
/**
 * Get a {@link BranchableTree} from a {@link ITree}.
 * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
 * @privateRemarks This function will be removed if/when the branching API becomes public,
 * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
 * @alpha
 * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
 */
export declare function getBranch(tree: ITree): BranchableTree;
/**
 * Get a {@link BranchableTree} from a {@link TreeView}.
 * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
 * Branches are currently an unstable "alpha" API and are subject to change in the future.
 * @privateRemarks This function will be removed if/when the branching API becomes public,
 * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
 * @alpha
 * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
 */
export declare function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(view: TreeViewAlpha<T>): BranchableTree;
/**
 * Format versions supported by SharedTree.
 *
 * Each version documents a required minimum version of the \@fluidframework/tree package.
 * @alpha
 */
export declare const SharedTreeFormatVersion: {
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     *
     * @deprecated - FF does not currently plan on supporting this format long-term.
     * Do not write production documents using this format, as they may not be loadable in the future.
     */
    readonly v1: 1;
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     */
    readonly v2: 2;
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     */
    readonly v3: 3;
};
/**
 * Format versions supported by SharedTree.
 *
 * Each version documents a required minimum version of the \@fluidframework/tree package.
 * @alpha
 * @privateRemarks
 * See packages/dds/tree/docs/main/compatibility.md for information on how to add support for a new format.
 *
 * TODO: Before this gets promoted past Alpha,
 * a separate abstraction more suited for use in the public API should be adopted rather than reusing the same types used internally.
 * Such an abstraction should probably be in the form of a Fluid-Framework wide compatibility enum.
 */
export type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;
/**
 * Configuration options for SharedTree.
 * @alpha
 */
export type SharedTreeOptions = Partial<ICodecOptions> & Partial<SharedTreeFormatOptions> & ForestOptions;
export interface SharedTreeOptionsInternal extends SharedTreeOptions {
    disposeForksAfterTransaction?: boolean;
}
/**
 * Configuration options for SharedTree's internal tree storage.
 * @alpha
 */
export interface ForestOptions {
    /**
     * The {@link ForestType} indicating which forest type should be created for the SharedTree.
     */
    readonly forest?: ForestType;
}
/**
 * Options for configuring the persisted format SharedTree uses.
 * @alpha
 */
export interface SharedTreeFormatOptions {
    /**
     * See {@link TreeCompressionStrategy}.
     * default: TreeCompressionStrategy.Compressed
     */
    treeEncodeType: TreeCompressionStrategy;
    /**
     * The format version SharedTree should use to persist documents.
     *
     * This option has compatibility implications for applications using SharedTree.
     * Each version documents a required minimum version of \@fluidframework/tree.
     * If this minimum version fails to be met, the SharedTree may fail to load.
     * To be safe, application authors should verify that they have saturated this version
     * of \@fluidframework/tree in their ecosystem before changing the format version.
     *
     * This option defaults to SharedTreeFormatVersion.v2.
     */
    formatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion];
}
/**
 * Used to distinguish between different forest types.
 * @remarks
 * Current options are {@link ForestTypeReference}, {@link ForestTypeOptimized} and {@link ForestTypeExpensiveDebug}.
 * @sealed @alpha
 */
export interface ForestType extends ErasedType<"ForestType"> {
}
/**
 * Reference implementation of forest.
 * @remarks
 * A simple implementation with minimal complexity and moderate debuggability, validation and performance.
 * @privateRemarks
 * The "ObjectForest" forest type.
 * @alpha
 */
export declare const ForestTypeReference: ForestType;
/**
 * Optimized implementation of forest.
 * @remarks
 * A complex optimized forest implementation, which has minimal validation and debuggability to optimize for performance.
 * Uses an internal representation optimized for size designed to scale to larger datasets with reduced overhead.
 * @privateRemarks
 * The "ChunkedForest" forest type.
 * @alpha
 */
export declare const ForestTypeOptimized: ForestType;
/**
 * Slow implementation of forest intended only for debugging.
 * @remarks
 * Includes validation with scales poorly.
 * May be asymptotically slower than {@link ForestTypeReference}, and may perform very badly with larger data sizes.
 * @privateRemarks
 * The "ObjectForest" forest type with expensive asserts for debugging.
 * @alpha
 */
export declare const ForestTypeExpensiveDebug: ForestType;
/**
 * Build and return a forest of the requested type.
 */
export declare function buildConfiguredForest(factory: ForestType, schema: TreeStoredSchemaSubscription, idCompressor: IIdCompressor): IEditableForest;
export declare const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal>;
/**
 * A channel factory that creates {@link ISharedTree}s.
 */
export declare class SharedTreeFactory implements IChannelFactory<ISharedTree> {
    private readonly options;
    readonly type: string;
    readonly attributes: IChannelAttributes;
    constructor(options?: SharedTreeOptionsInternal);
    load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, channelAttributes: Readonly<IChannelAttributes>): Promise<SharedTree>;
    create(runtime: IFluidDataStoreRuntime, id: string): SharedTree;
}
//# sourceMappingURL=sharedTree.d.ts.map