Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/node_modules
node_modules
coverage
*.log
npm-debug.log
Expand All @@ -23,10 +23,7 @@ dist
**/*.js
**/*.d.ts
core/**/dist
core/**/node_modules
plugin/**/dist
plugin/**/node_modules
standalone/**/node_modules/

plugin/oneapi/test/fixtures/modules/*/oneapi
plugin/dal/test/fixtures/modules/*/dal/
Expand Down
2 changes: 2 additions & 0 deletions .nycrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ exclude:
- plugin/*/test/**/*
- integration/*/test/**/*
- standalone/*/test/**/*
- benchmark/**/*
- test-util/*/dist
11 changes: 5 additions & 6 deletions benchmark/http/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "tegg_benchmark",
"egg": {
"typescript": true
},
"scripts": {
"dev": "egg-bin dev"
},
"dependencies": {
"@eggjs/tegg": "^1.1.1",
"@eggjs/tegg-config": "^1.1.1",
"@eggjs/tegg-controller-plugin": "^1.1.1",
"@eggjs/tegg-plugin": "^1.1.1",
"@eggjs/tegg": "^1.6.4",
"@eggjs/tegg-config": "^1.3.3",
"@eggjs/tegg-controller-plugin": "^1.7.5",
"@eggjs/tegg-plugin": "^1.5.5",
"@eggjs/tsconfig": "^1.1.0",
"egg": "^2.36.0"
"egg": "^3.9.1"
},
"devDependencies": {
"egg-bin": "^5.1.1"
Expand Down
4 changes: 2 additions & 2 deletions core/aop-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"scripts": {
"clean": "tsc -b --clean",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc-pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc-pub",
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc:pub",
"autod": "autod"
},
"author": "killagu <[email protected]>",
Expand Down
108 changes: 55 additions & 53 deletions core/aop-runtime/test/aop-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,65 @@ describe('test/aop-runtime.test.ts', () => {
});

it('should work', async () => {
const ctx = new EggTestContext();
const hello = await CoreTestHelper.getObject(Hello, ctx);
const callTrace = await CoreTestHelper.getObject(CallTrace);
const msg = await hello.hello('aop');
const traceMsg = callTrace.msgs;
assert(msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))');
assert.deepStrictEqual(traceMsg, [
{
className: 'CrosscutAdvice',
methodName: 'beforeCall',
id: 233,
name: 'aop',
},
{
className: 'PointcutAdvice',
methodName: 'beforeCall',
id: 233,
name: 'aop',
},
{
className: 'CrosscutAdvice',
methodName: 'afterReturn',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
},
{
className: 'PointcutAdvice',
methodName: 'afterReturn',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
},
{
className: 'CrosscutAdvice',
methodName: 'afterFinally',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
},
{
className: 'PointcutAdvice',
methodName: 'afterFinally',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
},
]);
await EggTestContext.mockContext(async () => {
const hello = await CoreTestHelper.getObject(Hello);
const callTrace = await CoreTestHelper.getObject(CallTrace);
const msg = await hello.hello('aop');
const traceMsg = callTrace.msgs;
assert(msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))');
assert.deepStrictEqual(traceMsg, [
{
className: 'CrosscutAdvice',
methodName: 'beforeCall',
id: 233,
name: 'aop',
},
{
className: 'PointcutAdvice',
methodName: 'beforeCall',
id: 233,
name: 'aop',
},
{
className: 'CrosscutAdvice',
methodName: 'afterReturn',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
},
{
className: 'PointcutAdvice',
methodName: 'afterReturn',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
},
{
className: 'CrosscutAdvice',
methodName: 'afterFinally',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
},
{
className: 'PointcutAdvice',
methodName: 'afterFinally',
id: 233,
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
},
]);
});
});

it('mock should work', async () => {
const ctx = new EggTestContext();
const hello = await CoreTestHelper.getObject(Hello, ctx);
let helloMocked = false;
mm(Hello.prototype, 'hello', async () => {
helloMocked = true;
await EggTestContext.mockContext(async () => {
const hello = await CoreTestHelper.getObject(Hello);
let helloMocked = false;
mm(Hello.prototype, 'hello', async () => {
helloMocked = true;
});
await hello.hello('aop');
assert(helloMocked === true);
});
await hello.hello('aop');
assert(helloMocked === true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion core/background-task/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@eggjs/tegg-lifecycle": "^1.0.0"
},
"devDependencies": {
"egg": "^2.26.0",
"egg": "^3.9.1",
"mz-modules": "^2.1.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion core/controller-decorator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"egg": "^2.26.0"
"egg": "^3.9.1"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccessLevel, ContextProto, EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator';
import { AccessLevel, EggProtoImplClass, PrototypeUtil, SingletonProto } from '@eggjs/core-decorator';
import { StackUtil } from '@eggjs/tegg-common-util';
import HTTPInfoUtil from '../../util/HTTPInfoUtil';
import ControllerInfoUtil from '../../util/ControllerInfoUtil';
Expand All @@ -14,13 +14,13 @@ export function HTTPController(param?: HTTPControllerParams) {
return function(constructor: EggProtoImplClass) {
ControllerInfoUtil.setControllerType(constructor, ControllerType.HTTP);
if (param?.controllerName) {
ControllerInfoUtil.setControllerName(constructor, param?.controllerName);
ControllerInfoUtil.setControllerName(constructor, param.controllerName);
}
if (param?.path) {
HTTPInfoUtil.setHTTPPath(param.path, constructor);
}
// TODO elegant?
const func = ContextProto({
const func = SingletonProto({
accessLevel: AccessLevel.PUBLIC,
name: param?.protoName,
});
Expand Down
14 changes: 7 additions & 7 deletions core/core-decorator/src/model/QualifierInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ export type QualifierValue = string | number;
* hello(name: string): Promise<void>;
* }
*
* @ContextProto({ name: 'helloService' })
* @HelloService(HelloServiceType.Email)
* \@ContextProto({ name: 'helloService' })
* \@HelloService(HelloServiceType.Email)
* class EmailHelloService implement HelloService {
* ...
* }
*
* @ContextProto({ name: 'helloService' })
* @HelloService(HelloServiceType.Message)
* \@ContextProto({ name: 'helloService' })
* \@HelloService(HelloServiceType.Message)
* class MessageHelloService implement HelloService {
* ...
* }
*
* @ContextProto()
* \@ContextProto()
* class HelloFacade {
* @Inject
* @HelloService(HelloServiceType.Message)
* \@Inject
* \@HelloService(HelloServiceType.Message)
* helloService: HelloService;
* }
*/
Expand Down
4 changes: 2 additions & 2 deletions core/dynamic-inject-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"scripts": {
"clean": "tsc -b --clean",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc-pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc-pub",
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc:pub",
"autod": "autod"
},
"author": "killagu <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class EggObjectFactoryPrototype implements EggPrototype {
this.accessLevel = property.accessLevel;
this.loadUnitId = loadUnit.id;
this.name = property.name || NameUtil.getClassName(this.clazz);
this.injectObjects = [];
}

constructEggObject(): EggObjectFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class EggContextObjectFactory extends AbstractEggObjectFactory {
if (!protoObj) {
throw new Error(`can not get proto for clazz ${implClazz.name}`);
}
const eggObject = await this.eggContainerFactory.getOrCreateEggObject(protoObj, protoObj.name, this.eggContext);
const eggObject = await this.eggContainerFactory.getOrCreateEggObject(protoObj, protoObj.name);
return eggObject.obj as T;
}
}
42 changes: 22 additions & 20 deletions core/dynamic-inject-runtime/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@ describe('test/dynamic-inject-runtime.test.ts', () => {
});

it('should work', async () => {
const ctx = new EggTestContext();
const helloService = await CoreTestHelper.getObject(HelloService, ctx);
const msgs = await helloService.hello();
assert.deepStrictEqual(msgs, [
'hello, foo(context:0)',
'hello, bar(context:0)',
'hello, foo(singleton:0)',
'hello, bar(singleton:0)',
]);
await EggTestContext.mockContext(async () => {
const helloService = await CoreTestHelper.getObject(HelloService);
const msgs = await helloService.hello();
assert.deepStrictEqual(msgs, [
'hello, foo(context:0)',
'hello, bar(context:0)',
'hello, foo(singleton:0)',
'hello, bar(singleton:0)',
]);
});

const ctx2 = new EggTestContext();
const helloService2 = await CoreTestHelper.getObject(HelloService, ctx2);
const msgs2 = await helloService2.hello();
assert.deepStrictEqual(msgs2, [
'hello, foo(context:0)',
'hello, bar(context:0)',
// singleton use the same object
// counter should has cache
'hello, foo(singleton:1)',
'hello, bar(singleton:1)',
]);
await EggTestContext.mockContext(async () => {
const helloService = await CoreTestHelper.getObject(HelloService);
const msgs = await helloService.hello();
assert.deepStrictEqual(msgs, [
'hello, foo(context:0)',
'hello, bar(context:0)',
// singleton use the same object
// counter should has cache
'hello, foo(singleton:1)',
'hello, bar(singleton:1)',
]);
});
});
});
4 changes: 2 additions & 2 deletions core/dynamic-inject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"scripts": {
"clean": "tsc -b --clean",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc-pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc-pub",
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc:pub",
"autod": "autod"
},
"author": "killagu <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions core/eventbus-decorator/src/Event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccessLevel, ContextProto, PrototypeUtil } from '@eggjs/core-decorator';
import { AccessLevel, PrototypeUtil, SingletonProto } from '@eggjs/core-decorator';
import { StackUtil } from '@eggjs/tegg-common-util';
import { EventHandler } from '../index';
import { EventInfoUtil } from './EventInfoUtil';
Expand All @@ -9,7 +9,7 @@ import { Events } from '@eggjs/tegg';
export function Event<E extends keyof Events>(eventName: E) {
return function(clazz: new () => EventHandler<E>) {
EventInfoUtil.setEventName(eventName, clazz);
const func = ContextProto({
const func = SingletonProto({
accessLevel: AccessLevel.PUBLIC,
});
func(clazz);
Expand Down
2 changes: 1 addition & 1 deletion core/eventbus-decorator/test/Event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('test/Event.test.ts', () => {
tsc,
[ '--noEmit', '--experimentalDecorators', ...files ],
)
.debug()
// .debug()
.expect('stdout', /Type 'number' is not assignable to type 'string'/)
.notExpect('code', 0)
.end();
Expand Down
2 changes: 1 addition & 1 deletion core/eventbus-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@eggjs/tegg-metadata": "^1.4.3",
"@eggjs/tegg-runtime": "^1.4.3",
"coffee": "^5.4.0",
"egg": "^2.29.3",
"egg": "^3.9.1",
"mm": "^3.2.0",
"mz-modules": "^2.1.0"
},
Expand Down
6 changes: 3 additions & 3 deletions core/eventbus-runtime/src/EventHandlerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventHandler, EventName, Events } from '@eggjs/eventbus-decorator';
import { EggContext } from '@eggjs/tegg-runtime';
import { EggContainerFactory } from '@eggjs/tegg-runtime';
import { EggPrototype } from '@eggjs/tegg-metadata';
import { MapUtil } from '@eggjs/tegg-common-util';
import { AccessLevel, SingletonProto } from '@eggjs/core-decorator';
Expand All @@ -19,10 +19,10 @@ export class EventHandlerFactory {
return this.handlerProtoMap.has(event);
}

async getHandlers(event: EventName, ctx: EggContext): Promise<Array<EventHandler<keyof Events>>> {
async getHandlers(event: EventName): Promise<Array<EventHandler<keyof Events>>> {
const handlerProtos = this.handlerProtoMap.get(event) || [];
const eggObjs = await Promise.all(handlerProtos.map(proto => {
return ctx.getOrCreateEggObject(proto.name, proto, ctx);
return EggContainerFactory.getOrCreateEggObject(proto, proto.name);
}));
return eggObjs.map(t => t.obj as EventHandler<keyof Events>);
}
Expand Down
Loading