/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { ValueSchema } from "../../core";
import { forbidden } from "../defaultFieldKinds";
/**
 * @returns true iff `schema` trees should default to being viewed as just their value when possible.
 *
 * @remarks
 * This may return true for some types which EditableTree does not unwrap to just their value,
 * since EditableTree avoids ever unwrapping primitives that are objects
 * so users checking for primitives by type won't be broken.
 * Checking for this object case is done elsewhere.
 * @alpha
 */
export function isPrimitive(schema) {
    // TODO: use a separate `TreeViewSchema` type, with metadata that determines if the type is primitive.
    // Since the above is not done yet, use use a heuristic:
    return (schema.value !== ValueSchema.Nothing &&
        schema.localFields.size === 0 &&
        schema.globalFields.size === 0 &&
        schema.extraGlobalFields === false &&
        schema.extraLocalFields.kind.identifier === forbidden.identifier);
}
export function adaptWithProxy(target, proxyHandler) {
    // Proxy constructor assumes handler emulates target's interface.
    // Ours does not, so this cast is required.
    return new Proxy(target, proxyHandler);
}
export function getOwnArrayKeys(length) {
    return Object.getOwnPropertyNames(Array.from(Array(length)));
}
export function keyIsValidIndex(key, length) {
    const index = Number(key);
    if (typeof key === "string" && String(index) !== key)
        return false;
    return Number.isInteger(index) && 0 <= index && index < length;
}
//# sourceMappingURL=utilities.js.map