@atlantjs/arch 3.1.1 → 3.1.2
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/@atlantjs.json +3 -0
- package/arch/modules/application/databases/database.config.js +1 -1
- package/arch/modules/application/databases/database.helper.abstract.d.ts +10 -10
- package/arch/modules/application/databases/database.helper.abstract.js +49 -0
- package/arch/modules/application/failures/failure.abstract.d.ts +2 -2
- package/arch/modules/domain/entities/entity.abstract.d.ts +10 -0
- package/arch/modules/domain/entities/entity.abstract.js +26 -0
- package/arch/modules/domain/entities/solid.abstract.d.ts +2 -2
- package/arch/modules/domain/entities/solid.abstract.js +4 -0
- package/arch/modules/infrastructure/repositories/schemas/schema.abstract.d.ts +9 -0
- package/arch/modules/infrastructure/repositories/{entities/entity.abstract.js → schemas/schema.abstract.js} +7 -7
- package/index.d.ts +3 -2
- package/index.js +6 -2
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/arch/modules/domain/solid.abstract.d.ts +0 -4
- package/arch/modules/domain/solid.abstract.js +0 -2
- package/arch/modules/infrastructure/repositories/entities/entity.abstract.d.ts +0 -9
|
@@ -23,7 +23,7 @@ class DatabaseConfigAbstract {
|
|
|
23
23
|
password: this.props.password,
|
|
24
24
|
database: this.props.database,
|
|
25
25
|
synchronize: guardian_1.Guardian.isFalsy((0, env_vars_1.isProdOrHomolog)()),
|
|
26
|
-
entities: [`${__dirname}/../../**/*.
|
|
26
|
+
entities: [`${__dirname}/../../**/*.schema{.ts,.js}`],
|
|
27
27
|
migrations: ["./migrations/*.ts"],
|
|
28
28
|
};
|
|
29
29
|
if (guardian_1.Guardian.isEqual(this.props.type, "aurora-mysql")) {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { DataSource,
|
|
1
|
+
import { DataSource, EntityTarget, FindOptionsRelations, FindOptionsWhere, ObjectLiteral } from "typeorm";
|
|
2
|
+
import { Optional } from "../../../../@tool-box/utils/ducts/optional-type";
|
|
2
3
|
import { Return } from "../../../../@tool-box/utils/ducts/return-type";
|
|
3
4
|
import { DatabaseConfigAbstract } from "./database.config";
|
|
4
5
|
import { FailureAbstract } from "../failures/failure.abstract";
|
|
5
|
-
import {
|
|
6
|
-
import { EntityAbstract } from "../../infrastructure/repositories/entities/entity.abstract";
|
|
6
|
+
import { EntityAbstract } from "../../../../index";
|
|
7
7
|
export declare abstract class DatabaseHelperAbstract {
|
|
8
8
|
private database;
|
|
9
9
|
private queryRunner;
|
|
10
10
|
connect(db: DatabaseConfigAbstract): Promise<DataSource>;
|
|
11
11
|
disconnect(): Promise<void>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
read<T extends EntityTarget<ObjectLiteral>, E extends ObjectLiteral>(schema: T, relations: FindOptionsRelations<E>, condition: FindOptionsWhere<T>[] | FindOptionsWhere<T>): Promise<Return<Optional<ObjectLiteral[]>, FailureAbstract>>;
|
|
13
|
+
write<T extends EntityTarget<ObjectLiteral>>(schema: T, sortedEntities: EntityAbstract[]): Promise<any>;
|
|
14
|
+
delete<T extends EntityTarget<ObjectLiteral>>(entity: T, condition: FindOptionsWhere<T>[] | FindOptionsWhere<T>): Promise<Return<undefined, undefined>>;
|
|
15
|
+
private getManager;
|
|
16
|
+
private openTransaction;
|
|
17
|
+
private commit;
|
|
18
|
+
private rollback;
|
|
19
19
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DatabaseHelperAbstract = void 0;
|
|
4
4
|
const optional_type_1 = require("../../../../@tool-box/utils/ducts/optional-type");
|
|
5
5
|
const return_type_1 = require("../../../../@tool-box/utils/ducts/return-type");
|
|
6
|
+
const guardian_1 = require("../../../../@tool-box/utils/type-guard/guardian");
|
|
6
7
|
const database_helper_abstract_commit_failure_1 = require("./database.helper.abstract.commit.failure");
|
|
7
8
|
const database_helper_abstract_get_manager_failure_1 = require("./database.helper.abstract.get-manager.failure");
|
|
8
9
|
const database_helper_abstract_rollback_failure_1 = require("./database.helper.abstract.rollback.failure");
|
|
@@ -20,6 +21,54 @@ class DatabaseHelperAbstract {
|
|
|
20
21
|
await this.database.unpack().destroy();
|
|
21
22
|
this.database = optional_type_1.Nothing;
|
|
22
23
|
}
|
|
24
|
+
async read(schema, relations, condition) {
|
|
25
|
+
const clientWrapped = this.getManager();
|
|
26
|
+
if (clientWrapped.hasFailure())
|
|
27
|
+
return (0, return_type_1.Failure)(clientWrapped.unwrapFail());
|
|
28
|
+
const client = clientWrapped.unwrap();
|
|
29
|
+
const repository = client.getRepository(schema);
|
|
30
|
+
const registryPacked = (0, optional_type_1.Optional)(await repository.find({ where: condition, relations }));
|
|
31
|
+
return (0, return_type_1.Success)(registryPacked);
|
|
32
|
+
}
|
|
33
|
+
async write(schema, sortedEntities) {
|
|
34
|
+
try {
|
|
35
|
+
const client = await this.openTransaction();
|
|
36
|
+
const repository = client.getRepository(schema);
|
|
37
|
+
sortedEntities.forEach(async (sortedEntity) => {
|
|
38
|
+
if (sortedEntity.id.hasNothing()) {
|
|
39
|
+
return (0, return_type_1.Failure)();
|
|
40
|
+
}
|
|
41
|
+
const registryPacked = (0, optional_type_1.Optional)(await repository.findOne({
|
|
42
|
+
where: { id: sortedEntity.id.toString() },
|
|
43
|
+
}));
|
|
44
|
+
if (guardian_1.Guardian.isUndefined(sortedEntity.toPersist)) {
|
|
45
|
+
return (0, return_type_1.Failure)();
|
|
46
|
+
}
|
|
47
|
+
if (registryPacked.hasNothing()) {
|
|
48
|
+
await repository.save(sortedEntity.toPersist());
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
await repository.update({ id: sortedEntity.id.toString() }, sortedEntity.toPersist());
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
await this.commit();
|
|
55
|
+
return (0, return_type_1.Success)();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
await this.rollback();
|
|
59
|
+
return (0, return_type_1.Failure)();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async delete(entity, condition) {
|
|
63
|
+
const client = await this.openTransaction();
|
|
64
|
+
const repository = client.getRepository(entity);
|
|
65
|
+
const registryPacked = (0, optional_type_1.Optional)(await repository.find({ where: condition }));
|
|
66
|
+
if (registryPacked.hasNothing()) {
|
|
67
|
+
return (0, return_type_1.Failure)();
|
|
68
|
+
}
|
|
69
|
+
repository.delete(condition);
|
|
70
|
+
return (0, return_type_1.Success)();
|
|
71
|
+
}
|
|
23
72
|
getManager() {
|
|
24
73
|
if (this.database.hasNothing()) {
|
|
25
74
|
return (0, return_type_1.Failure)(new database_helper_abstract_get_manager_failure_1.DatabaseHelperAbstractGetManagerFailure());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SolidAbstract } from "../../domain/solid.abstract";
|
|
1
|
+
import { FailurePrimitive, FailureProps } from "./failure.abstract.type";
|
|
2
|
+
import { SolidAbstract } from "../../domain/entities/solid.abstract";
|
|
3
3
|
export declare abstract class FailureAbstract implements SolidAbstract {
|
|
4
4
|
private readonly props;
|
|
5
5
|
protected readonly _code: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Optional } from "../../../../@tool-box/utils/ducts/optional-type";
|
|
2
|
+
import { UuidAbstract } from "./uuid.abstract";
|
|
3
|
+
import { SolidAbstract } from "../../../../index";
|
|
4
|
+
export declare abstract class EntityAbstract extends SolidAbstract {
|
|
5
|
+
protected _id?: UuidAbstract | undefined;
|
|
6
|
+
constructor(_id?: UuidAbstract | undefined);
|
|
7
|
+
get id(): Optional<UuidAbstract>;
|
|
8
|
+
private requireToPersist;
|
|
9
|
+
abstract toPersist?(): EntityAbstract;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EntityAbstract = void 0;
|
|
7
|
+
const optional_type_1 = require("../../../../@tool-box/utils/ducts/optional-type");
|
|
8
|
+
const guardian_1 = require("../../../../@tool-box/utils/type-guard/guardian");
|
|
9
|
+
const _atlantjs_json_1 = __importDefault(require("../../../@atlantjs.json"));
|
|
10
|
+
const index_1 = require("../../../../index");
|
|
11
|
+
class EntityAbstract extends index_1.SolidAbstract {
|
|
12
|
+
constructor(_id) {
|
|
13
|
+
super();
|
|
14
|
+
this._id = _id;
|
|
15
|
+
if (guardian_1.Guardian.isEqual(_atlantjs_json_1.default.projectType, "backend")) {
|
|
16
|
+
this.requireToPersist();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
get id() {
|
|
20
|
+
return (0, optional_type_1.Optional)(this._id);
|
|
21
|
+
}
|
|
22
|
+
requireToPersist() {
|
|
23
|
+
throw new Error("toPersist method must be implemented");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.EntityAbstract = EntityAbstract;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntityAbstract } from "../../../domain/entities/entity.abstract";
|
|
2
|
+
import { BaseEntity } from "typeorm";
|
|
3
|
+
export declare abstract class SchemaAbstract extends BaseEntity {
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
updatedAt: Date;
|
|
6
|
+
abstract toEntity(): EntityAbstract;
|
|
7
|
+
protected beforeInsert(): void;
|
|
8
|
+
protected beforeUpdate(): void;
|
|
9
|
+
}
|
|
@@ -9,9 +9,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.SchemaAbstract = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
|
-
class
|
|
14
|
+
class SchemaAbstract extends typeorm_1.BaseEntity {
|
|
15
15
|
beforeInsert() {
|
|
16
16
|
this.createdAt = new Date(Date.now());
|
|
17
17
|
this.updatedAt = new Date(Date.now());
|
|
@@ -20,24 +20,24 @@ class EntityAbstract extends typeorm_1.BaseEntity {
|
|
|
20
20
|
this.updatedAt = new Date(Date.now());
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
exports.
|
|
23
|
+
exports.SchemaAbstract = SchemaAbstract;
|
|
24
24
|
__decorate([
|
|
25
25
|
(0, typeorm_1.Column)({ name: "createdAt", type: "date" }),
|
|
26
26
|
__metadata("design:type", Date)
|
|
27
|
-
],
|
|
27
|
+
], SchemaAbstract.prototype, "createdAt", void 0);
|
|
28
28
|
__decorate([
|
|
29
29
|
(0, typeorm_1.Column)({ name: "updatedAt", type: "date" }),
|
|
30
30
|
__metadata("design:type", Date)
|
|
31
|
-
],
|
|
31
|
+
], SchemaAbstract.prototype, "updatedAt", void 0);
|
|
32
32
|
__decorate([
|
|
33
33
|
(0, typeorm_1.BeforeInsert)(),
|
|
34
34
|
__metadata("design:type", Function),
|
|
35
35
|
__metadata("design:paramtypes", []),
|
|
36
36
|
__metadata("design:returntype", void 0)
|
|
37
|
-
],
|
|
37
|
+
], SchemaAbstract.prototype, "beforeInsert", null);
|
|
38
38
|
__decorate([
|
|
39
39
|
(0, typeorm_1.BeforeUpdate)(),
|
|
40
40
|
__metadata("design:type", Function),
|
|
41
41
|
__metadata("design:paramtypes", []),
|
|
42
42
|
__metadata("design:returntype", void 0)
|
|
43
|
-
],
|
|
43
|
+
], SchemaAbstract.prototype, "beforeUpdate", null);
|
package/index.d.ts
CHANGED
|
@@ -28,13 +28,14 @@ export { MiddlewareHandlerAbstract } from "./arch/modules/domain/middlewares/mid
|
|
|
28
28
|
export { ProviderAbstract } from "./arch/modules/domain/providers/provider.abstract";
|
|
29
29
|
export { RepositoryAbstract } from "./arch/modules/domain/repositories/repository.abstract";
|
|
30
30
|
export { ServiceAbstract } from "./arch/modules/domain/services/service.abstract";
|
|
31
|
-
export { SolidAbstract } from "./arch/modules/domain/solid.abstract";
|
|
31
|
+
export { SolidAbstract } from "./arch/modules/domain/entities/solid.abstract";
|
|
32
32
|
export { UsecaseAbstract } from "./arch/modules/domain/usecases/usecase.abstract";
|
|
33
33
|
export { ControllerAbstract } from "./arch/modules/infrastructure/controllers/controller.abstract";
|
|
34
34
|
export { PayloadAbstract } from "./arch/modules/infrastructure/controllers/payloads/payload.abstract";
|
|
35
35
|
export { ValidatorAbstract } from "./arch/modules/infrastructure/controllers/payloads/validators/validator.abstract";
|
|
36
36
|
export { ResponseAbstract } from "./arch/modules/infrastructure/controllers/responses/response.abstract";
|
|
37
|
-
export { EntityAbstract } from "./arch/modules/
|
|
37
|
+
export { EntityAbstract } from "./arch/modules/domain/entities/entity.abstract";
|
|
38
|
+
export { SchemaAbstract } from "./arch/modules/infrastructure/repositories/schemas/schema.abstract";
|
|
38
39
|
export { ENVIRONMENT, IAM_MOVINGAPP_REALM_PUBLIC_KEY_RS256, APP_PORT, LOAD_MODULES, CORS_ALLOWED_ORIGINS, isProdOrHomolog, } from "./setup/env/env-vars";
|
|
39
40
|
export { initializeApi as initializeAtlantjs } from "./setup";
|
|
40
41
|
export { diContainer } from "./setup/dependency-injections";
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diContainer = exports.initializeAtlantjs = exports.isProdOrHomolog = exports.CORS_ALLOWED_ORIGINS = exports.LOAD_MODULES = exports.APP_PORT = exports.IAM_MOVINGAPP_REALM_PUBLIC_KEY_RS256 = exports.ENVIRONMENT = exports.EntityAbstract = exports.ResponseAbstract = exports.ValidatorAbstract = exports.PayloadAbstract = exports.ControllerAbstract = exports.UsecaseAbstract = exports.ServiceAbstract = exports.RepositoryAbstract = exports.ProviderAbstract = exports.MiddlewareHandlerAbstract = exports.NodeEnvs = exports.HttpStatusCodes = exports.UuidAbstract = exports.$string = exports.$object = exports.$number = exports.$date = exports.$boolean = exports.$array = exports.InjectionsAbstract = exports.UnknownFailure = exports.FailureAbstract = exports.DatabaseHelperAbstract = exports.Guardian = exports.RandomValue = exports.HttpClient = exports.Return = exports.Failure = exports.Success = exports.Optional = exports.Nothing = exports.Something = exports.ExtendedMap = exports.EntityBuilder = exports.CreateFakeUsecase = exports.UuidBuilder = exports.FailureBuilder = void 0;
|
|
3
|
+
exports.diContainer = exports.initializeAtlantjs = exports.isProdOrHomolog = exports.CORS_ALLOWED_ORIGINS = exports.LOAD_MODULES = exports.APP_PORT = exports.IAM_MOVINGAPP_REALM_PUBLIC_KEY_RS256 = exports.ENVIRONMENT = exports.SchemaAbstract = exports.EntityAbstract = exports.ResponseAbstract = exports.ValidatorAbstract = exports.PayloadAbstract = exports.ControllerAbstract = exports.UsecaseAbstract = exports.SolidAbstract = exports.ServiceAbstract = exports.RepositoryAbstract = exports.ProviderAbstract = exports.MiddlewareHandlerAbstract = exports.NodeEnvs = exports.HttpStatusCodes = exports.UuidAbstract = exports.$string = exports.$object = exports.$number = exports.$date = exports.$boolean = exports.$array = exports.InjectionsAbstract = exports.UnknownFailure = exports.FailureAbstract = exports.DatabaseHelperAbstract = exports.Guardian = exports.RandomValue = exports.HttpClient = exports.Return = exports.Failure = exports.Success = exports.Optional = exports.Nothing = exports.Something = exports.ExtendedMap = exports.EntityBuilder = exports.CreateFakeUsecase = exports.UuidBuilder = exports.FailureBuilder = void 0;
|
|
4
4
|
require("#/utils/datatypes/string-utils");
|
|
5
5
|
require("#/utils/datatypes/boolean-utils");
|
|
6
6
|
var failure_builder_1 = require("./@tool-box/tests/builders/failures/failure.builder");
|
|
@@ -61,6 +61,8 @@ var repository_abstract_1 = require("./arch/modules/domain/repositories/reposito
|
|
|
61
61
|
Object.defineProperty(exports, "RepositoryAbstract", { enumerable: true, get: function () { return repository_abstract_1.RepositoryAbstract; } });
|
|
62
62
|
var service_abstract_1 = require("./arch/modules/domain/services/service.abstract");
|
|
63
63
|
Object.defineProperty(exports, "ServiceAbstract", { enumerable: true, get: function () { return service_abstract_1.ServiceAbstract; } });
|
|
64
|
+
var solid_abstract_1 = require("./arch/modules/domain/entities/solid.abstract");
|
|
65
|
+
Object.defineProperty(exports, "SolidAbstract", { enumerable: true, get: function () { return solid_abstract_1.SolidAbstract; } });
|
|
64
66
|
var usecase_abstract_1 = require("./arch/modules/domain/usecases/usecase.abstract");
|
|
65
67
|
Object.defineProperty(exports, "UsecaseAbstract", { enumerable: true, get: function () { return usecase_abstract_1.UsecaseAbstract; } });
|
|
66
68
|
var controller_abstract_1 = require("./arch/modules/infrastructure/controllers/controller.abstract");
|
|
@@ -71,8 +73,10 @@ var validator_abstract_1 = require("./arch/modules/infrastructure/controllers/pa
|
|
|
71
73
|
Object.defineProperty(exports, "ValidatorAbstract", { enumerable: true, get: function () { return validator_abstract_1.ValidatorAbstract; } });
|
|
72
74
|
var response_abstract_1 = require("./arch/modules/infrastructure/controllers/responses/response.abstract");
|
|
73
75
|
Object.defineProperty(exports, "ResponseAbstract", { enumerable: true, get: function () { return response_abstract_1.ResponseAbstract; } });
|
|
74
|
-
var entity_abstract_1 = require("./arch/modules/
|
|
76
|
+
var entity_abstract_1 = require("./arch/modules/domain/entities/entity.abstract");
|
|
75
77
|
Object.defineProperty(exports, "EntityAbstract", { enumerable: true, get: function () { return entity_abstract_1.EntityAbstract; } });
|
|
78
|
+
var schema_abstract_1 = require("./arch/modules/infrastructure/repositories/schemas/schema.abstract");
|
|
79
|
+
Object.defineProperty(exports, "SchemaAbstract", { enumerable: true, get: function () { return schema_abstract_1.SchemaAbstract; } });
|
|
76
80
|
var env_vars_1 = require("./setup/env/env-vars");
|
|
77
81
|
Object.defineProperty(exports, "ENVIRONMENT", { enumerable: true, get: function () { return env_vars_1.ENVIRONMENT; } });
|
|
78
82
|
Object.defineProperty(exports, "IAM_MOVINGAPP_REALM_PUBLIC_KEY_RS256", { enumerable: true, get: function () { return env_vars_1.IAM_MOVINGAPP_REALM_PUBLIC_KEY_RS256; } });
|