@travetto/config 7.1.4 → 8.0.0-alpha.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 +3 -2
- package/package.json +3 -3
- package/src/decorator.ts +1 -1
- package/src/parser/json.ts +1 -1
- package/src/parser/parser.ts +2 -2
- package/src/parser/properties.ts +1 -1
- package/src/service.ts +5 -5
- package/src/source/env.ts +1 -1
- package/src/source/override.ts +1 -1
- /package/src/{util.ts → override.ts} +0 -0
package/README.md
CHANGED
|
@@ -146,7 +146,7 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
146
146
|
|
|
147
147
|
get(): ConfigPayload | undefined {
|
|
148
148
|
try {
|
|
149
|
-
const data: Record<string, unknown> = JSONUtil.
|
|
149
|
+
const data: Record<string, unknown> = JSONUtil.fromUTF8(process.env[this.#envKey] || '{}');
|
|
150
150
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
151
151
|
} catch {
|
|
152
152
|
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
|
@@ -209,10 +209,11 @@ You can see that the `DBConfig` allows for the `port` to be overridden by the `D
|
|
|
209
209
|
$ trv main doc/dbconfig-run.ts
|
|
210
210
|
|
|
211
211
|
{
|
|
212
|
+
'$trv': 'runtime',
|
|
212
213
|
message: 'Failed to construct @travetto/config:doc/dbconfig#DBConfig as validation errors have occurred',
|
|
213
214
|
category: 'data',
|
|
214
215
|
type: 'ValidationResultError',
|
|
215
|
-
at:
|
|
216
|
+
at: 2029-03-14T04:00:00.618Z,
|
|
216
217
|
details: {
|
|
217
218
|
class: '@travetto/config:doc/dbconfig#DBConfig',
|
|
218
219
|
import: '@travetto/config/doc/dbconfig.ts',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Configuration support",
|
|
6
6
|
"keywords": [
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"directory": "module/config"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/di": "^
|
|
31
|
-
"@travetto/schema": "^
|
|
30
|
+
"@travetto/di": "^8.0.0-alpha.0",
|
|
31
|
+
"@travetto/schema": "^8.0.0-alpha.0",
|
|
32
32
|
"yaml": "^2.8.2"
|
|
33
33
|
},
|
|
34
34
|
"travetto": {
|
package/src/decorator.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { DependencyRegistryIndex } from '@travetto/di';
|
|
|
3
3
|
import { SchemaRegistryIndex } from '@travetto/schema';
|
|
4
4
|
|
|
5
5
|
import { ConfigurationService, ConfigBaseType } from './service.ts';
|
|
6
|
-
import { ConfigOverrideUtil } from './
|
|
6
|
+
import { ConfigOverrideUtil } from './override.ts';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Indicates that the given class should be populated with the configured fields, on instantiation
|
package/src/parser/json.ts
CHANGED
package/src/parser/parser.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { DependencyRegistryIndex, Injectable } from '@travetto/di';
|
|
5
|
-
import {
|
|
5
|
+
import { RuntimeError, toConcrete } from '@travetto/runtime';
|
|
6
6
|
|
|
7
7
|
import type { ConfigData, ConfigParser } from './types.ts';
|
|
8
8
|
|
|
@@ -26,7 +26,7 @@ export class ParserManager {
|
|
|
26
26
|
async parse(file: string): Promise<ConfigData> {
|
|
27
27
|
const ext = path.extname(file);
|
|
28
28
|
if (!this.#parsers[ext]) {
|
|
29
|
-
throw new
|
|
29
|
+
throw new RuntimeError(`Unknown config format: ${ext}`, { category: 'data' });
|
|
30
30
|
}
|
|
31
31
|
return fs.readFile(file, 'utf8').then(content => this.#parsers[ext].parse(content));
|
|
32
32
|
}
|
package/src/parser/properties.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class PropertiesConfigParser implements ConfigParser {
|
|
|
42
42
|
for (let i = 0; i < lines.length; i++) {
|
|
43
43
|
let line = lines[i];
|
|
44
44
|
while (i < lines.length && line.endsWith('\\')) {
|
|
45
|
-
line = `${line.replace(
|
|
45
|
+
line = `${line.replace(/[\\]$/, '')}${lines[i += 1].trimStart()}`;
|
|
46
46
|
}
|
|
47
47
|
const entry = PropertiesConfigParser.parseLine(line);
|
|
48
48
|
if (entry) {
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import util from 'node:util';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { RuntimeError, toConcrete, castTo, type Class, Env, Runtime, RuntimeResources, getClass } from '@travetto/runtime';
|
|
4
4
|
import { DependencyRegistryIndex, getDefaultQualifier, Injectable } from '@travetto/di';
|
|
5
5
|
import { BindUtil, DataUtil, SchemaRegistryIndex, SchemaValidator, ValidationResultError } from '@travetto/schema';
|
|
6
6
|
|
|
@@ -50,7 +50,7 @@ export class ConfigurationService {
|
|
|
50
50
|
* - If of the same priority, then alpha sort on the source
|
|
51
51
|
*/
|
|
52
52
|
async postConstruct(): Promise<void> {
|
|
53
|
-
const providers =
|
|
53
|
+
const providers = DependencyRegistryIndex.getCandidates(toConcrete<ConfigSource>());
|
|
54
54
|
|
|
55
55
|
const configs = await Promise.all(
|
|
56
56
|
providers.map(async (candidate) => await DependencyRegistryIndex.getInstance<ConfigSource>(candidate.candidateType, candidate.qualifier))
|
|
@@ -62,7 +62,7 @@ export class ConfigurationService {
|
|
|
62
62
|
new FileConfigSource(parser),
|
|
63
63
|
...configs,
|
|
64
64
|
new OverrideConfigSource()
|
|
65
|
-
].map(source => source.get()));
|
|
65
|
+
].map(async source => source.get()));
|
|
66
66
|
|
|
67
67
|
const payloads = possible
|
|
68
68
|
.flat()
|
|
@@ -93,7 +93,7 @@ export class ConfigurationService {
|
|
|
93
93
|
* - Will not show fields marked as secret
|
|
94
94
|
*/
|
|
95
95
|
async exportActive(): Promise<{ sources: ConfigSpecSimple[], active: ConfigData }> {
|
|
96
|
-
const configTargets =
|
|
96
|
+
const configTargets = DependencyRegistryIndex.getCandidates(ConfigBaseType);
|
|
97
97
|
const configs = await Promise.all(
|
|
98
98
|
configTargets
|
|
99
99
|
.filter(candidate => candidate.qualifier === getDefaultQualifier(candidate.class)) // Is self targeting?
|
|
@@ -119,7 +119,7 @@ export class ConfigurationService {
|
|
|
119
119
|
async bindTo<T>(cls: Class<T>, item: T, namespace: string, validate = true): Promise<T> {
|
|
120
120
|
const classId = cls.Ⲑid;
|
|
121
121
|
if (!SchemaRegistryIndex.has(cls)) {
|
|
122
|
-
throw new
|
|
122
|
+
throw new RuntimeError(`${classId} is not a valid schema class, config is not supported`);
|
|
123
123
|
}
|
|
124
124
|
BindUtil.bindSchemaToObject(cls, item, this.#get(namespace));
|
|
125
125
|
if (validate) {
|
package/src/source/env.ts
CHANGED
|
@@ -15,7 +15,7 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
15
15
|
|
|
16
16
|
get(): ConfigPayload | undefined {
|
|
17
17
|
try {
|
|
18
|
-
const data: Record<string, unknown> = JSONUtil.
|
|
18
|
+
const data: Record<string, unknown> = JSONUtil.fromUTF8(process.env[this.#envKey] || '{}');
|
|
19
19
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
20
20
|
} catch {
|
|
21
21
|
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
package/src/source/override.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConfigData } from '../parser/types.ts';
|
|
2
2
|
import type { ConfigSource, ConfigPayload } from './types.ts';
|
|
3
|
-
import { ConfigOverrideUtil } from '../
|
|
3
|
+
import { ConfigOverrideUtil } from '../override.ts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Overridable config source, provides ability to override field level values, currently used by
|
|
File without changes
|