Skip to content

Commit bacda4c

Browse files
committed
feat(v1): v1 @ddd-framework refactor using decorators for the core module plus seedwork support
1 parent 282c685 commit bacda4c

File tree

209 files changed

+2610
-3629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+2610
-3629
lines changed

.workspaces/@ddd-framework.code-workspace

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@
1212
"path": "../lib/core",
1313
"name": "@ddd-framework/core"
1414
},
15-
{
16-
"path": "../lib/cqrs",
17-
"name": "@ddd-framework/cqrs"
18-
},
1915
{
2016
"path": "../lib/dto",
2117
"name": "@ddd-framework/dto"
2218
},
23-
{
24-
"path": "../lib/event-sourcing",
25-
"name": "@ddd-framework/event-sourcing"
26-
},
2719
{
2820
"path": "../lib/seedwork",
2921
"name": "@ddd-framework/seedwork"

lib/collections/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ddd-framework/collections",
3-
"version": "0.0.1",
3+
"version": "1.0.0-alpha.0",
44
"private": false,
55
"publishConfig": {
66
"access": "public",
@@ -27,7 +27,7 @@
2727
"watch": "tsc --project tsconfig.build.json --watch"
2828
},
2929
"peerDependencies": {
30-
"@ddd-framework/core": "^0.3.0"
30+
"@ddd-framework/core": "^1.0.0"
3131
},
3232
"devDependencies": {
3333
"@config/eslint": "workspace:*",
@@ -39,12 +39,10 @@
3939
"@types/jest": "~29.5.1",
4040
"@types/lodash": "~4.14.194",
4141
"@types/node": "~20.1.5",
42-
"@types/uuid": "~9.0.1",
4342
"jest": "~29.5.0",
4443
"lodash": "~4.17.21",
4544
"reflect-metadata": "~0.1.13",
4645
"ts-jest": "~29.1.0",
47-
"typescript": "~5.0.4",
48-
"uuid": "~9.0.0"
46+
"typescript": "~5.0.4"
4947
}
5048
}

lib/collections/src/List.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Entity, ValueObject } from '@ddd-framework/core';
22

33
/**
4-
* Represents a collection of ValueObject objects.
4+
* Represents an immutable collection of objects that can be accessed by index.
5+
* Provides methods to search, sort, and manipulate lists.
56
*/
6-
export default class List<Item = unknown>
7+
export class List<Item = unknown>
78
extends ValueObject
89
implements Iterable<Item>
910
{
@@ -34,15 +35,13 @@ export default class List<Item = unknown>
3435
* Returns the first item in the List.
3536
*/
3637
public get first(): Item | undefined {
37-
if (this.array.length === 0) return undefined;
3838
return this.array[0];
3939
}
4040

4141
/**
4242
* Returns the last item in the List.
4343
*/
4444
public get last(): Item | undefined {
45-
if (this.array.length === 0) return undefined;
4645
return this.array[this.array.length - 1];
4746
}
4847

lib/collections/src/__tests__/List.test.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { v4 } from 'uuid';
1+
import { faker } from '@faker-js/faker';
22

3-
import User, { UserId } from '../../tests/User';
4-
import List from '../List';
3+
import { User, UserId } from '../../tests/user';
4+
import { List } from '../list';
55

66
describe('List', () => {
7-
const user = new User(new UserId(v4()));
8-
const userTwo = new User(new UserId(v4()));
7+
const user = new User(new UserId(faker.string.uuid()));
8+
const userTwo = new User(new UserId(faker.string.uuid()));
99

1010
describe('constructor', () => {
1111
test('spread argument', () => {
@@ -160,16 +160,16 @@ describe('List', () => {
160160

161161
test('clear', () => {
162162
const list = new List<UserId>()
163-
.insert(new UserId(v4()))
164-
.insert(new UserId(v4()))
165-
.insert(new UserId(v4()))
166-
.insert(new UserId(v4()))
167-
.insert(new UserId(v4()))
168-
.insert(new UserId(v4()))
169-
.insert(new UserId(v4()))
170-
.insert(new UserId(v4()))
171-
.insert(new UserId(v4()))
172-
.insert(new UserId(v4()));
163+
.insert(new UserId(faker.string.uuid()))
164+
.insert(new UserId(faker.string.uuid()))
165+
.insert(new UserId(faker.string.uuid()))
166+
.insert(new UserId(faker.string.uuid()))
167+
.insert(new UserId(faker.string.uuid()))
168+
.insert(new UserId(faker.string.uuid()))
169+
.insert(new UserId(faker.string.uuid()))
170+
.insert(new UserId(faker.string.uuid()))
171+
.insert(new UserId(faker.string.uuid()))
172+
.insert(new UserId(faker.string.uuid()));
173173

174174
expect(list.count).toBe(10);
175175

@@ -184,16 +184,16 @@ describe('List', () => {
184184

185185
test('map', () => {
186186
const userIds = new List<UserId>()
187-
.insert(new UserId(v4()))
188-
.insert(new UserId(v4()))
189-
.insert(new UserId(v4()))
190-
.insert(new UserId(v4()))
191-
.insert(new UserId(v4()))
192-
.insert(new UserId(v4()))
193-
.insert(new UserId(v4()))
194-
.insert(new UserId(v4()))
195-
.insert(new UserId(v4()))
196-
.insert(new UserId(v4()));
187+
.insert(new UserId(faker.string.uuid()))
188+
.insert(new UserId(faker.string.uuid()))
189+
.insert(new UserId(faker.string.uuid()))
190+
.insert(new UserId(faker.string.uuid()))
191+
.insert(new UserId(faker.string.uuid()))
192+
.insert(new UserId(faker.string.uuid()))
193+
.insert(new UserId(faker.string.uuid()))
194+
.insert(new UserId(faker.string.uuid()))
195+
.insert(new UserId(faker.string.uuid()))
196+
.insert(new UserId(faker.string.uuid()));
197197

198198
const strings = userIds.map((id) => id.unpack());
199199

@@ -212,16 +212,16 @@ describe('List', () => {
212212

213213
test('shuffle', () => {
214214
const list = new List<UserId>()
215-
.insert(new UserId(v4()))
216-
.insert(new UserId(v4()))
217-
.insert(new UserId(v4()))
218-
.insert(new UserId(v4()))
219-
.insert(new UserId(v4()))
220-
.insert(new UserId(v4()))
221-
.insert(new UserId(v4()))
222-
.insert(new UserId(v4()))
223-
.insert(new UserId(v4()))
224-
.insert(new UserId(v4()));
215+
.insert(new UserId(faker.string.uuid()))
216+
.insert(new UserId(faker.string.uuid()))
217+
.insert(new UserId(faker.string.uuid()))
218+
.insert(new UserId(faker.string.uuid()))
219+
.insert(new UserId(faker.string.uuid()))
220+
.insert(new UserId(faker.string.uuid()))
221+
.insert(new UserId(faker.string.uuid()))
222+
.insert(new UserId(faker.string.uuid()))
223+
.insert(new UserId(faker.string.uuid()))
224+
.insert(new UserId(faker.string.uuid()));
225225

226226
const newList = new List(list);
227227

lib/collections/src/__tests__/EntityCollection.test.ts renamed to lib/collections/src/__tests__/entity-collection.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { v4 } from 'uuid';
1+
import { faker } from '@faker-js/faker';
22

3-
import User, { UserId } from '../../tests/User';
4-
import EntityCollection from '../EntityCollection';
3+
import { User, UserId } from '../../tests/user';
4+
import { EntityCollection } from '../entity-collection';
55

66
describe('EntityCollection', () => {
7-
const user = new User(new UserId(v4()));
8-
const userTwo = new User(new UserId(v4()));
7+
const user = new User(new UserId(faker.string.uuid()));
8+
const userTwo = new User(new UserId(faker.string.uuid()));
99

1010
test('count', () => {
1111
const collection = new EntityCollection<User>();
@@ -75,11 +75,11 @@ describe('EntityCollection', () => {
7575

7676
collection.add(user);
7777

78-
expect(collection.contains(user.id)).toBeTruthy();
78+
expect(collection.contains(user)).toBeTruthy();
7979

80-
collection.remove(user.id);
80+
collection.remove(user);
8181

82-
expect(collection.contains(user.id)).toBeFalsy();
82+
expect(collection.contains(user)).toBeFalsy();
8383
});
8484
});
8585

@@ -115,11 +115,11 @@ describe('EntityCollection', () => {
115115

116116
collection.add(user);
117117

118-
expect(collection.get(user.id)).toBeTruthy();
118+
expect(collection.get(user)).toBeTruthy();
119119

120-
collection.remove(user.id);
120+
collection.remove(user);
121121

122-
expect(collection.get(user.id)).toBe(undefined);
122+
expect(collection.get(user)).toBe(undefined);
123123
});
124124
});
125125

@@ -141,11 +141,11 @@ describe('EntityCollection', () => {
141141

142142
collection.add(user);
143143

144-
expect(collection.contains(user.id)).toBeTruthy();
144+
expect(collection.contains(user)).toBeTruthy();
145145

146-
collection.remove(user.id);
146+
collection.remove(user);
147147

148-
expect(collection.contains(user.id)).toBeFalsy();
148+
expect(collection.contains(user)).toBeFalsy();
149149
});
150150
});
151151

0 commit comments

Comments
 (0)