@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.
Files changed (94) 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 +103 -23
  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 +28 -13
  8. package/dist/base-entity.js.map +1 -1
  9. package/dist/change-tracker.d.ts +2 -1
  10. package/dist/change-tracker.d.ts.map +1 -1
  11. package/dist/change-tracker.js +61 -35
  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 +105 -81
  16. package/dist/criteria.js.map +1 -1
  17. package/dist/domain-event-bus.js +4 -4
  18. package/dist/domain-event-bus.js.map +1 -1
  19. package/dist/domain-event.js +3 -0
  20. package/dist/domain-event.js.map +1 -1
  21. package/dist/entity-changes.js +1 -0
  22. package/dist/entity-changes.js.map +1 -1
  23. package/dist/entity-schema-registry.d.ts +137 -3
  24. package/dist/entity-schema-registry.d.ts.map +1 -1
  25. package/dist/entity-schema-registry.js +160 -7
  26. package/dist/entity-schema-registry.js.map +1 -1
  27. package/dist/exceptions.js +26 -1
  28. package/dist/exceptions.js.map +1 -1
  29. package/dist/id.js +2 -0
  30. package/dist/id.js.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/paginated-result.d.ts +4 -4
  34. package/dist/paginated-result.d.ts.map +1 -1
  35. package/dist/paginated-result.js +14 -19
  36. package/dist/paginated-result.js.map +1 -1
  37. package/dist/repository/unit-of-work.js +3 -7
  38. package/dist/repository/unit-of-work.js.map +1 -1
  39. package/dist/types/change-tracker.d.ts +30 -0
  40. package/dist/types/change-tracker.d.ts.map +1 -1
  41. package/dist/types/criteria.d.ts +1 -4
  42. package/dist/types/criteria.d.ts.map +1 -1
  43. package/dist/types/domain.d.ts +2 -1
  44. package/dist/types/domain.d.ts.map +1 -1
  45. package/dist/types/utils.d.ts +2 -2
  46. package/dist/utils/helpers.d.ts +1 -0
  47. package/dist/utils/helpers.d.ts.map +1 -1
  48. package/dist/utils/helpers.js +23 -0
  49. package/dist/utils/helpers.js.map +1 -1
  50. package/dist/validation-error.d.ts +15 -1
  51. package/dist/validation-error.d.ts.map +1 -1
  52. package/dist/validation-error.js +46 -3
  53. package/dist/validation-error.js.map +1 -1
  54. package/dist/value-object.d.ts +1 -1
  55. package/dist/value-object.d.ts.map +1 -1
  56. package/dist/value-object.js +30 -2
  57. package/dist/value-object.js.map +1 -1
  58. package/package.json +17 -3
  59. package/src/aggregate-changes.ts +133 -24
  60. package/src/base-entity.ts +22 -11
  61. package/src/change-tracker.ts +113 -54
  62. package/src/criteria.ts +151 -109
  63. package/src/entity-schema-registry.ts +256 -6
  64. package/src/index.ts +1 -1
  65. package/src/paginated-result.ts +21 -29
  66. package/src/types/change-tracker.ts +31 -0
  67. package/src/types/criteria.ts +1 -4
  68. package/src/types/domain.ts +2 -1
  69. package/src/types/utils.ts +2 -2
  70. package/src/utils/helpers.ts +28 -0
  71. package/src/validation-error.ts +54 -4
  72. package/src/value-object.ts +6 -1
  73. package/.versionrc.json +0 -21
  74. package/CHANGELOG.md +0 -163
  75. package/tests/aggregate-changes.test.ts +0 -284
  76. package/tests/criteria.test.ts +0 -716
  77. package/tests/depth/deep-tracking.test.ts +0 -554
  78. package/tests/domain-events.test.ts +0 -431
  79. package/tests/entity-equality.test.ts +0 -464
  80. package/tests/entity-schema-registry.test.ts +0 -382
  81. package/tests/entity-validation.test.ts +0 -252
  82. package/tests/history-tracker.spec.ts +0 -439
  83. package/tests/id.test.ts +0 -338
  84. package/tests/load-test/data.json +0 -347211
  85. package/tests/load-test/entities.ts +0 -97
  86. package/tests/load-test/generate-data.ts +0 -81
  87. package/tests/load-test/lead-to-domain.mapper.ts +0 -24
  88. package/tests/load-test/load.test.ts +0 -38
  89. package/tests/repository.test.ts +0 -635
  90. package/tests/to-json.test.ts +0 -99
  91. package/tests/utils.ts +0 -290
  92. package/tests/value-object-validation.test.ts +0 -219
  93. package/tests/value-objects.test.ts +0 -80
  94. 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
- });