@celljs/core 4.2.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -20
- package/cell.schema.json +84 -0
- package/cell.yml +13 -12
- package/esm/browser/application/frontend-application.d.ts +2 -2
- package/esm/browser/application/frontend-application.js +6 -25
- package/esm/browser/application/frontend-application.js.map +1 -1
- package/esm/common/annotation/component.js +1 -2
- package/esm/common/annotation/component.js.map +1 -1
- package/esm/common/annotation/service.js +2 -1
- package/esm/common/annotation/service.js.map +1 -1
- package/esm/common/application/application-entry.js +4 -0
- package/esm/common/application/application-entry.js.map +1 -1
- package/esm/common/application/application-protocol.d.ts +9 -3
- package/esm/common/application/application-protocol.js +19 -7
- package/esm/common/application/application-protocol.js.map +1 -1
- package/esm/common/application/application.js +1 -1
- package/esm/common/application/application.js.map +1 -1
- package/esm/common/config/config-util.d.ts +3 -0
- package/esm/common/config/config-util.js +6 -1
- package/esm/common/config/config-util.js.map +1 -1
- package/esm/common/config/dynamic-config.d.ts +3 -0
- package/esm/common/config/dynamic-config.js +3 -1
- package/esm/common/config/dynamic-config.js.map +1 -1
- package/esm/common/config/env-config-util.d.ts +32 -26
- package/esm/common/config/env-config-util.js +84 -40
- package/esm/common/config/env-config-util.js.map +1 -1
- package/esm/common/constants.d.ts +1 -1
- package/esm/common/constants.js +1 -1
- package/esm/common/constants.js.map +1 -1
- package/esm/common/container/auto-bind.js +2 -2
- package/esm/common/container/auto-bind.js.map +1 -1
- package/esm/common/container/container.js +3 -3
- package/esm/common/container/container.js.map +1 -1
- package/esm/common/el/core-context-initializer.js +3 -1
- package/esm/common/el/core-context-initializer.js.map +1 -1
- package/esm/common/el/expression-engine.d.ts +3 -3
- package/esm/common/el/expression-engine.js +18 -9
- package/esm/common/el/expression-engine.js.map +1 -1
- package/esm/common/el/expression-handler.js +2 -1
- package/esm/common/el/expression-handler.js.map +1 -1
- package/esm/common/el/expression-util.d.ts +17 -4
- package/esm/common/el/expression-util.js +28 -9
- package/esm/common/el/expression-util.js.map +1 -1
- package/esm/common/index.d.ts +1 -0
- package/esm/common/index.js +1 -0
- package/esm/common/index.js.map +1 -1
- package/esm/common/logger/abstract-logger.d.ts +2 -1
- package/esm/common/logger/abstract-logger.js +28 -17
- package/esm/common/logger/abstract-logger.js.map +1 -1
- package/esm/common/logger/logger-protocol.d.ts +2 -2
- package/esm/common/logger/logger-protocol.js +1 -1
- package/esm/common/logger/logger-protocol.js.map +1 -1
- package/esm/common/logger/logger.js +11 -4
- package/esm/common/logger/logger.js.map +1 -1
- package/esm/common/security-check/index.d.ts +2 -0
- package/esm/common/security-check/index.js +3 -0
- package/esm/common/security-check/index.js.map +1 -0
- package/esm/common/security-check/security-check-protocol.d.ts +40 -0
- package/esm/common/security-check/security-check-protocol.js +24 -0
- package/esm/common/security-check/security-check-protocol.js.map +1 -0
- package/esm/common/security-check/security-checker.d.ts +14 -0
- package/esm/common/security-check/security-checker.js +61 -0
- package/esm/common/security-check/security-checker.js.map +1 -0
- package/esm/common/utils/emitter.d.ts +2 -0
- package/esm/common/utils/emitter.js +4 -0
- package/esm/common/utils/emitter.js.map +1 -1
- package/esm/common/utils/error-util.d.ts +8 -0
- package/esm/common/utils/error-util.js +24 -0
- package/esm/common/utils/error-util.js.map +1 -1
- package/esm/common/utils/event.d.ts +6 -1
- package/esm/common/utils/event.js +20 -6
- package/esm/common/utils/event.js.map +1 -1
- package/esm/common/utils/uuid.d.ts +1 -1
- package/esm/common/utils/uuid.js +1 -1
- package/esm/common/utils/uuid.js.map +1 -1
- package/esm/node/application/backend-application.js +1 -1
- package/esm/node/application/backend-application.js.map +1 -1
- package/esm/node/context/context.js +3 -3
- package/esm/node/context/context.js.map +1 -1
- package/lib/browser/application/frontend-application.d.ts +2 -2
- package/lib/browser/application/frontend-application.d.ts.map +1 -1
- package/lib/browser/application/frontend-application.js +6 -25
- package/lib/browser/application/frontend-application.js.map +1 -1
- package/lib/common/annotation/component.js +1 -2
- package/lib/common/annotation/component.js.map +1 -1
- package/lib/common/annotation/service.d.ts.map +1 -1
- package/lib/common/annotation/service.js +2 -1
- package/lib/common/annotation/service.js.map +1 -1
- package/lib/common/annotation/service.spec.d.ts +2 -0
- package/lib/common/annotation/service.spec.d.ts.map +1 -0
- package/lib/common/annotation/service.spec.js +43 -0
- package/lib/common/annotation/service.spec.js.map +1 -0
- package/lib/common/aop/aop.spec.js +4 -4
- package/lib/common/aop/aop.spec.js.map +1 -1
- package/lib/common/application/application-entry.js +4 -0
- package/lib/common/application/application-entry.js.map +1 -1
- package/lib/common/application/application-protocol.d.ts +9 -3
- package/lib/common/application/application-protocol.d.ts.map +1 -1
- package/lib/common/application/application-protocol.js +19 -7
- package/lib/common/application/application-protocol.js.map +1 -1
- package/lib/common/application/application.js +1 -1
- package/lib/common/application/application.js.map +1 -1
- package/lib/common/application/lifecycle.spec.js +54 -7
- package/lib/common/application/lifecycle.spec.js.map +1 -1
- package/lib/common/config/config-util.d.ts +3 -0
- package/lib/common/config/config-util.d.ts.map +1 -1
- package/lib/common/config/config-util.js +5 -0
- package/lib/common/config/config-util.js.map +1 -1
- package/lib/common/config/dynamic-config.d.ts +3 -0
- package/lib/common/config/dynamic-config.d.ts.map +1 -1
- package/lib/common/config/dynamic-config.js +4 -2
- package/lib/common/config/dynamic-config.js.map +1 -1
- package/lib/common/config/env-config-util.d.ts +32 -26
- package/lib/common/config/env-config-util.d.ts.map +1 -1
- package/lib/common/config/env-config-util.js +84 -40
- package/lib/common/config/env-config-util.js.map +1 -1
- package/lib/common/config/env-config-util.spec.js +148 -132
- package/lib/common/config/env-config-util.spec.js.map +1 -1
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/constants.d.ts.map +1 -1
- package/lib/common/constants.js +1 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/container/auto-bind.js +2 -2
- package/lib/common/container/auto-bind.js.map +1 -1
- package/lib/common/container/container.js +3 -3
- package/lib/common/container/container.js.map +1 -1
- package/lib/common/el/core-context-initializer.d.ts.map +1 -1
- package/lib/common/el/core-context-initializer.js +3 -1
- package/lib/common/el/core-context-initializer.js.map +1 -1
- package/lib/common/el/expression-engine.d.ts +3 -3
- package/lib/common/el/expression-engine.js +18 -9
- package/lib/common/el/expression-engine.js.map +1 -1
- package/lib/common/el/expression-engine.spec.js +15 -7
- package/lib/common/el/expression-engine.spec.js.map +1 -1
- package/lib/common/el/expression-handler.d.ts.map +1 -1
- package/lib/common/el/expression-handler.js +2 -1
- package/lib/common/el/expression-handler.js.map +1 -1
- package/lib/common/el/expression-util.d.ts +17 -4
- package/lib/common/el/expression-util.d.ts.map +1 -1
- package/lib/common/el/expression-util.js +28 -10
- package/lib/common/el/expression-util.js.map +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/logger/abstract-logger.d.ts +2 -1
- package/lib/common/logger/abstract-logger.d.ts.map +1 -1
- package/lib/common/logger/abstract-logger.js +28 -17
- package/lib/common/logger/abstract-logger.js.map +1 -1
- package/lib/common/logger/logger-protocol.d.ts +2 -2
- package/lib/common/logger/logger-protocol.d.ts.map +1 -1
- package/lib/common/logger/logger-protocol.js +1 -1
- package/lib/common/logger/logger-protocol.js.map +1 -1
- package/lib/common/logger/logger.d.ts.map +1 -1
- package/lib/common/logger/logger.js +11 -4
- package/lib/common/logger/logger.js.map +1 -1
- package/lib/common/logger/logger.spec.js +35 -0
- package/lib/common/logger/logger.spec.js.map +1 -1
- package/lib/common/security-check/index.d.ts +3 -0
- package/lib/common/security-check/index.d.ts.map +1 -0
- package/lib/common/security-check/index.js +19 -0
- package/lib/common/security-check/index.js.map +1 -0
- package/lib/common/security-check/security-check-protocol.d.ts +41 -0
- package/lib/common/security-check/security-check-protocol.d.ts.map +1 -0
- package/lib/common/security-check/security-check-protocol.js +28 -0
- package/lib/common/security-check/security-check-protocol.js.map +1 -0
- package/lib/common/security-check/security-checker.d.ts +15 -0
- package/lib/common/security-check/security-checker.d.ts.map +1 -0
- package/lib/common/security-check/security-checker.js +64 -0
- package/lib/common/security-check/security-checker.js.map +1 -0
- package/lib/common/security-check/security-checker.spec.d.ts +2 -0
- package/lib/common/security-check/security-checker.spec.d.ts.map +1 -0
- package/lib/common/security-check/security-checker.spec.js +68 -0
- package/lib/common/security-check/security-checker.spec.js.map +1 -0
- package/lib/common/utils/emitter.d.ts +2 -0
- package/lib/common/utils/emitter.d.ts.map +1 -1
- package/lib/common/utils/emitter.js +4 -0
- package/lib/common/utils/emitter.js.map +1 -1
- package/lib/common/utils/error-util.d.ts +8 -0
- package/lib/common/utils/error-util.d.ts.map +1 -1
- package/lib/common/utils/error-util.js +24 -0
- package/lib/common/utils/error-util.js.map +1 -1
- package/lib/common/utils/event.d.ts +6 -1
- package/lib/common/utils/event.d.ts.map +1 -1
- package/lib/common/utils/event.js +20 -6
- package/lib/common/utils/event.js.map +1 -1
- package/lib/common/utils/utils-behavior.spec.js +21 -2
- package/lib/common/utils/utils-behavior.spec.js.map +1 -1
- package/lib/common/utils/uuid.d.ts +1 -1
- package/lib/common/utils/uuid.d.ts.map +1 -1
- package/lib/common/utils/uuid.js +2 -2
- package/lib/common/utils/uuid.js.map +1 -1
- package/lib/node/application/backend-application.js +1 -1
- package/lib/node/application/backend-application.js.map +1 -1
- package/lib/node/context/context.d.ts.map +1 -1
- package/lib/node/context/context.js +3 -3
- package/lib/node/context/context.js.map +1 -1
- package/lib/node/context/context.spec.js +13 -0
- package/lib/node/context/context.spec.js.map +1 -1
- package/package.json +6 -2
- package/src/browser/application/frontend-application.ts +7 -28
- package/src/common/annotation/component.ts +1 -1
- package/src/common/annotation/service.spec.ts +29 -0
- package/src/common/annotation/service.ts +2 -1
- package/src/common/aop/aop.spec.ts +4 -4
- package/src/common/application/application-entry.ts +4 -0
- package/src/common/application/application-protocol.ts +21 -11
- package/src/common/application/application.ts +1 -1
- package/src/common/application/lifecycle.spec.ts +52 -8
- package/src/common/config/config-util.ts +7 -1
- package/src/common/config/dynamic-config.ts +6 -1
- package/src/common/config/env-config-util.spec.ts +152 -149
- package/src/common/config/env-config-util.ts +95 -51
- package/src/common/constants.ts +1 -1
- package/src/common/container/auto-bind.ts +1 -1
- package/src/common/container/container.ts +3 -3
- package/src/common/el/core-context-initializer.ts +4 -2
- package/src/common/el/expression-engine.spec.ts +17 -8
- package/src/common/el/expression-engine.ts +17 -9
- package/src/common/el/expression-handler.ts +2 -1
- package/src/common/el/expression-util.ts +37 -8
- package/src/common/index.ts +1 -0
- package/src/common/logger/abstract-logger.ts +30 -17
- package/src/common/logger/logger-protocol.ts +1 -1
- package/src/common/logger/logger.spec.ts +37 -0
- package/src/common/logger/logger.ts +12 -4
- package/src/common/security-check/index.ts +2 -0
- package/src/common/security-check/security-check-protocol.ts +59 -0
- package/src/common/security-check/security-checker.spec.ts +70 -0
- package/src/common/security-check/security-checker.ts +48 -0
- package/src/common/utils/emitter.ts +5 -0
- package/src/common/utils/error-util.ts +27 -1
- package/src/common/utils/event.ts +20 -9
- package/src/common/utils/utils-behavior.spec.ts +23 -3
- package/src/common/utils/uuid.ts +1 -1
- package/src/node/application/backend-application.ts +1 -1
- package/src/node/context/context.spec.ts +14 -0
- package/src/node/context/context.ts +2 -3
- package/cell.remote.yml +0 -8
|
@@ -7,9 +7,9 @@ import { MethodBeforeAdvice, AfterReturningAdvice, AfterThrowsAdvice } from './a
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* AOP 的约定(阶段 1.E 行为测试):@Aspect 登记通知,proxy: true 的组件被代理。
|
|
10
|
-
* 需要
|
|
10
|
+
* 需要 aop.enabled(core 的 cell.yml 默认 true;这里直接放进配置)。
|
|
11
11
|
*/
|
|
12
|
-
const AOP_ON = {
|
|
12
|
+
const AOP_ON = { aop: { enabled: true } };
|
|
13
13
|
|
|
14
14
|
function recordingAspects(log: string[], pointcut?: string) {
|
|
15
15
|
const opt = <T>(id: T) => (pointcut ? { id, pointcut } : id) as any;
|
|
@@ -84,7 +84,7 @@ describe('core AOP', () => {
|
|
|
84
84
|
expect(await result).to.equal(8);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
it('没有 proxy: true 的组件不被代理;
|
|
87
|
+
it('没有 proxy: true 的组件不被代理;aop.enabled 为 false 时也不代理', async () => {
|
|
88
88
|
const log: string[] = [];
|
|
89
89
|
recordingAspects(log);
|
|
90
90
|
@Component()
|
|
@@ -99,7 +99,7 @@ describe('core AOP', () => {
|
|
|
99
99
|
class Disabled {
|
|
100
100
|
hi() { return 'hi'; }
|
|
101
101
|
}
|
|
102
|
-
await ApplicationFactory.create({
|
|
102
|
+
await ApplicationFactory.create({ aop: { enabled: false } });
|
|
103
103
|
expect(ContainerUtil.get(Disabled).hi()).to.equal('hi');
|
|
104
104
|
expect(log).to.deep.equal([]);
|
|
105
105
|
});
|
|
@@ -29,6 +29,10 @@ const host = ApplicationHost.get();
|
|
|
29
29
|
if (reason) {
|
|
30
30
|
console.error(reason);
|
|
31
31
|
}
|
|
32
|
+
// Nothing may keep the process alive, and it must not end as a success.
|
|
33
|
+
if (typeof process !== 'undefined') {
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
})().catch(error => {
|
|
34
38
|
// The container failed to load (a DI module threw): stop, or tell the host.
|
|
@@ -4,6 +4,8 @@ import { Event } from '../utils/event';
|
|
|
4
4
|
import { Emitter } from '../utils/emitter';
|
|
5
5
|
import { Logger } from '../logger/logger-protocol';
|
|
6
6
|
import { Autowired, Optional } from '../annotation';
|
|
7
|
+
import { SecurityChecker } from '../security-check/security-check-protocol';
|
|
8
|
+
import { ErrorUtil } from '../utils/error-util';
|
|
7
9
|
|
|
8
10
|
export const ApplicationLifecycle = Symbol('ApplicationLifecycle');
|
|
9
11
|
export const Application = Symbol('Application');
|
|
@@ -41,35 +43,43 @@ export abstract class AbstractApplication implements Application {
|
|
|
41
43
|
@Autowired(Logger)
|
|
42
44
|
protected readonly logger: Logger;
|
|
43
45
|
|
|
46
|
+
@Autowired(SecurityChecker)
|
|
47
|
+
protected readonly securityChecker: SecurityChecker;
|
|
48
|
+
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
50
|
+
* Applies the security checks (in production, `securityChecks: fail` stops here), then calls
|
|
51
|
+
* `initialize` of every lifecycle and `onStart` one after the other. A lifecycle that throws is
|
|
52
|
+
* logged and the others still run.
|
|
46
53
|
*/
|
|
47
54
|
protected async doStart(): Promise<void> {
|
|
55
|
+
await this.securityChecker.enforce();
|
|
48
56
|
for (const lifecycle of this.lifecycles) {
|
|
49
57
|
if (lifecycle.initialize) {
|
|
50
58
|
try {
|
|
51
59
|
lifecycle.initialize();
|
|
52
60
|
} catch (error) {
|
|
53
|
-
this.logger.error(
|
|
61
|
+
this.logger.error(`Could not initialize lifecycle ${lifecycle.constructor.name}: ${ErrorUtil.describe(error)}`);
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
// TODO
|
|
59
|
-
|
|
60
65
|
for (const lifecycle of this.lifecycles) {
|
|
61
66
|
if (lifecycle.onStart) {
|
|
62
67
|
try {
|
|
63
|
-
await
|
|
68
|
+
await this.startLifecycle(lifecycle);
|
|
64
69
|
} catch (error) {
|
|
65
|
-
this.logger.error(
|
|
70
|
+
this.logger.error(`Could not start lifecycle ${lifecycle.constructor.name}: ${ErrorUtil.describe(error)}`);
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
/** Runs `onStart` of one lifecycle; the frontend measures it. */
|
|
77
|
+
protected startLifecycle(lifecycle: ApplicationLifecycle<Application>): MaybePromise<void> {
|
|
78
|
+
return lifecycle.onStart!(this);
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
/**
|
|
72
|
-
*
|
|
82
|
+
* Calls `onStop` of every lifecycle; one that throws is logged and the others still run.
|
|
73
83
|
*/
|
|
74
84
|
protected doStop(): void {
|
|
75
85
|
for (const lifecycle of this.lifecycles) {
|
|
@@ -77,7 +87,7 @@ export abstract class AbstractApplication implements Application {
|
|
|
77
87
|
try {
|
|
78
88
|
lifecycle.onStop(this);
|
|
79
89
|
} catch (error) {
|
|
80
|
-
this.logger.error(
|
|
90
|
+
this.logger.error(`Could not stop lifecycle ${lifecycle.constructor.name}: ${ErrorUtil.describe(error)}`);
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
}
|
|
@@ -89,7 +99,7 @@ export type ApplicationState =
|
|
|
89
99
|
'init'
|
|
90
100
|
| 'started'
|
|
91
101
|
| 'ready'
|
|
92
|
-
| '
|
|
102
|
+
| 'stopped';
|
|
93
103
|
|
|
94
104
|
export interface ApplicationStateService<T extends string> {
|
|
95
105
|
state: T;
|
|
@@ -138,4 +148,4 @@ export abstract class AbstractApplicationStateService<T extends string> implemen
|
|
|
138
148
|
return Promise.race(states.map(s => this.reachedState(s)));
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
}
|
|
151
|
+
}
|
|
@@ -7,6 +7,7 @@ import { ContainerUtil } from '../container/container-util';
|
|
|
7
7
|
import { Scope } from '../container/scope';
|
|
8
8
|
import { Logger } from '../logger/logger-protocol';
|
|
9
9
|
import { MockLogger } from '../test/mock-logger';
|
|
10
|
+
import { SecurityCheck, SecurityCheckError, SecurityWarning } from '../security-check/security-check-protocol';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* 应用生命周期的约定(阶段 1.E 行为测试):ApplicationLifecycle 的调用顺序、出错时的行为、状态变化。
|
|
@@ -97,7 +98,12 @@ describe('core 应用生命周期', () => {
|
|
|
97
98
|
await app.start();
|
|
98
99
|
await app.stop();
|
|
99
100
|
expect(rec.events).to.deep.equal(['init', 'start', 'stop']);
|
|
100
|
-
|
|
101
|
+
// Each line names the lifecycle and carries the error with its stack.
|
|
102
|
+
expect(rec.errors.map(line => line.split('\n')[0])).to.deep.equal([
|
|
103
|
+
'Could not initialize lifecycle Broken: Error: init boom',
|
|
104
|
+
'Could not start lifecycle Broken: Error: start boom',
|
|
105
|
+
'Could not stop lifecycle Broken: Error: stop boom'
|
|
106
|
+
]);
|
|
101
107
|
expect([Broken, Healthy]).to.have.length(2);
|
|
102
108
|
});
|
|
103
109
|
|
|
@@ -107,23 +113,23 @@ describe('core 应用生命周期', () => {
|
|
|
107
113
|
await app.stop();
|
|
108
114
|
});
|
|
109
115
|
|
|
110
|
-
it('状态:init → started → ready,stop 之后是
|
|
116
|
+
it('状态:init → started → ready,stop 之后是 stopped;reachedState 与 onStateChanged', async () => {
|
|
111
117
|
const app = await ApplicationFactory.create({});
|
|
112
118
|
const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
|
|
113
119
|
expect(states.state).to.equal('init');
|
|
114
120
|
const seen: string[] = [];
|
|
115
121
|
states.onStateChanged(s => seen.push(s));
|
|
116
122
|
const ready = states.reachedState('ready');
|
|
117
|
-
const readyOrStopped = states.reachedAnyState('ready', '
|
|
123
|
+
const readyOrStopped = states.reachedAnyState('ready', 'stopped');
|
|
118
124
|
await app.start();
|
|
119
125
|
await ready;
|
|
120
126
|
await readyOrStopped;
|
|
121
127
|
expect(states.state).to.equal('ready');
|
|
122
128
|
await app.stop();
|
|
123
|
-
expect(states.state).to.equal('
|
|
124
|
-
expect(seen).to.deep.equal(['started', 'ready', '
|
|
129
|
+
expect(states.state).to.equal('stopped');
|
|
130
|
+
expect(seen).to.deep.equal(['started', 'ready', 'stopped']);
|
|
125
131
|
// 当前状态再等会立刻 resolve
|
|
126
|
-
await states.reachedState('
|
|
132
|
+
await states.reachedState('stopped');
|
|
127
133
|
});
|
|
128
134
|
|
|
129
135
|
it('离开一个状态之后,再 reachedState(那个状态) 立即 resolve(F7)', async () => {
|
|
@@ -133,7 +139,7 @@ describe('core 应用生命周期', () => {
|
|
|
133
139
|
const race = (p: Promise<void>) => Promise.race([p.then(() => 'resolved'), new Promise(r => setTimeout(() => r('pending'), 20))]);
|
|
134
140
|
expect(await race(states.reachedState('ready'))).to.equal('resolved');
|
|
135
141
|
expect(await race(states.reachedState('started'))).to.equal('resolved');
|
|
136
|
-
expect(await race(states.reachedState('
|
|
142
|
+
expect(await race(states.reachedState('stopped'))).to.equal('pending');
|
|
137
143
|
});
|
|
138
144
|
|
|
139
145
|
it('同一个状态重复设置不会重复通知', async () => {
|
|
@@ -145,4 +151,42 @@ describe('core 应用生命周期', () => {
|
|
|
145
151
|
states.state = 'started';
|
|
146
152
|
expect(seen).to.deep.equal(['started']);
|
|
147
153
|
});
|
|
148
|
-
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('启动时的安全检查', () => {
|
|
157
|
+
/** Registers a check that warns and a lifecycle that records its start; autoBind of the next create() takes them. */
|
|
158
|
+
function components(rec: Recorder) {
|
|
159
|
+
@Component(SecurityCheck)
|
|
160
|
+
class PublicKeyCheck implements SecurityCheck {
|
|
161
|
+
check(): SecurityWarning[] {
|
|
162
|
+
return [{ code: 'CELL_SECURITY_TEST', message: 'The key is public.', hint: 'Set your own key.' }];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
@Component(ApplicationLifecycle)
|
|
166
|
+
class Started implements ApplicationLifecycle<Application> {
|
|
167
|
+
onStart() { rec.events.push('start'); }
|
|
168
|
+
}
|
|
169
|
+
return [PublicKeyCheck, Started];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
it('生产环境 securityChecks: fail 时 start() 拒绝启动,生命周期不会运行;warn 时照常启动', async () => {
|
|
173
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
174
|
+
const rec: Recorder = { events: [], errors: [] };
|
|
175
|
+
process.env.NODE_ENV = 'production';
|
|
176
|
+
try {
|
|
177
|
+
components(rec);
|
|
178
|
+
const failing = await ApplicationFactory.create({ securityChecks: 'fail', logger: { level: 'error' } });
|
|
179
|
+
const error = await failing.start().then(() => undefined, e => e);
|
|
180
|
+
expect(error).to.be.instanceOf(SecurityCheckError);
|
|
181
|
+
expect(error.code).to.equal('CELL_SECURITY_CHECK_FAILED');
|
|
182
|
+
expect(rec.events).to.deep.equal([]);
|
|
183
|
+
components(rec);
|
|
184
|
+
const warning = await ApplicationFactory.create({ securityChecks: 'warn', logger: { level: 'error' } });
|
|
185
|
+
await warning.start();
|
|
186
|
+
expect(rec.events).to.deep.equal(['start']);
|
|
187
|
+
await warning.stop();
|
|
188
|
+
} finally {
|
|
189
|
+
process.env.NODE_ENV = nodeEnv;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigProvider } from './config-protocol';
|
|
2
2
|
import { ContainerUtil } from '../container';
|
|
3
|
-
import { config } from './dynamic-config';
|
|
3
|
+
import { config, types } from './dynamic-config';
|
|
4
|
+
import type { ConfigTypes } from './env-config-util';
|
|
4
5
|
import { currentThis } from '../utils';
|
|
5
6
|
|
|
6
7
|
export namespace ConfigUtil {
|
|
@@ -11,4 +12,9 @@ export namespace ConfigUtil {
|
|
|
11
12
|
export function getRaw() {
|
|
12
13
|
return currentThis.cellProps || config;
|
|
13
14
|
}
|
|
15
|
+
|
|
16
|
+
/** Schema types of keys whose value is an expression; tests that set `cellProps` may set `cellConfigTypes`. */
|
|
17
|
+
export function getTypes(): ConfigTypes {
|
|
18
|
+
return currentThis.cellConfigTypes || types;
|
|
19
|
+
}
|
|
14
20
|
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigTypes } from './env-config-util';
|
|
2
|
+
|
|
3
|
+
// Replaced by the build (@celljs/vite) with the merged configuration of the application.
|
|
2
4
|
export const config: { [key: string]: any } = {};
|
|
5
|
+
|
|
6
|
+
/** Schema types of the keys whose value is an expression, which evaluation converts to (`server.port: ${env.PORT ?? 3000}`). */
|
|
7
|
+
export const types: ConfigTypes = {};
|