@velony/domain 1.0.0 → 1.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/dist/aggregate-root.d.ts +11 -0
- package/dist/aggregate-root.js +18 -0
- package/dist/aggregate-root.js.map +1 -0
- package/dist/domain-event.d.ts +11 -0
- package/dist/domain-event.js +23 -0
- package/dist/domain-event.js.map +1 -0
- package/dist/entity.d.ts +10 -0
- package/dist/entity.js +18 -0
- package/dist/entity.js.map +1 -0
- package/dist/id.d.ts +6 -0
- package/dist/id.js +9 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/primitive-value-object.d.ts +8 -0
- package/dist/primitive-value-object.js +15 -0
- package/dist/primitive-value-object.js.map +1 -0
- package/dist/value-object.d.ts +10 -0
- package/dist/value-object.js +15 -0
- package/dist/value-object.js.map +1 -0
- package/dist/value-objects/storage-path.vo.d.ts +10 -0
- package/dist/value-objects/storage-path.vo.js +31 -0
- package/dist/value-objects/storage-path.vo.js.map +1 -0
- package/package.json +12 -2
- package/.prettierrc +0 -4
- package/eslint.config.mjs +0 -55
- package/src/Id.ts +0 -9
- package/src/aggregate-root.ts +0 -23
- package/src/domain-event.ts +0 -25
- package/src/entity.ts +0 -21
- package/src/primitive-value-object.ts +0 -17
- package/src/value-object.ts +0 -19
- package/src/value-objects/storage-path.vo.ts +0 -34
- package/tsconfig.json +0 -23
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DomainEvent } from './domain-event';
|
|
2
|
+
import { Entity } from './entity';
|
|
3
|
+
import { Id } from './id';
|
|
4
|
+
declare const AGGREGATE_ROOT_BRAND: unique symbol;
|
|
5
|
+
export declare abstract class AggregateRoot<TIdentifier extends Id<string | number>> extends Entity<TIdentifier> {
|
|
6
|
+
private readonly [AGGREGATE_ROOT_BRAND];
|
|
7
|
+
private _domainEvents;
|
|
8
|
+
pullDomainEvents(): DomainEvent<any>[];
|
|
9
|
+
protected addDomainEvent(event: DomainEvent<any>): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
[AGGREGATE_ROOT_BRAND];
|
|
7
|
+
_domainEvents = [];
|
|
8
|
+
pullDomainEvents() {
|
|
9
|
+
const events = [...this._domainEvents];
|
|
10
|
+
this._domainEvents = [];
|
|
11
|
+
return events;
|
|
12
|
+
}
|
|
13
|
+
addDomainEvent(event) {
|
|
14
|
+
this._domainEvents.push(event);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.AggregateRoot = AggregateRoot;
|
|
18
|
+
//# sourceMappingURL=aggregate-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../src/aggregate-root.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAKlC,MAAsB,aAEpB,SAAQ,eAAmB;IACV,CAAC,oBAAoB,CAAC,CAAO;IAEtC,aAAa,GAAuB,EAAE,CAAC;IAExC,gBAAgB;QACrB,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,cAAc,CAAC,KAAuB;QAC9C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF;AAhBD,sCAgBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const DOMAIN_EVENT_BRAND: unique symbol;
|
|
2
|
+
export declare abstract class DomainEvent<TPayload> {
|
|
3
|
+
private readonly [DOMAIN_EVENT_BRAND];
|
|
4
|
+
static readonly type: string;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly aggregateId: string;
|
|
7
|
+
readonly payload: TPayload;
|
|
8
|
+
readonly occurredAt: Date;
|
|
9
|
+
protected constructor(aggregateId: string, payload: TPayload);
|
|
10
|
+
get type(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainEvent = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class DomainEvent {
|
|
6
|
+
[exports.DOMAIN_EVENT_BRAND];
|
|
7
|
+
static type;
|
|
8
|
+
id;
|
|
9
|
+
aggregateId;
|
|
10
|
+
payload;
|
|
11
|
+
occurredAt;
|
|
12
|
+
constructor(aggregateId, payload) {
|
|
13
|
+
this.id = (0, uuid_1.v7)();
|
|
14
|
+
this.aggregateId = aggregateId;
|
|
15
|
+
this.occurredAt = new Date();
|
|
16
|
+
this.payload = payload;
|
|
17
|
+
}
|
|
18
|
+
get type() {
|
|
19
|
+
return this.constructor.type;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.DomainEvent = DomainEvent;
|
|
23
|
+
//# sourceMappingURL=domain-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../src/domain-event.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAIpC,MAAsB,WAAW;IACd,CAAC,0BAAkB,CAAC,CAAO;IAErC,MAAM,CAAU,IAAI,CAAS;IAEpB,EAAE,CAAS;IACX,WAAW,CAAS;IACpB,OAAO,CAAW;IAClB,UAAU,CAAO;IAEjC,YAAsB,WAAmB,EAAE,OAAiB;QAC1D,IAAI,CAAC,EAAE,GAAG,IAAA,SAAM,GAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAW,IAAI;QACb,OAAQ,IAAI,CAAC,WAA4C,CAAC,IAAI,CAAC;IACjE,CAAC;CACF;AApBD,kCAoBC"}
|
package/dist/entity.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Id } from './id';
|
|
2
|
+
declare const ENTITY_BRAND: unique symbol;
|
|
3
|
+
export declare abstract class Entity<TIdentifier extends Id<string | number>> {
|
|
4
|
+
private readonly [ENTITY_BRAND];
|
|
5
|
+
protected readonly _id: TIdentifier;
|
|
6
|
+
protected constructor(id: TIdentifier);
|
|
7
|
+
get id(): TIdentifier;
|
|
8
|
+
equals(other: this): boolean;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/entity.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = void 0;
|
|
4
|
+
class Entity {
|
|
5
|
+
[ENTITY_BRAND];
|
|
6
|
+
_id;
|
|
7
|
+
constructor(id) {
|
|
8
|
+
this._id = id;
|
|
9
|
+
}
|
|
10
|
+
get id() {
|
|
11
|
+
return this._id;
|
|
12
|
+
}
|
|
13
|
+
equals(other) {
|
|
14
|
+
return this._id.equals(other._id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Entity = Entity;
|
|
18
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":";;;AAIA,MAAsB,MAAM;IACT,CAAC,YAAY,CAAC,CAAO;IAEnB,GAAG,CAAc;IAEpC,YAAsB,EAAe;QACnC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,KAAW;QACvB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;CACF;AAhBD,wBAgBC"}
|
package/dist/id.d.ts
ADDED
package/dist/id.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Id = void 0;
|
|
4
|
+
const primitive_value_object_js_1 = require("./primitive-value-object.js");
|
|
5
|
+
class Id extends primitive_value_object_js_1.PrimitiveValueObject {
|
|
6
|
+
[ID_BRAND];
|
|
7
|
+
}
|
|
8
|
+
exports.Id = Id;
|
|
9
|
+
//# sourceMappingURL=id.js.map
|
package/dist/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":";;;AAAA,2EAAmE;AAInE,MAAsB,EAEpB,SAAQ,gDAAuB;IACd,CAAC,QAAQ,CAAC,CAAO;CACnC;AAJD,gBAIC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Entity } from './entity';
|
|
2
|
+
export { Id } from './id';
|
|
3
|
+
export { ValueObject } from './value-object';
|
|
4
|
+
export { PrimitiveValueObject } from './primitive-value-object';
|
|
5
|
+
export { AggregateRoot } from './aggregate-root';
|
|
6
|
+
export { DomainEvent } from './domain-event';
|
|
7
|
+
export { StoragePath } from './value-objects/storage-path.vo';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoragePath = exports.DomainEvent = exports.AggregateRoot = exports.PrimitiveValueObject = exports.ValueObject = exports.Id = exports.Entity = void 0;
|
|
4
|
+
var entity_1 = require("./entity");
|
|
5
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return entity_1.Entity; } });
|
|
6
|
+
var id_1 = require("./id");
|
|
7
|
+
Object.defineProperty(exports, "Id", { enumerable: true, get: function () { return id_1.Id; } });
|
|
8
|
+
var value_object_1 = require("./value-object");
|
|
9
|
+
Object.defineProperty(exports, "ValueObject", { enumerable: true, get: function () { return value_object_1.ValueObject; } });
|
|
10
|
+
var primitive_value_object_1 = require("./primitive-value-object");
|
|
11
|
+
Object.defineProperty(exports, "PrimitiveValueObject", { enumerable: true, get: function () { return primitive_value_object_1.PrimitiveValueObject; } });
|
|
12
|
+
var aggregate_root_1 = require("./aggregate-root");
|
|
13
|
+
Object.defineProperty(exports, "AggregateRoot", { enumerable: true, get: function () { return aggregate_root_1.AggregateRoot; } });
|
|
14
|
+
var domain_event_1 = require("./domain-event");
|
|
15
|
+
Object.defineProperty(exports, "DomainEvent", { enumerable: true, get: function () { return domain_event_1.DomainEvent; } });
|
|
16
|
+
var storage_path_vo_1 = require("./value-objects/storage-path.vo");
|
|
17
|
+
Object.defineProperty(exports, "StoragePath", { enumerable: true, get: function () { return storage_path_vo_1.StoragePath; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,2BAA0B;AAAjB,wFAAA,EAAE,OAAA;AACX,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,mEAA8D;AAArD,8GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValueObject } from './value-object';
|
|
2
|
+
declare const PRIMITIVE_VO_BRAND: unique symbol;
|
|
3
|
+
export declare abstract class PrimitiveValueObject<T extends string | number | boolean> extends ValueObject<T> {
|
|
4
|
+
private readonly [PRIMITIVE_VO_BRAND];
|
|
5
|
+
equals(other: this): boolean;
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrimitiveValueObject = void 0;
|
|
4
|
+
const value_object_1 = require("./value-object");
|
|
5
|
+
class PrimitiveValueObject extends value_object_1.ValueObject {
|
|
6
|
+
[PRIMITIVE_VO_BRAND];
|
|
7
|
+
equals(other) {
|
|
8
|
+
return this._value === other.value;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return String(this._value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PrimitiveValueObject = PrimitiveValueObject;
|
|
15
|
+
//# sourceMappingURL=primitive-value-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive-value-object.js","sourceRoot":"","sources":["../src/primitive-value-object.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAI7C,MAAsB,oBAEpB,SAAQ,0BAAc;IACL,CAAC,kBAAkB,CAAC,CAAO;IAErC,MAAM,CAAC,KAAW;QACvB,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC;IACrC,CAAC;IAEM,QAAQ;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF;AAZD,oDAYC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const VO_BRAND: unique symbol;
|
|
2
|
+
export declare abstract class ValueObject<TValue> {
|
|
3
|
+
private readonly [VO_BRAND];
|
|
4
|
+
protected readonly _value: TValue;
|
|
5
|
+
protected constructor(value: TValue);
|
|
6
|
+
get value(): TValue;
|
|
7
|
+
abstract equals(other: this): boolean;
|
|
8
|
+
abstract toString(): string;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueObject = void 0;
|
|
4
|
+
class ValueObject {
|
|
5
|
+
[VO_BRAND];
|
|
6
|
+
_value;
|
|
7
|
+
constructor(value) {
|
|
8
|
+
this._value = value;
|
|
9
|
+
}
|
|
10
|
+
get value() {
|
|
11
|
+
return this._value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ValueObject = ValueObject;
|
|
15
|
+
//# sourceMappingURL=value-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-object.js","sourceRoot":"","sources":["../src/value-object.ts"],"names":[],"mappings":";;;AAEA,MAAsB,WAAW;IACd,CAAC,QAAQ,CAAC,CAAO;IAEf,MAAM,CAAS;IAElC,YAAsB,KAAa;QACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CAKF;AAhBD,kCAgBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PrimitiveValueObject } from '../primitive-value-object';
|
|
2
|
+
declare const STORAGE_PATH_VO_BRAND: unique symbol;
|
|
3
|
+
export declare class StoragePath extends PrimitiveValueObject<string> {
|
|
4
|
+
private readonly [STORAGE_PATH_VO_BRAND];
|
|
5
|
+
private constructor();
|
|
6
|
+
static create(value: string): StoragePath;
|
|
7
|
+
toUrl(baseUrl: string): string;
|
|
8
|
+
get extension(): string;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoragePath = void 0;
|
|
4
|
+
const primitive_value_object_1 = require("../primitive-value-object");
|
|
5
|
+
class StoragePath extends primitive_value_object_1.PrimitiveValueObject {
|
|
6
|
+
[STORAGE_PATH_VO_BRAND];
|
|
7
|
+
constructor(value) {
|
|
8
|
+
super(value);
|
|
9
|
+
}
|
|
10
|
+
static create(value) {
|
|
11
|
+
if (value.startsWith('/')) {
|
|
12
|
+
throw new Error('Storage path should not start with /');
|
|
13
|
+
}
|
|
14
|
+
if (value.includes('//')) {
|
|
15
|
+
throw new Error('Storage path contains invalid double slashes');
|
|
16
|
+
}
|
|
17
|
+
if (value.includes('..')) {
|
|
18
|
+
throw new Error('Storage path cannot contain ..');
|
|
19
|
+
}
|
|
20
|
+
return new StoragePath(value);
|
|
21
|
+
}
|
|
22
|
+
toUrl(baseUrl) {
|
|
23
|
+
return `${baseUrl.replace(/\/$/, '')}/${this._value}`;
|
|
24
|
+
}
|
|
25
|
+
get extension() {
|
|
26
|
+
const parts = this._value.split('.');
|
|
27
|
+
return parts.at(-1)?.toLowerCase() ?? '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.StoragePath = StoragePath;
|
|
31
|
+
//# sourceMappingURL=storage-path.vo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-path.vo.js","sourceRoot":"","sources":["../../src/value-objects/storage-path.vo.ts"],"names":[],"mappings":";;;AAAA,sEAAiE;AAIjE,MAAa,WAAY,SAAQ,6CAA4B;IAC1C,CAAC,qBAAqB,CAAC,CAAO;IAE/C,YAAoB,KAAa;QAC/B,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,KAAa;QAChC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;IACxD,CAAC;IAED,IAAW,SAAS;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC3C,CAAC;CACF;AA7BD,kCA6BC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velony/domain",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
6
16
|
"scripts": {
|
|
7
17
|
"build": "tsc",
|
|
8
18
|
"lint": "eslint src"
|
package/.prettierrc
DELETED
package/eslint.config.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import securityPlugin from 'eslint-plugin-security';
|
|
4
|
-
import prettierPlugin from 'eslint-plugin-prettier/recommended';
|
|
5
|
-
import prettierConfig from 'eslint-config-prettier';
|
|
6
|
-
|
|
7
|
-
export default [
|
|
8
|
-
// Base configs
|
|
9
|
-
eslint.configs.recommended,
|
|
10
|
-
...tseslint.configs.recommended,
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
settings: {
|
|
14
|
-
'import/resolver': {
|
|
15
|
-
typescript: {
|
|
16
|
-
project: './tsconfig.json',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
// Security
|
|
23
|
-
securityPlugin.configs.recommended,
|
|
24
|
-
|
|
25
|
-
// TypeScript-specific rules
|
|
26
|
-
{
|
|
27
|
-
files: ['**/*.ts'],
|
|
28
|
-
rules: {
|
|
29
|
-
'no-console': 'warn',
|
|
30
|
-
'@typescript-eslint/no-unused-vars': [
|
|
31
|
-
'warn',
|
|
32
|
-
{
|
|
33
|
-
argsIgnorePattern: '^_',
|
|
34
|
-
varsIgnorePattern: '^_',
|
|
35
|
-
caughtErrorsIgnorePattern: '^_',
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
39
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
40
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
41
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// Prettier integration
|
|
46
|
-
prettierPlugin,
|
|
47
|
-
|
|
48
|
-
// Ignore patterns
|
|
49
|
-
{
|
|
50
|
-
ignores: ['node_modules/', 'dist/', '.eslintrc.js', 'eslint.config.mjs'],
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// Disable rules conflicting with Prettier (must be last)
|
|
54
|
-
prettierConfig,
|
|
55
|
-
];
|
package/src/Id.ts
DELETED
package/src/aggregate-root.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DomainEvent } from './domain-event';
|
|
2
|
-
import { Entity } from './entity';
|
|
3
|
-
import { Id } from './Id';
|
|
4
|
-
|
|
5
|
-
declare const AGGREGATE_ROOT_BRAND: unique symbol;
|
|
6
|
-
|
|
7
|
-
export abstract class AggregateRoot<
|
|
8
|
-
TIdentifier extends Id<string | number>,
|
|
9
|
-
> extends Entity<TIdentifier> {
|
|
10
|
-
private readonly [AGGREGATE_ROOT_BRAND]: void;
|
|
11
|
-
|
|
12
|
-
private _domainEvents: DomainEvent<any>[] = [];
|
|
13
|
-
|
|
14
|
-
public pullDomainEvents(): DomainEvent<any>[] {
|
|
15
|
-
const events = [...this._domainEvents];
|
|
16
|
-
this._domainEvents = [];
|
|
17
|
-
return events;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected addDomainEvent(event: DomainEvent<any>): void {
|
|
21
|
-
this._domainEvents.push(event);
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/domain-event.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { v7 as uuidv7 } from 'uuid';
|
|
2
|
-
|
|
3
|
-
export declare const DOMAIN_EVENT_BRAND: unique symbol;
|
|
4
|
-
|
|
5
|
-
export abstract class DomainEvent<TPayload> {
|
|
6
|
-
private readonly [DOMAIN_EVENT_BRAND]: void;
|
|
7
|
-
|
|
8
|
-
public static readonly type: string;
|
|
9
|
-
|
|
10
|
-
public readonly id: string;
|
|
11
|
-
public readonly aggregateId: string;
|
|
12
|
-
public readonly payload: TPayload;
|
|
13
|
-
public readonly occurredAt: Date;
|
|
14
|
-
|
|
15
|
-
protected constructor(aggregateId: string, payload: TPayload) {
|
|
16
|
-
this.id = uuidv7();
|
|
17
|
-
this.aggregateId = aggregateId;
|
|
18
|
-
this.occurredAt = new Date();
|
|
19
|
-
this.payload = payload;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public get type(): string {
|
|
23
|
-
return (this.constructor as typeof DomainEvent<TPayload>).type;
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/entity.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Id } from './Id';
|
|
2
|
-
|
|
3
|
-
declare const ENTITY_BRAND: unique symbol;
|
|
4
|
-
|
|
5
|
-
export abstract class Entity<TIdentifier extends Id<string | number>> {
|
|
6
|
-
private readonly [ENTITY_BRAND]: void;
|
|
7
|
-
|
|
8
|
-
protected readonly _id: TIdentifier;
|
|
9
|
-
|
|
10
|
-
protected constructor(id: TIdentifier) {
|
|
11
|
-
this._id = id;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public get id(): TIdentifier {
|
|
15
|
-
return this._id;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public equals(other: this): boolean {
|
|
19
|
-
return this._id.equals(other._id);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from './value-object';
|
|
2
|
-
|
|
3
|
-
declare const PRIMITIVE_VO_BRAND: unique symbol;
|
|
4
|
-
|
|
5
|
-
export abstract class PrimitiveValueObject<
|
|
6
|
-
T extends string | number | boolean,
|
|
7
|
-
> extends ValueObject<T> {
|
|
8
|
-
private readonly [PRIMITIVE_VO_BRAND]: void;
|
|
9
|
-
|
|
10
|
-
public equals(other: this): boolean {
|
|
11
|
-
return this._value === other.value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public toString(): string {
|
|
15
|
-
return String(this._value);
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/value-object.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
declare const VO_BRAND: unique symbol;
|
|
2
|
-
|
|
3
|
-
export abstract class ValueObject<TValue> {
|
|
4
|
-
private readonly [VO_BRAND]: void;
|
|
5
|
-
|
|
6
|
-
protected readonly _value: TValue;
|
|
7
|
-
|
|
8
|
-
protected constructor(value: TValue) {
|
|
9
|
-
this._value = value;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public get value(): TValue {
|
|
13
|
-
return this._value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public abstract equals(other: this): boolean;
|
|
17
|
-
|
|
18
|
-
public abstract toString(): string;
|
|
19
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { PrimitiveValueObject } from '../primitive-value-object';
|
|
2
|
-
|
|
3
|
-
declare const STORAGE_PATH_VO_BRAND: unique symbol;
|
|
4
|
-
|
|
5
|
-
export class StoragePath extends PrimitiveValueObject<string> {
|
|
6
|
-
private readonly [STORAGE_PATH_VO_BRAND]: void;
|
|
7
|
-
|
|
8
|
-
private constructor(value: string) {
|
|
9
|
-
super(value);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static create(value: string): StoragePath {
|
|
13
|
-
if (value.startsWith('/')) {
|
|
14
|
-
throw new Error('Storage path should not start with /');
|
|
15
|
-
}
|
|
16
|
-
if (value.includes('//')) {
|
|
17
|
-
throw new Error('Storage path contains invalid double slashes');
|
|
18
|
-
}
|
|
19
|
-
if (value.includes('..')) {
|
|
20
|
-
throw new Error('Storage path cannot contain ..');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new StoragePath(value);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public toUrl(baseUrl: string): string {
|
|
27
|
-
return `${baseUrl.replace(/\/$/, '')}/${this._value}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public get extension(): string {
|
|
31
|
-
const parts = this._value.split('.');
|
|
32
|
-
return parts.at(-1)?.toLowerCase() ?? '';
|
|
33
|
-
}
|
|
34
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "nodenext",
|
|
4
|
-
"moduleResolution": "nodenext",
|
|
5
|
-
"resolvePackageJsonExports": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"isolatedModules": true,
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"removeComments": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"target": "ES2023",
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"outDir": "./dist",
|
|
14
|
-
"rootDir": "./src",
|
|
15
|
-
"baseUrl": "./",
|
|
16
|
-
"incremental": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"strictNullChecks": true,
|
|
19
|
-
"forceConsistentCasingInFileNames": true
|
|
20
|
-
},
|
|
21
|
-
"include": ["src"],
|
|
22
|
-
"exclude": ["node_modules", "dist"]
|
|
23
|
-
}
|