framework-do-dede 6.0.0 → 6.0.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/README.md +15 -12
- package/dist/application/index.d.ts +2 -2
- package/dist/application/index.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/infra/model/model.d.ts +2 -3
- package/dist/infra/model/model.js +0 -5
- package/dist/protocols/repository.d.ts +4 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -346,12 +346,9 @@ class CreatePhotoUseCase extends UseCase<void, void> {
|
|
|
346
346
|
Entities sao dominio puro. `Model` vive na borda e faz o mapeamento banco <-> model, alem de converter `Entity` <-> `Model`. Repositorios trabalham com `Model`, nao com `Entity`.
|
|
347
347
|
|
|
348
348
|
```ts
|
|
349
|
-
import { Entity, Model,
|
|
349
|
+
import { Entity, Model, column } from './src';
|
|
350
350
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
@model<UserTable>('users')
|
|
354
|
-
class UserModel extends Model<UserTable, User> {
|
|
351
|
+
class UserModel extends Model<User> {
|
|
355
352
|
@column('id')
|
|
356
353
|
id!: string;
|
|
357
354
|
|
|
@@ -398,7 +395,7 @@ return Optional.ofNullable(model);
|
|
|
398
395
|
|
|
399
396
|
Regras principais:
|
|
400
397
|
|
|
401
|
-
- `Model` guarda metadados de coluna (via `@column`)
|
|
398
|
+
- `Model` guarda metadados de coluna (via `@column`)
|
|
402
399
|
- `fromModel` aplica o mapeamento coluna -> propriedade e ignora `null/undefined` (retorna o proprio model)
|
|
403
400
|
- `fromEntity` / `toEntity` fazem a conversao entity <-> model
|
|
404
401
|
- `Entity` recebe o `Model` no construtor (acoplamento forte na borda)
|
|
@@ -494,11 +491,10 @@ Quando um erro e lancado, o handler padroniza a resposta. Erros de dominio (`App
|
|
|
494
491
|
Interfaces tipadas para padrao de repositorio:
|
|
495
492
|
|
|
496
493
|
- `Optional<T>` (helper inspirado em micronaut/spring)
|
|
497
|
-
- `
|
|
498
|
-
- `
|
|
499
|
-
- `RepositoryUpdate<T extends RepositoryModel>`
|
|
494
|
+
- `RepositoryCreate<T extends Entity>`
|
|
495
|
+
- `RepositoryUpdate<T extends Entity>`
|
|
500
496
|
- `RepositoryRemove`
|
|
501
|
-
- `RepositoryRestore<T extends
|
|
497
|
+
- `RepositoryRestore<T extends Entity>`
|
|
502
498
|
- `RepositoryRemoveBy<T>`
|
|
503
499
|
- `RepositoryRestoreBy<T>`
|
|
504
500
|
- `RepositoryExistsBy<T>`
|
|
@@ -511,7 +507,7 @@ Interfaces tipadas para padrao de repositorio:
|
|
|
511
507
|
import { Optional } from './src';
|
|
512
508
|
|
|
513
509
|
class UserRepository {
|
|
514
|
-
async restore(id: string): Promise<Optional<
|
|
510
|
+
async restore(id: string): Promise<Optional<User>> {
|
|
515
511
|
const result = await this.orm
|
|
516
512
|
.select()
|
|
517
513
|
.from(userTable)
|
|
@@ -519,12 +515,19 @@ class UserRepository {
|
|
|
519
515
|
|
|
520
516
|
const row = result[0] ?? null;
|
|
521
517
|
const model = row ? new UserModel().fromModel(row) : null;
|
|
522
|
-
|
|
518
|
+
const entity = model ? model.toEntity() : null;
|
|
519
|
+
return Optional.ofNullable(entity);
|
|
523
520
|
}
|
|
524
521
|
}
|
|
525
522
|
|
|
526
523
|
const user = await repo.restore('1').orElseThrow('Usuario nao encontrado');
|
|
527
524
|
const userByEmail = await repo.restoreByEmail('a@b.com').orElseNull();
|
|
525
|
+
const userOrThrow = await repo.restoreByEmail('a@b.com').orElseThrow(
|
|
526
|
+
() => new Unauthorized('Usuario ou senha invalida')
|
|
527
|
+
);
|
|
528
|
+
const userOrThrow2 = await repo.restoreByEmail('a@b.com').orElseThrow(
|
|
529
|
+
new Unauthorized('Usuario ou senha invalida')
|
|
530
|
+
);
|
|
528
531
|
```
|
|
529
532
|
|
|
530
533
|
## Exemplos
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, Version, PresetIgnore, type Middleware, type Input, type Tracer, type TracerData } from './controller';
|
|
2
2
|
import { Entity, Restrict, VirtualProperty, GetterPrefix, Transform } from '../infra/serialization/entity';
|
|
3
|
-
import { Model,
|
|
3
|
+
import { Model, column } from '../infra/model/model';
|
|
4
4
|
import { DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter } from './usecase';
|
|
5
|
-
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, Version, PresetIgnore, DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
5
|
+
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, Version, PresetIgnore, DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column, };
|
|
6
6
|
export { Storage, CacheGateway, EventDispatcher } from './services';
|
|
7
7
|
export type { Middleware, Input, Tracer, TracerData };
|
|
8
8
|
export type { StorageGateway } from './services';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, Version, PresetIgnore } from './controller';
|
|
2
2
|
import { Entity, Restrict, VirtualProperty, GetterPrefix, Transform } from '../infra/serialization/entity';
|
|
3
|
-
import { Model,
|
|
3
|
+
import { Model, column } from '../infra/model/model';
|
|
4
4
|
import { DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, } from './usecase';
|
|
5
|
-
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, Version, PresetIgnore, DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
5
|
+
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, Version, PresetIgnore, DecorateUseCase, UseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column, };
|
|
6
6
|
export { Storage, CacheGateway, EventDispatcher } from './services';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Post, Get, Put, Delete, Patch, Controller, Input, Version, PresetIgnore, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
1
|
+
import { Post, Get, Put, Delete, Patch, Controller, Input, Version, PresetIgnore, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column, UseCase, DecorateUseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Storage, CacheGateway, EventDispatcher } from "./application";
|
|
2
2
|
import { Container, DefaultContainer, Inject, setDefaultContainer } from './infra/di/registry';
|
|
3
3
|
import { Dede, type Options, Register } from './dede';
|
|
4
4
|
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from './http/errors/server';
|
|
@@ -8,5 +8,5 @@ import type { ValidatorDefinition } from './interface/validation/validator';
|
|
|
8
8
|
import type { StorageGateway, Event, EventPayload } from './application';
|
|
9
9
|
import { RepositoryModel } from './protocols/model';
|
|
10
10
|
import type { RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryExistsBy, RepositoryRestore, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination } from './protocols/repository';
|
|
11
|
-
export { Controller, Post, Get, Put, Delete, Patch, Input, Version, PresetIgnore, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
11
|
+
export { Controller, Post, Get, Put, Delete, Patch, Input, Version, PresetIgnore, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column, UseCase, DecorateUseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Storage, CacheGateway, EventDispatcher, Inject, Container, DefaultContainer, setDefaultContainer, Dede, Options, Register, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError, AppError, Optional, RepositoryModel, RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryRestore, RepositoryExistsBy, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination };
|
|
12
12
|
export type { ValidatorDefinition, StorageGateway, Event, EventPayload };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Post, Get, Put, Delete, Patch, Controller, Version, PresetIgnore, UseMiddleware, UseMiddlewares, Tracing,
|
|
4
4
|
// controller
|
|
5
5
|
// entity
|
|
6
|
-
Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
6
|
+
Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column,
|
|
7
7
|
// entity
|
|
8
8
|
// usecase
|
|
9
9
|
UseCase, DecorateUseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter,
|
|
@@ -18,4 +18,4 @@ import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, Unprocessable
|
|
|
18
18
|
import { AppError } from './domain/errors/app-error';
|
|
19
19
|
import { Optional } from './domain/optional';
|
|
20
20
|
import { RepositoryModel } from './protocols/model';
|
|
21
|
-
export { Controller, Post, Get, Put, Delete, Patch, Version, PresetIgnore, UseMiddleware, UseMiddlewares, Tracing, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model,
|
|
21
|
+
export { Controller, Post, Get, Put, Delete, Patch, Version, PresetIgnore, UseMiddleware, UseMiddlewares, Tracing, Entity, Restrict, VirtualProperty, GetterPrefix, Transform, Model, column, UseCase, DecorateUseCase, Hook, BeforeHook, AfterHook, HookBefore, HookAfter, Storage, CacheGateway, EventDispatcher, Inject, Container, DefaultContainer, setDefaultContainer, Dede, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError, AppError, Optional, RepositoryModel };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Entity } from "../../infra/serialization/entity";
|
|
1
2
|
import { RepositoryModel } from "../../protocols/model";
|
|
2
3
|
export type ColumnDefinition = {
|
|
3
4
|
column: string;
|
|
4
5
|
property: string;
|
|
5
6
|
};
|
|
6
|
-
export declare abstract class Model<
|
|
7
|
-
table: TTable;
|
|
7
|
+
export declare abstract class Model<TEntity extends Entity = Entity> extends RepositoryModel<TEntity> {
|
|
8
8
|
columns: ColumnDefinition[];
|
|
9
9
|
[property: string]: any;
|
|
10
10
|
fromModel(input: Record<string, any> | null | undefined): this;
|
|
@@ -12,5 +12,4 @@ export declare abstract class Model<TTable = string, TEntity = any> extends Repo
|
|
|
12
12
|
toModel(): Record<string, any>;
|
|
13
13
|
abstract toEntity(): TEntity;
|
|
14
14
|
}
|
|
15
|
-
export declare function model<TTable>(table: TTable): (target: any) => void;
|
|
16
15
|
export declare function column(columnName: string): (target: any, propertyKey: string) => void;
|
|
@@ -32,11 +32,6 @@ export class Model extends RepositoryModel {
|
|
|
32
32
|
return record;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export function model(table) {
|
|
36
|
-
return function (target) {
|
|
37
|
-
target.prototype.table = table;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
35
|
export function column(columnName) {
|
|
41
36
|
return function (target, propertyKey) {
|
|
42
37
|
target.columns = target.columns || [];
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Optional } from "../domain";
|
|
2
|
-
|
|
3
|
-
export interface RepositoryCreate<T extends RepositoryModel> {
|
|
1
|
+
import { Entity, Optional } from "../domain";
|
|
2
|
+
export interface RepositoryCreate<T extends Entity> {
|
|
4
3
|
create(input: T): Promise<void>;
|
|
5
4
|
}
|
|
6
|
-
export interface RepositoryUpdate<T extends
|
|
5
|
+
export interface RepositoryUpdate<T extends Entity> {
|
|
7
6
|
update(input: T): Promise<void>;
|
|
8
7
|
}
|
|
9
8
|
export interface RepositoryRemove {
|
|
10
9
|
remove(id: string | number): Promise<void>;
|
|
11
10
|
}
|
|
12
|
-
export interface RepositoryRestore<T extends
|
|
11
|
+
export interface RepositoryRestore<T extends Entity> {
|
|
13
12
|
restore(id: string | number): Promise<Optional<T>>;
|
|
14
13
|
}
|
|
15
14
|
export type RepositoryRemoveBy<T> = {
|