@seidor-cloud-produtos/orbit-backend-lib 0.0.2 → 0.0.3
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/.editorconfig +0 -0
- package/.env.example +0 -0
- package/.eslintignore +0 -0
- package/.eslintrc.json +7 -11
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +4 -0
- package/.prettierrc +0 -0
- package/README.md +4 -1
- package/commitlint.config.js +0 -0
- package/dist/commitlint.config.d.ts +2 -0
- package/dist/commitlint.config.js +2 -0
- package/dist/lib/clean-arch/application/queue/handler.d.ts +3 -0
- package/dist/lib/clean-arch/application/queue/handler.js +2 -0
- package/dist/lib/clean-arch/application/queue/messages-in-memory.d.ts +6 -0
- package/dist/lib/clean-arch/application/queue/messages-in-memory.js +2 -0
- package/dist/lib/clean-arch/application/queue/queue-connection.d.ts +6 -0
- package/dist/lib/clean-arch/application/queue/queue-connection.js +2 -0
- package/dist/lib/clean-arch/application/queue/queue.d.ts +6 -0
- package/dist/lib/clean-arch/application/queue/queue.js +2 -0
- package/dist/lib/clean-arch/domain/entities/aggregate-root.d.ts +8 -0
- package/dist/lib/clean-arch/domain/entities/aggregate-root.js +19 -0
- package/dist/lib/clean-arch/domain/entities/common-dto.d.ts +14 -0
- package/dist/lib/clean-arch/domain/entities/common-dto.js +2 -0
- package/dist/lib/clean-arch/domain/entities/entity.d.ts +9 -0
- package/dist/lib/clean-arch/domain/entities/entity.js +26 -0
- package/dist/lib/clean-arch/domain/entities/unique-entity-id.d.ts +7 -0
- package/dist/lib/clean-arch/domain/entities/unique-entity-id.js +19 -0
- package/dist/lib/clean-arch/domain/entities/value-object.d.ts +4 -0
- package/dist/lib/clean-arch/domain/entities/value-object.js +9 -0
- package/dist/lib/clean-arch/domain/entities/watched-list.d.ts +25 -0
- package/dist/lib/clean-arch/domain/entities/watched-list.js +88 -0
- package/dist/lib/clean-arch/domain/entities/watched-list.spec.d.ts +1 -0
- package/dist/lib/clean-arch/domain/entities/watched-list.spec.js +49 -0
- package/dist/lib/clean-arch/domain/errors/application-error.d.ts +4 -0
- package/dist/lib/clean-arch/domain/errors/application-error.js +9 -0
- package/dist/lib/clean-arch/domain/errors/domain-error.d.ts +4 -0
- package/dist/lib/clean-arch/domain/errors/domain-error.js +9 -0
- package/dist/lib/clean-arch/domain/errors/validation-error.d.ts +10 -0
- package/dist/lib/clean-arch/domain/errors/validation-error.js +11 -0
- package/dist/lib/clean-arch/domain/events/domain-event.d.ts +4 -0
- package/dist/lib/clean-arch/domain/events/domain-event.js +2 -0
- package/dist/lib/clean-arch/domain/types/optional.d.ts +1 -0
- package/dist/lib/clean-arch/domain/types/optional.js +2 -0
- package/dist/lib/clean-arch/infra/adapters/express-adapter.d.ts +12 -0
- package/dist/lib/clean-arch/infra/adapters/express-adapter.js +45 -0
- package/dist/lib/clean-arch/infra/adapters/fastify-adapter.d.ts +11 -0
- package/dist/lib/clean-arch/infra/adapters/fastify-adapter.js +52 -0
- package/dist/lib/clean-arch/infra/authorizations/authorization.d.ts +18 -0
- package/dist/lib/clean-arch/infra/authorizations/authorization.js +31 -0
- package/dist/lib/clean-arch/infra/authorizations/authorizer.d.ts +9 -0
- package/dist/lib/clean-arch/infra/authorizations/authorizer.js +20 -0
- package/dist/lib/clean-arch/infra/authorizations/authorizer.spec.d.ts +1 -0
- package/dist/lib/clean-arch/infra/authorizations/authorizer.spec.js +152 -0
- package/dist/lib/clean-arch/infra/authorizations/not-allowed.d.ts +5 -0
- package/dist/lib/clean-arch/infra/authorizations/not-allowed.js +9 -0
- package/dist/lib/clean-arch/infra/errors/infra-error.d.ts +4 -0
- package/dist/lib/clean-arch/infra/errors/infra-error.js +9 -0
- package/dist/lib/clean-arch/infra/http/controller.d.ts +19 -0
- package/dist/lib/clean-arch/infra/http/controller.js +72 -0
- package/dist/lib/clean-arch/infra/http/handle-bool-filter.d.ts +1 -0
- package/dist/lib/clean-arch/infra/http/handle-bool-filter.js +9 -0
- package/dist/lib/clean-arch/infra/http/handle-is-active-query.d.ts +1 -0
- package/dist/lib/clean-arch/infra/http/handle-is-active-query.js +9 -0
- package/dist/lib/clean-arch/infra/http/handle-sort-param-query.d.ts +1 -0
- package/dist/lib/clean-arch/infra/http/handle-sort-param-query.js +16 -0
- package/dist/lib/clean-arch/infra/http/handle-user-headers.d.ts +11 -0
- package/dist/lib/clean-arch/infra/http/handle-user-headers.js +12 -0
- package/dist/lib/clean-arch/infra/http/health-connections.d.ts +15 -0
- package/dist/lib/clean-arch/infra/http/health-connections.js +12 -0
- package/dist/lib/clean-arch/infra/http/http.d.ts +6 -0
- package/dist/lib/clean-arch/infra/http/http.js +2 -0
- package/dist/lib/clean-arch/shared/pagination/dto-response.d.ts +8 -0
- package/dist/lib/clean-arch/shared/pagination/dto-response.js +2 -0
- package/dist/lib/clean-arch/shared/pagination/get-take-and-skip.d.ts +4 -0
- package/dist/lib/clean-arch/shared/pagination/get-take-and-skip.js +9 -0
- package/dist/lib/clean-arch/shared/pagination/pagination.d.ts +7 -0
- package/dist/lib/clean-arch/shared/pagination/pagination.js +2 -0
- package/dist/lib/frameworks/express/authorizations/authorization-express.d.ts +19 -0
- package/dist/lib/frameworks/express/authorizations/authorization-express.js +32 -0
- package/dist/lib/frameworks/express/authorizations/authorization-express.spec.d.ts +1 -0
- package/dist/lib/frameworks/express/authorizations/authorization-express.spec.js +77 -0
- package/dist/lib/frameworks/express/authorizations/midleware-express.d.ts +3 -0
- package/dist/lib/frameworks/express/authorizations/midleware-express.js +18 -0
- package/dist/lib/frameworks/nest/authorizations/guard-nest.d.ts +7 -0
- package/dist/lib/frameworks/nest/authorizations/guard-nest.js +33 -0
- package/dist/lib/infra/authorizations/auth-matcher.d.ts +10 -0
- package/dist/lib/infra/authorizations/auth-matcher.js +54 -0
- package/dist/lib/infra/authorizations/auth-matcher.spec.d.ts +1 -0
- package/dist/lib/infra/authorizations/auth-matcher.spec.js +103 -0
- package/dist/lib/infra/authorizations/validator/api/api-validator.d.ts +15 -0
- package/dist/lib/infra/authorizations/validator/api/api-validator.js +26 -0
- package/dist/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.d.ts +7 -0
- package/dist/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.js +41 -0
- package/dist/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.d.ts +1 -0
- package/dist/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.js +113 -0
- package/dist/lib/infra/authorizations/validator/auth-validator.d.ts +14 -0
- package/dist/lib/infra/authorizations/validator/auth-validator.js +24 -0
- package/dist/lib/infra/authorizations/validator/auth-validator.spec.d.ts +1 -0
- package/dist/lib/infra/authorizations/validator/auth-validator.spec.js +69 -0
- package/dist/lib/infra/http/errors/api-common-error.d.ts +25 -0
- package/dist/lib/infra/http/errors/api-common-error.js +2 -0
- package/dist/lib/infra/http/errors/api-error.d.ts +7 -0
- package/dist/lib/infra/http/errors/api-error.js +11 -0
- package/dist/lib/infra/http/errors/unauthorized-response.d.ts +6 -0
- package/dist/lib/infra/http/errors/unauthorized-response.js +2 -0
- package/dist/tsup.config.d.ts +2 -0
- package/dist/tsup.config.js +10 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +21 -0
- package/lib/clean-arch/application/queue/handler.ts +3 -0
- package/lib/clean-arch/application/queue/messages-in-memory.ts +7 -0
- package/lib/clean-arch/application/queue/queue-connection.ts +7 -0
- package/lib/clean-arch/application/queue/queue.ts +12 -0
- package/lib/clean-arch/domain/entities/aggregate-root.ts +22 -0
- package/lib/clean-arch/domain/entities/common-dto.ts +16 -0
- package/lib/clean-arch/domain/entities/entity.ts +31 -0
- package/lib/clean-arch/domain/entities/unique-entity-id.ts +21 -0
- package/lib/clean-arch/domain/entities/value-object.ts +7 -0
- package/lib/clean-arch/domain/entities/watched-list.spec.ts +65 -0
- package/lib/clean-arch/domain/entities/watched-list.ts +130 -0
- package/lib/clean-arch/domain/errors/application-error.ts +8 -0
- package/lib/clean-arch/domain/errors/domain-error.ts +8 -0
- package/lib/clean-arch/domain/errors/validation-error.ts +17 -0
- package/lib/clean-arch/domain/events/domain-event.ts +4 -0
- package/lib/clean-arch/domain/types/optional.ts +1 -0
- package/lib/clean-arch/infra/adapters/express-adapter.ts +49 -0
- package/lib/clean-arch/infra/adapters/fastify-adapter.ts +65 -0
- package/lib/clean-arch/infra/authorizations/authorization.ts +48 -0
- package/lib/clean-arch/infra/authorizations/authorizer.spec.ts +155 -0
- package/lib/clean-arch/infra/authorizations/authorizer.ts +23 -0
- package/lib/clean-arch/infra/authorizations/not-allowed.ts +8 -0
- package/lib/clean-arch/infra/errors/infra-error.ts +8 -0
- package/lib/clean-arch/infra/http/controller.ts +95 -0
- package/lib/clean-arch/infra/http/handle-bool-filter.ts +7 -0
- package/lib/clean-arch/infra/http/handle-is-active-query.ts +7 -0
- package/lib/clean-arch/infra/http/handle-sort-param-query.ts +12 -0
- package/lib/clean-arch/infra/http/handle-user-headers.ts +13 -0
- package/lib/clean-arch/infra/http/health-connections.ts +21 -0
- package/lib/clean-arch/infra/http/http.ts +7 -0
- package/lib/clean-arch/shared/pagination/dto-response.ts +5 -0
- package/lib/clean-arch/shared/pagination/get-take-and-skip.ts +6 -0
- package/lib/clean-arch/shared/pagination/pagination.ts +8 -0
- package/lib/frameworks/express/authorizations/authorization-express.spec.ts +108 -0
- package/lib/frameworks/express/authorizations/authorization-express.ts +54 -0
- package/lib/frameworks/express/authorizations/midleware-express.ts +17 -0
- package/lib/frameworks/nest/authorizations/guard-nest.ts +25 -0
- package/lib/infra/authorizations/auth-matcher.spec.ts +130 -0
- package/lib/infra/authorizations/auth-matcher.ts +76 -0
- package/lib/infra/authorizations/validator/api/api-validator.ts +40 -0
- package/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.ts +126 -0
- package/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.ts +52 -0
- package/lib/infra/authorizations/validator/auth-validator.spec.ts +82 -0
- package/lib/infra/authorizations/validator/auth-validator.ts +35 -0
- package/lib/infra/http/errors/api-common-error.ts +25 -0
- package/lib/infra/http/errors/api-error.ts +13 -0
- package/lib/infra/http/errors/unauthorized-response.ts +7 -0
- package/package.json +17 -10
- package/tsconfig.json +1 -1
- package/tsup.config.ts +0 -0
- package/vitest.config.ts +2 -3
- package/src/index.d.ts +0 -13
package/.editorconfig
CHANGED
|
File without changes
|
package/.env.example
CHANGED
|
File without changes
|
package/.eslintignore
CHANGED
|
File without changes
|
package/.eslintrc.json
CHANGED
|
@@ -21,22 +21,18 @@
|
|
|
21
21
|
"no-useless-constructor": "off",
|
|
22
22
|
"no-console": "off",
|
|
23
23
|
"@typescript-eslint/ban-types": "off",
|
|
24
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
24
25
|
"import-helpers/order-imports": [
|
|
25
26
|
"warn",
|
|
26
27
|
{
|
|
27
28
|
"newlinesBetween": "always",
|
|
28
29
|
"groups": [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"/^@/infra/",
|
|
36
|
-
"/^@/shared/",
|
|
37
|
-
"/^@/application/",
|
|
38
|
-
"/^@/domain/",
|
|
39
|
-
["parent", "sibling", "index"]
|
|
30
|
+
"/^node/",
|
|
31
|
+
"module",
|
|
32
|
+
"/^@/infra/",
|
|
33
|
+
"/^@/frameworks/",
|
|
34
|
+
"/^@/clean-arch/",
|
|
35
|
+
["parent", "sibling", "index"]
|
|
40
36
|
],
|
|
41
37
|
"alphabetize": { "order": "asc", "ignoreCase": true }
|
|
42
38
|
}
|
package/.husky/pre-push
ADDED
package/.prettierrc
CHANGED
|
File without changes
|
package/README.md
CHANGED
package/commitlint.config.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import DomainEvent from '@/clean-arch/domain/events/domain-event';
|
|
2
|
+
import Handler from './handler';
|
|
3
|
+
export default interface Queue {
|
|
4
|
+
on(queueName: string, callback: Handler): Promise<void>;
|
|
5
|
+
publish(exchangeName: string, domainEvent: DomainEvent, configs?: Record<string, any>): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CommonDTO } from './common-dto';
|
|
2
|
+
import { Entity } from './entity';
|
|
3
|
+
export declare abstract class AggregateRoot<Props extends CommonDTO> extends Entity<Props> {
|
|
4
|
+
get createdAt(): Date;
|
|
5
|
+
set createdAt(date: Date);
|
|
6
|
+
get updatedAt(): Date | undefined;
|
|
7
|
+
touch(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateRoot = void 0;
|
|
4
|
+
const entity_1 = require("./entity");
|
|
5
|
+
class AggregateRoot extends entity_1.Entity {
|
|
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
|
+
}
|
|
19
|
+
exports.AggregateRoot = AggregateRoot;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type CommonDTO = {
|
|
2
|
+
createdAt: Date;
|
|
3
|
+
updatedAt?: Date;
|
|
4
|
+
};
|
|
5
|
+
export type CreateCommonDTO = {
|
|
6
|
+
createdAt?: Date;
|
|
7
|
+
updatedAt?: Date;
|
|
8
|
+
};
|
|
9
|
+
export type UserRequestDTO = {
|
|
10
|
+
createdByName: string;
|
|
11
|
+
createdByEmail: string;
|
|
12
|
+
updatedByName: string;
|
|
13
|
+
updatedByEmail: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UniqueEntityId } from './unique-entity-id';
|
|
2
|
+
export declare abstract class Entity<Props> {
|
|
3
|
+
private _id;
|
|
4
|
+
protected props: Props;
|
|
5
|
+
get id(): UniqueEntityId;
|
|
6
|
+
set id(id: UniqueEntityId);
|
|
7
|
+
protected constructor(props: Props, id?: UniqueEntityId);
|
|
8
|
+
equals(entity: Entity<any>): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = void 0;
|
|
4
|
+
const unique_entity_id_1 = require("./unique-entity-id");
|
|
5
|
+
class Entity {
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
if (entity.id === this._id) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Entity = Entity;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueEntityId = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
class UniqueEntityId {
|
|
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
|
+
}
|
|
19
|
+
exports.UniqueEntityId = UniqueEntityId;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare abstract class WatchedList<T> {
|
|
2
|
+
currentItems: T[];
|
|
3
|
+
private initial;
|
|
4
|
+
private new;
|
|
5
|
+
private removed;
|
|
6
|
+
private updated;
|
|
7
|
+
constructor(initialItems?: T[]);
|
|
8
|
+
abstract compareItems(a: T, b: T): boolean;
|
|
9
|
+
getItems(): T[];
|
|
10
|
+
getNewItems(): T[];
|
|
11
|
+
getRemovedItems(): T[];
|
|
12
|
+
getUpdatedItems(): T[];
|
|
13
|
+
addUpdatedItem(item: T): number;
|
|
14
|
+
private isCurrentItem;
|
|
15
|
+
private isNewItem;
|
|
16
|
+
private isRemovedItem;
|
|
17
|
+
private removeFromNew;
|
|
18
|
+
private removeFromCurrent;
|
|
19
|
+
private removeFromRemoved;
|
|
20
|
+
private wasAddedInitially;
|
|
21
|
+
exists(item: T): boolean;
|
|
22
|
+
add(item: T): void;
|
|
23
|
+
remove(item: T): void;
|
|
24
|
+
update(items: T[]): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WatchedList = void 0;
|
|
4
|
+
class WatchedList {
|
|
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 (this.currentItems.filter((v) => this.compareItems(item, v)).length !==
|
|
29
|
+
0);
|
|
30
|
+
}
|
|
31
|
+
isNewItem(item) {
|
|
32
|
+
return this.new.filter((v) => this.compareItems(item, v)).length !== 0;
|
|
33
|
+
}
|
|
34
|
+
isRemovedItem(item) {
|
|
35
|
+
return (this.removed.filter((v) => this.compareItems(item, v)).length !== 0);
|
|
36
|
+
}
|
|
37
|
+
removeFromNew(item) {
|
|
38
|
+
this.new = this.new.filter(v => !this.compareItems(v, item));
|
|
39
|
+
}
|
|
40
|
+
removeFromCurrent(item) {
|
|
41
|
+
this.currentItems = this.currentItems.filter(v => !this.compareItems(item, v));
|
|
42
|
+
}
|
|
43
|
+
removeFromRemoved(item) {
|
|
44
|
+
this.removed = this.removed.filter(v => !this.compareItems(item, v));
|
|
45
|
+
}
|
|
46
|
+
wasAddedInitially(item) {
|
|
47
|
+
return (this.initial.filter((v) => this.compareItems(item, v)).length !== 0);
|
|
48
|
+
}
|
|
49
|
+
exists(item) {
|
|
50
|
+
return this.isCurrentItem(item);
|
|
51
|
+
}
|
|
52
|
+
add(item) {
|
|
53
|
+
if (this.isRemovedItem(item)) {
|
|
54
|
+
this.removeFromRemoved(item);
|
|
55
|
+
}
|
|
56
|
+
if (!this.isNewItem(item) && !this.wasAddedInitially(item)) {
|
|
57
|
+
this.new.push(item);
|
|
58
|
+
}
|
|
59
|
+
if (!this.isCurrentItem(item)) {
|
|
60
|
+
this.currentItems.push(item);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
remove(item) {
|
|
64
|
+
this.removeFromCurrent(item);
|
|
65
|
+
if (this.isNewItem(item)) {
|
|
66
|
+
this.removeFromNew(item);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!this.isRemovedItem(item)) {
|
|
70
|
+
this.removed.push(item);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
update(items) {
|
|
74
|
+
const newItems = items.filter(a => {
|
|
75
|
+
return !this.getItems().some(b => this.compareItems(a, b));
|
|
76
|
+
});
|
|
77
|
+
const removedItems = this.getItems().filter(a => {
|
|
78
|
+
return !items.some(b => this.compareItems(a, b));
|
|
79
|
+
});
|
|
80
|
+
const updatedItems = items.filter(item => !newItems.some(a => this.compareItems(item, a) &&
|
|
81
|
+
!removedItems.some(b => this.compareItems(item, b))));
|
|
82
|
+
this.currentItems = items;
|
|
83
|
+
this.new = newItems;
|
|
84
|
+
this.removed = removedItems;
|
|
85
|
+
this.updated = updatedItems;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.WatchedList = WatchedList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const watched_list_1 = require("./watched-list");
|
|
4
|
+
class NumberWatchedList extends watched_list_1.WatchedList {
|
|
5
|
+
compareItems(a, b) {
|
|
6
|
+
return a === b;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
describe('Watched List', () => {
|
|
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
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ValidationError extends Error {
|
|
4
|
+
constructor(errors) {
|
|
5
|
+
super('Validation Error');
|
|
6
|
+
this.code = 400;
|
|
7
|
+
this.name = 'Validation Error';
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = ValidationError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import Controller from '../http/controller';
|
|
3
|
+
import Http, { MethodType } from '../http/http';
|
|
4
|
+
export default class ExpressAdapter implements Http {
|
|
5
|
+
readonly envs: Record<string, string>;
|
|
6
|
+
readonly instance: Express;
|
|
7
|
+
private server;
|
|
8
|
+
constructor(envs: Record<string, string>);
|
|
9
|
+
on(method: MethodType, url: string, callback: Controller): void;
|
|
10
|
+
listen(port: number): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const cors_1 = __importDefault(require("cors"));
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
class ExpressAdapter {
|
|
9
|
+
constructor(envs) {
|
|
10
|
+
this.envs = envs;
|
|
11
|
+
this.instance = (0, express_1.default)();
|
|
12
|
+
this.instance.use((0, cors_1.default)());
|
|
13
|
+
this.instance.use(express_1.default.json({ limit: '10mb' }));
|
|
14
|
+
this.instance.use(express_1.default.urlencoded({ limit: '10mb', extended: false }));
|
|
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
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
const error = callback.throw(err);
|
|
30
|
+
return response.status(error.code).json(error.data || {});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async listen(port) {
|
|
35
|
+
this.server = this.instance.listen(port, () => {
|
|
36
|
+
if (this.envs.NODE_ENV !== 'test') {
|
|
37
|
+
console.log(`🚀 Server is running on PORT ${port}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async close() {
|
|
42
|
+
await this.server.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = ExpressAdapter;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import Controller from '../http/controller';
|
|
3
|
+
import Http, { MethodType } from '../http/http';
|
|
4
|
+
export default class FastifyAdapter implements Http {
|
|
5
|
+
readonly envs: Record<string, string>;
|
|
6
|
+
readonly instance: FastifyInstance;
|
|
7
|
+
constructor(envs: Record<string, string>);
|
|
8
|
+
on(method: MethodType, url: string, callback: Controller): void;
|
|
9
|
+
listen(port: number): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
+
const qs_1 = __importDefault(require("qs"));
|
|
9
|
+
class FastifyAdapter {
|
|
10
|
+
constructor(envs) {
|
|
11
|
+
this.envs = envs;
|
|
12
|
+
this.instance = (0, fastify_1.default)({
|
|
13
|
+
bodyLimit: 10 * 1024 * 1024,
|
|
14
|
+
querystringParser: str => qs_1.default.parse(str),
|
|
15
|
+
});
|
|
16
|
+
this.instance.register(cors_1.default);
|
|
17
|
+
}
|
|
18
|
+
on(method, url, callback) {
|
|
19
|
+
this.instance[method](url, async (request, reply) => {
|
|
20
|
+
try {
|
|
21
|
+
const requestData = {
|
|
22
|
+
body: request.body,
|
|
23
|
+
params: request.params,
|
|
24
|
+
headers: request.headers,
|
|
25
|
+
query: request.query,
|
|
26
|
+
};
|
|
27
|
+
const output = await callback.handle(requestData);
|
|
28
|
+
return reply.status(output.code || 200).send(output.data || {});
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const error = callback.throw(err);
|
|
32
|
+
return reply.status(error.code || 200).send(error.data || {});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async listen(port) {
|
|
37
|
+
this.instance.listen({ port }, async (err, _) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
process.exit();
|
|
41
|
+
}
|
|
42
|
+
await this.instance?.ready();
|
|
43
|
+
if (this.envs.NODE_ENV !== 'test') {
|
|
44
|
+
console.log(`🚀 Server is running on PORT ${port}`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
await this.instance.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = FastifyAdapter;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AuthParams } from '@/infra/authorizations/auth-matcher';
|
|
2
|
+
import { APIAuthValidator } from '@/infra/authorizations/validator/api/api-validator';
|
|
3
|
+
import AuthValidator from '@/infra/authorizations/validator/auth-validator';
|
|
4
|
+
import { UnauthorizedResponse } from '@/infra/http/errors/unauthorized-response';
|
|
5
|
+
import { Request, Response } from '../http/controller';
|
|
6
|
+
type AuthorizationMetaData = {
|
|
7
|
+
handle(input: Request): Promise<Response>;
|
|
8
|
+
request: Request;
|
|
9
|
+
};
|
|
10
|
+
export default class Authorization extends APIAuthValidator {
|
|
11
|
+
controller: AuthorizationMetaData;
|
|
12
|
+
static create(query: AuthParams, controllerMetaData: AuthorizationMetaData): Promise<AuthValidator>;
|
|
13
|
+
protected unauthorize(response: UnauthorizedResponse): void;
|
|
14
|
+
protected getRequestId(): string;
|
|
15
|
+
protected getAuthorizations(): Promise<string[]>;
|
|
16
|
+
protected handleAuthorized(): Promise<Response>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|