Socket
Socket
Sign inDemoInstall

egg-aop

Package Overview
Dependencies
3
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.10 to 0.3.11

67

lib/getInstance.js

@@ -13,8 +13,2 @@ "use strict";

exports.contextTypeSymbol = Symbol('contextType');
function registerInstance(ioc, value, clsType, app, ctx) {
ioc.register(value, clsType);
ioc.inject(value, (_globalType, typeCls) => {
return getInstance(typeCls, app, ctx);
});
}
function getInstance(clsType, app, ctx) {

@@ -29,3 +23,3 @@ let ioc = undefined;

if (!targetClsType) {
throw new Error(`ClassType [${utils_1.getGlobalType(clsType)}] NOT found!`);
throw new Error(`ClassType [${utils_1.getGlobalType(clsType)}] NOT found in typeLoader!`);
}

@@ -43,42 +37,41 @@ const from = targetClsType[exports.contextTypeSymbol];

let value = ioc.get(clsType);
if (!value) {
if (!targetClsType) {
throw new Error(`classType NOT registered! [${utils_1.getGlobalType(clsType)}]`);
if (value) {
return value;
}
if (from === 'Application') {
if (!app) {
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Application/Context class instance.`);
}
if (from === 'Application') {
if (!app) {
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Application/Context class instance.`);
}
if (useCtxProxyForAppComponent) {
value = app.iocContext.get(clsType);
}
if (useCtxProxyForAppComponent) {
value = app.iocContext.get(clsType);
if (!value) {
value = ciHooks.reduce((pre, cur) => cur(pre, app), new targetClsType(app));
value = new targetClsType(app);
appctx_1.setApp(value, app);
if (useCtxProxyForAppComponent) {
registerInstance(app.iocContext, value, clsType, app, ctx);
}
app.iocContext.register(value, clsType);
}
if (useCtxProxyForAppComponent) {
value = new Proxy(value, {
get(target, property) {
if (property === appctx_1.ctxSymbol) {
return ctx;
}
return target[property];
value = new Proxy(value, {
get(target, property) {
if (property === appctx_1.ctxSymbol) {
return ctx;
}
});
}
return typeof target[property] === 'function' ? target[property].bind(this) : target[property];
}
});
value = ciHooks.reduce((pre, cur) => cur(pre, app), value);
}
else if (from === 'Context') {
if (!ctx) {
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Context class instance.`);
}
value = ciHooks.reduce((pre, cur) => cur(pre, app, ctx), new targetClsType(ctx));
appctx_1.setCtx(value, ctx);
else {
value = ciHooks.reduce((pre, cur) => cur(pre, app), new targetClsType(app));
appctx_1.setApp(value, app);
}
registerInstance(ioc, value, clsType, app, ctx);
}
else if (from === 'Context') {
if (!ctx) {
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Context class instance.`);
}
value = ciHooks.reduce((pre, cur) => cur(pre, app, ctx), new targetClsType(ctx));
appctx_1.setCtx(value, ctx);
}
ioc.register(value, clsType);
return value;
}
exports.getInstance = getInstance;
{
"name": "egg-aop",
"version": "0.3.10",
"version": "0.3.11",
"description": "aop for egg.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc