@woltz/rich-domain 1.2.4 → 1.3.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/aggregate-changes.d.ts +56 -14
- package/dist/aggregate-changes.d.ts.map +1 -1
- package/dist/aggregate-changes.js +103 -23
- package/dist/aggregate-changes.js.map +1 -1
- package/dist/base-entity.d.ts +1 -1
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +28 -13
- package/dist/base-entity.js.map +1 -1
- package/dist/change-tracker.d.ts +2 -1
- package/dist/change-tracker.d.ts.map +1 -1
- package/dist/change-tracker.js +61 -35
- package/dist/change-tracker.js.map +1 -1
- package/dist/criteria.d.ts +7 -15
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js +105 -81
- package/dist/criteria.js.map +1 -1
- package/dist/domain-event-bus.js +4 -4
- package/dist/domain-event-bus.js.map +1 -1
- package/dist/domain-event.js +3 -0
- package/dist/domain-event.js.map +1 -1
- package/dist/entity-changes.js +1 -0
- package/dist/entity-changes.js.map +1 -1
- package/dist/entity-schema-registry.d.ts +137 -3
- package/dist/entity-schema-registry.d.ts.map +1 -1
- package/dist/entity-schema-registry.js +160 -7
- package/dist/entity-schema-registry.js.map +1 -1
- package/dist/exceptions.js +26 -1
- package/dist/exceptions.js.map +1 -1
- package/dist/id.js +2 -0
- package/dist/id.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/paginated-result.d.ts +4 -4
- package/dist/paginated-result.d.ts.map +1 -1
- package/dist/paginated-result.js +14 -19
- package/dist/paginated-result.js.map +1 -1
- package/dist/repository/unit-of-work.js +3 -7
- package/dist/repository/unit-of-work.js.map +1 -1
- package/dist/types/change-tracker.d.ts +30 -0
- package/dist/types/change-tracker.d.ts.map +1 -1
- package/dist/types/criteria.d.ts +1 -4
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/domain.d.ts +2 -1
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/utils.d.ts +2 -2
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +23 -0
- package/dist/utils/helpers.js.map +1 -1
- package/dist/validation-error.d.ts +15 -1
- package/dist/validation-error.d.ts.map +1 -1
- package/dist/validation-error.js +46 -3
- package/dist/validation-error.js.map +1 -1
- package/dist/value-object.d.ts +1 -1
- package/dist/value-object.d.ts.map +1 -1
- package/dist/value-object.js +30 -2
- package/dist/value-object.js.map +1 -1
- package/package.json +17 -3
- package/src/aggregate-changes.ts +133 -24
- package/src/base-entity.ts +22 -11
- package/src/change-tracker.ts +113 -54
- package/src/criteria.ts +151 -109
- package/src/entity-schema-registry.ts +256 -6
- package/src/index.ts +1 -1
- package/src/paginated-result.ts +21 -29
- package/src/types/change-tracker.ts +31 -0
- package/src/types/criteria.ts +1 -4
- package/src/types/domain.ts +2 -1
- package/src/types/utils.ts +2 -2
- package/src/utils/helpers.ts +28 -0
- package/src/validation-error.ts +54 -4
- package/src/value-object.ts +6 -1
- package/.versionrc.json +0 -21
- package/CHANGELOG.md +0 -163
- package/tests/aggregate-changes.test.ts +0 -284
- package/tests/criteria.test.ts +0 -716
- package/tests/depth/deep-tracking.test.ts +0 -554
- package/tests/domain-events.test.ts +0 -431
- package/tests/entity-equality.test.ts +0 -464
- package/tests/entity-schema-registry.test.ts +0 -382
- package/tests/entity-validation.test.ts +0 -252
- package/tests/history-tracker.spec.ts +0 -439
- package/tests/id.test.ts +0 -338
- package/tests/load-test/data.json +0 -347211
- package/tests/load-test/entities.ts +0 -97
- package/tests/load-test/generate-data.ts +0 -81
- package/tests/load-test/lead-to-domain.mapper.ts +0 -24
- package/tests/load-test/load.test.ts +0 -38
- package/tests/repository.test.ts +0 -635
- package/tests/to-json.test.ts +0 -99
- package/tests/utils.ts +0 -290
- package/tests/value-object-validation.test.ts +0 -219
- package/tests/value-objects.test.ts +0 -80
- package/tsconfig.json +0 -9
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
Aggregate,
|
|
4
|
-
Entity,
|
|
5
|
-
EntityValidation,
|
|
6
|
-
Id,
|
|
7
|
-
ValueObject,
|
|
8
|
-
VOValidation,
|
|
9
|
-
} from "../../src";
|
|
10
|
-
|
|
11
|
-
const DateSchema = z.union([z.date(), z.string().datetime()]);
|
|
12
|
-
|
|
13
|
-
const AddressProps = z.object({
|
|
14
|
-
street: z.string(),
|
|
15
|
-
city: z.string(),
|
|
16
|
-
state: z.string(),
|
|
17
|
-
zip: z.string(),
|
|
18
|
-
country: z.string(),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
type AddressProps = z.infer<typeof AddressProps>;
|
|
22
|
-
|
|
23
|
-
export class Address extends ValueObject<AddressProps> {
|
|
24
|
-
protected static validation: VOValidation<AddressProps> = {
|
|
25
|
-
schema: AddressProps,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const ProposalProps = z.object({
|
|
30
|
-
id: z.instanceof(Id),
|
|
31
|
-
leadId: z.string(),
|
|
32
|
-
contractId: z.string(),
|
|
33
|
-
status: z.enum(["pending", "approved", "rejected"]),
|
|
34
|
-
createdAt: DateSchema,
|
|
35
|
-
updatedAt: DateSchema,
|
|
36
|
-
value: z.number(),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
type ProposalProps = z.infer<typeof ProposalProps>;
|
|
40
|
-
|
|
41
|
-
export class Proposal extends Entity<ProposalProps> {
|
|
42
|
-
protected static validation: EntityValidation<ProposalProps> = {
|
|
43
|
-
schema: ProposalProps,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const ContactProps = z.object({
|
|
48
|
-
id: z.instanceof(Id),
|
|
49
|
-
userId: z.string().optional(),
|
|
50
|
-
leadId: z.string().optional(),
|
|
51
|
-
name: z.string(),
|
|
52
|
-
email: z.string().email(),
|
|
53
|
-
phone: z.string(),
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
type ContactProps = z.infer<typeof ContactProps>;
|
|
57
|
-
|
|
58
|
-
export class Contact extends Entity<ContactProps> {
|
|
59
|
-
protected static validation: EntityValidation<ContactProps> = {
|
|
60
|
-
schema: ContactProps,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const ContractProps = z.object({
|
|
65
|
-
id: z.instanceof(Id),
|
|
66
|
-
proposalId: z.string(),
|
|
67
|
-
proposal: z.instanceof(Proposal),
|
|
68
|
-
signes: z.array(ContactProps),
|
|
69
|
-
createdAt: DateSchema,
|
|
70
|
-
updatedAt: DateSchema,
|
|
71
|
-
signedAt: DateSchema.optional(),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
type ContractProps = z.infer<typeof ContractProps>;
|
|
75
|
-
|
|
76
|
-
export class Contract extends Aggregate<ContractProps> {
|
|
77
|
-
protected static validation: EntityValidation<ContractProps> = {
|
|
78
|
-
schema: ContractProps,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const LeadProps = z.object({
|
|
83
|
-
id: z.instanceof(Id),
|
|
84
|
-
capturedName: z.string(),
|
|
85
|
-
capturedEmail: z.string().email(),
|
|
86
|
-
proposals: z.array(z.instanceof(Proposal)),
|
|
87
|
-
address: z.instanceof(Address),
|
|
88
|
-
contact: z.instanceof(Contact),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export type LeadProps = z.infer<typeof LeadProps>;
|
|
92
|
-
|
|
93
|
-
export class Lead extends Aggregate<LeadProps> {
|
|
94
|
-
protected static validation: EntityValidation<LeadProps> = {
|
|
95
|
-
schema: LeadProps,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { faker } from "@faker-js/faker";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
const LEADS_COUNT = 10000;
|
|
5
|
-
|
|
6
|
-
const createId = () => faker.string.uuid();
|
|
7
|
-
|
|
8
|
-
const createAddress = () => {
|
|
9
|
-
return {
|
|
10
|
-
street: faker.location.streetAddress(),
|
|
11
|
-
city: faker.location.city(),
|
|
12
|
-
state: faker.location.state(),
|
|
13
|
-
zip: faker.location.zipCode(),
|
|
14
|
-
country: faker.location.country(),
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const createProposal = (leadId: string) => {
|
|
19
|
-
const createdDate = faker.date.past();
|
|
20
|
-
return {
|
|
21
|
-
id: createId(),
|
|
22
|
-
leadId: leadId,
|
|
23
|
-
contractId: createId(),
|
|
24
|
-
status: faker.helpers.arrayElement(["pending", "approved", "rejected"]),
|
|
25
|
-
createdAt: createdDate,
|
|
26
|
-
updatedAt: faker.date.between({ from: createdDate, to: new Date() }),
|
|
27
|
-
value: parseFloat(faker.finance.amount({ min: 1000, max: 50000, dec: 2 })),
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const createContact = (leadId: string) => {
|
|
32
|
-
return {
|
|
33
|
-
id: createId(),
|
|
34
|
-
userId: faker.datatype.boolean() ? createId() : undefined,
|
|
35
|
-
leadId: leadId,
|
|
36
|
-
name: faker.person.fullName(),
|
|
37
|
-
email: faker.internet.email(),
|
|
38
|
-
phone: faker.phone.number(),
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const createLead = () => {
|
|
43
|
-
const leadId = createId();
|
|
44
|
-
const firstName = faker.person.firstName();
|
|
45
|
-
const lastName = faker.person.lastName();
|
|
46
|
-
|
|
47
|
-
const numProposals = faker.number.int({ min: 0, max: 3 });
|
|
48
|
-
|
|
49
|
-
const proposalsArray = Array.from({ length: numProposals }).map(() =>
|
|
50
|
-
createProposal(leadId)
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
id: leadId,
|
|
55
|
-
capturedName: `${firstName} ${lastName}`,
|
|
56
|
-
capturedEmail: faker.internet.email({ firstName, lastName }),
|
|
57
|
-
|
|
58
|
-
address: createAddress(),
|
|
59
|
-
|
|
60
|
-
contact: createContact(leadId),
|
|
61
|
-
proposals: proposalsArray,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export async function generateData() {
|
|
66
|
-
return await new Promise((resolve, reject) => {
|
|
67
|
-
try {
|
|
68
|
-
console.log(`Generating ${LEADS_COUNT} leads...`);
|
|
69
|
-
const leads: any[] = [];
|
|
70
|
-
for (let i = 0; i < LEADS_COUNT; i++) {
|
|
71
|
-
leads.push(createLead());
|
|
72
|
-
}
|
|
73
|
-
const jsonOutput = JSON.stringify(leads, null, 2);
|
|
74
|
-
fs.writeFileSync(`${__dirname}/data.json`, jsonOutput);
|
|
75
|
-
console.log(`Success! data.json created with ${leads.length} items.`);
|
|
76
|
-
resolve(true);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
reject(error);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Id, Mapper } from "../../src";
|
|
2
|
-
import { Address, Contact, Lead, Proposal } from "./entities";
|
|
3
|
-
|
|
4
|
-
export class LeadToDomainMapper extends Mapper<any, Lead> {
|
|
5
|
-
public build(props: any): Lead {
|
|
6
|
-
return new Lead({
|
|
7
|
-
id: Id.from(props.id),
|
|
8
|
-
capturedName: props.capturedName,
|
|
9
|
-
capturedEmail: props.capturedEmail,
|
|
10
|
-
address: new Address(props.address),
|
|
11
|
-
contact: new Contact({
|
|
12
|
-
...props.contact,
|
|
13
|
-
id: Id.from(props.contact.id),
|
|
14
|
-
}),
|
|
15
|
-
proposals: props.proposals.map(
|
|
16
|
-
(proposal: any) =>
|
|
17
|
-
new Proposal({
|
|
18
|
-
...proposal,
|
|
19
|
-
id: Id.from(proposal.id),
|
|
20
|
-
})
|
|
21
|
-
),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Lead } from "./entities";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { generateData } from "./generate-data";
|
|
4
|
-
import { LeadToDomainMapper } from "./lead-to-domain.mapper";
|
|
5
|
-
import { PaginatedResult } from "../../src";
|
|
6
|
-
|
|
7
|
-
describe("Big Data", () => {
|
|
8
|
-
let leads: Lead[] = [];
|
|
9
|
-
|
|
10
|
-
function populateLeads() {
|
|
11
|
-
const data = fs.readFileSync(`${__dirname}/data.json`, "utf8");
|
|
12
|
-
const leadsData = JSON.parse(data);
|
|
13
|
-
const toDomainMapper = new LeadToDomainMapper();
|
|
14
|
-
leads = leadsData.map((lead: any) => toDomainMapper.build(lead));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
beforeAll(async () => {
|
|
18
|
-
const hasData = fs.existsSync(`${__dirname}/data.json`);
|
|
19
|
-
if (!hasData) {
|
|
20
|
-
await generateData();
|
|
21
|
-
}
|
|
22
|
-
populateLeads();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should have 10000 leads", () => {
|
|
26
|
-
expect(leads.length).toBe(10000);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should deserialize to JSON correctly", () => {
|
|
30
|
-
const paginationResult = PaginatedResult.create(
|
|
31
|
-
leads,
|
|
32
|
-
{ page: 1, limit: 10, offset: 0 },
|
|
33
|
-
1000
|
|
34
|
-
);
|
|
35
|
-
const json = paginationResult.toJSON();
|
|
36
|
-
expect(json.data.length).toBe(10000);
|
|
37
|
-
});
|
|
38
|
-
});
|