/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { FieldKey, TreeFieldStoredSchema, ITreeCursorSynchronous, TreeNodeSchemaIdentifier, Value, StoredSchemaRepository, TreeStoredSchema, StoredSchemaCollection } from "../../core";
import { FullSchemaPolicy } from "../modular-schema";
import { TreeChunk } from "./chunk";
import { BasicChunk } from "./basicChunk";
import { FieldShape, TreeShape, UniformChunk } from "./uniformChunk";
export interface Disposable {
    /**
     * Cleans up resources used by this, such as inbound event registrations.
     */
    dispose(): void;
}
/**
 * Creates a ChunkPolicy which responds to schema changes.
 */
export declare function makeTreeChunker(schema: StoredSchemaRepository, policy: FullSchemaPolicy): IChunker;
/**
 * Extends ChunkPolicy to include stateful details required by ChunkedForest.
 *
 * This extra complexity is mostly due to the fact that schema can change over time,
 * and that chunk policy uses caching which thus needs invalidation.
 */
export interface IChunker extends ChunkPolicy, Disposable {
    readonly schema: StoredSchemaRepository;
    clone(schema: StoredSchemaRepository): IChunker;
}
/**
 * Indicates that there are multiple possible `TreeShape` trees with a given type can have.
 *
 * @remarks
 * For example, a schema transitively containing a sequence field, optional field, or allowing multiple child types will be Polymorphic.
 * See `tryShapeFromSchema` for how to tell if a type is Polymorphic.
 *
 * TODO: cache some of the possible shapes here.
 */
export declare class Polymorphic {
}
/**
 * See `Polymorphic`.
 * For now Polymorphic is stateless, so just use a singleton.
 */
export declare const polymorphic: Polymorphic;
/**
 * Information about the possible shapes a tree could take based on its type.
 * Note that this information is for a specific version of the schema.
 */
export type ShapeInfo = TreeShape | Polymorphic;
export declare class Chunker implements IChunker {
    readonly schema: StoredSchemaRepository;
    readonly policy: FullSchemaPolicy;
    readonly sequenceChunkSplitThreshold: number;
    readonly sequenceChunkInlineThreshold: number;
    readonly uniformChunkNodeCount: number;
    private readonly tryShapeFromSchema;
    /**
     * Cache for information about possible shapes for types.
     * Corresponds to the version of the schema in `schema`.
     * Cleared when `schema` changes.
     */
    private readonly typeShapes;
    private unregisterSchemaCallback;
    constructor(schema: StoredSchemaRepository, policy: FullSchemaPolicy, sequenceChunkSplitThreshold: number, sequenceChunkInlineThreshold: number, uniformChunkNodeCount: number, tryShapeFromSchema: (schema: TreeStoredSchema, policy: FullSchemaPolicy, type: TreeNodeSchemaIdentifier, shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>) => ShapeInfo);
    clone(schema: StoredSchemaRepository): IChunker;
    shapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo;
    dispose(): void;
    private schemaChanged;
}
/**
 * Get a TreeChunk for the current node (and its children) of cursor.
 * This will copy if needed, but add refs to existing chunks which hold the data.
 */
export declare function chunkTree(cursor: ITreeCursorSynchronous, policy: ChunkPolicy): TreeChunk;
/**
 * Get a TreeChunk[] for the current field (and its children) of cursor.
 * This will copy if needed, but add refs to existing chunks which hold the data.
 */
export declare function chunkField(cursor: ITreeCursorSynchronous, policy: ChunkPolicy): TreeChunk[];
/**
 * Get a BasicChunk for the current node (and its children) of cursor.
 * This will copy if needed, and add refs to existing chunks which hold the data.
 */
export declare function basicChunkTree(cursor: ITreeCursorSynchronous, policy: ChunkPolicy): BasicChunk;
export declare function makePolicy(policy?: Partial<ChunkPolicy>): ChunkPolicy;
export declare function shapesFromSchema(schema: StoredSchemaCollection, policy: FullSchemaPolicy): Map<TreeNodeSchemaIdentifier, ShapeInfo>;
/**
 * If `schema` has only one shape, return it.
 *
 * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.
 */
export declare function tryShapeFromSchema(schema: StoredSchemaCollection, policy: FullSchemaPolicy, type: TreeNodeSchemaIdentifier, shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>): ShapeInfo;
/**
 * If `schema` has only one shape, return it.
 *
 * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.
 */
export declare function tryShapeFromFieldSchema(schema: StoredSchemaCollection, policy: FullSchemaPolicy, type: TreeFieldStoredSchema, key: FieldKey, shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>): FieldShape | undefined;
/**
 * Default settings for use for {@link ChunkPolicy}.
 * Use `makeTreeChunker` to create a policy with the defaults, but leverages to schema.
 */
export declare const defaultChunkPolicy: ChunkPolicy;
export declare const basicOnlyChunkPolicy: ChunkPolicy;
/**
 * Policy for how to chunk a tree.
 */
export interface ChunkPolicy {
    /**
     * Group sequences longer than this into into sequence chunks of this length or less.
     *
     * Must be at least 2.
     * Can be set to `Number.POSITIVE_INFINITY` to never introduce extra sequence chunks.
     */
    readonly sequenceChunkSplitThreshold: number;
    /**
     * SequenceChunks this long or shorter may get inlined into their parent chunk.
     */
    readonly sequenceChunkInlineThreshold: number;
    /**
     * Maximum total nodes to put in a UniformChunk.
     */
    readonly uniformChunkNodeCount: number;
    /**
     * Returns information about the shapes trees of type `schema` can take.
     */
    shapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo;
}
export declare function chunkRange(cursor: ITreeCursorSynchronous, policy: ChunkPolicy, length: number, skipLastNavigation: boolean): TreeChunk[];
export declare function insertValues(cursor: ITreeCursorSynchronous, shape: TreeShape, values: Value[]): void;
/**
 * Read up to `maxTopLevelLength` nodes from `cursor`, stopping when limit is hit or type of node changes.
 *
 * This requires that the all trees with matching type match the provided shape.
 * This cannot be used if other shapes are possible for this type.
 *
 * If this stops early due to the type changing, `skipLastNavigation` is not involved:
 * `skipLastNavigation` only determines if the cursor will be left on the node after the last one (possibly exiting the field)
 * if the full length is used.
 */
export declare function uniformChunkFromCursor(cursor: ITreeCursorSynchronous, shape: TreeShape, maxTopLevelLength: number, skipLastNavigation: boolean): UniformChunk;
//# sourceMappingURL=chunkTree.d.ts.map