"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleSchema = exports.nullSchema = exports.booleanSchema = exports.numberSchema = exports.stringSchema = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../domains/index.js");
const index_js_2 = require("../feature-libraries/index.js");
const schemaCaching_js_1 = require("./schemaCaching.js");
const schemaTypes_js_1 = require("./schemaTypes.js");
/**
 * Instances of this class are schema for leaf nodes.
 * @remarks
 * Unlike other schema, leaf schema are class instances instead of classes themselves.
 * This is because the instance type (the tree node type) for leaves are not objects,
 * so those instances can't be instances of a schema based class.
 * @privateRemarks
 * This class refers to the underlying flex tree schema in its constructor, so this class can't be included in the package API.
 */
class LeafNodeSchema {
    create(data) {
        if ((0, index_js_2.isFlexTreeNode)(data)) {
            const value = data.value;
            (0, internal_1.assert)((0, index_js_2.valueSchemaAllows)(this.info, value), 0x916 /* invalid value */);
            return value;
        }
        return data;
    }
    constructor(schema) {
        this.kind = schemaTypes_js_1.NodeKind.Leaf;
        this.implicitlyConstructable = true;
        (0, schemaCaching_js_1.setFlexSchemaFromClassSchema)(this, schema);
        this.identifier = schema.name;
        this.info = schema.info;
    }
}
/**
 * Wrapper around LeafNodeSchema's constructor that provides the return type that is desired in the package public API.
 */
function makeLeaf(schema) {
    return new LeafNodeSchema(schema);
}
// Leaf schema shared between all SchemaFactory instances.
exports.stringSchema = makeLeaf(index_js_1.leaf.string);
exports.numberSchema = makeLeaf(index_js_1.leaf.number);
exports.booleanSchema = makeLeaf(index_js_1.leaf.boolean);
exports.nullSchema = makeLeaf(index_js_1.leaf.null);
exports.handleSchema = makeLeaf(index_js_1.leaf.handle);
//# sourceMappingURL=leafNodeSchema.js.map