@candlerip/shared3 0.0.41 → 0.0.43

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.41",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,14 +1,14 @@
1
1
  import * as dotenv from 'dotenv';
2
2
  import { NUMBER_ENVIRONMENT_VARIABLE_NAMES } from '../../../environment-variable-name/index.js';
3
- import { CustomErrorWorker } from '../../../../error/index.js';
3
+ import { customErrorWorker } from '../../../../error/index.js';
4
4
  export const loadEnvFile = (environmentMode) => {
5
- const { composeCustomError } = CustomErrorWorker.getInstance({ environmentMode });
5
+ const { composeCustomError } = customErrorWorker({ 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
- const { error, parsed } = envFile;
10
- if (error || !parsed) {
11
- return composeCustomError(`Error loading ${fileName}`, { error });
9
+ const { error: err, parsed } = envFile;
10
+ if (err || !parsed) {
11
+ return composeCustomError(`Error loading ${fileName}`, { err });
12
12
  }
13
13
  NUMBER_ENVIRONMENT_VARIABLE_NAMES.forEach((it) => {
14
14
  if (parsed[it]) {
@@ -19,4 +19,3 @@ export const loadEnvFile = (environmentMode) => {
19
19
  data: parsed,
20
20
  };
21
21
  };
22
- loadEnvFile('development');
@@ -1 +1 @@
1
- export declare const NUMBER_ENVIRONMENT_VARIABLE_NAMES: ("CACHE_SERVICE_PORT" | "LOGGER_SERVICE_PORT" | "RABBITMQ_PORT" | "RABBITMQ_MANAGEMENT_PORT" | "REDIS_PORT" | "APP_NAME" | "DOMAIN_NAME" | "S3_IMAGES_BUCKET_NAME" | "DATABASE_URL" | "REDIS_PWD" | "REDIS_URL" | "DICTIONARY_SERVICE_PORT" | "FRONTEND_URL" | "RABBITMQ_URL" | "RABBITMQ_PWD" | "RABBITMQ_USER")[];
1
+ export declare const NUMBER_ENVIRONMENT_VARIABLE_NAMES: ("CACHE_SERVICE_PORT" | "LOGGER_SERVICE_PORT" | "RABBITMQ_PORT" | "RABBITMQ_MANAGEMENT_PORT" | "REDIS_PORT" | "APP_NAME" | "DOMAIN_NAME" | "S3_IMAGES_BUCKET_NAME" | "DATABASE_URL" | "RABBITMQ_URL" | "REDIS_PWD" | "REDIS_URL" | "DICTIONARY_SERVICE_PORT" | "FRONTEND_URL" | "RABBITMQ_PWD" | "RABBITMQ_USER")[];
@@ -1,2 +1,2 @@
1
- import { ICustomErrorWorker } from './types.js';
2
- export declare const CustomErrorWorker: ICustomErrorWorker;
1
+ import { CustomErrorWorker } from './types.js';
2
+ export declare const customErrorWorker: CustomErrorWorker;
@@ -1,34 +1,25 @@
1
- export const CustomErrorWorker = (() => {
2
- let projectName;
3
- const getInstance = (infoInput) => {
4
- let info = infoInput;
5
- const addInfo = (infoInput) => {
6
- info = {
1
+ import { ProjectSingleton } from '../../../../project/index.js';
2
+ export const customErrorWorker = (infoInput) => {
3
+ let info = infoInput;
4
+ const addInfo = (infoInput) => {
5
+ info = {
6
+ ...info,
7
+ ...infoInput,
8
+ };
9
+ };
10
+ const composeCustomError = (message, infoInput) => ({
11
+ customError: {
12
+ id: Math.random().toString(16).slice(2).toUpperCase(),
13
+ info: {
7
14
  ...info,
8
15
  ...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,
20
16
  },
21
- });
22
- return {
23
- addInfo,
24
- composeCustomError,
25
- };
26
- };
27
- const init = (projectNameInput) => {
28
- projectName = projectNameInput;
29
- };
17
+ message,
18
+ projectName: ProjectSingleton.getProjectName(),
19
+ },
20
+ });
30
21
  return {
31
- getInstance,
32
- init,
22
+ addInfo,
23
+ composeCustomError,
33
24
  };
34
- })();
25
+ };
@@ -1,15 +1,10 @@
1
1
  import { CustomError } from '../../domains/index.js';
2
- export interface ICustomErrorWorker {
3
- getInstance: GetInstance;
4
- init: Init;
5
- }
2
+ export type CustomErrorWorker = (info?: CustomError['info']) => ICustomErrorWorker;
3
+ export type ICustomErrorWorker = {
4
+ addInfo: AddInfo;
5
+ composeCustomError: ComposeCustomError;
6
+ };
6
7
  export type AddInfo = (props: CustomError['info']) => void;
7
8
  export type ComposeCustomError = (message: CustomError['message'], info?: CustomError['info']) => {
8
9
  customError: CustomError;
9
10
  };
10
- export type GetInstance = (info: CustomError['info']) => CustomErrorWorkerInstance;
11
- export type Init = (projectName: CustomError['projectName']) => void;
12
- export type CustomErrorWorkerInstance = {
13
- addInfo: AddInfo;
14
- composeCustomError: ComposeCustomError;
15
- };
@@ -0,0 +1 @@
1
+ export * from './promise-all/index.js';
@@ -0,0 +1 @@
1
+ export * from './promise-all/index.js';
@@ -0,0 +1,12 @@
1
+ import { CustomError } from '../../error/index.js';
2
+ export declare const promiseAll: <T>(promises: Promise<{
3
+ customError: CustomError;
4
+ } | {
5
+ data: unknown;
6
+ }>[], keys?: string[]) => Promise<{
7
+ customErrors: {
8
+ customError: CustomError;
9
+ }[];
10
+ } | {
11
+ data: T;
12
+ }>;
@@ -0,0 +1,24 @@
1
+ export const promiseAll = async (promises, keys) => {
2
+ const resp = await Promise.all(promises);
3
+ const customErrors = resp.filter((it) => 'customError' in it);
4
+ const values = resp.filter((it) => 'data' in it).map((it) => it.data);
5
+ if (customErrors.length > 0) {
6
+ return { customErrors };
7
+ }
8
+ if (!keys) {
9
+ let data = {};
10
+ values.forEach((it) => {
11
+ data = Object.assign(data, it);
12
+ });
13
+ return {
14
+ data: data,
15
+ };
16
+ }
17
+ const data = {};
18
+ values.forEach((it, i) => {
19
+ data[keys[i]] = it;
20
+ });
21
+ return {
22
+ data: data,
23
+ };
24
+ };
package/src/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from './aws/index.js';
2
2
  export * from './database/index.js';
3
3
  export * from './environment/index.js';
4
4
  export * from './error/index.js';
5
+ export * from './helper/index.js';
5
6
  export * from './project/index.js';
6
7
  export * from './type/index.js';
package/src/index.js CHANGED
@@ -2,5 +2,6 @@ export * from './aws/index.js';
2
2
  export * from './database/index.js';
3
3
  export * from './environment/index.js';
4
4
  export * from './error/index.js';
5
+ export * from './helper/index.js';
5
6
  export * from './project/index.js';
6
7
  export * from './type/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './project-config/index.js';
2
2
  export * from './project-name/index.js';
3
+ export * from './singletons/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './project-config/index.js';
2
2
  export * from './project-name/index.js';
3
+ export * from './singletons/index.js';
@@ -6,7 +6,7 @@ export declare const PROJECT_CONFIG: {
6
6
  readonly environmentVariableNames: readonly ["APP_NAME", "DOMAIN_NAME", "S3_IMAGES_BUCKET_NAME"];
7
7
  };
8
8
  readonly 'cache-service-project-config': {
9
- readonly environmentVariableNames: readonly ["CACHE_SERVICE_PORT", "DATABASE_URL", "REDIS_PWD", "REDIS_URL"];
9
+ readonly environmentVariableNames: readonly ["CACHE_SERVICE_PORT", "DATABASE_URL", "RABBITMQ_URL", "REDIS_PWD", "REDIS_URL"];
10
10
  };
11
11
  readonly 'dictionary-service-project-config': {
12
12
  readonly environmentVariableNames: readonly ["DICTIONARY_SERVICE_PORT"];
@@ -6,7 +6,7 @@ export const PROJECT_CONFIG = {
6
6
  environmentVariableNames: ['APP_NAME', 'DOMAIN_NAME', 'S3_IMAGES_BUCKET_NAME'],
7
7
  },
8
8
  'cache-service-project-config': {
9
- environmentVariableNames: ['CACHE_SERVICE_PORT', 'DATABASE_URL', 'REDIS_PWD', 'REDIS_URL'],
9
+ environmentVariableNames: ['CACHE_SERVICE_PORT', 'DATABASE_URL', 'RABBITMQ_URL', 'REDIS_PWD', 'REDIS_URL'],
10
10
  },
11
11
  'dictionary-service-project-config': {
12
12
  environmentVariableNames: ['DICTIONARY_SERVICE_PORT'],
@@ -0,0 +1 @@
1
+ export * from './project-singleton/index.js';
@@ -0,0 +1 @@
1
+ export * from './project-singleton/index.js';
@@ -0,0 +1,2 @@
1
+ import { IProjectSingleton } from './types.js';
2
+ export declare const ProjectSingleton: IProjectSingleton;
@@ -0,0 +1,11 @@
1
+ export const ProjectSingleton = (() => {
2
+ let projectName;
3
+ const getProjectName = () => projectName;
4
+ const init = (projectNameInput) => {
5
+ projectName = projectNameInput;
6
+ };
7
+ return {
8
+ getProjectName,
9
+ init,
10
+ };
11
+ })();
@@ -0,0 +1,7 @@
1
+ import { ProjectName } from '../../project-name/index.js';
2
+ export interface IProjectSingleton {
3
+ getProjectName: GetProjectName;
4
+ init: Init;
5
+ }
6
+ export type GetProjectName = () => ProjectName;
7
+ export type Init = (projectName: ProjectName) => void;
@@ -0,0 +1 @@
1
+ export {};