UNPKG

@kitmi/jacaranda

Version:

JavaScript application framework

68 lines (67 loc) 2.48 kB
/** * Enable business feature * @module Feature_Business */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path")); const _Feature = /*#__PURE__*/ _interop_require_default(require("../Feature")); const _utils = require("@kitmi/utils"); const _types = require("@kitmi/types"); const _Business = /*#__PURE__*/ _interop_require_default(require("../helpers/Business")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _default = { stage: _Feature.default.SERVICE, load_: async function(app, options, name) { const { path: _path, db } = app.featureConfig(options, { schema: { path: { type: 'text', default: 'business' }, db: { type: 'text', optional: true } } }, name); let businessClasses = (0, _utils.get)(app.registry, _path); if (!businessClasses) { businessClasses = require(_nodepath.default.join(app.sourcePath, _path)); } app.bus = (businessName, fromApp, ctx)=>{ if (ctx == null && fromApp?.request) { ctx = fromApp; fromApp = null; } if (fromApp) { let _app = app.getOtherApp(fromApp); return _app.bus(businessName, null, ctx); } const businessClass = businessClasses[businessName]; if (!businessClass) { throw new _types.InvalidArgument(`Business class "${businessName}" not found.`); } const _dbName = db || app.settings.defaultDb; if (businessClass.length > 0 || businessClass.prototype instanceof _Business.default) { return new businessClass(app, _dbName, ctx); } // compatibility with those who don't extend from Business class Object.setPrototypeOf(businessClass.prototype, _Business.default.prototype); Object.setPrototypeOf(businessClass, _Business.default); return new businessClass(app, _dbName, ctx); }; } }; //# sourceMappingURL=businessLogic.js.map