fase(1): shared domain building blocks
This commit is contained in:
2
dist/shared/application/EventBus.js
vendored
Normal file
2
dist/shared/application/EventBus.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
dist/shared/application/EventHandler.js
vendored
Normal file
2
dist/shared/application/EventHandler.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
dist/shared/application/UseCase.js
vendored
Normal file
2
dist/shared/application/UseCase.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
19
dist/shared/application/index.js
vendored
Normal file
19
dist/shared/application/index.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./UseCase"), exports);
|
||||
__exportStar(require("./EventBus"), exports);
|
||||
__exportStar(require("./EventHandler"), exports);
|
||||
22
dist/shared/domain/AggregateRoot.js
vendored
Normal file
22
dist/shared/domain/AggregateRoot.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AggregateRoot = void 0;
|
||||
const Entity_1 = require("./Entity");
|
||||
class AggregateRoot extends Entity_1.Entity {
|
||||
constructor(props, id) {
|
||||
super(props, id);
|
||||
this._domainEvents = [];
|
||||
}
|
||||
get domainEvents() {
|
||||
return this._domainEvents;
|
||||
}
|
||||
addDomainEvent(event) {
|
||||
this._domainEvents.push(event);
|
||||
}
|
||||
clearEvents() {
|
||||
const events = [...this._domainEvents];
|
||||
this._domainEvents = [];
|
||||
return events;
|
||||
}
|
||||
}
|
||||
exports.AggregateRoot = AggregateRoot;
|
||||
2
dist/shared/domain/DomainEvent.js
vendored
Normal file
2
dist/shared/domain/DomainEvent.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
17
dist/shared/domain/Entity.js
vendored
Normal file
17
dist/shared/domain/Entity.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Entity = void 0;
|
||||
const UniqueId_1 = require("./UniqueId");
|
||||
class Entity {
|
||||
constructor(props, id) {
|
||||
this._id = id ?? UniqueId_1.UniqueId.create();
|
||||
this.props = props;
|
||||
}
|
||||
get id() { return this._id; }
|
||||
equals(other) {
|
||||
if (!other)
|
||||
return false;
|
||||
return this._id.equals(other._id);
|
||||
}
|
||||
}
|
||||
exports.Entity = Entity;
|
||||
11
dist/shared/domain/Result.js
vendored
Normal file
11
dist/shared/domain/Result.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Err = exports.Ok = void 0;
|
||||
exports.isOk = isOk;
|
||||
exports.isErr = isErr;
|
||||
const Ok = (value) => ({ ok: true, value });
|
||||
exports.Ok = Ok;
|
||||
const Err = (error) => ({ ok: false, error });
|
||||
exports.Err = Err;
|
||||
function isOk(r) { return r.ok; }
|
||||
function isErr(r) { return !r.ok; }
|
||||
18
dist/shared/domain/UniqueId.js
vendored
Normal file
18
dist/shared/domain/UniqueId.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UniqueId = void 0;
|
||||
const uuid_1 = require("uuid");
|
||||
class UniqueId {
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
}
|
||||
static create() { return new UniqueId((0, uuid_1.v4)()); }
|
||||
static from(value) { return new UniqueId(value); }
|
||||
toString() { return this.value; }
|
||||
equals(other) {
|
||||
if (!other)
|
||||
return false;
|
||||
return this.value === other.value;
|
||||
}
|
||||
}
|
||||
exports.UniqueId = UniqueId;
|
||||
14
dist/shared/domain/ValueObject.js
vendored
Normal file
14
dist/shared/domain/ValueObject.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValueObject = void 0;
|
||||
class ValueObject {
|
||||
constructor(props) {
|
||||
this.props = Object.freeze(props);
|
||||
}
|
||||
equals(other) {
|
||||
if (!other)
|
||||
return false;
|
||||
return JSON.stringify(this.props) === JSON.stringify(other.props);
|
||||
}
|
||||
}
|
||||
exports.ValueObject = ValueObject;
|
||||
22
dist/shared/domain/index.js
vendored
Normal file
22
dist/shared/domain/index.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./Result"), exports);
|
||||
__exportStar(require("./UniqueId"), exports);
|
||||
__exportStar(require("./Entity"), exports);
|
||||
__exportStar(require("./AggregateRoot"), exports);
|
||||
__exportStar(require("./ValueObject"), exports);
|
||||
__exportStar(require("./DomainEvent"), exports);
|
||||
Reference in New Issue
Block a user