@travetto/config 3.4.4 → 4.0.0-rc.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 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(Env.get(this.#envKey, '{}'));
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: Env.get(this.#envKey) });
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
@@ -1,3 +1,4 @@
1
+ /// <reference path="./src/trv.d.ts" />
1
2
  export * from './src/decorator';
2
3
  export * from './src/service';
3
4
  export * from './src/source/env';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/config",
3
- "version": "3.4.4",
3
+ "version": "4.0.0-rc.0",
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": "^3.4.2",
30
- "@travetto/schema": "^3.4.4",
31
- "@travetto/yaml": "^3.4.2"
29
+ "@travetto/di": "^4.0.0-rc.0",
30
+ "@travetto/schema": "^4.0.0-rc.0",
31
+ "@travetto/yaml": "^4.0.0-rc.0"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "Configuration"
@@ -1,4 +1,4 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
3
  import { DependencyRegistry, Injectable } from '@travetto/di';
4
4
  import { AppError } from '@travetto/base';
@@ -1,7 +1,7 @@
1
1
  export type ConfigData = Record<string, unknown>;
2
2
 
3
3
  /**
4
- * @concrete ../internal/types:ConfigParserTarget
4
+ * @concrete ../internal/types#ConfigParserTarget
5
5
  */
6
6
  export interface ConfigParser {
7
7
  ext: string[];
package/src/service.ts CHANGED
@@ -1,8 +1,8 @@
1
- import util from 'util';
1
+ import util from 'node:util';
2
2
 
3
- import { AppError, Class, ClassInstance, GlobalEnv, DataUtil } from '@travetto/base';
3
+ import { AppError, Class, ClassInstance, DataUtil, Env, RuntimeResources } from '@travetto/base';
4
4
  import { DependencyRegistry, Injectable } from '@travetto/di';
5
- import { RootIndex } from '@travetto/manifest';
5
+ import { RuntimeIndex, RuntimeContext } from '@travetto/manifest';
6
6
  import { BindUtil, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
7
7
 
8
8
  import { ConfigSourceTarget, ConfigTarget } from './internal/types';
@@ -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 = RootIndex.getFunctionMetadata(cls)!.source;
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: RootIndex.manifestDigest(),
147
- env: GlobalEnv.toJSON(),
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(Env.get(this.#envKey, '{}'));
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: Env.get(this.#envKey) });
20
+ console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
23
21
  }
24
22
  }
25
23
  }
@@ -1,7 +1,7 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
- import { Env, GlobalEnv, ResourceLoader } from '@travetto/base';
4
- import { RootIndex, path } from '@travetto/manifest';
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-base config source, builds on common file resource provider
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, paths?: string[], profiles?: Profile[]) {
20
+ constructor(parser: ParserManager) {
21
21
  this.#parser = parser;
22
- this.#searchPaths = ResourceLoader.getSearchPaths(paths).reverse();
23
- this.#profiles = profiles ?? [
22
+ this.#searchPaths = RuntimeResources.searchPaths.slice().reverse();
23
+ this.#profiles = ([
24
24
  ['application', 100],
25
- [GlobalEnv.envName, 200],
26
- ...(Env.getList('TRV_PROFILES') ?? [])
27
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
28
- .map((p, i) => [p, 300 + i * 10] as [string, number])
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(`${RootIndex.manifest.workspacePath}/`, '')
45
+ detail: full.replace(`${RuntimeContext.workspace.path}/`, '')
47
46
  })));
48
47
  }
49
48
  }
@@ -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:ConfigSourceTarget
9
+ * @concrete ../internal/types#ConfigSourceTarget
10
10
  */
11
11
  export interface ConfigSource {
12
12
  get(): OrProm<OneOf<ConfigSpec>>;
package/src/trv.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import '@travetto/base';
2
+
3
+ declare global {
4
+ interface TravettoEnv {
5
+ /**
6
+ * Configuration profiles, in addition to TRV_ENV
7
+ */
8
+ TRV_PROFILES: string[];
9
+ }
10
+ }