Skip to content

Commit a45b62a

Browse files
committedOct 20, 2023
replacement of v4() with native function randomUUID
1 parent 19ae46c commit a45b62a

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed
 

‎src/libs/ddd/command.base.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { RequestContextService } from '@libs/application/context/AppRequestContext';
2-
import { v4 } from 'uuid';
32
import { ArgumentNotProvidedException } from '../exceptions';
43
import { Guard } from '../guard';
54

@@ -43,7 +42,7 @@ export class Command {
4342
);
4443
}
4544
const ctx = RequestContextService.getContext();
46-
this.id = props.id || v4();
45+
this.id = props.id || crypto.randomUUID();
4746
this.metadata = {
4847
correlationId: props?.metadata?.correlationId || ctx.requestId,
4948
causationId: props?.metadata?.causationId,

‎src/libs/ddd/domain-event.base.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ArgumentNotProvidedException } from '../exceptions';
22
import { Guard } from '../guard';
3-
import { v4 } from 'uuid';
43
import { RequestContextService } from '@libs/application/context/AppRequestContext';
54

65
type DomainEventMetadata = {
@@ -41,7 +40,7 @@ export abstract class DomainEvent {
4140
'DomainEvent props should not be empty',
4241
);
4342
}
44-
this.id = v4();
43+
this.id = crypto.randomUUID();
4544
this.aggregateId = props.aggregateId;
4645
this.metadata = {
4746
correlationId:

‎src/modules/user/domain/user.entity.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
UserProps,
88
UserRoles,
99
} from './user.types';
10-
import { v4 } from 'uuid';
1110
import { UserDeletedDomainEvent } from './events/user-deleted.domain-event';
1211
import { UserRoleChangedDomainEvent } from './events/user-role-changed.domain-event';
1312
import { UserAddressUpdatedDomainEvent } from './events/user-address-updated.domain-event';
@@ -16,7 +15,7 @@ export class UserEntity extends AggregateRoot<UserProps> {
1615
protected readonly _id: AggregateID;
1716

1817
static create(create: CreateUserProps): UserEntity {
19-
const id = v4();
18+
const id = crypto.randomUUID();
2019
/* Setting a default role since we are not accepting it during creation. */
2120
const props: UserProps = { ...create, role: UserRoles.guest };
2221
const user = new UserEntity({ id, props });

‎src/modules/wallet/domain/wallet.entity.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AggregateID, AggregateRoot } from '@libs/ddd';
22
import { ArgumentOutOfRangeException } from '@libs/exceptions';
33
import { Err, Ok, Result } from 'oxide.ts';
4-
import { v4 } from 'uuid';
54
import { WalletCreatedDomainEvent } from './events/wallet-created.domain-event';
65
import { WalletNotEnoughBalanceError } from './wallet.errors';
76

@@ -17,7 +16,7 @@ export class WalletEntity extends AggregateRoot<WalletProps> {
1716
protected readonly _id: AggregateID;
1817

1918
static create(create: CreateWalletProps): WalletEntity {
20-
const id = v4();
19+
const id = crypto.randomUUID();
2120
const props: WalletProps = { ...create, balance: 0 };
2221
const wallet = new WalletEntity({ id, props });
2322

0 commit comments

Comments
 (0)
Failed to load comments.