@methodus/server
Version:
Server components for @methodus workflow
50 lines • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fp_1 = require("../fp");
const path = require("path");
const log_1 = require("../log");
class Proxy {
static ProxyClass(packageName, className, localClassPath) {
return (target) => {
const methodus = fp_1.fp.maybeMethodus(target)[className];
const classTransport = "Local";
if (!methodus) {
throw (new Error(`error finding configuration ${packageName} ${className},${localClassPath}`));
}
if (!classTransport || classTransport === "Local") {
const startPathForLoad = packageName;
const localLoadPath = path.join(startPathForLoad, localClassPath).replace(/\\/g, '/');
log_1.logger.info(`trying to load ${localLoadPath} locally`);
try {
try {
const localClass = require(localLoadPath);
log_1.logger.info(`succesfully loaded ${localLoadPath} locally`);
return localClass[className];
}
catch (error) {
try {
log_1.logger.info(`will try other options ${localClassPath} locally`);
const localClass = require(path.join(process.cwd(), startPathForLoad, localClassPath));
log_1.logger.info(`succesfully loaded ${localClass} locally`);
return localClass[className];
}
catch (error) {
log_1.logger.info(`will try last option ${localClassPath} locally`);
const localClass = require(path.join(process.cwd(), 'node_modules', startPathForLoad, localClassPath));
log_1.logger.info(`succesfully loaded ${localClass} locally`);
return localClass[className];
}
}
}
catch (ex) {
log_1.logger.error(ex);
throw (ex);
}
}
log_1.logger.info('returned the contract it self for' + className);
return target;
};
}
}
exports.Proxy = Proxy;
//# sourceMappingURL=proxy.js.map