@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
|
@@ -5,53 +5,50 @@ const expect = chai.expect;
|
|
|
5
5
|
|
|
6
6
|
describe('EnvConfigUtil', () => {
|
|
7
7
|
const config = () => ({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
cors: null,
|
|
13
|
-
},
|
|
8
|
+
server: { path: '/', port: 3000, endpoint: 'http://localhost:${server.port}' },
|
|
9
|
+
'serve-static': { enabled: true },
|
|
10
|
+
typeorm: { ormConfig: [{ type: 'sqlite', database: 'db.sql', logging: false }] },
|
|
11
|
+
cors: null as unknown,
|
|
14
12
|
accounts: { title: 'Accounts', providers: ['github'] },
|
|
15
13
|
mode: ['production'],
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
it('sets keys
|
|
16
|
+
it('sets keys, matching case, underscores and dashes loosely', () => {
|
|
19
17
|
const target = config();
|
|
20
18
|
const result = EnvConfigUtil.apply(
|
|
21
19
|
target,
|
|
22
20
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
CELL_SERVER__PORT: '8080',
|
|
22
|
+
CELL_SERVE_STATIC__ENABLED: 'FALSE',
|
|
23
|
+
CELL_TYPEORM__ORM_CONFIG__0__DATABASE: '/data/db.sql',
|
|
24
|
+
CELL_TYPEORM__ORM_CONFIG__0__LOGGING: 'true',
|
|
27
25
|
PATH: '/usr/bin',
|
|
28
|
-
}
|
|
29
|
-
'backend',
|
|
26
|
+
}
|
|
30
27
|
);
|
|
31
28
|
expect(result.problems).to.deep.equal([]);
|
|
32
29
|
expect(result.applied).to.deep.equal([
|
|
33
|
-
{ variable: '
|
|
34
|
-
{ variable: '
|
|
35
|
-
{ variable: '
|
|
36
|
-
{ variable: '
|
|
30
|
+
{ variable: 'CELL_SERVER__PORT', path: 'server.port' },
|
|
31
|
+
{ variable: 'CELL_SERVE_STATIC__ENABLED', path: 'serve-static.enabled' },
|
|
32
|
+
{ variable: 'CELL_TYPEORM__ORM_CONFIG__0__DATABASE', path: 'typeorm.ormConfig.0.database' },
|
|
33
|
+
{ variable: 'CELL_TYPEORM__ORM_CONFIG__0__LOGGING', path: 'typeorm.ormConfig.0.logging' },
|
|
37
34
|
]);
|
|
38
|
-
expect(target.
|
|
39
|
-
expect(target
|
|
40
|
-
expect(target.
|
|
35
|
+
expect(target.server.port).to.equal(8080);
|
|
36
|
+
expect(target['serve-static'].enabled).to.equal(false);
|
|
37
|
+
expect(target.typeorm.ormConfig[0]).to.deep.equal({ type: 'sqlite', database: '/data/db.sql', logging: true });
|
|
41
38
|
});
|
|
42
39
|
|
|
43
40
|
it('keeps expressions of other keys for later evaluation', () => {
|
|
44
41
|
const target = config();
|
|
45
|
-
EnvConfigUtil.apply(target, {
|
|
46
|
-
expect(target.
|
|
42
|
+
EnvConfigUtil.apply(target, { CELL_SERVER__PORT: '8080' });
|
|
43
|
+
expect(target.server.endpoint).to.equal('http://localhost:${server.port}');
|
|
47
44
|
});
|
|
48
45
|
|
|
49
|
-
it('reaches top-level
|
|
46
|
+
it('reaches every top-level key', () => {
|
|
50
47
|
const target = config();
|
|
51
|
-
const { applied } = EnvConfigUtil.apply(target, {
|
|
52
|
-
expect(applied.map(a => a.path)).to.deep.equal(['accounts.title', '
|
|
48
|
+
const { applied } = EnvConfigUtil.apply(target, { CELL_ACCOUNTS__TITLE: 'Team', CELL_SERVER__PATH: '/api' });
|
|
49
|
+
expect(applied.map(a => a.path)).to.deep.equal(['accounts.title', 'server.path']);
|
|
53
50
|
expect(target.accounts.title).to.equal('Team');
|
|
54
|
-
expect(target.
|
|
51
|
+
expect(target.server.path).to.equal('/api');
|
|
55
52
|
});
|
|
56
53
|
|
|
57
54
|
it('parses objects and arrays as JSON and leaves strings as they are', () => {
|
|
@@ -59,16 +56,15 @@ describe('EnvConfigUtil', () => {
|
|
|
59
56
|
const result = EnvConfigUtil.apply(
|
|
60
57
|
target,
|
|
61
58
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
'backend',
|
|
59
|
+
CELL_ACCOUNTS__PROVIDERS: '["github","gitlab"]',
|
|
60
|
+
CELL_CORS: '{"origin":"*"}',
|
|
61
|
+
CELL_SERVER__ENDPOINT: '8080',
|
|
62
|
+
}
|
|
67
63
|
);
|
|
68
64
|
expect(result.problems).to.deep.equal([]);
|
|
69
65
|
expect(target.accounts.providers).to.deep.equal(['github', 'gitlab']);
|
|
70
|
-
expect(target.
|
|
71
|
-
expect(target.
|
|
66
|
+
expect(target.cors).to.deep.equal({ origin: '*' });
|
|
67
|
+
expect(target.server.endpoint).to.equal('8080');
|
|
72
68
|
});
|
|
73
69
|
|
|
74
70
|
it('reports variables that match no key or do not fit its type, and changes nothing for them', () => {
|
|
@@ -76,36 +72,35 @@ describe('EnvConfigUtil', () => {
|
|
|
76
72
|
const { applied, problems } = EnvConfigUtil.apply(
|
|
77
73
|
target,
|
|
78
74
|
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
'backend',
|
|
75
|
+
CELL_SERVER__PROT: '1',
|
|
76
|
+
CELL_SERVR__PORT: '1',
|
|
77
|
+
CELL_SERVER__PORT: 'abc',
|
|
78
|
+
CELL_SERVE_STATIC__ENABLED: 'yes',
|
|
79
|
+
CELL_ACCOUNTS__PROVIDERS: 'github',
|
|
80
|
+
CELL_TYPEORM__ORM_CONFIG__3__TYPE: 'mysql',
|
|
81
|
+
CELL_SERVER__PORT__X: '1',
|
|
82
|
+
CELL_SERVER____PORT: '1',
|
|
83
|
+
}
|
|
89
84
|
);
|
|
90
85
|
expect(applied).to.deep.equal([]);
|
|
91
86
|
expect(target).to.deep.equal(config());
|
|
92
87
|
const messages = Object.fromEntries(problems.map(p => [p.variable, p.message]));
|
|
93
|
-
expect(messages.
|
|
94
|
-
"no key 'PROT' under
|
|
88
|
+
expect(messages.CELL_SERVER__PROT).to.equal(
|
|
89
|
+
"no key 'PROT' under server (keys: path, port, endpoint). Only keys present in cell.yml can be overridden.",
|
|
95
90
|
);
|
|
96
|
-
expect(messages.
|
|
97
|
-
"no key 'SERVR'
|
|
91
|
+
expect(messages.CELL_SERVR__PORT).to.equal(
|
|
92
|
+
"no key 'SERVR' under the top level (keys: server, serve-static, typeorm, cors, accounts, mode). Only keys present in cell.yml can be overridden.",
|
|
98
93
|
);
|
|
99
|
-
expect(messages.
|
|
100
|
-
expect(messages.
|
|
101
|
-
expect(messages.
|
|
102
|
-
expect(messages.
|
|
103
|
-
expect(messages.
|
|
104
|
-
expect(messages.
|
|
94
|
+
expect(messages.CELL_SERVER__PORT).to.equal("server.port is a number, got 'abc'. Use a decimal number such as 8080, -1 or 0.5.");
|
|
95
|
+
expect(messages.CELL_SERVE_STATIC__ENABLED).to.equal("serve-static.enabled is a boolean, got 'yes'. Use true or false.");
|
|
96
|
+
expect(messages.CELL_ACCOUNTS__PROVIDERS).to.contain('accounts.providers is an array; pass it as JSON');
|
|
97
|
+
expect(messages.CELL_TYPEORM__ORM_CONFIG__3__TYPE).to.contain('(indexes 0-0)');
|
|
98
|
+
expect(messages.CELL_SERVER__PORT__X).to.equal("server.port is not an object, so it has no key 'X'.");
|
|
99
|
+
expect(messages.CELL_SERVER____PORT).to.contain('empty segment');
|
|
105
100
|
});
|
|
106
101
|
|
|
107
|
-
it('applies the
|
|
108
|
-
const variables = {
|
|
102
|
+
it('applies the CELL_ variables of process.env and warns about the ones that do not apply', () => {
|
|
103
|
+
const variables = { CELL_SERVER__PORT: '8080', CELL_SERVER__PROT: '1', CELL_FRONTEND__SERVER__PATH: '/ui' };
|
|
109
104
|
const warn = console.warn;
|
|
110
105
|
const warnings: string[] = [];
|
|
111
106
|
console.warn = (message: string) => warnings.push(message);
|
|
@@ -113,10 +108,11 @@ describe('EnvConfigUtil', () => {
|
|
|
113
108
|
try {
|
|
114
109
|
const target = config();
|
|
115
110
|
const result = EnvConfigUtil.applyProcessEnv(target);
|
|
116
|
-
expect(result.applied).to.deep.equal([{ variable: '
|
|
117
|
-
expect(target.
|
|
111
|
+
expect(result.applied).to.deep.equal([{ variable: 'CELL_SERVER__PORT', path: 'server.port' }]);
|
|
112
|
+
expect(target.server).to.deep.include({ port: 8080, path: '/' });
|
|
118
113
|
expect(warnings).to.deep.equal([
|
|
119
|
-
|
|
114
|
+
'[cell] CELL_FRONTEND__SERVER__PATH is ignored: the CELL_BACKEND__ / CELL_FRONTEND__ prefixes are gone: the same variable serves both sides, e.g. CELL_SERVER__PATH.',
|
|
115
|
+
"[cell] CELL_SERVER__PROT is ignored: no key 'PROT' under server (keys: path, port, endpoint). Only keys present in cell.yml can be overridden.",
|
|
120
116
|
]);
|
|
121
117
|
} finally {
|
|
122
118
|
console.warn = warn;
|
|
@@ -129,22 +125,22 @@ describe('EnvConfigUtil', () => {
|
|
|
129
125
|
it('takes finite numbers in JSON syntax only', () => {
|
|
130
126
|
const port = (value: string) => {
|
|
131
127
|
const target = config();
|
|
132
|
-
const { applied, problems } = EnvConfigUtil.apply(target, {
|
|
133
|
-
return applied.length === 1 ? target.
|
|
128
|
+
const { applied, problems } = EnvConfigUtil.apply(target, { CELL_SERVER__PORT: value });
|
|
129
|
+
return applied.length === 1 ? target.server.port : problems[0].message;
|
|
134
130
|
};
|
|
135
131
|
for (const [value, expected] of [['8080', 8080], ['0', 0], ['-1', -1], ['0.5', 0.5], ['1e3', 1000], ['-2.5E-1', -0.25]] as const) {
|
|
136
132
|
expect(port(value), value).to.equal(expected);
|
|
137
133
|
}
|
|
138
134
|
for (const value of ['Infinity', '-Infinity', 'NaN', '1e999', '0x10', '0b1', '1_000', '+1', '08080', '.5', '5.', '', ' 8080', '8080 ']) {
|
|
139
|
-
expect(port(value), JSON.stringify(value)).to.equal(`
|
|
135
|
+
expect(port(value), JSON.stringify(value)).to.equal(`server.port is a number, got '${value}'. Use a decimal number such as 8080, -1 or 0.5.`);
|
|
140
136
|
}
|
|
141
137
|
});
|
|
142
138
|
|
|
143
139
|
it('follows null in cell.yml with JSON when the value is JSON, else text', () => {
|
|
144
140
|
const cors = (value: string) => {
|
|
145
141
|
const target = config();
|
|
146
|
-
EnvConfigUtil.apply(target, {
|
|
147
|
-
return target.
|
|
142
|
+
EnvConfigUtil.apply(target, { CELL_CORS: value });
|
|
143
|
+
return target.cors;
|
|
148
144
|
};
|
|
149
145
|
expect(cors('null')).to.equal(null);
|
|
150
146
|
expect(cors('5')).to.equal(5);
|
|
@@ -160,59 +156,57 @@ describe('EnvConfigUtil', () => {
|
|
|
160
156
|
const { applied, problems } = EnvConfigUtil.apply(
|
|
161
157
|
target,
|
|
162
158
|
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
'backend',
|
|
159
|
+
CELL_SERVER__PORT: '${env.PORT ?: 3000}',
|
|
160
|
+
CELL_SERVE_STATIC__ENABLED: '${env.STATIC == "on"}',
|
|
161
|
+
CELL_ACCOUNTS__PROVIDERS: '${app.providers}',
|
|
162
|
+
CELL_SERVER__PATH: '/${env.BASE}',
|
|
163
|
+
}
|
|
169
164
|
);
|
|
170
165
|
expect(problems).to.deep.equal([]);
|
|
171
166
|
expect(applied).to.have.length(4);
|
|
172
|
-
expect(target.
|
|
173
|
-
expect(target
|
|
174
|
-
expect(target.accounts.providers).to.equal('${
|
|
175
|
-
expect(target.
|
|
167
|
+
expect(target.server.port).to.equal('${env.PORT ?: 3000}');
|
|
168
|
+
expect(target['serve-static'].enabled).to.equal('${env.STATIC == "on"}');
|
|
169
|
+
expect(target.accounts.providers).to.equal('${app.providers}');
|
|
170
|
+
expect(target.server.path).to.equal('/${env.BASE}');
|
|
176
171
|
});
|
|
177
172
|
|
|
178
173
|
it('rejects text around an expression where the key needs a number, boolean, object or array', () => {
|
|
179
174
|
const { applied, problems } = EnvConfigUtil.apply(
|
|
180
175
|
config(),
|
|
181
|
-
{
|
|
182
|
-
'backend',
|
|
176
|
+
{ CELL_SERVER__PORT: '80${env.X}', CELL_SERVE_STATIC__ENABLED: '${a} ${b}', CELL_ACCOUNTS__PROVIDERS: 'x${a}' }
|
|
183
177
|
);
|
|
184
178
|
expect(applied).to.deep.equal([]);
|
|
185
179
|
expect(problems.map(p => p.variable)).to.deep.equal([
|
|
186
|
-
'
|
|
187
|
-
'
|
|
188
|
-
'
|
|
180
|
+
'CELL_ACCOUNTS__PROVIDERS',
|
|
181
|
+
'CELL_SERVER__PORT',
|
|
182
|
+
'CELL_SERVE_STATIC__ENABLED',
|
|
189
183
|
]);
|
|
190
184
|
});
|
|
191
185
|
|
|
192
186
|
it('takes true and false in any case for booleans and names the value it rejects', () => {
|
|
193
187
|
const enabled = (value: string) => {
|
|
194
188
|
const target = config();
|
|
195
|
-
const { problems } = EnvConfigUtil.apply(target, {
|
|
196
|
-
return problems.length > 0 ? problems[0].message : target
|
|
189
|
+
const { problems } = EnvConfigUtil.apply(target, { CELL_SERVE_STATIC__ENABLED: value });
|
|
190
|
+
return problems.length > 0 ? problems[0].message : target['serve-static'].enabled;
|
|
197
191
|
};
|
|
198
192
|
expect(enabled('FALSE')).to.equal(false);
|
|
199
193
|
expect(enabled('True')).to.equal(true);
|
|
200
194
|
for (const value of ['yes', '1', '0', '', ' true']) {
|
|
201
|
-
expect(enabled(value)).to.equal(`
|
|
195
|
+
expect(enabled(value)).to.equal(`serve-static.enabled is a boolean, got '${value}'. Use true or false.`);
|
|
202
196
|
}
|
|
203
197
|
});
|
|
204
198
|
|
|
205
199
|
it('rejects integers that a number cannot hold exactly', () => {
|
|
206
200
|
const port = (value: string) => {
|
|
207
201
|
const target = config();
|
|
208
|
-
const { problems } = EnvConfigUtil.apply(target, {
|
|
209
|
-
return problems.length > 0 ? problems[0].message : target.
|
|
202
|
+
const { problems } = EnvConfigUtil.apply(target, { CELL_SERVER__PORT: value });
|
|
203
|
+
return problems.length > 0 ? problems[0].message : target.server.port;
|
|
210
204
|
};
|
|
211
205
|
expect(port('9007199254740991')).to.equal(9007199254740991);
|
|
212
206
|
expect(port('-9007199254740991')).to.equal(-9007199254740991);
|
|
213
207
|
expect(port('1.5e300')).to.equal(1.5e300);
|
|
214
208
|
expect(port('9007199254740993')).to.equal(
|
|
215
|
-
"
|
|
209
|
+
"server.port is a number, got '9007199254740993', which is too large to keep exactly. Use a string in cell.yml for such values.",
|
|
216
210
|
);
|
|
217
211
|
});
|
|
218
212
|
|
|
@@ -221,121 +215,130 @@ describe('EnvConfigUtil', () => {
|
|
|
221
215
|
const { applied, problems } = EnvConfigUtil.apply(
|
|
222
216
|
target,
|
|
223
217
|
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
'backend',
|
|
218
|
+
CELL_ACCOUNTS__PROVIDERS__00: 'gitlab',
|
|
219
|
+
CELL_TYPEORM__ORM_CONFIG__00__TYPE: 'mysql',
|
|
220
|
+
CELL_TYPEORM__ORM_CONFIG__0__TYPE: 'postgres',
|
|
221
|
+
}
|
|
229
222
|
);
|
|
230
|
-
expect(applied.map(a => a.path)).to.deep.equal(['
|
|
231
|
-
expect(problems.map(p => p.variable)).to.deep.equal(['
|
|
223
|
+
expect(applied.map(a => a.path)).to.deep.equal(['typeorm.ormConfig.0.type']);
|
|
224
|
+
expect(problems.map(p => p.variable)).to.deep.equal(['CELL_ACCOUNTS__PROVIDERS__00', 'CELL_TYPEORM__ORM_CONFIG__00__TYPE']);
|
|
232
225
|
expect(problems[0].message).to.equal("no key '00' under accounts.providers (indexes 0-0). Only keys present in cell.yml can be overridden.");
|
|
233
226
|
// '00' must not become a property of the array next to item 0.
|
|
234
227
|
expect(Object.keys(target.accounts.providers)).to.deep.equal(['0']);
|
|
235
|
-
expect(target.
|
|
228
|
+
expect(target.typeorm.ormConfig[0].type).to.equal('postgres');
|
|
236
229
|
});
|
|
237
230
|
|
|
238
231
|
describe('keys set by more than one variable', () => {
|
|
239
232
|
const conflict = (env: Record<string, string>) => {
|
|
240
233
|
const target = config();
|
|
241
|
-
return { target, ...EnvConfigUtil.apply(target, env
|
|
234
|
+
return { target, ...EnvConfigUtil.apply(target, env) };
|
|
242
235
|
};
|
|
243
236
|
|
|
244
237
|
it('applies none of the variables that set the same key, however they spell it', () => {
|
|
245
238
|
const { target, applied, problems } = conflict({
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
239
|
+
CELL_SERVER__PORT: '1',
|
|
240
|
+
CELL_server__port: '2',
|
|
241
|
+
CELL_SERVER__P_ORT: '3',
|
|
242
|
+
CELL_SERVER__PATH: '/api',
|
|
250
243
|
});
|
|
251
|
-
expect(applied).to.deep.equal([{ variable: '
|
|
252
|
-
expect(target.
|
|
253
|
-
expect(problems.map(p => p.variable)).to.deep.equal(['
|
|
254
|
-
expect(problems[
|
|
255
|
-
'sets
|
|
244
|
+
expect(applied).to.deep.equal([{ variable: 'CELL_SERVER__PATH', path: 'server.path' }]);
|
|
245
|
+
expect(target.server.port).to.equal(3000);
|
|
246
|
+
expect(problems.map(p => p.variable)).to.deep.equal(['CELL_SERVER__PORT', 'CELL_SERVER__P_ORT', 'CELL_server__port']);
|
|
247
|
+
expect(problems[0].message).to.equal(
|
|
248
|
+
'sets server.port, which CELL_SERVER__P_ORT (server.port), CELL_server__port (server.port) also set. Set each key with one variable; to change items of an object or array you replace, write them into its JSON.',
|
|
256
249
|
);
|
|
257
250
|
});
|
|
258
251
|
|
|
259
252
|
it('applies neither a key nor a key inside it, in either order of the names', () => {
|
|
260
253
|
const pairs = [
|
|
261
254
|
// The whole array sorts first, then the item.
|
|
262
|
-
['
|
|
255
|
+
['CELL_TYPEORM__ORM_CONFIG', 'CELL_TYPEORM__ORM_CONFIG__0__DATABASE'],
|
|
263
256
|
// The item sorts first: applied in order, the array would have wiped it out.
|
|
264
|
-
['
|
|
265
|
-
['
|
|
257
|
+
['CELL_TYPEORM__ORM_CONFIG', 'CELL_typeorm__ormConfig__0__DATABASE'],
|
|
258
|
+
['CELL_typeorm__ormConfig', 'CELL_TYPEORM__ORM_CONFIG__0__DATABASE'],
|
|
266
259
|
];
|
|
267
260
|
for (const [whole, item] of pairs) {
|
|
268
261
|
const { target, applied, problems } = conflict({ [whole]: '[{"type":"mysql"}]', [item]: 'x.sql' });
|
|
269
262
|
expect(applied, `${whole} + ${item}`).to.deep.equal([]);
|
|
270
263
|
expect(problems.map(p => p.variable).sort()).to.deep.equal([item, whole].sort());
|
|
271
|
-
expect(problems.find(p => p.variable === item)!.message).to.contain(`which ${whole} (
|
|
272
|
-
expect(target.
|
|
264
|
+
expect(problems.find(p => p.variable === item)!.message).to.contain(`which ${whole} (typeorm.ormConfig) also sets`);
|
|
265
|
+
expect(target.typeorm.ormConfig).to.deep.equal(config().typeorm.ormConfig);
|
|
273
266
|
}
|
|
274
267
|
});
|
|
275
268
|
|
|
276
269
|
it('lets variables of different keys under the same object apply', () => {
|
|
277
|
-
const { applied, problems } = conflict({
|
|
270
|
+
const { applied, problems } = conflict({ CELL_TYPEORM__ORM_CONFIG__0__TYPE: 'mysql', CELL_TYPEORM__ORM_CONFIG__0__DATABASE: 'x' });
|
|
278
271
|
expect(problems).to.deep.equal([]);
|
|
279
272
|
expect(applied).to.have.length(2);
|
|
280
273
|
});
|
|
281
274
|
|
|
282
275
|
it('does not depend on the order of the variables in the environment', () => {
|
|
283
|
-
const names = ['
|
|
276
|
+
const names = ['CELL_TYPEORM__ORM_CONFIG__0__DATABASE', 'CELL_typeorm__ormConfig', 'CELL_SERVER__PORT'];
|
|
284
277
|
const run = (order: string[]) => {
|
|
285
278
|
const target = config();
|
|
286
279
|
const env = Object.fromEntries(order.map(name => [name, name.endsWith('ORM_CONFIG') ? '[]' : '1']));
|
|
287
|
-
return JSON.stringify({ result: EnvConfigUtil.apply(target, env
|
|
280
|
+
return JSON.stringify({ result: EnvConfigUtil.apply(target, env), target });
|
|
288
281
|
};
|
|
289
282
|
expect(run([...names].reverse())).to.equal(run(names));
|
|
290
283
|
});
|
|
291
284
|
});
|
|
292
285
|
|
|
293
|
-
|
|
294
|
-
const
|
|
286
|
+
it('reads CELL_ variables, leaving the toolchain ones and those of other tools alone', () => {
|
|
287
|
+
const target = config();
|
|
288
|
+
const result = EnvConfigUtil.apply(target, {
|
|
289
|
+
CELL_SERVER__PORT: '3',
|
|
290
|
+
CELL_MODE: 'production',
|
|
291
|
+
CELL_PRESET: 'node',
|
|
292
|
+
CELL_REGION: 'cn-hangzhou',
|
|
293
|
+
SERVER__PORT: '4',
|
|
294
|
+
});
|
|
295
|
+
expect(result).to.deep.equal({ applied: [{ variable: 'CELL_SERVER__PORT', path: 'server.port' }], problems: [] });
|
|
296
|
+
expect(target.server.port).to.equal(3);
|
|
297
|
+
expect(target.mode).to.deep.equal(['production']);
|
|
298
|
+
expect(EnvConfigUtil.isOverride('CELL_MODE')).to.equal(false);
|
|
299
|
+
});
|
|
295
300
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
it('reports a name with __ whose first key does not exist, and the earlier prefixes', () => {
|
|
302
|
+
const { applied, problems } = EnvConfigUtil.apply(config(), {
|
|
303
|
+
CELL_SERVR__PORT: '1',
|
|
304
|
+
CELL__SERVER__PORT: '2',
|
|
305
|
+
CELL_BACKEND__SERVER__PORT: '3',
|
|
306
|
+
});
|
|
307
|
+
expect(applied).to.deep.equal([]);
|
|
308
|
+
expect(Object.fromEntries(problems.map(p => [p.variable, p.message]))).to.deep.equal({
|
|
309
|
+
CELL_BACKEND__SERVER__PORT: 'the CELL_BACKEND__ / CELL_FRONTEND__ prefixes are gone: the same variable serves both sides, e.g. CELL_SERVER__PORT.',
|
|
310
|
+
CELL_SERVR__PORT: "no key 'SERVR' under the top level (keys: server, serve-static, typeorm, cors, accounts, mode). Only keys present in cell.yml can be overridden.",
|
|
311
|
+
CELL__SERVER__PORT: 'one underscore after CELL, then `__` between keys: CELL_SERVER__PORT.',
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe('schema types', () => {
|
|
316
|
+
it('convert a value replacing an expression to the type of the key', () => {
|
|
317
|
+
const target = { server: { port: '${env.PORT ?? 3000}', secure: '${env.SECURE ?? false}' } };
|
|
318
|
+
const { applied, problems } = EnvConfigUtil.apply(target, { CELL_SERVER__PORT: '8080', CELL_SERVER__SECURE: 'TRUE' }, { 'server.port': 'integer', 'server.secure': 'boolean' });
|
|
303
319
|
expect(problems).to.deep.equal([]);
|
|
304
|
-
expect(applied).to.
|
|
305
|
-
|
|
306
|
-
{ variable: 'CELL_BACKEND__ACCOUNTS__TITLE', path: 'accounts.title', shadows: 'cell.accounts' },
|
|
307
|
-
{ variable: 'CELL_BACKEND__SERVER__X', path: 'server.x', shadows: 'cell.server' },
|
|
308
|
-
]);
|
|
309
|
-
expect(target).to.deep.equal({ cell: { server: { port: 3000 }, accounts: { title: 'Inner' } }, server: { x: 5 }, accounts: { title: 'Top', team: 'u' } });
|
|
320
|
+
expect(applied).to.have.length(2);
|
|
321
|
+
expect(target.server).to.deep.equal({ port: 8080, secure: true });
|
|
310
322
|
});
|
|
311
323
|
|
|
312
|
-
it('
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
{ CELL_BACKEND__CELL__ACCOUNTS__TITLE: 'In', CELL_BACKEND__CELL__SERVER__PORT: '8080', CELL_BACKEND__SERVER__PORT: '1' },
|
|
317
|
-
'backend',
|
|
318
|
-
);
|
|
319
|
-
expect(applied).to.deep.equal([
|
|
320
|
-
{ variable: 'CELL_BACKEND__CELL__ACCOUNTS__TITLE', path: 'cell.accounts.title' },
|
|
321
|
-
{ variable: 'CELL_BACKEND__CELL__SERVER__PORT', path: 'cell.server.port' },
|
|
322
|
-
]);
|
|
323
|
-
expect(target.cell).to.deep.equal({ server: { port: 8080 }, accounts: { title: 'In' } });
|
|
324
|
-
expect(problems).to.deep.equal([
|
|
325
|
-
{ variable: 'CELL_BACKEND__SERVER__PORT', message: "no key 'PORT' under server (keys: x). Only keys present in cell.yml can be overridden." },
|
|
326
|
-
]);
|
|
324
|
+
it('record the type of a number or boolean key that a variable sets to an expression', () => {
|
|
325
|
+
const types = {};
|
|
326
|
+
EnvConfigUtil.apply({ server: { port: 3000, host: 'x' } }, { CELL_SERVER__PORT: '${env.PLATFORM_PORT}', CELL_SERVER__HOST: '${env.HOST}' }, types);
|
|
327
|
+
expect(types).to.deep.equal({ 'server.port': 'number' });
|
|
327
328
|
});
|
|
328
329
|
|
|
329
|
-
it('
|
|
330
|
-
const
|
|
331
|
-
|
|
330
|
+
it('reject a value that does not fit the type', () => {
|
|
331
|
+
const target = { server: { port: '${env.PORT}' } };
|
|
332
|
+
const { problems } = EnvConfigUtil.apply(target, { CELL_SERVER__PORT: '80.5' }, { 'server.port': 'integer' });
|
|
333
|
+
expect(problems[0].message).to.equal("server.port is an integer, got '80.5'.");
|
|
332
334
|
});
|
|
333
|
-
});
|
|
334
335
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
it('toType converts text and keeps other values', () => {
|
|
337
|
+
expect(EnvConfigUtil.toType('number', '1.5', 'a')).to.equal(1.5);
|
|
338
|
+
expect(EnvConfigUtil.toType('boolean', 'false', 'a')).to.equal(false);
|
|
339
|
+
expect(EnvConfigUtil.toType('integer', 3, 'a')).to.equal(3);
|
|
340
|
+
expect(EnvConfigUtil.toType('string', '3', 'a')).to.equal('3');
|
|
341
|
+
expect(() => EnvConfigUtil.toType('number', 'abc', 'a')).to.throw("a is a number, got 'abc'.");
|
|
342
|
+
});
|
|
340
343
|
});
|
|
341
344
|
});
|