/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { FieldKey, ITreeCursorSynchronous, MapTree, Value } from "../core/index.js";
import { TreeDataContext } from "./fieldGenerator.js";
import { FlexFieldKind } from "./modular-schema/index.js";
import { AllowedTypesToFlexInsertableTree, InsertableFlexField, InsertableFlexNode } from "./schema-aware/index.js";
import { AllowedTypeSet, FlexAllowedTypes, FlexFieldSchema, FlexTreeNodeSchema, FlexTreeSchema } from "./typed-schema/index.js";
/**
 * This library defines a tree data format that can infer its types from context.
 * It can only be used when the schema is known.
 * The format is optimized for ergonomics when the developer knows the schema,
 * and needs to declare or navigate trees.
 *
 * The format defined here is very tolerant to optimize for flexibility of expressing trees:
 * APIs exposing data in this format should likely further constrain what is allowed.
 * For example guarantee which fields and nodes should be inlined, and that types will be required everywhere.
 *
 * This is from Flex tree one which has been deleted and should no longer be used!
 */
/**
 * Check if NewFieldContent is made of {@link ITreeCursor}s.
 *
 * Useful when APIs want to take in tree data in multiple formats, including cursors.
 */
export declare function areCursors(data: NewFieldContent): data is ITreeCursorSynchronous | readonly ITreeCursorSynchronous[];
/**
 * A symbol for the name of the type of a tree in contexts where string keys are already in use for fields.
 * See {@link TreeNodeSchemaIdentifier}.
 * @internal
 */
export declare const typeNameSymbol: unique symbol;
/**
 * A symbol for the value of a tree node in contexts where string keys are already in use for fields.
 * @internal
 */
export declare const valueSymbol: unique symbol;
export declare function getFieldKind(fieldSchema: FlexFieldSchema): FlexFieldKind;
/**
 * @returns all allowed child types for `typeSet`.
 */
export declare function getAllowedTypes(schemaData: FlexTreeSchema, typeSet: AllowedTypeSet): ReadonlySet<FlexTreeNodeSchema>;
/**
 * @returns all types, for which the data is schema-compatible.
 */
export declare function getPossibleTypes(context: FlexTreeSchema, typeSet: AllowedTypeSet, data: ContextuallyTypedNodeData): FlexTreeNodeSchema[];
/**
 * A symbol used to define a {@link MarkedArrayLike} interface.
 * @internal
 */
export declare const arrayLikeMarkerSymbol: unique symbol;
/**
 * Can be used to mark a type which works like an array, but is not compatible with `Array.isArray`.
 * @internal
 */
export interface MarkedArrayLike<TGet, TSet extends TGet = TGet> extends ArrayLikeMut<TGet, TSet> {
    readonly [arrayLikeMarkerSymbol]: true;
    [Symbol.iterator](): IterableIterator<TGet>;
}
/**
 * Can be used to mark a type which works like an array, but is not compatible with `Array.isArray`.
 * @internal
 */
export interface ReadonlyMarkedArrayLike<T> extends ArrayLike<T> {
    readonly [arrayLikeMarkerSymbol]: true;
    [Symbol.iterator](): IterableIterator<T>;
}
/**
 * `ArrayLike` numeric indexed access, but writable.
 *
 * @remarks
 * Note that due to language limitations, this also allows reading as TSet.
 * This is why `TSet extends TGet` is required.
 *
 * See https://github.com/microsoft/TypeScript/issues/43826.
 * @internal
 */
export interface ArrayLikeMut<TGet, TSet extends TGet = TGet> extends ArrayLike<TGet> {
    [n: number]: TSet;
}
/**
 * Content of a tree which needs external schema information to interpret.
 *
 * This format is intended for concise authoring of tree literals when the schema is statically known.
 *
 * Once schema aware APIs are implemented, they can be used to provide schema specific subsets of this type.
 * @internal
 */
export type ContextuallyTypedNodeData = ContextuallyTypedNodeDataObject | number | string | boolean | null | readonly ContextuallyTypedNodeData[] | MarkedArrayLike<ContextuallyTypedNodeData>;
/**
 * Content of a field which needs external schema information to interpret.
 *
 * This format is intended for concise authoring of tree literals when the schema is statically known.
 *
 * Once schema aware APIs are implemented, they can be used to provide schema specific subsets of this type.
 * @internal
 */
export type ContextuallyTypedFieldData = ContextuallyTypedNodeData | undefined;
/**
 * Checks the type of a `ContextuallyTypedNodeData`.
 */
export declare function isArrayLike(data: ContextuallyTypedFieldData): data is readonly ContextuallyTypedNodeData[] | ReadonlyMarkedArrayLike<ContextuallyTypedNodeData>;
/**
 * Checks the type of a `ContextuallyTypedNodeData`.
 * @internal
 */
export declare function isContextuallyTypedNodeDataObject(data: ContextuallyTypedNodeData | undefined): data is ContextuallyTypedNodeDataObject;
/**
 * Object case of {@link ContextuallyTypedNodeData}.
 * @internal
 */
export interface ContextuallyTypedNodeDataObject {
    /**
     * Value stored on this node.
     */
    readonly [valueSymbol]?: Value;
    /**
     * The type of the node.
     * If this node is well-formed, it must follow this schema.
     */
    readonly [typeNameSymbol]?: string;
    /**
     * Fields of this node, indexed by their field keys.
     *
     * Allow explicit undefined for compatibility with FlexTree, and type-safety on read.
     */
    [key: FieldKey]: ContextuallyTypedFieldData;
    /**
     * Fields of this node, indexed by their field keys as strings.
     *
     * Allow unbranded field keys as a convenience for literals.
     */
    [key: string]: ContextuallyTypedFieldData;
}
/**
 * Construct a tree from ContextuallyTypedNodeData.
 *
 * TODO: this should probably be refactored into a `try` function which either returns a Cursor or a SchemaError with a path to the error.
 * @returns a cursor in Nodes mode for a single node containing the provided data.
 * @internal
 */
export declare function cursorFromContextualData(context: TreeDataContext, typeSet: AllowedTypeSet, data: ContextuallyTypedNodeData): ITreeCursorSynchronous;
/**
 * Strongly typed {@link cursorFromContextualData} for a TreeNodeSchema.
 * @returns a cursor in Nodes mode for a single node containing the provided data.
 * @internal
 */
export declare function cursorForTypedTreeData<T extends FlexTreeNodeSchema>(context: TreeDataContext, schema: T, data: InsertableFlexNode<T>): ITreeCursorSynchronous;
/**
 * Strongly typed {@link cursorFromContextualData} for AllowedTypes.
 * @returns a cursor in Nodes mode for a single node containing the provided data.
 * @internal
 */
export declare function cursorForTypedData<T extends FlexAllowedTypes>(context: TreeDataContext, schema: T, data: AllowedTypesToFlexInsertableTree<T>): ITreeCursorSynchronous;
/**
 * Construct a tree from ContextuallyTypedNodeData.
 * Returns a cursor in Field mode.
 *
 * TODO: this should probably be refactored into a `try` function which either returns a Cursor or a SchemaError with a path to the error.
 */
export declare function cursorsFromContextualData(context: TreeDataContext, field: FlexFieldSchema, data: ContextuallyTypedNodeData | undefined): ITreeCursorSynchronous;
/**
 * Strongly typed {@link cursorsFromContextualData} for a TreeFieldSchema
 * @internal
 */
export declare function cursorsForTypedFieldData<T extends FlexFieldSchema>(context: TreeDataContext, schema: T, data: InsertableFlexField<T>): ITreeCursorSynchronous;
/**
 * Construct a MapTree from ContextuallyTypedNodeData.
 *
 * TODO: this should probably be refactored into a `try` function which either returns a MapTree or a SchemaError with a path to the error.
 * TODO: test suite.
 *
 * @remarks
 * This version is only exported as a more testable entry point than `cursorFromContextualData` which keeps the use of `MapTree` as an implementation detail.
 * This should not be reexported from the parent module.
 */
export declare function applyTypesFromContext(context: TreeDataContext, typeSet: AllowedTypeSet, data: ContextuallyTypedNodeData): MapTree;
/**
 * Construct a MapTree from ContextuallyTypedNodeData.
 *
 * TODO: this should probably be refactored into a `try` function which either returns a MapTree or a SchemaError with a path to the error.
 * TODO: test suite.
 *
 * @remarks
 * This version is only exported as a more testable entry point than `cursorsFromContextualData` which keeps the use of `MapTree` as an implementation detail.
 * This should not be reexported from the parent module.
 */
export declare function applyFieldTypesFromContext(context: TreeDataContext, field: FlexFieldSchema, data: ContextuallyTypedFieldData): MapTree[];
/**
 * Content to use for a field.
 *
 * When used, this content will be deeply copied into the tree, and must comply with the schema.
 *
 * The content must follow the {@link Multiplicity} of the {@link FlexFieldKind}:
 * - use a single cursor for an `optional` or `value` field;
 * - use array of cursors for a `sequence` field;
 *
 * TODO: this should allow a field cursor instead of an array of cursors.
 * TODO: Make this generic so a variant of this type that allows placeholders for detached sequences to consume.
 * @internal
 */
export type NewFieldContent = ITreeCursorSynchronous | readonly ITreeCursorSynchronous[] | ContextuallyTypedFieldData;
/**
 * Convert NewFieldContent into ITreeCursorSynchronous.
 * The returned cursor will be in Field mode.
 */
export declare function normalizeNewFieldContent(context: TreeDataContext, schema: FlexFieldSchema, content: NewFieldContent): ITreeCursorSynchronous;
//# sourceMappingURL=contextuallyTyped.d.ts.map