@woltz/rich-domain 1.2.4 → 1.3.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.
Files changed (72) hide show
  1. package/dist/aggregate-changes.d.ts +56 -14
  2. package/dist/aggregate-changes.d.ts.map +1 -1
  3. package/dist/aggregate-changes.js +102 -22
  4. package/dist/aggregate-changes.js.map +1 -1
  5. package/dist/base-entity.d.ts +1 -1
  6. package/dist/base-entity.d.ts.map +1 -1
  7. package/dist/base-entity.js +11 -8
  8. package/dist/base-entity.js.map +1 -1
  9. package/dist/change-tracker.d.ts +1 -0
  10. package/dist/change-tracker.d.ts.map +1 -1
  11. package/dist/change-tracker.js +41 -27
  12. package/dist/change-tracker.js.map +1 -1
  13. package/dist/criteria.d.ts +7 -15
  14. package/dist/criteria.d.ts.map +1 -1
  15. package/dist/criteria.js +99 -76
  16. package/dist/criteria.js.map +1 -1
  17. package/dist/entity-schema-registry.d.ts +133 -3
  18. package/dist/entity-schema-registry.d.ts.map +1 -1
  19. package/dist/entity-schema-registry.js +155 -4
  20. package/dist/entity-schema-registry.js.map +1 -1
  21. package/dist/paginated-result.d.ts +4 -4
  22. package/dist/paginated-result.d.ts.map +1 -1
  23. package/dist/paginated-result.js +6 -20
  24. package/dist/paginated-result.js.map +1 -1
  25. package/dist/types/change-tracker.d.ts +30 -0
  26. package/dist/types/change-tracker.d.ts.map +1 -1
  27. package/dist/types/criteria.d.ts +1 -4
  28. package/dist/types/criteria.d.ts.map +1 -1
  29. package/dist/types/domain.d.ts +2 -0
  30. package/dist/types/domain.d.ts.map +1 -1
  31. package/dist/types/utils.d.ts +2 -2
  32. package/dist/utils/helpers.d.ts +1 -0
  33. package/dist/utils/helpers.d.ts.map +1 -1
  34. package/dist/utils/helpers.js +23 -0
  35. package/dist/utils/helpers.js.map +1 -1
  36. package/dist/value-object.d.ts +1 -1
  37. package/dist/value-object.js +1 -1
  38. package/package.json +17 -3
  39. package/src/aggregate-changes.ts +133 -24
  40. package/src/base-entity.ts +13 -8
  41. package/src/change-tracker.ts +107 -38
  42. package/src/criteria.ts +151 -109
  43. package/src/entity-schema-registry.ts +253 -6
  44. package/src/paginated-result.ts +10 -30
  45. package/src/types/change-tracker.ts +31 -0
  46. package/src/types/criteria.ts +1 -4
  47. package/src/types/domain.ts +2 -0
  48. package/src/types/utils.ts +2 -2
  49. package/src/utils/helpers.ts +28 -0
  50. package/src/value-object.ts +1 -1
  51. package/.versionrc.json +0 -21
  52. package/CHANGELOG.md +0 -163
  53. package/tests/aggregate-changes.test.ts +0 -284
  54. package/tests/criteria.test.ts +0 -716
  55. package/tests/depth/deep-tracking.test.ts +0 -554
  56. package/tests/domain-events.test.ts +0 -431
  57. package/tests/entity-equality.test.ts +0 -464
  58. package/tests/entity-schema-registry.test.ts +0 -382
  59. package/tests/entity-validation.test.ts +0 -252
  60. package/tests/history-tracker.spec.ts +0 -439
  61. package/tests/id.test.ts +0 -338
  62. package/tests/load-test/data.json +0 -347211
  63. package/tests/load-test/entities.ts +0 -97
  64. package/tests/load-test/generate-data.ts +0 -81
  65. package/tests/load-test/lead-to-domain.mapper.ts +0 -24
  66. package/tests/load-test/load.test.ts +0 -38
  67. package/tests/repository.test.ts +0 -635
  68. package/tests/to-json.test.ts +0 -99
  69. package/tests/utils.ts +0 -290
  70. package/tests/value-object-validation.test.ts +0 -219
  71. package/tests/value-objects.test.ts +0 -80
  72. 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
- });