@gravito/enterprise 0.1.0 → 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/dist/index.d.mts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +134 -0
- package/dist/index.mjs +101 -0
- package/package.json +5 -5
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Command
|
|
3
|
+
*
|
|
4
|
+
* Represents an intent to change the state of the system.
|
|
5
|
+
*/
|
|
6
|
+
declare abstract class Command {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Command Handler Interface
|
|
11
|
+
*/
|
|
12
|
+
interface CommandHandler<TCommand extends Command, TResult = void> {
|
|
13
|
+
handle(command: TCommand): Promise<TResult>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Base Query
|
|
18
|
+
*
|
|
19
|
+
* Represents an intent to retrieve data from the system.
|
|
20
|
+
*/
|
|
21
|
+
declare abstract class Query {
|
|
22
|
+
constructor();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Query Handler Interface
|
|
26
|
+
*/
|
|
27
|
+
interface QueryHandler<TQuery extends Query, TResult> {
|
|
28
|
+
handle(query: TQuery): Promise<TResult>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare abstract class UseCase<TInput, TOutput> {
|
|
32
|
+
constructor();
|
|
33
|
+
abstract execute(input: TInput): Promise<TOutput> | TOutput;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare abstract class DomainEvent {
|
|
37
|
+
readonly occurredOn: Date;
|
|
38
|
+
readonly eventId: string;
|
|
39
|
+
constructor(eventId?: string, occurredOn?: Date);
|
|
40
|
+
get eventName(): string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare abstract class Entity<TId> {
|
|
44
|
+
protected readonly _id: TId;
|
|
45
|
+
constructor(id: TId);
|
|
46
|
+
get id(): TId;
|
|
47
|
+
equals(other: Entity<TId>): boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Aggregate Root
|
|
52
|
+
*
|
|
53
|
+
* A DDD aggregate root that can record and clear domain events.
|
|
54
|
+
*/
|
|
55
|
+
declare abstract class AggregateRoot<TId> extends Entity<TId> {
|
|
56
|
+
private _domainEvents;
|
|
57
|
+
protected addDomainEvent(event: DomainEvent): void;
|
|
58
|
+
pullDomainEvents(): DomainEvent[];
|
|
59
|
+
clearDomainEvents(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Repository<TEntity extends Entity<TId>, TId> {
|
|
63
|
+
save(entity: TEntity): Promise<void>;
|
|
64
|
+
findById(id: TId): Promise<TEntity | null>;
|
|
65
|
+
findAll(): Promise<TEntity[]>;
|
|
66
|
+
delete(id: TId): Promise<void>;
|
|
67
|
+
exists(id: TId): Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare abstract class ValueObject<T> {
|
|
71
|
+
protected readonly props: T;
|
|
72
|
+
constructor(props: T);
|
|
73
|
+
equals(other: ValueObject<T>): boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { AggregateRoot, Command, type CommandHandler, DomainEvent, Entity, Query, type QueryHandler, type Repository, UseCase, ValueObject };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Command
|
|
3
|
+
*
|
|
4
|
+
* Represents an intent to change the state of the system.
|
|
5
|
+
*/
|
|
6
|
+
declare abstract class Command {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Command Handler Interface
|
|
11
|
+
*/
|
|
12
|
+
interface CommandHandler<TCommand extends Command, TResult = void> {
|
|
13
|
+
handle(command: TCommand): Promise<TResult>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Base Query
|
|
18
|
+
*
|
|
19
|
+
* Represents an intent to retrieve data from the system.
|
|
20
|
+
*/
|
|
21
|
+
declare abstract class Query {
|
|
22
|
+
constructor();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Query Handler Interface
|
|
26
|
+
*/
|
|
27
|
+
interface QueryHandler<TQuery extends Query, TResult> {
|
|
28
|
+
handle(query: TQuery): Promise<TResult>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare abstract class UseCase<TInput, TOutput> {
|
|
32
|
+
constructor();
|
|
33
|
+
abstract execute(input: TInput): Promise<TOutput> | TOutput;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare abstract class DomainEvent {
|
|
37
|
+
readonly occurredOn: Date;
|
|
38
|
+
readonly eventId: string;
|
|
39
|
+
constructor(eventId?: string, occurredOn?: Date);
|
|
40
|
+
get eventName(): string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare abstract class Entity<TId> {
|
|
44
|
+
protected readonly _id: TId;
|
|
45
|
+
constructor(id: TId);
|
|
46
|
+
get id(): TId;
|
|
47
|
+
equals(other: Entity<TId>): boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Aggregate Root
|
|
52
|
+
*
|
|
53
|
+
* A DDD aggregate root that can record and clear domain events.
|
|
54
|
+
*/
|
|
55
|
+
declare abstract class AggregateRoot<TId> extends Entity<TId> {
|
|
56
|
+
private _domainEvents;
|
|
57
|
+
protected addDomainEvent(event: DomainEvent): void;
|
|
58
|
+
pullDomainEvents(): DomainEvent[];
|
|
59
|
+
clearDomainEvents(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Repository<TEntity extends Entity<TId>, TId> {
|
|
63
|
+
save(entity: TEntity): Promise<void>;
|
|
64
|
+
findById(id: TId): Promise<TEntity | null>;
|
|
65
|
+
findAll(): Promise<TEntity[]>;
|
|
66
|
+
delete(id: TId): Promise<void>;
|
|
67
|
+
exists(id: TId): Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare abstract class ValueObject<T> {
|
|
71
|
+
protected readonly props: T;
|
|
72
|
+
constructor(props: T);
|
|
73
|
+
equals(other: ValueObject<T>): boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { AggregateRoot, Command, type CommandHandler, DomainEvent, Entity, Query, type QueryHandler, type Repository, UseCase, ValueObject };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AggregateRoot: () => AggregateRoot,
|
|
24
|
+
Command: () => Command,
|
|
25
|
+
DomainEvent: () => DomainEvent,
|
|
26
|
+
Entity: () => Entity,
|
|
27
|
+
Query: () => Query,
|
|
28
|
+
UseCase: () => UseCase,
|
|
29
|
+
ValueObject: () => ValueObject
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/Application/Command.ts
|
|
34
|
+
var Command = class {
|
|
35
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
36
|
+
constructor() {
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/Application/Query.ts
|
|
41
|
+
var Query = class {
|
|
42
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
43
|
+
constructor() {
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/Application/UseCase.ts
|
|
48
|
+
var UseCase = class {
|
|
49
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
50
|
+
constructor() {
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/Domain/Entity.ts
|
|
55
|
+
var Entity = class _Entity {
|
|
56
|
+
_id;
|
|
57
|
+
constructor(id) {
|
|
58
|
+
this._id = id;
|
|
59
|
+
}
|
|
60
|
+
get id() {
|
|
61
|
+
return this._id;
|
|
62
|
+
}
|
|
63
|
+
equals(other) {
|
|
64
|
+
if (other === null || other === void 0) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (this === other) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (!(other instanceof _Entity)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return this._id === other._id;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/Domain/AggregateRoot.ts
|
|
78
|
+
var AggregateRoot = class extends Entity {
|
|
79
|
+
_domainEvents = [];
|
|
80
|
+
addDomainEvent(event) {
|
|
81
|
+
this._domainEvents.push(event);
|
|
82
|
+
}
|
|
83
|
+
pullDomainEvents() {
|
|
84
|
+
const events = [...this._domainEvents];
|
|
85
|
+
this._domainEvents = [];
|
|
86
|
+
return events;
|
|
87
|
+
}
|
|
88
|
+
clearDomainEvents() {
|
|
89
|
+
this._domainEvents = [];
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/Domain/DomainEvent.ts
|
|
94
|
+
var DomainEvent = class {
|
|
95
|
+
occurredOn;
|
|
96
|
+
eventId;
|
|
97
|
+
constructor(eventId, occurredOn) {
|
|
98
|
+
this.eventId = eventId || crypto.randomUUID();
|
|
99
|
+
this.occurredOn = occurredOn || /* @__PURE__ */ new Date();
|
|
100
|
+
}
|
|
101
|
+
get eventName() {
|
|
102
|
+
return this.constructor.name;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/Domain/ValueObject.ts
|
|
107
|
+
var ValueObject = class {
|
|
108
|
+
props;
|
|
109
|
+
constructor(props) {
|
|
110
|
+
this.props = Object.freeze({ ...props });
|
|
111
|
+
}
|
|
112
|
+
equals(other) {
|
|
113
|
+
if (other === null || other === void 0) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (this === other) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (other.constructor !== this.constructor) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return JSON.stringify(this.props) === JSON.stringify(other.props);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
AggregateRoot,
|
|
128
|
+
Command,
|
|
129
|
+
DomainEvent,
|
|
130
|
+
Entity,
|
|
131
|
+
Query,
|
|
132
|
+
UseCase,
|
|
133
|
+
ValueObject
|
|
134
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/Application/Command.ts
|
|
2
|
+
var Command = class {
|
|
3
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
4
|
+
constructor() {
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/Application/Query.ts
|
|
9
|
+
var Query = class {
|
|
10
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
11
|
+
constructor() {
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/Application/UseCase.ts
|
|
16
|
+
var UseCase = class {
|
|
17
|
+
// biome-ignore lint/complexity/noUselessConstructor: mark constructor for coverage without changing behavior
|
|
18
|
+
constructor() {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/Domain/Entity.ts
|
|
23
|
+
var Entity = class _Entity {
|
|
24
|
+
_id;
|
|
25
|
+
constructor(id) {
|
|
26
|
+
this._id = id;
|
|
27
|
+
}
|
|
28
|
+
get id() {
|
|
29
|
+
return this._id;
|
|
30
|
+
}
|
|
31
|
+
equals(other) {
|
|
32
|
+
if (other === null || other === void 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (this === other) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (!(other instanceof _Entity)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return this._id === other._id;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/Domain/AggregateRoot.ts
|
|
46
|
+
var AggregateRoot = class extends Entity {
|
|
47
|
+
_domainEvents = [];
|
|
48
|
+
addDomainEvent(event) {
|
|
49
|
+
this._domainEvents.push(event);
|
|
50
|
+
}
|
|
51
|
+
pullDomainEvents() {
|
|
52
|
+
const events = [...this._domainEvents];
|
|
53
|
+
this._domainEvents = [];
|
|
54
|
+
return events;
|
|
55
|
+
}
|
|
56
|
+
clearDomainEvents() {
|
|
57
|
+
this._domainEvents = [];
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/Domain/DomainEvent.ts
|
|
62
|
+
var DomainEvent = class {
|
|
63
|
+
occurredOn;
|
|
64
|
+
eventId;
|
|
65
|
+
constructor(eventId, occurredOn) {
|
|
66
|
+
this.eventId = eventId || crypto.randomUUID();
|
|
67
|
+
this.occurredOn = occurredOn || /* @__PURE__ */ new Date();
|
|
68
|
+
}
|
|
69
|
+
get eventName() {
|
|
70
|
+
return this.constructor.name;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/Domain/ValueObject.ts
|
|
75
|
+
var ValueObject = class {
|
|
76
|
+
props;
|
|
77
|
+
constructor(props) {
|
|
78
|
+
this.props = Object.freeze({ ...props });
|
|
79
|
+
}
|
|
80
|
+
equals(other) {
|
|
81
|
+
if (other === null || other === void 0) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (this === other) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (other.constructor !== this.constructor) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return JSON.stringify(this.props) === JSON.stringify(other.props);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export {
|
|
94
|
+
AggregateRoot,
|
|
95
|
+
Command,
|
|
96
|
+
DomainEvent,
|
|
97
|
+
Entity,
|
|
98
|
+
Query,
|
|
99
|
+
UseCase,
|
|
100
|
+
ValueObject
|
|
101
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/enterprise",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Enterprise architecture primitives for Gravito framework (DDD/Clean Architecture)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
15
15
|
"test": "bun test",
|
|
16
16
|
"lint": "biome check .",
|
|
17
|
-
"typecheck": "tsc --noEmit",
|
|
17
|
+
"typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
|
|
18
18
|
"test:coverage": "bun test --coverage --coverage-threshold=80",
|
|
19
19
|
"test:ci": "bun test --coverage --coverage-threshold=80"
|
|
20
20
|
},
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"author": "Gravito Team",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"gravito
|
|
33
|
+
"@gravito/core": "workspace:*"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"tsup": "^8.0.0",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
38
|
"bun-types": "latest"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|