/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { brand } from "../../util";
import { ValueSchema, } from "./schema";
/**
 * APIs to help build schema.
 *
 * See typedSchema.ts for a wrapper for these APIs that captures the types as TypeScript types
 * in addition to runtime data.
 */
/**
 * Empty readonly set.
 */
export const emptySet = new Set();
/**
 * Empty readonly map.
 */
export const emptyMap = new Map();
/**
 * Helper for building {@link FieldStoredSchema}.
 * @alpha
 */
export function fieldSchema(kind, types) {
    return {
        kind,
        types: types === undefined ? undefined : new Set(types),
    };
}
const defaultExtraGlobalFields = false;
/**
 * Helper for building {@link TreeStoredSchema}.
 */
export function treeSchema(data) {
    var _a, _b, _c, _d;
    const localFields = new Map();
    const local = (_a = data.localFields) !== null && _a !== void 0 ? _a : {};
    // eslint-disable-next-line no-restricted-syntax
    for (const key in local) {
        if (Object.prototype.hasOwnProperty.call(local, key)) {
            localFields.set(brand(key), local[key]);
        }
    }
    return {
        localFields,
        globalFields: new Set((_b = data.globalFields) !== null && _b !== void 0 ? _b : []),
        extraLocalFields: data.extraLocalFields,
        extraGlobalFields: (_c = data.extraGlobalFields) !== null && _c !== void 0 ? _c : defaultExtraGlobalFields,
        value: (_d = data.value) !== null && _d !== void 0 ? _d : ValueSchema.Nothing,
    };
}
//# sourceMappingURL=builders.js.map