/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
/*
 * This file contains a format for serializing the compatibility impacting subset of simple schema.

 * This format can be used for both view and stored simple schema.
 * This only includes all parts of the schema that impact compatibility according to SchemaCompatibilityTester.
 * It may not include some details which impact maintenance of application enforced invariants (like persisted metadata or logic in view schema).
 */
import { Type } from "@sinclair/typebox";
const noAdditionalProps = { additionalProperties: false };
/**
 * The format version for the schema.
 */
export const SimpleSchemaFormatVersion = {
    v1: 1,
};
/**
 * The allowed types and their attributes in the simple schema format.
 * @see {@link SimpleAllowedTypes}.
 */
export const SimpleAllowedTypeAttributesFormat = Type.Object({
    isStaged: Type.Optional(Type.Boolean()),
}, noAdditionalProps);
/**
 * A set of allowed types in the simple schema format.
 * The keys are the type identifiers, and the values are their attributes.
 */
export const SimpleAllowedTypesFormat = Type.Record(Type.String(), SimpleAllowedTypeAttributesFormat);
/**
 * Persisted format for a field schema in the simple schema format.
 * @see {@link SimpleFieldSchema}.
 */
export const SimpleFieldSchemaFormat = Type.Object({
    kind: Type.Integer(),
    simpleAllowedTypes: SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for an object field schema in the simple schema format.
 * @see {@link SimpleObjectFieldSchema}.
 */
export const SimpleObjectFieldSchemaFormat = Type.Object({
    kind: Type.Integer(),
    simpleAllowedTypes: SimpleAllowedTypesFormat,
    storedKey: Type.String(),
}, noAdditionalProps);
/**
 * Persisted format for an array node schema in the simple schema format.
 * @see {@link SimpleArrayNodeSchema}.
 */
export const SimpleArrayNodeSchemaFormat = Type.Object({
    kind: Type.Integer(),
    simpleAllowedTypes: SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a map node schema in the simple schema format.
 * @see {@link SimpleMapNodeSchema}.
 */
export const SimpleMapNodeSchemaFormat = Type.Object({
    kind: Type.Integer(),
    simpleAllowedTypes: SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a record node schema in the simple schema format.
 * @see {@link SimpleRecordNodeSchema}.
 */
export const SimpleRecordNodeSchemaFormat = Type.Object({
    kind: Type.Integer(),
    simpleAllowedTypes: SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a leaf node schema in the simple schema format.
 * @see {@link SimpleLeafNodeSchema}.
 */
export const SimpleLeafNodeSchemaFormat = Type.Object({
    kind: Type.Integer(),
    leafKind: Type.Integer(),
}, noAdditionalProps);
/**
 * Persisted format for the field schemas of an object node in the simple schema format.
 */
export const SimpleObjectFieldSchemasFormat = Type.Record(Type.String(), SimpleObjectFieldSchemaFormat);
/**
 * Persisted format for an object node schema in the simple schema format.
 * @see {@link SimpleObjectNodeSchema}.
 */
export const SimpleObjectNodeSchemaFormat = Type.Object({
    kind: Type.Integer(),
    fields: SimpleObjectFieldSchemasFormat,
    allowUnknownOptionalFields: Type.Optional(Type.Boolean()),
}, noAdditionalProps);
/**
 * Discriminated union of all possible node schemas.
 *
 * See {@link DiscriminatedUnionDispatcher} for more information on this pattern.
 */
export const SimpleNodeSchemaUnionFormat = Type.Object({
    array: Type.Optional(SimpleArrayNodeSchemaFormat),
    map: Type.Optional(SimpleMapNodeSchemaFormat),
    record: Type.Optional(SimpleRecordNodeSchemaFormat),
    leaf: Type.Optional(SimpleLeafNodeSchemaFormat),
    object: Type.Optional(SimpleObjectNodeSchemaFormat),
});
/**
 * Helper type for the schema definitions map in the persisted format.
 */
export const SimpleSchemaDefinitionsFormat = Type.Record(Type.String(), SimpleNodeSchemaUnionFormat);
/**
 * Persisted format for the compatibility impacting subset of simple schema.
 * @see {@link SimpleTreeSchema}.
 */
export const SimpleTreeSchemaFormat = Type.Object({
    version: Type.Literal(SimpleSchemaFormatVersion.v1),
    root: SimpleFieldSchemaFormat,
    definitions: SimpleSchemaDefinitionsFormat,
}, noAdditionalProps);
//# sourceMappingURL=simpleSchemaFormatV1.js.map