@aneuhold/be-ts-lib 1.0.1 → 1.0.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.
package/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import OSFileSystemService from './services/applications/OSFileSystemService';
6
6
  import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
7
7
  import ITermService from './services/applications/ITermService';
8
8
  import ConfigService from './services/ConfigService/ConfigService';
9
+ import Config from './services/ConfigService/ConfigDefinition';
9
10
  export { CLIService, CurrentEnv, ChromeService, DockerService, OSFileSystemService, sleep, OperatingSystemType, ShellType, TerminalType, ITermService, ConfigService };
10
- export type {};
11
+ export type { Config };
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AAGnE,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,CAAC;AAGF,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,MAAM,MAAM,2CAA2C,CAAC;AAG/D,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,CAAC;AAGF,YAAY,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The environment configuration that is pulled in for the current environment
3
+ * from the GitHub repository.
4
+ */
5
+ export default interface Config {
6
+ someKey: string;
7
+ }
8
+ //# sourceMappingURL=ConfigDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigDefinition.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigDefinition.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,24 @@
1
1
  import 'dotenv/config';
2
+ import Config from './ConfigDefinition';
2
3
  export type ConfigEnv = 'local' | 'dev' | 'prod';
3
4
  /**
4
- * A class which can be used to load configuration into the local environment
5
- * from a pre-defined location.
5
+ * A class which can be used to load configuration into the ConfigService
6
+ * from a pre-defined location. This requries that a `.env` file exists in the
7
+ * root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
6
8
  */
7
9
  export default class ConfigService {
10
+ static env: ConfigEnv | null;
8
11
  private static gitHub;
9
- static useConfig(env: string): Promise<void>;
12
+ private static configObject;
13
+ /**
14
+ * Returns the configuration object that has been loaded in for the current
15
+ * environment.
16
+ */
17
+ static get config(): Config;
18
+ /**
19
+ * Loads configuration from the GitHub repository into the ConfigService.
20
+ */
21
+ static useConfig(env: ConfigEnv): Promise<void>;
10
22
  /**
11
23
  * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
12
24
  * local environment or .env file.
@@ -14,6 +26,8 @@ export default class ConfigService {
14
26
  private static getGitHubClient;
15
27
  /**
16
28
  * Inserts the provided configuration into the local environment.
29
+ *
30
+ * This may not actually need to happen.
17
31
  */
18
32
  private static insertPropertiesIntoEnv;
19
33
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAGvB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;WAEhC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBlD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAG9B;CACH"}
1
+ {"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAEvB,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAQ;IAEpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;IAE7C,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuB;IAElD;;;OAGG;IACH,MAAM,KAAK,MAAM,IAAI,MAAM,CAO1B;IAED;;OAEG;WACU,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBrD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAG9B;CACH"}
@@ -4,12 +4,29 @@ const octokit_1 = require("octokit");
4
4
  require("dotenv/config");
5
5
  const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
6
6
  /**
7
- * A class which can be used to load configuration into the local environment
8
- * from a pre-defined location.
7
+ * A class which can be used to load configuration into the ConfigService
8
+ * from a pre-defined location. This requries that a `.env` file exists in the
9
+ * root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
9
10
  */
10
11
  class ConfigService {
12
+ static env = null;
11
13
  static gitHub = null;
14
+ static configObject = null;
15
+ /**
16
+ * Returns the configuration object that has been loaded in for the current
17
+ * environment.
18
+ */
19
+ static get config() {
20
+ if (!ConfigService.configObject) {
21
+ throw new Error('ConfigService has not been initialized yet. Use ConfigService.useConfig() to initialize it.');
22
+ }
23
+ return ConfigService.configObject;
24
+ }
25
+ /**
26
+ * Loads configuration from the GitHub repository into the ConfigService.
27
+ */
12
28
  static async useConfig(env) {
29
+ ConfigService.env = env;
13
30
  if (!ConfigService.gitHub) {
14
31
  ConfigService.gitHub = ConfigService.getGitHubClient();
15
32
  }
@@ -23,8 +40,7 @@ class ConfigService {
23
40
  path: `${env}.jsonc`
24
41
  });
25
42
  const strippedJson = ConfigService.stripJsonComments(result.data);
26
- const config = JSON.parse(strippedJson);
27
- ConfigService.insertPropertiesIntoEnv(config);
43
+ ConfigService.configObject = JSON.parse(strippedJson);
28
44
  }
29
45
  catch (error) {
30
46
  core_ts_lib_1.Logger.error(`Failed to load ${env}.json, error: ${error}`);
@@ -46,6 +62,8 @@ class ConfigService {
46
62
  }
47
63
  /**
48
64
  * Inserts the provided configuration into the local environment.
65
+ *
66
+ * This may not actually need to happen.
49
67
  */
50
68
  static insertPropertiesIntoEnv(config) {
51
69
  Object.entries(config).forEach(([key, value]) => {
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const console_1 = require("console");
7
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
8
7
  const ConfigService_1 = __importDefault(require("./ConfigService"));
9
8
  describe('ConfigService', () => {
10
9
  describe('useConfig', () => {
@@ -16,13 +15,7 @@ describe('ConfigService', () => {
16
15
  it('should load configuration from GitHub', async () => {
17
16
  const env = 'local';
18
17
  await ConfigService_1.default.useConfig(env);
19
- (0, console_1.assert)(process.env.SOME_KEY === 'SOME_VALUE');
20
- });
21
- it('should throw an error when loading configuration fails', async () => {
22
- const env = 'invalid_env';
23
- core_ts_lib_1.TestUtils.suppressConsole();
24
- await expect(ConfigService_1.default.useConfig(env)).rejects.toThrow();
25
- core_ts_lib_1.TestUtils.restoreConsole();
18
+ (0, console_1.assert)(ConfigService_1.default.config.someKey === 'SOME_VALUE');
26
19
  });
27
20
  });
28
21
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/be-ts-lib",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A backend TypeScript library used for common functionality in personal backend projects.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",