Skip to content

Commit

Permalink
feature: primera version
Browse files Browse the repository at this point in the history
  • Loading branch information
ldiego73 committed May 14, 2020
0 parents commit 6d62e6c
Show file tree
Hide file tree
Showing 126 changed files with 8,396 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2020 Luis Diego

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
```
libs/
@micro/logger
@micro/kernel
modules/
countries
domain
entities
exceptions
aggregation-roots
value-objects
events
repositories-interfaces
infraestructure
repositories
logger
dtos *
mappers
application
commands
queries
handlers
uses-cases
interfaces
rest
controllers
routers
server.js
graphl
queries
mutations
server.js
console
commands
cli.js
app
app.js
pokemon
customers
products
orders
```
12 changes: 12 additions & 0 deletions libs/kernel/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions libs/kernel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
reports/
lib/
16 changes: 16 additions & 0 deletions libs/kernel/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Directories
/src
/test

# Others
.babelrc
.editorconfig
.eslintignore
.eslintrc.yml
.gitattributes
.gitignore
.npmignore
.prettierrc
babel.config.js
tsconfig.json
webpack.config.js
7 changes: 7 additions & 0 deletions libs/kernel/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"endOfLine": "auto",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
9 changes: 9 additions & 0 deletions libs/kernel/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2020 Luis Diego

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions libs/kernel/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts?$",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"js"
],
"collectCoverage": true,
"coverageReporters": [
"json",
"text",
"html"
],
"coverageDirectory": "reports"
}
40 changes: 40 additions & 0 deletions libs/kernel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@micro/kernel",
"version": "1.0.0",
"description": "Micro kernel for Microservices using DDD",
"author": {
"name": "Luis Diego",
"email": "[email protected]",
"url": "http://github.com/ldiego73"
},
"license": "MIT",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/"
],
"scripts": {
"clean": "rimraf lib",
"prebuild": "yarn clean",
"build": "webpack",
"test": "jest --passWithNoTests"
},
"dependencies": {
"@types/uuid": "^7.0.3",
"fast-deep-equal": "^3.1.1",
"uuid": "^8.0.0"
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@types/node": "^13.13.5",
"glob": "^7.1.6",
"jest": "^26.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^25.5.0",
"ts-loader": "^7.0.2",
"typescript": "^3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-node-externals": "^1.7.2"
}
}
3 changes: 3 additions & 0 deletions libs/kernel/src/application/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './use-case';
export * from './use-case.error';
export * from './transform';
4 changes: 4 additions & 0 deletions libs/kernel/src/application/transform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Transform<T, U> {
toDto(t: T): U;
toColletion?(t: T[]): U[];
}
19 changes: 19 additions & 0 deletions libs/kernel/src/application/use-case.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Failure } from '../result';

export interface UseCaseError {
message: string;
error: any;
}

export class UseCaseUnexpectedError extends Failure<UseCaseError> {
public constructor(error: any) {
super({
message: 'An unexpected error occurred.',
error,
});
}

public static create(error: any): UseCaseUnexpectedError {
return new UseCaseUnexpectedError(error);
}
}
3 changes: 3 additions & 0 deletions libs/kernel/src/application/use-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface UseCase<Request, Response> {
execute(request?: Request): Promise<Response> | Response;
}
8 changes: 8 additions & 0 deletions libs/kernel/src/domain/aggregate-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Entity } from './entity';
import { UniqueEntityId } from './unique-entity-id';

export abstract class AggregateRoot<T> extends Entity<T> {
get id(): UniqueEntityId {
return this._id;
}
}
4 changes: 4 additions & 0 deletions libs/kernel/src/domain/domain.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface DomainError {
message: string;
error?: any;
}
32 changes: 32 additions & 0 deletions libs/kernel/src/domain/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { UniqueEntityId } from './unique-entity-id';

const isEntity = (v: any): v is Entity<any> => {
return v instanceof Entity;
};

export abstract class Entity<T> {
protected readonly _id: UniqueEntityId;
public readonly props: T;

constructor(props: T, id?: UniqueEntityId) {
this._id = id ?? new UniqueEntityId();
this.props = props;
}

equals(object?: Entity<T>): boolean {
if (object === null || object === undefined) {
return false;
}

if (this === object) {
return true;
}

/* istanbul ignore next */
if (!isEntity(object)) {
return false;
}

return this._id.equals(object._id);
}
}
26 changes: 26 additions & 0 deletions libs/kernel/src/domain/identifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export class Identifier<T> {
constructor(private value: T) {
this.value = value;
}

equals(id?: Identifier<T>): boolean {
if (id === null || id === undefined) {
return false;
}

/* istanbul ignore next */
if (!(id instanceof this.constructor)) {
return false;
}

return id.toValue() === this.value;
}

toString() {
return String(this.value);
}

toValue(): T {
return this.value;
}
}
6 changes: 6 additions & 0 deletions libs/kernel/src/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './aggregate-root';
export * from './entity';
export * from './identifier';
export * from './unique-entity-id';
export * from './value-object';
export * from './domain.error';
8 changes: 8 additions & 0 deletions libs/kernel/src/domain/unique-entity-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { v4 as uuid } from 'uuid';
import { Identifier } from './identifier';

export class UniqueEntityId extends Identifier<string | number> {
constructor(id?: string | number) {
super(id ?? uuid());
}
}
25 changes: 25 additions & 0 deletions libs/kernel/src/domain/value-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import equal from 'fast-deep-equal';

interface ValueObjectProps {
[index: string]: any;
}

export abstract class ValueObject<T extends ValueObjectProps> {
public readonly props: T;

constructor(props: T) {
this.props = Object.freeze(props);
}

public equals(vo?: ValueObject<T>): boolean {
if (vo === null || vo === undefined) {
return false;
}

/* istanbul ignore next */
if (vo.props === undefined) {
return false;
}
return equal(this.props, vo.props);
}
}
4 changes: 4 additions & 0 deletions libs/kernel/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './domain';
export * from './infraestructure';
export * from './application';
export * from './result';
2 changes: 2 additions & 0 deletions libs/kernel/src/infraestructure/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './repository';
export * from './mapper';
4 changes: 4 additions & 0 deletions libs/kernel/src/infraestructure/mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Mapper<T> {
toDomain(raw: any): T;
toPersistence(t: T): any;
}
7 changes: 7 additions & 0 deletions libs/kernel/src/infraestructure/repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Repository<T> {
findAll(): Promise<T[]>;

save(t: T): Promise<void>;
create(t: T): Promise<void>;
update(t: T): Promise<void>;
}
Loading

0 comments on commit 6d62e6c

Please sign in to comment.