@atlantjs/backend 4.1.0 → 5.0.1
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/backend/application/databases/database.config.js +2 -2
- package/backend/application/env/env-vars.d.ts +3 -3
- package/backend/application/env/env-vars.js +32 -14
- package/index.d.ts +1 -1
- package/index.js +3 -3
- package/package.json +1 -1
- package/setup/parchment/parchment.d.ts +5 -0
- package/setup/parchment/parchment.js +69 -0
- package/setup/parchment/parchment.type.d.ts +9 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/setup/env-var/env-var.type.d.ts +0 -15
- package/setup/env-var/index.d.ts +0 -16
- package/setup/env-var/index.js +0 -111
- /package/setup/{env-var/env-var.error.d.ts → parchment/parchment.error.d.ts} +0 -0
- /package/setup/{env-var/env-var.error.js → parchment/parchment.error.js} +0 -0
- /package/setup/{env-var/env-var.type.js → parchment/parchment.type.js} +0 -0
|
@@ -23,7 +23,7 @@ class DatabaseConfigAbstract {
|
|
|
23
23
|
password: this.props.adminPassword,
|
|
24
24
|
database: this.props.name,
|
|
25
25
|
schema: this.props.schemaName,
|
|
26
|
-
synchronize: env_vars_1.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED,
|
|
26
|
+
synchronize: arch_1._.isEqual(env_vars_1.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED, "true"),
|
|
27
27
|
entities: this.props.schemaPaths,
|
|
28
28
|
migrations: this.props.migrationPaths,
|
|
29
29
|
};
|
|
@@ -34,7 +34,7 @@ class DatabaseConfigAbstract {
|
|
|
34
34
|
resourceArn: this.props.resourceArn ?? "",
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
if (arch_1._.
|
|
37
|
+
if (arch_1._.isEqual(env_vars_1.DATABASE_SSL_ENABLED, "true")) {
|
|
38
38
|
Object.assign(baseConfig, this.sslConfig);
|
|
39
39
|
}
|
|
40
40
|
this.configs = new typeorm_1.DataSource(baseConfig);
|
|
@@ -5,11 +5,11 @@ export declare const DATABASE_NAME: string;
|
|
|
5
5
|
export declare const DATABASE_DEFAULT_SCHEMA: string;
|
|
6
6
|
export declare const DATABASE_HOST: string;
|
|
7
7
|
export declare const DATABASE_ADMIN_PASSWORD: string;
|
|
8
|
-
export declare const DATABASE_PORT:
|
|
8
|
+
export declare const DATABASE_PORT: number;
|
|
9
9
|
export declare const DATABASE_ADMIN_USER: string;
|
|
10
10
|
export declare const DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED: boolean;
|
|
11
11
|
export declare const DATABASE_SSL_ENABLED: boolean;
|
|
12
|
-
export declare const APP_PORT:
|
|
13
|
-
export declare const LOAD_MODULES: string;
|
|
12
|
+
export declare const APP_PORT: number;
|
|
13
|
+
export declare const LOAD_MODULES: string[];
|
|
14
14
|
export declare const CORS_ALLOWED_ORIGINS: string;
|
|
15
15
|
export declare const ENVIRONMENT: NodeEnvs;
|
|
@@ -2,65 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ENVIRONMENT = exports.CORS_ALLOWED_ORIGINS = exports.LOAD_MODULES = exports.APP_PORT = exports.DATABASE_SSL_ENABLED = exports.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED = exports.DATABASE_ADMIN_USER = exports.DATABASE_PORT = exports.DATABASE_ADMIN_PASSWORD = exports.DATABASE_HOST = exports.DATABASE_DEFAULT_SCHEMA = exports.DATABASE_NAME = exports.DATABASE_TYPE = void 0;
|
|
4
4
|
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
const
|
|
6
|
-
exports.DATABASE_TYPE =
|
|
5
|
+
const parchment_1 = require("../../../setup/parchment/parchment");
|
|
6
|
+
exports.DATABASE_TYPE = parchment_1.Parchment.verse({
|
|
7
7
|
name: "DATABASE_TYPE",
|
|
8
8
|
type: "enum",
|
|
9
9
|
description: "The type of the database",
|
|
10
10
|
default: "postgres",
|
|
11
11
|
values: ["aurora-postgres", "postgres", "sqlite"],
|
|
12
|
+
isRequired: true,
|
|
12
13
|
});
|
|
13
|
-
exports.DATABASE_NAME =
|
|
14
|
+
exports.DATABASE_NAME = parchment_1.Parchment.verse({
|
|
14
15
|
name: "DATABASE_NAME",
|
|
16
|
+
type: "text",
|
|
15
17
|
description: "The name of the database",
|
|
18
|
+
isRequired: true,
|
|
16
19
|
});
|
|
17
|
-
exports.DATABASE_DEFAULT_SCHEMA =
|
|
20
|
+
exports.DATABASE_DEFAULT_SCHEMA = parchment_1.Parchment.verse({
|
|
18
21
|
name: "DATABASE_DEFAULT_SCHEMA",
|
|
22
|
+
type: "text",
|
|
19
23
|
description: "The name of default schema the database",
|
|
24
|
+
isRequired: true,
|
|
20
25
|
});
|
|
21
|
-
exports.DATABASE_HOST =
|
|
26
|
+
exports.DATABASE_HOST = parchment_1.Parchment.verse({
|
|
22
27
|
name: "DATABASE_HOST",
|
|
23
28
|
description: "The host address of the database server",
|
|
29
|
+
type: "text",
|
|
30
|
+
isRequired: true,
|
|
24
31
|
});
|
|
25
|
-
exports.DATABASE_ADMIN_PASSWORD =
|
|
32
|
+
exports.DATABASE_ADMIN_PASSWORD = parchment_1.Parchment.verse({
|
|
26
33
|
name: "DATABASE_ADMIN_PASSWORD",
|
|
27
34
|
description: "The password for the database user",
|
|
35
|
+
type: "text",
|
|
36
|
+
isRequired: true,
|
|
28
37
|
});
|
|
29
|
-
exports.DATABASE_PORT =
|
|
38
|
+
exports.DATABASE_PORT = parchment_1.Parchment.verse({
|
|
30
39
|
name: "DATABASE_PORT",
|
|
31
40
|
type: "port-number",
|
|
32
41
|
description: "The port number on which the database server is running",
|
|
42
|
+
isRequired: true,
|
|
33
43
|
});
|
|
34
|
-
exports.DATABASE_ADMIN_USER =
|
|
44
|
+
exports.DATABASE_ADMIN_USER = parchment_1.Parchment.verse({
|
|
35
45
|
name: "DATABASE_ADMIN_USER",
|
|
36
46
|
description: "The username for the database database",
|
|
47
|
+
type: "text",
|
|
48
|
+
isRequired: true,
|
|
37
49
|
});
|
|
38
|
-
exports.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED =
|
|
50
|
+
exports.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED = parchment_1.Parchment.verse({
|
|
39
51
|
name: "DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED",
|
|
40
52
|
type: "boolean",
|
|
41
53
|
description: "Flag indicating whether the ORM automatically creates tables in the database based on .schema.ts files",
|
|
54
|
+
isRequired: true,
|
|
42
55
|
});
|
|
43
|
-
exports.DATABASE_SSL_ENABLED =
|
|
56
|
+
exports.DATABASE_SSL_ENABLED = parchment_1.Parchment.verse({
|
|
44
57
|
name: "DATABASE_SSL_ENABLED",
|
|
45
58
|
type: "boolean",
|
|
46
59
|
description: "Flag indicating whether the database requires an SSL connection",
|
|
60
|
+
isRequired: true,
|
|
47
61
|
});
|
|
48
|
-
exports.APP_PORT =
|
|
62
|
+
exports.APP_PORT = parchment_1.Parchment.verse({
|
|
49
63
|
name: "APP_PORT",
|
|
50
64
|
type: "port-number",
|
|
51
65
|
description: "The port number on which the application will run",
|
|
66
|
+
isRequired: true,
|
|
52
67
|
});
|
|
53
|
-
exports.LOAD_MODULES =
|
|
68
|
+
exports.LOAD_MODULES = parchment_1.Parchment.verse({
|
|
54
69
|
name: "LOAD_MODULES",
|
|
55
70
|
type: "array",
|
|
56
71
|
description: "List of modules, separated by commas, to be loaded by the application",
|
|
72
|
+
isRequired: true,
|
|
57
73
|
});
|
|
58
|
-
exports.CORS_ALLOWED_ORIGINS =
|
|
74
|
+
exports.CORS_ALLOWED_ORIGINS = parchment_1.Parchment.verse({
|
|
59
75
|
name: "CORS_ALLOWED_ORIGINS",
|
|
60
76
|
default: "*",
|
|
61
77
|
description: "Allowed origins for CORS",
|
|
78
|
+
type: "text",
|
|
79
|
+
isRequired: true,
|
|
62
80
|
});
|
|
63
|
-
exports.ENVIRONMENT =
|
|
81
|
+
exports.ENVIRONMENT = parchment_1.Parchment.verse({
|
|
64
82
|
name: "ENVIRONMENT",
|
|
65
83
|
type: "enum",
|
|
66
84
|
isRequired: true,
|
package/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { IsTimeString } from "./backend/infrastructure/controllers/validators/is
|
|
|
9
9
|
export { DatabaseConfigAbstract } from "./backend/application/databases/database.config";
|
|
10
10
|
export { DatabaseHelperAbstract } from "./backend/application/databases/database.helper.abstract";
|
|
11
11
|
export { APP_PORT, LOAD_MODULES, CORS_ALLOWED_ORIGINS, ENVIRONMENT, DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED, DATABASE_SSL_ENABLED, DATABASE_TYPE, DATABASE_NAME, DATABASE_DEFAULT_SCHEMA, DATABASE_HOST, DATABASE_ADMIN_USER, DATABASE_ADMIN_PASSWORD, DATABASE_PORT, } from "./backend/application/env/env-vars";
|
|
12
|
-
export {
|
|
12
|
+
export { Parchment } from "./setup/parchment/parchment";
|
|
13
13
|
export { InjectionsAbstract } from "./backend/application/injections.abstract";
|
|
14
14
|
export { PrimaryColumn, Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne, ManyToMany, BeforeInsert, BeforeUpdate, } from "typeorm";
|
|
15
15
|
export { EntityAbstract } from "./backend/domain/entities/entity.abstract";
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DatabaseConfigAbstract = exports.IsTimeString = exports.IsPayload = exports.registerDecorator = exports.IsNotEmptyObject = exports.IsDateString = exports.IsObject = exports.IsArray = exports.IsString = exports.IsInt = exports.IsEnum = exports.IsNumber = exports.IsDate = exports.IsBoolean = exports.IsNumberString = exports.IsUrl = exports.IsUUID = exports.IsJWT = exports.IsJSON = exports.IsPort = exports.IsIP = exports.IsCurrency = exports.IsEmail = exports.IsBase64 = exports.IsDecimal = exports.MaxDate = exports.MinDate = exports.Min = exports.Max = exports.IsNegative = exports.IsPositive = exports.IsNotEmpty = exports.IsEmpty = exports.IsLongitude = exports.IsLatitude = exports.IsLatLong = exports.ValidateInner = exports.IsOptional = exports.Params = exports.Param = exports.Req = exports.Body = exports.Res = exports.JsonController = exports.UseBefore = exports.Patch = exports.Delete = exports.Post = exports.Get = exports.getFromContainer = void 0;
|
|
4
|
-
exports.initializeApi = exports.DatabaseLiteConfigAbstract = exports.injectable = exports.inject = exports.Container = exports.Server = exports.DefaultErrorHandlerMiddleware = exports.CorsMiddleware = exports.BodyParserMiddleware = exports.DiContainerAbstract = exports.diContainer = exports.startContainer = exports.SchemaAbstract = exports.ResponseAbstract = exports.ValidatorAbstract = exports.PayloadAbstract = exports.ControllerAbstract = exports.CommandAbstract = exports.ServiceAbstract = exports.RepositoryAbstract = exports.ProviderAbstract = exports.MiddlewareHandlerAbstract = exports.EntityAbstract = exports.BeforeUpdate = exports.BeforeInsert = exports.ManyToMany = exports.OneToOne = exports.OneToMany = exports.ManyToOne = exports.JoinColumn = exports.Entity = exports.Column = exports.PrimaryColumn = exports.InjectionsAbstract = exports.
|
|
4
|
+
exports.initializeApi = exports.DatabaseLiteConfigAbstract = exports.injectable = exports.inject = exports.Container = exports.Server = exports.DefaultErrorHandlerMiddleware = exports.CorsMiddleware = exports.BodyParserMiddleware = exports.DiContainerAbstract = exports.diContainer = exports.startContainer = exports.SchemaAbstract = exports.ResponseAbstract = exports.ValidatorAbstract = exports.PayloadAbstract = exports.ControllerAbstract = exports.CommandAbstract = exports.ServiceAbstract = exports.RepositoryAbstract = exports.ProviderAbstract = exports.MiddlewareHandlerAbstract = exports.EntityAbstract = exports.BeforeUpdate = exports.BeforeInsert = exports.ManyToMany = exports.OneToOne = exports.OneToMany = exports.ManyToOne = exports.JoinColumn = exports.Entity = exports.Column = exports.PrimaryColumn = exports.InjectionsAbstract = exports.Parchment = exports.DATABASE_PORT = exports.DATABASE_ADMIN_PASSWORD = exports.DATABASE_ADMIN_USER = exports.DATABASE_HOST = exports.DATABASE_DEFAULT_SCHEMA = exports.DATABASE_NAME = exports.DATABASE_TYPE = exports.DATABASE_SSL_ENABLED = exports.DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED = exports.ENVIRONMENT = exports.CORS_ALLOWED_ORIGINS = exports.LOAD_MODULES = exports.APP_PORT = exports.DatabaseHelperAbstract = void 0;
|
|
5
5
|
require("./backend/application/env/load-envs");
|
|
6
6
|
require("reflect-metadata");
|
|
7
7
|
const setup_1 = require("./setup");
|
|
@@ -77,8 +77,8 @@ Object.defineProperty(exports, "DATABASE_HOST", { enumerable: true, get: functio
|
|
|
77
77
|
Object.defineProperty(exports, "DATABASE_ADMIN_USER", { enumerable: true, get: function () { return env_vars_1.DATABASE_ADMIN_USER; } });
|
|
78
78
|
Object.defineProperty(exports, "DATABASE_ADMIN_PASSWORD", { enumerable: true, get: function () { return env_vars_1.DATABASE_ADMIN_PASSWORD; } });
|
|
79
79
|
Object.defineProperty(exports, "DATABASE_PORT", { enumerable: true, get: function () { return env_vars_1.DATABASE_PORT; } });
|
|
80
|
-
var
|
|
81
|
-
Object.defineProperty(exports, "
|
|
80
|
+
var parchment_1 = require("./setup/parchment/parchment");
|
|
81
|
+
Object.defineProperty(exports, "Parchment", { enumerable: true, get: function () { return parchment_1.Parchment; } });
|
|
82
82
|
var injections_abstract_1 = require("./backend/application/injections.abstract");
|
|
83
83
|
Object.defineProperty(exports, "InjectionsAbstract", { enumerable: true, get: function () { return injections_abstract_1.InjectionsAbstract; } });
|
|
84
84
|
var typeorm_1 = require("typeorm");
|
package/package.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Parchment = void 0;
|
|
4
|
+
const arch_1 = require("@atlantjs/arch");
|
|
5
|
+
const parchment_error_1 = require("./parchment.error");
|
|
6
|
+
class Parchment {
|
|
7
|
+
static verse({ ...verse }) {
|
|
8
|
+
const setValue = process.env[verse.name] || verse.default?.toString();
|
|
9
|
+
if (arch_1._.isEmpty(setValue) && verse.isRequired.truthy()) {
|
|
10
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, "The environment variable must have its value defined");
|
|
11
|
+
}
|
|
12
|
+
return Parchment.convertSetValue(verse, setValue);
|
|
13
|
+
}
|
|
14
|
+
static convertSetValue(verse, value) {
|
|
15
|
+
if (arch_1._.isUndefined(value)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (verse.type === "array") {
|
|
19
|
+
return value.split(",");
|
|
20
|
+
}
|
|
21
|
+
if (verse.type === "boolean") {
|
|
22
|
+
if (arch_1._.isAnyOf(value, ["false", "true"]).falsy()) {
|
|
23
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `The value of the environment variable ${value} must be "false" or "true"`);
|
|
24
|
+
}
|
|
25
|
+
return arch_1._.isEqual(value, "true");
|
|
26
|
+
}
|
|
27
|
+
if (verse.type === "enum") {
|
|
28
|
+
if (arch_1._.isUndefined(verse.values)) {
|
|
29
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `A definição da variável de ambiente ${verse.name} deve conter os valores de referencia`);
|
|
30
|
+
}
|
|
31
|
+
if (verse.values.includes(value).falsy()) {
|
|
32
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `A variável ${verse.name} deve conter algum dos seguintes valores: [${verse.values.join(", ")}]`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (verse.type === "float") {
|
|
37
|
+
const floatValue = Number.parseFloat(value);
|
|
38
|
+
if (Number.isNaN(floatValue)) {
|
|
39
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `The value of the environment variable ${verse.name} must be a valid float number`);
|
|
40
|
+
}
|
|
41
|
+
return floatValue;
|
|
42
|
+
}
|
|
43
|
+
if (verse.type === "int") {
|
|
44
|
+
const intValue = Number.parseInt(value, 10);
|
|
45
|
+
if (Number.isNaN(intValue)) {
|
|
46
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser um número inteiro válido`);
|
|
47
|
+
}
|
|
48
|
+
return intValue;
|
|
49
|
+
}
|
|
50
|
+
if (verse.type === "port-number") {
|
|
51
|
+
const portNumber = Number.parseInt(value, 10);
|
|
52
|
+
if (Number.isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {
|
|
53
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser um número de porta válido entre 1 e 65535`);
|
|
54
|
+
}
|
|
55
|
+
return portNumber;
|
|
56
|
+
}
|
|
57
|
+
if (verse.type === "text") {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
if (verse.type === "url-https") {
|
|
61
|
+
const urlPattern = /^https?:\/\/[^\s/$.?#].[^\s]*$/i;
|
|
62
|
+
if (!urlPattern.test(value)) {
|
|
63
|
+
throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser uma URL válida começando com http ou https`);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Parchment = Parchment;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type VerseTypes = "text" | "port-number" | "array" | "enum" | "url-https" | "int" | "boolean" | "float";
|
|
2
|
+
export interface PickVerseType<VerseType> {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
type: VerseTypes;
|
|
6
|
+
values?: string[];
|
|
7
|
+
isRequired: boolean;
|
|
8
|
+
default?: VerseType;
|
|
9
|
+
}
|