import cmp from"./lib/cmp.js";import{DataError}from"./lib/errors.js";import valueToKey from"./lib/valueToKey.js";class FDBKeyRange{static only(value){if(0===arguments.length)throw new TypeError;return value=valueToKey(value),new FDBKeyRange(value,value,!1,!1)}static lowerBound(lower,open=!1){if(0===arguments.length)throw new TypeError;return lower=valueToKey(lower),new FDBKeyRange(lower,void 0,open,!0)}static upperBound(upper,open=!1){if(0===arguments.length)throw new TypeError;return upper=valueToKey(upper),new FDBKeyRange(void 0,upper,!0,open)}static bound(lower,upper,lowerOpen=!1,upperOpen=!1){if(arguments.length<2)throw new TypeError;const cmpResult=cmp(lower,upper);if(1===cmpResult||0===cmpResult&&(lowerOpen||upperOpen))throw new DataError;return lower=valueToKey(lower),upper=valueToKey(upper),new FDBKeyRange(lower,upper,lowerOpen,upperOpen)}constructor(lower,upper,lowerOpen,upperOpen){this.lower=lower,this.upper=upper,this.lowerOpen=lowerOpen,this.upperOpen=upperOpen}includes(key){if(0===arguments.length)throw new TypeError;if(key=valueToKey(key),void 0!==this.lower){const cmpResult=cmp(this.lower,key);if(1===cmpResult||0===cmpResult&&this.lowerOpen)return!1}if(void 0!==this.upper){const cmpResult=cmp(this.upper,key);if(-1===cmpResult||0===cmpResult&&this.upperOpen)return!1}return!0}toString(){return"[object IDBKeyRange]"}}export default FDBKeyRange;