@candlerip/shared 0.0.4
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/devops/environment/create-env-file.sh +29 -0
- package/devops/eslint/eslint.sh +4 -0
- package/devops/npm/publish-to-npm.sh +10 -0
- package/devops/prettier/config.js +7 -0
- package/devops/prettier/prettier.sh +4 -0
- package/devops/publish-package.sh +12 -0
- package/devops/typescript/tsc-build.sh +6 -0
- package/devops/typescript/tsc-watch.sh +5 -0
- package/devops/typescript/tsconfig.base.json +18 -0
- package/dist/backend/environment/env-file/index.d.ts +1 -0
- package/dist/backend/environment/env-file/index.js +1 -0
- package/dist/backend/environment/env-file/utils/index.d.ts +1 -0
- package/dist/backend/environment/env-file/utils/index.js +1 -0
- package/dist/backend/environment/env-file/utils/load-env-file/index.d.ts +2 -0
- package/dist/backend/environment/env-file/utils/load-env-file/index.js +47 -0
- package/dist/backend/environment/env-file/utils/load-env-file/type.d.ts +4 -0
- package/dist/backend/environment/env-file/utils/load-env-file/type.js +1 -0
- package/dist/backend/environment/index.d.ts +1 -0
- package/dist/backend/environment/index.js +1 -0
- package/dist/common/environment/environment-mode/configs.d.ts +1 -0
- package/dist/common/environment/environment-mode/configs.js +1 -0
- package/dist/common/environment/environment-mode/domains.d.ts +2 -0
- package/dist/common/environment/environment-mode/domains.js +1 -0
- package/dist/common/environment/environment-mode/index.d.ts +3 -0
- package/dist/common/environment/environment-mode/index.js +3 -0
- package/dist/common/environment/environment-mode/type-guards/index.d.ts +3 -0
- package/dist/common/environment/environment-mode/type-guards/index.js +3 -0
- package/dist/common/environment/environment-mode/type-guards/is-development.d.ts +1 -0
- package/dist/common/environment/environment-mode/type-guards/is-development.js +1 -0
- package/dist/common/environment/environment-mode/type-guards/is-environment-mode.d.ts +2 -0
- package/dist/common/environment/environment-mode/type-guards/is-environment-mode.js +2 -0
- package/dist/common/environment/environment-mode/type-guards/is-production.d.ts +1 -0
- package/dist/common/environment/environment-mode/type-guards/is-production.js +1 -0
- package/dist/common/environment/environment-variables/domains.d.ts +18 -0
- package/dist/common/environment/environment-variables/domains.js +1 -0
- package/dist/common/environment/environment-variables/index.d.ts +2 -0
- package/dist/common/environment/environment-variables/index.js +2 -0
- package/dist/common/environment/environment-variables/singletons/index.d.ts +8 -0
- package/dist/common/environment/environment-variables/singletons/index.js +20 -0
- package/dist/common/environment/environment-variables/singletons/type.d.ts +6 -0
- package/dist/common/environment/environment-variables/singletons/type.js +1 -0
- package/dist/common/environment/index.d.ts +2 -0
- package/dist/common/environment/index.js +2 -0
- package/dist/common/error/domains.d.ts +13 -0
- package/dist/common/error/domains.js +1 -0
- package/dist/common/error/index.d.ts +3 -0
- package/dist/common/error/index.js +3 -0
- package/dist/common/error/utils/compose-error/index.d.ts +2 -0
- package/dist/common/error/utils/compose-error/index.js +7 -0
- package/dist/common/error/utils/compose-error/type.d.ts +2 -0
- package/dist/common/error/utils/compose-error/type.js +1 -0
- package/dist/common/error/utils/console-error/index.d.ts +2 -0
- package/dist/common/error/utils/console-error/index.js +12 -0
- package/dist/common/error/utils/console-error/type.d.ts +2 -0
- package/dist/common/error/utils/console-error/type.js +1 -0
- package/dist/common/error/utils/index.d.ts +2 -0
- package/dist/common/error/utils/index.js +2 -0
- package/dist/common/error/workers/index.d.ts +2 -0
- package/dist/common/error/workers/index.js +32 -0
- package/dist/common/error/workers/type.d.ts +19 -0
- package/dist/common/error/workers/type.js +1 -0
- package/dist/common/helpers/index.d.ts +2 -0
- package/dist/common/helpers/index.js +2 -0
- package/dist/common/helpers/reveal-all-object-props/index.d.ts +2 -0
- package/dist/common/helpers/reveal-all-object-props/index.js +13 -0
- package/dist/common/helpers/reveal-all-object-props/type.d.ts +1 -0
- package/dist/common/helpers/reveal-all-object-props/type.js +1 -0
- package/dist/common/helpers/stringify/index.d.ts +2 -0
- package/dist/common/helpers/stringify/index.js +3 -0
- package/dist/common/helpers/stringify/type.d.ts +1 -0
- package/dist/common/helpers/stringify/type.js +1 -0
- package/dist/common/index.d.ts +5 -0
- package/dist/common/index.js +5 -0
- package/dist/common/service/index.d.ts +1 -0
- package/dist/common/service/index.js +1 -0
- package/dist/common/service/singletons/index.d.ts +5 -0
- package/dist/common/service/singletons/index.js +11 -0
- package/dist/common/service/singletons/type.d.ts +2 -0
- package/dist/common/service/singletons/type.js +1 -0
- package/dist/common/type/array/index.d.ts +1 -0
- package/dist/common/type/array/index.js +1 -0
- package/dist/common/type/array/type-guards.d.ts +1 -0
- package/dist/common/type/array/type-guards.js +9 -0
- package/dist/common/type/index.d.ts +3 -0
- package/dist/common/type/index.js +3 -0
- package/dist/common/type/null/index.d.ts +1 -0
- package/dist/common/type/null/index.js +1 -0
- package/dist/common/type/null/type-guards.d.ts +1 -0
- package/dist/common/type/null/type-guards.js +1 -0
- package/dist/common/type/object/index.d.ts +1 -0
- package/dist/common/type/object/index.js +1 -0
- package/dist/common/type/object/type-guards.d.ts +1 -0
- package/dist/common/type/object/type-guards.js +11 -0
- package/dist/devops/eslint/configs.d.ts +2 -0
- package/dist/devops/eslint/configs.js +8 -0
- package/dist/devops/eslint/index.d.ts +2 -0
- package/dist/devops/eslint/index.js +2 -0
- package/dist/devops/eslint/utils/compose-eslint-config/index.d.ts +2 -0
- package/dist/devops/eslint/utils/compose-eslint-config/index.js +20 -0
- package/dist/devops/eslint/utils/compose-eslint-config/type.d.ts +4 -0
- package/dist/devops/eslint/utils/compose-eslint-config/type.js +1 -0
- package/dist/devops/eslint/utils/index.d.ts +1 -0
- package/dist/devops/eslint/utils/index.js +1 -0
- package/dist/devops/index.d.ts +1 -0
- package/dist/devops/index.js +1 -0
- package/package.json +43 -0
- package/src/backend/environment/env-file/index.ts +1 -0
- package/src/backend/environment/env-file/utils/index.ts +1 -0
- package/src/backend/environment/env-file/utils/load-env-file/index.ts +53 -0
- package/src/backend/environment/env-file/utils/load-env-file/type.ts +5 -0
- package/src/backend/environment/index.ts +1 -0
- package/src/common/environment/environment-mode/configs.ts +1 -0
- package/src/common/environment/environment-mode/domains.ts +3 -0
- package/src/common/environment/environment-mode/index.ts +5 -0
- package/src/common/environment/environment-mode/type-guards/index.ts +5 -0
- package/src/common/environment/environment-mode/type-guards/is-development.ts +1 -0
- package/src/common/environment/environment-mode/type-guards/is-environment-mode.ts +4 -0
- package/src/common/environment/environment-mode/type-guards/is-production.ts +1 -0
- package/src/common/environment/environment-variables/domains.ts +19 -0
- package/src/common/environment/environment-variables/index.ts +3 -0
- package/src/common/environment/environment-variables/singletons/index.ts +29 -0
- package/src/common/environment/environment-variables/singletons/type.ts +11 -0
- package/src/common/environment/index.ts +3 -0
- package/src/common/error/domains.ts +8 -0
- package/src/common/error/index.ts +5 -0
- package/src/common/error/utils/compose-error/index.ts +9 -0
- package/src/common/error/utils/compose-error/type.ts +3 -0
- package/src/common/error/utils/console-error/index.ts +18 -0
- package/src/common/error/utils/console-error/type.ts +3 -0
- package/src/common/error/utils/index.ts +3 -0
- package/src/common/error/workers/index.ts +41 -0
- package/src/common/error/workers/type.ts +21 -0
- package/src/common/helpers/index.ts +3 -0
- package/src/common/helpers/reveal-all-object-props/index.ts +16 -0
- package/src/common/helpers/reveal-all-object-props/type.ts +1 -0
- package/src/common/helpers/stringify/index.ts +5 -0
- package/src/common/helpers/stringify/type.ts +1 -0
- package/src/common/index.ts +9 -0
- package/src/common/service/index.ts +1 -0
- package/src/common/service/singletons/index.ts +16 -0
- package/src/common/service/singletons/type.ts +3 -0
- package/src/common/type/array/index.ts +1 -0
- package/src/common/type/array/type-guards.ts +11 -0
- package/src/common/type/index.ts +5 -0
- package/src/common/type/null/index.ts +1 -0
- package/src/common/type/null/type-guards.ts +1 -0
- package/src/common/type/object/index.ts +1 -0
- package/src/common/type/object/type-guards.ts +12 -0
- package/src/devops/eslint/configs.ts +10 -0
- package/src/devops/eslint/index.ts +3 -0
- package/src/devops/eslint/utils/compose-eslint-config/index.ts +29 -0
- package/src/devops/eslint/utils/compose-eslint-config/type.ts +3 -0
- package/src/devops/eslint/utils/index.ts +1 -0
- package/src/devops/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type-guards.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isObject: (data?: unknown) => data is Record<string, unknown>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import * as globals from 'globals';
|
|
5
|
+
import { ESLINT_RULES } from '../../configs.js';
|
|
6
|
+
export const composeEslintConfig = (props = {}) => {
|
|
7
|
+
const { ignores = [] } = props;
|
|
8
|
+
return defineConfig(eslint.configs.recommended, ...tseslint.configs.recommended, {
|
|
9
|
+
ignores,
|
|
10
|
+
}, {
|
|
11
|
+
languageOptions: {
|
|
12
|
+
globals: {
|
|
13
|
+
...globals.browser,
|
|
14
|
+
...globals.node,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}, {
|
|
18
|
+
rules: ESLINT_RULES,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compose-eslint-config/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compose-eslint-config/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './eslint/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './eslint/index.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@candlerip/shared",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": "=22.19.0"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"devops",
|
|
10
|
+
"dist",
|
|
11
|
+
"src",
|
|
12
|
+
"package-lock.json",
|
|
13
|
+
"package.json"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"crs-eslint": "devops/eslint/eslint.sh",
|
|
17
|
+
"crs-prettier": "devops/prettier/prettier.sh",
|
|
18
|
+
"crs-tsc-build": "devops/typescript/tsc-build.sh",
|
|
19
|
+
"crs-tsc-watch": "devops/typescript/tsc-watch.sh"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./backend/environment": "./dist/backend/environment/index.js",
|
|
23
|
+
"./common": "./dist/common/index.js",
|
|
24
|
+
"./devops": "./dist/devops/index.js"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "sh ./devops/typescript/tsc-build.sh",
|
|
28
|
+
"publish-package": "sh ./devops/publish-package.sh",
|
|
29
|
+
"start": "sh ./devops/typescript/tsc-watch.sh"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"eslint": "^9.35.0",
|
|
33
|
+
"globals": "^16.4.0",
|
|
34
|
+
"jiti": "^2.5.1",
|
|
35
|
+
"prettier": "^3.6.2",
|
|
36
|
+
"tsc-alias": "^1.8.16",
|
|
37
|
+
"typescript": "^5.9.2",
|
|
38
|
+
"typescript-eslint": "^8.43.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^24.3.1"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './load-env-file';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { ErrorWorker } from '../../../../../common';
|
|
3
|
+
import { LoadEnvFile } from './type';
|
|
4
|
+
|
|
5
|
+
export const loadEnvFile: LoadEnvFile = (environmentMode) => {
|
|
6
|
+
const { composeError } = ErrorWorker({ info: { environmentMode } });
|
|
7
|
+
|
|
8
|
+
let fileName = '.env';
|
|
9
|
+
if (environmentMode) {
|
|
10
|
+
fileName += `.${environmentMode}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const parsed = {} as Record<string, string>;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const file = fs.readFileSync(fileName, 'utf-8');
|
|
17
|
+
file.split('\n').forEach((fileLine) => {
|
|
18
|
+
if (fileLine.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const envVar = fileLine.split('=');
|
|
22
|
+
parsed[`${envVar[0]}`] = envVar[1];
|
|
23
|
+
});
|
|
24
|
+
} catch (err) {
|
|
25
|
+
return {
|
|
26
|
+
error: composeError(`Error loading ${fileName}`, {
|
|
27
|
+
info: {
|
|
28
|
+
err,
|
|
29
|
+
fileName,
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
const data = {} as any;
|
|
37
|
+
|
|
38
|
+
(Object.keys(parsed) as Array<keyof typeof parsed>).forEach((key) => {
|
|
39
|
+
const parsedItem = parsed[key];
|
|
40
|
+
|
|
41
|
+
if (['false', 'true'].includes(parsedItem)) {
|
|
42
|
+
data[key] = Boolean(parsedItem === 'true');
|
|
43
|
+
} else if (!Number.isNaN(parseInt(parsedItem))) {
|
|
44
|
+
data[key] = parseInt(parsedItem);
|
|
45
|
+
} else {
|
|
46
|
+
data[key] = parsedItem;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
data,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './env-file';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ENVIRONMENT_MODES = ['development', 'production'] as const;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isDevelopment = (data?: unknown): data is 'development' => data === 'development';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isProduction = (data?: unknown): data is 'production' => data === 'production';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EnvironmentMode } from '../environment-mode';
|
|
2
|
+
|
|
3
|
+
export type EnvironmentVariables = {
|
|
4
|
+
APP_NAME: string;
|
|
5
|
+
AWS_REGION: string;
|
|
6
|
+
AWS_S3_IMAGES_BUCKET_NAME: string;
|
|
7
|
+
CACHE_SERVICE_PORT: string;
|
|
8
|
+
CACHE_ENABLED: boolean;
|
|
9
|
+
DATABASE_URL: string;
|
|
10
|
+
DOMAIN_NAME: string;
|
|
11
|
+
FRONTEND_URL: string;
|
|
12
|
+
LOGGER_SERVICE_PORT: string;
|
|
13
|
+
MOBILE_APP_URL: string;
|
|
14
|
+
NODE_ENV: EnvironmentMode;
|
|
15
|
+
RABBITMQ_URL: string;
|
|
16
|
+
REDIS_PWD: string;
|
|
17
|
+
REDIS_URL: string;
|
|
18
|
+
REDIS_URL_APP: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isDevelopment as isDev, isProduction as isProd } from '../../environment-mode';
|
|
2
|
+
import { EnvironmentVariables } from '../domains';
|
|
3
|
+
import { GetEnv, GetEnvs, Init, IsDevelopment, IsProduction } from './type';
|
|
4
|
+
|
|
5
|
+
export const EnvironmentVariablesSingleton = (() => {
|
|
6
|
+
let _envs: Partial<EnvironmentVariables>;
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const getEnv: GetEnv = (name) => _envs[name] as any;
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const getEnvs: GetEnvs = (names) => names.reduce((acc, curr) => ({ ...acc, [`${curr}`]: _envs[curr] }), {}) as any;
|
|
13
|
+
|
|
14
|
+
const init: Init = (envs) => {
|
|
15
|
+
_envs = envs;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const isDevelopment: IsDevelopment = () => isDev(_envs.NODE_ENV);
|
|
19
|
+
|
|
20
|
+
const isProduction: IsProduction = () => isProd(_envs.NODE_ENV);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
getEnv,
|
|
24
|
+
getEnvs,
|
|
25
|
+
init,
|
|
26
|
+
isDevelopment,
|
|
27
|
+
isProduction,
|
|
28
|
+
};
|
|
29
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EnvironmentVariables } from '../domains';
|
|
2
|
+
|
|
3
|
+
export type GetEnv = <T extends keyof EnvironmentVariables = never>(name: T) => EnvironmentVariables[T];
|
|
4
|
+
|
|
5
|
+
export type GetEnvs = <T extends keyof EnvironmentVariables = never>(names: T[]) => Pick<EnvironmentVariables, T>;
|
|
6
|
+
|
|
7
|
+
export type Init = (envs: Partial<EnvironmentVariables>) => void;
|
|
8
|
+
|
|
9
|
+
export type IsDevelopment = () => boolean;
|
|
10
|
+
|
|
11
|
+
export type IsProduction = () => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ServiceSingleton } from '../../../service';
|
|
2
|
+
import { ComposeError } from './type';
|
|
3
|
+
|
|
4
|
+
export const composeError: ComposeError = (message, info) => ({
|
|
5
|
+
id: Math.random().toString(16).slice(2).toUpperCase(),
|
|
6
|
+
info,
|
|
7
|
+
message: message ?? '',
|
|
8
|
+
serviceName: ServiceSingleton.getServiceName(),
|
|
9
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { stringify } from '../../../helpers';
|
|
2
|
+
import { ConsoleError } from './type';
|
|
3
|
+
|
|
4
|
+
export const consoleError: ConsoleError = (error) => {
|
|
5
|
+
const { id, info, message, serviceName } = error;
|
|
6
|
+
|
|
7
|
+
let msg = `ERROR: ${message} (ID) ${id}`;
|
|
8
|
+
|
|
9
|
+
if (serviceName) {
|
|
10
|
+
msg += ` (SERVICE-NAME) ${serviceName}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (info) {
|
|
14
|
+
msg += ` (INFO) ${stringify(info)}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.error(msg);
|
|
18
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { _ComposeInfo, ErrorWorkerType, GetError, ResetError, AddErrorInfo, AddErrorMessage, ComposeError } from './type';
|
|
2
|
+
import { composeError as composeErrorFunc } from '../utils';
|
|
3
|
+
|
|
4
|
+
export const ErrorWorker: ErrorWorkerType = (props) => {
|
|
5
|
+
let _error = props ? composeErrorFunc(props.message, props.info) : undefined;
|
|
6
|
+
|
|
7
|
+
const _composeInfo: _ComposeInfo = (info) => {
|
|
8
|
+
if (_error) {
|
|
9
|
+
_error.info = {
|
|
10
|
+
..._error.info,
|
|
11
|
+
...info,
|
|
12
|
+
};
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
_error = composeErrorFunc(undefined, info);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const addErrorInfo: AddErrorInfo = (info) => {
|
|
19
|
+
_composeInfo(info);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const addErrorMessage: AddErrorMessage = (message) => {
|
|
23
|
+
_error = composeErrorFunc(message);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const composeError: ComposeError = (message, info) => composeErrorFunc(message, info ?? _error?.info);
|
|
27
|
+
|
|
28
|
+
const getError: GetError = () => (_error ? { error: _error } : undefined);
|
|
29
|
+
|
|
30
|
+
const resetError: ResetError = () => {
|
|
31
|
+
_error = undefined;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
addErrorInfo,
|
|
36
|
+
addErrorMessage,
|
|
37
|
+
composeError,
|
|
38
|
+
getError,
|
|
39
|
+
resetError,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Error } from '../domains';
|
|
2
|
+
|
|
3
|
+
export type ErrorWorkerType = (props?: { message?: string; info?: Record<string, unknown> }) => {
|
|
4
|
+
addErrorInfo: AddErrorInfo;
|
|
5
|
+
addErrorMessage: AddErrorMessage;
|
|
6
|
+
composeError: ComposeError;
|
|
7
|
+
getError: GetError;
|
|
8
|
+
resetError: ResetError;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type _ComposeInfo = (info?: Record<string, unknown>) => void;
|
|
12
|
+
|
|
13
|
+
export type AddErrorInfo = (info: Record<string, unknown>) => void;
|
|
14
|
+
|
|
15
|
+
export type AddErrorMessage = (message: string) => void;
|
|
16
|
+
|
|
17
|
+
export type ComposeError = (message: string, info?: Record<string, unknown>) => Error;
|
|
18
|
+
|
|
19
|
+
export type GetError = () => { error: Error } | undefined;
|
|
20
|
+
|
|
21
|
+
export type ResetError = () => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isObject } from '../../type';
|
|
2
|
+
import { RevealAllObjectProps } from './type';
|
|
3
|
+
|
|
4
|
+
export const revealAllObjectProps: RevealAllObjectProps = (obj) => {
|
|
5
|
+
const newObj = {} as Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
8
|
+
if (isObject(obj[key])) {
|
|
9
|
+
newObj[key] = revealAllObjectProps(obj[key]);
|
|
10
|
+
} else {
|
|
11
|
+
newObj[key] = obj[key];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return newObj;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RevealAllObjectProps = (obj: Record<string, unknown>) => Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Stringify = (obj: unknown) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './singletons';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GetServiceName, Init } from './type';
|
|
2
|
+
|
|
3
|
+
export const ServiceSingleton = (() => {
|
|
4
|
+
let _serviceName: string;
|
|
5
|
+
|
|
6
|
+
const getServiceName: GetServiceName = () => _serviceName;
|
|
7
|
+
|
|
8
|
+
const init: Init = (serviceName) => {
|
|
9
|
+
_serviceName = serviceName;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
getServiceName,
|
|
14
|
+
init,
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type-guards';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type-guards';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isNull = (data?: unknown): data is null => data === null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type-guards';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isArray } from '../array';
|
|
2
|
+
import { isNull } from '../null';
|
|
3
|
+
|
|
4
|
+
export const isObject = (data?: unknown): data is Record<string, unknown> => {
|
|
5
|
+
if (typeof data !== 'object') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return !isArray(data);
|
|
12
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import * as globals from 'globals';
|
|
5
|
+
import { ComposeEslintConfig } from './type';
|
|
6
|
+
import { ESLINT_RULES } from '../../configs';
|
|
7
|
+
|
|
8
|
+
export const composeEslintConfig: ComposeEslintConfig = (props = {}) => {
|
|
9
|
+
const { ignores = [] } = props;
|
|
10
|
+
|
|
11
|
+
return defineConfig(
|
|
12
|
+
eslint.configs.recommended,
|
|
13
|
+
...tseslint.configs.recommended,
|
|
14
|
+
{
|
|
15
|
+
ignores,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
languageOptions: {
|
|
19
|
+
globals: {
|
|
20
|
+
...globals.browser,
|
|
21
|
+
...globals.node,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
rules: ESLINT_RULES,
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compose-eslint-config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './eslint';
|