Skip to content

Commit 772aeb9

Browse files
authored
feat(break): use async local storage (#69)
feat: use async local storage
1 parent efc615e commit 772aeb9

File tree

75 files changed

+797
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+797
-434
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/node_modules
1+
node_modules
22
coverage
33
*.log
44
npm-debug.log
@@ -23,10 +23,7 @@ dist
2323
**/*.js
2424
**/*.d.ts
2525
core/**/dist
26-
core/**/node_modules
2726
plugin/**/dist
28-
plugin/**/node_modules
29-
standalone/**/node_modules/
3027

3128
plugin/oneapi/test/fixtures/modules/*/oneapi
3229
plugin/dal/test/fixtures/modules/*/dal/

.nycrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ exclude:
2424
- plugin/*/test/**/*
2525
- integration/*/test/**/*
2626
- standalone/*/test/**/*
27+
- benchmark/**/*
28+
- test-util/*/dist

benchmark/http/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"name": "tegg_benchmark",
33
"egg": {
4-
"typescript": true
54
},
65
"scripts": {
76
"dev": "egg-bin dev"
87
},
98
"dependencies": {
10-
"@eggjs/tegg": "^1.1.1",
11-
"@eggjs/tegg-config": "^1.1.1",
12-
"@eggjs/tegg-controller-plugin": "^1.1.1",
13-
"@eggjs/tegg-plugin": "^1.1.1",
9+
"@eggjs/tegg": "^1.6.4",
10+
"@eggjs/tegg-config": "^1.3.3",
11+
"@eggjs/tegg-controller-plugin": "^1.7.5",
12+
"@eggjs/tegg-plugin": "^1.5.5",
1413
"@eggjs/tsconfig": "^1.1.0",
15-
"egg": "^2.36.0"
14+
"egg": "^3.9.1"
1615
},
1716
"devDependencies": {
1817
"egg-bin": "^5.1.1"

core/aop-runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"scripts": {
2222
"clean": "tsc -b --clean",
2323
"tsc": "npm run clean && tsc -p ./tsconfig.json",
24-
"tsc-pub": "npm run clean && tsc -p ./tsconfig.pub.json",
25-
"prepublishOnly": "npm run tsc-pub",
24+
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
25+
"prepublishOnly": "npm run tsc:pub",
2626
"autod": "autod"
2727
},
2828
"author": "killagu <[email protected]>",

core/aop-runtime/test/aop-runtime.test.ts

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -45,63 +45,65 @@ describe('test/aop-runtime.test.ts', () => {
4545
});
4646

4747
it('should work', async () => {
48-
const ctx = new EggTestContext();
49-
const hello = await CoreTestHelper.getObject(Hello, ctx);
50-
const callTrace = await CoreTestHelper.getObject(CallTrace);
51-
const msg = await hello.hello('aop');
52-
const traceMsg = callTrace.msgs;
53-
assert(msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))');
54-
assert.deepStrictEqual(traceMsg, [
55-
{
56-
className: 'CrosscutAdvice',
57-
methodName: 'beforeCall',
58-
id: 233,
59-
name: 'aop',
60-
},
61-
{
62-
className: 'PointcutAdvice',
63-
methodName: 'beforeCall',
64-
id: 233,
65-
name: 'aop',
66-
},
67-
{
68-
className: 'CrosscutAdvice',
69-
methodName: 'afterReturn',
70-
id: 233,
71-
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
72-
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
73-
},
74-
{
75-
className: 'PointcutAdvice',
76-
methodName: 'afterReturn',
77-
id: 233,
78-
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
79-
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
80-
},
81-
{
82-
className: 'CrosscutAdvice',
83-
methodName: 'afterFinally',
84-
id: 233,
85-
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
86-
},
87-
{
88-
className: 'PointcutAdvice',
89-
methodName: 'afterFinally',
90-
id: 233,
91-
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
92-
},
93-
]);
48+
await EggTestContext.mockContext(async () => {
49+
const hello = await CoreTestHelper.getObject(Hello);
50+
const callTrace = await CoreTestHelper.getObject(CallTrace);
51+
const msg = await hello.hello('aop');
52+
const traceMsg = callTrace.msgs;
53+
assert(msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))');
54+
assert.deepStrictEqual(traceMsg, [
55+
{
56+
className: 'CrosscutAdvice',
57+
methodName: 'beforeCall',
58+
id: 233,
59+
name: 'aop',
60+
},
61+
{
62+
className: 'PointcutAdvice',
63+
methodName: 'beforeCall',
64+
id: 233,
65+
name: 'aop',
66+
},
67+
{
68+
className: 'CrosscutAdvice',
69+
methodName: 'afterReturn',
70+
id: 233,
71+
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
72+
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
73+
},
74+
{
75+
className: 'PointcutAdvice',
76+
methodName: 'afterReturn',
77+
id: 233,
78+
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
79+
result: 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))',
80+
},
81+
{
82+
className: 'CrosscutAdvice',
83+
methodName: 'afterFinally',
84+
id: 233,
85+
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
86+
},
87+
{
88+
className: 'PointcutAdvice',
89+
methodName: 'afterFinally',
90+
id: 233,
91+
name: 'withPointAroundParam(withCrosscutAroundParam(aop))',
92+
},
93+
]);
94+
});
9495
});
9596

9697
it('mock should work', async () => {
97-
const ctx = new EggTestContext();
98-
const hello = await CoreTestHelper.getObject(Hello, ctx);
99-
let helloMocked = false;
100-
mm(Hello.prototype, 'hello', async () => {
101-
helloMocked = true;
98+
await EggTestContext.mockContext(async () => {
99+
const hello = await CoreTestHelper.getObject(Hello);
100+
let helloMocked = false;
101+
mm(Hello.prototype, 'hello', async () => {
102+
helloMocked = true;
103+
});
104+
await hello.hello('aop');
105+
assert(helloMocked === true);
102106
});
103-
await hello.hello('aop');
104-
assert(helloMocked === true);
105107
});
106108
});
107109

core/background-task/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@eggjs/tegg-lifecycle": "^1.0.0"
4242
},
4343
"devDependencies": {
44-
"egg": "^2.26.0",
44+
"egg": "^3.9.1",
4545
"mz-modules": "^2.1.0"
4646
},
4747
"publishConfig": {

core/controller-decorator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"reflect-metadata": "^0.1.13"
4545
},
4646
"devDependencies": {
47-
"egg": "^2.26.0"
47+
"egg": "^3.9.1"
4848
},
4949
"publishConfig": {
5050
"access": "public"

core/controller-decorator/src/decorator/http/HTTPController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccessLevel, ContextProto, EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator';
1+
import { AccessLevel, EggProtoImplClass, PrototypeUtil, SingletonProto } from '@eggjs/core-decorator';
22
import { StackUtil } from '@eggjs/tegg-common-util';
33
import HTTPInfoUtil from '../../util/HTTPInfoUtil';
44
import ControllerInfoUtil from '../../util/ControllerInfoUtil';
@@ -14,13 +14,13 @@ export function HTTPController(param?: HTTPControllerParams) {
1414
return function(constructor: EggProtoImplClass) {
1515
ControllerInfoUtil.setControllerType(constructor, ControllerType.HTTP);
1616
if (param?.controllerName) {
17-
ControllerInfoUtil.setControllerName(constructor, param?.controllerName);
17+
ControllerInfoUtil.setControllerName(constructor, param.controllerName);
1818
}
1919
if (param?.path) {
2020
HTTPInfoUtil.setHTTPPath(param.path, constructor);
2121
}
2222
// TODO elegant?
23-
const func = ContextProto({
23+
const func = SingletonProto({
2424
accessLevel: AccessLevel.PUBLIC,
2525
name: param?.protoName,
2626
});

core/core-decorator/src/model/QualifierInfo.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ export type QualifierValue = string | number;
1414
* hello(name: string): Promise<void>;
1515
* }
1616
*
17-
* @ContextProto({ name: 'helloService' })
18-
* @HelloService(HelloServiceType.Email)
17+
* \@ContextProto({ name: 'helloService' })
18+
* \@HelloService(HelloServiceType.Email)
1919
* class EmailHelloService implement HelloService {
2020
* ...
2121
* }
2222
*
23-
* @ContextProto({ name: 'helloService' })
24-
* @HelloService(HelloServiceType.Message)
23+
* \@ContextProto({ name: 'helloService' })
24+
* \@HelloService(HelloServiceType.Message)
2525
* class MessageHelloService implement HelloService {
2626
* ...
2727
* }
2828
*
29-
* @ContextProto()
29+
* \@ContextProto()
3030
* class HelloFacade {
31-
* @Inject
32-
* @HelloService(HelloServiceType.Message)
31+
* \@Inject
32+
* \@HelloService(HelloServiceType.Message)
3333
* helloService: HelloService;
3434
* }
3535
*/

core/dynamic-inject-runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"scripts": {
2121
"clean": "tsc -b --clean",
2222
"tsc": "npm run clean && tsc -p ./tsconfig.json",
23-
"tsc-pub": "npm run clean && tsc -p ./tsconfig.pub.json",
24-
"prepublishOnly": "npm run tsc-pub",
23+
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
24+
"prepublishOnly": "npm run tsc:pub",
2525
"autod": "autod"
2626
},
2727
"author": "killagu <[email protected]>",

0 commit comments

Comments
 (0)