forked from BoscoDomingo/typescript-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c860ff
commit 602319c
Showing
37 changed files
with
405 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_COMPILE_CACHE = /tmp/node-cache | ||
PORT = 8080 | ||
NODE_ENV=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...in1/createUser/createUserUseCase.input.ts → ...ion/createUser/createUserUseCase.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { User } from "../../../domain/domain1/entities/user.entity.js"; | ||
|
||
export class CreateUserUseCaseInput { | ||
constructor(readonly user: User) {} | ||
} | ||
import type { User } from "../../domain/entities/user.entity.js"; | ||
|
||
export class CreateUserUseCaseInput { | ||
constructor(readonly user: User) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { UUIDv7 } from "../../domain/value_objects/uuidv7.js"; | ||
|
||
export interface CreateUserUseCaseOutput { | ||
id: UUIDv7; | ||
} |
30 changes: 15 additions & 15 deletions
30
...n/domain1/createUser/createUserUseCase.ts → ...plication/createUser/createUserUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import type { UserRepository } from "../../../domain/domain1/repositories/user.repository.js"; | ||
import type { CreateUserUseCaseInput } from "./createUserUseCase.input.js"; | ||
import type { CreateUserUseCaseOutput } from "./createUserUseCase.output.js"; | ||
|
||
export class CreateUserUseCase { | ||
constructor(private readonly repository: UserRepository) {} | ||
|
||
async execute({ | ||
user, | ||
}: CreateUserUseCaseInput): Promise<CreateUserUseCaseOutput> { | ||
await this.repository.save(user); | ||
// TO-DO: Send the createdUser event | ||
return { id: user.id }; | ||
} | ||
} | ||
import type { UserRepository } from "../../domain/repositories/user.repository.js"; | ||
import type { CreateUserUseCaseInput } from "./createUserUseCase.input.js"; | ||
import type { CreateUserUseCaseOutput } from "./createUserUseCase.output.js"; | ||
|
||
export class CreateUserUseCase { | ||
constructor(private readonly repository: UserRepository) {} | ||
|
||
async execute({ | ||
user, | ||
}: CreateUserUseCaseInput): Promise<CreateUserUseCaseOutput> { | ||
await this.repository.save(user); | ||
// TO-DO: Send the createdUser event | ||
return { id: user.id }; | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/application/domain1/createUser/createUserUseCase.output.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { UUIDv7 } from "../../domain/value_objects/uuidv7.js"; | ||
|
||
export interface FindUserUseCaseInput { | ||
id: UUIDv7; | ||
} |
25 changes: 12 additions & 13 deletions
25
...ication/domain1/getUser/getUserUseCase.ts → src/application/getUser/getUserUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import type { User } from "../../../domain/domain1/entities/user.entity.js"; | ||
import type { UserRepository } from "../../../domain/domain1/repositories/user.repository.js"; | ||
|
||
import type { FindUserUseCaseInput as GetUserUseCaseInput } from "./getUserUseCase.input.js"; | ||
|
||
export class GetUserUseCase { | ||
constructor(private readonly repository: UserRepository) {} | ||
|
||
async execute(input: GetUserUseCaseInput): Promise<User> { | ||
const result = await this.repository.getById(input.id); | ||
return result; | ||
} | ||
} | ||
import type { User } from "../../domain/entities/user.entity.js"; | ||
import type { UserRepository } from "../../domain/repositories/user.repository.js"; | ||
import type { FindUserUseCaseInput as GetUserUseCaseInput } from "./getUserUseCase.input.js"; | ||
|
||
export class GetUserUseCase { | ||
constructor(private readonly repository: UserRepository) {} | ||
|
||
async execute(input: GetUserUseCaseInput): Promise<User> { | ||
const result = await this.repository.getById(input.id); | ||
return result; | ||
} | ||
} |
21 changes: 12 additions & 9 deletions
21
...main/domain1/criteria/example.criteria.ts → src/domain/criteria/criteria.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import type { Filter } from "./filter.js"; | ||
import type { CursorPagination, Pagination } from "./pagination.js"; | ||
import type { Sorting } from "./sorting.js"; | ||
|
||
export interface ExampleCriteria { | ||
readonly filters: Set<Filter>; | ||
readonly sorting?: Sorting; | ||
readonly pagination?: Pagination | CursorPagination; | ||
} | ||
import type { Filter } from "./filter.js"; | ||
import type { CursorPagination, Pagination } from "./pagination.js"; | ||
import type { Sorting } from "./sorting.js"; | ||
|
||
/** Represents a query combining multiple filters. | ||
Filters inside a group are combined with `AND`, different groups are combined with `OR` */ | ||
export interface CompositeCriteria { | ||
readonly filterGroups: Set<Set<Filter>>; | ||
readonly sorting?: Sorting; | ||
readonly pagination?: Pagination | CursorPagination; | ||
} |
14 changes: 7 additions & 7 deletions
14
src/domain/domain1/criteria/filter.ts → src/domain/criteria/filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { Operators } from "./operators.js"; | ||
|
||
export interface Filter { | ||
readonly field: string; | ||
readonly operator: Operators; | ||
readonly value: string | number | boolean | Date; | ||
} | ||
import type { Operators } from "./operators.js"; | ||
|
||
export interface Filter { | ||
readonly field: string; | ||
readonly operator: Operators; | ||
readonly value: string | number | boolean | Date; | ||
} |
32 changes: 16 additions & 16 deletions
32
src/domain/domain1/criteria/operators.ts → src/domain/criteria/operators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
export enum Operators { | ||
EQUAL = "EQ", | ||
NOT_EQUAL = "NE", | ||
GREATER_THAN = "GT", | ||
GREATER_THAN_OR_EQUAL = "GTE", | ||
LESS_THAN = "LT", | ||
LESS_THAN_OR_EQUAL = "LTE", | ||
EXISTS = "EXISTS", | ||
// IN = "IN", | ||
// NOT_IN = "NOT_IN", | ||
// LIKE = "LIKE", | ||
// NOT_LIKE = "NOT_LIKE", | ||
// IS_NULL = "IS_NULL", | ||
// IS_NOT_NULL = "IS_NOT_NULL", | ||
// BETWEEN = "BETWEEN", | ||
} | ||
export enum Operators { | ||
EQUAL = "EQ", | ||
NOT_EQUAL = "NE", | ||
GREATER_THAN = "GT", | ||
GREATER_THAN_OR_EQUAL = "GTE", | ||
LESS_THAN = "LT", | ||
LESS_THAN_OR_EQUAL = "LTE", | ||
EXISTS = "EXISTS", | ||
// IN = "IN", | ||
// NOT_IN = "NOT_IN", | ||
// LIKE = "LIKE", | ||
// NOT_LIKE = "NOT_LIKE", | ||
// IS_NULL = "IS_NULL", | ||
// IS_NOT_NULL = "IS_NOT_NULL", | ||
// BETWEEN = "BETWEEN", | ||
} |
22 changes: 11 additions & 11 deletions
22
src/domain/domain1/criteria/pagination.ts → src/domain/criteria/pagination.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export interface Pagination { | ||
readonly page?: number; | ||
readonly size?: number; | ||
} | ||
|
||
export interface CursorPagination { | ||
readonly cursor?: string; | ||
readonly direction?: "before" | "after" | "around"; | ||
readonly size?: number; | ||
readonly includeCursor?: boolean; | ||
} | ||
export interface Pagination { | ||
readonly page?: number; | ||
readonly size?: number; | ||
} | ||
|
||
export interface CursorPagination { | ||
readonly cursor?: string; | ||
readonly direction?: "before" | "after" | "around"; | ||
readonly size?: number; | ||
readonly includeCursor?: boolean; | ||
} |
8 changes: 4 additions & 4 deletions
8
src/domain/domain1/criteria/sorting.ts → src/domain/criteria/sorting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface Sorting { | ||
readonly field: string; | ||
readonly direction: "asc" | "desc"; | ||
} | ||
export interface Sorting { | ||
readonly field: string; | ||
readonly direction: "asc" | "desc"; | ||
} |
62 changes: 31 additions & 31 deletions
62
src/domain/domain1/entities/user.entity.ts → src/domain/entities/user.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { UUIDv7 } from "../../value_objects/uuidv7.js"; | ||
|
||
export class User { | ||
readonly id: UUIDv7 = new UUIDv7(); | ||
name: string; | ||
readonly createdAt: Date; | ||
updatedAt: Date; | ||
|
||
constructor(input: { | ||
readonly id?: UUIDv7; | ||
readonly name: string; | ||
readonly createdAt: Date; | ||
readonly updatedAt: Date; | ||
}) { | ||
const { id, name, createdAt, updatedAt } = input; | ||
|
||
// These are just example validations, you should add your own | ||
if (createdAt > new Date()) { | ||
throw new Error("Invalid createdAt date"); | ||
} | ||
|
||
if (updatedAt > new Date()) { | ||
throw new Error("Invalid updatedAt date"); | ||
} | ||
|
||
this.id = id ?? new UUIDv7(); | ||
this.name = name; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
} | ||
} | ||
import { UUIDv7 } from "../value_objects/uuidv7.js"; | ||
|
||
export class User { | ||
readonly id: UUIDv7 = new UUIDv7(); | ||
name: string; | ||
readonly createdAt: Date; | ||
updatedAt: Date; | ||
|
||
constructor(input: { | ||
readonly id?: UUIDv7; | ||
readonly name: string; | ||
readonly createdAt: Date; | ||
readonly updatedAt: Date; | ||
}) { | ||
const { id, name, createdAt, updatedAt } = input; | ||
|
||
// These are just example validations, you should add your own | ||
if (createdAt > new Date()) { | ||
throw new Error("Invalid createdAt date"); | ||
} | ||
|
||
if (updatedAt > new Date()) { | ||
throw new Error("Invalid updatedAt date"); | ||
} | ||
|
||
this.id = id ?? new UUIDv7(); | ||
this.name = name; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
src/domain/domain1/errors/insert.error.ts → src/domain/errors/insert.error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export class InsertError extends Error { | ||
constructor(message: string, data: Record<string, unknown>) { | ||
super(`${message}: ${JSON.stringify(data)}`); | ||
} | ||
} | ||
export class InsertError extends Error { | ||
constructor(message: string, data: Record<string, unknown>) { | ||
super(`${message}: ${JSON.stringify(data)}`); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
src/domain/domain1/errors/notFound.error.ts → src/domain/errors/notFound.error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export class NotFoundError extends Error { | ||
constructor(message: string, data: Record<string, unknown>) { | ||
super(`${message}: ${JSON.stringify(data)}`); | ||
} | ||
} | ||
export class NotFoundError extends Error { | ||
constructor(message: string, data: Record<string, unknown>) { | ||
super(`${message}: ${JSON.stringify(data)}`); | ||
} | ||
} |
16 changes: 8 additions & 8 deletions
16
src/domain/domain1/events/example.event.ts → src/domain/events/example.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export class ExampleEvent { | ||
constructor( | ||
public readonly message: string, | ||
public readonly data: Map<string, unknown>, | ||
public readonly createdAt: Date, | ||
public readonly receivedAt: Date, | ||
) {} | ||
} | ||
export class ExampleEvent { | ||
constructor( | ||
public readonly message: string, | ||
public readonly data: Map<string, unknown>, | ||
public readonly createdAt: Date, | ||
public readonly receivedAt: Date, | ||
) {} | ||
} |
Oops, something went wrong.