@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,29 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ ARRAY=(${1//,/ })
5
+
6
+ NAMES_ARRAY[0]="${ARRAY[@]:0:10}"
7
+ NAMES_ARRAY[1]="${ARRAY[@]:10:20}"
8
+ NAMES_ARRAY[2]="${ARRAY[@]:20:30}"
9
+
10
+ ENVS=()
11
+ for NAMES in "${NAMES_ARRAY[@]}"
12
+ do
13
+ if [ -n "$NAMES" ]; then
14
+ PARAMS=$(aws ssm get-parameters --names $NAMES --output text --query "Parameters[*].{Name:Name,Value:Value}" --with-decryption | sed -E 's/\s+/=/g')
15
+ PARAMS1="${PARAMS[@]//_DEVELOPMENT/}"
16
+ PARAMS2="${PARAMS1[@]//_PRODUCTION/}"
17
+ PARAMS3="${PARAMS2[@]//AMAZONWEBSERVICES/AWS}"
18
+ ENVS+=("$PARAMS3")
19
+ fi
20
+ done
21
+
22
+ if [[ $2 ]]
23
+ then
24
+ FILENAME=".env.$2"
25
+ else
26
+ FILENAME=".env"
27
+ fi
28
+
29
+ printf "%s\n" "${ENVS[@]}" > $FILENAME
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ npx eslint .
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ ./devops/environment/create-env-file.sh NPM_ACCESS_TOKEN
5
+
6
+ source .env
7
+
8
+ npm config set //registry.npmjs.org/:_authToken ${NPM_ACCESS_TOKEN}
9
+
10
+ npm publish . --access=public
@@ -0,0 +1,7 @@
1
+ export const PRETTIER_CONFIG = {
2
+ semi: true,
3
+ printWidth: 150,
4
+ singleQuote: true,
5
+ tabWidth: 2,
6
+ trailingComma: 'all',
7
+ };
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ npx prettier . --write
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ ./devops/prettier/prettier.sh
5
+
6
+ ./devops/eslint/eslint.sh
7
+
8
+ ./devops/typescript/tsc-build.sh
9
+
10
+ git-push.sh
11
+
12
+ ./devops/npm/publish-to-npm.sh
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ rm -rf dist
5
+ npx tsc
6
+ npx tsc-alias
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ rm -rf dist
5
+ npx tsc --watch
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "esModuleInterop": true,
5
+ "module": "ES2022",
6
+ "moduleResolution": "bundler",
7
+ "outDir": "${configDir}/dist",
8
+ "rootDir": "${configDir}/src",
9
+ "skipLibCheck": true,
10
+ "strict": true,
11
+ "target": "ES2022"
12
+ },
13
+ "tsc-alias": {
14
+ "verbose": false,
15
+ "resolveFullPaths": true
16
+ },
17
+ "include": ["${configDir}/src/**/*"]
18
+ }
@@ -0,0 +1 @@
1
+ export * from './utils/index.js';
@@ -0,0 +1 @@
1
+ export * from './utils/index.js';
@@ -0,0 +1 @@
1
+ export * from './load-env-file/index.js';
@@ -0,0 +1 @@
1
+ export * from './load-env-file/index.js';
@@ -0,0 +1,2 @@
1
+ import { LoadEnvFile } from './type.js';
2
+ export declare const loadEnvFile: LoadEnvFile;
@@ -0,0 +1,47 @@
1
+ import fs from 'fs';
2
+ import { ErrorWorker } from '../../../../../common/index.js';
3
+ export const loadEnvFile = (environmentMode) => {
4
+ const { composeError } = ErrorWorker({ info: { environmentMode } });
5
+ let fileName = '.env';
6
+ if (environmentMode) {
7
+ fileName += `.${environmentMode}`;
8
+ }
9
+ const parsed = {};
10
+ try {
11
+ const file = fs.readFileSync(fileName, 'utf-8');
12
+ file.split('\n').forEach((fileLine) => {
13
+ if (fileLine.length === 0) {
14
+ return;
15
+ }
16
+ const envVar = fileLine.split('=');
17
+ parsed[`${envVar[0]}`] = envVar[1];
18
+ });
19
+ }
20
+ catch (err) {
21
+ return {
22
+ error: composeError(`Error loading ${fileName}`, {
23
+ info: {
24
+ err,
25
+ fileName,
26
+ },
27
+ }),
28
+ };
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ const data = {};
32
+ Object.keys(parsed).forEach((key) => {
33
+ const parsedItem = parsed[key];
34
+ if (['false', 'true'].includes(parsedItem)) {
35
+ data[key] = Boolean(parsedItem === 'true');
36
+ }
37
+ else if (!Number.isNaN(parseInt(parsedItem))) {
38
+ data[key] = parseInt(parsedItem);
39
+ }
40
+ else {
41
+ data[key] = parsedItem;
42
+ }
43
+ });
44
+ return {
45
+ data,
46
+ };
47
+ };
@@ -0,0 +1,4 @@
1
+ import { EnvironmentMode, EnvironmentVariables, TError } from '../../../../../common/index.js';
2
+ export type LoadEnvFile = <T extends Array<keyof EnvironmentVariables> = never>(environmentMode?: EnvironmentMode) => TError<{
3
+ [K in T[number]]: EnvironmentVariables[K];
4
+ }>;
@@ -0,0 +1 @@
1
+ export * from './env-file/index.js';
@@ -0,0 +1 @@
1
+ export * from './env-file/index.js';
@@ -0,0 +1 @@
1
+ export declare const ENVIRONMENT_MODES: readonly ["development", "production"];
@@ -0,0 +1 @@
1
+ export const ENVIRONMENT_MODES = ['development', 'production'];
@@ -0,0 +1,2 @@
1
+ import { ENVIRONMENT_MODES } from './configs.js';
2
+ export type EnvironmentMode = (typeof ENVIRONMENT_MODES)[number];
@@ -0,0 +1,3 @@
1
+ export * from './configs.js';
2
+ export * from './domains.js';
3
+ export * from './type-guards/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './configs.js';
2
+ export * from './domains.js';
3
+ export * from './type-guards/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './is-development.js';
2
+ export * from './is-environment-mode.js';
3
+ export * from './is-production.js';
@@ -0,0 +1,3 @@
1
+ export * from './is-development.js';
2
+ export * from './is-environment-mode.js';
3
+ export * from './is-production.js';
@@ -0,0 +1 @@
1
+ export declare const isDevelopment: (data?: unknown) => data is "development";
@@ -0,0 +1 @@
1
+ export const isDevelopment = (data) => data === 'development';
@@ -0,0 +1,2 @@
1
+ import { EnvironmentMode } from '../domains.js';
2
+ export declare const isEnvironmentMode: (data?: unknown) => data is EnvironmentMode;
@@ -0,0 +1,2 @@
1
+ import { ENVIRONMENT_MODES } from '../configs.js';
2
+ export const isEnvironmentMode = (data) => ENVIRONMENT_MODES.some((it) => data === it);
@@ -0,0 +1 @@
1
+ export declare const isProduction: (data?: unknown) => data is "production";
@@ -0,0 +1 @@
1
+ export const isProduction = (data) => data === 'production';
@@ -0,0 +1,18 @@
1
+ import { EnvironmentMode } from '../environment-mode/index.js';
2
+ export type EnvironmentVariables = {
3
+ APP_NAME: string;
4
+ AWS_REGION: string;
5
+ AWS_S3_IMAGES_BUCKET_NAME: string;
6
+ CACHE_SERVICE_PORT: string;
7
+ CACHE_ENABLED: boolean;
8
+ DATABASE_URL: string;
9
+ DOMAIN_NAME: string;
10
+ FRONTEND_URL: string;
11
+ LOGGER_SERVICE_PORT: string;
12
+ MOBILE_APP_URL: string;
13
+ NODE_ENV: EnvironmentMode;
14
+ RABBITMQ_URL: string;
15
+ REDIS_PWD: string;
16
+ REDIS_URL: string;
17
+ REDIS_URL_APP: string;
18
+ };
@@ -0,0 +1,2 @@
1
+ export * from './domains.js';
2
+ export * from './singletons/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './domains.js';
2
+ export * from './singletons/index.js';
@@ -0,0 +1,8 @@
1
+ import { GetEnv, GetEnvs, Init, IsDevelopment, IsProduction } from './type.js';
2
+ export declare const EnvironmentVariablesSingleton: {
3
+ getEnv: GetEnv;
4
+ getEnvs: GetEnvs;
5
+ init: Init;
6
+ isDevelopment: IsDevelopment;
7
+ isProduction: IsProduction;
8
+ };
@@ -0,0 +1,20 @@
1
+ import { isDevelopment as isDev, isProduction as isProd } from '../../environment-mode/index.js';
2
+ export const EnvironmentVariablesSingleton = (() => {
3
+ let _envs;
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ const getEnv = (name) => _envs[name];
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ const getEnvs = (names) => names.reduce((acc, curr) => ({ ...acc, [`${curr}`]: _envs[curr] }), {});
8
+ const init = (envs) => {
9
+ _envs = envs;
10
+ };
11
+ const isDevelopment = () => isDev(_envs.NODE_ENV);
12
+ const isProduction = () => isProd(_envs.NODE_ENV);
13
+ return {
14
+ getEnv,
15
+ getEnvs,
16
+ init,
17
+ isDevelopment,
18
+ isProduction,
19
+ };
20
+ })();
@@ -0,0 +1,6 @@
1
+ import { EnvironmentVariables } from '../domains.js';
2
+ export type GetEnv = <T extends keyof EnvironmentVariables = never>(name: T) => EnvironmentVariables[T];
3
+ export type GetEnvs = <T extends keyof EnvironmentVariables = never>(names: T[]) => Pick<EnvironmentVariables, T>;
4
+ export type Init = (envs: Partial<EnvironmentVariables>) => void;
5
+ export type IsDevelopment = () => boolean;
6
+ export type IsProduction = () => boolean;
@@ -0,0 +1,2 @@
1
+ export * from './environment-mode/index.js';
2
+ export * from './environment-variables/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './environment-mode/index.js';
2
+ export * from './environment-variables/index.js';
@@ -0,0 +1,13 @@
1
+ export interface Error {
2
+ id: string;
3
+ info?: Record<string, unknown>;
4
+ message: string;
5
+ serviceName?: string;
6
+ }
7
+ export type TError<T = never> = {
8
+ data: T;
9
+ error?: never;
10
+ } | {
11
+ error: Error;
12
+ data?: never;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './domains.js';
2
+ export * from './utils/index.js';
3
+ export * from './workers/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './domains.js';
2
+ export * from './utils/index.js';
3
+ export * from './workers/index.js';
@@ -0,0 +1,2 @@
1
+ import { ComposeError } from './type.js';
2
+ export declare const composeError: ComposeError;
@@ -0,0 +1,7 @@
1
+ import { ServiceSingleton } from '../../../service/index.js';
2
+ export const composeError = (message, info) => ({
3
+ id: Math.random().toString(16).slice(2).toUpperCase(),
4
+ info,
5
+ message: message ?? '',
6
+ serviceName: ServiceSingleton.getServiceName(),
7
+ });
@@ -0,0 +1,2 @@
1
+ import { Error } from '../../domains.js';
2
+ export type ComposeError = (message?: string, info?: Record<string, unknown>) => Error;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ConsoleError } from './type.js';
2
+ export declare const consoleError: ConsoleError;
@@ -0,0 +1,12 @@
1
+ import { stringify } from '../../../helpers/index.js';
2
+ export const consoleError = (error) => {
3
+ const { id, info, message, serviceName } = error;
4
+ let msg = `ERROR: ${message} (ID) ${id}`;
5
+ if (serviceName) {
6
+ msg += ` (SERVICE-NAME) ${serviceName}`;
7
+ }
8
+ if (info) {
9
+ msg += ` (INFO) ${stringify(info)}`;
10
+ }
11
+ console.error(msg);
12
+ };
@@ -0,0 +1,2 @@
1
+ import { Error } from '../../domains.js';
2
+ export type ConsoleError = (error: Error) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './compose-error/index.js';
2
+ export * from './console-error/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './compose-error/index.js';
2
+ export * from './console-error/index.js';
@@ -0,0 +1,2 @@
1
+ import { ErrorWorkerType } from './type.js';
2
+ export declare const ErrorWorker: ErrorWorkerType;
@@ -0,0 +1,32 @@
1
+ import { composeError as composeErrorFunc } from '../utils/index.js';
2
+ export const ErrorWorker = (props) => {
3
+ let _error = props ? composeErrorFunc(props.message, props.info) : undefined;
4
+ const _composeInfo = (info) => {
5
+ if (_error) {
6
+ _error.info = {
7
+ ..._error.info,
8
+ ...info,
9
+ };
10
+ return;
11
+ }
12
+ _error = composeErrorFunc(undefined, info);
13
+ };
14
+ const addErrorInfo = (info) => {
15
+ _composeInfo(info);
16
+ };
17
+ const addErrorMessage = (message) => {
18
+ _error = composeErrorFunc(message);
19
+ };
20
+ const composeError = (message, info) => composeErrorFunc(message, info ?? _error?.info);
21
+ const getError = () => (_error ? { error: _error } : undefined);
22
+ const resetError = () => {
23
+ _error = undefined;
24
+ };
25
+ return {
26
+ addErrorInfo,
27
+ addErrorMessage,
28
+ composeError,
29
+ getError,
30
+ resetError,
31
+ };
32
+ };
@@ -0,0 +1,19 @@
1
+ import { Error } from '../domains.js';
2
+ export type ErrorWorkerType = (props?: {
3
+ message?: string;
4
+ info?: Record<string, unknown>;
5
+ }) => {
6
+ addErrorInfo: AddErrorInfo;
7
+ addErrorMessage: AddErrorMessage;
8
+ composeError: ComposeError;
9
+ getError: GetError;
10
+ resetError: ResetError;
11
+ };
12
+ export type _ComposeInfo = (info?: Record<string, unknown>) => void;
13
+ export type AddErrorInfo = (info: Record<string, unknown>) => void;
14
+ export type AddErrorMessage = (message: string) => void;
15
+ export type ComposeError = (message: string, info?: Record<string, unknown>) => Error;
16
+ export type GetError = () => {
17
+ error: Error;
18
+ } | undefined;
19
+ export type ResetError = () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './reveal-all-object-props/index.js';
2
+ export * from './stringify/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './reveal-all-object-props/index.js';
2
+ export * from './stringify/index.js';
@@ -0,0 +1,2 @@
1
+ import { RevealAllObjectProps } from './type.js';
2
+ export declare const revealAllObjectProps: RevealAllObjectProps;
@@ -0,0 +1,13 @@
1
+ import { isObject } from '../../type/index.js';
2
+ export const revealAllObjectProps = (obj) => {
3
+ const newObj = {};
4
+ Object.getOwnPropertyNames(obj).forEach((key) => {
5
+ if (isObject(obj[key])) {
6
+ newObj[key] = revealAllObjectProps(obj[key]);
7
+ }
8
+ else {
9
+ newObj[key] = obj[key];
10
+ }
11
+ });
12
+ return newObj;
13
+ };
@@ -0,0 +1 @@
1
+ export type RevealAllObjectProps = (obj: Record<string, unknown>) => Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import { Stringify } from './type.js';
2
+ export declare const stringify: Stringify;
@@ -0,0 +1,3 @@
1
+ import { isObject } from '../../type/index.js';
2
+ import { revealAllObjectProps } from '../reveal-all-object-props/index.js';
3
+ export const stringify = (obj) => JSON.stringify(isObject(obj) ? revealAllObjectProps(obj) : obj);
@@ -0,0 +1 @@
1
+ export type Stringify = (obj: unknown) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './environment/index.js';
2
+ export * from './error/index.js';
3
+ export * from './helpers/index.js';
4
+ export * from './service/index.js';
5
+ export * from './type/index.js';
@@ -0,0 +1,5 @@
1
+ export * from './environment/index.js';
2
+ export * from './error/index.js';
3
+ export * from './helpers/index.js';
4
+ export * from './service/index.js';
5
+ export * from './type/index.js';
@@ -0,0 +1 @@
1
+ export * from './singletons/index.js';
@@ -0,0 +1 @@
1
+ export * from './singletons/index.js';
@@ -0,0 +1,5 @@
1
+ import { GetServiceName, Init } from './type.js';
2
+ export declare const ServiceSingleton: {
3
+ getServiceName: GetServiceName;
4
+ init: Init;
5
+ };
@@ -0,0 +1,11 @@
1
+ export const ServiceSingleton = (() => {
2
+ let _serviceName;
3
+ const getServiceName = () => _serviceName;
4
+ const init = (serviceName) => {
5
+ _serviceName = serviceName;
6
+ };
7
+ return {
8
+ getServiceName,
9
+ init,
10
+ };
11
+ })();
@@ -0,0 +1,2 @@
1
+ export type GetServiceName = () => string;
2
+ export type Init = (serviceName: string) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './type-guards.js';
@@ -0,0 +1 @@
1
+ export * from './type-guards.js';
@@ -0,0 +1 @@
1
+ export declare const isArray: <T>(data?: unknown, typeGuard?: (data?: unknown) => data is T) => data is T[];
@@ -0,0 +1,9 @@
1
+ export const isArray = (data, typeGuard) => {
2
+ if (!Array.isArray(data)) {
3
+ return false;
4
+ }
5
+ if (typeGuard && !data.every((a) => typeGuard(a))) {
6
+ return false;
7
+ }
8
+ return true;
9
+ };
@@ -0,0 +1,3 @@
1
+ export * from './array/index.js';
2
+ export * from './null/index.js';
3
+ export * from './object/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './array/index.js';
2
+ export * from './null/index.js';
3
+ export * from './object/index.js';
@@ -0,0 +1 @@
1
+ export * from './type-guards.js';
@@ -0,0 +1 @@
1
+ export * from './type-guards.js';
@@ -0,0 +1 @@
1
+ export declare const isNull: (data?: unknown) => data is null;
@@ -0,0 +1 @@
1
+ export const isNull = (data) => data === null;
@@ -0,0 +1 @@
1
+ export * from './type-guards.js';