/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Adapters, FieldKey, TreeSchemaIdentifier, TreeTypeSet, ValueSchema } from "../../core";
import { MakeNominal, Assume, RestrictiveReadonlyRecord, _InlineTrick, FlattenKeys, Named } from "../../util";
import { FieldKinds } from "../default-field-kinds";
import { FieldKind, FullSchemaPolicy } from "../modular-schema";
import { LazyItem } from "./flexList";
import { ObjectToMap, WithDefault } from "./typeUtils";
/**
 * @alpha
 */
export interface Fields {
    readonly [key: string]: FieldSchema;
}
/**
 * @alpha
 */
export declare type NormalizeStructFieldsInner<T extends Fields> = {
    [Property in keyof T]: NormalizeField<T[Property]>;
};
/**
 * @alpha
 */
export declare type NormalizeStructFields<T extends Fields | undefined> = NormalizeStructFieldsInner<WithDefault<T, Record<string, never>>>;
/**
 * Placeholder for to `TreeSchema` to use in constraints where `TreeSchema` is desired but using it causes
 * recursive types to fail to compile due to TypeScript limitations.
 *
 * Using `TreeSchema` instead in some key "extends" clauses cause recursive types to error with:
 * "'theSchema' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer."
 *
 * TODO: how much more specific of a type can be provided without triggering the above error?
 * @alpha
 */
export declare type RecursiveTreeSchema = unknown;
/**
 * Placeholder for to `TreeSchemaSpecification` to use in constraints where `TreeSchemaSpecification` is desired but using it causes
 * recursive types to fail to compile due to TypeScript limitations.
 *
 * See `RecursiveTreeSchema`.
 *
 * TODO: how much more specific of a type can be provided without triggering the above error?
 * @alpha
 */
export declare type RecursiveTreeSchemaSpecification = unknown;
/**
 * T must extend TreeSchemaSpecification.
 * This can not be enforced using TypeScript since doing so breaks recursive type support.
 * See note on SchemaBuilder.fieldRecursive.
 * @alpha
 */
export declare class TreeSchema<Name extends string = string, T extends RecursiveTreeSchemaSpecification = TreeSchemaSpecification> {
    readonly builder: Named<string>;
    readonly structFields: ObjectToMap<NormalizeStructFields<Assume<T, TreeSchemaSpecification>["structFields"]>, FieldKey, FieldSchema>;
    readonly structFieldsObject: NormalizeStructFields<Assume<T, TreeSchemaSpecification>["structFields"]>;
    readonly mapFields: WithDefault<Assume<T, TreeSchemaSpecification>["mapFields"], undefined>;
    readonly leafValue: WithDefault<Assume<T, TreeSchemaSpecification>["leafValue"], undefined>;
    readonly name: Name & TreeSchemaIdentifier;
    readonly info: Assume<T, TreeSchemaSpecification>;
    constructor(builder: Named<string>, name: Name, info: T);
}
/**
 * @alpha
 */
export declare type MapSchema = TreeSchema & MapSchemaSpecification;
/**
 * @alpha
 */
export declare type LeafSchema = TreeSchema & LeafSchemaSpecification;
/**
 * TODO: this includes FieldNodeSchema when it shouldn't
 * @alpha
 */
export declare type StructSchema = TreeSchema & {
    [P in keyof (MapSchemaSpecification & LeafSchemaSpecification)]?: undefined;
};
/**
 * @alpha
 *
 * This is the subset of StructSchema that uses {@link EmptyKey} so the the old (editable-tree 1) API unboxes it.
 * TODO: Once that API is removed, this can be cleaned up and properly separated from StructSchema
 */
export declare type FieldNodeSchema = StructSchema & {
    /**
     * The fields of this node.
     * Only uses the {@link EmptyKey}.
     *
     * TODO: this extra indirection will be removed when refactoring TreeSchema (see other related TODOs for details).
     */
    structFieldsObject: {
        /**
         * The field this node wraps.
         * It is under the {@link EmptyKey}.
         */
        [""]: FieldSchema;
    };
};
export declare function schemaIsMap(schema: TreeSchema): schema is MapSchema;
export declare function schemaIsLeaf(schema: TreeSchema): schema is LeafSchema;
export declare function schemaIsFieldNode(schema: TreeSchema): schema is FieldNodeSchema;
export declare function schemaIsStruct(schema: TreeSchema): schema is StructSchema;
/**
 * Convert FieldSchemaSpecification | undefined into FieldSchema.
 * @alpha
 */
export declare type NormalizeField<T extends FieldSchema | undefined> = T extends FieldSchema ? T : FieldSchema<typeof FieldKinds.forbidden, []>;
/**
 * Allow any node (as long as it meets the schema for its own type).
 * @alpha
 */
export declare const Any: "Any";
/**
 * Allow any node (as long as it meets the schema for its own type).
 * @alpha
 */
export declare type Any = typeof Any;
/**
 * Tree type, but can be wrapped in a function to allow referring to types before they are declared.
 * This makes recursive and co-recursive types possible.
 * @alpha
 */
export declare type LazyTreeSchema = TreeSchema | (() => TreeSchema);
/**
 * Types for use in fields.
 *
 * "Any" is boxed in an array to allow use as variadic parameter.
 * @alpha
 */
export declare type AllowedTypes = [Any] | readonly LazyItem<TreeSchema>[];
/**
 * Checks if an {@link AllowedTypes} is {@link (Any:type)}.
 * @alpha
 */
export declare function allowedTypesIsAny(t: AllowedTypes): t is [Any];
/**
 * `TreeSchemaSpecification` for {@link SchemaBuilder.struct}.
 * @alpha
 */
export interface StructSchemaSpecification {
    readonly structFields: RestrictiveReadonlyRecord<string, FieldSchema>;
}
/**
 * `TreeSchemaSpecification` for {@link SchemaBuilder.map}.
 * @alpha
 */
export interface MapSchemaSpecification {
    readonly mapFields: MapFieldSchema;
}
/**
 * Subset of FieldSchema thats legal in maps.
 * This requires empty to be a valid value for the map.
 * @alpha
 */
export declare type MapFieldSchema = FieldSchema<typeof FieldKinds.optional | typeof FieldKinds.sequence>;
/**
 * `TreeSchemaSpecification` for {@link SchemaBuilder.leaf}.
 * @alpha
 */
export interface LeafSchemaSpecification {
    readonly leafValue: ValueSchema;
}
/**
 * Object for capturing information about a TreeStoredSchema for use at both compile time and runtime.
 * @alpha
 */
export declare type TreeSchemaSpecification = [
    FlattenKeys<(StructSchemaSpecification | MapSchemaSpecification | LeafSchemaSpecification) & Partial<StructSchemaSpecification & MapSchemaSpecification & LeafSchemaSpecification>>
][_InlineTrick];
/**
 * All policy for a specific field,
 * including functionality that does not have to be kept consistent across versions or deterministic.
 *
 * This can include policy for how to use this schema for "view" purposes, and well as how to expose editing APIs.
 * @sealed @alpha
 */
export declare class FieldSchema<Kind extends FieldKind = FieldKind, Types = AllowedTypes> {
    readonly kind: Kind;
    readonly allowedTypes: Types;
    /**
     * Schema for a field which must always be empty.
     */
    static readonly empty: FieldSchema<import("../default-field-kinds").Forbidden, never[]>;
    protected _typeCheck?: MakeNominal;
    /**
     * @param kind - The {@link https://en.wikipedia.org/wiki/Kind_(type_theory) | kind} of this field.
     * Determine the multiplicity, viewing and editing APIs as well as the merge resolution policy.
     * @param allowedTypes - What types of tree nodes are allowed in this field.
     */
    constructor(kind: Kind, allowedTypes: Types);
    get types(): TreeTypeSet;
}
/**
 * Convert {@link AllowedTypes} to {@link TreeTypeSet}.
 * @alpha
 */
export declare function allowedTypesToTypeSet(t: AllowedTypes): TreeTypeSet;
/**
 * Schema data that can be be used to view a document.
 * Strongly typed over its rootFieldSchema.
 *
 * @remarks
 * This type is mainly used as a type constraint to mean that the code working with it requires strongly typed schema.
 * The actual type used will include detailed schema information for all the types in the collection.
 * This pattern is used to implement SchemaAware APIs.
 *
 * @alpha
 */
export interface TypedSchemaCollection<T extends FieldSchema = FieldSchema> {
    readonly rootFieldSchema: T;
    readonly treeSchema: ReadonlyMap<TreeSchemaIdentifier, TreeSchema>;
    readonly policy: FullSchemaPolicy;
    readonly adapters: Adapters;
}
//# sourceMappingURL=typedTreeSchema.d.ts.map