"use strict";
/*!
  Copyright 2018 Ron Buckton (rbuckton@chronicles.org)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../types");
const types_2 = require("./types");
/** @internal */
function IsDefined(value) {
    return value !== undefined && value !== null;
}
exports.IsDefined = IsDefined;
/** @internal */
function IsObject(value) {
    return typeof value === "object" && value !== null
        || typeof value === "function";
}
exports.IsObject = IsObject;
function IsFunctionOrUndefined(value) {
    return typeof value === "function" || value === undefined;
}
/** @internal */
function IsPromiseLike(value) {
    return IsObject(value)
        && "then" in value && typeof value.then === "function";
}
exports.IsPromiseLike = IsPromiseLike;
/** @internal */
function IsHierarchyProvider(value) {
    return IsObject(value)
        && "parent" in value && typeof value.parent === "function"
        && "children" in value && typeof value.children === "function"
        && IsFunctionOrUndefined(value.owns);
}
exports.IsHierarchyProvider = IsHierarchyProvider;
/** @internal */
function IsGrouping(value) {
    return IsObject(value)
        && "key" in value
        && types_1.Grouping.key in value
        && Symbol.iterator in value;
}
exports.IsGrouping = IsGrouping;
/** @internal */
function IsArrayLike(value) {
    return IsObject(value) && typeof value !== "function"
        && "length" in value;
}
exports.IsArrayLike = IsArrayLike;
/** @internal */
function IsIterable(value) {
    return IsObject(value)
        && Symbol.iterator in value;
}
exports.IsIterable = IsIterable;
/** @internal */
function IsOrderedIterable(value) {
    return IsObject(value)
        && Symbol.iterator in value
        && types_1.OrderedIterable.thenBy in value;
}
exports.IsOrderedIterable = IsOrderedIterable;
/** @internal */
function IsHierarchyIterable(value) {
    return IsObject(value)
        && Symbol.iterator in value
        && types_1.Hierarchical.hierarchy in value;
}
exports.IsHierarchyIterable = IsHierarchyIterable;
/** @internal */
function IsOrderedHierarchyIterable(value) {
    return IsObject(value)
        && Symbol.iterator in value
        && types_1.OrderedIterable.thenBy in value
        && types_1.Hierarchical.hierarchy in value;
}
exports.IsOrderedHierarchyIterable = IsOrderedHierarchyIterable;
/** @internal */
function IsAsyncIterable(value) {
    return IsObject(value)
        && Symbol.asyncIterator in value;
}
exports.IsAsyncIterable = IsAsyncIterable;
/** @internal */
function IsAsyncOrderedIterable(value) {
    return IsObject(value)
        && Symbol.asyncIterator in value
        && types_1.AsyncOrderedIterable.thenByAsync in value;
}
exports.IsAsyncOrderedIterable = IsAsyncOrderedIterable;
/** @internal */
function IsAsyncHierarchyIterable(value) {
    return IsObject(value)
        && Symbol.asyncIterator in value
        && types_1.Hierarchical.hierarchy in value;
}
exports.IsAsyncHierarchyIterable = IsAsyncHierarchyIterable;
/** @internal */
function IsAsyncOrderedHierarchyIterable(value) {
    return IsObject(value)
        && Symbol.asyncIterator in value
        && types_1.AsyncOrderedIterable.thenByAsync in value
        && types_1.Hierarchical.hierarchy in value;
}
exports.IsAsyncOrderedHierarchyIterable = IsAsyncOrderedHierarchyIterable;
/** @internal */
function IsPossiblyAsyncIterable(value) {
    return IsAsyncIterable(value)
        || IsIterable(value);
}
exports.IsPossiblyAsyncIterable = IsPossiblyAsyncIterable;
/** @internal */
function IsPossiblyAsyncOrderedIterable(value) {
    return IsAsyncOrderedIterable(value)
        || IsOrderedIterable(value);
}
exports.IsPossiblyAsyncOrderedIterable = IsPossiblyAsyncOrderedIterable;
/** @internal */
function IsPossiblyAsyncHierarchyIterable(value) {
    return IsAsyncHierarchyIterable(value)
        || IsHierarchyIterable(value);
}
exports.IsPossiblyAsyncHierarchyIterable = IsPossiblyAsyncHierarchyIterable;
/** @internal */
function IsPossiblyAsyncOrderedHierarchyIterable(value) {
    return IsAsyncOrderedHierarchyIterable(value)
        || IsOrderedHierarchyIterable(value);
}
exports.IsPossiblyAsyncOrderedHierarchyIterable = IsPossiblyAsyncOrderedHierarchyIterable;
/** @internal */
function IsQueryable(value) {
    return IsIterable(value)
        || IsArrayLike(value);
}
exports.IsQueryable = IsQueryable;
/** @internal */
function IsQuerySource(value) {
    return IsObject(value) && types_2.QuerySource.source in value;
}
exports.IsQuerySource = IsQuerySource;
/** @internal */
function IsAsyncQuerySource(value) {
    return IsObject(value) && types_2.AsyncQuerySource.source in value;
}
exports.IsAsyncQuerySource = IsAsyncQuerySource;
/** @internal */
function IsComparable(x) {
    return types_1.Comparable.isComparable(x);
}
exports.IsComparable = IsComparable;
/** @internal */
function IsEqualer(x) {
    return typeof x === "object"
        && x !== null
        && "equals" in x && typeof x.equals === "function"
        && "hash" in x && typeof x.hash === "function";
}
exports.IsEqualer = IsEqualer;
/** @internal */
function IsComparer(x) {
    return typeof x === "object"
        && x !== null
        && "compare" in x && typeof x.compare === "function";
}
exports.IsComparer = IsComparer;
//# sourceMappingURL=guards.js.map