@seidor-cloud-produtos/orbit-backend-lib 0.0.19 → 0.0.20
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/dist/clean-arch/application/queue/handler.js +2 -2
- package/dist/clean-arch/application/queue/messages-in-memory.js +2 -2
- package/dist/clean-arch/application/queue/queue-connection.js +2 -2
- package/dist/clean-arch/application/queue/queue.js +2 -2
- package/dist/clean-arch/domain/entities/aggregate-root.js +15 -15
- package/dist/clean-arch/domain/entities/common-dto.js +2 -2
- package/dist/clean-arch/domain/entities/entity.js +20 -20
- package/dist/clean-arch/domain/entities/unique-entity-id.js +15 -15
- package/dist/clean-arch/domain/entities/value-object.js +5 -5
- package/dist/clean-arch/domain/entities/watched-list.js +93 -84
- package/dist/clean-arch/domain/entities/watched-list.spec.js +45 -45
- package/dist/clean-arch/domain/errors/application-error.js +6 -6
- package/dist/clean-arch/domain/errors/domain-error.js +6 -6
- package/dist/clean-arch/domain/errors/validation-error.js +8 -8
- package/dist/clean-arch/domain/events/domain-event.js +2 -2
- package/dist/clean-arch/domain/types/optional.js +2 -2
- package/dist/clean-arch/infra/adapters/express-adapter.js +41 -40
- package/dist/clean-arch/infra/adapters/fastify-adapter.js +47 -48
- package/dist/clean-arch/infra/authorizations/authorization.js +24 -25
- package/dist/clean-arch/infra/authorizations/authorizer.js +17 -17
- package/dist/clean-arch/infra/authorizations/authorizer.spec.js +151 -132
- package/dist/clean-arch/infra/authorizations/not-allowed.js +6 -6
- package/dist/clean-arch/infra/errors/infra-error.js +6 -6
- package/dist/clean-arch/infra/http/controller.js +72 -64
- package/dist/clean-arch/infra/http/handle-bool-filter.js +6 -6
- package/dist/clean-arch/infra/http/handle-is-active-query.js +6 -6
- package/dist/clean-arch/infra/http/handle-sort-param-query.js +12 -12
- package/dist/clean-arch/infra/http/handle-user-headers.js +8 -8
- package/dist/clean-arch/infra/http/health-connections.js +9 -9
- package/dist/clean-arch/infra/http/http.js +2 -2
- package/dist/clean-arch/shared/pagination/dto-response.js +2 -2
- package/dist/clean-arch/shared/pagination/get-take-and-skip.js +5 -5
- package/dist/clean-arch/shared/pagination/pagination.js +2 -2
- package/dist/frameworks/express/authorizations/authorization-express.js +27 -28
- package/dist/frameworks/express/authorizations/authorization-express.spec.js +89 -72
- package/dist/frameworks/express/authorizations/midleware-express.js +15 -13
- package/dist/frameworks/nest/authorizations/guard-nest.js +25 -22
- package/dist/index.js +4 -4
- package/dist/infra/authorizations/auth-matcher.js +46 -46
- package/dist/infra/authorizations/auth-matcher.spec.js +121 -96
- package/dist/infra/authorizations/validator/api/api-validator.js +25 -20
- package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.js +38 -37
- package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.js +123 -109
- package/dist/infra/authorizations/validator/auth-validator.js +21 -19
- package/dist/infra/authorizations/validator/auth-validator.spec.js +63 -57
- package/dist/infra/http/errors/api-common-error.js +2 -2
- package/dist/infra/http/errors/api-error.js +7 -7
- package/dist/infra/http/errors/unauthorized-response.js +2 -2
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.AggregateRoot = void 0;
|
|
4
|
-
const entity_1 = require(
|
|
4
|
+
const entity_1 = require('./entity');
|
|
5
5
|
class AggregateRoot extends entity_1.Entity {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
get createdAt() {
|
|
7
|
+
return this.props.createdAt;
|
|
8
|
+
}
|
|
9
|
+
set createdAt(date) {
|
|
10
|
+
this.props.createdAt = date;
|
|
11
|
+
}
|
|
12
|
+
get updatedAt() {
|
|
13
|
+
return this.props.updatedAt;
|
|
14
|
+
}
|
|
15
|
+
touch() {
|
|
16
|
+
this.props.updatedAt = new Date();
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
exports.AggregateRoot = AggregateRoot;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const unique_entity_id_1 = require(
|
|
4
|
+
const unique_entity_id_1 = require('./unique-entity-id');
|
|
5
5
|
class Entity {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
get id() {
|
|
7
|
+
return this._id;
|
|
8
|
+
}
|
|
9
|
+
set id(id) {
|
|
10
|
+
this._id = id;
|
|
11
|
+
}
|
|
12
|
+
constructor(props, id) {
|
|
13
|
+
this._id = id ?? new unique_entity_id_1.UniqueEntityId(id);
|
|
14
|
+
this.props = props;
|
|
15
|
+
}
|
|
16
|
+
equals(entity) {
|
|
17
|
+
if (entity === this) {
|
|
18
|
+
return true;
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
constructor(props, id) {
|
|
13
|
-
this._id = id ?? new unique_entity_id_1.UniqueEntityId(id);
|
|
14
|
-
this.props = props;
|
|
15
|
-
}
|
|
16
|
-
equals(entity) {
|
|
17
|
-
if (entity === this) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
if (entity.id === this._id) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
20
|
+
if (entity.id === this._id) {
|
|
21
|
+
return true;
|
|
24
22
|
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
26
|
exports.Entity = Entity;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.UniqueEntityId = void 0;
|
|
4
|
-
const node_crypto_1 = require(
|
|
4
|
+
const node_crypto_1 = require('node:crypto');
|
|
5
5
|
class UniqueEntityId {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
constructor(value) {
|
|
7
|
+
this.value = value ?? (0, node_crypto_1.randomUUID)();
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return this.value;
|
|
11
|
+
}
|
|
12
|
+
toValue() {
|
|
13
|
+
return this.value;
|
|
14
|
+
}
|
|
15
|
+
equals(id) {
|
|
16
|
+
return id.toValue() === this.toValue();
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
exports.UniqueEntityId = UniqueEntityId;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.ValueObject = void 0;
|
|
4
4
|
class ValueObject {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(props) {
|
|
6
|
+
this.props = props;
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
exports.ValueObject = ValueObject;
|
|
@@ -1,88 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.WatchedList = void 0;
|
|
4
4
|
class WatchedList {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
5
|
+
constructor(initialItems) {
|
|
6
|
+
this.currentItems = initialItems || [];
|
|
7
|
+
this.initial = initialItems || [];
|
|
8
|
+
this.new = [];
|
|
9
|
+
this.removed = [];
|
|
10
|
+
this.updated = [];
|
|
11
|
+
}
|
|
12
|
+
getItems() {
|
|
13
|
+
return this.currentItems;
|
|
14
|
+
}
|
|
15
|
+
getNewItems() {
|
|
16
|
+
return this.new;
|
|
17
|
+
}
|
|
18
|
+
getRemovedItems() {
|
|
19
|
+
return this.removed;
|
|
20
|
+
}
|
|
21
|
+
getUpdatedItems() {
|
|
22
|
+
return this.updated;
|
|
23
|
+
}
|
|
24
|
+
addUpdatedItem(item) {
|
|
25
|
+
return this.updated.push(item);
|
|
26
|
+
}
|
|
27
|
+
isCurrentItem(item) {
|
|
28
|
+
return (
|
|
29
|
+
this.currentItems.filter(v => this.compareItems(item, v)).length !== 0
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
isNewItem(item) {
|
|
33
|
+
return this.new.filter(v => this.compareItems(item, v)).length !== 0;
|
|
34
|
+
}
|
|
35
|
+
isRemovedItem(item) {
|
|
36
|
+
return this.removed.filter(v => this.compareItems(item, v)).length !== 0;
|
|
37
|
+
}
|
|
38
|
+
removeFromNew(item) {
|
|
39
|
+
this.new = this.new.filter(v => !this.compareItems(v, item));
|
|
40
|
+
}
|
|
41
|
+
removeFromCurrent(item) {
|
|
42
|
+
this.currentItems = this.currentItems.filter(
|
|
43
|
+
v => !this.compareItems(item, v),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
removeFromRemoved(item) {
|
|
47
|
+
this.removed = this.removed.filter(v => !this.compareItems(item, v));
|
|
48
|
+
}
|
|
49
|
+
wasAddedInitially(item) {
|
|
50
|
+
return this.initial.filter(v => this.compareItems(item, v)).length !== 0;
|
|
51
|
+
}
|
|
52
|
+
exists(item) {
|
|
53
|
+
return this.isCurrentItem(item);
|
|
54
|
+
}
|
|
55
|
+
add(item) {
|
|
56
|
+
if (this.isRemovedItem(item)) {
|
|
57
|
+
this.removeFromRemoved(item);
|
|
58
|
+
}
|
|
59
|
+
if (!this.isNewItem(item) && !this.wasAddedInitially(item)) {
|
|
60
|
+
this.new.push(item);
|
|
61
|
+
}
|
|
62
|
+
if (!this.isCurrentItem(item)) {
|
|
63
|
+
this.currentItems.push(item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
remove(item) {
|
|
67
|
+
this.removeFromCurrent(item);
|
|
68
|
+
if (this.isNewItem(item)) {
|
|
69
|
+
this.removeFromNew(item);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!this.isRemovedItem(item)) {
|
|
73
|
+
this.removed.push(item);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
update(items) {
|
|
77
|
+
const newItems = items.filter(a => {
|
|
78
|
+
return !this.getItems().some(b => this.compareItems(a, b));
|
|
79
|
+
});
|
|
80
|
+
const removedItems = this.getItems().filter(a => {
|
|
81
|
+
return !items.some(b => this.compareItems(a, b));
|
|
82
|
+
});
|
|
83
|
+
const updatedItems = items.filter(
|
|
84
|
+
item =>
|
|
85
|
+
!newItems.some(
|
|
86
|
+
a =>
|
|
87
|
+
this.compareItems(item, a) &&
|
|
88
|
+
!removedItems.some(b => this.compareItems(item, b)),
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
this.currentItems = items;
|
|
92
|
+
this.new = newItems;
|
|
93
|
+
this.removed = removedItems;
|
|
94
|
+
this.updated = updatedItems;
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
exports.WatchedList = WatchedList;
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const watched_list_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const watched_list_1 = require('./watched-list');
|
|
4
4
|
class NumberWatchedList extends watched_list_1.WatchedList {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
compareItems(a, b) {
|
|
6
|
+
return a === b;
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
describe('Watched List', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
it('should be able to create a watched list with initial items', () => {
|
|
11
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
12
|
+
expect(list.currentItems).toHaveLength(3);
|
|
13
|
+
});
|
|
14
|
+
it('should be able to add new items to the list', () => {
|
|
15
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
16
|
+
list.add(4);
|
|
17
|
+
expect(list.currentItems).toHaveLength(4);
|
|
18
|
+
expect(list.getNewItems()).toEqual([4]);
|
|
19
|
+
});
|
|
20
|
+
it('should be able to add remove items from the list', () => {
|
|
21
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
22
|
+
list.remove(2);
|
|
23
|
+
expect(list.currentItems).toHaveLength(2);
|
|
24
|
+
expect(list.getRemovedItems()).toEqual([2]);
|
|
25
|
+
});
|
|
26
|
+
it('should be able to add an item even if it was removed before', () => {
|
|
27
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
28
|
+
list.remove(2);
|
|
29
|
+
list.add(2);
|
|
30
|
+
expect(list.currentItems).toHaveLength(3);
|
|
31
|
+
expect(list.getRemovedItems()).toEqual([]);
|
|
32
|
+
expect(list.getNewItems()).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
it('should be able to remove an item even if it was added before', () => {
|
|
35
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
36
|
+
list.add(4);
|
|
37
|
+
list.remove(4);
|
|
38
|
+
expect(list.currentItems).toHaveLength(3);
|
|
39
|
+
expect(list.getRemovedItems()).toEqual([]);
|
|
40
|
+
expect(list.getNewItems()).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
it('should be able to update watched list items', () => {
|
|
43
|
+
const list = new NumberWatchedList([1, 2, 3]);
|
|
44
|
+
list.update([1, 3, 5]);
|
|
45
|
+
expect(list.getRemovedItems()).toEqual([2]);
|
|
46
|
+
expect(list.getNewItems()).toEqual([5]);
|
|
47
|
+
expect(list.getUpdatedItems()).toEqual([1, 3]);
|
|
48
|
+
});
|
|
49
49
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
class ApplicationError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
constructor(message, code = 400) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
exports.default = ApplicationError;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
class DomainError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
constructor(message, code = 400) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
exports.default = DomainError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
class ValidationError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
constructor(errors) {
|
|
5
|
+
super('Validation Error');
|
|
6
|
+
this.code = 400;
|
|
7
|
+
this.name = 'Validation Error';
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
exports.default = ValidationError;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const tslib_1 = require(
|
|
4
|
-
const cors_1 = tslib_1.__importDefault(require(
|
|
5
|
-
const express_1 = tslib_1.__importDefault(require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const tslib_1 = require('tslib');
|
|
4
|
+
const cors_1 = tslib_1.__importDefault(require('cors'));
|
|
5
|
+
const express_1 = tslib_1.__importDefault(require('express'));
|
|
6
6
|
class ExpressAdapter {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
constructor(envs) {
|
|
8
|
+
this.envs = envs;
|
|
9
|
+
this.instance = (0, express_1.default)();
|
|
10
|
+
this.instance.use((0, cors_1.default)());
|
|
11
|
+
this.instance.use(express_1.default.json({ limit: '10mb' }));
|
|
12
|
+
this.instance.use(
|
|
13
|
+
express_1.default.urlencoded({ limit: '10mb', extended: false }),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
on(method, url, callback) {
|
|
17
|
+
this.instance[method](url, async (request, response) => {
|
|
18
|
+
try {
|
|
19
|
+
const requestData = {
|
|
20
|
+
body: request.body,
|
|
21
|
+
params: request.params,
|
|
22
|
+
headers: request.headers,
|
|
23
|
+
query: request.query,
|
|
24
|
+
};
|
|
25
|
+
const output = await callback.handle(requestData);
|
|
26
|
+
return response.status(output.code || 200).json(output.data || {});
|
|
27
|
+
} catch (err) {
|
|
28
|
+
const error = callback.throw(err);
|
|
29
|
+
return response.status(error.code).json(error.data || {});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async listen(port) {
|
|
34
|
+
this.server = this.instance.listen(port, () => {
|
|
35
|
+
if (this.envs.NODE_ENV !== 'test') {
|
|
36
|
+
console.log(`🚀 Server is running on PORT ${port}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async close() {
|
|
41
|
+
await this.server.close();
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
44
|
exports.default = ExpressAdapter;
|