Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: native crypto import #146

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libs/ddd/command.base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequestContextService } from '@libs/application/context/AppRequestContext';
import { ArgumentNotProvidedException } from '../exceptions';
import { Guard } from '../guard';
import { randomUUID } from 'crypto';

export type CommandProps<T> = Omit<T, 'id' | 'metadata'> & Partial<Command>;

Expand Down Expand Up @@ -42,7 +43,7 @@ export class Command {
);
}
const ctx = RequestContextService.getContext();
this.id = props.id || crypto.randomUUID();
this.id = props.id || randomUUID();
this.metadata = {
correlationId: props?.metadata?.correlationId || ctx.requestId,
causationId: props?.metadata?.causationId,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ddd/domain-event.base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { randomUUID } from 'crypto';
import { ArgumentNotProvidedException } from '../exceptions';
import { Guard } from '../guard';
import { RequestContextService } from '@libs/application/context/AppRequestContext';
Expand Down Expand Up @@ -40,7 +41,7 @@ export abstract class DomainEvent {
'DomainEvent props should not be empty',
);
}
this.id = crypto.randomUUID();
this.id = randomUUID();
this.aggregateId = props.aggregateId;
this.metadata = {
correlationId:
Expand Down
3 changes: 2 additions & 1 deletion src/modules/user/domain/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
import { UserDeletedDomainEvent } from './events/user-deleted.domain-event';
import { UserRoleChangedDomainEvent } from './events/user-role-changed.domain-event';
import { UserAddressUpdatedDomainEvent } from './events/user-address-updated.domain-event';
import { randomUUID } from 'crypto';

export class UserEntity extends AggregateRoot<UserProps> {
protected readonly _id: AggregateID;

static create(create: CreateUserProps): UserEntity {
const id = crypto.randomUUID();
const id = randomUUID();
/* Setting a default role since we are not accepting it during creation. */
const props: UserProps = { ...create, role: UserRoles.guest };
const user = new UserEntity({ id, props });
Expand Down
3 changes: 2 additions & 1 deletion src/modules/wallet/domain/wallet.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ArgumentOutOfRangeException } from '@libs/exceptions';
import { Err, Ok, Result } from 'oxide.ts';
import { WalletCreatedDomainEvent } from './events/wallet-created.domain-event';
import { WalletNotEnoughBalanceError } from './wallet.errors';
import { randomUUID } from 'crypto';

export interface CreateWalletProps {
userId: AggregateID;
Expand All @@ -16,7 +17,7 @@ export class WalletEntity extends AggregateRoot<WalletProps> {
protected readonly _id: AggregateID;

static create(create: CreateWalletProps): WalletEntity {
const id = crypto.randomUUID();
const id = randomUUID();
const props: WalletProps = { ...create, balance: 0 };
const wallet = new WalletEntity({ id, props });

Expand Down