@pocket-architect/core 0.1.8 → 0.1.9
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/build/AggregateRoot.d.ts +1 -1
- package/build/AggregateRoot.js.map +1 -1
- package/build/Entity.d.ts +5 -5
- package/build/Entity.js.map +1 -1
- package/build/Entity.spec.js.map +1 -1
- package/build/EntityId.d.ts +6 -5
- package/build/EntityId.js +3 -2
- package/build/EntityId.js.map +1 -1
- package/build/EntityId.spec.js +2 -2
- package/build/EntityId.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/AggregateRoot.ts +1 -1
- package/src/Entity.spec.ts +2 -2
- package/src/Entity.ts +7 -7
- package/src/EntityId.spec.ts +3 -3
- package/src/EntityId.ts +8 -7
package/build/AggregateRoot.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Entity } from './Entity';
|
|
2
2
|
import { EntityId } from './EntityId';
|
|
3
|
-
export declare abstract class AggregateRoot<T, H extends EntityId
|
|
3
|
+
export declare abstract class AggregateRoot<T, E, H extends EntityId<E>> extends Entity<T, E, H> {
|
|
4
4
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AggregateRoot.js","sourceRoot":"","sources":["../src/AggregateRoot.ts"],"names":[],"mappings":";;;;AAAA,mCAAkC;AAGlC;
|
|
1
|
+
{"version":3,"file":"AggregateRoot.js","sourceRoot":"","sources":["../src/AggregateRoot.ts"],"names":[],"mappings":";;;;AAAA,mCAAkC;AAGlC;IAAyE,yCAAe;IAAxF;;IAEA,CAAC;IAAD,oBAAC;AAAD,CAAC,AAFD,CAAyE,eAAM,GAE9E;AAFqB,sCAAa"}
|
package/build/Entity.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { EntityId } from './EntityId';
|
|
2
|
-
export declare abstract class Entity<T, H extends EntityId
|
|
3
|
-
protected readonly _id:
|
|
2
|
+
export declare abstract class Entity<T, E, H extends EntityId<E>> {
|
|
3
|
+
protected readonly _id: EntityId<E>;
|
|
4
4
|
protected props: T;
|
|
5
|
-
protected constructor(props: T, id?: H |
|
|
6
|
-
equals(object?: Entity<T, H>): boolean;
|
|
7
|
-
get id():
|
|
5
|
+
protected constructor(props: T, id?: H | E);
|
|
6
|
+
equals(object?: Entity<T, E, H>): boolean;
|
|
7
|
+
get id(): EntityId<E>;
|
|
8
8
|
toPrimitive(): T;
|
|
9
9
|
toJSON(): T;
|
|
10
10
|
}
|
package/build/Entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC,IAAM,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC,IAAM,QAAQ,GAAG,UAA8B,CAAkB;IAC/D,OAAO,CAAC,YAAY,MAAM,CAAA;AAC5B,CAAC,CAAA;AAED;IAIE,gBAAsB,KAAQ,EAAE,EAAQ;QACtC,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,GAAG,GAAM,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAQ,CAAI,EAAE,CAAC,CAAC,CAAC;QACpE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,GAAM,CAAC,IAAI,mBAAQ,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEM,uBAAM,GAAb,UAAc,MAAwB;QACpC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACpB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,sBAAI,sBAAE;aAAN;YACE,OAAO,IAAI,CAAC,GAAG,CAAA;QACjB,CAAC;;;OAAA;IAED,4BAAW,GAAX;QACE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,uBAAM,GAAN;QACE,OAAO,IAAI,CAAC,WAAW,EAAE,CAAA;IAC3B,CAAC;IACH,aAAC;AAAD,CAAC,AAxCD,IAwCC;AAxCqB,wBAAM"}
|
package/build/Entity.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.spec.js","sourceRoot":"","sources":["../src/Entity.spec.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,uCAAsC;AAKtC;IAAyB,
|
|
1
|
+
{"version":3,"file":"Entity.spec.js","sourceRoot":"","sources":["../src/Entity.spec.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,uCAAsC;AAKtC;IAAyB,sCAA2C;IAApE;;IAIA,CAAC;IAHQ,iBAAM,GAAb,UAAc,KAAgB,EAAE,EAA2B;QACzD,OAAO,IAAI,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IACH,iBAAC;AAAD,CAAC,AAJD,CAAyB,eAAM,GAI9B;AAED,QAAQ,CAAC,QAAQ,EAAE;IACjB,IAAI,MAAkB,CAAC;IAEvB,SAAS,CAAC;QACR,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE;;;YACL,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,EA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E,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;;;SAC/E,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/build/EntityId.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export declare class EntityId {
|
|
2
|
-
protected _recordId:
|
|
1
|
+
export declare class EntityId<T> {
|
|
2
|
+
protected _recordId: T | null;
|
|
3
3
|
protected _uuid: string;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
protected _hasValue: boolean;
|
|
5
|
+
constructor(recordId?: T, uuid?: string);
|
|
6
|
+
toPrimitive(): T;
|
|
6
7
|
toString(): string;
|
|
7
|
-
equals(id: EntityId): boolean;
|
|
8
|
+
equals(id: EntityId<T>): boolean;
|
|
8
9
|
}
|
package/build/EntityId.js
CHANGED
|
@@ -10,13 +10,14 @@ var EntityId = /** @class */ (function () {
|
|
|
10
10
|
if (uuid === void 0) { uuid = null; }
|
|
11
11
|
this._recordId = null;
|
|
12
12
|
this._uuid = null;
|
|
13
|
-
this.
|
|
13
|
+
this._hasValue = false;
|
|
14
|
+
this._recordId = recordId ? recordId : null;
|
|
14
15
|
if (!uuid) {
|
|
15
16
|
this._uuid = (0, uuid_by_string_1.default)(recordId ? recordId.toString() : (0, cuid2_1.createId)(), (0, uuid_by_string_1.default)(this.constructor.name));
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
EntityId.prototype.toPrimitive = function () {
|
|
19
|
-
return this._recordId;
|
|
20
|
+
return this._hasValue ? this._recordId : null;
|
|
20
21
|
};
|
|
21
22
|
EntityId.prototype.toString = function () {
|
|
22
23
|
return this._uuid;
|
package/build/EntityId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityId.js","sourceRoot":"","sources":["../src/EntityId.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,8CAA+C;AAE/C;
|
|
1
|
+
{"version":3,"file":"EntityId.js","sourceRoot":"","sources":["../src/EntityId.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,8CAA+C;AAE/C;IAKE,kBAAY,QAAkB,EAAE,IAAmB;QAAvC,yBAAA,EAAA,eAAkB;QAAE,qBAAA,EAAA,WAAmB;QAJzC,cAAS,GAAW,IAAI,CAAC;QACzB,UAAK,GAAW,IAAI,CAAC;QACrB,cAAS,GAAY,KAAK,CAAC;QAGnC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAA,gBAAQ,GAAE,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC;IAED,8BAAW,GAAX;QACE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAChD,CAAC;IAED,2BAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,yBAAM,GAAN,UAAO,EAAe;QACpB,OAAO,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,CAAC;IACjC,CAAC;IACH,eAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,4BAAQ"}
|
package/build/EntityId.spec.js
CHANGED
|
@@ -13,9 +13,9 @@ describe('ValueObject', function () {
|
|
|
13
13
|
test('base', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
14
14
|
var id, id2, id3;
|
|
15
15
|
return tslib_1.__generator(this, function (_a) {
|
|
16
|
-
id = new TestId(
|
|
16
|
+
id = new TestId(1);
|
|
17
17
|
id2 = new EntityId_1.EntityId('1');
|
|
18
|
-
id3 = new TestId(
|
|
18
|
+
id3 = new TestId(1);
|
|
19
19
|
expect(id).toEqual(id3);
|
|
20
20
|
expect(id).not.toEqual(id2);
|
|
21
21
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityId.spec.js","sourceRoot":"","sources":["../src/EntityId.spec.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC;IAAqB,
|
|
1
|
+
{"version":3,"file":"EntityId.spec.js","sourceRoot":"","sources":["../src/EntityId.spec.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC;IAAqB,kCAAgB;IAArC;;IACA,CAAC;IAAD,aAAC;AAAD,CAAC,AADD,CAAqB,mBAAQ,GAC5B;AAED,QAAQ,CAAC,aAAa,EAAE;IACtB,IAAI,CAAC,MAAM,EAAE;;;YACL,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;YACnB,GAAG,GAAG,IAAI,mBAAQ,CAAC,GAAG,CAAC,CAAC;YACxB,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxB,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;;;SAC7B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/AggregateRoot.ts
CHANGED
package/src/Entity.spec.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { EntityId } from './EntityId';
|
|
|
4
4
|
interface TestProps {
|
|
5
5
|
name: string;
|
|
6
6
|
}
|
|
7
|
-
class TestEntity extends Entity<TestProps, EntityId
|
|
8
|
-
static create(props: TestProps, id?:EntityId
|
|
7
|
+
class TestEntity extends Entity<TestProps, number, EntityId<number>> {
|
|
8
|
+
static create(props: TestProps, id?:EntityId<number>|number): TestEntity {
|
|
9
9
|
return new TestEntity(props, id);
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/Entity.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { EntityId } from './EntityId';
|
|
2
2
|
|
|
3
|
-
const isEntity = <T,
|
|
3
|
+
const isEntity = <T, E, M extends EntityId<E>>(v: Entity<T, E, M>): v is Entity<T, E, M> => {
|
|
4
4
|
return v instanceof Entity
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export abstract class Entity<T, H extends EntityId
|
|
8
|
-
protected readonly _id:
|
|
7
|
+
export abstract class Entity<T, E, H extends EntityId<E>> {
|
|
8
|
+
protected readonly _id: EntityId<E>;
|
|
9
9
|
protected props: T;
|
|
10
10
|
|
|
11
|
-
protected constructor(props: T, id?: H|
|
|
11
|
+
protected constructor(props: T, id?: H|E) {
|
|
12
12
|
if (id) {
|
|
13
|
-
this._id = <H>(typeof id === 'object' ? id : new EntityId(id));
|
|
13
|
+
this._id = <H>(typeof id === 'object' ? id : new EntityId<E>(id));
|
|
14
14
|
} else {
|
|
15
15
|
this._id = <H>(new EntityId());
|
|
16
16
|
}
|
|
17
17
|
this.props = props
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public equals(object?: Entity<T, H>): boolean {
|
|
20
|
+
public equals(object?: Entity<T, E, H>): boolean {
|
|
21
21
|
if (object === null || object === undefined) {
|
|
22
22
|
return false
|
|
23
23
|
}
|
|
@@ -33,7 +33,7 @@ export abstract class Entity<T, H extends EntityId> {
|
|
|
33
33
|
return this._id.equals(object._id);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
get id():
|
|
36
|
+
get id(): EntityId<E> {
|
|
37
37
|
return this._id
|
|
38
38
|
}
|
|
39
39
|
|
package/src/EntityId.spec.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EntityId } from './EntityId';
|
|
2
2
|
|
|
3
|
-
class TestId extends EntityId {
|
|
3
|
+
class TestId extends EntityId<number> {
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
describe('ValueObject', () => {
|
|
7
7
|
test('base', async () => {
|
|
8
|
-
const id = new TestId(
|
|
8
|
+
const id = new TestId(1);
|
|
9
9
|
const id2 = new EntityId('1');
|
|
10
|
-
const id3 = new TestId(
|
|
10
|
+
const id3 = new TestId(1);
|
|
11
11
|
expect(id).toEqual(id3);
|
|
12
12
|
expect(id).not.toEqual(id2);
|
|
13
13
|
});
|
package/src/EntityId.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import createUUID from 'uuid-by-string'
|
|
2
2
|
import { createId } from '@paralleldrive/cuid2'
|
|
3
3
|
|
|
4
|
-
export class EntityId {
|
|
5
|
-
protected _recordId:
|
|
4
|
+
export class EntityId<T> {
|
|
5
|
+
protected _recordId: T|null = null;
|
|
6
6
|
protected _uuid: string = null;
|
|
7
|
+
protected _hasValue: boolean = false;
|
|
7
8
|
|
|
8
|
-
constructor(recordId:
|
|
9
|
-
this._recordId = recordId ? recordId
|
|
9
|
+
constructor(recordId: T = null, uuid: string = null) {
|
|
10
|
+
this._recordId = recordId ? recordId : null;
|
|
10
11
|
if (!uuid) {
|
|
11
12
|
this._uuid = createUUID(recordId ? recordId.toString() : createId(), createUUID(this.constructor.name));
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
toPrimitive():
|
|
16
|
-
return this._recordId;
|
|
16
|
+
toPrimitive(): T {
|
|
17
|
+
return this._hasValue ? this._recordId : null;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
toString(): string {
|
|
20
21
|
return this._uuid;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
equals(id: EntityId): boolean {
|
|
24
|
+
equals(id: EntityId<T>): boolean {
|
|
24
25
|
return this._uuid === id._uuid;
|
|
25
26
|
}
|
|
26
27
|
}
|