@atlantjs/backend 1.2.3 → 1.2.5

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.
@@ -1,6 +1,6 @@
1
1
  import { NodeEnvs } from "@atlantjs/arch";
2
- export declare const APP_PORT: unknown;
3
- export declare const LOAD_MODULES: string[];
2
+ export declare const APP_PORT: string;
3
+ export declare const LOAD_MODULES: string;
4
4
  export declare const CORS_ALLOWED_ORIGINS: string;
5
5
  export declare const ENVIRONMENT: NodeEnvs;
6
6
  export declare const isProdOrHomolog: () => boolean;
@@ -3,32 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isProdOrHomolog = exports.ENVIRONMENT = exports.CORS_ALLOWED_ORIGINS = exports.LOAD_MODULES = exports.APP_PORT = void 0;
4
4
  const env_var_1 = require("../../../setup/env-var");
5
5
  const arch_1 = require("@atlantjs/arch");
6
- exports.APP_PORT = new env_var_1.EnvVar({
6
+ exports.APP_PORT = env_var_1.EnvVar.get({
7
7
  name: "APP_PORT",
8
8
  type: "port-number",
9
9
  description: "The port number on which the application will run",
10
- }).get();
11
- exports.LOAD_MODULES = new env_var_1.EnvVar({
10
+ });
11
+ exports.LOAD_MODULES = env_var_1.EnvVar.get({
12
12
  name: "LOAD_MODULES",
13
13
  type: "array",
14
14
  description: "List of modules, separated by commas, to be loaded by the application",
15
- }).get();
16
- exports.CORS_ALLOWED_ORIGINS = new env_var_1.EnvVar({
15
+ });
16
+ exports.CORS_ALLOWED_ORIGINS = env_var_1.EnvVar.get({
17
17
  name: "CORS_ALLOWED_ORIGINS",
18
- defaultValue: "*",
18
+ default: "*",
19
19
  description: "Allowed origins for CORS",
20
- }).get();
21
- exports.ENVIRONMENT = new env_var_1.EnvVar({
20
+ });
21
+ exports.ENVIRONMENT = env_var_1.EnvVar.get({
22
22
  name: "ENVIRONMENT",
23
23
  type: "enum",
24
24
  isRequired: true,
25
- enumValues: [
25
+ values: [
26
26
  arch_1.NodeEnvs.test,
27
27
  arch_1.NodeEnvs.development,
28
28
  arch_1.NodeEnvs.production,
29
29
  arch_1.NodeEnvs.homolog,
30
30
  ],
31
31
  description: "The current environment in which the application is running",
32
- }).get();
32
+ });
33
33
  const isProdOrHomolog = () => [arch_1.NodeEnvs.homolog, arch_1.NodeEnvs.production].includes(exports.ENVIRONMENT);
34
34
  exports.isProdOrHomolog = isProdOrHomolog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlantjs/backend",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "main": "index.js",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PickEnvError = void 0;
4
4
  class PickEnvError extends Error {
5
5
  constructor(variableName, variableDescription, messageError) {
6
- super(`${messageError}\n - ${variableName}: ${variableDescription}`);
6
+ super(`EnvVarError: \n${messageError}:\n\n ${variableName}: ${variableDescription}`);
7
7
  }
8
8
  }
9
9
  exports.PickEnvError = PickEnvError;
@@ -3,13 +3,13 @@ interface BasePickEnvType<ValueType> {
3
3
  name: string;
4
4
  description: string;
5
5
  type?: Exclude<EnvTypes, "enum">;
6
- enumValues?: string[];
6
+ values?: string[];
7
7
  isRequired?: boolean;
8
- defaultValue?: ValueType;
8
+ default?: ValueType;
9
9
  }
10
10
  interface EnumPickEnvType<ValueType> extends Omit<BasePickEnvType<ValueType>, 'type'> {
11
11
  type: "enum";
12
- enumValues: string[];
12
+ values: string[];
13
13
  }
14
14
  export type PickEnvType<ValueType = string> = BasePickEnvType<ValueType> | EnumPickEnvType<ValueType>;
15
15
  export {};
@@ -1,17 +1,16 @@
1
1
  import { PickEnvType } from "./env-var.type";
2
- export declare class EnvVar<ValueType> {
3
- private variableValue;
4
- private variableName;
5
- private variableType;
6
- private variableDescription;
7
- private enumValues?;
8
- constructor({ name, type, isRequired, defaultValue, enumValues, description }: PickEnvType<ValueType>);
9
- get(): ValueType;
10
- private urlHttpVerify;
11
- private portNumberVerify;
12
- private intVerify;
13
- private floatVerify;
14
- private arrayVerify;
15
- private booleanVerify;
16
- private enumVerify;
2
+ export declare class EnvVar {
3
+ private static variableValue;
4
+ private static variableName;
5
+ private static variableType;
6
+ private static variableDescription;
7
+ private static enumValues?;
8
+ static get<ValueType = string>({ name, type, isRequired, default: defaultValue, values: enumValues, description }: PickEnvType<ValueType>): ValueType;
9
+ private static urlHttpVerify;
10
+ private static portNumberVerify;
11
+ private static intVerify;
12
+ private static floatVerify;
13
+ private static arrayVerify;
14
+ private static booleanVerify;
15
+ private static enumVerify;
17
16
  }
@@ -4,7 +4,7 @@ exports.EnvVar = void 0;
4
4
  const env_var_error_1 = require("./env-var.error");
5
5
  const arch_1 = require("@atlantjs/arch");
6
6
  class EnvVar {
7
- constructor({ name, type = "string", isRequired = true, defaultValue, enumValues, description }) {
7
+ static get({ name, type = "string", isRequired = true, default: defaultValue, values: enumValues, description }) {
8
8
  this.variableValue = process.env[name] || defaultValue?.toString();
9
9
  this.variableType = type;
10
10
  this.variableName = name;
@@ -13,8 +13,6 @@ class EnvVar {
13
13
  if (arch_1.Guardian.isEmpty(this.variableValue) && isRequired.truthy()) {
14
14
  throw new env_var_error_1.PickEnvError(this.variableName, this.variableDescription, `A variável de ambiente tem que ter seu valor definido`);
15
15
  }
16
- }
17
- get() {
18
16
  switch (this.variableType) {
19
17
  case "boolean":
20
18
  this.booleanVerify();
@@ -40,7 +38,7 @@ class EnvVar {
40
38
  }
41
39
  return this.variableValue;
42
40
  }
43
- urlHttpVerify() {
41
+ static urlHttpVerify() {
44
42
  if (arch_1.Guardian.isEmpty(this.variableValue)) {
45
43
  return undefined;
46
44
  }
@@ -50,7 +48,7 @@ class EnvVar {
50
48
  }
51
49
  return this.variableValue;
52
50
  }
53
- portNumberVerify() {
51
+ static portNumberVerify() {
54
52
  if (arch_1.Guardian.isEmpty(this.variableValue)) {
55
53
  return undefined;
56
54
  }
@@ -60,7 +58,7 @@ class EnvVar {
60
58
  }
61
59
  return this.variableValue;
62
60
  }
63
- intVerify() {
61
+ static intVerify() {
64
62
  if (arch_1.Guardian.isEmpty(this.variableValue)) {
65
63
  return undefined;
66
64
  }
@@ -70,7 +68,7 @@ class EnvVar {
70
68
  }
71
69
  return intValue;
72
70
  }
73
- floatVerify() {
71
+ static floatVerify() {
74
72
  if (arch_1.Guardian.isEmpty(this.variableValue)) {
75
73
  return undefined;
76
74
  }
@@ -80,13 +78,13 @@ class EnvVar {
80
78
  }
81
79
  return floatValue;
82
80
  }
83
- arrayVerify() {
81
+ static arrayVerify() {
84
82
  if (arch_1.Guardian.isUndefined(this.variableValue)) {
85
83
  return [];
86
84
  }
87
85
  return this.variableValue.split(",");
88
86
  }
89
- booleanVerify() {
87
+ static booleanVerify() {
90
88
  if (arch_1.Guardian.isEmpty(this.variableValue)) {
91
89
  return undefined;
92
90
  }
@@ -97,7 +95,7 @@ class EnvVar {
97
95
  return true;
98
96
  return false;
99
97
  }
100
- enumVerify() {
98
+ static enumVerify() {
101
99
  if (arch_1.Guardian.isUndefined(this.variableValue)) {
102
100
  return undefined;
103
101
  }