swagger-typed-express-docs
Version:
Simple express runtime parser and documentation swagger generator with 100% support of Typescript static types
106 lines (105 loc) • 4.38 kB
JavaScript
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.notNullable = exports.deepMerge = exports.validateUntilFirstSuccess = exports.syncAllSettled = exports.mergePaths = exports.trimSlash = exports.removeLastSlash = exports.removeFirstSlash = exports.isObject = exports.mapEntries = void 0;
var mapEntries = function (fn, obj) {
return Object.fromEntries(Object.entries(obj).map(fn));
};
exports.mapEntries = mapEntries;
var isObject = function (a) { return typeof a === 'object' && a !== null && !Array.isArray(a); };
exports.isObject = isObject;
var removeFirstSlash = function (path) { return (path.startsWith('/') ? path.substr(1) : path); };
exports.removeFirstSlash = removeFirstSlash;
var removeLastSlash = function (path) { return (path.endsWith('/') ? path.slice(0, -1) : path); };
exports.removeLastSlash = removeLastSlash;
var trimSlash = function (path) { return (0, exports.removeFirstSlash)((0, exports.removeLastSlash)(path)); };
exports.trimSlash = trimSlash;
var mergePaths = function (path1, path2) {
return "/".concat([(0, exports.trimSlash)(path1), (0, exports.trimSlash)(path2)].filter(Boolean).join('/'));
};
exports.mergePaths = mergePaths;
var syncAllSettled = function (syncFns) {
var e_1, _a;
var results = [];
try {
for (var syncFns_1 = __values(syncFns), syncFns_1_1 = syncFns_1.next(); !syncFns_1_1.done; syncFns_1_1 = syncFns_1.next()) {
var syncFn = syncFns_1_1.value;
try {
var value = syncFn();
results.push({ status: 'fulfilled', value: value });
}
catch (err) {
results.push({ status: 'rejected', reason: err });
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (syncFns_1_1 && !syncFns_1_1.done && (_a = syncFns_1.return)) _a.call(syncFns_1);
}
finally { if (e_1) throw e_1.error; }
}
return results;
};
exports.syncAllSettled = syncAllSettled;
var validateUntilFirstSuccess = function (validationFns) {
var e_2, _a;
var errors = { status: 'rejected', reasons: [] };
var index = -1;
try {
for (var validationFns_1 = __values(validationFns), validationFns_1_1 = validationFns_1.next(); !validationFns_1_1.done; validationFns_1_1 = validationFns_1.next()) {
var validate = validationFns_1_1.value;
try {
index++;
var result = validate();
return { status: 'fulfilled', data: result, index: index };
}
catch (err) {
errors.reasons.push(err);
continue;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (validationFns_1_1 && !validationFns_1_1.done && (_a = validationFns_1.return)) _a.call(validationFns_1);
}
finally { if (e_2) throw e_2.error; }
}
return errors;
};
exports.validateUntilFirstSuccess = validateUntilFirstSuccess;
var merge = function (a, b) {
return (0, exports.isObject)(a) && (0, exports.isObject)(b) ? (0, exports.deepMerge)(a, b) : (0, exports.isObject)(a) && !(0, exports.isObject)(b) ? a : b;
};
var coalesceByKey = function (source) {
return function (acc, key) {
return (acc[key] && source[key]
? (acc[key] = merge(acc[key], source[key]))
: (acc[key] = source[key])) && acc;
};
};
var deepMerge = function (target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
return sources.reduce(function (acc, source) { return Object.keys(source).reduce(coalesceByKey(source), acc); }, target);
};
exports.deepMerge = deepMerge;
var notNullable = function (x) {
return x !== undefined && x !== null && x !== false;
};
exports.notNullable = notNullable;
;