@celljs/core 3.9.0 → 4.0.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/cell.remote.yml +8 -0
- package/cell.yml +0 -3
- package/esm/common/application/application-entry.js +21 -3
- package/esm/common/application/application-entry.js.map +1 -1
- package/esm/common/application/application-host.d.ts +38 -0
- package/esm/common/application/application-host.js +17 -0
- package/esm/common/application/application-host.js.map +1 -0
- package/esm/common/application/index.d.ts +1 -0
- package/esm/common/application/index.js +1 -0
- package/esm/common/application/index.js.map +1 -1
- package/esm/common/config/env-config-util.d.ts +48 -0
- package/esm/common/config/env-config-util.js +185 -0
- package/esm/common/config/env-config-util.js.map +1 -0
- package/esm/common/config/index.d.ts +1 -0
- package/esm/common/config/index.js +1 -0
- package/esm/common/config/index.js.map +1 -1
- package/lib/common/application/application-entry.d.ts.map +1 -1
- package/lib/common/application/application-entry.js +21 -3
- package/lib/common/application/application-entry.js.map +1 -1
- package/lib/common/application/application-host.d.ts +39 -0
- package/lib/common/application/application-host.d.ts.map +1 -0
- package/lib/common/application/application-host.js +20 -0
- package/lib/common/application/application-host.js.map +1 -0
- package/lib/common/application/index.d.ts +1 -0
- package/lib/common/application/index.d.ts.map +1 -1
- package/lib/common/application/index.js +1 -0
- package/lib/common/application/index.js.map +1 -1
- package/lib/common/config/env-config-util.d.ts +49 -0
- package/lib/common/config/env-config-util.d.ts.map +1 -0
- package/lib/common/config/env-config-util.js +188 -0
- package/lib/common/config/env-config-util.js.map +1 -0
- package/lib/common/config/env-config-util.spec.d.ts +2 -0
- package/lib/common/config/env-config-util.spec.d.ts.map +1 -0
- package/lib/common/config/env-config-util.spec.js +314 -0
- package/lib/common/config/env-config-util.spec.js.map +1 -0
- package/lib/common/config/index.d.ts +1 -0
- package/lib/common/config/index.d.ts.map +1 -1
- package/lib/common/config/index.js +1 -0
- package/lib/common/config/index.js.map +1 -1
- package/package.json +14 -25
- package/src/common/application/application-entry.ts +20 -4
- package/src/common/application/application-host.ts +46 -0
- package/src/common/application/index.ts +1 -0
- package/src/common/config/env-config-util.spec.ts +341 -0
- package/src/common/config/env-config-util.ts +225 -0
- package/src/common/config/index.ts +1 -0
- package/cell-remote.yml +0 -3
package/cell.remote.yml
ADDED
package/cell.yml
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { container } from '../container/dynamic-container.js';
|
|
2
2
|
import { Application } from './application-protocol.js';
|
|
3
|
+
import { ApplicationHost } from './application-host.js';
|
|
3
4
|
import { ContainerProvider } from '../container/index.js';
|
|
4
5
|
export { container } from '../container/dynamic-container.js';
|
|
6
|
+
const host = ApplicationHost.get();
|
|
5
7
|
(async () => {
|
|
8
|
+
var _a;
|
|
6
9
|
const c = await container;
|
|
7
10
|
try {
|
|
8
11
|
ContainerProvider.provide();
|
|
@@ -12,12 +15,27 @@ export { container } from '../container/dynamic-container.js';
|
|
|
12
15
|
// NoOp
|
|
13
16
|
}
|
|
14
17
|
ContainerProvider.set(c);
|
|
18
|
+
await ((_a = host === null || host === void 0 ? void 0 : host.beforeStart) === null || _a === void 0 ? void 0 : _a.call(host));
|
|
15
19
|
const application = c.get(Application);
|
|
16
|
-
|
|
20
|
+
try {
|
|
21
|
+
await application.start();
|
|
22
|
+
host === null || host === void 0 ? void 0 : host.started({ container: c, stop: () => application.stop() });
|
|
23
|
+
}
|
|
24
|
+
catch (reason) {
|
|
25
|
+
if (host) {
|
|
26
|
+
host.failed(reason);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
17
29
|
console.error(`Failed to start the ${application.constructor.name}.`);
|
|
18
30
|
if (reason) {
|
|
19
31
|
console.error(reason);
|
|
20
32
|
}
|
|
21
|
-
}
|
|
22
|
-
})()
|
|
33
|
+
}
|
|
34
|
+
})().catch(error => {
|
|
35
|
+
// The container failed to load (a DI module threw): stop, or tell the host.
|
|
36
|
+
if (!host) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
host.failed(error);
|
|
40
|
+
});
|
|
23
41
|
//# sourceMappingURL=application-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-entry.js","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,CAAC,KAAK,IAAI,EAAE
|
|
1
|
+
{"version":3,"file":"application-entry.js","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,EAAE,CAAC;AAEnC,CAAC,KAAK,IAAI,EAAE;;IACR,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC;IAC1B,IAAI,CAAC;QACD,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;IACX,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,OAAM,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,+CAAjB,IAAI,CAAiB,CAAA,CAAC;IAC5B,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,CAAc,WAAW,CAAC,CAAC;IACpD,IAAI,CAAC;QACD,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QACd,IAAI,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACpB,OAAO;QACX,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,uBAAuB,WAAW,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC;QACtE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;AACL,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACf,4EAA4E;IAC5E,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,MAAM,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an application entry reports to the process that loaded it, instead of listening on a port.
|
|
3
|
+
* `handler` is the HTTP request handler, `server` the server it is attached to (when the host has one).
|
|
4
|
+
*/
|
|
5
|
+
export interface StartedApplication {
|
|
6
|
+
/** The DI container of the application. */
|
|
7
|
+
container: unknown;
|
|
8
|
+
/** Node.js `(req, res)` handler of HTTP entries. */
|
|
9
|
+
handler?: (req: any, res: any, next?: (error?: unknown) => void) => void;
|
|
10
|
+
/** Stops the application: lifecycle `onStop` hooks, timers, connections. */
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A process that runs the application in-process: `cell dev` (one port with Vite) and tests. When a
|
|
15
|
+
* host is set, entries hand over their request handler with {@link started} instead of listening.
|
|
16
|
+
*/
|
|
17
|
+
export interface ApplicationHost {
|
|
18
|
+
/** The HTTP server requests come from; passed to `ServerAware` components (WebSocket and the like). */
|
|
19
|
+
readonly server?: unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Called once the DI container is loaded, before the application starts; the application starts
|
|
22
|
+
* when the returned promise resolves. Cloudflare Workers allow code generation (`new Function`)
|
|
23
|
+
* only while modules load and I/O only while a request is handled, so the worker loads the
|
|
24
|
+
* modules at startup and starts the application on the first request.
|
|
25
|
+
*/
|
|
26
|
+
beforeStart?(): Promise<void>;
|
|
27
|
+
started(application: StartedApplication): void;
|
|
28
|
+
failed(error: unknown): void;
|
|
29
|
+
}
|
|
30
|
+
export declare namespace ApplicationHost {
|
|
31
|
+
/**
|
|
32
|
+
* A global symbol: the host is set by the toolchain, which does not share module instances with
|
|
33
|
+
* the application it loads (a Vite module runner, a bundle).
|
|
34
|
+
*/
|
|
35
|
+
const KEY: unique symbol;
|
|
36
|
+
function get(): ApplicationHost | undefined;
|
|
37
|
+
function set(host: ApplicationHost | undefined): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var ApplicationHost;
|
|
2
|
+
(function (ApplicationHost) {
|
|
3
|
+
/**
|
|
4
|
+
* A global symbol: the host is set by the toolchain, which does not share module instances with
|
|
5
|
+
* the application it loads (a Vite module runner, a bundle).
|
|
6
|
+
*/
|
|
7
|
+
ApplicationHost.KEY = Symbol.for('@celljs/core/application-host');
|
|
8
|
+
function get() {
|
|
9
|
+
return globalThis[ApplicationHost.KEY];
|
|
10
|
+
}
|
|
11
|
+
ApplicationHost.get = get;
|
|
12
|
+
function set(host) {
|
|
13
|
+
globalThis[ApplicationHost.KEY] = host;
|
|
14
|
+
}
|
|
15
|
+
ApplicationHost.set = set;
|
|
16
|
+
})(ApplicationHost || (ApplicationHost = {}));
|
|
17
|
+
//# sourceMappingURL=application-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-host.js","sourceRoot":"","sources":["../../../src/common/application/application-host.ts"],"names":[],"mappings":"AA+BA,MAAM,KAAW,eAAe,CAc/B;AAdD,WAAiB,eAAe;IAC5B;;;OAGG;IACU,mBAAG,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE/D,SAAgB,GAAG;QACf,OAAQ,UAA0D,CAAC,mBAAG,CAAC,CAAC;IAC5E,CAAC;IAFe,gBAAA,GAAG,MAElB,CAAA;IAED,SAAgB,GAAG,CAAC,IAAiC;QAChD,UAA0D,CAAC,mBAAG,CAAC,GAAG,IAAI,CAAC;IAC5E,CAAC;IAFe,gBAAA,GAAG,MAElB,CAAA;AACL,CAAC,EAdgB,eAAe,KAAf,eAAe,QAc/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** An environment variable that was applied to the configuration. */
|
|
2
|
+
export interface EnvOverride {
|
|
3
|
+
variable: string;
|
|
4
|
+
/** Dotted path of the overridden key, e.g. `cell.server.port`. */
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* Set when the first key also exists under `cell`: the top-level key wins, and this is the path
|
|
8
|
+
* under `cell` that the variable does not set (reach it with `CELL_<TARGET>__CELL__...`).
|
|
9
|
+
*/
|
|
10
|
+
shadows?: string;
|
|
11
|
+
}
|
|
12
|
+
/** An environment variable with the override prefix that could not be applied. */
|
|
13
|
+
export interface EnvOverrideProblem {
|
|
14
|
+
variable: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
export interface EnvOverrideResult {
|
|
18
|
+
applied: EnvOverride[];
|
|
19
|
+
problems: EnvOverrideProblem[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Overrides configuration keys from environment variables: `CELL_BACKEND__SERVER__PORT=8080` sets
|
|
23
|
+
* `cell.server.port` of the backend. Segments are separated by `__` and matched against existing
|
|
24
|
+
* keys ignoring case, `_` and `-` (`ORM_CONFIG` matches `ormConfig`, `SERVE_STATIC` matches
|
|
25
|
+
* `serve-static`); array items are addressed by canonical index. The first key is looked up at the
|
|
26
|
+
* top level, then under `cell`, so `SERVER__PORT` is short for `CELL__SERVER__PORT` unless the
|
|
27
|
+
* project has a top-level `server` of its own; `CELL__...` always means `cell`.
|
|
28
|
+
*
|
|
29
|
+
* Only existing keys can be overridden, so a misspelled variable is reported instead of silently
|
|
30
|
+
* ignored. Each key is set by one variable at most: variables that set the same key, or a key and
|
|
31
|
+
* one inside it, are all reported and none applies, whatever their order. The value is converted to
|
|
32
|
+
* the type of the value it replaces (a finite number in JSON syntax, `true` / `false`, JSON for
|
|
33
|
+
* objects and arrays, JSON or text where cell.yml has `null`, text for strings); a value that is one
|
|
34
|
+
* `${...}` expression is kept and evaluated like cell.yml. Overrides land before `${...}`
|
|
35
|
+
* expressions are evaluated, so references such as `${cell.server.port}` see the new value. The
|
|
36
|
+
* backend applies its variables at startup; the frontend applies them when it is built.
|
|
37
|
+
*/
|
|
38
|
+
export declare namespace EnvConfigUtil {
|
|
39
|
+
const PREFIXES: {
|
|
40
|
+
readonly backend: 'CELL_BACKEND__';
|
|
41
|
+
readonly frontend: 'CELL_FRONTEND__';
|
|
42
|
+
};
|
|
43
|
+
type Target = keyof typeof PREFIXES;
|
|
44
|
+
/** Applies the variables of `target` in `env` to `config` in place. */
|
|
45
|
+
function apply(config: Record<string, any>, env: Record<string, string | undefined>, target: Target): EnvOverrideResult;
|
|
46
|
+
/** Applies the backend variables of `process.env` and warns about the ones that do not apply. */
|
|
47
|
+
function applyProcessEnv(config: Record<string, any>): EnvOverrideResult;
|
|
48
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overrides configuration keys from environment variables: `CELL_BACKEND__SERVER__PORT=8080` sets
|
|
3
|
+
* `cell.server.port` of the backend. Segments are separated by `__` and matched against existing
|
|
4
|
+
* keys ignoring case, `_` and `-` (`ORM_CONFIG` matches `ormConfig`, `SERVE_STATIC` matches
|
|
5
|
+
* `serve-static`); array items are addressed by canonical index. The first key is looked up at the
|
|
6
|
+
* top level, then under `cell`, so `SERVER__PORT` is short for `CELL__SERVER__PORT` unless the
|
|
7
|
+
* project has a top-level `server` of its own; `CELL__...` always means `cell`.
|
|
8
|
+
*
|
|
9
|
+
* Only existing keys can be overridden, so a misspelled variable is reported instead of silently
|
|
10
|
+
* ignored. Each key is set by one variable at most: variables that set the same key, or a key and
|
|
11
|
+
* one inside it, are all reported and none applies, whatever their order. The value is converted to
|
|
12
|
+
* the type of the value it replaces (a finite number in JSON syntax, `true` / `false`, JSON for
|
|
13
|
+
* objects and arrays, JSON or text where cell.yml has `null`, text for strings); a value that is one
|
|
14
|
+
* `${...}` expression is kept and evaluated like cell.yml. Overrides land before `${...}`
|
|
15
|
+
* expressions are evaluated, so references such as `${cell.server.port}` see the new value. The
|
|
16
|
+
* backend applies its variables at startup; the frontend applies them when it is built.
|
|
17
|
+
*/
|
|
18
|
+
export var EnvConfigUtil;
|
|
19
|
+
(function (EnvConfigUtil) {
|
|
20
|
+
EnvConfigUtil.PREFIXES = { backend: 'CELL_BACKEND__', frontend: 'CELL_FRONTEND__' };
|
|
21
|
+
/** Applies the variables of `target` in `env` to `config` in place. */
|
|
22
|
+
function apply(config, env, target) {
|
|
23
|
+
const result = { applied: [], problems: [] };
|
|
24
|
+
const prefix = EnvConfigUtil.PREFIXES[target];
|
|
25
|
+
const resolved = [];
|
|
26
|
+
for (const variable of Object.keys(env).filter(name => name.startsWith(prefix)).sort()) {
|
|
27
|
+
const value = env[variable];
|
|
28
|
+
if (value === undefined) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
resolved.push({ variable, value, ...resolve(config, variable.slice(prefix.length).split('__')) });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
result.problems.push({ variable, message: error.message });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Paths are resolved against cell.yml before anything changes, so the outcome never depends on the order of the variables.
|
|
39
|
+
for (const entry of resolved) {
|
|
40
|
+
const path = entry.keys.join('.');
|
|
41
|
+
const others = resolved.filter(other => other !== entry && overlaps(entry.keys, other.keys));
|
|
42
|
+
if (others.length > 0) {
|
|
43
|
+
const list = others.map(other => `${other.variable} (${other.keys.join('.')})`).join(', ');
|
|
44
|
+
result.problems.push({ variable: entry.variable, message: `sets ${path}, which ${list} also set${others.length === 1 ? 's' : ''}. Set each key with one variable; to change items of an object or array you replace, write them into its JSON.` });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
assign(config, entry.keys, entry.value);
|
|
49
|
+
result.applied.push({ variable: entry.variable, path, ...(entry.shadows ? { shadows: entry.shadows } : {}) });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
result.problems.push({ variable: entry.variable, message: error.message });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
result.problems.sort((x, y) => (x.variable < y.variable ? -1 : x.variable > y.variable ? 1 : 0));
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
EnvConfigUtil.apply = apply;
|
|
59
|
+
/** Applies the backend variables of `process.env` and warns about the ones that do not apply. */
|
|
60
|
+
function applyProcessEnv(config) {
|
|
61
|
+
const result = apply(config, process.env, 'backend');
|
|
62
|
+
for (const problem of result.problems) {
|
|
63
|
+
console.warn(`[cell] ${problem.variable} is ignored: ${problem.message}`);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
EnvConfigUtil.applyProcessEnv = applyProcessEnv;
|
|
68
|
+
/** The same key, or one inside the other. */
|
|
69
|
+
function overlaps(a, b) {
|
|
70
|
+
const length = Math.min(a.length, b.length);
|
|
71
|
+
return a.slice(0, length).every((key, i) => key === b[i]);
|
|
72
|
+
}
|
|
73
|
+
function resolve(config, segments) {
|
|
74
|
+
if (segments.some(segment => !segment)) {
|
|
75
|
+
throw new Error('empty segment; separate keys with exactly two underscores.');
|
|
76
|
+
}
|
|
77
|
+
const cell = config.cell && typeof config.cell === 'object' ? config.cell : undefined;
|
|
78
|
+
const top = find(config, segments[0]);
|
|
79
|
+
const inCell = cell ? find(cell, segments[0]) : undefined;
|
|
80
|
+
if (top === undefined && inCell === undefined) {
|
|
81
|
+
const cellKeys = cell ? ` or under cell (keys: ${Object.keys(cell).join(', ') || '(none)'})` : '';
|
|
82
|
+
throw new Error(`no key '${segments[0]}' at the top level (keys: ${Object.keys(config).join(', ') || '(none)'})${cellKeys}. Only keys present in cell.yml can be overridden.`);
|
|
83
|
+
}
|
|
84
|
+
const keys = top === undefined ? ['cell'] : [];
|
|
85
|
+
const shadows = top !== undefined && inCell !== undefined && top !== 'cell' ? `cell.${inCell}` : undefined;
|
|
86
|
+
let node = top === undefined ? cell : config;
|
|
87
|
+
for (let i = 0; i < segments.length; i++) {
|
|
88
|
+
const key = find(node, segments[i]);
|
|
89
|
+
if (key === undefined) {
|
|
90
|
+
const where = keys.length > 0 ? keys.join('.') : 'the top level';
|
|
91
|
+
const available = Array.isArray(node) ? `indexes 0-${node.length - 1}` : `keys: ${Object.keys(node).join(', ') || '(none)'}`;
|
|
92
|
+
throw new Error(`no key '${segments[i]}' under ${where} (${available}). Only keys present in cell.yml can be overridden.`);
|
|
93
|
+
}
|
|
94
|
+
keys.push(key);
|
|
95
|
+
if (i < segments.length - 1) {
|
|
96
|
+
if (!node[key] || typeof node[key] !== 'object') {
|
|
97
|
+
throw new Error(`${keys.join('.')} is not an object, so it has no key '${segments[i + 1]}'.`);
|
|
98
|
+
}
|
|
99
|
+
node = node[key];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { keys, ...(shadows ? { shadows } : {}) };
|
|
103
|
+
}
|
|
104
|
+
function assign(config, keys, value) {
|
|
105
|
+
const parent = keys.slice(0, -1).reduce((node, key) => node[key], config);
|
|
106
|
+
const last = keys[keys.length - 1];
|
|
107
|
+
parent[last] = convert(parent[last], value, keys.join('.'));
|
|
108
|
+
}
|
|
109
|
+
function find(node, segment) {
|
|
110
|
+
var _a;
|
|
111
|
+
if (Array.isArray(node)) {
|
|
112
|
+
// Canonical indexes only: '08' would set a property named '08', not item 8.
|
|
113
|
+
return /^(0|[1-9]\d*)$/.test(segment) && Number(segment) < node.length ? segment : undefined;
|
|
114
|
+
}
|
|
115
|
+
const wanted = normalize(segment);
|
|
116
|
+
const keys = Object.keys(node);
|
|
117
|
+
return (_a = keys.find(key => key === segment)) !== null && _a !== void 0 ? _a : keys.find(key => normalize(key) === wanted);
|
|
118
|
+
}
|
|
119
|
+
function normalize(key) {
|
|
120
|
+
return key.replace(/[-_]/g, '').toLowerCase();
|
|
121
|
+
}
|
|
122
|
+
/** JSON number syntax: `Number()` would also take '', 'Infinity', '0x10' and ' 8 '. */
|
|
123
|
+
const NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/;
|
|
124
|
+
/** A value that is one `${...}` expression and nothing else. */
|
|
125
|
+
function isExpression(value) {
|
|
126
|
+
return value.startsWith('${') && value.endsWith('}') && value.indexOf('${', 2) === -1;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Converts `value` to the type of `current`, the value in cell.yml. A value that is one `${...}`
|
|
130
|
+
* expression is kept for evaluation, as if written in cell.yml, so its result decides the type:
|
|
131
|
+
* `CELL_BACKEND__SERVER__PORT='${env.PORT}'` works although the port is a number.
|
|
132
|
+
*/
|
|
133
|
+
function convert(current, value, path) {
|
|
134
|
+
if (isExpression(value)) {
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
switch (typeof current) {
|
|
138
|
+
case 'number':
|
|
139
|
+
return number(value, path);
|
|
140
|
+
case 'boolean':
|
|
141
|
+
if (!/^(true|false)$/i.test(value)) {
|
|
142
|
+
throw new Error(`${path} is a boolean, got '${value}'. Use true or false.`);
|
|
143
|
+
}
|
|
144
|
+
return value.toLowerCase() === 'true';
|
|
145
|
+
case 'object':
|
|
146
|
+
if (current === null) {
|
|
147
|
+
// No type to follow: JSON when it is JSON (null, 5, true, "x", [], {}), else the text.
|
|
148
|
+
const parsed = parse(value);
|
|
149
|
+
return parsed ? parsed.value : value;
|
|
150
|
+
}
|
|
151
|
+
return json(current, value, path);
|
|
152
|
+
default:
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function number(value, path) {
|
|
157
|
+
const result = NUMBER.test(value) ? Number(value) : NaN;
|
|
158
|
+
if (!Number.isFinite(result)) {
|
|
159
|
+
throw new Error(`${path} is a number, got '${value}'. Use a decimal number such as 8080, -1 or 0.5.`);
|
|
160
|
+
}
|
|
161
|
+
// An integer literal past 2^53 would silently become a different number.
|
|
162
|
+
if (/^-?\d+$/.test(value) && !Number.isSafeInteger(result)) {
|
|
163
|
+
throw new Error(`${path} is a number, got '${value}', which is too large to keep exactly. Use a string in cell.yml for such values.`);
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
function json(current, value, path) {
|
|
168
|
+
var _a;
|
|
169
|
+
const kind = Array.isArray(current) ? 'an array' : 'an object';
|
|
170
|
+
const parsed = (_a = parse(value)) === null || _a === void 0 ? void 0 : _a.value;
|
|
171
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed) !== Array.isArray(current)) {
|
|
172
|
+
throw new Error(`${path} is ${kind}; pass it as JSON, or override its keys one by one.`);
|
|
173
|
+
}
|
|
174
|
+
return parsed;
|
|
175
|
+
}
|
|
176
|
+
function parse(value) {
|
|
177
|
+
try {
|
|
178
|
+
return { value: JSON.parse(value) };
|
|
179
|
+
}
|
|
180
|
+
catch (_a) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
})(EnvConfigUtil || (EnvConfigUtil = {}));
|
|
185
|
+
//# sourceMappingURL=env-config-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-config-util.js","sourceRoot":"","sources":["../../../src/common/config/env-config-util.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,KAAW,aAAa,CAwL7B;AAxLD,WAAiB,aAAa;IAEb,sBAAQ,GAAG,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,EAAW,CAAC;IAY5F,uEAAuE;IACvE,SAAgB,KAAK,CAAC,MAA2B,EAAE,GAAuC,EAAE,MAAc;QACtG,MAAM,MAAM,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QAChE,MAAM,MAAM,GAAG,sBAAQ,CAAC,MAAM,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAe,EAAE,CAAC;QAChC,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACrF,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC5B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtB,SAAS;YACb,CAAC;YACD,IAAI,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC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,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACpG,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,OAAO,IAAI,qDAAqD,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,SAAS,KAAK,CAAC,KAAa;QACxB,IAAI,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,CAAC;mBAAO,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;AACL,CAAC,EAxLgB,aAAa,KAAb,aAAa,QAwL7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-entry.d.ts","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application-entry.d.ts","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.container = void 0;
|
|
4
4
|
const dynamic_container_1 = require("../container/dynamic-container");
|
|
5
5
|
const application_protocol_1 = require("./application-protocol");
|
|
6
|
+
const application_host_1 = require("./application-host");
|
|
6
7
|
const container_1 = require("../container");
|
|
7
8
|
var dynamic_container_2 = require("../container/dynamic-container");
|
|
8
9
|
Object.defineProperty(exports, "container", { enumerable: true, get: function () { return dynamic_container_2.container; } });
|
|
10
|
+
const host = application_host_1.ApplicationHost.get();
|
|
9
11
|
(async () => {
|
|
12
|
+
var _a;
|
|
10
13
|
const c = await dynamic_container_1.container;
|
|
11
14
|
try {
|
|
12
15
|
container_1.ContainerProvider.provide();
|
|
@@ -16,12 +19,27 @@ Object.defineProperty(exports, "container", { enumerable: true, get: function ()
|
|
|
16
19
|
// NoOp
|
|
17
20
|
}
|
|
18
21
|
container_1.ContainerProvider.set(c);
|
|
22
|
+
await ((_a = host === null || host === void 0 ? void 0 : host.beforeStart) === null || _a === void 0 ? void 0 : _a.call(host));
|
|
19
23
|
const application = c.get(application_protocol_1.Application);
|
|
20
|
-
|
|
24
|
+
try {
|
|
25
|
+
await application.start();
|
|
26
|
+
host === null || host === void 0 ? void 0 : host.started({ container: c, stop: () => application.stop() });
|
|
27
|
+
}
|
|
28
|
+
catch (reason) {
|
|
29
|
+
if (host) {
|
|
30
|
+
host.failed(reason);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
21
33
|
console.error(`Failed to start the ${application.constructor.name}.`);
|
|
22
34
|
if (reason) {
|
|
23
35
|
console.error(reason);
|
|
24
36
|
}
|
|
25
|
-
}
|
|
26
|
-
})()
|
|
37
|
+
}
|
|
38
|
+
})().catch(error => {
|
|
39
|
+
// The container failed to load (a DI module threw): stop, or tell the host.
|
|
40
|
+
if (!host) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
host.failed(error);
|
|
44
|
+
});
|
|
27
45
|
//# sourceMappingURL=application-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-entry.js","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":";;;AAAA,sEAA2D;AAC3D,iEAAqD;AACrD,4CAAiD;AACjD,oEAA2D;AAAlD,8GAAA,SAAS,OAAA;AAElB,CAAC,KAAK,IAAI,EAAE
|
|
1
|
+
{"version":3,"file":"application-entry.js","sourceRoot":"","sources":["../../../src/common/application/application-entry.ts"],"names":[],"mappings":";;;AAAA,sEAA2D;AAC3D,iEAAqD;AACrD,yDAAqD;AACrD,4CAAiD;AACjD,oEAA2D;AAAlD,8GAAA,SAAS,OAAA;AAElB,MAAM,IAAI,GAAG,kCAAe,CAAC,GAAG,EAAE,CAAC;AAEnC,CAAC,KAAK,IAAI,EAAE;;IACR,MAAM,CAAC,GAAG,MAAM,6BAAS,CAAC;IAC1B,IAAI,CAAC;QACD,6BAAiB,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;IACX,CAAC;IACD,6BAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,OAAM,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,+CAAjB,IAAI,CAAiB,CAAA,CAAC;IAC5B,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,CAAc,kCAAW,CAAC,CAAC;IACpD,IAAI,CAAC;QACD,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QACd,IAAI,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACpB,OAAO;QACX,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,uBAAuB,WAAW,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC;QACtE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;AACL,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACf,4EAA4E;IAC5E,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,MAAM,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an application entry reports to the process that loaded it, instead of listening on a port.
|
|
3
|
+
* `handler` is the HTTP request handler, `server` the server it is attached to (when the host has one).
|
|
4
|
+
*/
|
|
5
|
+
export interface StartedApplication {
|
|
6
|
+
/** The DI container of the application. */
|
|
7
|
+
container: unknown;
|
|
8
|
+
/** Node.js `(req, res)` handler of HTTP entries. */
|
|
9
|
+
handler?: (req: any, res: any, next?: (error?: unknown) => void) => void;
|
|
10
|
+
/** Stops the application: lifecycle `onStop` hooks, timers, connections. */
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A process that runs the application in-process: `cell dev` (one port with Vite) and tests. When a
|
|
15
|
+
* host is set, entries hand over their request handler with {@link started} instead of listening.
|
|
16
|
+
*/
|
|
17
|
+
export interface ApplicationHost {
|
|
18
|
+
/** The HTTP server requests come from; passed to `ServerAware` components (WebSocket and the like). */
|
|
19
|
+
readonly server?: unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Called once the DI container is loaded, before the application starts; the application starts
|
|
22
|
+
* when the returned promise resolves. Cloudflare Workers allow code generation (`new Function`)
|
|
23
|
+
* only while modules load and I/O only while a request is handled, so the worker loads the
|
|
24
|
+
* modules at startup and starts the application on the first request.
|
|
25
|
+
*/
|
|
26
|
+
beforeStart?(): Promise<void>;
|
|
27
|
+
started(application: StartedApplication): void;
|
|
28
|
+
failed(error: unknown): void;
|
|
29
|
+
}
|
|
30
|
+
export declare namespace ApplicationHost {
|
|
31
|
+
/**
|
|
32
|
+
* A global symbol: the host is set by the toolchain, which does not share module instances with
|
|
33
|
+
* the application it loads (a Vite module runner, a bundle).
|
|
34
|
+
*/
|
|
35
|
+
const KEY: unique symbol;
|
|
36
|
+
function get(): ApplicationHost | undefined;
|
|
37
|
+
function set(host: ApplicationHost | undefined): void;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=application-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-host.d.ts","sourceRoot":"","sources":["../../../src/common/application/application-host.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;IACnB,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI,CAAC;IACzE,4EAA4E;IAC5E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,WAAW,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC/C,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAED,yBAAiB,eAAe,CAAC;IAC7B;;;OAGG;IACI,MAAM,GAAG,eAA8C,CAAC;IAE/D,SAAgB,GAAG,IAAI,eAAe,GAAG,SAAS,CAEjD;IAED,SAAgB,GAAG,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAE3D;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationHost = void 0;
|
|
4
|
+
var ApplicationHost;
|
|
5
|
+
(function (ApplicationHost) {
|
|
6
|
+
/**
|
|
7
|
+
* A global symbol: the host is set by the toolchain, which does not share module instances with
|
|
8
|
+
* the application it loads (a Vite module runner, a bundle).
|
|
9
|
+
*/
|
|
10
|
+
ApplicationHost.KEY = Symbol.for('@celljs/core/application-host');
|
|
11
|
+
function get() {
|
|
12
|
+
return globalThis[ApplicationHost.KEY];
|
|
13
|
+
}
|
|
14
|
+
ApplicationHost.get = get;
|
|
15
|
+
function set(host) {
|
|
16
|
+
globalThis[ApplicationHost.KEY] = host;
|
|
17
|
+
}
|
|
18
|
+
ApplicationHost.set = set;
|
|
19
|
+
})(ApplicationHost || (exports.ApplicationHost = ApplicationHost = {}));
|
|
20
|
+
//# sourceMappingURL=application-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-host.js","sourceRoot":"","sources":["../../../src/common/application/application-host.ts"],"names":[],"mappings":";;;AA+BA,IAAiB,eAAe,CAc/B;AAdD,WAAiB,eAAe;IAC5B;;;OAGG;IACU,mBAAG,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE/D,SAAgB,GAAG;QACf,OAAQ,UAA0D,CAAC,mBAAG,CAAC,CAAC;IAC5E,CAAC;IAFe,gBAAA,GAAG,MAElB,CAAA;IAED,SAAgB,GAAG,CAAC,IAAiC;QAChD,UAA0D,CAAC,mBAAG,CAAC,GAAG,IAAI,CAAC;IAC5E,CAAC;IAFe,gBAAA,GAAG,MAElB,CAAA;AACL,CAAC,EAdgB,eAAe,aAAf,eAAe,GAAf,eAAe,QAc/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./application-protocol"), exports);
|
|
18
18
|
__exportStar(require("./application-error"), exports);
|
|
19
|
+
__exportStar(require("./application-host"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,sDAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/application/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,sDAAoC;AACpC,qDAAmC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** An environment variable that was applied to the configuration. */
|
|
2
|
+
export interface EnvOverride {
|
|
3
|
+
variable: string;
|
|
4
|
+
/** Dotted path of the overridden key, e.g. `cell.server.port`. */
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* Set when the first key also exists under `cell`: the top-level key wins, and this is the path
|
|
8
|
+
* under `cell` that the variable does not set (reach it with `CELL_<TARGET>__CELL__...`).
|
|
9
|
+
*/
|
|
10
|
+
shadows?: string;
|
|
11
|
+
}
|
|
12
|
+
/** An environment variable with the override prefix that could not be applied. */
|
|
13
|
+
export interface EnvOverrideProblem {
|
|
14
|
+
variable: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
export interface EnvOverrideResult {
|
|
18
|
+
applied: EnvOverride[];
|
|
19
|
+
problems: EnvOverrideProblem[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Overrides configuration keys from environment variables: `CELL_BACKEND__SERVER__PORT=8080` sets
|
|
23
|
+
* `cell.server.port` of the backend. Segments are separated by `__` and matched against existing
|
|
24
|
+
* keys ignoring case, `_` and `-` (`ORM_CONFIG` matches `ormConfig`, `SERVE_STATIC` matches
|
|
25
|
+
* `serve-static`); array items are addressed by canonical index. The first key is looked up at the
|
|
26
|
+
* top level, then under `cell`, so `SERVER__PORT` is short for `CELL__SERVER__PORT` unless the
|
|
27
|
+
* project has a top-level `server` of its own; `CELL__...` always means `cell`.
|
|
28
|
+
*
|
|
29
|
+
* Only existing keys can be overridden, so a misspelled variable is reported instead of silently
|
|
30
|
+
* ignored. Each key is set by one variable at most: variables that set the same key, or a key and
|
|
31
|
+
* one inside it, are all reported and none applies, whatever their order. The value is converted to
|
|
32
|
+
* the type of the value it replaces (a finite number in JSON syntax, `true` / `false`, JSON for
|
|
33
|
+
* objects and arrays, JSON or text where cell.yml has `null`, text for strings); a value that is one
|
|
34
|
+
* `${...}` expression is kept and evaluated like cell.yml. Overrides land before `${...}`
|
|
35
|
+
* expressions are evaluated, so references such as `${cell.server.port}` see the new value. The
|
|
36
|
+
* backend applies its variables at startup; the frontend applies them when it is built.
|
|
37
|
+
*/
|
|
38
|
+
export declare namespace EnvConfigUtil {
|
|
39
|
+
const PREFIXES: {
|
|
40
|
+
readonly backend: 'CELL_BACKEND__';
|
|
41
|
+
readonly frontend: 'CELL_FRONTEND__';
|
|
42
|
+
};
|
|
43
|
+
type Target = keyof typeof PREFIXES;
|
|
44
|
+
/** Applies the variables of `target` in `env` to `config` in place. */
|
|
45
|
+
function apply(config: Record<string, any>, env: Record<string, string | undefined>, target: Target): EnvOverrideResult;
|
|
46
|
+
/** Applies the backend variables of `process.env` and warns about the ones that do not apply. */
|
|
47
|
+
function applyProcessEnv(config: Record<string, any>): EnvOverrideResult;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=env-config-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-config-util.d.ts","sourceRoot":"","sources":["../../../src/common/config/env-config-util.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,yBAAiB,aAAa,CAAC;IAEpB,MAAM,QAAQ;iBAAK,OAAO,EAAE,gBAAgB;iBAAE,QAAQ,EAAE,iBAAiB;KAAW,CAAC;IAE5F,KAAY,MAAM,GAAG,MAAM,OAAO,QAAQ,CAAC;IAU3C,uEAAuE;IACvE,SAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAiC7H;IAED,iGAAiG;IACjG,SAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAM9E;CA+HJ"}
|