@tramvai/module-environment 5.5.4 → 5.6.2
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.
|
@@ -18,9 +18,9 @@ class EnvironmentManagerServer extends EnvironmentManager {
|
|
|
18
18
|
constructor(tokens, templates = []) {
|
|
19
19
|
super();
|
|
20
20
|
this.tokens = tokens;
|
|
21
|
-
this.templates = templates.reduce((acc, { key, fn }) => {
|
|
21
|
+
this.templates = templates.reduce((acc, { key, fn, validator }) => {
|
|
22
22
|
// TODO: key duplicates?
|
|
23
|
-
acc[key] = fn;
|
|
23
|
+
acc[key] = { fn, validator };
|
|
24
24
|
return acc;
|
|
25
25
|
}, {});
|
|
26
26
|
this.processing();
|
|
@@ -26,9 +26,9 @@ class EnvironmentManagerServer extends EnvironmentManager.EnvironmentManager {
|
|
|
26
26
|
constructor(tokens, templates = []) {
|
|
27
27
|
super();
|
|
28
28
|
this.tokens = tokens;
|
|
29
|
-
this.templates = templates.reduce((acc, { key, fn }) => {
|
|
29
|
+
this.templates = templates.reduce((acc, { key, fn, validator }) => {
|
|
30
30
|
// TODO: key duplicates?
|
|
31
|
-
acc[key] = fn;
|
|
31
|
+
acc[key] = { fn, validator };
|
|
32
32
|
return acc;
|
|
33
33
|
}, {});
|
|
34
34
|
this.processing();
|
package/lib/shared/template.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { EnvTemplate } from '@tramvai/tokens-common';
|
|
2
|
-
export type Templates = Record<string,
|
|
2
|
+
export type Templates = Record<string, {
|
|
3
|
+
fn: EnvTemplate['fn'];
|
|
4
|
+
validator: EnvTemplate['validator'];
|
|
5
|
+
}>;
|
|
3
6
|
export declare function interpolate({ envKey, envValue, templates, }: {
|
|
4
7
|
envKey: string;
|
|
5
8
|
envValue: string | undefined;
|
|
@@ -7,11 +7,15 @@ function interpolate({ envKey, envValue, templates, }) {
|
|
|
7
7
|
}
|
|
8
8
|
return envValue.replace(templateRegex, (templateRaw, templateStr) => {
|
|
9
9
|
// expect string in `key:param1,param2` format
|
|
10
|
-
const [key,
|
|
10
|
+
const [key, ...rest] = templateStr.split(':');
|
|
11
|
+
const paramsRaw = rest.join('');
|
|
11
12
|
const params = paramsRaw.split(',').filter(Boolean);
|
|
12
13
|
const template = templates[key];
|
|
13
14
|
if (template) {
|
|
14
|
-
|
|
15
|
+
if (template.validator) {
|
|
16
|
+
template.validator(envKey, params);
|
|
17
|
+
}
|
|
18
|
+
return template.fn(...params);
|
|
15
19
|
}
|
|
16
20
|
throw Error(`Problem with "${envKey}=${originalValue}" env variable - template for ${templateRaw} not found.`);
|
|
17
21
|
});
|
package/lib/shared/template.js
CHANGED
|
@@ -11,11 +11,15 @@ function interpolate({ envKey, envValue, templates, }) {
|
|
|
11
11
|
}
|
|
12
12
|
return envValue.replace(templateRegex, (templateRaw, templateStr) => {
|
|
13
13
|
// expect string in `key:param1,param2` format
|
|
14
|
-
const [key,
|
|
14
|
+
const [key, ...rest] = templateStr.split(':');
|
|
15
|
+
const paramsRaw = rest.join('');
|
|
15
16
|
const params = paramsRaw.split(',').filter(Boolean);
|
|
16
17
|
const template = templates[key];
|
|
17
18
|
if (template) {
|
|
18
|
-
|
|
19
|
+
if (template.validator) {
|
|
20
|
+
template.validator(envKey, params);
|
|
21
|
+
}
|
|
22
|
+
return template.fn(...params);
|
|
19
23
|
}
|
|
20
24
|
throw Error(`Problem with "${envKey}=${originalValue}" env variable - template for ${templateRaw} not found.`);
|
|
21
25
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-environment",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@tinkoff/utils": "^2.1.2",
|
|
22
|
-
"@tramvai/core": "5.
|
|
23
|
-
"@tramvai/papi": "5.
|
|
24
|
-
"@tramvai/state": "5.
|
|
25
|
-
"@tramvai/tokens-common": "5.
|
|
26
|
-
"@tramvai/tokens-server": "5.
|
|
22
|
+
"@tramvai/core": "5.6.2",
|
|
23
|
+
"@tramvai/papi": "5.6.2",
|
|
24
|
+
"@tramvai/state": "5.6.2",
|
|
25
|
+
"@tramvai/tokens-common": "5.6.2",
|
|
26
|
+
"@tramvai/tokens-server": "5.6.2",
|
|
27
27
|
"@tinkoff/dippy": "0.11.3",
|
|
28
28
|
"react": ">=16.14.0",
|
|
29
29
|
"react-dom": ">=16.14.0",
|