@velony/domain 1.0.0 → 1.0.1
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/Id.d.ts +6 -0
- package/dist/Id.js +5 -0
- package/dist/Id.js.map +1 -0
- package/dist/aggregate-root.d.ts +11 -0
- package/dist/aggregate-root.js +14 -0
- package/dist/aggregate-root.js.map +1 -0
- package/dist/domain-event.d.ts +11 -0
- package/dist/domain-event.js +19 -0
- package/dist/domain-event.js.map +1 -0
- package/dist/entity.d.ts +10 -0
- package/dist/entity.js +14 -0
- package/dist/entity.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/primitive-value-object.d.ts +8 -0
- package/dist/primitive-value-object.js +11 -0
- package/dist/primitive-value-object.js.map +1 -0
- package/dist/value-object.d.ts +10 -0
- package/dist/value-object.js +11 -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 +27 -0
- package/dist/value-objects/storage-path.vo.js.map +1 -0
- package/package.json +13 -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
package/dist/Id.d.ts
ADDED
package/dist/Id.js
ADDED
package/dist/Id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAInE,MAAM,OAAgB,EAEpB,SAAQ,oBAAuB;IACd,CAAC,QAAQ,CAAC,CAAO;CACnC"}
|
|
@@ -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,14 @@
|
|
|
1
|
+
import { Entity } from './entity';
|
|
2
|
+
export class AggregateRoot extends Entity {
|
|
3
|
+
[AGGREGATE_ROOT_BRAND];
|
|
4
|
+
_domainEvents = [];
|
|
5
|
+
pullDomainEvents() {
|
|
6
|
+
const events = [...this._domainEvents];
|
|
7
|
+
this._domainEvents = [];
|
|
8
|
+
return events;
|
|
9
|
+
}
|
|
10
|
+
addDomainEvent(event) {
|
|
11
|
+
this._domainEvents.push(event);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=aggregate-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../src/aggregate-root.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,MAAM,OAAgB,aAEpB,SAAQ,MAAmB;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"}
|
|
@@ -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,19 @@
|
|
|
1
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
2
|
+
export class DomainEvent {
|
|
3
|
+
[DOMAIN_EVENT_BRAND];
|
|
4
|
+
static type;
|
|
5
|
+
id;
|
|
6
|
+
aggregateId;
|
|
7
|
+
payload;
|
|
8
|
+
occurredAt;
|
|
9
|
+
constructor(aggregateId, payload) {
|
|
10
|
+
this.id = uuidv7();
|
|
11
|
+
this.aggregateId = aggregateId;
|
|
12
|
+
this.occurredAt = new Date();
|
|
13
|
+
this.payload = payload;
|
|
14
|
+
}
|
|
15
|
+
get type() {
|
|
16
|
+
return this.constructor.type;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=domain-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../src/domain-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAIpC,MAAM,OAAgB,WAAW;IACd,CAAC,kBAAkB,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,MAAM,EAAE,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"}
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAIA,MAAM,OAAgB,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"}
|
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,8 @@
|
|
|
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';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { ValueObject } from './value-object';
|
|
2
|
+
export class PrimitiveValueObject extends ValueObject {
|
|
3
|
+
[PRIMITIVE_VO_BRAND];
|
|
4
|
+
equals(other) {
|
|
5
|
+
return this._value === other.value;
|
|
6
|
+
}
|
|
7
|
+
toString() {
|
|
8
|
+
return String(this._value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,MAAM,OAAgB,oBAEpB,SAAQ,WAAc;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"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"value-object.js","sourceRoot":"","sources":["../src/value-object.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,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"}
|
|
@@ -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,27 @@
|
|
|
1
|
+
import { PrimitiveValueObject } from '../primitive-value-object';
|
|
2
|
+
export class StoragePath extends PrimitiveValueObject {
|
|
3
|
+
[STORAGE_PATH_VO_BRAND];
|
|
4
|
+
constructor(value) {
|
|
5
|
+
super(value);
|
|
6
|
+
}
|
|
7
|
+
static create(value) {
|
|
8
|
+
if (value.startsWith('/')) {
|
|
9
|
+
throw new Error('Storage path should not start with /');
|
|
10
|
+
}
|
|
11
|
+
if (value.includes('//')) {
|
|
12
|
+
throw new Error('Storage path contains invalid double slashes');
|
|
13
|
+
}
|
|
14
|
+
if (value.includes('..')) {
|
|
15
|
+
throw new Error('Storage path cannot contain ..');
|
|
16
|
+
}
|
|
17
|
+
return new StoragePath(value);
|
|
18
|
+
}
|
|
19
|
+
toUrl(baseUrl) {
|
|
20
|
+
return `${baseUrl.replace(/\/$/, '')}/${this._value}`;
|
|
21
|
+
}
|
|
22
|
+
get extension() {
|
|
23
|
+
const parts = this._value.split('.');
|
|
24
|
+
return parts.at(-1)?.toLowerCase() ?? '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# 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,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE,MAAM,OAAO,WAAY,SAAQ,oBAA4B;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"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velony/domain",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
6
17
|
"scripts": {
|
|
7
18
|
"build": "tsc",
|
|
8
19
|
"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
|
-
}
|