@atlantjs/backend 5.1.0 → 6.0.0
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/README.md +0 -8
- package/backend/application/databases/database-lite.config.js +7 -9
- package/backend/application/databases/database.config.js +18 -20
- package/backend/application/databases/database.helper.abstract.commit.failure.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.commit.failure.js +4 -8
- package/backend/application/databases/database.helper.abstract.d.ts +12 -12
- package/backend/application/databases/database.helper.abstract.delete.failure.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.delete.failure.js +5 -9
- package/backend/application/databases/database.helper.abstract.get-manager.failure.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.get-manager.failure.js +4 -8
- package/backend/application/databases/database.helper.abstract.js +51 -61
- package/backend/application/databases/database.helper.abstract.rollback.failure.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.rollback.failure.js +4 -8
- package/backend/application/databases/database.helper.abstract.write.failure.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.write.failure.js +4 -8
- package/backend/application/env/env-vars.js +19 -22
- package/backend/application/env/load-envs.js +8 -13
- package/backend/application/injections.abstract.js +9 -12
- package/backend/application/injections.abstract.type.js +1 -2
- package/backend/domain/commands/command.abstract.js +1 -5
- package/backend/domain/middlewares/middleware.handler.abstract.js +1 -5
- package/backend/domain/objects/edges/metadata.edge.d.ts +10 -0
- package/backend/domain/objects/edges/metadata.edge.js +21 -0
- package/backend/domain/objects/edges/metadata.polygon.d.ts +4 -0
- package/backend/domain/objects/edges/metadata.polygon.js +1 -0
- package/backend/domain/objects/face.abstract.d.ts +8 -0
- package/backend/domain/objects/face.abstract.js +2 -0
- package/backend/domain/objects/solid.abstract.d.ts +12 -0
- package/backend/domain/objects/solid.abstract.js +9 -0
- package/backend/domain/objects/vertices/vertex.abstract.d.ts +11 -0
- package/backend/domain/objects/vertices/vertex.abstract.js +9 -0
- package/backend/domain/providers/provider.abstract.js +1 -5
- package/backend/domain/repositories/repository.abstract.js +1 -5
- package/backend/domain/services/service.abstract.js +1 -5
- package/backend/infrastructure/controllers/controller.abstract.d.ts +3 -3
- package/backend/infrastructure/controllers/controller.abstract.js +6 -10
- package/backend/infrastructure/controllers/payloads/payload.abstract.js +1 -5
- package/backend/infrastructure/controllers/payloads/validators/validator.abstract.js +1 -5
- package/backend/infrastructure/controllers/responses/response.abstract.d.ts +1 -1
- package/backend/infrastructure/controllers/responses/response.abstract.js +1 -5
- package/backend/infrastructure/controllers/validators/is-time-string.js +4 -7
- package/index.d.ts +2 -2
- package/index.js +34 -137
- package/package.json +3 -5
- package/setup/dependency-injections/di-container.abstract.js +8 -12
- package/setup/dependency-injections/di-container.js +3 -6
- package/setup/dependency-injections/index.js +5 -10
- package/setup/index.js +12 -16
- package/setup/parchment/parchment.error.js +1 -5
- package/setup/parchment/parchment.js +18 -20
- package/setup/parchment/parchment.type.js +1 -2
- package/setup/server/body-parser-middleware.js +7 -16
- package/setup/server/cors-middleware.js +9 -15
- package/setup/server/default-error-handler-middleware.js +11 -18
- package/setup/server/server.js +28 -35
- package/setup/server/unknow.error.d.ts +1 -1
- package/setup/server/unknow.error.js +8 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/backend/domain/entities/entity.abstract.d.ts +0 -9
- package/backend/domain/entities/entity.abstract.js +0 -11
- package/backend/infrastructure/repositories/schemas/schema.abstract.d.ts +0 -8
- package/backend/infrastructure/repositories/schemas/schema.abstract.js +0 -6
package/README.md
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class DatabaseLiteConfigAbstract {
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED } from "../env/env-vars";
|
|
3
|
+
export class DatabaseLiteConfigAbstract {
|
|
4
|
+
props;
|
|
5
|
+
configs;
|
|
7
6
|
constructor(props) {
|
|
8
7
|
this.props = props;
|
|
9
8
|
const baseConfig = {
|
|
10
9
|
type: this.props.type,
|
|
11
10
|
database: this.props.binaryFilePath,
|
|
12
|
-
synchronize:
|
|
11
|
+
synchronize: DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED,
|
|
13
12
|
extra: {
|
|
14
13
|
cipher: "aes-256-cbc",
|
|
15
14
|
key: props.accessKey,
|
|
@@ -17,7 +16,6 @@ class DatabaseLiteConfigAbstract {
|
|
|
17
16
|
entities: props.schemaPaths,
|
|
18
17
|
migrations: props.migrationPaths,
|
|
19
18
|
};
|
|
20
|
-
this.configs = new
|
|
19
|
+
this.configs = new DataSource(baseConfig);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
exports.DatabaseLiteConfigAbstract = DatabaseLiteConfigAbstract;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { _ } from "@atlantjs/arch";
|
|
2
|
+
import { DataSource } from "typeorm";
|
|
3
|
+
import { DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED, DATABASE_SSL_ENABLED, } from "../env/env-vars";
|
|
4
|
+
export class DatabaseConfigAbstract {
|
|
5
|
+
props;
|
|
6
|
+
configs;
|
|
7
|
+
sslConfig = {
|
|
8
|
+
ssl: true,
|
|
9
|
+
extra: {
|
|
10
|
+
ssl: {
|
|
11
|
+
rejectUnauthorized: false,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
8
15
|
constructor(props) {
|
|
9
16
|
this.props = props;
|
|
10
|
-
this.sslConfig = {
|
|
11
|
-
ssl: true,
|
|
12
|
-
extra: {
|
|
13
|
-
ssl: {
|
|
14
|
-
rejectUnauthorized: false,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
17
|
const baseConfig = {
|
|
19
18
|
type: this.props.type,
|
|
20
19
|
host: this.props.host,
|
|
@@ -23,21 +22,20 @@ class DatabaseConfigAbstract {
|
|
|
23
22
|
password: this.props.adminPassword,
|
|
24
23
|
database: this.props.name,
|
|
25
24
|
schema: this.props.schemaName,
|
|
26
|
-
synchronize:
|
|
25
|
+
synchronize: DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED,
|
|
27
26
|
entities: this.props.schemaPaths,
|
|
28
27
|
migrations: this.props.migrationPaths,
|
|
29
28
|
};
|
|
30
|
-
if (
|
|
29
|
+
if (_.isEqual(this.props.type, "aurora-mysql")) {
|
|
31
30
|
Object.assign(baseConfig, {
|
|
32
31
|
region: this.props.region ?? "",
|
|
33
32
|
secretArn: this.props.secretArn ?? "",
|
|
34
33
|
resourceArn: this.props.resourceArn ?? "",
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
if (
|
|
36
|
+
if (DATABASE_SSL_ENABLED) {
|
|
38
37
|
Object.assign(baseConfig, this.sslConfig);
|
|
39
38
|
}
|
|
40
|
-
this.configs = new
|
|
39
|
+
this.configs = new DataSource(baseConfig);
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
exports.DatabaseConfigAbstract = DatabaseConfigAbstract;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class DatabaseHelperAbstractCommitFailure extends
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export declare class DatabaseHelperAbstractCommitFailure extends FailureSketchEdge {
|
|
3
3
|
constructor(error?: any);
|
|
4
4
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DatabaseHelperAbstractCommitFailure = void 0;
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
class DatabaseHelperAbstractCommitFailure extends arch_1.FailureAbstract {
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export class DatabaseHelperAbstractCommitFailure extends FailureSketchEdge {
|
|
6
3
|
constructor(error) {
|
|
7
4
|
super({
|
|
8
|
-
|
|
5
|
+
failureClass: DatabaseHelperAbstractCommitFailure,
|
|
9
6
|
message: "Transaction is not open. Run '.openTransaction()' before commit",
|
|
10
|
-
error,
|
|
7
|
+
stackTrace: error,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.DatabaseHelperAbstractCommitFailure = DatabaseHelperAbstractCommitFailure;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FailureSketchEdge, Newable, Optional, Return } from "@atlantjs/arch";
|
|
2
2
|
import { DataSource, EntityTarget, FindOptionsRelations, ObjectLiteral } from "typeorm";
|
|
3
3
|
import { DatabaseLiteConfigAbstract } from "./database-lite.config";
|
|
4
4
|
import { DatabaseConfigAbstract } from "./database.config";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { SolidAbstract } from "../../domain/objects/solid.abstract";
|
|
6
|
+
import { VertexAbstract } from "../../domain/objects/vertices/vertex.abstract";
|
|
7
|
+
interface FaceEntity {
|
|
8
|
+
face: EntityTarget<ObjectLiteral>;
|
|
9
|
+
entity: SolidAbstract | VertexAbstract;
|
|
10
10
|
}
|
|
11
|
-
interface
|
|
12
|
-
|
|
11
|
+
interface FaceEntityReturn {
|
|
12
|
+
face: EntityTarget<ObjectLiteral>;
|
|
13
13
|
id: string;
|
|
14
14
|
}
|
|
15
15
|
export declare abstract class DatabaseHelperAbstract {
|
|
@@ -17,13 +17,13 @@ export declare abstract class DatabaseHelperAbstract {
|
|
|
17
17
|
private queryRunner;
|
|
18
18
|
connect(db: DatabaseConfigAbstract | DatabaseLiteConfigAbstract): Promise<DataSource>;
|
|
19
19
|
disconnect(): Promise<void>;
|
|
20
|
-
read<T extends Newable<ObjectLiteral>, E extends ObjectLiteral>(
|
|
20
|
+
read<T extends Newable<ObjectLiteral>, E extends ObjectLiteral>(face: T, condition: {
|
|
21
21
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
22
|
-
}, relations: FindOptionsRelations<E>): Promise<Return<Optional<InstanceType<T>[]>,
|
|
23
|
-
write(
|
|
22
|
+
}, relations: FindOptionsRelations<E>): Promise<Return<Optional<InstanceType<T>[]>, FailureSketchEdge>>;
|
|
23
|
+
write(faceEntities: FaceEntity[]): Promise<Return<FaceEntityReturn[], FailureSketchEdge>>;
|
|
24
24
|
delete<T extends Newable<ObjectLiteral>>(schema: T, condition: {
|
|
25
25
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
26
|
-
}, isSoft?: boolean): Promise<Return<undefined,
|
|
26
|
+
}, isSoft?: boolean): Promise<Return<undefined, FailureSketchEdge>>;
|
|
27
27
|
private getManager;
|
|
28
28
|
private openTransaction;
|
|
29
29
|
private commit;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class DatabaseHelperAbstractDeleteFailure extends
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export declare class DatabaseHelperAbstractDeleteFailure extends FailureSketchEdge {
|
|
3
3
|
constructor(isSoft: boolean, error?: any);
|
|
4
4
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DatabaseHelperAbstractDeleteFailure = void 0;
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
class DatabaseHelperAbstractDeleteFailure extends arch_1.FailureAbstract {
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export class DatabaseHelperAbstractDeleteFailure extends FailureSketchEdge {
|
|
6
3
|
constructor(isSoft, error) {
|
|
7
4
|
super({
|
|
8
|
-
|
|
9
|
-
message: `Failed to ${
|
|
10
|
-
error,
|
|
5
|
+
failureClass: DatabaseHelperAbstractDeleteFailure,
|
|
6
|
+
message: `Failed to ${isSoft.truthy() ? "soft" : "hard"} delete the record in the database`,
|
|
7
|
+
stackTrace: error,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.DatabaseHelperAbstractDeleteFailure = DatabaseHelperAbstractDeleteFailure;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class DatabaseHelperAbstractGetManagerFailure extends
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export declare class DatabaseHelperAbstractGetManagerFailure extends FailureSketchEdge {
|
|
3
3
|
constructor(error?: any);
|
|
4
4
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DatabaseHelperAbstractGetManagerFailure = void 0;
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
class DatabaseHelperAbstractGetManagerFailure extends arch_1.FailureAbstract {
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export class DatabaseHelperAbstractGetManagerFailure extends FailureSketchEdge {
|
|
6
3
|
constructor(error) {
|
|
7
4
|
super({
|
|
8
|
-
|
|
5
|
+
failureClass: DatabaseHelperAbstractGetManagerFailure,
|
|
9
6
|
message: "The database is not connected",
|
|
10
|
-
error,
|
|
7
|
+
stackTrace: error,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.DatabaseHelperAbstractGetManagerFailure = DatabaseHelperAbstractGetManagerFailure;
|
|
@@ -1,103 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class DatabaseHelperAbstract {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.database = arch_1.Nothing;
|
|
13
|
-
this.queryRunner = arch_1.Nothing;
|
|
14
|
-
}
|
|
1
|
+
import { Failure, Nothing, Optional, Success, _, } from "@atlantjs/arch";
|
|
2
|
+
import { DatabaseHelperAbstractCommitFailure } from "./database.helper.abstract.commit.failure";
|
|
3
|
+
import { DatabaseHelperAbstractDeleteFailure } from "./database.helper.abstract.delete.failure";
|
|
4
|
+
import { DatabaseHelperAbstractGetManagerFailure } from "./database.helper.abstract.get-manager.failure";
|
|
5
|
+
import { DatabaseHelperAbstractRollbackFailure } from "./database.helper.abstract.rollback.failure";
|
|
6
|
+
import { DatabaseHelperAbstractWriteFailure } from "./database.helper.abstract.write.failure";
|
|
7
|
+
export class DatabaseHelperAbstract {
|
|
8
|
+
database = Nothing;
|
|
9
|
+
queryRunner = Nothing;
|
|
15
10
|
async connect(db) {
|
|
16
|
-
this.database =
|
|
11
|
+
this.database = Optional(db.configs);
|
|
17
12
|
await this.database.unpack().initialize();
|
|
18
13
|
return this.database.unpack();
|
|
19
14
|
}
|
|
20
15
|
async disconnect() {
|
|
21
16
|
await this.database.unpack().destroy();
|
|
22
|
-
this.database =
|
|
17
|
+
this.database = Nothing;
|
|
23
18
|
}
|
|
24
|
-
async read(
|
|
19
|
+
async read(face, condition, relations) {
|
|
25
20
|
const clientWrapped = this.getManager();
|
|
26
21
|
if (clientWrapped.hasFailure())
|
|
27
|
-
return
|
|
22
|
+
return Failure(clientWrapped.unwrapFail());
|
|
28
23
|
const client = clientWrapped.unwrap();
|
|
29
|
-
const repository = client.getRepository(
|
|
30
|
-
const registryPacked =
|
|
24
|
+
const repository = client.getRepository(face);
|
|
25
|
+
const registryPacked = Optional((await repository.find({
|
|
31
26
|
where: { ...condition, deleted: false },
|
|
32
27
|
relations,
|
|
33
28
|
})));
|
|
34
29
|
if (relations && registryPacked.hasSomething()) {
|
|
35
|
-
const filterDeletedRelations = (
|
|
36
|
-
if (!
|
|
30
|
+
const filterDeletedRelations = (face, rels) => {
|
|
31
|
+
if (!face || typeof face !== "object" || !rels)
|
|
37
32
|
return;
|
|
38
33
|
for (const rel of rels) {
|
|
39
|
-
const relValue =
|
|
34
|
+
const relValue = face[rel];
|
|
40
35
|
if (Array.isArray(relValue)) {
|
|
41
|
-
|
|
36
|
+
face[rel] = relValue.filter((item) => !item?.deleted);
|
|
42
37
|
}
|
|
43
38
|
else if (relValue.deleted) {
|
|
44
|
-
|
|
39
|
+
face[rel] = undefined;
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
};
|
|
48
|
-
for (const
|
|
49
|
-
filterDeletedRelations(
|
|
43
|
+
for (const faces of registryPacked.unpack()) {
|
|
44
|
+
filterDeletedRelations(faces, relations);
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
|
-
return
|
|
47
|
+
return Success(registryPacked);
|
|
53
48
|
}
|
|
54
|
-
async write(
|
|
49
|
+
async write(faceEntities) {
|
|
55
50
|
try {
|
|
56
51
|
const client = await this.openTransaction();
|
|
57
52
|
const ids = [];
|
|
58
|
-
for (const
|
|
59
|
-
const repository = client.getRepository(
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
return
|
|
53
|
+
for (const faceEntity of faceEntities) {
|
|
54
|
+
const repository = client.getRepository(faceEntity.face);
|
|
55
|
+
if (_.isUndefined(faceEntity.entity.toSeal) ||
|
|
56
|
+
_.isUndefined(faceEntity.entity.id)) {
|
|
57
|
+
return Failure(new DatabaseHelperAbstractWriteFailure());
|
|
63
58
|
}
|
|
64
|
-
const
|
|
65
|
-
const uniqueColumnValue = arch_1._.isNotUndefined(schemaEntity.unique)
|
|
66
|
-
? String(schemaEntity.entity[schemaEntity.unique])
|
|
67
|
-
: schemaEntity.entity.id.toString();
|
|
68
|
-
const registryFoundedPacked = (0, arch_1.Optional)(await repository.findOne({
|
|
59
|
+
const registryFoundedPacked = Optional(await repository.findOne({
|
|
69
60
|
where: {
|
|
70
|
-
|
|
61
|
+
id: faceEntity.entity.id.toString(),
|
|
71
62
|
},
|
|
72
63
|
}));
|
|
73
64
|
if (registryFoundedPacked.hasNothing()) {
|
|
74
|
-
await repository.save(
|
|
65
|
+
await repository.save(faceEntity.entity.toSeal());
|
|
75
66
|
}
|
|
76
67
|
else {
|
|
77
|
-
await repository.update({ id:
|
|
68
|
+
await repository.update({ id: faceEntity.entity.id.toString() }, faceEntity.entity.toSeal());
|
|
78
69
|
}
|
|
79
70
|
ids.push({
|
|
80
|
-
|
|
81
|
-
id:
|
|
71
|
+
face: faceEntity.face,
|
|
72
|
+
id: faceEntity.entity.id.toString(),
|
|
82
73
|
});
|
|
83
74
|
}
|
|
84
75
|
await this.commit();
|
|
85
|
-
return
|
|
76
|
+
return Success(ids);
|
|
86
77
|
}
|
|
87
78
|
catch (error) {
|
|
88
79
|
await this.rollback();
|
|
89
|
-
return
|
|
80
|
+
return Failure(new DatabaseHelperAbstractWriteFailure(error));
|
|
90
81
|
}
|
|
91
82
|
}
|
|
92
83
|
async delete(schema, condition, isSoft = true) {
|
|
93
84
|
try {
|
|
94
85
|
const client = await this.openTransaction();
|
|
95
86
|
const repository = client.getRepository(schema);
|
|
96
|
-
const registriesPacked =
|
|
87
|
+
const registriesPacked = Optional(await repository.find({ where: condition }));
|
|
97
88
|
if (registriesPacked.hasNothing()) {
|
|
98
|
-
return
|
|
89
|
+
return Failure(new DatabaseHelperAbstractDeleteFailure(isSoft));
|
|
99
90
|
}
|
|
100
|
-
if (
|
|
91
|
+
if (isSoft.falsy()) {
|
|
101
92
|
repository.delete(condition);
|
|
102
93
|
}
|
|
103
94
|
else {
|
|
@@ -108,22 +99,22 @@ class DatabaseHelperAbstract {
|
|
|
108
99
|
}
|
|
109
100
|
}
|
|
110
101
|
await this.commit();
|
|
111
|
-
return
|
|
102
|
+
return Success();
|
|
112
103
|
}
|
|
113
104
|
catch (error) {
|
|
114
105
|
await this.rollback();
|
|
115
|
-
return
|
|
106
|
+
return Failure(new DatabaseHelperAbstractDeleteFailure(isSoft, error));
|
|
116
107
|
}
|
|
117
108
|
}
|
|
118
109
|
getManager() {
|
|
119
110
|
if (this.database.hasNothing()) {
|
|
120
|
-
return
|
|
111
|
+
return Failure(new DatabaseHelperAbstractGetManagerFailure());
|
|
121
112
|
}
|
|
122
|
-
return
|
|
113
|
+
return Success(this.database.unpack().manager);
|
|
123
114
|
}
|
|
124
115
|
async openTransaction() {
|
|
125
116
|
if (this.queryRunner.hasNothing()) {
|
|
126
|
-
this.queryRunner =
|
|
117
|
+
this.queryRunner = Optional(this.database.unpack().createQueryRunner());
|
|
127
118
|
await this.queryRunner.unpack().connect();
|
|
128
119
|
await this.queryRunner.unpack().startTransaction();
|
|
129
120
|
}
|
|
@@ -131,21 +122,20 @@ class DatabaseHelperAbstract {
|
|
|
131
122
|
}
|
|
132
123
|
async commit() {
|
|
133
124
|
if (this.queryRunner.hasNothing()) {
|
|
134
|
-
return
|
|
125
|
+
return Failure(new DatabaseHelperAbstractCommitFailure());
|
|
135
126
|
}
|
|
136
127
|
await this.queryRunner.unpack().commitTransaction();
|
|
137
128
|
await this.queryRunner.unpack().release();
|
|
138
|
-
this.queryRunner =
|
|
139
|
-
return
|
|
129
|
+
this.queryRunner = Nothing;
|
|
130
|
+
return Success();
|
|
140
131
|
}
|
|
141
132
|
async rollback() {
|
|
142
133
|
if (this.queryRunner.hasNothing()) {
|
|
143
|
-
return
|
|
134
|
+
return Failure(new DatabaseHelperAbstractRollbackFailure());
|
|
144
135
|
}
|
|
145
136
|
await this.queryRunner.unpack().rollbackTransaction();
|
|
146
137
|
await this.queryRunner.unpack().release();
|
|
147
|
-
this.queryRunner =
|
|
148
|
-
return
|
|
138
|
+
this.queryRunner = Nothing;
|
|
139
|
+
return Success();
|
|
149
140
|
}
|
|
150
141
|
}
|
|
151
|
-
exports.DatabaseHelperAbstract = DatabaseHelperAbstract;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class DatabaseHelperAbstractRollbackFailure extends
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export declare class DatabaseHelperAbstractRollbackFailure extends FailureSketchEdge {
|
|
3
3
|
constructor(error?: any);
|
|
4
4
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DatabaseHelperAbstractRollbackFailure = void 0;
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
class DatabaseHelperAbstractRollbackFailure extends arch_1.FailureAbstract {
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export class DatabaseHelperAbstractRollbackFailure extends FailureSketchEdge {
|
|
6
3
|
constructor(error) {
|
|
7
4
|
super({
|
|
8
|
-
|
|
5
|
+
failureClass: DatabaseHelperAbstractRollbackFailure,
|
|
9
6
|
message: "Transaction is not open. Run '.openTransaction()' before commit",
|
|
10
|
-
error,
|
|
7
|
+
stackTrace: error,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.DatabaseHelperAbstractRollbackFailure = DatabaseHelperAbstractRollbackFailure;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class DatabaseHelperAbstractWriteFailure extends
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export declare class DatabaseHelperAbstractWriteFailure extends FailureSketchEdge {
|
|
3
3
|
constructor(error?: any);
|
|
4
4
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DatabaseHelperAbstractWriteFailure = void 0;
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
class DatabaseHelperAbstractWriteFailure extends arch_1.FailureAbstract {
|
|
1
|
+
import { FailureSketchEdge } from "@atlantjs/arch";
|
|
2
|
+
export class DatabaseHelperAbstractWriteFailure extends FailureSketchEdge {
|
|
6
3
|
constructor(error) {
|
|
7
4
|
super({
|
|
8
|
-
|
|
5
|
+
failureClass: DatabaseHelperAbstractWriteFailure,
|
|
9
6
|
message: "Failed to insert or update the record in the database",
|
|
10
|
-
error,
|
|
7
|
+
stackTrace: error,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.DatabaseHelperAbstractWriteFailure = DatabaseHelperAbstractWriteFailure;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const arch_1 = require("@atlantjs/arch");
|
|
5
|
-
const parchment_1 = require("../../../setup/parchment/parchment");
|
|
6
|
-
exports.DATABASE_TYPE = parchment_1.Parchment.verse({
|
|
1
|
+
import { NodeEnvs } from "@atlantjs/arch";
|
|
2
|
+
import { Parchment } from "../../../setup/parchment/parchment";
|
|
3
|
+
export const DATABASE_TYPE = Parchment.verse({
|
|
7
4
|
name: "DATABASE_TYPE",
|
|
8
5
|
type: "enum",
|
|
9
6
|
description: "The type of the database",
|
|
@@ -11,82 +8,82 @@ exports.DATABASE_TYPE = parchment_1.Parchment.verse({
|
|
|
11
8
|
values: ["aurora-postgres", "postgres", "sqlite"],
|
|
12
9
|
isRequired: true,
|
|
13
10
|
});
|
|
14
|
-
|
|
11
|
+
export const DATABASE_NAME = Parchment.verse({
|
|
15
12
|
name: "DATABASE_NAME",
|
|
16
13
|
type: "text",
|
|
17
14
|
description: "The name of the database",
|
|
18
15
|
isRequired: true,
|
|
19
16
|
});
|
|
20
|
-
|
|
17
|
+
export const DATABASE_DEFAULT_SCHEMA = Parchment.verse({
|
|
21
18
|
name: "DATABASE_DEFAULT_SCHEMA",
|
|
22
19
|
type: "text",
|
|
23
20
|
description: "The name of default schema the database",
|
|
24
21
|
isRequired: true,
|
|
25
22
|
});
|
|
26
|
-
|
|
23
|
+
export const DATABASE_HOST = Parchment.verse({
|
|
27
24
|
name: "DATABASE_HOST",
|
|
28
25
|
description: "The host address of the database server",
|
|
29
26
|
type: "text",
|
|
30
27
|
isRequired: true,
|
|
31
28
|
});
|
|
32
|
-
|
|
29
|
+
export const DATABASE_ADMIN_PASSWORD = Parchment.verse({
|
|
33
30
|
name: "DATABASE_ADMIN_PASSWORD",
|
|
34
31
|
description: "The password for the database user",
|
|
35
32
|
type: "text",
|
|
36
33
|
isRequired: true,
|
|
37
34
|
});
|
|
38
|
-
|
|
35
|
+
export const DATABASE_PORT = Parchment.verse({
|
|
39
36
|
name: "DATABASE_PORT",
|
|
40
37
|
type: "port-number",
|
|
41
38
|
description: "The port number on which the database server is running",
|
|
42
39
|
isRequired: true,
|
|
43
40
|
});
|
|
44
|
-
|
|
41
|
+
export const DATABASE_ADMIN_USER = Parchment.verse({
|
|
45
42
|
name: "DATABASE_ADMIN_USER",
|
|
46
43
|
description: "The username for the database database",
|
|
47
44
|
type: "text",
|
|
48
45
|
isRequired: true,
|
|
49
46
|
});
|
|
50
|
-
|
|
47
|
+
export const DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED = Parchment.verse({
|
|
51
48
|
name: "DATABASE_AUTOMATICALLY_CREATE_TABLES_ENABLED",
|
|
52
49
|
type: "boolean",
|
|
53
50
|
description: "Flag indicating whether the ORM automatically creates tables in the database based on .schema.ts files",
|
|
54
51
|
isRequired: true,
|
|
55
52
|
});
|
|
56
|
-
|
|
53
|
+
export const DATABASE_SSL_ENABLED = Parchment.verse({
|
|
57
54
|
name: "DATABASE_SSL_ENABLED",
|
|
58
55
|
type: "boolean",
|
|
59
56
|
description: "Flag indicating whether the database requires an SSL connection",
|
|
60
57
|
isRequired: true,
|
|
61
58
|
});
|
|
62
|
-
|
|
59
|
+
export const APP_PORT = Parchment.verse({
|
|
63
60
|
name: "APP_PORT",
|
|
64
61
|
type: "port-number",
|
|
65
62
|
description: "The port number on which the application will run",
|
|
66
63
|
isRequired: true,
|
|
67
64
|
});
|
|
68
|
-
|
|
65
|
+
export const LOAD_MODULES = Parchment.verse({
|
|
69
66
|
name: "LOAD_MODULES",
|
|
70
67
|
type: "array",
|
|
71
68
|
description: "List of modules, separated by commas, to be loaded by the application",
|
|
72
69
|
isRequired: true,
|
|
73
70
|
});
|
|
74
|
-
|
|
71
|
+
export const CORS_ALLOWED_ORIGINS = Parchment.verse({
|
|
75
72
|
name: "CORS_ALLOWED_ORIGINS",
|
|
76
73
|
default: "*",
|
|
77
74
|
description: "Allowed origins for CORS",
|
|
78
75
|
type: "text",
|
|
79
76
|
isRequired: true,
|
|
80
77
|
});
|
|
81
|
-
|
|
78
|
+
export const ENVIRONMENT = Parchment.verse({
|
|
82
79
|
name: "ENVIRONMENT",
|
|
83
80
|
type: "enum",
|
|
84
81
|
isRequired: true,
|
|
85
82
|
values: [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
NodeEnvs.test,
|
|
84
|
+
NodeEnvs.development,
|
|
85
|
+
NodeEnvs.production,
|
|
86
|
+
NodeEnvs.homolog,
|
|
90
87
|
],
|
|
91
88
|
description: "The current environment in which the application is running",
|
|
92
89
|
});
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const arch_1 = require("@atlantjs/arch");
|
|
9
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
-
const envFilePath = node_path_1.default.join(__dirname, "..", "..", "..", "..", "..", "..", process.env.ENVIRONMENT === arch_1.NodeEnvs.test ? ".env.test" : ".env");
|
|
11
|
-
if (!node_fs_1.default.existsSync(envFilePath)) {
|
|
12
|
-
console.error(`The ${process.env.ENVIRONMENT === arch_1.NodeEnvs.test ? ".env.test" : ".env"} file is missing with the variables and their values`);
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { NodeEnvs } from "@atlantjs/arch";
|
|
4
|
+
import * as dotenv from "dotenv";
|
|
5
|
+
const envFilePath = path.join(__dirname, "..", "..", "..", "..", "..", "..", process.env.ENVIRONMENT === NodeEnvs.test ? ".env.test" : ".env");
|
|
6
|
+
if (!fs.existsSync(envFilePath)) {
|
|
7
|
+
console.error(`The ${process.env.ENVIRONMENT === NodeEnvs.test ? ".env.test" : ".env"} file is missing with the variables and their values`);
|
|
13
8
|
}
|
|
14
|
-
|
|
9
|
+
dotenv.config({ path: envFilePath });
|