"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleTreeSchemaFormat = exports.SimpleSchemaDefinitionsFormat = exports.SimpleNodeSchemaUnionFormat = exports.SimpleObjectNodeSchemaFormat = exports.SimpleObjectFieldSchemasFormat = exports.SimpleLeafNodeSchemaFormat = exports.SimpleRecordNodeSchemaFormat = exports.SimpleMapNodeSchemaFormat = exports.SimpleArrayNodeSchemaFormat = exports.SimpleObjectFieldSchemaFormat = exports.SimpleFieldSchemaFormat = exports.SimpleAllowedTypesFormat = exports.SimpleAllowedTypeAttributesFormat = exports.SimpleSchemaFormatVersion = void 0;
/*
 * 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).
 */
const typebox_1 = require("@sinclair/typebox");
const noAdditionalProps = { additionalProperties: false };
/**
 * The format version for the schema.
 */
exports.SimpleSchemaFormatVersion = {
    v1: 1,
};
/**
 * The allowed types and their attributes in the simple schema format.
 * @see {@link SimpleAllowedTypes}.
 */
exports.SimpleAllowedTypeAttributesFormat = typebox_1.Type.Object({
    isStaged: typebox_1.Type.Optional(typebox_1.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.
 */
exports.SimpleAllowedTypesFormat = typebox_1.Type.Record(typebox_1.Type.String(), exports.SimpleAllowedTypeAttributesFormat);
/**
 * Persisted format for a field schema in the simple schema format.
 * @see {@link SimpleFieldSchema}.
 */
exports.SimpleFieldSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    simpleAllowedTypes: exports.SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for an object field schema in the simple schema format.
 * @see {@link SimpleObjectFieldSchema}.
 */
exports.SimpleObjectFieldSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    simpleAllowedTypes: exports.SimpleAllowedTypesFormat,
    storedKey: typebox_1.Type.String(),
}, noAdditionalProps);
/**
 * Persisted format for an array node schema in the simple schema format.
 * @see {@link SimpleArrayNodeSchema}.
 */
exports.SimpleArrayNodeSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    simpleAllowedTypes: exports.SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a map node schema in the simple schema format.
 * @see {@link SimpleMapNodeSchema}.
 */
exports.SimpleMapNodeSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    simpleAllowedTypes: exports.SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a record node schema in the simple schema format.
 * @see {@link SimpleRecordNodeSchema}.
 */
exports.SimpleRecordNodeSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    simpleAllowedTypes: exports.SimpleAllowedTypesFormat,
}, noAdditionalProps);
/**
 * Persisted format for a leaf node schema in the simple schema format.
 * @see {@link SimpleLeafNodeSchema}.
 */
exports.SimpleLeafNodeSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    leafKind: typebox_1.Type.Integer(),
}, noAdditionalProps);
/**
 * Persisted format for the field schemas of an object node in the simple schema format.
 */
exports.SimpleObjectFieldSchemasFormat = typebox_1.Type.Record(typebox_1.Type.String(), exports.SimpleObjectFieldSchemaFormat);
/**
 * Persisted format for an object node schema in the simple schema format.
 * @see {@link SimpleObjectNodeSchema}.
 */
exports.SimpleObjectNodeSchemaFormat = typebox_1.Type.Object({
    kind: typebox_1.Type.Integer(),
    fields: exports.SimpleObjectFieldSchemasFormat,
    allowUnknownOptionalFields: typebox_1.Type.Optional(typebox_1.Type.Boolean()),
}, noAdditionalProps);
/**
 * Discriminated union of all possible node schemas.
 *
 * See {@link DiscriminatedUnionDispatcher} for more information on this pattern.
 */
exports.SimpleNodeSchemaUnionFormat = typebox_1.Type.Object({
    array: typebox_1.Type.Optional(exports.SimpleArrayNodeSchemaFormat),
    map: typebox_1.Type.Optional(exports.SimpleMapNodeSchemaFormat),
    record: typebox_1.Type.Optional(exports.SimpleRecordNodeSchemaFormat),
    leaf: typebox_1.Type.Optional(exports.SimpleLeafNodeSchemaFormat),
    object: typebox_1.Type.Optional(exports.SimpleObjectNodeSchemaFormat),
});
/**
 * Helper type for the schema definitions map in the persisted format.
 */
exports.SimpleSchemaDefinitionsFormat = typebox_1.Type.Record(typebox_1.Type.String(), exports.SimpleNodeSchemaUnionFormat);
/**
 * Persisted format for the compatibility impacting subset of simple schema.
 * @see {@link SimpleTreeSchema}.
 */
exports.SimpleTreeSchemaFormat = typebox_1.Type.Object({
    version: typebox_1.Type.Literal(exports.SimpleSchemaFormatVersion.v1),
    root: exports.SimpleFieldSchemaFormat,
    definitions: exports.SimpleSchemaDefinitionsFormat,
}, noAdditionalProps);
//# sourceMappingURL=simpleSchemaFormatV1.js.map