@schorts/shared-kernel 1.1.0 → 1.1.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/CHANGELOG +15 -1
- package/__tests__/dao/dao.test.ts +17 -0
- package/__tests__/entities/register-entity.decorator.test.ts +54 -0
- package/dist/auth/auth-provider.d.ts +2 -1
- package/dist/auth/auth-provider.d.ts.map +1 -1
- package/dist/dao/dao.d.ts +15 -0
- package/dist/dao/dao.d.ts.map +1 -0
- package/dist/dao/dao.js +3 -0
- package/dist/dao/dao.js.map +1 -0
- package/dist/dao/index.d.ts +2 -0
- package/dist/dao/index.d.ts.map +1 -0
- package/dist/dao/index.js +3 -0
- package/dist/dao/index.js.map +1 -0
- package/dist/entities/entity-registry.d.ts +14 -0
- package/dist/entities/entity-registry.d.ts.map +1 -0
- package/dist/entities/entity-registry.js +22 -0
- package/dist/entities/entity-registry.js.map +1 -0
- package/dist/entities/entity.d.ts +4 -3
- package/dist/entities/entity.d.ts.map +1 -1
- package/dist/entities/entity.js +3 -0
- package/dist/entities/entity.js.map +1 -1
- package/dist/entities/exceptions/entity-not-registered.d.ts +3 -0
- package/dist/entities/exceptions/entity-not-registered.d.ts.map +1 -0
- package/dist/entities/exceptions/entity-not-registered.js +7 -0
- package/dist/entities/exceptions/entity-not-registered.js.map +1 -0
- package/dist/entities/exceptions/index.d.ts +2 -0
- package/dist/entities/exceptions/index.d.ts.map +1 -0
- package/dist/entities/exceptions/index.js +6 -0
- package/dist/entities/exceptions/index.js.map +1 -0
- package/dist/entities/index.d.ts +3 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +7 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/register-entity.decorator.d.ts +9 -0
- package/dist/entities/register-entity.decorator.d.ts.map +1 -0
- package/dist/entities/register-entity.decorator.js +11 -0
- package/dist/entities/register-entity.decorator.js.map +1 -0
- package/dist/unit-of-work/index.d.ts +2 -0
- package/dist/unit-of-work/index.d.ts.map +1 -0
- package/dist/unit-of-work/index.js +3 -0
- package/dist/unit-of-work/index.js.map +1 -0
- package/dist/unit-of-work/unit-of-work.d.ts +6 -0
- package/dist/unit-of-work/unit-of-work.d.ts.map +1 -0
- package/dist/unit-of-work/unit-of-work.js +3 -0
- package/dist/unit-of-work/unit-of-work.js.map +1 -0
- package/package.json +1 -1
- package/src/entities/entity-registry.ts +1 -1
- package/src/entities/index.ts +1 -0
- package/src/entities/register-entity.decorator.ts +16 -0
package/CHANGELOG
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.1.2] - 2025-09-30
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Now the `DAO` actions like `create`, `update` and `delete` can receive a `UnitOfWork`.
|
|
13
|
+
|
|
14
|
+
## [1.1.1] - 2025-09-30
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Added `RegisterEntity` decorator to only decorate the entity to add it to the `EntityRegistry`.
|
|
19
|
+
|
|
8
20
|
## [1.1.0] - 2025-09-30
|
|
9
21
|
|
|
10
22
|
### Changed
|
|
@@ -38,7 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
38
50
|
|
|
39
51
|
- Removed indirect dependencies from the `package.json`.
|
|
40
52
|
|
|
41
|
-
[1.
|
|
53
|
+
[1.1.2]: https://github.com/schorts99/shared-kernel/compare/v1.1.1...v1.1.2
|
|
54
|
+
[1.1.1]: https://github.com/schorts99/shared-kernel/compare/v1.1.0...v1.1.1
|
|
55
|
+
[1.1.0]: https://github.com/schorts99/shared-kernel/compare/v1.0.5...v1.1.0
|
|
42
56
|
[1.0.5]: https://github.com/schorts99/shared-kernel/compare/v1.0.4...v0.0.5
|
|
43
57
|
[1.0.4]: https://github.com/schorts99/shared-kernel/compare/v1.0.3...v0.0.4
|
|
44
58
|
[1.0.3]: https://github.com/schorts99/shared-kernel/releases/tag/v1.0.3
|
|
@@ -4,6 +4,7 @@ import { DAO } from "../../src/dao";
|
|
|
4
4
|
import { Entity } from "../../src/entities";
|
|
5
5
|
import { Criteria } from "../../src/criteria";
|
|
6
6
|
import { UUIDValue } from "../../src/value-objects";
|
|
7
|
+
import { UnitOfWork } from "../../src/unit-of-work";
|
|
7
8
|
|
|
8
9
|
type Model = {
|
|
9
10
|
id: string;
|
|
@@ -15,6 +16,10 @@ class IDValue extends UUIDValue {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
class ModelEntity extends Entity<IDValue, Model> {
|
|
19
|
+
constructor(id: IDValue) {
|
|
20
|
+
super(id);
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
toPrimitives(): Model {
|
|
19
24
|
throw new Error("Method not implemented.");
|
|
20
25
|
}
|
|
@@ -82,6 +87,10 @@ describe("DAO", () => {
|
|
|
82
87
|
expectTypeOf<DAO<Model, ModelEntity>>().toHaveProperty("create");
|
|
83
88
|
});
|
|
84
89
|
|
|
90
|
+
it('should receive the entity and can receive a UnitOfWork', () => {
|
|
91
|
+
expectTypeOf<DAO<Model, ModelEntity>['create']>().parameters.toEqualTypeOf<[ModelEntity, UnitOfWork?]>();
|
|
92
|
+
});
|
|
93
|
+
|
|
85
94
|
it('should return a promise with the created entity', () => {
|
|
86
95
|
expectTypeOf<DAO<Model, ModelEntity>['create']>().returns.toEqualTypeOf<Promise<ModelEntity>>();
|
|
87
96
|
});
|
|
@@ -92,6 +101,10 @@ describe("DAO", () => {
|
|
|
92
101
|
expectTypeOf<DAO<Model, ModelEntity>>().toHaveProperty("update");
|
|
93
102
|
});
|
|
94
103
|
|
|
104
|
+
it('should receive the entity and can receive a UnitOfWork', () => {
|
|
105
|
+
expectTypeOf<DAO<Model, ModelEntity>['update']>().parameters.toEqualTypeOf<[ModelEntity, UnitOfWork?]>();
|
|
106
|
+
});
|
|
107
|
+
|
|
95
108
|
it('should return a promise with the updated entity', () => {
|
|
96
109
|
expectTypeOf<DAO<Model, ModelEntity>['update']>().returns.toEqualTypeOf<Promise<ModelEntity>>();
|
|
97
110
|
});
|
|
@@ -102,6 +115,10 @@ describe("DAO", () => {
|
|
|
102
115
|
expectTypeOf<DAO<Model, ModelEntity>>().toHaveProperty("delete");
|
|
103
116
|
});
|
|
104
117
|
|
|
118
|
+
it('should receive the entity and can receive a UnitOfWork', () => {
|
|
119
|
+
expectTypeOf<DAO<Model, ModelEntity>['delete']>().parameters.toEqualTypeOf<[ModelEntity, UnitOfWork?]>();
|
|
120
|
+
});
|
|
121
|
+
|
|
105
122
|
it('should return a promise with the deleted entity', () => {
|
|
106
123
|
expectTypeOf<DAO<Model, ModelEntity>['delete']>().returns.toEqualTypeOf<Promise<ModelEntity>>();
|
|
107
124
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RegisterEntity, EntityRegistry, Entity, EntityNotRegistered } from "../../src/entities";
|
|
2
|
+
import { UUIDValue } from "../../src/value-objects";
|
|
3
|
+
|
|
4
|
+
type MockModel = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
class ID extends UUIDValue {
|
|
9
|
+
attributeName = "id";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class MockEntity extends Entity<ID, MockModel> {
|
|
13
|
+
constructor(id: ID) {
|
|
14
|
+
super(id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toPrimitives(): MockModel {
|
|
18
|
+
return {
|
|
19
|
+
id: this.id.value,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static fromPrimitives<MockModel>(model: MockModel): MockEntity {
|
|
24
|
+
return new MockEntity(new ID(model["id"]));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
RegisterEntity("mock")(MockEntity);
|
|
29
|
+
|
|
30
|
+
describe("RegisterEntity", () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
(EntityRegistry as any).registry.clear();
|
|
33
|
+
RegisterEntity("mock")(MockEntity);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("registers the entity constructor under the given type", () => {
|
|
37
|
+
const resolved = EntityRegistry.resolve<MockModel>("mock");
|
|
38
|
+
expect(resolved).toBe(MockEntity);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("creates an entity instance from registered type", () => {
|
|
42
|
+
const model = { id: 'abc-123' };
|
|
43
|
+
const entity = EntityRegistry.create("mock", model);
|
|
44
|
+
|
|
45
|
+
expect(entity).toBeInstanceOf(MockEntity);
|
|
46
|
+
expect(entity.id.value).toBe("abc-123");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("throws if trying to create an unregistered entity", () => {
|
|
50
|
+
const model = { id: '123' };
|
|
51
|
+
|
|
52
|
+
expect(() => EntityRegistry.create("unknown", model)).toThrow(EntityNotRegistered);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Entity } from "../entities";
|
|
2
2
|
import { BaseModel } from "../models";
|
|
3
|
-
|
|
3
|
+
import { ValueObject } from "../value-objects";
|
|
4
|
+
export interface AuthProvider<UserEntity extends Entity<ValueObject, BaseModel>> {
|
|
4
5
|
authenticate(...args: any[]): Promise<void>;
|
|
5
6
|
logout(): Promise<void>;
|
|
6
7
|
isAuthenticated(): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../../src/auth/auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../../src/auth/auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,WAAW,YAAY,CAAC,UAAU,SAAS,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC;IAC7E,YAAY,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,WAAW,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAC1C,YAAY,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACvE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseModel } from "../models";
|
|
2
|
+
import { Entity as BaseEntity } from "../entities";
|
|
3
|
+
import { Criteria } from "../criteria";
|
|
4
|
+
import { UnitOfWork } from "../unit-of-work";
|
|
5
|
+
import { ValueObject } from "../value-objects";
|
|
6
|
+
export interface DAO<Model extends BaseModel, Entity extends BaseEntity<ValueObject, Model>> {
|
|
7
|
+
getAll(): Promise<Entity[]>;
|
|
8
|
+
findByID(id: Entity["id"]["value"]): Promise<Entity | null>;
|
|
9
|
+
findOneBy(criteria: Criteria): Promise<Entity | null>;
|
|
10
|
+
search(criteria: Criteria): Promise<Entity[]>;
|
|
11
|
+
create(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
12
|
+
update(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
13
|
+
delete(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=dao.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dao.d.ts","sourceRoot":"","sources":["../../src/dao/dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,WAAW,GAAG,CAAC,KAAK,SAAS,SAAS,EAAE,MAAM,SAAS,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC;IACzF,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5D,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACtD,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3D"}
|
package/dist/dao/dao.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dao.js","sourceRoot":"","sources":["../../src/dao/dao.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dao/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dao/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseModel } from "../models";
|
|
2
|
+
import { Entity } from "./entity";
|
|
3
|
+
import { ValueObject } from "../value-objects";
|
|
4
|
+
type EntityConstructor<Model extends BaseModel = BaseModel> = {
|
|
5
|
+
fromPrimitives(model: Model): Entity<ValueObject, Model>;
|
|
6
|
+
};
|
|
7
|
+
export declare class EntityRegistry {
|
|
8
|
+
private static registry;
|
|
9
|
+
static register<Model extends BaseModel>(type: string, entity: EntityConstructor<Model>): void;
|
|
10
|
+
static resolve<Model extends BaseModel>(type: string): EntityConstructor<Model> | null;
|
|
11
|
+
static create<Model extends BaseModel>(type: string, model: Model): Entity<ValueObject, Model>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=entity-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-registry.d.ts","sourceRoot":"","sources":["../../src/entities/entity-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,KAAK,iBAAiB,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS,IAAI;IAC5D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;CAC1D,CAAC;AAEF,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwC;IAE/D,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI;IAI9F,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI;IAItF,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC;CAS/F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityRegistry = void 0;
|
|
4
|
+
const exceptions_1 = require("./exceptions");
|
|
5
|
+
class EntityRegistry {
|
|
6
|
+
static registry = new Map();
|
|
7
|
+
static register(type, entity) {
|
|
8
|
+
this.registry.set(type, entity);
|
|
9
|
+
}
|
|
10
|
+
static resolve(type) {
|
|
11
|
+
return (this.registry.get(type) || null);
|
|
12
|
+
}
|
|
13
|
+
static create(type, model) {
|
|
14
|
+
const entity = this.resolve(type);
|
|
15
|
+
if (!entity) {
|
|
16
|
+
throw new exceptions_1.EntityNotRegistered(`Entity type "${type}" not registered`);
|
|
17
|
+
}
|
|
18
|
+
return entity.fromPrimitives(model);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.EntityRegistry = EntityRegistry;
|
|
22
|
+
//# sourceMappingURL=entity-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-registry.js","sourceRoot":"","sources":["../../src/entities/entity-registry.ts"],"names":[],"mappings":";;;AAEA,6CAAmD;AAOnD,MAAa,cAAc;IACjB,MAAM,CAAC,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IAE/D,MAAM,CAAC,QAAQ,CAA0B,IAAY,EAAE,MAAgC;QACrF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,OAAO,CAA0B,IAAY;QAClD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAoC,CAAC;IAC9E,CAAC;IAED,MAAM,CAAC,MAAM,CAA0B,IAAY,EAAE,KAAY;QAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAQ,IAAI,CAAC,CAAC;QAEzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,gCAAmB,CAAC,gBAAgB,IAAI,kBAAkB,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;;AAnBH,wCAoBC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ValueObject } from "../value-objects";
|
|
2
2
|
import { BaseModel } from "../models";
|
|
3
3
|
import { DomainEvent } from "../domain-events";
|
|
4
|
-
export declare abstract class Entity<Model extends BaseModel> {
|
|
5
|
-
readonly id:
|
|
4
|
+
export declare abstract class Entity<IDValue extends ValueObject, Model extends BaseModel> {
|
|
5
|
+
readonly id: IDValue;
|
|
6
6
|
private domainEvents;
|
|
7
|
-
constructor(id:
|
|
7
|
+
constructor(id: IDValue);
|
|
8
8
|
pullDomainEvents(): Array<DomainEvent>;
|
|
9
9
|
recordDomainEvent(domainEvent: DomainEvent): void;
|
|
10
10
|
abstract toPrimitives(): Model;
|
|
11
|
+
static fromPrimitives<Model extends BaseModel>(_model: Model): void;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,8BAAsB,MAAM,CAAC,KAAK,SAAS,SAAS;
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,8BAAsB,MAAM,CAAC,OAAO,SAAS,WAAW,EAAE,KAAK,SAAS,SAAS;IAGnE,QAAQ,CAAC,EAAE,EAAE,OAAO;IAFhC,OAAO,CAAC,YAAY,CAA0B;gBAEzB,EAAE,EAAE,OAAO;IAEhC,gBAAgB,IAAI,KAAK,CAAC,WAAW,CAAC;IAOtC,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAIjD,QAAQ,CAAC,YAAY,IAAI,KAAK;IAC9B,MAAM,CAAC,cAAc,CAAC,KAAK,SAAS,SAAS,EAAE,MAAM,EAAE,KAAK;CAG7D"}
|
package/dist/entities/entity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entities/entity.ts"],"names":[],"mappings":";;;AAIA,MAAsB,MAAM;IAGL;IAFb,YAAY,GAAuB,EAAE,CAAC;IAE9C,YAAqB,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entities/entity.ts"],"names":[],"mappings":";;;AAIA,MAAsB,MAAM;IAGL;IAFb,YAAY,GAAuB,EAAE,CAAC;IAE9C,YAAqB,EAAW;QAAX,OAAE,GAAF,EAAE,CAAS;IAAG,CAAC;IAEpC,gBAAgB;QACd,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QAEvB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,iBAAiB,CAAC,WAAwB;QACxC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAGD,MAAM,CAAC,cAAc,CAA0B,MAAa;QAC1D,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF;AApBD,wBAoBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-not-registered.d.ts","sourceRoot":"","sources":["../../../src/entities/exceptions/entity-not-registered.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityNotRegistered = void 0;
|
|
4
|
+
class EntityNotRegistered extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.EntityNotRegistered = EntityNotRegistered;
|
|
7
|
+
//# sourceMappingURL=entity-not-registered.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-not-registered.js","sourceRoot":"","sources":["../../../src/entities/exceptions/entity-not-registered.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;CAAG;AAAjD,kDAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/entities/exceptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityNotRegistered = void 0;
|
|
4
|
+
var entity_not_registered_1 = require("./entity-not-registered");
|
|
5
|
+
Object.defineProperty(exports, "EntityNotRegistered", { enumerable: true, get: function () { return entity_not_registered_1.EntityNotRegistered; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entities/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA"}
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/entities/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Entity = void 0;
|
|
3
|
+
exports.RegisterEntity = exports.EntityNotRegistered = exports.EntityRegistry = exports.Entity = void 0;
|
|
4
4
|
var entity_1 = require("./entity");
|
|
5
5
|
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return entity_1.Entity; } });
|
|
6
|
+
var entity_registry_1 = require("./entity-registry");
|
|
7
|
+
Object.defineProperty(exports, "EntityRegistry", { enumerable: true, get: function () { return entity_registry_1.EntityRegistry; } });
|
|
8
|
+
var exceptions_1 = require("./exceptions");
|
|
9
|
+
Object.defineProperty(exports, "EntityNotRegistered", { enumerable: true, get: function () { return exceptions_1.EntityNotRegistered; } });
|
|
10
|
+
var register_entity_decorator_1 = require("./register-entity.decorator");
|
|
11
|
+
Object.defineProperty(exports, "RegisterEntity", { enumerable: true, get: function () { return register_entity_decorator_1.RegisterEntity; } });
|
|
6
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,2CAAmD;AAA1C,iHAAA,mBAAmB,OAAA;AAC5B,yEAA6D;AAApD,2HAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseModel } from "../models";
|
|
2
|
+
import { Entity as BaseEntity } from "./entity";
|
|
3
|
+
import { ValueObject } from "../value-objects";
|
|
4
|
+
type EntityConstructor<Model extends BaseModel = BaseModel> = {
|
|
5
|
+
fromPrimitives(model: Model): BaseEntity<ValueObject, Model>;
|
|
6
|
+
};
|
|
7
|
+
export declare function RegisterEntity<Model extends BaseModel = BaseModel>(type: string): <Entity extends EntityConstructor<Model>>(entity: Entity) => Entity;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=register-entity.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-entity.decorator.d.ts","sourceRoot":"","sources":["../../src/entities/register-entity.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,KAAK,iBAAiB,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS,IAAI;IAC5D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;CAC9D,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,IAC7D,MAAM,SAAS,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ,MAAM,KAAG,MAAM,CAKlF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegisterEntity = RegisterEntity;
|
|
4
|
+
const entity_registry_1 = require("./entity-registry");
|
|
5
|
+
function RegisterEntity(type) {
|
|
6
|
+
return function (entity) {
|
|
7
|
+
entity_registry_1.EntityRegistry.register(type, entity);
|
|
8
|
+
return entity;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=register-entity.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-entity.decorator.js","sourceRoot":"","sources":["../../src/entities/register-entity.decorator.ts"],"names":[],"mappings":";;AASA,wCAMC;AAfD,uDAAmD;AASnD,SAAgB,cAAc,CAAsC,IAAY;IAC9E,OAAO,UAAmD,MAAc;QACtE,gCAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEtC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/unit-of-work/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/unit-of-work/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-of-work.d.ts","sourceRoot":"","sources":["../../src/unit-of-work/unit-of-work.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-of-work.js","sourceRoot":"","sources":["../../src/unit-of-work/unit-of-work.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schorts/shared-kernel",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A modular, type-safe foundation for building expressive, maintainable applications. This package provides core abstractions for domain modeling, HTTP integration, authentication, state management, and more — designed to be framework-agnostic and highly extensible.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@ export class EntityRegistry {
|
|
|
16
16
|
|
|
17
17
|
static resolve<Model extends BaseModel>(type: string): EntityConstructor<Model> | null {
|
|
18
18
|
return (this.registry.get(type) || null) as EntityConstructor<Model> | null;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
static create<Model extends BaseModel>(type: string, model: Model): Entity<ValueObject, Model> {
|
|
22
22
|
const entity = this.resolve<Model>(type);
|
package/src/entities/index.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EntityRegistry } from "./entity-registry";
|
|
2
|
+
import { BaseModel } from "../models";
|
|
3
|
+
import { Entity as BaseEntity } from "./entity";
|
|
4
|
+
import { ValueObject } from "../value-objects";
|
|
5
|
+
|
|
6
|
+
type EntityConstructor<Model extends BaseModel = BaseModel> = {
|
|
7
|
+
fromPrimitives(model: Model): BaseEntity<ValueObject, Model>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function RegisterEntity<Model extends BaseModel = BaseModel>(type: string) {
|
|
11
|
+
return function <Entity extends EntityConstructor<Model>>(entity: Entity): Entity {
|
|
12
|
+
EntityRegistry.register(type, entity);
|
|
13
|
+
|
|
14
|
+
return entity;
|
|
15
|
+
};
|
|
16
|
+
}
|