Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | 1x 1x 118x 130x 118x 118x 130x 130x 130x 1x 1x 1x 1x 1x 1x 118x 118x 117x 118x 118x 118x 118x 118x 1x 118x 118x 118x 118x 118x 118x 118x 118x 118x 118x 1x 1x 124x 124x 1x | import AWS from "aws-sdk";
const abort = {};
function update(obj1, obj2) {
each(obj2, function iterator(key, item) {
obj1[key] = item;
});
return obj1;
}
function each(object, iterFunction) {
for (var key in object) {
Eif (Object.prototype.hasOwnProperty.call(object, key)) {
var ret = iterFunction.call(this, key, object[key]);
Iif (ret === abort) break;
}
}
}
export function inherit(klass?, features?) {
var newObject = null;
if (features === undefined) {
features = klass;
klass = Object;
newObject = {};
} else {
var ctor = function ConstructorWrapper() { };
ctor.prototype = klass.prototype;
newObject = new ctor();
}
// constructor not supplied, create pass-through ctor
if (features.constructor === Object) {
features.constructor = function () {
if (klass !== Object) {
return klass.apply(this, arguments);
}
};
}
features.constructor.prototype = newObject;
update(features.constructor.prototype, features);
features.constructor.__super__ = klass;
return features.constructor;
}
export function promisifyMethod(methodName?, PromiseDependency?) {
return function promise() {
var self = this;
var args = Array.prototype.slice.call(arguments);
return new PromiseDependency(function (resolve, reject) {
args.push(function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
self[methodName].apply(self, args);
});
};
}
export function addPromises(constructors?, PromiseDependency?) {
var deletePromises = false;
if (PromiseDependency === undefined && AWS && AWS.config) {
PromiseDependency = AWS.config.getPromisesDependency();
}
if (PromiseDependency === undefined && typeof Promise !== 'undefined') {
PromiseDependency = Promise;
}
if (typeof PromiseDependency !== 'function') deletePromises = true;
if (!Array.isArray(constructors)) constructors = [constructors];
for (var ind = 0; ind < constructors.length; ind++) {
var constructor = constructors[ind];
if (deletePromises) {
if (constructor.deletePromisesFromClass) {
constructor.deletePromisesFromClass();
}
} else if (constructor.addPromisesToClass) {
constructor.addPromisesToClass(PromiseDependency);
}
}
}
export const fn = {
noop: function () { },
callback: function (err) { if (err) throw err; },
// /**
// * Turn a synchronous function into as "async" function by making it call
// * a callback. The underlying function is called with all but the last argument,
// * which is treated as the callback. The callback is passed passed a first argument
// * of null on success to mimick standard node callbacks.
// */
// makeAsync: function makeAsync(fn, expectedArgs) {
// if (expectedArgs && expectedArgs <= fn.length) {
// return fn;
// }
// return function () {
// var args = Array.prototype.slice.call(arguments, 0);
// var callback = args.pop();
// var result = fn.apply(null, args);
// callback(result);
// };
// }
}
export function copy(object) {
if (object === null || object === undefined) return object;
var dupe = {};
// jshint forin:false
for (var key in object) {
dupe[key] = object[key];
}
return dupe;
}
export function error(err, options) {
var originalError = null;
if (typeof err.message === 'string' && err.message !== '') {
Iif (typeof options === 'string' || (options && options.message)) {
originalError = copy(err);
originalError.message = err.message;
}
}
err.message = err.message || null;
Iif (typeof options === 'string') {
err.message = options;
} else Eif (typeof options === 'object' && options !== null) {
update(err, options);
if (options.message)
err.message = options.message;
Eif (options.code || options.name)
err.code = options.code || options.name;
Iif (options.stack)
err.stack = options.stack;
}
Eif (typeof Object.defineProperty === 'function') {
Object.defineProperty(err, 'name', { writable: true, enumerable: false });
Object.defineProperty(err, 'message', { enumerable: true });
}
err.name = String(options && options.name || err.name || err.code || 'Error');
err.time = new Date();
Iif (originalError) err.originalError = originalError;
return err;
}
export function arrayEach(array, iterFunction) {
for (var idx in array) {
if (Object.prototype.hasOwnProperty.call(array, idx)) {
var ret = iterFunction.call(this, array[idx], parseInt(idx, 10));
if (ret === abort) break;
}
}
}
export const date = {
/**
* @return [Date] the current JavaScript date object. Since all
* AWS services rely on this date object, you can override
* this function to provide a special time value to AWS service
* requests.
*/
getDate: function getDate() {
Iif (AWS.config.systemClockOffset) { // use offset when non-zero
return new Date(new Date().getTime() + AWS.config.systemClockOffset);
} else {
return new Date();
}
}
};
export default {
inherit,
promisifyMethod,
addPromises,
error,
arrayEach,
fn,
date
};
|