/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { FieldKey, Value, TreeStoredSchema, ValueSchema, FieldStoredSchema, LocalFieldKey, SchemaDataAndPolicy, TreeSchemaIdentifier, TreeTypeSet, MapTree, ITreeCursorSynchronous } from "../core";
import { AllowedTypes, FieldKind, FieldSchema, TreeSchema } from "./modular-schema";
import { AllowedTypesToTypedTrees, ApiMode, TypedField, TypedNode } from "./schema-aware";
/**
 * A symbol for the name of the type of a tree in contexts where string keys are already in use for fields.
 * See {@link TreeSchemaIdentifier}.
 * @alpha
 */
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.
 * @alpha
 */
export declare const valueSymbol: unique symbol;
/**
 * @alpha
 */
export declare type PrimitiveValue = string | boolean | number;
/**
 * @alpha
 */
export declare function isPrimitiveValue(nodeValue: Value): nodeValue is PrimitiveValue;
export declare function allowsValue(schema: ValueSchema, nodeValue: Value): boolean;
/**
 * @returns the key and the schema of the primary field out of the given tree schema.
 *
 * See note on {@link EmptyKey} for what is a primary field.
 * @alpha
 */
export declare function getPrimaryField(schema: TreeStoredSchema): {
    key: LocalFieldKey;
    schema: FieldStoredSchema;
} | undefined;
export declare function getFieldSchema(field: FieldKey, schemaData: SchemaDataAndPolicy, schema?: TreeStoredSchema): FieldStoredSchema;
export declare function getFieldKind(fieldSchema: FieldStoredSchema): FieldKind;
/**
 * @returns all allowed child types for `typeSet`.
 */
export declare function getAllowedTypes(schema: SchemaDataAndPolicy, typeSet: TreeTypeSet): ReadonlySet<TreeSchemaIdentifier>;
/**
 * @returns all types, for which the data is schema-compatible.
 */
export declare function getPossibleTypes(schemaData: SchemaDataAndPolicy, typeSet: TreeTypeSet, data: ContextuallyTypedNodeData): TreeSchemaIdentifier[];
/**
 * A symbol used to define a {@link MarkedArrayLike} interface.
 * @alpha
 */
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`.
 * @alpha
 */
export interface MarkedArrayLike<TGet, TSet extends TGet = TGet> extends ArrayLikeMut<TGet, TSet> {
    readonly [arrayLikeMarkerSymbol]: true;
    [Symbol.iterator](): IterableIterator<TGet>;
}
/**
 * `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.
 * @alpha
 */
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.
 * @alpha
 */
export declare type ContextuallyTypedNodeData = ContextuallyTypedNodeDataObject | PrimitiveValue | 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.
 * @alpha
 */
export declare type ContextuallyTypedFieldData = ContextuallyTypedNodeData | undefined;
/**
 * Checks the type of a `ContextuallyTypedNodeData`.
 */
export declare function isArrayLike(data: ContextuallyTypedFieldData): data is readonly ContextuallyTypedNodeData[] | MarkedArrayLike<ContextuallyTypedNodeData>;
/**
 * Checks the type of a `ContextuallyTypedNodeData`.
 * @alpha
 */
export declare function isWritableArrayLike(data: ContextuallyTypedFieldData): data is MarkedArrayLike<ContextuallyTypedNodeData>;
/**
 * Checks the type of a `ContextuallyTypedNodeData`.
 * @alpha
 */
export declare function isContextuallyTypedNodeDataObject(data: ContextuallyTypedNodeData | undefined): data is ContextuallyTypedNodeDataObject;
/**
 * Object case of {@link ContextuallyTypedNodeData}.
 * @alpha
 */
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 EditableTree, and type-safety on read.
     */
    [key: FieldKey]: ContextuallyTypedFieldData;
    /**
     * Fields of this node, indexed by their field keys as strings.
     *
     * Allow unbranded local field keys and 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.
 * @alpha
 */
export declare function cursorFromContextualData(schemaData: SchemaDataAndPolicy, typeSet: TreeTypeSet, data: ContextuallyTypedNodeData): ITreeCursorSynchronous;
/**
 * Strongly typed {@link cursorFromContextualData} for a TreeSchema
 * @alpha
 */
export declare function cursorForTypedTreeData<T extends TreeSchema>(schemaData: SchemaDataAndPolicy, schema: T, data: TypedNode<T, ApiMode.Simple>): ITreeCursorSynchronous;
/**
 * Strongly typed {@link cursorFromContextualData} for AllowedTypes.
 * @alpha
 */
export declare function cursorForTypedData<T extends AllowedTypes>(schemaData: SchemaDataAndPolicy, schema: T, data: AllowedTypesToTypedTrees<ApiMode.Simple, T>): ITreeCursorSynchronous;
/**
 * 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.
 * TODO: migrate APIs which take arrays of cursors to take cursors in fields mode.
 */
export declare function cursorsFromContextualData(schemaData: SchemaDataAndPolicy, field: FieldStoredSchema, data: ContextuallyTypedNodeData | undefined): ITreeCursorSynchronous[];
/**
 * Strongly typed {@link cursorsFromContextualData} for a FieldSchema
 * @alpha
 */
export declare function cursorsForTypedFieldData<T extends FieldSchema>(schemaData: SchemaDataAndPolicy, schema: T, data: TypedField<ApiMode.Simple, 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(schemaData: SchemaDataAndPolicy, typeSet: TreeTypeSet, 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(schemaData: SchemaDataAndPolicy, field: FieldStoredSchema, data: ContextuallyTypedFieldData): MapTree[];
//# sourceMappingURL=contextuallyTyped.d.ts.map