"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 = exports.LeafNodeSchema = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../core/index.js");
const index_js_2 = require("../feature-libraries/index.js");
const index_js_3 = require("./core/index.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;
    }
    createFromInsertable(data) {
        return data;
    }
    constructor(name, t) {
        this.kind = index_js_3.NodeKind.Leaf;
        this.implicitlyConstructable = true;
        this.childTypes = new Set();
        this.identifier = name;
        this.info = t;
    }
}
exports.LeafNodeSchema = LeafNodeSchema;
/**
 * Wrapper around LeafNodeSchema's constructor that provides the return type that is desired in the package public API.
 */
function makeLeaf(name, t) {
    // Names in this domain follow https://en.wikipedia.org/wiki/Reverse_domain_name_notation
    return new LeafNodeSchema(`com.fluidframework.leaf.${name}`, t);
}
// Leaf schema shared between all SchemaFactory instances.
exports.stringSchema = makeLeaf("string", index_js_1.ValueSchema.String);
exports.numberSchema = makeLeaf("number", index_js_1.ValueSchema.Number);
exports.booleanSchema = makeLeaf("boolean", index_js_1.ValueSchema.Boolean);
exports.nullSchema = makeLeaf("null", index_js_1.ValueSchema.Null);
exports.handleSchema = makeLeaf("handle", index_js_1.ValueSchema.FluidHandle);
//# sourceMappingURL=leafNodeSchema.js.map