swc/bundler/tests/.cache/untrusted/40621ada605966bd2ee8eb4a73ff081b1b44d52c.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

99 lines
2.4 KiB
TypeScript

// Loaded from https://raw.githubusercontent.com/denjucks/dex/master/lib/helpers.js
/* eslint no-console:0 */
import _ from './deps/lodash@4.17.15/index.js';
const isFunction = _.isFunction;
const isPlainObject = _.isPlainObject;
const isTypedArray = _.isTypedArray;
import { CLIENT_ALIASES } from './constants.js';
// 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 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 (Array.isArray(mixed)) {
for (let i = 0; i < mixed.length; i++) {
if (argContainsUndefined) break;
argContainsUndefined = containsUndefined(mixed[i]);
}
} else if (isPlainObject(mixed)) {
Object.keys(mixed).forEach((key) => {
if (!argContainsUndefined) {
argContainsUndefined = containsUndefined(mixed[key]);
}
});
} else {
argContainsUndefined = mixed === undefined;
}
return argContainsUndefined;
}
export function getUndefinedIndices(mixed) {
const indices = [];
if (Array.isArray(mixed)) {
mixed.forEach((item, index) => {
if (containsUndefined(item)) {
indices.push(index);
}
});
} else if (isPlainObject(mixed)) {
Object.keys(mixed).forEach((key) => {
if (containsUndefined(mixed[key])) {
indices.push(key);
}
});
} else {
indices.push(0);
}
return indices;
}
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 (context === undefined) {
return this._queryContext;
}
this._queryContext = context;
return this;
};
}
export function resolveClientNameWithAliases(clientName) {
return CLIENT_ALIASES[clientName] || clientName;
}
export default {
addQueryContext,
containsUndefined,
normalizeArr,
resolveClientNameWithAliases,
getUndefinedIndices,
};