Socket
Socket
Sign inDemoInstall

egg-aop

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-aop - npm Package Compare versions

Comparing version 0.3.13 to 0.4.0

17

lib/decorators.d.ts

@@ -0,1 +1,2 @@

export { inject, lazyInject } from 'power-di/helper';
import { InstanceSource } from './getInstance';

@@ -27,17 +28,1 @@ /**

export declare function application(keyType?: any): (target: any) => void;
/**
* lazy inject
* This can new Class and inject app/ctx (need from ctx)
* @export
* @param {*} [classType] class or string
* @returns void
*/
export declare function lazyInject(classType?: any): any;
/**
* inject
* This can new Class and inject app/ctx (need from ctx)
* @export
* @param {*} [classType] class or string
* @returns void
*/
export declare function inject(classType?: any): any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const decorators_1 = require("power-di/lib/helper/decorators");
const helper_1 = require("power-di/helper");
const appctx_1 = require("./appctx");
const getInstance_1 = require("./getInstance");
var helper_1 = require("power-di/helper");
exports.inject = helper_1.inject;
exports.lazyInject = helper_1.lazyInject;
const typeLoader_1 = require("./typeLoader");

@@ -45,42 +44,1 @@ /**

exports.application = application;
/**
* lazy inject
* This can new Class and inject app/ctx (need from ctx)
* @export
* @param {*} [classType] class or string
* @returns void
*/
function lazyInject(classType) {
return (target, key) => {
helper_1.lazyInject(classType)(target, key);
classType = decorators_1.getClsTypeByDecorator(classType, target, key);
return {
configurable: true,
get: function () {
const ctx = appctx_1.getCtx(this);
let app = appctx_1.getApp(this);
if (!app && ctx) {
app = ctx.app;
}
const value = getInstance_1.getInstance(classType, app, ctx);
Object.defineProperty(this, key, {
configurable: true,
value: value
});
return value;
}
};
};
}
exports.lazyInject = lazyInject;
/**
* inject
* This can new Class and inject app/ctx (need from ctx)
* @export
* @param {*} [classType] class or string
* @returns void
*/
function inject(classType) {
return lazyInject(classType);
}
exports.inject = inject;

2

lib/getInstance.d.ts

@@ -0,1 +1,2 @@

import { IocContext } from 'power-di';
export declare type InstanceSource = 'Context' | 'Application';

@@ -5,2 +6,3 @@ export declare type CreateInstanceHookFunction = (instance: any, app: any, ctx?: any) => any;

export declare const contextTypeSymbol: unique symbol;
export declare function injectInstance(ioc: IocContext, inst: any, app: any, ctx: any): void;
export declare function getInstance<T = any>(clsType: any, app: any, ctx: any): T;

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

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

@@ -49,2 +55,3 @@ let ioc = undefined;

app.iocContext.register(value, clsType);
injectInstance(app.iocContext, value, app, ctx);
}

@@ -77,4 +84,5 @@ value = new Proxy(value, {

ioc.register(value, clsType);
injectInstance(ioc, value, app, ctx);
return value;
}
exports.getInstance = getInstance;
{
"name": "egg-aop",
"version": "0.3.13",
"version": "0.4.0",
"description": "aop for egg.",

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc