@travetto/config 3.4.4 → 4.0.0-rc.1
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 +2 -4
- package/__index__.ts +1 -0
- package/package.json +4 -4
- package/src/parser/parser.ts +1 -1
- package/src/parser/types.ts +1 -1
- package/src/service.ts +19 -7
- package/src/source/env.ts +2 -4
- package/src/source/file.ts +12 -13
- package/src/source/types.ts +1 -1
- package/src/trv.d.ts +10 -0
package/README.md
CHANGED
|
@@ -117,8 +117,6 @@ export class MemoryConfigSource implements ConfigSource {
|
|
|
117
117
|
|
|
118
118
|
**Code: Environment JSON Provider**
|
|
119
119
|
```typescript
|
|
120
|
-
import { Env } from '@travetto/base';
|
|
121
|
-
|
|
122
120
|
import { ConfigSource, ConfigSpec } from './types';
|
|
123
121
|
|
|
124
122
|
/**
|
|
@@ -135,10 +133,10 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
135
133
|
|
|
136
134
|
get(): ConfigSpec | undefined {
|
|
137
135
|
try {
|
|
138
|
-
const data = JSON.parse(
|
|
136
|
+
const data = JSON.parse(process.env[this.#envKey] || '{}');
|
|
139
137
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
140
138
|
} catch (e) {
|
|
141
|
-
console.error(`env.${this.#envKey} is an invalid format`, { text:
|
|
139
|
+
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
142
|
}
|
package/__index__.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"description": "Configuration support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yaml",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"directory": "module/config"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/di": "^
|
|
30
|
-
"@travetto/schema": "^
|
|
31
|
-
"@travetto/yaml": "^
|
|
29
|
+
"@travetto/di": "^4.0.0-rc.1",
|
|
30
|
+
"@travetto/schema": "^4.0.0-rc.1",
|
|
31
|
+
"@travetto/yaml": "^4.0.0-rc.1"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Configuration"
|
package/src/parser/parser.ts
CHANGED
package/src/parser/types.ts
CHANGED
package/src/service.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import util from 'util';
|
|
1
|
+
import util from 'node:util';
|
|
2
2
|
|
|
3
|
-
import { AppError, Class, ClassInstance,
|
|
3
|
+
import { AppError, Class, ClassInstance, Env, RuntimeResources } from '@travetto/base';
|
|
4
4
|
import { DependencyRegistry, Injectable } from '@travetto/di';
|
|
5
|
-
import {
|
|
6
|
-
import { BindUtil, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
|
|
5
|
+
import { RuntimeIndex, RuntimeContext } from '@travetto/manifest';
|
|
6
|
+
import { BindUtil, DataUtil, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
|
|
7
7
|
|
|
8
8
|
import { ConfigSourceTarget, ConfigTarget } from './internal/types';
|
|
9
9
|
import { ParserManager } from './parser/parser';
|
|
@@ -127,7 +127,7 @@ export class ConfigurationService {
|
|
|
127
127
|
const ogMessage = err.message;
|
|
128
128
|
err.message = `Failed to construct ${cls.Ⲑid} as validation errors have occurred`;
|
|
129
129
|
err.stack = err.stack?.replace(ogMessage, err.message);
|
|
130
|
-
const file =
|
|
130
|
+
const file = RuntimeIndex.getFunctionMetadata(cls)!.source;
|
|
131
131
|
err.payload = { class: cls.Ⲑid, file, ...(err.payload ?? {}) };
|
|
132
132
|
}
|
|
133
133
|
throw err;
|
|
@@ -142,11 +142,23 @@ export class ConfigurationService {
|
|
|
142
142
|
async initBanner(): Promise<void> {
|
|
143
143
|
const og = util.inspect.defaultOptions.depth;
|
|
144
144
|
util.inspect.defaultOptions.depth = 100;
|
|
145
|
+
|
|
145
146
|
console.log('Initialized', {
|
|
146
|
-
manifest:
|
|
147
|
-
|
|
147
|
+
manifest: {
|
|
148
|
+
main: RuntimeContext.main,
|
|
149
|
+
workspace: RuntimeContext.workspace
|
|
150
|
+
},
|
|
151
|
+
env: {
|
|
152
|
+
name: Env.name,
|
|
153
|
+
debug: Env.debug,
|
|
154
|
+
production: Env.production,
|
|
155
|
+
dynamic: Env.dynamic,
|
|
156
|
+
resourcePaths: RuntimeResources.searchPaths,
|
|
157
|
+
profiles: Env.TRV_PROFILES.list ?? []
|
|
158
|
+
},
|
|
148
159
|
config: await this.exportActive()
|
|
149
160
|
});
|
|
161
|
+
|
|
150
162
|
util.inspect.defaultOptions.depth = og;
|
|
151
163
|
}
|
|
152
164
|
}
|
package/src/source/env.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Env } from '@travetto/base';
|
|
2
|
-
|
|
3
1
|
import { ConfigSource, ConfigSpec } from './types';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -16,10 +14,10 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
16
14
|
|
|
17
15
|
get(): ConfigSpec | undefined {
|
|
18
16
|
try {
|
|
19
|
-
const data = JSON.parse(
|
|
17
|
+
const data = JSON.parse(process.env[this.#envKey] || '{}');
|
|
20
18
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
21
19
|
} catch (e) {
|
|
22
|
-
console.error(`env.${this.#envKey} is an invalid format`, { text:
|
|
20
|
+
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
}
|
package/src/source/file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { Env,
|
|
4
|
-
import {
|
|
3
|
+
import { Env, RuntimeResources } from '@travetto/base';
|
|
4
|
+
import { RuntimeContext, path } from '@travetto/manifest';
|
|
5
5
|
|
|
6
6
|
import { ConfigSource, ConfigSpec } from './types';
|
|
7
7
|
import { ParserManager } from '../parser/parser';
|
|
@@ -9,7 +9,7 @@ import { ParserManager } from '../parser/parser';
|
|
|
9
9
|
type Profile = [string, number] | readonly [string, number];
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* File-
|
|
12
|
+
* File-based config source, relies on resource search paths for finding files
|
|
13
13
|
*/
|
|
14
14
|
export class FileConfigSource implements ConfigSource {
|
|
15
15
|
|
|
@@ -17,16 +17,15 @@ export class FileConfigSource implements ConfigSource {
|
|
|
17
17
|
#searchPaths: string[];
|
|
18
18
|
#parser: ParserManager;
|
|
19
19
|
|
|
20
|
-
constructor(parser: ParserManager
|
|
20
|
+
constructor(parser: ParserManager) {
|
|
21
21
|
this.#parser = parser;
|
|
22
|
-
this.#searchPaths =
|
|
23
|
-
this.#profiles =
|
|
22
|
+
this.#searchPaths = RuntimeResources.searchPaths.slice().reverse();
|
|
23
|
+
this.#profiles = ([
|
|
24
24
|
['application', 100],
|
|
25
|
-
[
|
|
26
|
-
...(Env.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
];
|
|
25
|
+
[Env.name!, 200],
|
|
26
|
+
...(Env.TRV_PROFILES.list ?? [])
|
|
27
|
+
.map((p, i) => [p, 300 + i * 10] as const)
|
|
28
|
+
] as const).filter(x => !!x[0]);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
async get(): Promise<ConfigSpec[]> {
|
|
@@ -43,7 +42,7 @@ export class FileConfigSource implements ConfigSource {
|
|
|
43
42
|
data,
|
|
44
43
|
priority: priority + i++,
|
|
45
44
|
source: `file://${profile}`,
|
|
46
|
-
detail: full.replace(`${
|
|
45
|
+
detail: full.replace(`${RuntimeContext.workspace.path}/`, '')
|
|
47
46
|
})));
|
|
48
47
|
}
|
|
49
48
|
}
|
package/src/source/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ type OneOf<T> = T[] | T | undefined;
|
|
|
6
6
|
export type ConfigSpec = { data: ConfigData, priority: number, source: string, detail?: string };
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @concrete ../internal/types
|
|
9
|
+
* @concrete ../internal/types#ConfigSourceTarget
|
|
10
10
|
*/
|
|
11
11
|
export interface ConfigSource {
|
|
12
12
|
get(): OrProm<OneOf<ConfigSpec>>;
|