@atlantjs/arch 3.1.0 → 3.1.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/arch/modules/application/databases/database.config.d.ts +19 -0
- package/arch/modules/application/databases/database.config.js +42 -0
- package/arch/modules/application/databases/database.helper.abstract.commit.failure.d.ts +4 -0
- package/arch/modules/application/databases/database.helper.abstract.commit.failure.js +14 -0
- package/arch/modules/application/databases/database.helper.abstract.d.ts +17 -2
- package/arch/modules/application/databases/database.helper.abstract.get-manager.failure.d.ts +4 -0
- package/arch/modules/application/databases/database.helper.abstract.get-manager.failure.js +14 -0
- package/arch/modules/application/databases/database.helper.abstract.js +50 -0
- package/arch/modules/application/databases/database.helper.abstract.rollback.failure.d.ts +4 -0
- package/arch/modules/application/databases/database.helper.abstract.rollback.failure.js +14 -0
- package/arch/modules/infrastructure/repositories/entities/entity.abstract.d.ts +4 -1
- package/arch/modules/infrastructure/repositories/entities/entity.abstract.js +38 -1
- package/arch/modules/infrastructure/services/http-client.abstract.d.ts +0 -0
- package/arch/modules/infrastructure/services/http-client.abstract.js +1 -0
- package/arch/modules/infrastructure/services/payloads/service.payload.abstract.d.ts +0 -0
- package/arch/modules/infrastructure/services/payloads/service.payload.abstract.js +1 -0
- package/arch/modules/infrastructure/services/responses/service.response.abstract.d.ts +0 -0
- package/arch/modules/infrastructure/services/responses/service.response.abstract.js +1 -0
- package/index.d.ts +0 -1
- package/package.json +2 -1
- package/setup/index.d.ts +4 -5
- package/setup/index.js +8 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/arch/modules/application/databases/database.factory.abstract.d.ts +0 -3
- package/arch/modules/application/databases/database.factory.abstract.js +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataSource, DatabaseType } from "typeorm";
|
|
2
|
+
interface DatabaseConfigProps {
|
|
3
|
+
type: DatabaseType;
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
database: string;
|
|
9
|
+
region?: string;
|
|
10
|
+
secretArn?: string;
|
|
11
|
+
resourceArn?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class DatabaseConfigAbstract {
|
|
14
|
+
private readonly props;
|
|
15
|
+
configs: DataSource;
|
|
16
|
+
private productionOrHomologConfigs;
|
|
17
|
+
constructor(props: DatabaseConfigProps);
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseConfigAbstract = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const guardian_1 = require("../../../../@tool-box/utils/type-guard/guardian");
|
|
6
|
+
const env_vars_1 = require("../../../../setup/env/env-vars");
|
|
7
|
+
class DatabaseConfigAbstract {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
this.props = props;
|
|
10
|
+
this.productionOrHomologConfigs = {
|
|
11
|
+
ssl: true,
|
|
12
|
+
extra: {
|
|
13
|
+
ssl: {
|
|
14
|
+
rejectUnauthorized: false,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const baseConfig = {
|
|
19
|
+
type: this.props.type,
|
|
20
|
+
host: this.props.host,
|
|
21
|
+
port: this.props.port,
|
|
22
|
+
username: this.props.username,
|
|
23
|
+
password: this.props.password,
|
|
24
|
+
database: this.props.database,
|
|
25
|
+
synchronize: guardian_1.Guardian.isFalsy((0, env_vars_1.isProdOrHomolog)()),
|
|
26
|
+
entities: [`${__dirname}/../../**/*.entity{.ts,.js}`],
|
|
27
|
+
migrations: ["./migrations/*.ts"],
|
|
28
|
+
};
|
|
29
|
+
if (guardian_1.Guardian.isEqual(this.props.type, "aurora-mysql")) {
|
|
30
|
+
Object.assign(baseConfig, {
|
|
31
|
+
region: this.props.region ?? "",
|
|
32
|
+
secretArn: this.props.secretArn ?? "",
|
|
33
|
+
resourceArn: this.props.resourceArn ?? "",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (this.props.host.indexOf("localhost") < 0) {
|
|
37
|
+
Object.assign(baseConfig, this.productionOrHomologConfigs);
|
|
38
|
+
}
|
|
39
|
+
this.configs = new typeorm_1.DataSource(baseConfig);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.DatabaseConfigAbstract = DatabaseConfigAbstract;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseHelperAbstractCommitFailure = void 0;
|
|
4
|
+
const failure_abstract_1 = require("../failures/failure.abstract");
|
|
5
|
+
class DatabaseHelperAbstractCommitFailure extends failure_abstract_1.FailureAbstract {
|
|
6
|
+
constructor(error) {
|
|
7
|
+
super({
|
|
8
|
+
className: DatabaseHelperAbstractCommitFailure.name,
|
|
9
|
+
message: "Transaction is not open",
|
|
10
|
+
error,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DatabaseHelperAbstractCommitFailure = DatabaseHelperAbstractCommitFailure;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
import { DataSource, EntityManager } from "typeorm";
|
|
2
|
+
import { Return } from "../../../../@tool-box/utils/ducts/return-type";
|
|
3
|
+
import { DatabaseConfigAbstract } from "./database.config";
|
|
4
|
+
import { FailureAbstract } from "../failures/failure.abstract";
|
|
5
|
+
import { SolidAbstract } from "../../domain/solid.abstract";
|
|
6
|
+
import { EntityAbstract } from "../../infrastructure/repositories/entities/entity.abstract";
|
|
1
7
|
export declare abstract class DatabaseHelperAbstract {
|
|
2
|
-
|
|
3
|
-
|
|
8
|
+
private database;
|
|
9
|
+
private queryRunner;
|
|
10
|
+
connect(db: DatabaseConfigAbstract): Promise<DataSource>;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
abstract read<T extends EntityAbstract>(entity: T, condition: any): T;
|
|
13
|
+
abstract write<T extends EntityAbstract>(entity: T, data: SolidAbstract): unknown;
|
|
14
|
+
abstract delete<T extends EntityAbstract>(entity: T, condition: any): unknown;
|
|
15
|
+
protected getManager(): Return<EntityManager, FailureAbstract>;
|
|
16
|
+
protected openTransaction(): Promise<EntityManager>;
|
|
17
|
+
protected commit(): Promise<Return<undefined, FailureAbstract>>;
|
|
18
|
+
protected rollback(): Promise<Return<undefined, FailureAbstract>>;
|
|
4
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseHelperAbstractGetManagerFailure = void 0;
|
|
4
|
+
const failure_abstract_1 = require("../failures/failure.abstract");
|
|
5
|
+
class DatabaseHelperAbstractGetManagerFailure extends failure_abstract_1.FailureAbstract {
|
|
6
|
+
constructor(error) {
|
|
7
|
+
super({
|
|
8
|
+
className: DatabaseHelperAbstractGetManagerFailure.name,
|
|
9
|
+
message: "The database is not connected",
|
|
10
|
+
error,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DatabaseHelperAbstractGetManagerFailure = DatabaseHelperAbstractGetManagerFailure;
|
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DatabaseHelperAbstract = void 0;
|
|
4
|
+
const optional_type_1 = require("../../../../@tool-box/utils/ducts/optional-type");
|
|
5
|
+
const return_type_1 = require("../../../../@tool-box/utils/ducts/return-type");
|
|
6
|
+
const database_helper_abstract_commit_failure_1 = require("./database.helper.abstract.commit.failure");
|
|
7
|
+
const database_helper_abstract_get_manager_failure_1 = require("./database.helper.abstract.get-manager.failure");
|
|
8
|
+
const database_helper_abstract_rollback_failure_1 = require("./database.helper.abstract.rollback.failure");
|
|
4
9
|
class DatabaseHelperAbstract {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.database = optional_type_1.Nothing;
|
|
12
|
+
this.queryRunner = optional_type_1.Nothing;
|
|
13
|
+
}
|
|
14
|
+
async connect(db) {
|
|
15
|
+
this.database = (0, optional_type_1.Optional)(db.configs);
|
|
16
|
+
await this.database.unpack().initialize();
|
|
17
|
+
return this.database.unpack();
|
|
18
|
+
}
|
|
19
|
+
async disconnect() {
|
|
20
|
+
await this.database.unpack().destroy();
|
|
21
|
+
this.database = optional_type_1.Nothing;
|
|
22
|
+
}
|
|
23
|
+
getManager() {
|
|
24
|
+
if (this.database.hasNothing()) {
|
|
25
|
+
return (0, return_type_1.Failure)(new database_helper_abstract_get_manager_failure_1.DatabaseHelperAbstractGetManagerFailure());
|
|
26
|
+
}
|
|
27
|
+
return (0, return_type_1.Success)(this.database.unpack().manager);
|
|
28
|
+
}
|
|
29
|
+
async openTransaction() {
|
|
30
|
+
if (this.queryRunner.hasNothing()) {
|
|
31
|
+
this.queryRunner = (0, optional_type_1.Optional)(this.database.unpack().createQueryRunner());
|
|
32
|
+
await this.queryRunner.unpack().connect();
|
|
33
|
+
await this.queryRunner.unpack().startTransaction();
|
|
34
|
+
}
|
|
35
|
+
return this.queryRunner.unpack().manager;
|
|
36
|
+
}
|
|
37
|
+
async commit() {
|
|
38
|
+
if (this.queryRunner.hasNothing()) {
|
|
39
|
+
return (0, return_type_1.Failure)(new database_helper_abstract_commit_failure_1.DatabaseHelperAbstractCommitFailure());
|
|
40
|
+
}
|
|
41
|
+
await this.queryRunner.unpack().commitTransaction();
|
|
42
|
+
await this.queryRunner.unpack().release();
|
|
43
|
+
this.queryRunner = optional_type_1.Nothing;
|
|
44
|
+
return (0, return_type_1.Success)();
|
|
45
|
+
}
|
|
46
|
+
async rollback() {
|
|
47
|
+
if (this.queryRunner.hasNothing()) {
|
|
48
|
+
return (0, return_type_1.Failure)(new database_helper_abstract_rollback_failure_1.DatabaseHelperAbstractRollbackFailure());
|
|
49
|
+
}
|
|
50
|
+
await this.queryRunner.unpack().rollbackTransaction();
|
|
51
|
+
await this.queryRunner.unpack().release();
|
|
52
|
+
this.queryRunner = optional_type_1.Nothing;
|
|
53
|
+
return (0, return_type_1.Success)();
|
|
54
|
+
}
|
|
5
55
|
}
|
|
6
56
|
exports.DatabaseHelperAbstract = DatabaseHelperAbstract;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseHelperAbstractRollbackFailure = void 0;
|
|
4
|
+
const failure_abstract_1 = require("../failures/failure.abstract");
|
|
5
|
+
class DatabaseHelperAbstractRollbackFailure extends failure_abstract_1.FailureAbstract {
|
|
6
|
+
constructor(error) {
|
|
7
|
+
super({
|
|
8
|
+
className: DatabaseHelperAbstractRollbackFailure.name,
|
|
9
|
+
message: "Transaction is not open",
|
|
10
|
+
error,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DatabaseHelperAbstractRollbackFailure = DatabaseHelperAbstractRollbackFailure;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SolidAbstract } from "../../../domain/solid.abstract";
|
|
2
|
-
|
|
2
|
+
import { BaseEntity } from "typeorm";
|
|
3
|
+
export declare abstract class EntityAbstract extends BaseEntity {
|
|
3
4
|
createdAt: Date;
|
|
4
5
|
updatedAt: Date;
|
|
5
6
|
abstract toSolid(): SolidAbstract;
|
|
7
|
+
protected beforeInsert(): void;
|
|
8
|
+
protected beforeUpdate(): void;
|
|
6
9
|
}
|
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.EntityAbstract = void 0;
|
|
4
|
-
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
class EntityAbstract extends typeorm_1.BaseEntity {
|
|
15
|
+
beforeInsert() {
|
|
16
|
+
this.createdAt = new Date(Date.now());
|
|
17
|
+
this.updatedAt = new Date(Date.now());
|
|
18
|
+
}
|
|
19
|
+
beforeUpdate() {
|
|
20
|
+
this.updatedAt = new Date(Date.now());
|
|
21
|
+
}
|
|
5
22
|
}
|
|
6
23
|
exports.EntityAbstract = EntityAbstract;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, typeorm_1.Column)({ name: "createdAt", type: "date" }),
|
|
26
|
+
__metadata("design:type", Date)
|
|
27
|
+
], EntityAbstract.prototype, "createdAt", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, typeorm_1.Column)({ name: "updatedAt", type: "date" }),
|
|
30
|
+
__metadata("design:type", Date)
|
|
31
|
+
], EntityAbstract.prototype, "updatedAt", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
34
|
+
__metadata("design:type", Function),
|
|
35
|
+
__metadata("design:paramtypes", []),
|
|
36
|
+
__metadata("design:returntype", void 0)
|
|
37
|
+
], EntityAbstract.prototype, "beforeInsert", null);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.BeforeUpdate)(),
|
|
40
|
+
__metadata("design:type", Function),
|
|
41
|
+
__metadata("design:paramtypes", []),
|
|
42
|
+
__metadata("design:returntype", void 0)
|
|
43
|
+
], EntityAbstract.prototype, "beforeUpdate", null);
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export { Success, Failure, Return } from "./@tool-box/utils/ducts/return-type";
|
|
|
11
11
|
export { HttpClient } from "./@tool-box/utils/http-client/http-client";
|
|
12
12
|
export { RandomValue } from "./@tool-box/utils/randoms/random-value";
|
|
13
13
|
export { Guardian } from "./@tool-box/utils/type-guard/guardian";
|
|
14
|
-
export { DatabaseFactoryAbstract } from "./arch/modules/application/databases/database.factory.abstract";
|
|
15
14
|
export { DatabaseHelperAbstract } from "./arch/modules/application/databases/database.helper.abstract";
|
|
16
15
|
export { FailureAbstract } from "./arch/modules/application/failures/failure.abstract";
|
|
17
16
|
export { UnknownFailure } from "./arch/modules/application/failures/unknown-failure";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlantjs/arch",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"module-alias": "^2.2.3",
|
|
49
49
|
"reflect-metadata": "^0.2.2",
|
|
50
50
|
"routing-controllers": "^0.10.4",
|
|
51
|
+
"typeorm": "^0.3.20",
|
|
51
52
|
"uuid": "^10.0.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
package/setup/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import "./env/load-envs";
|
|
3
3
|
import { Newable } from "../@tool-box/utils/datatypes/generic-types";
|
|
4
|
-
import {
|
|
4
|
+
import { DatabaseConfigAbstract } from "../arch/modules/application/databases/database.config";
|
|
5
5
|
import { DatabaseHelperAbstract } from "../arch/modules/application/databases/database.helper.abstract";
|
|
6
6
|
interface ServerProps {
|
|
7
|
-
databases
|
|
7
|
+
databases?: [
|
|
8
8
|
{
|
|
9
9
|
ref: Newable<Symbol>;
|
|
10
|
-
target:
|
|
10
|
+
target: DatabaseHelperAbstract;
|
|
11
|
+
configs: DatabaseConfigAbstract;
|
|
11
12
|
}
|
|
12
13
|
];
|
|
13
|
-
databaseFactories: DatabaseFactoryAbstract[];
|
|
14
|
-
databaseHelpers: DatabaseHelperAbstract[];
|
|
15
14
|
}
|
|
16
15
|
export declare function initializeApi(props: ServerProps): void;
|
|
17
16
|
export {};
|
package/setup/index.js
CHANGED
|
@@ -12,13 +12,14 @@ function initializeApi(props) {
|
|
|
12
12
|
initializeModules();
|
|
13
13
|
(0, dependency_injections_1.startContainer)();
|
|
14
14
|
server_1.Server.initialize();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
if (guardian_1.Guardian.isNotUndefined(props.databases)) {
|
|
16
|
+
Promise.all([
|
|
17
|
+
props.databases.map((database) => {
|
|
18
|
+
dependency_injections_1.diContainer.bind(database.ref).toConstantValue(database.target);
|
|
19
|
+
database.target.connect(database.configs);
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
25
|
console.error(`❌ Error occurred: ${error}`);
|