@candlerip/shared3 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -2,13 +2,13 @@ import * as dotenv from 'dotenv';
2
2
  import { NUMBER_ENVIRONMENT_VARIABLE_NAMES } from '../../../environment-variable-name/index.js';
3
3
  import { CustomErrorWorker } from '../../../../error/index.js';
4
4
  export const loadEnvFile = (environmentMode) => {
5
- CustomErrorWorker.addInfo({ environmentMode });
5
+ const { composeCustomError } = CustomErrorWorker.getInstance({ environmentMode });
6
6
  const fileName = `.env.${environmentMode}`;
7
7
  const envFile = dotenv.config({ path: `./${fileName}` });
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
9
  const { error, parsed } = envFile;
10
10
  if (error || !parsed) {
11
- return CustomErrorWorker.compose(`Error loading ${fileName}`, { error });
11
+ return composeCustomError(`Error loading ${fileName}`, { error });
12
12
  }
13
13
  NUMBER_ENVIRONMENT_VARIABLE_NAMES.forEach((it) => {
14
14
  if (parsed[it]) {
@@ -19,3 +19,4 @@ export const loadEnvFile = (environmentMode) => {
19
19
  data: parsed,
20
20
  };
21
21
  };
22
+ loadEnvFile('development');
@@ -1,29 +1,34 @@
1
1
  export const CustomErrorWorker = (() => {
2
2
  let projectName;
3
- let info;
4
- const addInfo = (infoInput) => {
5
- info = {
6
- ...info,
7
- ...infoInput,
8
- };
9
- };
10
- const compose = (message, infoInput) => ({
11
- customError: {
12
- id: Math.random().toString(16).slice(2).toUpperCase(),
13
- info: {
3
+ const getInstance = (infoInput) => {
4
+ let info = infoInput;
5
+ const addInfo = (infoInput) => {
6
+ info = {
14
7
  ...info,
15
8
  ...infoInput,
9
+ };
10
+ };
11
+ const composeCustomError = (message, infoInput) => ({
12
+ customError: {
13
+ id: Math.random().toString(16).slice(2).toUpperCase(),
14
+ info: {
15
+ ...info,
16
+ ...infoInput,
17
+ },
18
+ message,
19
+ projectName,
16
20
  },
17
- message,
18
- projectName,
19
- },
20
- });
21
+ });
22
+ return {
23
+ addInfo,
24
+ composeCustomError,
25
+ };
26
+ };
21
27
  const init = (projectNameInput) => {
22
28
  projectName = projectNameInput;
23
29
  };
24
30
  return {
25
- addInfo,
26
- compose,
31
+ getInstance,
27
32
  init,
28
33
  };
29
34
  })();
@@ -1,11 +1,14 @@
1
1
  import { CustomError } from '../../domains/index.js';
2
2
  export interface ICustomErrorWorker {
3
- addInfo: AddInfo;
4
- compose: Compose;
3
+ getInstance: GetInstance;
5
4
  init: Init;
6
5
  }
7
6
  export type AddInfo = (props: CustomError['info']) => void;
8
- export type Compose = (message: CustomError['message'], info?: CustomError['info']) => {
7
+ export type ComposeCustomError = (message: CustomError['message'], info?: CustomError['info']) => {
9
8
  customError: CustomError;
10
9
  };
10
+ export type GetInstance = (info: CustomError['info']) => {
11
+ addInfo: AddInfo;
12
+ composeCustomError: ComposeCustomError;
13
+ };
11
14
  export type Init = (projectName: CustomError['projectName']) => void;