helpers.js
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eslint no-console:0 */
import { map, pick, keys, isFunction, isUndefined, isObject, isArray, isTypedArray } from 'lodash'
import chalk from 'chalk';
// Pick off the attributes from only the current layer of the object.
export function skim(data) {
return map(data, (obj) => pick(obj, keys(obj)));
}
// 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;
}
export function debugLog(msg) {
console.log(msg);
}
export function error(msg) {
console.log(chalk.red(`Knex:Error ${msg}`))
}
// Used to signify deprecated functionality.
export function deprecate(method, alternate) {
warn(`${method} is deprecated, please use ${alternate}`);
}
// Used to warn about incorrect use, without error'ing
export function warn(msg) {
console.log(chalk.yellow(`Knex:warning - ${msg}`))
}
export function exit(msg) {
console.log(chalk.red(msg))
process.exit(1)
}
export function containsUndefined(mixed) {
let argContainsUndefined = false;
if (isTypedArray(mixed))
return false;
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]);
}
} else if(isObject(mixed)) {
for(const key in mixed) {
if(argContainsUndefined) break;
argContainsUndefined = this.containsUndefined(mixed[key]);
}
} else {
argContainsUndefined = isUndefined(mixed);
}
return argContainsUndefined;
}