2016-05-17 01:01:34 +10:00
|
|
|
/* eslint no-console:0 */
|
2015-05-09 13:58:18 -04:00
|
|
|
|
2018-02-14 17:00:50 +01:00
|
|
|
import {
|
|
|
|
isFunction,
|
|
|
|
isUndefined,
|
|
|
|
isPlainObject,
|
|
|
|
isArray,
|
|
|
|
isTypedArray
|
|
|
|
} from 'lodash'
|
2016-05-17 01:01:34 +10:00
|
|
|
|
|
|
|
// Check if the first argument is an array, otherwise uses all arguments as an
|
|
|
|
// array.
|
|
|
|
export function normalizeArr() {
|
|
|
|
const args = new Array(arguments.length);
|
|
|
|
for (let i = 0; i < args.length; i++) {
|
|
|
|
args[i] = arguments[i];
|
|
|
|
}
|
|
|
|
if (Array.isArray(args[0])) {
|
|
|
|
return args[0];
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
2015-05-09 13:58:18 -04:00
|
|
|
|
2016-05-28 19:45:00 +02:00
|
|
|
export function containsUndefined(mixed) {
|
|
|
|
let argContainsUndefined = false;
|
|
|
|
|
2016-07-31 08:22:18 -04:00
|
|
|
if (isTypedArray(mixed))
|
|
|
|
return false;
|
|
|
|
|
2016-05-28 19:45:00 +02:00
|
|
|
if(mixed && isFunction(mixed.toSQL)) {
|
|
|
|
//Any QueryBuilder or Raw will automatically be validated during compile.
|
|
|
|
return argContainsUndefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isArray(mixed)) {
|
|
|
|
for(let i = 0; i < mixed.length; i++) {
|
|
|
|
if(argContainsUndefined) break;
|
|
|
|
argContainsUndefined = this.containsUndefined(mixed[i]);
|
|
|
|
}
|
2018-02-14 17:00:50 +01:00
|
|
|
} else if(isPlainObject(mixed)) {
|
2016-05-28 19:45:00 +02:00
|
|
|
for(const key in mixed) {
|
2017-10-31 15:15:53 -07:00
|
|
|
if (mixed.hasOwnProperty(key)) {
|
|
|
|
if(argContainsUndefined) break;
|
|
|
|
argContainsUndefined = this.containsUndefined(mixed[key]);
|
|
|
|
}
|
2016-05-28 19:45:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
argContainsUndefined = isUndefined(mixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return argContainsUndefined;
|
2018-02-01 23:41:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function addQueryContext(Target) {
|
|
|
|
// Stores or returns (if called with no arguments) context passed to
|
|
|
|
// wrapIdentifier and postProcessResponse hooks
|
|
|
|
Target.prototype.queryContext = function(context) {
|
|
|
|
if (isUndefined(context)) {
|
|
|
|
return this._queryContext;
|
|
|
|
}
|
|
|
|
this._queryContext = context;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|