helene
Version:
Real-time Web Apps for Node.js
28 lines • 1.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.intercept = intercept;
const isNil_1 = __importDefault(require("lodash/isNil"));
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
/**
* Get the params and the result and combine in a single output.
*
* @param func
*/
function intercept(func) {
return async function (params) {
let result = func.call(this, params);
if (func.constructor.name === 'AsyncFunction' || result instanceof Promise)
result = await result;
/**
* If the result is not an object, return it as is. We need to support primitives.
*/
if (!(0, isNil_1.default)(result) && !(0, isPlainObject_1.default)(result)) {
return result;
}
return Object.assign({}, params, result ?? {});
};
}
//# sourceMappingURL=intercept.js.map