@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.
Files changed (154) hide show
  1. package/devops/environment/create-env-file.sh +29 -0
  2. package/devops/eslint/eslint.sh +4 -0
  3. package/devops/npm/publish-to-npm.sh +10 -0
  4. package/devops/prettier/config.js +7 -0
  5. package/devops/prettier/prettier.sh +4 -0
  6. package/devops/publish-package.sh +12 -0
  7. package/devops/typescript/tsc-build.sh +6 -0
  8. package/devops/typescript/tsc-watch.sh +5 -0
  9. package/devops/typescript/tsconfig.base.json +18 -0
  10. package/dist/backend/environment/env-file/index.d.ts +1 -0
  11. package/dist/backend/environment/env-file/index.js +1 -0
  12. package/dist/backend/environment/env-file/utils/index.d.ts +1 -0
  13. package/dist/backend/environment/env-file/utils/index.js +1 -0
  14. package/dist/backend/environment/env-file/utils/load-env-file/index.d.ts +2 -0
  15. package/dist/backend/environment/env-file/utils/load-env-file/index.js +47 -0
  16. package/dist/backend/environment/env-file/utils/load-env-file/type.d.ts +4 -0
  17. package/dist/backend/environment/env-file/utils/load-env-file/type.js +1 -0
  18. package/dist/backend/environment/index.d.ts +1 -0
  19. package/dist/backend/environment/index.js +1 -0
  20. package/dist/common/environment/environment-mode/configs.d.ts +1 -0
  21. package/dist/common/environment/environment-mode/configs.js +1 -0
  22. package/dist/common/environment/environment-mode/domains.d.ts +2 -0
  23. package/dist/common/environment/environment-mode/domains.js +1 -0
  24. package/dist/common/environment/environment-mode/index.d.ts +3 -0
  25. package/dist/common/environment/environment-mode/index.js +3 -0
  26. package/dist/common/environment/environment-mode/type-guards/index.d.ts +3 -0
  27. package/dist/common/environment/environment-mode/type-guards/index.js +3 -0
  28. package/dist/common/environment/environment-mode/type-guards/is-development.d.ts +1 -0
  29. package/dist/common/environment/environment-mode/type-guards/is-development.js +1 -0
  30. package/dist/common/environment/environment-mode/type-guards/is-environment-mode.d.ts +2 -0
  31. package/dist/common/environment/environment-mode/type-guards/is-environment-mode.js +2 -0
  32. package/dist/common/environment/environment-mode/type-guards/is-production.d.ts +1 -0
  33. package/dist/common/environment/environment-mode/type-guards/is-production.js +1 -0
  34. package/dist/common/environment/environment-variables/domains.d.ts +18 -0
  35. package/dist/common/environment/environment-variables/domains.js +1 -0
  36. package/dist/common/environment/environment-variables/index.d.ts +2 -0
  37. package/dist/common/environment/environment-variables/index.js +2 -0
  38. package/dist/common/environment/environment-variables/singletons/index.d.ts +8 -0
  39. package/dist/common/environment/environment-variables/singletons/index.js +20 -0
  40. package/dist/common/environment/environment-variables/singletons/type.d.ts +6 -0
  41. package/dist/common/environment/environment-variables/singletons/type.js +1 -0
  42. package/dist/common/environment/index.d.ts +2 -0
  43. package/dist/common/environment/index.js +2 -0
  44. package/dist/common/error/domains.d.ts +13 -0
  45. package/dist/common/error/domains.js +1 -0
  46. package/dist/common/error/index.d.ts +3 -0
  47. package/dist/common/error/index.js +3 -0
  48. package/dist/common/error/utils/compose-error/index.d.ts +2 -0
  49. package/dist/common/error/utils/compose-error/index.js +7 -0
  50. package/dist/common/error/utils/compose-error/type.d.ts +2 -0
  51. package/dist/common/error/utils/compose-error/type.js +1 -0
  52. package/dist/common/error/utils/console-error/index.d.ts +2 -0
  53. package/dist/common/error/utils/console-error/index.js +12 -0
  54. package/dist/common/error/utils/console-error/type.d.ts +2 -0
  55. package/dist/common/error/utils/console-error/type.js +1 -0
  56. package/dist/common/error/utils/index.d.ts +2 -0
  57. package/dist/common/error/utils/index.js +2 -0
  58. package/dist/common/error/workers/index.d.ts +2 -0
  59. package/dist/common/error/workers/index.js +32 -0
  60. package/dist/common/error/workers/type.d.ts +19 -0
  61. package/dist/common/error/workers/type.js +1 -0
  62. package/dist/common/helpers/index.d.ts +2 -0
  63. package/dist/common/helpers/index.js +2 -0
  64. package/dist/common/helpers/reveal-all-object-props/index.d.ts +2 -0
  65. package/dist/common/helpers/reveal-all-object-props/index.js +13 -0
  66. package/dist/common/helpers/reveal-all-object-props/type.d.ts +1 -0
  67. package/dist/common/helpers/reveal-all-object-props/type.js +1 -0
  68. package/dist/common/helpers/stringify/index.d.ts +2 -0
  69. package/dist/common/helpers/stringify/index.js +3 -0
  70. package/dist/common/helpers/stringify/type.d.ts +1 -0
  71. package/dist/common/helpers/stringify/type.js +1 -0
  72. package/dist/common/index.d.ts +5 -0
  73. package/dist/common/index.js +5 -0
  74. package/dist/common/service/index.d.ts +1 -0
  75. package/dist/common/service/index.js +1 -0
  76. package/dist/common/service/singletons/index.d.ts +5 -0
  77. package/dist/common/service/singletons/index.js +11 -0
  78. package/dist/common/service/singletons/type.d.ts +2 -0
  79. package/dist/common/service/singletons/type.js +1 -0
  80. package/dist/common/type/array/index.d.ts +1 -0
  81. package/dist/common/type/array/index.js +1 -0
  82. package/dist/common/type/array/type-guards.d.ts +1 -0
  83. package/dist/common/type/array/type-guards.js +9 -0
  84. package/dist/common/type/index.d.ts +3 -0
  85. package/dist/common/type/index.js +3 -0
  86. package/dist/common/type/null/index.d.ts +1 -0
  87. package/dist/common/type/null/index.js +1 -0
  88. package/dist/common/type/null/type-guards.d.ts +1 -0
  89. package/dist/common/type/null/type-guards.js +1 -0
  90. package/dist/common/type/object/index.d.ts +1 -0
  91. package/dist/common/type/object/index.js +1 -0
  92. package/dist/common/type/object/type-guards.d.ts +1 -0
  93. package/dist/common/type/object/type-guards.js +11 -0
  94. package/dist/devops/eslint/configs.d.ts +2 -0
  95. package/dist/devops/eslint/configs.js +8 -0
  96. package/dist/devops/eslint/index.d.ts +2 -0
  97. package/dist/devops/eslint/index.js +2 -0
  98. package/dist/devops/eslint/utils/compose-eslint-config/index.d.ts +2 -0
  99. package/dist/devops/eslint/utils/compose-eslint-config/index.js +20 -0
  100. package/dist/devops/eslint/utils/compose-eslint-config/type.d.ts +4 -0
  101. package/dist/devops/eslint/utils/compose-eslint-config/type.js +1 -0
  102. package/dist/devops/eslint/utils/index.d.ts +1 -0
  103. package/dist/devops/eslint/utils/index.js +1 -0
  104. package/dist/devops/index.d.ts +1 -0
  105. package/dist/devops/index.js +1 -0
  106. package/package.json +43 -0
  107. package/src/backend/environment/env-file/index.ts +1 -0
  108. package/src/backend/environment/env-file/utils/index.ts +1 -0
  109. package/src/backend/environment/env-file/utils/load-env-file/index.ts +53 -0
  110. package/src/backend/environment/env-file/utils/load-env-file/type.ts +5 -0
  111. package/src/backend/environment/index.ts +1 -0
  112. package/src/common/environment/environment-mode/configs.ts +1 -0
  113. package/src/common/environment/environment-mode/domains.ts +3 -0
  114. package/src/common/environment/environment-mode/index.ts +5 -0
  115. package/src/common/environment/environment-mode/type-guards/index.ts +5 -0
  116. package/src/common/environment/environment-mode/type-guards/is-development.ts +1 -0
  117. package/src/common/environment/environment-mode/type-guards/is-environment-mode.ts +4 -0
  118. package/src/common/environment/environment-mode/type-guards/is-production.ts +1 -0
  119. package/src/common/environment/environment-variables/domains.ts +19 -0
  120. package/src/common/environment/environment-variables/index.ts +3 -0
  121. package/src/common/environment/environment-variables/singletons/index.ts +29 -0
  122. package/src/common/environment/environment-variables/singletons/type.ts +11 -0
  123. package/src/common/environment/index.ts +3 -0
  124. package/src/common/error/domains.ts +8 -0
  125. package/src/common/error/index.ts +5 -0
  126. package/src/common/error/utils/compose-error/index.ts +9 -0
  127. package/src/common/error/utils/compose-error/type.ts +3 -0
  128. package/src/common/error/utils/console-error/index.ts +18 -0
  129. package/src/common/error/utils/console-error/type.ts +3 -0
  130. package/src/common/error/utils/index.ts +3 -0
  131. package/src/common/error/workers/index.ts +41 -0
  132. package/src/common/error/workers/type.ts +21 -0
  133. package/src/common/helpers/index.ts +3 -0
  134. package/src/common/helpers/reveal-all-object-props/index.ts +16 -0
  135. package/src/common/helpers/reveal-all-object-props/type.ts +1 -0
  136. package/src/common/helpers/stringify/index.ts +5 -0
  137. package/src/common/helpers/stringify/type.ts +1 -0
  138. package/src/common/index.ts +9 -0
  139. package/src/common/service/index.ts +1 -0
  140. package/src/common/service/singletons/index.ts +16 -0
  141. package/src/common/service/singletons/type.ts +3 -0
  142. package/src/common/type/array/index.ts +1 -0
  143. package/src/common/type/array/type-guards.ts +11 -0
  144. package/src/common/type/index.ts +5 -0
  145. package/src/common/type/null/index.ts +1 -0
  146. package/src/common/type/null/type-guards.ts +1 -0
  147. package/src/common/type/object/index.ts +1 -0
  148. package/src/common/type/object/type-guards.ts +12 -0
  149. package/src/devops/eslint/configs.ts +10 -0
  150. package/src/devops/eslint/index.ts +3 -0
  151. package/src/devops/eslint/utils/compose-eslint-config/index.ts +29 -0
  152. package/src/devops/eslint/utils/compose-eslint-config/type.ts +3 -0
  153. package/src/devops/eslint/utils/index.ts +1 -0
  154. 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,11 @@
1
+ import { isArray } from '../array/index.js';
2
+ import { isNull } from '../null/index.js';
3
+ export const isObject = (data) => {
4
+ if (typeof data !== 'object') {
5
+ return false;
6
+ }
7
+ if (isNull(data)) {
8
+ return false;
9
+ }
10
+ return !isArray(data);
11
+ };
@@ -0,0 +1,2 @@
1
+ import { Linter } from 'eslint';
2
+ export declare const ESLINT_RULES: Partial<Linter.RulesRecord>;
@@ -0,0 +1,8 @@
1
+ export const ESLINT_RULES = {
2
+ 'no-console': [
3
+ 2,
4
+ {
5
+ allow: ['error', 'info'],
6
+ },
7
+ ],
8
+ };
@@ -0,0 +1,2 @@
1
+ export * from './configs.js';
2
+ export * from './utils/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './configs.js';
2
+ export * from './utils/index.js';
@@ -0,0 +1,2 @@
1
+ import { ComposeEslintConfig } from './type.js';
2
+ export declare const composeEslintConfig: ComposeEslintConfig;
@@ -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,4 @@
1
+ import { Config } from 'typescript-eslint';
2
+ export type ComposeEslintConfig = (props?: {
3
+ ignores?: string[];
4
+ }) => Config;
@@ -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,5 @@
1
+ import { EnvironmentMode, EnvironmentVariables, TError } from '../../../../../common';
2
+
3
+ export type LoadEnvFile = <T extends Array<keyof EnvironmentVariables> = never>(
4
+ environmentMode?: EnvironmentMode,
5
+ ) => TError<{ [K in T[number]]: EnvironmentVariables[K] }>;
@@ -0,0 +1 @@
1
+ export * from './env-file';
@@ -0,0 +1 @@
1
+ export const ENVIRONMENT_MODES = ['development', 'production'] as const;
@@ -0,0 +1,3 @@
1
+ import { ENVIRONMENT_MODES } from './configs';
2
+
3
+ export type EnvironmentMode = (typeof ENVIRONMENT_MODES)[number];
@@ -0,0 +1,5 @@
1
+ export * from './configs';
2
+
3
+ export * from './domains';
4
+
5
+ export * from './type-guards';
@@ -0,0 +1,5 @@
1
+ export * from './is-development';
2
+
3
+ export * from './is-environment-mode';
4
+
5
+ export * from './is-production';
@@ -0,0 +1 @@
1
+ export const isDevelopment = (data?: unknown): data is 'development' => data === 'development';
@@ -0,0 +1,4 @@
1
+ import { ENVIRONMENT_MODES } from '../configs';
2
+ import { EnvironmentMode } from '../domains';
3
+
4
+ export const isEnvironmentMode = (data?: unknown): data is EnvironmentMode => ENVIRONMENT_MODES.some((it) => data === it);
@@ -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,3 @@
1
+ export * from './domains';
2
+
3
+ export * from './singletons';
@@ -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,3 @@
1
+ export * from './environment-mode';
2
+
3
+ export * from './environment-variables';
@@ -0,0 +1,8 @@
1
+ export interface Error {
2
+ id: string;
3
+ info?: Record<string, unknown>;
4
+ message: string;
5
+ serviceName?: string;
6
+ }
7
+
8
+ export type TError<T = never> = { data: T; error?: never } | { error: Error; data?: never };
@@ -0,0 +1,5 @@
1
+ export * from './domains';
2
+
3
+ export * from './utils';
4
+
5
+ export * from './workers';
@@ -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,3 @@
1
+ import { Error } from '../../domains';
2
+
3
+ export type ComposeError = (message?: string, info?: Record<string, unknown>) => Error;
@@ -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,3 @@
1
+ import { Error } from '../../domains';
2
+
3
+ export type ConsoleError = (error: Error) => void;
@@ -0,0 +1,3 @@
1
+ export * from './compose-error';
2
+
3
+ export * from './console-error';
@@ -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,3 @@
1
+ export * from './reveal-all-object-props';
2
+
3
+ export * from './stringify';
@@ -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,5 @@
1
+ import { isObject } from '../../type';
2
+ import { revealAllObjectProps } from '../reveal-all-object-props';
3
+ import { Stringify } from './type';
4
+
5
+ export const stringify: Stringify = (obj) => JSON.stringify(isObject(obj) ? revealAllObjectProps(obj) : obj);
@@ -0,0 +1 @@
1
+ export type Stringify = (obj: unknown) => string;
@@ -0,0 +1,9 @@
1
+ export * from './environment';
2
+
3
+ export * from './error';
4
+
5
+ export * from './helpers';
6
+
7
+ export * from './service';
8
+
9
+ export * from './type';
@@ -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,3 @@
1
+ export type GetServiceName = () => string;
2
+
3
+ export type Init = (serviceName: string) => void;
@@ -0,0 +1 @@
1
+ export * from './type-guards';
@@ -0,0 +1,11 @@
1
+ export const isArray = <T>(data?: unknown, typeGuard?: (data?: unknown) => data is T): data is T[] => {
2
+ if (!Array.isArray(data)) {
3
+ return false;
4
+ }
5
+
6
+ if (typeGuard && !data.every((a) => typeGuard(a))) {
7
+ return false;
8
+ }
9
+
10
+ return true;
11
+ };
@@ -0,0 +1,5 @@
1
+ export * from './array';
2
+
3
+ export * from './null';
4
+
5
+ export * from './object';
@@ -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,10 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ export const ESLINT_RULES: Partial<Linter.RulesRecord> = {
4
+ 'no-console': [
5
+ 2,
6
+ {
7
+ allow: ['error', 'info'],
8
+ },
9
+ ],
10
+ };
@@ -0,0 +1,3 @@
1
+ export * from './configs';
2
+
3
+ export * from './utils';
@@ -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,3 @@
1
+ import { Config } from 'typescript-eslint';
2
+
3
+ export type ComposeEslintConfig = (props?: { ignores?: string[] }) => Config;
@@ -0,0 +1 @@
1
+ export * from './compose-eslint-config';
@@ -0,0 +1 @@
1
+ export * from './eslint';