@axisparkjs/ddd 1.0.0

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/PACKAGE.md ADDED
@@ -0,0 +1,3 @@
1
+ # @axisparkjs/ddd
2
+
3
+ Domain-driven design module for AxiSpark framework.
@@ -0,0 +1,10 @@
1
+ import { DomainEvent } from './domain-event';
2
+ import { Entity } from './entity';
3
+ import { HasDomainEvents } from './has-domain-events';
4
+ import { Identifier } from './identifier';
5
+ export declare abstract class AggregateRoot<T extends Identifier> extends Entity<T> implements HasDomainEvents {
6
+ private readonly _domainEvents;
7
+ addDomainEvent(event: DomainEvent): void;
8
+ pullDomainEvents(): DomainEvent[];
9
+ clearDomainEvents(): void;
10
+ }
@@ -0,0 +1,23 @@
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
+ constructor() {
7
+ super(...arguments);
8
+ this._domainEvents = [];
9
+ }
10
+ addDomainEvent(event) {
11
+ this._domainEvents.push(event);
12
+ }
13
+ pullDomainEvents() {
14
+ const events = [...this._domainEvents];
15
+ this.clearDomainEvents();
16
+ return events;
17
+ }
18
+ clearDomainEvents() {
19
+ this._domainEvents.length = 0;
20
+ }
21
+ }
22
+ exports.AggregateRoot = AggregateRoot;
23
+ //# sourceMappingURL=aggregate-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../src/domain/aggregate-root.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAOlC,MAAsB,aAAoC,SAAQ,eAAS;IAA3E;;QACqB,kBAAa,GAAkB,EAAE,CAAC;IA0BvD,CAAC;IApBU,cAAc,CAAC,KAAkB;QACpC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAMM,gBAAgB;QACnB,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QACvC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC;IAClB,CAAC;IAKM,iBAAiB;QACpB,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,CAAC;CACJ;AA3BD,sCA2BC"}
@@ -0,0 +1,5 @@
1
+ export declare abstract class DomainEvent {
2
+ private readonly _occurredOn;
3
+ constructor();
4
+ get occurredOn(): Date;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainEvent = void 0;
4
+ class DomainEvent {
5
+ constructor() {
6
+ this._occurredOn = new Date();
7
+ }
8
+ get occurredOn() {
9
+ return new Date(this._occurredOn);
10
+ }
11
+ }
12
+ exports.DomainEvent = DomainEvent;
13
+ //# sourceMappingURL=domain-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../../src/domain/domain-event.ts"],"names":[],"mappings":";;;AAGA,MAAsB,WAAW;IAM7B;QACI,IAAI,CAAC,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAClC,CAAC;IAMD,IAAI,UAAU;QACV,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;CACJ;AAjBD,kCAiBC"}
@@ -0,0 +1,3 @@
1
+ export declare abstract class DomainException extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainException = void 0;
4
+ class DomainException extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = this.constructor.name;
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ }
10
+ }
11
+ exports.DomainException = DomainException;
12
+ //# sourceMappingURL=domain-exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-exception.js","sourceRoot":"","sources":["../../src/domain/domain-exception.ts"],"names":[],"mappings":";;;AAGA,MAAsB,eAAgB,SAAQ,KAAK;IAK/C,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ;AAVD,0CAUC"}
@@ -0,0 +1,7 @@
1
+ import { Identifier } from './identifier';
2
+ export declare abstract class Entity<T extends Identifier> {
3
+ protected readonly _id: T;
4
+ constructor(id: T);
5
+ get id(): Readonly<T>;
6
+ equals(other: Entity<T>): boolean;
7
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Entity = void 0;
4
+ class Entity {
5
+ constructor(id) {
6
+ this._id = id;
7
+ }
8
+ get id() {
9
+ return this._id;
10
+ }
11
+ equals(other) {
12
+ if (other === null || other === undefined)
13
+ return false;
14
+ if (this === other)
15
+ return true;
16
+ return this.constructor === other.constructor && this._id.equals(other._id);
17
+ }
18
+ }
19
+ exports.Entity = Entity;
20
+ //# sourceMappingURL=entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/domain/entity.ts"],"names":[],"mappings":";;;AAMA,MAAsB,MAAM;IAOxB,YAAY,EAAK;QACb,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAClB,CAAC;IAMD,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAOM,MAAM,CAAC,KAAgB;QAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACxD,IAAI,IAAI,KAAK,KAAK;YAAE,OAAO,IAAI,CAAC;QAEhC,OAAO,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChF,CAAC;CACJ;AA9BD,wBA8BC"}
@@ -0,0 +1,4 @@
1
+ import { DomainEvent } from './domain-event';
2
+ export interface HasDomainEvents {
3
+ pullDomainEvents(): DomainEvent[];
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=has-domain-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-domain-events.js","sourceRoot":"","sources":["../../src/domain/has-domain-events.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { ValueObject } from './value-object';
2
+ export declare abstract class Identifier<T = string> extends ValueObject<T> {
3
+ toString(): string;
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Identifier = void 0;
4
+ const value_object_1 = require("./value-object");
5
+ class Identifier extends value_object_1.ValueObject {
6
+ toString() {
7
+ return String(this._value);
8
+ }
9
+ }
10
+ exports.Identifier = Identifier;
11
+ //# sourceMappingURL=identifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../src/domain/identifier.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAK7C,MAAsB,UAAuB,SAAQ,0BAAc;IAK/D,QAAQ;QACJ,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACJ;AARD,gCAQC"}
@@ -0,0 +1,7 @@
1
+ export * from './aggregate-root';
2
+ export * from './domain-event';
3
+ export * from './domain-exception';
4
+ export * from './entity';
5
+ export * from './has-domain-events';
6
+ export * from './identifier';
7
+ export * from './value-object';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./aggregate-root"), exports);
18
+ __exportStar(require("./domain-event"), exports);
19
+ __exportStar(require("./domain-exception"), exports);
20
+ __exportStar(require("./entity"), exports);
21
+ __exportStar(require("./has-domain-events"), exports);
22
+ __exportStar(require("./identifier"), exports);
23
+ __exportStar(require("./value-object"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,iDAA+B;AAC/B,qDAAmC;AACnC,2CAAyB;AACzB,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B"}
@@ -0,0 +1,8 @@
1
+ export declare abstract class ValueObject<T> {
2
+ protected readonly _value: T;
3
+ constructor(value: T);
4
+ get value(): Readonly<T>;
5
+ equals(vo: ValueObject<T>): boolean;
6
+ protected abstract validate(value: T): void;
7
+ abstract toString(): string;
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueObject = void 0;
4
+ class ValueObject {
5
+ constructor(value) {
6
+ this.validate(value);
7
+ this._value = value;
8
+ }
9
+ get value() {
10
+ return this._value;
11
+ }
12
+ equals(vo) {
13
+ if (vo === null || vo === undefined)
14
+ return false;
15
+ if (this === vo)
16
+ return true;
17
+ return JSON.stringify(this._value) === JSON.stringify(vo.value);
18
+ }
19
+ }
20
+ exports.ValueObject = ValueObject;
21
+ //# sourceMappingURL=value-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-object.js","sourceRoot":"","sources":["../../src/domain/value-object.ts"],"names":[],"mappings":";;;AAGA,MAAsB,WAAW;IAO7B,YAAY,KAAQ;QAChB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAMD,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAOM,MAAM,CAAC,EAAkB;QAC5B,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAClD,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;CAaJ;AA1CD,kCA0CC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './domain';
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./domain"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@axisparkjs/ddd",
3
+ "version": "1.0.0",
4
+ "description": "AxiSpark.js - The Ultimate Node.js Framework - @axisparkjs/ddd",
5
+ "author": "Pablo Gálvez Ortuño",
6
+ "license": "Apache-2.0",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "files": [
10
+ "lib",
11
+ "package.json",
12
+ "PACKAGE.md",
13
+ "tsconfig.build.json"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -b tsconfig.build.json",
17
+ "prettier": "prettier --config ../../.prettierrc.json --ignore-path ../../.prettierignore '**/*.{ts,js,mjs,json,md,html,css,scss}' --check",
18
+ "lint": "eslint --config ../../eslint.config.mjs .",
19
+ "test:unit": "export NODE_ENV=test && jest --config jest.config.ts",
20
+ "sonar": "sonar-scanner -Dsonar.projectKey=axisparkjs-ddd"
21
+ },
22
+ "engines": {
23
+ "node": ">= 20"
24
+ }
25
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "lib"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["node_modules", "lib", "jest.config.ts", "**/*.spec.ts"]
9
+ }